mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-05 16:02:03 +00:00
fix(dns): say in view when the backend can't query, clear or delete
This commit is contained in:
1 parent
4ae4e4965d
commit
45e2de4792
7 files changed
+119
-44
No files matched your search
+37
-30
@@ -5,6 +5,7 @@ import Download from '../../ui/icons/Download';
|
||||
import Refresh from '../../ui/icons/Refresh';
|
||||
import {
|
||||
ActionGroup,
|
||||
ActionHelp,
|
||||
Badge,
|
||||
Button,
|
||||
DataTable,
|
||||
@@ -44,13 +45,15 @@ export function Dns(props: PageProps) {
|
||||
vm.submit();
|
||||
}}
|
||||
>
|
||||
<div className="rp-toolbar">
|
||||
<TextField side label={t('ui.domain')} value={vm.domain} onChange={vm.setDomain} width={280} placeholder="example.com" />
|
||||
<LabeledSelect label={t('ui.type')} side value={vm.type} onChange={vm.setType} items={vm.choices} />
|
||||
<Button accent type="submit" isPending={vm.pending} isDisabled={vm.disabled}>
|
||||
{t('dns.query')}
|
||||
</Button>
|
||||
</div>
|
||||
<ActionHelp reason={vm.reason}>
|
||||
<div className="rp-toolbar">
|
||||
<TextField side label={t('ui.domain')} value={vm.domain} onChange={vm.setDomain} width={280} placeholder="example.com" />
|
||||
<LabeledSelect label={t('ui.type')} side value={vm.type} onChange={vm.setType} items={vm.choices} />
|
||||
<Button accent type="submit" isPending={vm.pending} isDisabled={vm.disabled}>
|
||||
{t('dns.query')}
|
||||
</Button>
|
||||
</div>
|
||||
</ActionHelp>
|
||||
</form>
|
||||
{vm.cards.length > 0 && (
|
||||
<div className="rp-col">
|
||||
@@ -137,29 +140,33 @@ function DnsCache({domain, clearFilter}: {domain: string; clearFilter: () => voi
|
||||
return (
|
||||
<>
|
||||
{vm.error && <ErrorMessage error={vm.error} onRetry={vm.retry} />}
|
||||
<div className="rp-toolbar">
|
||||
<Kv row items={vm.fields} />
|
||||
{vm.coverage.map(badge => (
|
||||
<Badge key={badge.id} tone="warn">
|
||||
{badge.text}
|
||||
</Badge>
|
||||
))}
|
||||
{vm.filterText && (
|
||||
<Button small onPress={clearFilter}>
|
||||
{vm.filterText}
|
||||
</Button>
|
||||
)}
|
||||
<span className="rp-grow" />
|
||||
<ConfirmButton
|
||||
label={t('dns.flushAll')}
|
||||
confirmationText={vm.confirmationText}
|
||||
isPending={vm.flushPending}
|
||||
isDisabled={vm.flushPending || vm.flushDisabled}
|
||||
onConfirm={vm.flush}
|
||||
onAbort={vm.abortFlush}
|
||||
/>
|
||||
</div>
|
||||
<DataTable label={t('ui.cache')} height={442} fit rows={vm.rows} loading={vm.loading} empty={vm.empty} cols={columns} />
|
||||
<ActionHelp reason={vm.flushReason}>
|
||||
<div className="rp-toolbar">
|
||||
<Kv row items={vm.fields} />
|
||||
{vm.coverage.map(badge => (
|
||||
<Badge key={badge.id} tone="warn">
|
||||
{badge.text}
|
||||
</Badge>
|
||||
))}
|
||||
{vm.filterText && (
|
||||
<Button small onPress={clearFilter}>
|
||||
{vm.filterText}
|
||||
</Button>
|
||||
)}
|
||||
<span className="rp-grow" />
|
||||
<ConfirmButton
|
||||
label={t('dns.flushAll')}
|
||||
confirmationText={vm.confirmationText}
|
||||
isPending={vm.flushPending}
|
||||
isDisabled={vm.flushPending || vm.flushDisabled}
|
||||
onConfirm={vm.flush}
|
||||
onAbort={vm.abortFlush}
|
||||
/>
|
||||
</div>
|
||||
</ActionHelp>
|
||||
<ActionHelp reason={vm.deleteReason}>
|
||||
<DataTable label={t('ui.cache')} height={442} fit rows={vm.rows} loading={vm.loading} empty={vm.empty} cols={columns} />
|
||||
</ActionHelp>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ export const messages = defineMessages({
|
||||
'dns.flushFailed': '無法清除快取:{error}',
|
||||
'dns.allTypes': '所有支援類型',
|
||||
'dns.query': '查詢',
|
||||
'dns.queryUnavailable': '此後端目前無法執行 DNS 查詢',
|
||||
'dns.typeUnsupported': '此後端不支援查詢此記錄類型',
|
||||
'dns.noTypes': '此後端未提供可查詢的記錄類型',
|
||||
'dns.hit': '快取命中',
|
||||
'dns.miss': '快取未命中',
|
||||
'dns.routeSource': '路由來源',
|
||||
@@ -49,6 +52,7 @@ export const messages = defineMessages({
|
||||
'dns.expires': '到期時間',
|
||||
'dns.staleUntil': '過期後仍可用至',
|
||||
'dns.deleteEntry': '刪除 {domain} 的 {type} 快取項目',
|
||||
'dns.deleteUnsupported': '此後端不支援刪除快取項目',
|
||||
'dns.entries': '快取項目',
|
||||
'dns.viewCache': '查看快取',
|
||||
'dns.log': '解析記錄',
|
||||
@@ -79,6 +83,7 @@ export const messages = defineMessages({
|
||||
'dns.flushConfirm': '將清除全部 {n} 筆快取項目,無法復原。',
|
||||
'dns.flushConfirmAll': '將清除全部快取項目,無法復原。',
|
||||
'dns.flushAll': '清除全部快取',
|
||||
'dns.flushUnsupported': '此後端不支援清除快取',
|
||||
'dns.answer': '{name} {type};TTL {ttl} 秒;{data}'
|
||||
},
|
||||
'zh-CN': {
|
||||
@@ -111,6 +116,9 @@ export const messages = defineMessages({
|
||||
'dns.flushFailed': '无法清除缓存:{error}',
|
||||
'dns.allTypes': '所有支持类型',
|
||||
'dns.query': '查询',
|
||||
'dns.queryUnavailable': '此后端当前无法执行 DNS 查询',
|
||||
'dns.typeUnsupported': '此后端不支持查询此记录类型',
|
||||
'dns.noTypes': '此后端未提供可查询的记录类型',
|
||||
'dns.hit': '缓存命中',
|
||||
'dns.miss': '缓存未命中',
|
||||
'dns.routeSource': '路由来源',
|
||||
@@ -129,6 +137,7 @@ export const messages = defineMessages({
|
||||
'dns.expires': '到期时间',
|
||||
'dns.staleUntil': '过期后仍可用至',
|
||||
'dns.deleteEntry': '删除 {domain} 的 {type} 缓存项',
|
||||
'dns.deleteUnsupported': '此后端不支持删除缓存项',
|
||||
'dns.entries': '缓存项',
|
||||
'dns.viewCache': '查看缓存',
|
||||
'dns.log': '解析记录',
|
||||
@@ -159,6 +168,7 @@ export const messages = defineMessages({
|
||||
'dns.flushConfirm': '将清除全部 {n} 条缓存项,无法撤销。',
|
||||
'dns.flushConfirmAll': '将清除全部缓存项,无法撤销。',
|
||||
'dns.flushAll': '清除全部缓存',
|
||||
'dns.flushUnsupported': '此后端不支持清除缓存',
|
||||
'dns.answer': '{name} {type};TTL {ttl} 秒;{data}'
|
||||
},
|
||||
en: {
|
||||
@@ -194,6 +204,9 @@ export const messages = defineMessages({
|
||||
'dns.flushFailed': 'Could not clear the cache: {error}',
|
||||
'dns.allTypes': 'All supported types',
|
||||
'dns.query': 'Query',
|
||||
'dns.queryUnavailable': 'This backend cannot run DNS queries right now',
|
||||
'dns.typeUnsupported': 'This backend cannot query this record type',
|
||||
'dns.noTypes': 'This backend offers no record types to query',
|
||||
'dns.hit': 'Cache hit',
|
||||
'dns.miss': 'Cache miss',
|
||||
'dns.routeSource': 'Route source',
|
||||
@@ -212,6 +225,7 @@ export const messages = defineMessages({
|
||||
'dns.expires': 'Expires',
|
||||
'dns.staleUntil': 'Stale until',
|
||||
'dns.deleteEntry': 'Delete the {type} cache entry for {domain}',
|
||||
'dns.deleteUnsupported': 'This backend does not support deleting cache entries',
|
||||
'dns.entries': 'Cache entries',
|
||||
'dns.viewCache': 'View cache',
|
||||
'dns.log': 'Resolution log',
|
||||
@@ -242,6 +256,7 @@ export const messages = defineMessages({
|
||||
'dns.flushConfirm': {one: 'This clears the {n} cache entry and cannot be undone.', other: 'This clears all {n} cache entries and cannot be undone.'},
|
||||
'dns.flushConfirmAll': 'This clears every cache entry and cannot be undone.',
|
||||
'dns.flushAll': 'Clear all cache',
|
||||
'dns.flushUnsupported': 'This backend does not support clearing the cache',
|
||||
'dns.answer': '{name} {type}; TTL {ttl} s; {data}'
|
||||
}
|
||||
});
|
||||
@@ -110,3 +110,28 @@ it('says the persistent cache is memory only rather than not covered, and explai
|
||||
expect(log.totalHelp).toEqual({title: t('dns.logTotal', {n: 3}), text: t('dns.logTotalHelp')});
|
||||
expect(dnsLogView(undefined, true, t).totalHelp).toBeNull();
|
||||
});
|
||||
|
||||
it('says why Query, Clear all cache and Delete are disabled when the backend does not support them', () => {
|
||||
const {resources} = capabilities;
|
||||
expect(dnsQueryView(null, resources, 'A', 'example.com', false, t).reason).toBeNull();
|
||||
// An empty domain speaks for itself, and nothing is said before the capabilities arrive or while a query runs.
|
||||
expect(dnsQueryView(null, resources, 'A', '', false, t).reason).toBeNull();
|
||||
expect(dnsQueryView(null, undefined, 'A', 'example.com', false, t).reason).toBeNull();
|
||||
const off = {...resources, dns_query: {...resources.dns_query, available: false}};
|
||||
expect(dnsQueryView(null, off, 'A', 'example.com', false, t).reason).toBe('This backend cannot run DNS queries right now');
|
||||
expect(dnsQueryView(null, off, 'A', 'example.com', true, t).reason).toBeNull();
|
||||
const aOnly = {...resources, dns_query: {...resources.dns_query, record_types: ['A']}};
|
||||
expect(dnsQueryView(null, aOnly, 'AAAA', 'example.com', false, t).reason).toBe('This backend cannot query this record type');
|
||||
const none = {...resources, dns_query: {...resources.dns_query, record_types: []}};
|
||||
expect(dnsQueryView(null, none, 'all', 'example.com', false, t).reason).toBe('This backend offers no record types to query');
|
||||
|
||||
const cache = dnsCacheView(dnsCache, resources, '', null, 'en-US', t);
|
||||
expect([cache.flushReason, cache.deleteReason]).toEqual([null, null]);
|
||||
const readOnly = {...resources, dns_cache: {...resources.dns_cache, flush: false, delete_entry: false}};
|
||||
const limited = dnsCacheView(dnsCache, readOnly, '', null, 'en-US', t);
|
||||
expect(limited.flushReason).toBe('This backend does not support clearing the cache');
|
||||
expect(limited.deleteReason).toBe('This backend does not support deleting cache entries');
|
||||
// No row, no Delete to explain; a change in flight shows as pending.
|
||||
expect(dnsCacheView(dnsCache, readOnly, 'nothing-matches', null, 'en-US', t).deleteReason).toBeNull();
|
||||
expect(dnsCacheView(dnsCache, readOnly, '', 'flush', 'en-US', t).flushReason).toBeNull();
|
||||
});
|
||||
+27
-14
@@ -31,10 +31,20 @@ export function dnsQueryView(
|
||||
t: LabelFn
|
||||
) {
|
||||
const types = resources?.dns_query.record_types ?? [];
|
||||
const typeOffered = type === 'all' ? types.length > 0 : types.includes(type);
|
||||
return {
|
||||
types,
|
||||
choices: [...types.map(id => ({id, label: id})), {id: 'all', label: t('dns.allTypes')}],
|
||||
disabled: busy || !resources?.dns_query.available || !(type === 'all' ? types.length > 0 : types.includes(type)) || !domain.trim(),
|
||||
disabled: busy || !resources?.dns_query.available || !typeOffered || !domain.trim(),
|
||||
// Why Query is disabled, when the backend is the reason; an empty domain speaks for itself.
|
||||
reason:
|
||||
!resources || busy
|
||||
? null
|
||||
: !resources.dns_query.available
|
||||
? t('dns.queryUnavailable')
|
||||
: typeOffered
|
||||
? null
|
||||
: t(type === 'all' ? 'dns.noTypes' : 'dns.typeUnsupported'),
|
||||
showCache: !!resources?.dns_cache.available,
|
||||
cards: result?.results.map(item => ({id: item.type, title: `${result.domain} ${item.type}`, ...dnsAnswerView(item, t)})) ?? [],
|
||||
tabs: dnsTabs(resources).map(tab => ({id: tab.id, label: t(tab.titleKey)}))
|
||||
@@ -49,6 +59,8 @@ export function dnsCacheView(
|
||||
t: LabelFn
|
||||
) {
|
||||
const filter = domain.toLowerCase();
|
||||
const cache = resources?.dns_cache;
|
||||
const rows = (data?.entries ?? []).filter(entry => !filter || entry.domain.toLowerCase().includes(filter));
|
||||
return {
|
||||
fields: [[t('dns.entries'), data ? formatNumber(data.total, locale) : '—']] as Array<[string, string]>,
|
||||
coverage: data
|
||||
@@ -68,20 +80,21 @@ export function dnsCacheView(
|
||||
filterText: filter ? t('dns.cacheFilter', {domain}) : '',
|
||||
confirmationText: data ? t('dns.flushConfirm', {n: data.total}) : t('dns.flushConfirmAll'),
|
||||
flushDisabled: !!busy || !resources?.dns_cache.available || !resources.dns_cache.flush,
|
||||
// Why Clear all cache and the rows' Delete are disabled, when the backend does not support them.
|
||||
flushReason: cache && !busy && (!cache.available || !cache.flush) ? t('dns.flushUnsupported') : null,
|
||||
deleteReason: cache && !busy && rows.length > 0 && (!cache.available || !cache.delete_entry) ? t('dns.deleteUnsupported') : null,
|
||||
empty: t(resources?.dns_cache.available && resources.dns_cache.read ? 'dns.empty' : 'dns.cacheUnavailable'),
|
||||
rows: (data?.entries ?? [])
|
||||
.filter(entry => !filter || entry.domain.toLowerCase().includes(filter))
|
||||
.map(entry => ({
|
||||
id: entry.entry_id,
|
||||
domain: entry.domain,
|
||||
type: entry.type,
|
||||
status: entry.status,
|
||||
expiresAt: entry.expires_at,
|
||||
staleUntil: entry.stale_until,
|
||||
deleteLabel: t('dns.deleteEntry', {domain: entry.domain, type: entry.type}),
|
||||
pending: busy === entry.entry_id,
|
||||
disabled: !!busy || !resources?.dns_cache.available || !resources.dns_cache.delete_entry
|
||||
}))
|
||||
rows: rows.map(entry => ({
|
||||
id: entry.entry_id,
|
||||
domain: entry.domain,
|
||||
type: entry.type,
|
||||
status: entry.status,
|
||||
expiresAt: entry.expires_at,
|
||||
staleUntil: entry.stale_until,
|
||||
deleteLabel: t('dns.deleteEntry', {domain: entry.domain, type: entry.type}),
|
||||
pending: busy === entry.entry_id,
|
||||
disabled: !!busy || !resources?.dns_cache.available || !resources.dns_cache.delete_entry
|
||||
}))
|
||||
};
|
||||
}
|
||||
// The selected record's detail, apart from the rows, so a click does not reformat every loaded record.
|
||||
|
||||
@@ -349,6 +349,9 @@ export const messages = {
|
||||
'dns.flushFailed': 'Could not clear the cache: {error}',
|
||||
'dns.allTypes': 'All supported types',
|
||||
'dns.query': 'Query',
|
||||
'dns.queryUnavailable': 'This backend cannot run DNS queries right now',
|
||||
'dns.typeUnsupported': 'This backend cannot query this record type',
|
||||
'dns.noTypes': 'This backend offers no record types to query',
|
||||
'dns.hit': 'Cache hit',
|
||||
'dns.miss': 'Cache miss',
|
||||
'dns.routeSource': 'Route source',
|
||||
@@ -367,6 +370,7 @@ export const messages = {
|
||||
'dns.expires': 'Expires',
|
||||
'dns.staleUntil': 'Stale until',
|
||||
'dns.deleteEntry': 'Delete the {type} cache entry for {domain}',
|
||||
'dns.deleteUnsupported': 'This backend does not support deleting cache entries',
|
||||
'dns.entries': 'Cache entries',
|
||||
'dns.viewCache': 'View cache',
|
||||
'dns.log': 'Resolution log',
|
||||
@@ -397,6 +401,7 @@ export const messages = {
|
||||
'dns.flushConfirm': {one: 'This clears the {n} cache entry and cannot be undone.', other: 'This clears all {n} cache entries and cannot be undone.'},
|
||||
'dns.flushConfirmAll': 'This clears every cache entry and cannot be undone.',
|
||||
'dns.flushAll': 'Clear all cache',
|
||||
'dns.flushUnsupported': 'This backend does not support clearing the cache',
|
||||
'dns.answer': '{name} {type}; TTL {ttl} s; {data}',
|
||||
'event.export': 'Export JSON',
|
||||
'event.kind': 'Kind',
|
||||
|
||||
@@ -326,6 +326,9 @@ export const messages = {
|
||||
'dns.flushFailed': '无法清除缓存:{error}',
|
||||
'dns.allTypes': '所有支持类型',
|
||||
'dns.query': '查询',
|
||||
'dns.queryUnavailable': '此后端当前无法执行 DNS 查询',
|
||||
'dns.typeUnsupported': '此后端不支持查询此记录类型',
|
||||
'dns.noTypes': '此后端未提供可查询的记录类型',
|
||||
'dns.hit': '缓存命中',
|
||||
'dns.miss': '缓存未命中',
|
||||
'dns.routeSource': '路由来源',
|
||||
@@ -344,6 +347,7 @@ export const messages = {
|
||||
'dns.expires': '到期时间',
|
||||
'dns.staleUntil': '过期后仍可用至',
|
||||
'dns.deleteEntry': '删除 {domain} 的 {type} 缓存项',
|
||||
'dns.deleteUnsupported': '此后端不支持删除缓存项',
|
||||
'dns.entries': '缓存项',
|
||||
'dns.viewCache': '查看缓存',
|
||||
'dns.log': '解析记录',
|
||||
@@ -374,6 +378,7 @@ export const messages = {
|
||||
'dns.flushConfirm': '将清除全部 {n} 条缓存项,无法撤销。',
|
||||
'dns.flushConfirmAll': '将清除全部缓存项,无法撤销。',
|
||||
'dns.flushAll': '清除全部缓存',
|
||||
'dns.flushUnsupported': '此后端不支持清除缓存',
|
||||
'dns.answer': '{name} {type};TTL {ttl} 秒;{data}',
|
||||
'event.export': '导出 JSON',
|
||||
'event.kind': '种类',
|
||||
|
||||
@@ -325,6 +325,9 @@ export const messages = {
|
||||
'dns.flushFailed': '無法清除快取:{error}',
|
||||
'dns.allTypes': '所有支援類型',
|
||||
'dns.query': '查詢',
|
||||
'dns.queryUnavailable': '此後端目前無法執行 DNS 查詢',
|
||||
'dns.typeUnsupported': '此後端不支援查詢此記錄類型',
|
||||
'dns.noTypes': '此後端未提供可查詢的記錄類型',
|
||||
'dns.hit': '快取命中',
|
||||
'dns.miss': '快取未命中',
|
||||
'dns.routeSource': '路由來源',
|
||||
@@ -343,6 +346,7 @@ export const messages = {
|
||||
'dns.expires': '到期時間',
|
||||
'dns.staleUntil': '過期後仍可用至',
|
||||
'dns.deleteEntry': '刪除 {domain} 的 {type} 快取項目',
|
||||
'dns.deleteUnsupported': '此後端不支援刪除快取項目',
|
||||
'dns.entries': '快取項目',
|
||||
'dns.viewCache': '查看快取',
|
||||
'dns.log': '解析記錄',
|
||||
@@ -373,6 +377,7 @@ export const messages = {
|
||||
'dns.flushConfirm': '將清除全部 {n} 筆快取項目,無法復原。',
|
||||
'dns.flushConfirmAll': '將清除全部快取項目,無法復原。',
|
||||
'dns.flushAll': '清除全部快取',
|
||||
'dns.flushUnsupported': '此後端不支援清除快取',
|
||||
'dns.answer': '{name} {type};TTL {ttl} 秒;{data}',
|
||||
'event.export': '匯出 JSON',
|
||||
'event.kind': '種類',
|
||||
|
||||
Reference in new issue
Block a user