From 481daa2f6f850c1363f37bebeb7ada7e85093847 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 07:54:15 +0800 Subject: [PATCH] [Workspace] Set the default color to first color from the palette (#7627) (#7683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/plugins/workspace/public/components/workspace_form/use_workspace_form.ts * Changeset file for PR #7627 created/updated * Separated a new WorkspaceDetailedFormProps for WorkspaceDetailedForm, and updated the type definition of getNumberOfChanges to support partial form data * Separated defaultWorkspaceFormValues to a constant * Changeset file for PR #7627 created/updated * Modified code format --------- (cherry picked from commit cd33e15933fb81a28cb7c1dd6bfd4bfb0e6e3cca) Signed-off-by: Kapian1234 Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/7627.yml | 2 ++ .../workspace_creator/workspace_creator.tsx | 15 ++++++++++++++- .../public/components/workspace_form/types.ts | 6 +++++- .../public/components/workspace_form/utils.ts | 4 ++-- .../workspace_form/workspace_detail_form.tsx | 4 ++-- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/7627.yml diff --git a/changelogs/fragments/7627.yml b/changelogs/fragments/7627.yml new file mode 100644 index 000000000000..8b5a7e830062 --- /dev/null +++ b/changelogs/fragments/7627.yml @@ -0,0 +1,2 @@ +feat: +- [Workspace] Set default color for workspace create form ([#7627](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7627)) \ No newline at end of file diff --git a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx index 88c46e973c00..c46d17b701ac 100644 --- a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx +++ b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx @@ -4,7 +4,13 @@ */ import React, { useCallback } from 'react'; -import { EuiPage, EuiPageBody, EuiPageHeader, EuiPageContent } from '@elastic/eui'; +import { + EuiPage, + EuiPageBody, + EuiPageHeader, + EuiPageContent, + euiPaletteColorBlind, +} from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { useObservable } from 'react-use'; import { BehaviorSubject } from 'rxjs'; @@ -18,6 +24,7 @@ import { convertPermissionSettingsToPermissions } from '../workspace_form'; import { DataSource } from '../../../common/types'; import { DataSourceManagementPluginSetup } from '../../../../../plugins/data_source_management/public'; import { WorkspaceUseCase } from '../../types'; +import { WorkspaceFormData } from '../workspace_form/types'; export interface WorkspaceCreatorProps { registeredUseCases$: BehaviorSubject; @@ -37,6 +44,11 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => { workspaceClient: WorkspaceClient; dataSourceManagement?: DataSourceManagementPluginSetup; }>(); + + const defaultWorkspaceFormValues: Partial = { + color: euiPaletteColorBlind()[0], + }; + const isPermissionEnabled = application?.capabilities.workspaces.permissionEnabled; const availableUseCases = useObservable(props.registeredUseCases$, []); @@ -107,6 +119,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => { permissionEnabled={isPermissionEnabled} dataSourceManagement={dataSourceManagement} availableUseCases={availableUseCases} + defaultValues={defaultWorkspaceFormValues} /> )} diff --git a/src/plugins/workspace/public/components/workspace_form/types.ts b/src/plugins/workspace/public/components/workspace_form/types.ts index 7b83bc36ddd3..cbcf7e8ded26 100644 --- a/src/plugins/workspace/public/components/workspace_form/types.ts +++ b/src/plugins/workspace/public/components/workspace_form/types.ts @@ -80,10 +80,14 @@ export interface WorkspaceFormProps { application: ApplicationStart; savedObjects: SavedObjectsStart; onSubmit?: (formData: WorkspaceFormSubmitData) => void; - defaultValues?: WorkspaceFormData; + defaultValues?: Partial; operationType: WorkspaceOperationType; permissionEnabled?: boolean; detailTab?: DetailTab; dataSourceManagement?: DataSourceManagementPluginSetup; availableUseCases: WorkspaceUseCase[]; } + +export interface WorkspaceDetailedFormProps extends WorkspaceFormProps { + defaultValues?: WorkspaceFormData; +} diff --git a/src/plugins/workspace/public/components/workspace_form/utils.ts b/src/plugins/workspace/public/components/workspace_form/utils.ts index 2ea76756d3d8..a1a340a78db6 100644 --- a/src/plugins/workspace/public/components/workspace_form/utils.ts +++ b/src/plugins/workspace/public/components/workspace_form/utils.ts @@ -461,12 +461,12 @@ const isSamePermissionSetting = (a: PermissionSettingLike, b: PermissionSettingL }; export const getNumberOfChanges = ( - newFormData: Omit, 'permissionSettings'> & { + newFormData: Partial> & { permissionSettings?: Array< Pick & Partial >; }, - initialFormData: Omit + initialFormData: Partial> ) => { let count = 0; if (newFormData.name !== initialFormData.name) { diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_detail_form.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_detail_form.tsx index 8c819d5fe167..b4b42743b410 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_detail_form.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_detail_form.tsx @@ -8,7 +8,7 @@ import React, { useRef } from 'react'; import { EuiPanel, EuiSpacer, EuiForm, EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui'; import { WorkspaceBottomBar } from './workspace_bottom_bar'; -import { WorkspaceFormProps } from './types'; +import { WorkspaceDetailedFormProps } from './types'; import { useWorkspaceForm } from './use_workspace_form'; import { WorkspaceUseCase } from './workspace_use_case'; import { WorkspacePermissionSettingPanel } from './workspace_permission_setting_panel'; @@ -41,7 +41,7 @@ const FormGroup = ({ title, children }: FormGroupProps) => ( ); -export const WorkspaceDetailForm = (props: WorkspaceFormProps) => { +export const WorkspaceDetailForm = (props: WorkspaceDetailedFormProps) => { const { detailTab, application,