fix(colors): fix color schemes (#13945)

* fix: fix color schemes

* fix: tests case
This commit is contained in:
simcha90 2021-04-04 15:53:21 +03:00 committed by GitHub
parent abd4051f7a
commit e06290663a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -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": {}}',
);
});
});

View File

@ -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));
}