From dfc7defaef779478cad1de58b854977a4953c982 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Mon, 9 Sep 2024 14:30:12 +0800 Subject: [PATCH] add experimental to user personal settings and support i18n (#8080) Signed-off-by: Hailong Cui --- changelogs/fragments/7953.yml | 2 +- .../create_or_upgrade_saved_config.ts | 4 +- .../server/ui_settings/ui_settings_client.ts | 8 +- src/core/server/ui_settings/utils.ts | 2 +- src/core/types/ui_settings.ts | 2 +- .../user_ui_settings_client_wrapper.ts | 5 - .../components/workspace_list/index.tsx | 117 +++++++++++++----- 7 files changed, 96 insertions(+), 44 deletions(-) diff --git a/changelogs/fragments/7953.yml b/changelogs/fragments/7953.yml index fae54257ade7..0b0782f6dafb 100644 --- a/changelogs/fragments/7953.yml +++ b/changelogs/fragments/7953.yml @@ -1,2 +1,2 @@ feat: -- [Workspace] Support user personal settings ([#7953](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7953)) \ No newline at end of file +- [Experimental] Support user personal settings ([#7953](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7953)) \ No newline at end of file diff --git a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts index d73bff2fab43..fc8c9452163b 100644 --- a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts +++ b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts @@ -36,7 +36,7 @@ import { Logger } from '../../logging'; import { getUpgradeableConfig } from './get_upgradeable_config'; import { UiSettingScope } from '../types'; -import { generateDocId } from '../utils'; +import { buildDocIdWithScope } from '../utils'; interface Options { savedObjectsClient: SavedObjectsClientContract; @@ -70,7 +70,7 @@ export async function createOrUpgradeSavedConfig( ); try { - const docId = generateDocId(version, scope); + const docId = buildDocIdWithScope(version, scope); // create the new SavedConfig await savedObjectsClient.create('config', attributes, { id: docId }); } catch (error) { diff --git a/src/core/server/ui_settings/ui_settings_client.ts b/src/core/server/ui_settings/ui_settings_client.ts index 56fd42946749..8c82ed0054bb 100644 --- a/src/core/server/ui_settings/ui_settings_client.ts +++ b/src/core/server/ui_settings/ui_settings_client.ts @@ -41,7 +41,7 @@ import { UiSettingScope, } from './types'; import { CannotOverrideError } from './ui_settings_errors'; -import { generateDocId } from './utils'; +import { buildDocIdWithScope } from './utils'; export interface UiSettingsServiceOptions { type: string; @@ -167,8 +167,6 @@ export class UiSettingsClient implements IUiSettingsClient { } async setMany(changes: Record, scope?: UiSettingScope) { - // log changes and scope - this.log.debug(`UiSettingsClient.setMany: ${JSON.stringify({ changes, scope })}`); this.onWriteHook(changes, scope); if (scope) { @@ -310,7 +308,7 @@ export class UiSettingsClient implements IUiSettingsClient { }) { changes = this.translateChanges(changes, 'timeline', 'timelion'); try { - const docId = generateDocId(this.id, scope); + const docId = buildDocIdWithScope(this.id, scope); await this.savedObjectsClient.update(this.type, docId, changes); } catch (error) { if (!SavedObjectsErrorHelpers.isNotFoundError(error) || !autoCreateOrUpgradeIfMissing) { @@ -341,7 +339,7 @@ export class UiSettingsClient implements IUiSettingsClient { scope, }: ReadOptions = {}): Promise> { try { - const docId = generateDocId(this.id, scope); + const docId = buildDocIdWithScope(this.id, scope); const resp = await this.savedObjectsClient.get>(this.type, docId); return this.translateChanges(resp.attributes, 'timelion', 'timeline'); } catch (error) { diff --git a/src/core/server/ui_settings/utils.ts b/src/core/server/ui_settings/utils.ts index 214f885c4a5c..da6f1ee64d96 100644 --- a/src/core/server/ui_settings/utils.ts +++ b/src/core/server/ui_settings/utils.ts @@ -7,7 +7,7 @@ import { UiSettingScope } from './types'; export const CURRENT_USER_PLACEHOLDER = ''; -export const generateDocId = (id: string, scope?: UiSettingScope) => { +export const buildDocIdWithScope = (id: string, scope?: UiSettingScope) => { if (scope === UiSettingScope.USER) { return `${CURRENT_USER_PLACEHOLDER}_${id}`; } diff --git a/src/core/types/ui_settings.ts b/src/core/types/ui_settings.ts index 58297589cd54..061c31c1d73a 100644 --- a/src/core/types/ui_settings.ts +++ b/src/core/types/ui_settings.ts @@ -58,7 +58,7 @@ export interface DeprecationSettings { /** * UiSettings scope options. - * @public + * @experimental */ export enum UiSettingScope { GLOBAL = 'global', diff --git a/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts b/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts index a17a32961034..1b5e44eac18b 100644 --- a/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts +++ b/src/plugins/advanced_settings/server/saved_objects/user_ui_settings_client_wrapper.ts @@ -12,8 +12,6 @@ import { CoreStart, ACL, SavedObjectsCreateOptions, - SavedObjectsFindOptions, - SavedObjectsFindResponse, OpenSearchDashboardsRequest, } from '../../../../core/server'; import { Logger, CURRENT_USER_PLACEHOLDER } from '../../../../core/server'; @@ -60,8 +58,6 @@ export class UserUISettingsClientWrapper { ): Promise> => { if (type === 'config') { const docId = this.normalizeDocId(id, wrapperOptions.request, this.core); - this.logger.debug(`Getting config with original: ${id} normalizeDocId: ${docId}`); - // user level return wrapperOptions.client.get(type, docId, options); } @@ -76,7 +72,6 @@ export class UserUISettingsClientWrapper { ): Promise> => { if (type === 'config') { const docId = this.normalizeDocId(id, wrapperOptions.request, this.core); - this.logger.debug(`Getting config with original: ${id} normalizeDocId: ${docId}`); // update user level settings return await wrapperOptions.client.update(type, docId, attributes, options); } diff --git a/src/plugins/workspace/public/components/workspace_list/index.tsx b/src/plugins/workspace/public/components/workspace_list/index.tsx index 1910c4b373c6..8366c240cca3 100644 --- a/src/plugins/workspace/public/components/workspace_list/index.tsx +++ b/src/plugins/workspace/public/components/workspace_list/index.tsx @@ -171,7 +171,7 @@ export const WorkspaceListInner = ({ const emptyStateMessage = useMemo(() => { return ( {i18n.translate('workspace.workspaceList.emptyState.title', { @@ -222,7 +222,9 @@ export const WorkspaceListInner = ({ const handleCopyId = (id: string) => { copyToClipboard(id); - notifications?.toasts.addSuccess('Workspace ID copied'); + notifications?.toasts.addSuccess( + i18n.translate('workspace.copyWorkspaceId.message', { defaultMessage: 'Workspace ID copied' }) + ); }; const handleSwitchWorkspace = useCallback( @@ -239,11 +241,19 @@ export const WorkspaceListInner = ({ const set = await uiSettings?.set(DEFAULT_WORKSPACE, item.id); if (set) { setDefaultWorkspaceId(item.id); - notifications?.toasts.addSuccess(`Default workspace been set to ${item.name}`); + notifications?.toasts.addSuccess( + i18n.translate('workspace.setDefaultWorkspace.success.message', { + defaultMessage: 'Default workspace been set to {name}', + values: { name: item.name }, + }) + ); } else { // toast notifications?.toasts.addWarning( - `Failed to set workspace ${item.name} as default workspace.` + i18n.translate('workspace.setDefaultWorkspace.error.message', { + defaultMessage: 'Failed to set workspace {name} as default workspace.', + values: { name: item.name }, + }) ); } }, @@ -349,7 +359,7 @@ export const WorkspaceListInner = ({ const columnsWithoutActions = [ { field: 'name', - name: 'Name', + name: i18n.translate('workspace.list.columns.name.title', { defaultMessage: 'Name' }), width: '18%', sortable: true, render: (name: string, item: WorkspaceAttributeWithPermission) => ( @@ -361,7 +371,11 @@ export const WorkspaceListInner = ({ {item.id === defaultWorkspaceId && ( - Default workspace + + {i18n.translate('workspace.defaultWorkspace.title', { + defaultMessage: 'Default workspace', + })} + )} @@ -372,13 +386,15 @@ export const WorkspaceListInner = ({ { field: 'useCase', - name: 'Use case', + name: i18n.translate('workspace.list.columns.useCase.title', { defaultMessage: 'Use case' }), width: '12%', }, { field: 'description', - name: 'Description', + name: i18n.translate('workspace.list.columns.description.title', { + defaultMessage: 'Description', + }), width: '15%', render: (description: string) => ( { return isDashboardAdmin ? ( - - Admin + + + {i18n.translate('workspace.role.admin.name', { defaultMessage: 'Admin' })} + ) : ( startCase(permissionMode) @@ -421,7 +446,9 @@ export const WorkspaceListInner = ({ }, { field: 'lastUpdatedTime', - name: 'Last updated', + name: i18n.translate('workspace.list.columns.lastUpdated.title', { + defaultMessage: 'Last updated', + }), width: '15%', truncateText: false, render: (lastUpdatedTime: string) => { @@ -431,7 +458,9 @@ export const WorkspaceListInner = ({ { field: 'dataSources', width: '15%', - name: 'Data sources', + name: i18n.translate('workspace.list.columns.dataSources.title', { + defaultMessage: 'Data sources', + }), render: (dataSources: string[], item: WorkspaceAttributeWithPermission) => { return renderDataWithMoreBadge(dataSources, 2, item.id, DetailTab.DataSources); }, @@ -439,47 +468,75 @@ export const WorkspaceListInner = ({ ]; const allActions = [ { - name: Copy ID, + name: ( + + {i18n.translate('workspace.list.actions.copyId.name', { defaultMessage: 'Copy ID' })} + + ), icon: 'copy', type: 'icon', - description: 'Copy workspace id', + description: i18n.translate('workspace.list.actions.copyId.description', { + defaultMessage: 'Copy workspace id', + }), 'data-test-subj': 'workspace-list-copy-id-icon', onClick: ({ id }: WorkspaceAttribute) => handleCopyId(id), }, { - name: Edit, + name: ( + + {i18n.translate('workspace.list.actions.edit.name', { defaultMessage: 'Edit' })} + + ), icon: 'pencil', type: 'icon', - description: 'Edit workspace', + description: i18n.translate('workspace.list.actions.edit.description', { + defaultMessage: 'Edit workspace', + }), 'data-test-subj': 'workspace-list-edit-icon', onClick: ({ id }: WorkspaceAttribute) => handleSwitchWorkspace(id), }, { - name: Set as my default, + name: ( + + {i18n.translate('workspace.list.actions.setDefault.name', { + defaultMessage: 'Set as my default', + })} + + ), icon: 'flag', type: 'icon', - description: 'Set as default workspace', + description: i18n.translate('workspace.list.actions.setDefault.description', { + defaultMessage: 'Set as my default workspace', + }), 'data-test-subj': 'workspace-list-set-default-icon', onClick: (item: WorkspaceAttribute) => handleSetDefaultWorkspace(item), }, { - name: Leave, + name: ( + + {i18n.translate('workspace.list.actions.leave.name', { defaultMessage: 'Leave' })} + + ), icon: 'exit', type: 'icon', - description: 'Leave workspace', + description: i18n.translate('workspace.list.actions.leave.description', { + defaultMessage: 'Leave workspace', + }), 'data-test-subj': 'workspace-list-leave-icon', available: () => false, }, { name: ( - Delete + {i18n.translate('workspace.list.actions.delete.name', { defaultMessage: 'Delete' })} ), icon: () => , type: 'icon', isPrimary: false, - description: 'Delete workspace', + description: i18n.translate('workspace.list.actions.delete.description', { + defaultMessage: 'Delete workspace', + }), 'data-test-subj': 'workspace-list-delete-icon', available: () => isDashboardAdmin, onClick: (item: WorkspaceAttribute) => { @@ -497,12 +554,12 @@ export const WorkspaceListInner = ({ return column.field; }); const availableColumns = columnsWithoutActions - .filter((column) => !excludedColumns.includes(column.field)) .filter((column) => { return ( - !includedColumnsFields || - includedColumnsFields.length === 0 || - includedColumnsFields.includes(column.field) + (!includedColumnsFields || + includedColumnsFields.length === 0 || + includedColumnsFields.includes(column.field)) && + !excludedColumns.includes(column.field) ); }) .map((column) => { @@ -515,7 +572,9 @@ export const WorkspaceListInner = ({ const actionColumns = [ { - name: 'Actions', + name: i18n.translate('workspace.list.columns.actions.title', { + defaultMessage: 'Actions', + }), field: '', actions: availableActions, },