From e06290663a23740e9cd3f50f2913b016bd7f205f Mon Sep 17 00:00:00 2001 From: simcha90 <56388545+simcha90@users.noreply.github.com> Date: Sun, 4 Apr 2021 15:53:21 +0300 Subject: [PATCH] fix(colors): fix color schemes (#13945) * fix: fix color schemes * fix: tests case --- .../dashboard/components/PropertiesModal_spec.jsx | 2 +- .../src/dashboard/components/PropertiesModal.jsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx index 5387c5e94..20edc28cd 100644 --- a/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx +++ b/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx @@ -113,7 +113,7 @@ describe('PropertiesModal', () => { const spy = jest.spyOn(modalInstance, 'onMetadataChange'); modalInstance.onColorSchemeChange('SUPERSET_DEFAULT'); expect(spy).toHaveBeenCalledWith( - '{"color_scheme": "SUPERSET_DEFAULT"}', + '{"color_scheme": "SUPERSET_DEFAULT", "label_colors": {}}', ); }); }); diff --git a/superset-frontend/src/dashboard/components/PropertiesModal.jsx b/superset-frontend/src/dashboard/components/PropertiesModal.jsx index 481893fb4..170d7871d 100644 --- a/superset-frontend/src/dashboard/components/PropertiesModal.jsx +++ b/superset-frontend/src/dashboard/components/PropertiesModal.jsx @@ -28,6 +28,7 @@ import { t, SupersetClient, getCategoricalSchemeRegistry, + CategoricalColorNamespace, } from '@superset-ui/core'; import Modal from 'src/common/components/Modal'; @@ -158,6 +159,15 @@ class PropertiesModal extends React.PureComponent { Object.keys(jsonMetadataObj).includes('color_scheme') ) { jsonMetadataObj.color_scheme = value; + jsonMetadataObj.label_colors = Object.keys( + jsonMetadataObj.label_colors ?? {}, + ).reduce( + (prev, next) => ({ + ...prev, + [next]: CategoricalColorNamespace.getScale(value)(next), + }), + {}, + ); this.onMetadataChange(jsonStringify(jsonMetadataObj)); }