Skip to content

Commit

Permalink
[Workspace] Set the default color to first color from the palette (#7627
Browse files Browse the repository at this point in the history
) (#7683)

* 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 cd33e15)

Signed-off-by: Kapian1234 <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 12, 2024
1 parent a35df4b commit 481daa2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7627.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Set default color for workspace create form ([#7627](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7627))
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<WorkspaceUseCase[]>;
Expand All @@ -37,6 +44,11 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
workspaceClient: WorkspaceClient;
dataSourceManagement?: DataSourceManagementPluginSetup;
}>();

const defaultWorkspaceFormValues: Partial<WorkspaceFormData> = {
color: euiPaletteColorBlind()[0],
};

const isPermissionEnabled = application?.capabilities.workspaces.permissionEnabled;
const availableUseCases = useObservable(props.registeredUseCases$, []);

Expand Down Expand Up @@ -107,6 +119,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
permissionEnabled={isPermissionEnabled}
dataSourceManagement={dataSourceManagement}
availableUseCases={availableUseCases}
defaultValues={defaultWorkspaceFormValues}
/>
)}
</EuiPageContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ export interface WorkspaceFormProps {
application: ApplicationStart;
savedObjects: SavedObjectsStart;
onSubmit?: (formData: WorkspaceFormSubmitData) => void;
defaultValues?: WorkspaceFormData;
defaultValues?: Partial<WorkspaceFormData>;
operationType: WorkspaceOperationType;
permissionEnabled?: boolean;
detailTab?: DetailTab;
dataSourceManagement?: DataSourceManagementPluginSetup;
availableUseCases: WorkspaceUseCase[];
}

export interface WorkspaceDetailedFormProps extends WorkspaceFormProps {
defaultValues?: WorkspaceFormData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ const isSamePermissionSetting = (a: PermissionSettingLike, b: PermissionSettingL
};

export const getNumberOfChanges = (
newFormData: Omit<Partial<WorkspaceFormSubmitData>, 'permissionSettings'> & {
newFormData: Partial<Omit<WorkspaceFormSubmitData, 'permissionSettings'>> & {
permissionSettings?: Array<
Pick<WorkspacePermissionSetting, 'id'> & Partial<WorkspacePermissionSetting>
>;
},
initialFormData: Omit<WorkspaceFormData, 'id'>
initialFormData: Partial<Omit<WorkspaceFormData, 'id'>>
) => {
let count = 0;
if (newFormData.name !== initialFormData.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,7 +41,7 @@ const FormGroup = ({ title, children }: FormGroupProps) => (
</EuiFlexGroup>
);

export const WorkspaceDetailForm = (props: WorkspaceFormProps) => {
export const WorkspaceDetailForm = (props: WorkspaceDetailedFormProps) => {
const {
detailTab,
application,
Expand Down

0 comments on commit 481daa2

Please sign in to comment.