You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/07/03 16:06:39 UTC

[GitHub] [superset] stephenLYZ commented on a diff in pull request #20589: chore: Update color scheme when deleted or changed

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


##########
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardContainer.tsx:
##########
@@ -122,6 +132,65 @@ const DashboardContainer: FC<DashboardContainerProps> = ({ topLevelTabs }) => {
     dispatch(setInScopeStatusOfFilters(scopes));
   }, [nativeFilterScopes, dashboardLayout, dispatch]);
 
+  useEffect(() => {
+    const currentMetadata = 
+      dashboardInfo.json_metadata?.length && JSON.parse(dashboardInfo.json_metadata);
+      if (currentMetadata?.color_scheme) {
+        const metadata = {...currentMetadata};
+        const colorScheme = metadata?.color_scheme;
+        const colorSchemeDomain = metadata?.color_scheme_domain || [];
+        const colorNamespace = metadata?.color_namespace || '';
+        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),
+            }),
+          }).then(() => {
+            dispatch(dashboardInfoChanged({
+              metadata,
+            }));
+            dispatch(setColorScheme(defaultColorScheme))
+          })
+        }
+        const genColorMap = (scheme: string, update = false) => {
+          // TODO: to check why colorMap is always empty
+          const colorMap = getSharedLabelColor().getColorMap(

Review Comment:
   I found `dashboardInfo.json_metadata` is not updated even though I have updated dashboard metadata, but using `dashboardInfo.metadata` is okay.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org