diff options
| author | Ali Al Jufairi <[email protected]> | 2025-08-10 09:04:52 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-10 00:04:52 +0000 |
| commit | 8a9a9275440e3681e9be73d741a5aba429ae501f (patch) | |
| tree | cc2c17101c57d0c34049a6ee390d0f1b9bf38018 /packages/cli/src/utils/dialogScopeUtils.ts | |
| parent | c632ec8b03ac5b459da9ccb041b9fca19252f69b (diff) | |
feat(ui): add /settings command and UI panel (#4738)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/utils/dialogScopeUtils.ts')
| -rw-r--r-- | packages/cli/src/utils/dialogScopeUtils.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/packages/cli/src/utils/dialogScopeUtils.ts b/packages/cli/src/utils/dialogScopeUtils.ts new file mode 100644 index 00000000..c175f9c8 --- /dev/null +++ b/packages/cli/src/utils/dialogScopeUtils.ts @@ -0,0 +1,64 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { SettingScope, LoadedSettings } from '../config/settings.js'; +import { settingExistsInScope } from './settingsUtils.js'; + +/** + * Shared scope labels for dialog components that need to display setting scopes + */ +export const SCOPE_LABELS = { + [SettingScope.User]: 'User Settings', + [SettingScope.Workspace]: 'Workspace Settings', + [SettingScope.System]: 'System Settings', +} as const; + +/** + * Helper function to get scope items for radio button selects + */ +export function getScopeItems() { + return [ + { label: SCOPE_LABELS[SettingScope.User], value: SettingScope.User }, + { + label: SCOPE_LABELS[SettingScope.Workspace], + value: SettingScope.Workspace, + }, + { label: SCOPE_LABELS[SettingScope.System], value: SettingScope.System }, + ]; +} + +/** + * Generate scope message for a specific setting + */ +export function getScopeMessageForSetting( + settingKey: string, + selectedScope: SettingScope, + settings: LoadedSettings, +): string { + const otherScopes = Object.values(SettingScope).filter( + (scope) => scope !== selectedScope, + ); + + const modifiedInOtherScopes = otherScopes.filter((scope) => { + const scopeSettings = settings.forScope(scope).settings; + return settingExistsInScope(settingKey, scopeSettings); + }); + + if (modifiedInOtherScopes.length === 0) { + return ''; + } + + const modifiedScopesStr = modifiedInOtherScopes.join(', '); + const currentScopeSettings = settings.forScope(selectedScope).settings; + const existsInCurrentScope = settingExistsInScope( + settingKey, + currentScopeSettings, + ); + + return existsInCurrentScope + ? `(Also modified in ${modifiedScopesStr})` + : `(Modified in ${modifiedScopesStr})`; +} |
