Skip to content

Commit

Permalink
[Workspace] Limit workspace colors (#8607) (#8618)
Browse files Browse the repository at this point in the history
* Limit workspace color



* Limit workspace color at detail page



* Changeset file for PR #8607 created/updated

* Add validation



---------



(cherry picked from commit 2b3fbf0)

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 Oct 17, 2024
1 parent 8dbad3f commit 5b819ee
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 6 deletions.
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))) {
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}
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

0 comments on commit 5b819ee

Please sign in to comment.