mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-05 16:02:03 +00:00
fix(settings): say in view why settings actions are disabled
The profile actions wait for a saved profile, Apply for backend options names an out-of-range value or says nothing changed, Refresh says there is no subscription, and a geodata update says its status could not be read.
This commit is contained in:
1 parent
6f08e99b11
commit
4ae4e4965d
14 files changed
+168
-60
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import {useT} from '../../i18n';
|
||||
import {ActionGroup, Button, Card, ConfirmButton, DataTable, ErrorMessage, Loading, TextTooltip, TimeCell} from '../../ui/ui';
|
||||
import {ActionGroup, ActionHelp, Button, Card, ConfirmButton, DataTable, ErrorMessage, Loading, TextTooltip, TimeCell} from '../../ui/ui';
|
||||
import {useBackendActions} from './useBackendActions';
|
||||
import {settingsCard} from './nav';
|
||||
|
||||
@@ -14,6 +14,7 @@ export function BackendActionsCard() {
|
||||
closeAll,
|
||||
geodataBusy,
|
||||
geodataBlocked,
|
||||
geodataReason,
|
||||
geodataLoading,
|
||||
geodataError,
|
||||
retryGeodata,
|
||||
@@ -26,6 +27,7 @@ export function BackendActionsCard() {
|
||||
refreshingAll,
|
||||
refreshAll,
|
||||
refreshDisabled,
|
||||
refreshReason,
|
||||
refreshLabel,
|
||||
canFlush,
|
||||
canRefresh,
|
||||
@@ -67,11 +69,13 @@ export function BackendActionsCard() {
|
||||
<span className="rp-label">{t('nav.nodes')}</span>
|
||||
<ErrorMessage error={providersError} onRetry={retryProviders} />
|
||||
{/* Loading shows on the button itself: a spinner row would push the other groups down and back. */}
|
||||
<div className="rp-cluster">
|
||||
<Button isPending={refreshingAll || providersLoading} isDisabled={refreshingAll || refreshDisabled} onPress={() => void refreshAll()}>
|
||||
{refreshLabel}
|
||||
</Button>
|
||||
</div>
|
||||
<ActionHelp reason={refreshReason}>
|
||||
<div className="rp-cluster">
|
||||
<Button isPending={refreshingAll || providersLoading} isDisabled={refreshingAll || refreshDisabled} onPress={() => void refreshAll()}>
|
||||
{refreshLabel}
|
||||
</Button>
|
||||
</div>
|
||||
</ActionHelp>
|
||||
</div>
|
||||
)}
|
||||
{canClose && (
|
||||
@@ -88,13 +92,15 @@ export function BackendActionsCard() {
|
||||
<div className="rp-geodata">
|
||||
<div className="rp-ops-group">
|
||||
<span className="rp-label">{t('settings.geodata')}</span>
|
||||
<div className="rp-cluster">
|
||||
{canUpdate && (
|
||||
<Button isPending={geodataBusy} isDisabled={geodataBlocked} onPress={update}>
|
||||
{t('settings.geodataUpdate')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<ActionHelp reason={canUpdate ? geodataReason : null}>
|
||||
<div className="rp-cluster">
|
||||
{canUpdate && (
|
||||
<Button isPending={geodataBusy} isDisabled={geodataBlocked} onPress={update}>
|
||||
{t('settings.geodataUpdate')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</ActionHelp>
|
||||
</div>
|
||||
<span className="rp-label">{t('settings.geodataNote')}</span>
|
||||
<ErrorMessage error={geodataError} onRetry={retryGeodata} />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useT} from '../../i18n';
|
||||
import {Button, Card, ConfirmDialog, ContextualHelp, Disclosure, ErrorMessage, Kv, LabeledSelect, Loading, Switch, TextField} from '../../ui/ui';
|
||||
import {ActionHelp, Button, Card, ConfirmDialog, ContextualHelp, Disclosure, ErrorMessage, Kv, LabeledSelect, Loading, Switch, TextField} from '../../ui/ui';
|
||||
import ChevronDown from '../../ui/icons/ChevronDown';
|
||||
import {useGeodataSettings} from './useGeodataSettings';
|
||||
import {settingsCard} from './nav';
|
||||
@@ -91,17 +91,19 @@ export function GeodataSettingsCard() {
|
||||
</div>
|
||||
<div className="rp-ops-group">
|
||||
<span className="rp-label">{t('settings.geodataStatus')}</span>
|
||||
<div className="rp-cluster">
|
||||
<span role="status" className={m.status.error ? 'rp-geodata-note negative' : undefined}>
|
||||
{m.status.text}
|
||||
</span>
|
||||
{m.status.help && <ContextualHelp {...m.status.help} />}
|
||||
{m.canUpdate && (
|
||||
<Button isPending={m.updating} isDisabled={m.updateBlocked} onPress={m.update}>
|
||||
{t('settings.geodataUpdateNow')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<ActionHelp reason={m.canUpdate ? m.updateReason : null}>
|
||||
<div className="rp-cluster">
|
||||
<span role="status" className={m.status.error ? 'rp-geodata-note negative' : undefined}>
|
||||
{m.status.text}
|
||||
</span>
|
||||
{m.status.help && <ContextualHelp {...m.status.help} />}
|
||||
{m.canUpdate && (
|
||||
<Button isPending={m.updating} isDisabled={m.updateBlocked} onPress={m.update}>
|
||||
{t('settings.geodataUpdateNow')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</ActionHelp>
|
||||
</div>
|
||||
<ErrorMessage error={m.statusError} onRetry={m.retryStatus} />
|
||||
{m.status.details.length > 0 && (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useT} from '../../i18n';
|
||||
import {Button, Card, ErrorMessage, InlineAlert, LabeledSelect, Light, Loading, TextField} from '../../ui/ui';
|
||||
import {ActionHelp, Button, Card, ErrorMessage, InlineAlert, LabeledSelect, Light, Loading, TextField} from '../../ui/ui';
|
||||
import {useRuntimeSettingsForm} from './useRuntimeSettingsForm';
|
||||
import {settingsCard} from './nav';
|
||||
|
||||
@@ -73,16 +73,18 @@ export function RuntimeSettingsCard() {
|
||||
{m.recordingNote && <span className="rp-label">{m.recordingNote}</span>}
|
||||
</div>
|
||||
)}
|
||||
<div className="rp-toolbar">
|
||||
<Button accent isPending={m.busy} isDisabled={m.blocked} onPress={m.apply}>
|
||||
{t('settings.apply')}
|
||||
</Button>
|
||||
{m.dirty && (
|
||||
<Button isDisabled={m.busy} onPress={m.discard}>
|
||||
{t('config.discard')}
|
||||
<ActionHelp reason={m.reason}>
|
||||
<div className="rp-toolbar">
|
||||
<Button accent isPending={m.busy} isDisabled={m.blocked} onPress={m.apply}>
|
||||
{t('settings.apply')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{m.dirty && (
|
||||
<Button isDisabled={m.busy} onPress={m.discard}>
|
||||
{t('config.discard')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</ActionHelp>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useId} from 'react';
|
||||
import {LANGS, useT, type Lang} from '../../i18n';
|
||||
import {Button, Card, ChoiceMenu, ErrorMessage, LabeledSelect, Light, ConfirmDialog, Switch, TextField} from '../../ui/ui';
|
||||
import {ActionHelp, Button, Card, ChoiceMenu, ErrorMessage, LabeledSelect, Light, ConfirmDialog, Switch, TextField} from '../../ui/ui';
|
||||
import type {PaletteId, Scheme, ToastPlacement, Wordmark} from '../../shell/preferences';
|
||||
import {useSettingsPage} from './useSettingsPage';
|
||||
import {useSignOut} from './useSignOut';
|
||||
@@ -19,6 +19,7 @@ export function Settings({query}: PageProps) {
|
||||
const {
|
||||
activeId,
|
||||
hasActive,
|
||||
profileReason,
|
||||
firstRun,
|
||||
error,
|
||||
retry,
|
||||
@@ -70,28 +71,30 @@ export function Settings({query}: PageProps) {
|
||||
{paired && <p className="rp-note">{t('settings.paired')}</p>}
|
||||
<Card level={2} title={t(cards.backend.titleKey)} titleId={cards.backend.headingId}>
|
||||
<ErrorMessage error={error} onRetry={retry} />
|
||||
<div className="rp-toolbar">
|
||||
<LabeledSelect
|
||||
label={t('settings.profile')}
|
||||
side
|
||||
value={activeId}
|
||||
isDisabled={!hasActive || saving}
|
||||
items={profile.choices}
|
||||
onChange={switchProfile}
|
||||
/>
|
||||
<Button onPress={addProfile}>{t('settings.addProfile')}</Button>
|
||||
<Button isDisabled={!hasActive} onPress={renameProfile}>
|
||||
{t('settings.renameProfile')}
|
||||
</Button>
|
||||
<Button isDisabled={!hasActive} onPress={() => setDialog('delete')}>
|
||||
{t('settings.deleteProfile')}
|
||||
</Button>
|
||||
{session && (
|
||||
<Button isPending={session.busy} onPress={() => void session.signOut()}>
|
||||
{t('settings.signOut')}
|
||||
<ActionHelp reason={profileReason}>
|
||||
<div className="rp-toolbar">
|
||||
<LabeledSelect
|
||||
label={t('settings.profile')}
|
||||
side
|
||||
value={activeId}
|
||||
isDisabled={!hasActive || saving}
|
||||
items={profile.choices}
|
||||
onChange={switchProfile}
|
||||
/>
|
||||
<Button onPress={addProfile}>{t('settings.addProfile')}</Button>
|
||||
<Button isDisabled={!hasActive} onPress={renameProfile}>
|
||||
{t('settings.renameProfile')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Button isDisabled={!hasActive} onPress={() => setDialog('delete')}>
|
||||
{t('settings.deleteProfile')}
|
||||
</Button>
|
||||
{session && (
|
||||
<Button isPending={session.busy} onPress={() => void session.signOut()}>
|
||||
{t('settings.signOut')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</ActionHelp>
|
||||
<form
|
||||
className="rp-form"
|
||||
noValidate
|
||||
|
||||
@@ -10,6 +10,7 @@ export const messages = defineMessages({
|
||||
'settings.addProfile': '新增設定檔',
|
||||
'settings.renameProfile': '重新命名設定檔',
|
||||
'settings.deleteProfile': '刪除設定檔',
|
||||
'settings.noProfile': '尚無設定檔,儲存後端後即會建立',
|
||||
'settings.deleteProfileHelp': '刪除 {name}?此設定檔的後端網址與 Token 將從此瀏覽器移除。',
|
||||
'settings.switchProfileHelp': '切換設定檔會放棄尚未儲存的後端網址與 Token 修改;已儲存的設定檔保持不變。',
|
||||
'settings.profileDiscardHelp': '此操作會放棄尚未儲存的後端網址與 Token 修改。',
|
||||
@@ -82,6 +83,7 @@ export const messages = defineMessages({
|
||||
'settings.actionsNone': '此後端不提供任何操作',
|
||||
'settings.closeAllHelp': '關閉後端持有的全部連線(目前 {n} 條),包含此對話框開啟後建立的連線;核心直連的連線會略過。',
|
||||
'settings.refreshAll': '重新整理全部訂閱({n})',
|
||||
'settings.noSubscriptions': '沒有可重新整理的訂閱',
|
||||
'settings.refreshedAll': '已重新整理 {n} 筆訂閱,共 {total} 筆',
|
||||
'settings.refreshedDegraded': '節點已套用,但資料路徑未恢復,經使用者空間代理的新連線會被拒絕。詳見概覽頁。',
|
||||
'settings.refreshedAllFailed': '已重新整理 {n} 筆訂閱,共 {total} 筆;{failed} 筆失敗',
|
||||
@@ -131,6 +133,7 @@ export const messages = defineMessages({
|
||||
'settings.geodataSaveFailed': '無法儲存地理資料設定',
|
||||
'settings.geodataStatus': '狀態',
|
||||
'settings.geodataUpdateNow': '立即更新',
|
||||
'settings.geodataUnread': '無法讀取地理資料狀態,因此無法更新',
|
||||
'settings.geodataLastUpdated': '上次更新',
|
||||
'settings.geodataLastError': '上次錯誤',
|
||||
'settings.geodataNever': '從未',
|
||||
@@ -145,6 +148,7 @@ export const messages = defineMessages({
|
||||
'settings.apiMajor': '後端 API 主版本為 {major},本面板依 API 主版本 1 的契約實作;欄位可能不相容。',
|
||||
'settings.installFailed': '無法安裝',
|
||||
'settings.runtimeFailed': '無法套用後端選項',
|
||||
'settings.runtimeInvalid': '{field}須為所示範圍內的整數',
|
||||
'settings.refreshAllFailed': '無法重新整理訂閱',
|
||||
'settings.geodataFailed': '無法更新地理資料'
|
||||
},
|
||||
@@ -157,6 +161,7 @@ export const messages = defineMessages({
|
||||
'settings.addProfile': '新建连接方案',
|
||||
'settings.renameProfile': '重命名连接方案',
|
||||
'settings.deleteProfile': '删除连接方案',
|
||||
'settings.noProfile': '尚无连接方案,保存后端后即会创建',
|
||||
'settings.deleteProfileHelp': '删除 {name}?此连接方案的后端网址与 Token 将从此浏览器移除。',
|
||||
'settings.switchProfileHelp': '切换连接方案会放弃尚未保存的后端网址与 Token 修改;已保存的连接方案保持不变。',
|
||||
'settings.profileDiscardHelp': '此操作会放弃尚未保存的后端网址与 Token 修改。',
|
||||
@@ -229,6 +234,7 @@ export const messages = defineMessages({
|
||||
'settings.actionsNone': '此后端不提供任何操作',
|
||||
'settings.closeAllHelp': '关闭后端持有的全部连接(当前 {n} 条),包括此对话框打开后建立的连接;内核直连的连接会跳过。',
|
||||
'settings.refreshAll': '刷新全部订阅({n})',
|
||||
'settings.noSubscriptions': '没有可刷新的订阅',
|
||||
'settings.refreshedAll': '已刷新 {n} 条订阅,共 {total} 条',
|
||||
'settings.refreshedDegraded': '节点已应用,但数据路径未恢复,经用户空间代理的新连接会被拒绝。详见概览页。',
|
||||
'settings.refreshedAllFailed': '已刷新 {n} 条订阅,共 {total} 条;{failed} 条失败',
|
||||
@@ -278,6 +284,7 @@ export const messages = defineMessages({
|
||||
'settings.geodataSaveFailed': '无法保存地理数据设置',
|
||||
'settings.geodataStatus': '状态',
|
||||
'settings.geodataUpdateNow': '立即更新',
|
||||
'settings.geodataUnread': '无法读取地理数据状态,因此无法更新',
|
||||
'settings.geodataLastUpdated': '上次更新',
|
||||
'settings.geodataLastError': '上次错误',
|
||||
'settings.geodataNever': '从未',
|
||||
@@ -292,6 +299,7 @@ export const messages = defineMessages({
|
||||
'settings.apiMajor': '后端 API 主版本为 {major},本面板按 API 主版本 1 的契约实现;字段可能不兼容。',
|
||||
'settings.installFailed': '无法安装',
|
||||
'settings.runtimeFailed': '无法应用后端选项',
|
||||
'settings.runtimeInvalid': '{field}须为所示范围内的整数',
|
||||
'settings.refreshAllFailed': '无法刷新订阅',
|
||||
'settings.geodataFailed': '无法更新地理数据'
|
||||
},
|
||||
@@ -304,6 +312,7 @@ export const messages = defineMessages({
|
||||
'settings.addProfile': 'Add profile',
|
||||
'settings.renameProfile': 'Rename profile',
|
||||
'settings.deleteProfile': 'Delete profile',
|
||||
'settings.noProfile': 'No profile yet; saving the backend creates one',
|
||||
'settings.deleteProfileHelp': 'Delete {name}? Its backend URL and token will be removed from this browser.',
|
||||
'settings.switchProfileHelp': 'Switching profiles discards unsaved backend URL and token changes. Saved profiles remain unchanged.',
|
||||
'settings.profileDiscardHelp': 'This discards unsaved backend URL and token changes.',
|
||||
@@ -379,6 +388,7 @@ export const messages = defineMessages({
|
||||
'settings.closeAllHelp':
|
||||
'Closes every connection the backend owns ({n} right now), including ones opened after this dialog; kernel-direct connections are skipped.',
|
||||
'settings.refreshAll': {one: 'Refresh subscription ({n})', other: 'Refresh all subscriptions ({n})'},
|
||||
'settings.noSubscriptions': 'No subscriptions to refresh',
|
||||
'settings.refreshedAll': 'Subscriptions refreshed: {n} of {total}',
|
||||
'settings.refreshedDegraded':
|
||||
'Nodes applied, but the datapath did not recover, so new connections proxied through userspace are refused. See Overview for details.',
|
||||
@@ -430,6 +440,7 @@ export const messages = defineMessages({
|
||||
'settings.geodataSaveFailed': 'Could not save the geodata settings',
|
||||
'settings.geodataStatus': 'Status',
|
||||
'settings.geodataUpdateNow': 'Update now',
|
||||
'settings.geodataUnread': 'The geodata status could not be read, so it cannot be updated',
|
||||
'settings.geodataLastUpdated': 'Last updated',
|
||||
'settings.geodataLastError': 'Last error',
|
||||
'settings.geodataNever': 'Never',
|
||||
@@ -445,6 +456,7 @@ export const messages = defineMessages({
|
||||
'settings.apiMajor': 'The backend uses API major version {major}. This panel implements the contract for major version 1, so fields may be incompatible.',
|
||||
'settings.installFailed': 'Could not install',
|
||||
'settings.runtimeFailed': 'Could not apply backend options',
|
||||
'settings.runtimeInvalid': '{field} must be a whole number within the range shown',
|
||||
'settings.refreshAllFailed': 'Could not refresh subscriptions',
|
||||
'settings.geodataFailed': 'Could not update geodata'
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import {useLifecycle} from '../shared/useLifecycle';
|
||||
import {closedAllTone} from '../../api/selectors';
|
||||
import {LOCALE, useLang, useT} from '../../i18n';
|
||||
import {toast} from '../../ui/ui';
|
||||
import {geodataRows} from './view';
|
||||
import {geodataRows, geodataUpdateReason, refreshAllReason} from './view';
|
||||
import {geodataConfigurable} from './nav';
|
||||
import {errorText} from '../../api/error';
|
||||
import {offered} from '../../api/capabilities';
|
||||
@@ -91,6 +91,7 @@ export function useBackendActions() {
|
||||
},
|
||||
geodataBusy: geodata.busy,
|
||||
geodataBlocked: geodata.busy || !geodata.data,
|
||||
geodataReason: geodataUpdateReason({busy: geodata.busy, loaded: !!geodata.data, failed: !!geodata.error}, t),
|
||||
geodataLoading: geodata.loading && !geodata.data,
|
||||
geodataError: geodata.error,
|
||||
retryGeodata: geodata.refetch,
|
||||
@@ -105,6 +106,7 @@ export function useBackendActions() {
|
||||
refreshingAll,
|
||||
refreshAll,
|
||||
refreshDisabled: !providersReady || !!refresh.busy || !subscriptions.length,
|
||||
refreshReason: refreshAllReason({ready: providersReady, busy: !!refresh.busy, count: subscriptions.length}, t),
|
||||
refreshLabel: t('settings.refreshAll', {n: providersReady ? subscriptions.length : '—'}),
|
||||
canFlush: !!(resources?.dns_cache.available && resources.dns_cache.flush),
|
||||
canRefresh: !!resources?.providers.can_refresh,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {toast, toastFailure} from '../../ui/ui';
|
||||
import {errorText} from '../../api/error';
|
||||
import {geodataPresets, type GeodataPreset, type GeodataPresetId} from '../../dae/geodata';
|
||||
import {geodataConfigurable} from './nav';
|
||||
import {geodataUpdateReason} from './view';
|
||||
import {
|
||||
assetDetails,
|
||||
cleanUrls,
|
||||
@@ -227,6 +228,7 @@ export function useGeodataSettings() {
|
||||
canUpdate,
|
||||
updating: geodata.busy,
|
||||
updateBlocked: busy || !geodata.data,
|
||||
updateReason: geodataUpdateReason({busy, loaded: !!geodata.data, failed: !!geodata.error}, t),
|
||||
update: () => void update()
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
recorderPatchValue,
|
||||
recorderView,
|
||||
recordingNote,
|
||||
runtimeApplyReason,
|
||||
type Numeric,
|
||||
type Recorder,
|
||||
type RecorderChoice
|
||||
@@ -112,6 +113,7 @@ export function useRuntimeSettingsForm() {
|
||||
},
|
||||
dirty,
|
||||
blocked: !Object.keys(patch).length || numeric.some(field => field.invalid),
|
||||
reason: runtimeApplyReason({busy: settings.busy, invalid: numeric.find(field => field.invalid)?.label ?? null, changed: Object.keys(patch).length > 0}, t),
|
||||
apply
|
||||
};
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import {useT} from '../../i18n';
|
||||
import {toast} from '../../ui/ui';
|
||||
import {SettingsContext} from '../../shell/preferences';
|
||||
import {useBackendForm} from './useBackendForm';
|
||||
import {profileView, paletteLabel} from './view';
|
||||
import {profileView, profileReason, paletteLabel} from './view';
|
||||
import {installHint, useInstallOffer} from '../../shell/install';
|
||||
export function useSettingsPage(query: string) {
|
||||
const t = useT();
|
||||
@@ -38,6 +38,7 @@ export function useSettingsPage(query: string) {
|
||||
firstRun: form.saved.api === null,
|
||||
activeId: form.saved.activeId,
|
||||
hasActive: !!form.active,
|
||||
profileReason: profileReason(!!form.active, t),
|
||||
invalidText: form.invalid ? t('settings.invalidUrl') : undefined,
|
||||
tokenType: showToken ? 'text' : 'password',
|
||||
tokenToggleText: t(showToken ? 'settings.hideToken' : 'settings.showToken'),
|
||||
|
||||
@@ -2,7 +2,21 @@ import {expect, it} from 'vitest';
|
||||
import {geodata, runtimeSettings} from '../../api/mock/fixtures';
|
||||
import type {RuntimeSettingsPatch} from '../../api/model';
|
||||
import {translate, type Translator} from '../../i18n';
|
||||
import {numericAccess, numericFieldView, geodataRows, probeFailure, profileView, paletteLabel, recorderView, recorderPatchValue, recordingNote} from './view';
|
||||
import {
|
||||
geodataRows,
|
||||
geodataUpdateReason,
|
||||
numericAccess,
|
||||
numericFieldView,
|
||||
paletteLabel,
|
||||
probeFailure,
|
||||
profileReason,
|
||||
profileView,
|
||||
recorderPatchValue,
|
||||
recorderView,
|
||||
recordingNote,
|
||||
refreshAllReason,
|
||||
runtimeApplyReason
|
||||
} from './view';
|
||||
import {ApiError} from '../../api/error';
|
||||
const t: Translator = (key, params) => translate('en', key, params);
|
||||
it('validates numeric bounds and writes typed partial patches without losing sibling edits', () => {
|
||||
@@ -71,3 +85,30 @@ it('names why a connection test failed and ignores a cancelled test', () => {
|
||||
expect(probeFailure(new TypeError('Failed to fetch'), idle, base, origin)).toEqual({key: 'settings.cors'});
|
||||
expect(probeFailure(new TypeError('Failed to fetch'), idle, base, 'https://router.example')).toEqual({key: 'settings.network'});
|
||||
});
|
||||
|
||||
it('says the profile actions wait for a saved profile', () => {
|
||||
expect(profileReason(false, t)).toBe('No profile yet; saving the backend creates one');
|
||||
expect(profileReason(true, t)).toBeNull();
|
||||
});
|
||||
|
||||
it('says why Apply for backend options is disabled: a value out of range first, then no change', () => {
|
||||
const idle = {busy: false, invalid: null, changed: true};
|
||||
expect(runtimeApplyReason(idle, t)).toBeNull();
|
||||
expect(runtimeApplyReason({...idle, changed: false}, t)).toBe('No changes to apply');
|
||||
expect(runtimeApplyReason({...idle, changed: false, invalid: 'Flow table size'}, t)).toBe('Flow table size must be a whole number within the range shown');
|
||||
expect(runtimeApplyReason({busy: true, invalid: 'x', changed: false}, t)).toBeNull();
|
||||
});
|
||||
|
||||
it('says why refreshing every subscription is disabled only once the list is read and empty', () => {
|
||||
expect(refreshAllReason({ready: true, busy: false, count: 0}, t)).toBe('No subscriptions to refresh');
|
||||
expect(refreshAllReason({ready: false, busy: false, count: 0}, t)).toBeNull();
|
||||
expect(refreshAllReason({ready: true, busy: true, count: 0}, t)).toBeNull();
|
||||
expect(refreshAllReason({ready: true, busy: false, count: 2}, t)).toBeNull();
|
||||
});
|
||||
|
||||
it('says a geodata update needs its status, and nothing while it loads', () => {
|
||||
expect(geodataUpdateReason({busy: false, loaded: false, failed: true}, t)).toBe('The geodata status could not be read, so it cannot be updated');
|
||||
expect(geodataUpdateReason({busy: false, loaded: false, failed: false}, t)).toBeNull();
|
||||
expect(geodataUpdateReason({busy: true, loaded: false, failed: true}, t)).toBeNull();
|
||||
expect(geodataUpdateReason({busy: false, loaded: true, failed: true}, t)).toBeNull();
|
||||
});
|
||||
@@ -115,6 +115,29 @@ export function profileView(
|
||||
: null
|
||||
};
|
||||
}
|
||||
// Why the profile select, Rename and Delete are disabled: nothing is saved yet to act on.
|
||||
export function profileReason(hasActive: boolean, t: Translator): string | null {
|
||||
return hasActive ? null : t('settings.noProfile');
|
||||
}
|
||||
|
||||
// Why Apply for backend options is disabled, first applicable: a value out of range, then nothing changed. Null while
|
||||
// the options are being applied.
|
||||
export function runtimeApplyReason({busy, invalid, changed}: {busy: boolean; invalid: string | null; changed: boolean}, t: Translator): string | null {
|
||||
if (busy) return null;
|
||||
if (invalid) return t('settings.runtimeInvalid', {field: invalid});
|
||||
return changed ? null : t('config.noChanges');
|
||||
}
|
||||
|
||||
// Why refreshing every subscription is disabled: there is none. Null while the list loads or a refresh runs.
|
||||
export function refreshAllReason({ready, busy, count}: {ready: boolean; busy: boolean; count: number}, t: Translator): string | null {
|
||||
return ready && !busy && !count ? t('settings.noSubscriptions') : null;
|
||||
}
|
||||
|
||||
// Why a geodata update is disabled: its status could not be read. Null while it loads or another change runs.
|
||||
export function geodataUpdateReason({busy, loaded, failed}: {busy: boolean; loaded: boolean; failed: boolean}, t: Translator): string | null {
|
||||
return !busy && !loaded && failed ? t('settings.geodataUnread') : null;
|
||||
}
|
||||
|
||||
export function paletteLabel(sections: Array<{items: Array<{id: string; label: string}>}>, id: string) {
|
||||
return sections.flatMap(section => section.items).find(item => item.id === id)?.label ?? id;
|
||||
}
|
||||
|
||||
@@ -1082,6 +1082,7 @@ export const messages = {
|
||||
'settings.addProfile': 'Add profile',
|
||||
'settings.renameProfile': 'Rename profile',
|
||||
'settings.deleteProfile': 'Delete profile',
|
||||
'settings.noProfile': 'No profile yet; saving the backend creates one',
|
||||
'settings.deleteProfileHelp': 'Delete {name}? Its backend URL and token will be removed from this browser.',
|
||||
'settings.switchProfileHelp': 'Switching profiles discards unsaved backend URL and token changes. Saved profiles remain unchanged.',
|
||||
'settings.profileDiscardHelp': 'This discards unsaved backend URL and token changes.',
|
||||
@@ -1156,6 +1157,7 @@ export const messages = {
|
||||
'settings.closeAllHelp':
|
||||
'Closes every connection the backend owns ({n} right now), including ones opened after this dialog; kernel-direct connections are skipped.',
|
||||
'settings.refreshAll': {one: 'Refresh subscription ({n})', other: 'Refresh all subscriptions ({n})'},
|
||||
'settings.noSubscriptions': 'No subscriptions to refresh',
|
||||
'settings.refreshedAll': 'Subscriptions refreshed: {n} of {total}',
|
||||
'settings.refreshedDegraded':
|
||||
'Nodes applied, but the datapath did not recover, so new connections proxied through userspace are refused. See Overview for details.',
|
||||
@@ -1207,6 +1209,7 @@ export const messages = {
|
||||
'settings.geodataSaveFailed': 'Could not save the geodata settings',
|
||||
'settings.geodataStatus': 'Status',
|
||||
'settings.geodataUpdateNow': 'Update now',
|
||||
'settings.geodataUnread': 'The geodata status could not be read, so it cannot be updated',
|
||||
'settings.geodataLastUpdated': 'Last updated',
|
||||
'settings.geodataLastError': 'Last error',
|
||||
'settings.geodataNever': 'Never',
|
||||
@@ -1222,6 +1225,7 @@ export const messages = {
|
||||
'settings.apiMajor': 'The backend uses API major version {major}. This panel implements the contract for major version 1, so fields may be incompatible.',
|
||||
'settings.installFailed': 'Could not install',
|
||||
'settings.runtimeFailed': 'Could not apply backend options',
|
||||
'settings.runtimeInvalid': '{field} must be a whole number within the range shown',
|
||||
'settings.refreshAllFailed': 'Could not refresh subscriptions',
|
||||
'settings.geodataFailed': 'Could not update geodata',
|
||||
'shell.langUnavailable': 'Could not switch to {name}: the interface text did not load.',
|
||||
|
||||
@@ -1044,6 +1044,7 @@ export const messages = {
|
||||
'settings.addProfile': '新建连接方案',
|
||||
'settings.renameProfile': '重命名连接方案',
|
||||
'settings.deleteProfile': '删除连接方案',
|
||||
'settings.noProfile': '尚无连接方案,保存后端后即会创建',
|
||||
'settings.deleteProfileHelp': '删除 {name}?此连接方案的后端网址与 Token 将从此浏览器移除。',
|
||||
'settings.switchProfileHelp': '切换连接方案会放弃尚未保存的后端网址与 Token 修改;已保存的连接方案保持不变。',
|
||||
'settings.profileDiscardHelp': '此操作会放弃尚未保存的后端网址与 Token 修改。',
|
||||
@@ -1116,6 +1117,7 @@ export const messages = {
|
||||
'settings.actionsNone': '此后端不提供任何操作',
|
||||
'settings.closeAllHelp': '关闭后端持有的全部连接(当前 {n} 条),包括此对话框打开后建立的连接;内核直连的连接会跳过。',
|
||||
'settings.refreshAll': '刷新全部订阅({n})',
|
||||
'settings.noSubscriptions': '没有可刷新的订阅',
|
||||
'settings.refreshedAll': '已刷新 {n} 条订阅,共 {total} 条',
|
||||
'settings.refreshedDegraded': '节点已应用,但数据路径未恢复,经用户空间代理的新连接会被拒绝。详见概览页。',
|
||||
'settings.refreshedAllFailed': '已刷新 {n} 条订阅,共 {total} 条;{failed} 条失败',
|
||||
@@ -1165,6 +1167,7 @@ export const messages = {
|
||||
'settings.geodataSaveFailed': '无法保存地理数据设置',
|
||||
'settings.geodataStatus': '状态',
|
||||
'settings.geodataUpdateNow': '立即更新',
|
||||
'settings.geodataUnread': '无法读取地理数据状态,因此无法更新',
|
||||
'settings.geodataLastUpdated': '上次更新',
|
||||
'settings.geodataLastError': '上次错误',
|
||||
'settings.geodataNever': '从未',
|
||||
@@ -1179,6 +1182,7 @@ export const messages = {
|
||||
'settings.apiMajor': '后端 API 主版本为 {major},本面板按 API 主版本 1 的契约实现;字段可能不兼容。',
|
||||
'settings.installFailed': '无法安装',
|
||||
'settings.runtimeFailed': '无法应用后端选项',
|
||||
'settings.runtimeInvalid': '{field}须为所示范围内的整数',
|
||||
'settings.refreshAllFailed': '无法刷新订阅',
|
||||
'settings.geodataFailed': '无法更新地理数据',
|
||||
'shell.langUnavailable': '无法切换至{name}:界面文字加载失败。',
|
||||
|
||||
@@ -1044,6 +1044,7 @@ export const messages = {
|
||||
'settings.addProfile': '新增設定檔',
|
||||
'settings.renameProfile': '重新命名設定檔',
|
||||
'settings.deleteProfile': '刪除設定檔',
|
||||
'settings.noProfile': '尚無設定檔,儲存後端後即會建立',
|
||||
'settings.deleteProfileHelp': '刪除 {name}?此設定檔的後端網址與 Token 將從此瀏覽器移除。',
|
||||
'settings.switchProfileHelp': '切換設定檔會放棄尚未儲存的後端網址與 Token 修改;已儲存的設定檔保持不變。',
|
||||
'settings.profileDiscardHelp': '此操作會放棄尚未儲存的後端網址與 Token 修改。',
|
||||
@@ -1116,6 +1117,7 @@ export const messages = {
|
||||
'settings.actionsNone': '此後端不提供任何操作',
|
||||
'settings.closeAllHelp': '關閉後端持有的全部連線(目前 {n} 條),包含此對話框開啟後建立的連線;核心直連的連線會略過。',
|
||||
'settings.refreshAll': '重新整理全部訂閱({n})',
|
||||
'settings.noSubscriptions': '沒有可重新整理的訂閱',
|
||||
'settings.refreshedAll': '已重新整理 {n} 筆訂閱,共 {total} 筆',
|
||||
'settings.refreshedDegraded': '節點已套用,但資料路徑未恢復,經使用者空間代理的新連線會被拒絕。詳見概覽頁。',
|
||||
'settings.refreshedAllFailed': '已重新整理 {n} 筆訂閱,共 {total} 筆;{failed} 筆失敗',
|
||||
@@ -1165,6 +1167,7 @@ export const messages = {
|
||||
'settings.geodataSaveFailed': '無法儲存地理資料設定',
|
||||
'settings.geodataStatus': '狀態',
|
||||
'settings.geodataUpdateNow': '立即更新',
|
||||
'settings.geodataUnread': '無法讀取地理資料狀態,因此無法更新',
|
||||
'settings.geodataLastUpdated': '上次更新',
|
||||
'settings.geodataLastError': '上次錯誤',
|
||||
'settings.geodataNever': '從未',
|
||||
@@ -1179,6 +1182,7 @@ export const messages = {
|
||||
'settings.apiMajor': '後端 API 主版本為 {major},本面板依 API 主版本 1 的契約實作;欄位可能不相容。',
|
||||
'settings.installFailed': '無法安裝',
|
||||
'settings.runtimeFailed': '無法套用後端選項',
|
||||
'settings.runtimeInvalid': '{field}須為所示範圍內的整數',
|
||||
'settings.refreshAllFailed': '無法重新整理訂閱',
|
||||
'settings.geodataFailed': '無法更新地理資料',
|
||||
'shell.guide': '安裝指南',
|
||||
|
||||
Reference in new issue
Block a user