diff --git a/.changeset/37480-settings-retired-option.md b/.changeset/37480-settings-retired-option.md new file mode 100644 index 00000000000..8994b1d76b9 --- /dev/null +++ b/.changeset/37480-settings-retired-option.md @@ -0,0 +1,13 @@ +--- +'@object-ui/console': patch +'@object-ui/i18n': patch +--- + +fix(console): a stored settings select, radio or multiselect value the setting no longer offers reads as "no longer available" instead of nothing chosen + +Clause-②: no +Metadata-protocol: none + +When a settings select's stored value is not among the options the setting declares today (an option removed in a later release, such as the knowledge adapter `ragflow`), the Setup select showed an empty box: no label and no placeholder. It now shows the stored code with a mark, for example "ragflow (no longer available)", as one disabled entry in the list. A radio group shows the same text as one checked, disabled item. A multiselect shows each stored member outside the options as a checked checkbox with the same text: ticking a current option keeps the member in the saved list, as before (and the server still refuses a save of that list while it holds one); unticking it removes it, and it cannot be ticked back. The admin can still pick a current option, which saves as before; the retired entry cannot be picked back. Values among the options, and an unset value, render as before. + +New locale key: `console.settingsView.selectValueRetired` (`{{value}}` is the stored code), in all eleven Console language packs. No props or exports change. diff --git a/content/docs/protocol/kernel/config-resolution.mdx b/content/docs/protocol/kernel/config-resolution.mdx index 2d2ac9e1618..2f7f1d1ef91 100644 --- a/content/docs/protocol/kernel/config-resolution.mdx +++ b/content/docs/protocol/kernel/config-resolution.mdx @@ -341,6 +341,17 @@ monotonic `version` so `rotateKey()` can re-wrap under a new key; the audit trai records the rotation. ObjectStack bundles no cloud provider implementation — see [Outside this contract](#outside-this-contract). +### Retired keys and options + +When a release removes a key or a select option from a manifest, rows already +stored for it are kept, unused, and never deleted by the platform; an encrypted +key's `sys_secret` row stays too. A stored value that is no longer an option +shows in Setup as "no longer available" until an admin picks a current one. No +settings door writes a removed key (`400 UNKNOWN_KEY`), so remove its rows by +hand: delete the key's row (namespace and key) from `sys_platform_setting` for a +`global`-scope manifest, or from `sys_setting` otherwise, and for an encrypted +key also the `sys_secret` row whose id that row holds in `value_enc`. + ## HTTP Surface `registerSettingsRoutes()` mounts the resolver under `/api/settings` diff --git a/ui/apps/console/src/pages/settings/SettingsField.tsx b/ui/apps/console/src/pages/settings/SettingsField.tsx index 264177c1a11..cc8b6f7a7fc 100644 --- a/ui/apps/console/src/pages/settings/SettingsField.tsx +++ b/ui/apps/console/src/pages/settings/SettingsField.tsx @@ -974,6 +974,14 @@ export function SettingsField(props: SettingsFieldProps) { />, ); } + // A stored value the manifest no longer offers (an option removed in a + // later release) has no item to name it, so the trigger would read + // blank. It gets one disabled item of its own, named with the stored + // code and a "no longer available" mark; picking a current option is + // an ordinary write, and the retired item cannot be picked back. + const stored = value == null ? '' : String(value); + const retired = + stored !== '' && !(spec.options ?? []).some((opt) => String(opt.value) === stored); return wrapper( , ); } - case 'radio': + case 'radio': { + // Same named state as the closed select above: a stored value the + // manifest no longer offers gets one disabled, checked item of its own, + // so the group does not read as nothing chosen. + const stored = value == null ? '' : String(value); + const retired = + stored !== '' && !(spec.options ?? []).some((opt) => String(opt.value) === stored); return wrapper( + {retired ? ( +
+ + +
+ ) : null} {spec.options?.map((opt) => (
@@ -1015,10 +1048,42 @@ export function SettingsField(props: SettingsFieldProps) { , undefined, ); + } case 'multiselect': { const arr = Array.isArray(value) ? (value as (string | number)[]) : []; + // Stored members the manifest no longer offers are named, checked, in + // the same "no longer available" words as the select and radio arms. + // Ticking a current option keeps them in the array (the next set is + // built from the whole stored array, as before), and the server refuses + // a write of this key while one is in it (`invalid_option`), so each + // stays UNTICKABLE: unticking drops it, and once dropped it is gone + // from the list, so it cannot be ticked back. + const offered = new Set((spec.options ?? []).map((opt) => String(opt.value))); + const retiredMembers = Array.from(new Set(arr.map(String))).filter( + (v) => v !== '' && !offered.has(v), + ); return wrapper(
+ {retiredMembers.map((v) => ( + + ))} {spec.options?.map((opt) => { const v = String(opt.value); const checked = arr.map(String).includes(v); diff --git a/ui/apps/console/src/pages/settings/__tests__/SettingsField.retiredOption-37480.test.tsx b/ui/apps/console/src/pages/settings/__tests__/SettingsField.retiredOption-37480.test.tsx new file mode 100644 index 00000000000..eff5a368df9 --- /dev/null +++ b/ui/apps/console/src/pages/settings/__tests__/SettingsField.retiredOption-37480.test.tsx @@ -0,0 +1,171 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * SettingsField — a closed `select` whose stored value is no longer among the + * manifest's `options` names that value as "no longer available" + * (objectstack#37480). + * + * An option removed in a later release (the knowledge adapter `ragflow`) left + * an environment that had saved it with a blank trigger: no label and no + * placeholder, because Radix shows the selected item's text and no item carried + * the stored code. The select now adds one disabled item for that code, so the + * trigger reads the code with the locale's "no longer available" mark, and the + * admin can still pick a current option. + */ + +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, cleanup, fireEvent } from '@testing-library/react'; +import { createI18n, I18nProvider } from '@object-ui/i18n'; + +import { SettingsField } from '../SettingsField'; +import type { Specifier } from '../types'; + +afterEach(cleanup); + +/** A closed select: exhaustive `options`, no `valueDomain`. */ +const ADAPTER: Specifier = { + type: 'select', + key: 'adapter', + label: 'Adapter', + options: [ + { value: 'builtin', label: 'Built-in' }, + { value: 'dify', label: 'Dify' }, + ], +}; + +function renderIn(language: string, value: unknown) { + const instance = createI18n({ defaultLanguage: language, detectBrowserLanguage: false }); + render( + + + , + ); + return instance; +} + +describe('objectstack#37480 — a stored select value outside the current options is named', () => { + it('under en, the trigger reads the stored code marked "no longer available"', () => { + const en = renderIn('en', 'ragflow'); + const named = en.t('console.settingsView.selectValueRetired', { value: 'ragflow' }); + + // The key resolves in the en pack (not the raw key, not the bare code). + expect(named).toBe('ragflow (no longer available)'); + expect(screen.getByRole('combobox')).toHaveTextContent(named); + expect(screen.getByRole('combobox')).not.toHaveTextContent(en.t('common.select')); + }); + + it('under zh-CN, the mark is the zh pack\'s text, not the en words', () => { + const zh = renderIn('zh-CN', 'ragflow'); + const zhText = zh.t('console.settingsView.selectValueRetired', { value: 'ragflow' }); + const enText = zh.getFixedT('en')('console.settingsView.selectValueRetired', { value: 'ragflow' }); + + expect(zhText).not.toBe(enText); + expect(zhText).toContain('ragflow'); + expect(screen.getByRole('combobox')).toHaveTextContent(zhText); + }); + + it('CONTROL — a stored value among the options renders its label, with no retired mark', () => { + const en = renderIn('en', 'dify'); + const combobox = screen.getByRole('combobox'); + expect(combobox).toHaveTextContent('Dify'); + expect(combobox).not.toHaveTextContent( + en.t('console.settingsView.selectValueRetired', { value: 'dify' }), + ); + expect(screen.queryByTestId('settings-select-retired')).toBeNull(); + }); + + it('CONTROL — no stored value still shows the placeholder, with no retired mark', () => { + const en = renderIn('en', undefined); + expect(screen.getByRole('combobox')).toHaveTextContent(en.t('common.select')); + expect(screen.queryByTestId('settings-select-retired')).toBeNull(); + }); +}); + +/** The same options drawn as a radio group. */ +const ADAPTER_RADIO: Specifier = { ...ADAPTER, type: 'radio' }; + +function renderRadioIn(language: string, value: unknown) { + const instance = createI18n({ defaultLanguage: language, detectBrowserLanguage: false }); + render( + + + , + ); + return instance; +} + +describe('objectstack#37480 — a stored radio value outside the current options is named', () => { + it('the group shows a checked, disabled item reading the stored code marked "no longer available"', () => { + const en = renderRadioIn('en', 'ragflow'); + const named = en.t('console.settingsView.selectValueRetired', { value: 'ragflow' }); + + const item = screen.getByRole('radio', { name: named }); + expect(item).toBeChecked(); + expect(item).toBeDisabled(); + // The current options stay pickable and unchecked. + expect(screen.getByRole('radio', { name: 'Dify' })).not.toBeChecked(); + expect(screen.getByRole('radio', { name: 'Dify' })).toBeEnabled(); + }); + + it('CONTROL — a stored value among the options checks its own item, with no retired item', () => { + renderRadioIn('en', 'dify'); + expect(screen.getByRole('radio', { name: 'Dify' })).toBeChecked(); + expect(screen.getAllByRole('radio')).toHaveLength(2); + expect(screen.queryByTestId('settings-radio-retired')).toBeNull(); + }); +}); + +/** The same options drawn as a multiselect. */ +const ADAPTER_MULTI: Specifier = { ...ADAPTER, type: 'multiselect' }; + +function renderMultiIn(language: string, value: unknown, onChange = vi.fn()) { + const instance = createI18n({ defaultLanguage: language, detectBrowserLanguage: false }); + render( + + + , + ); + return instance; +} + +describe('objectstack#37480 — a stored multiselect member outside the current options is named', () => { + it('the member shows as a checked checkbox reading the stored code marked "no longer available"', () => { + const en = renderMultiIn('en', ['ragflow', 'dify']); + const named = en.t('console.settingsView.selectValueRetired', { value: 'ragflow' }); + + expect(screen.getByRole('checkbox', { name: named })).toBeChecked(); + expect(screen.getByRole('checkbox', { name: 'Dify' })).toBeChecked(); + expect(screen.getByRole('checkbox', { name: 'Built-in' })).not.toBeChecked(); + }); + + it('ticking a current option keeps the retired member in the array, as before', () => { + const onChange = vi.fn(); + renderMultiIn('en', ['ragflow'], onChange); + fireEvent.click(screen.getByRole('checkbox', { name: 'Dify' })); + expect(onChange).toHaveBeenCalledWith(['ragflow', 'dify']); + }); + + it('unticking the retired member drops it from the array', () => { + const onChange = vi.fn(); + const en = renderMultiIn('en', ['ragflow', 'dify'], onChange); + fireEvent.click( + screen.getByRole('checkbox', { + name: en.t('console.settingsView.selectValueRetired', { value: 'ragflow' }), + }), + ); + expect(onChange).toHaveBeenCalledWith(['dify']); + }); + + it('CONTROL — members all among the options draw only the option checkboxes', () => { + renderMultiIn('en', ['dify']); + expect(screen.getAllByRole('checkbox')).toHaveLength(2); + expect(screen.getByRole('checkbox', { name: 'Dify' })).toBeChecked(); + expect(screen.queryByTestId('settings-multiselect-retired')).toBeNull(); + }); +}); diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 040ffe0ca80..43fbac23d85 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -2875,6 +2875,7 @@ const ar = { savedCleared: "تم مسح القيمة المحفوظة", deprecatedBadge: "مهمل", deprecatedBadgeReplacedBy: "مهمل ← {{replacedBy}}", + selectValueRetired: "{{value}} (لم يعد متاحًا)", unsupportedSpecifierType: "نوع إعداد غير مدعوم: {{type}}", mapAddRow: "إضافة صف", mapRemoveRow: "إزالة {{key}}", diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index b581fe53706..4fe0afc2734 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -2587,6 +2587,7 @@ const de = { savedCleared: "Gespeicherter Wert geleert", deprecatedBadge: "Veraltet", deprecatedBadgeReplacedBy: "Veraltet → {{replacedBy}}", + selectValueRetired: "{{value}} (nicht mehr verfügbar)", unsupportedSpecifierType: "Nicht unterstützter Einstellungstyp: {{type}}", mapAddRow: "Zeile hinzufügen", mapRemoveRow: "{{key}} entfernen", diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index e4a76084830..3be36e582d3 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -2810,6 +2810,9 @@ const en = { savedCleared: 'Saved value cleared', deprecatedBadge: 'Deprecated', deprecatedBadgeReplacedBy: 'Deprecated → {{replacedBy}}', + // `selectValueRetired` names a stored select value the setting no longer offers + // (an option removed in a later release); `{{value}}` is the stored code. + selectValueRetired: '{{value}} (no longer available)', unsupportedSpecifierType: 'Unsupported specifier type: {{type}}', // The `map` control (objectstack#31391): keyed rows over the keys the server // serves. `mapAddRow` is the picker that adds a row by its key, `{{key}}` in diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index c879e9508ec..2d299c4b622 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -2661,6 +2661,7 @@ const es = { savedCleared: "Valor guardado borrado", deprecatedBadge: "Obsoleto", deprecatedBadgeReplacedBy: "Obsoleto → {{replacedBy}}", + selectValueRetired: "{{value}} (ya no está disponible)", unsupportedSpecifierType: "Tipo de ajuste no admitido: {{type}}", mapAddRow: "Añadir una fila", mapRemoveRow: "Quitar {{key}}", diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 5bf4039eab7..5c6739be87b 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -2657,6 +2657,7 @@ const fr = { savedCleared: "Valeur enregistrée effacée", deprecatedBadge: "Obsolète", deprecatedBadgeReplacedBy: "Obsolète → {{replacedBy}}", + selectValueRetired: "{{value}} (plus disponible)", unsupportedSpecifierType: "Type de paramètre non pris en charge : {{type}}", mapAddRow: "Ajouter une ligne", mapRemoveRow: "Retirer {{key}}", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 5b689d2ef4e..0c04df49684 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -2589,6 +2589,7 @@ const ja = { savedCleared: "保存された値をクリアしました", deprecatedBadge: "非推奨", deprecatedBadgeReplacedBy: "非推奨 → {{replacedBy}}", + selectValueRetired: "{{value}}(現在は利用できません)", unsupportedSpecifierType: "サポートされていない設定項目の種類: {{type}}", mapAddRow: "行を追加", mapRemoveRow: "{{key}} を削除", diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 6d159da8f17..dcef235fbea 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -2587,6 +2587,7 @@ const ko = { savedCleared: "저장된 값을 지웠습니다", deprecatedBadge: "지원 중단됨", deprecatedBadgeReplacedBy: "지원 중단됨 → {{replacedBy}}", + selectValueRetired: "{{value}} (더 이상 사용할 수 없음)", unsupportedSpecifierType: "지원되지 않는 설정 항목 유형: {{type}}", mapAddRow: "행 추가", mapRemoveRow: "{{key}} 삭제", diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 09c1cc0730a..1c6599019ab 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -2656,6 +2656,7 @@ const pt = { savedCleared: "Valor salvo limpo", deprecatedBadge: "Obsoleto", deprecatedBadgeReplacedBy: "Obsoleto → {{replacedBy}}", + selectValueRetired: "{{value}} (não está mais disponível)", unsupportedSpecifierType: "Tipo de configuração não suportado: {{type}}", mapAddRow: "Adicionar uma linha", mapRemoveRow: "Remover {{key}}", diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index c1281b7a05c..7629e5b5b14 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -2737,6 +2737,7 @@ const ru = { savedCleared: "Сохранённое значение очищено", deprecatedBadge: "Устарело", deprecatedBadgeReplacedBy: "Устарело → {{replacedBy}}", + selectValueRetired: "{{value}} (больше недоступно)", unsupportedSpecifierType: "Неподдерживаемый тип настройки: {{type}}", mapAddRow: "Добавить строку", mapRemoveRow: "Удалить {{key}}", diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 832015de466..77c0f81f78d 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -2383,6 +2383,7 @@ const zh = { savedCleared: '已清除保存的值', deprecatedBadge: '已弃用', deprecatedBadgeReplacedBy: '已弃用 → {{replacedBy}}', + selectValueRetired: '{{value}}(已不可用)', unsupportedSpecifierType: '不支持的设置项类型:{{type}}', mapAddRow: '添加一行', mapRemoveRow: '移除 {{key}}', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index d397fc1bf28..a58b9cd833e 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -2383,6 +2383,7 @@ const zhHant = { savedCleared: '已清除儲存的值', deprecatedBadge: '已棄用', deprecatedBadgeReplacedBy: '已棄用 → {{replacedBy}}', + selectValueRetired: '{{value}}(已不可用)', unsupportedSpecifierType: '不支援的設定項型別:{{type}}', mapAddRow: '新增一行', mapRemoveRow: '移除 {{key}}',