kgabryje commented on code in PR #20589:
URL: https://github.com/apache/superset/pull/20589#discussion_r916079231


##########
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx:
##########
@@ -122,10 +132,86 @@ const DashboardContainer: FC<DashboardContainerProps> = 
({ topLevelTabs }) => {
     dispatch(setInScopeStatusOfFilters(scopes));
   }, [nativeFilterScopes, dashboardLayout, dispatch]);
 
+  const verifyUpdateColorScheme = useCallback(() => {
+    const currentMetadata = dashboardInfo.metadata;
+    if (currentMetadata?.color_scheme) {
+      const metadata = { ...currentMetadata };
+      const colorScheme = metadata?.color_scheme;
+      const colorSchemeDomain = metadata?.color_scheme_domain || [];
+      const categoricalSchemes = getCategoricalSchemeRegistry();
+      const registryColorSchemeDomain =
+        categoricalSchemes.get(colorScheme)?.colors || [];
+      const defaultColorScheme = categoricalSchemes.defaultKey;
+      const isColorSchemeExisting = !!categoricalSchemes.get(colorScheme);
+      const updateDashboard = () => {
+        SupersetClient.put({
+          endpoint: `/api/v1/dashboard/${dashboardInfo.id}`,
+          headers: { 'Content-Type': 'application/json' },
+          body: JSON.stringify({
+            json_metadata: jsonStringify(metadata),
+          }),
+        }).catch(e => console.log(e));

Review Comment:
   Also, shouldn't action like updating dashboard be handled in redux? Not sure 
what pattern we use in the rest of dashboard codebase, if we don't have a 
update dashboard action/thunk already, let's keep it as is



##########
superset-frontend/src/explore/components/controls/ColorSchemeControl/index.jsx:
##########
@@ -192,7 +192,7 @@ export default class ColorSchemeControl extends 
React.PureComponent {
       onChange: this.onChange,
       options,
       placeholder: t('Select scheme'),
-      value: currentScheme,
+      value: currentScheme && currentScheme.toString(),

Review Comment:
   ```suggestion
         value: currentScheme?.toString(),
   ```



##########
superset-frontend/src/dashboard/components/PropertiesModal/index.tsx:
##########
@@ -174,9 +174,13 @@ const PropertiesModal = ({
         delete metadata.positions;
       }
       const metaDataCopy = { ...metadata };
+
       if (metaDataCopy?.shared_label_colors) {
         delete metaDataCopy.shared_label_colors;
       }
+      if (metaDataCopy?.color_scheme_domain) {

Review Comment:
   I don't think we need that if statement. `metaDataCopy` object exists 
because we initialize it in line 176 and we don't need if field exists to call 
`delete` on it



##########
superset-frontend/src/explore/actions/hydrateExplore.ts:
##########
@@ -67,6 +71,31 @@ export const hydrateExplore =
       initialExploreState,
       initialFormData,
     ) as ControlStateMapping;
+    const colorSchemeKey = initialControls.color_scheme && 'color_scheme';
+    const linearColorSchemeKey =
+      initialControls.linear_color_scheme && 'linear_color_scheme';
+    // if the color scheme does not exist anymore
+    // fallbacks to the available default key
+    const verifyColorScheme = (type: 'CATEGORICAL' | 'SEQUENTIAL') => {
+      const schemes =
+        type === 'CATEGORICAL'
+          ? getCategoricalSchemeRegistry()
+          : getSequentialSchemeRegistry();
+      const key =
+        type === 'CATEGORICAL' ? colorSchemeKey : linearColorSchemeKey;
+      const defaultScheme = schemes.defaultKey
+        ? schemes.defaultKey
+        : type === 'CATEGORICAL'
+        ? 'supersetColors'
+        : 'superset_seq_1';

Review Comment:
   Could we simplify this expression? 



##########
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx:
##########
@@ -122,10 +132,86 @@ const DashboardContainer: FC<DashboardContainerProps> = 
({ topLevelTabs }) => {
     dispatch(setInScopeStatusOfFilters(scopes));
   }, [nativeFilterScopes, dashboardLayout, dispatch]);
 
+  const verifyUpdateColorScheme = useCallback(() => {
+    const currentMetadata = dashboardInfo.metadata;
+    if (currentMetadata?.color_scheme) {
+      const metadata = { ...currentMetadata };
+      const colorScheme = metadata?.color_scheme;
+      const colorSchemeDomain = metadata?.color_scheme_domain || [];
+      const categoricalSchemes = getCategoricalSchemeRegistry();
+      const registryColorSchemeDomain =
+        categoricalSchemes.get(colorScheme)?.colors || [];
+      const defaultColorScheme = categoricalSchemes.defaultKey;
+      const isColorSchemeExisting = !!categoricalSchemes.get(colorScheme);

Review Comment:
   nit: `doesColorSchemeExist` or `colorSchemeExists` 🙂 



##########
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx:
##########
@@ -122,10 +132,86 @@ const DashboardContainer: FC<DashboardContainerProps> = 
({ topLevelTabs }) => {
     dispatch(setInScopeStatusOfFilters(scopes));
   }, [nativeFilterScopes, dashboardLayout, dispatch]);
 
+  const verifyUpdateColorScheme = useCallback(() => {
+    const currentMetadata = dashboardInfo.metadata;
+    if (currentMetadata?.color_scheme) {
+      const metadata = { ...currentMetadata };
+      const colorScheme = metadata?.color_scheme;
+      const colorSchemeDomain = metadata?.color_scheme_domain || [];
+      const categoricalSchemes = getCategoricalSchemeRegistry();
+      const registryColorSchemeDomain =
+        categoricalSchemes.get(colorScheme)?.colors || [];
+      const defaultColorScheme = categoricalSchemes.defaultKey;
+      const isColorSchemeExisting = !!categoricalSchemes.get(colorScheme);
+      const updateDashboard = () => {
+        SupersetClient.put({
+          endpoint: `/api/v1/dashboard/${dashboardInfo.id}`,
+          headers: { 'Content-Type': 'application/json' },
+          body: JSON.stringify({
+            json_metadata: jsonStringify(metadata),
+          }),
+        }).catch(e => console.log(e));

Review Comment:
   Can we add error handling? Like displaying error toast
   Also, success toast for success?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to