From 4ae4e4965d9155d4203a42ca4bd61dadf97e655a Mon Sep 17 00:00:00 2001 From: Zakk Date: Mon, 28 Sep 2026 06:33:50 +1000 Subject: [PATCH] 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. --- src/features/settings/BackendActions.tsx | 32 ++++++++----- src/features/settings/GeodataSettings.tsx | 26 +++++----- src/features/settings/RuntimeSettings.tsx | 22 +++++---- src/features/settings/Settings.tsx | 47 ++++++++++--------- src/features/settings/messages.ts | 12 +++++ src/features/settings/useBackendActions.ts | 4 +- src/features/settings/useGeodataSettings.ts | 2 + .../settings/useRuntimeSettingsForm.ts | 2 + src/features/settings/useSettingsPage.ts | 3 +- src/features/settings/view.test.ts | 43 ++++++++++++++++- src/features/settings/view.ts | 23 +++++++++ src/i18n/locales/en.ts | 4 ++ src/i18n/locales/zh-CN.ts | 4 ++ src/i18n/locales/zh-TW.ts | 4 ++ 14 files changed, 168 insertions(+), 60 deletions(-) diff --git a/src/features/settings/BackendActions.tsx b/src/features/settings/BackendActions.tsx index 9d1f725b..74de3684 100644 --- a/src/features/settings/BackendActions.tsx +++ b/src/features/settings/BackendActions.tsx @@ -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() { {t('nav.nodes')} {/* Loading shows on the button itself: a spinner row would push the other groups down and back. */} -
- -
+ +
+ +
+
)} {canClose && ( @@ -88,13 +92,15 @@ export function BackendActionsCard() {
{t('settings.geodata')} -
- {canUpdate && ( - - )} -
+ +
+ {canUpdate && ( + + )} +
+
{t('settings.geodataNote')} diff --git a/src/features/settings/GeodataSettings.tsx b/src/features/settings/GeodataSettings.tsx index 810b7dc2..a0d62c2a 100644 --- a/src/features/settings/GeodataSettings.tsx +++ b/src/features/settings/GeodataSettings.tsx @@ -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() {
{t('settings.geodataStatus')} -
- - {m.status.text} - - {m.status.help && } - {m.canUpdate && ( - - )} -
+ +
+ + {m.status.text} + + {m.status.help && } + {m.canUpdate && ( + + )} +
+
{m.status.details.length > 0 && ( diff --git a/src/features/settings/RuntimeSettings.tsx b/src/features/settings/RuntimeSettings.tsx index 03bf0948..76fd9138 100644 --- a/src/features/settings/RuntimeSettings.tsx +++ b/src/features/settings/RuntimeSettings.tsx @@ -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 && {m.recordingNote}} )} -
- - {m.dirty && ( - - )} -
+ {m.dirty && ( + + )} + + )} diff --git a/src/features/settings/Settings.tsx b/src/features/settings/Settings.tsx index b147097b..4d5c10f2 100644 --- a/src/features/settings/Settings.tsx +++ b/src/features/settings/Settings.tsx @@ -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 &&

{t('settings.paired')}

} -
- - - - - {session && ( - + - )} -
+ + {session && ( + + )} + +
void update() }; } diff --git a/src/features/settings/useRuntimeSettingsForm.ts b/src/features/settings/useRuntimeSettingsForm.ts index bb461afb..8cdcd727 100644 --- a/src/features/settings/useRuntimeSettingsForm.ts +++ b/src/features/settings/useRuntimeSettingsForm.ts @@ -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 }; } diff --git a/src/features/settings/useSettingsPage.ts b/src/features/settings/useSettingsPage.ts index 56283fc9..2b690202 100644 --- a/src/features/settings/useSettingsPage.ts +++ b/src/features/settings/useSettingsPage.ts @@ -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'), diff --git a/src/features/settings/view.test.ts b/src/features/settings/view.test.ts index cd09b2c6..21a0bc36 100644 --- a/src/features/settings/view.test.ts +++ b/src/features/settings/view.test.ts @@ -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(); +}); diff --git a/src/features/settings/view.ts b/src/features/settings/view.ts index 73761e12..8f7e104f 100644 --- a/src/features/settings/view.ts +++ b/src/features/settings/view.ts @@ -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; } diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index e19e84eb..6df489b3 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -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.', diff --git a/src/i18n/locales/zh-CN.ts b/src/i18n/locales/zh-CN.ts index d116416b..28540744 100644 --- a/src/i18n/locales/zh-CN.ts +++ b/src/i18n/locales/zh-CN.ts @@ -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}:界面文字加载失败。', diff --git a/src/i18n/locales/zh-TW.ts b/src/i18n/locales/zh-TW.ts index 9f6693bf..c18d976e 100644 --- a/src/i18n/locales/zh-TW.ts +++ b/src/i18n/locales/zh-TW.ts @@ -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': '安裝指南',