File size: 1,821 Bytes
d810ed8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type { LoadedSettings } from '../config/settings.js';
import { SettingScope } 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})`;
}
|