Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace] Set the default color to first color from the palette #7627

Merged
merged 10 commits into from
Aug 12, 2024
Merged
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> = {
SuZhou-Joe marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -79,10 +79,14 @@ export interface WorkspaceFormProps {
application: ApplicationStart;
savedObjects: SavedObjectsStart;
onSubmit?: (formData: WorkspaceFormSubmitData) => void;
defaultValues?: WorkspaceFormData;
defaultValues?: Partial<WorkspaceFormData>;
Kapian1234 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -454,7 +454,7 @@ export const getNumberOfChanges = (
Pick<WorkspacePermissionSetting, 'id'> & Partial<WorkspacePermissionSetting>
>;
},
initialFormData: Omit<WorkspaceFormData, 'id'>
initialFormData: Omit<Partial<WorkspaceFormData>, 'id'>
Kapian1234 marked this conversation as resolved.
Show resolved Hide resolved
) => {
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
Loading