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] Limit workspace colors #8607

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8607.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Limit workspace colors ([#8607](/~https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8607))
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const CreatorDetailsPanel = ({
color={color}
onChange={onColorChange}
compressed
mode="swatch"
button={
<EuiFormControlLayout
icon={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('validateWorkspaceForm', () => {
it('should return error if color is invalid', () => {
expect(validateWorkspaceForm({ color: 'QWERTY' }, false).color).toEqual({
code: WorkspaceFormErrorCode.InvalidColor,
message: 'Color is invalid. Enter a valid color.',
message: 'Color is invalid. Choose a valid color.',
});
});
it('should return error if use case is empty', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { i18n } from '@osd/i18n';

import { euiPaletteColorBlind } from '@elastic/eui';
import type { SavedObjectPermissions } from '../../../../../core/types';
import { WorkspacePermissionMode } from '../../../common/constants';
import { isUseCaseFeatureConfig } from '../../utils';
Expand Down Expand Up @@ -335,11 +335,11 @@ export const validateWorkspaceForm = (
}),
};
}
if (color && !validateWorkspaceColor(color)) {
if (color && (!validateWorkspaceColor(color) || !euiPaletteColorBlind().includes(color))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since we have this !euiPaletteColorBlind().includes(color) check which inlcudes the logic for !validateWorkspaceColor(color), we can remove !validateWorkspaceColor(color).

formErrors.color = {
code: WorkspaceFormErrorCode.InvalidColor,
message: i18n.translate('workspace.form.features.invalidColor', {
defaultMessage: 'Color is invalid. Enter a valid color.',
defaultMessage: 'Color is invalid. Choose a valid color.',
}),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const WorkspaceDetailFormDetails = ({
error={formErrors.color?.message}
>
<EuiCompressedColorPicker
mode="swatch"
color={formData.color}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still allow user to type whatever color they want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add a rule for color validation when submitting like this: euiPaletteColorBlind().includes(color)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use same component as create page? for now they are different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I‘ve tried the validation and it works on both the create page and the detail page

onChange={handleColorChange}
readOnly={!isEditing}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('WorkspaceFormErrorCallout', () => {
},
});

expect(renderResult.getByText('Color: Enter a valid color.')).toBeInTheDocument();
expect(renderResult.getByText('Color: Choose a valid color.')).toBeInTheDocument();
});

it('should render use case suggestion', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const getSuggestionFromErrorCode = (error: WorkspaceFormError) => {
});
case WorkspaceFormErrorCode.InvalidColor:
return i18n.translate('workspace.form.errorCallout.invalidColor', {
defaultMessage: 'Enter a valid color.',
defaultMessage: 'Choose a valid color.',
});
default:
return error.message;
Expand Down
Loading