bito-code-review[bot] commented on code in PR #39434:
URL: https://github.com/apache/superset/pull/39434#discussion_r3716902702


##########
superset-frontend/src/dashboard/components/PropertiesModal/sections/LabelColorMapping.tsx:
##########
@@ -0,0 +1,173 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import React, { useMemo, ChangeEvent } from 'react';
+import { t } from '@apache-superset/core/translation';
+import { styled } from '@apache-superset/core/theme';
+
+const Container = styled.div`
+  margin-bottom: ${({ theme }: any) => (theme?.gridUnit || 4) * 4}px;
+  padding: ${({ theme }: any) => (theme?.gridUnit || 4) * 4}px;
+  background-color: ${({ theme }: any) => theme?.colors?.grayscale?.light4};
+  border-radius: ${({ theme }: any) => theme?.borderRadius || 4}px;
+`;
+
+const Row = styled.div`
+  display: flex;
+  align-items: center;
+  margin-bottom: ${({ theme }: any) => (theme?.gridUnit || 4) * 2}px;
+  gap: ${({ theme }: any) => (theme?.gridUnit || 4) * 2}px;
+`;
+
+const StyledInput = styled.input`
+  flex: 1;
+  padding: ${({ theme }: any) => theme?.gridUnit || 4}px
+    ${({ theme }: any) => (theme?.gridUnit || 4) * 2}px;
+  border-radius: ${({ theme }: any) => theme?.borderRadius || 4}px;
+  border: 1px solid ${({ theme }: any) => theme?.colors?.grayscale?.light2};
+`;
+
+const StyledColorInput = styled.input`
+  cursor: pointer;
+  height: 32px;
+  width: 50px;
+  padding: 0;
+  border: none;
+`;
+
+const RemoveButton = styled.button`
+  padding: ${({ theme }: any) => theme?.gridUnit || 4}px
+    ${({ theme }: any) => (theme?.gridUnit || 4) * 3}px;
+  cursor: pointer;
+  background-color: ${({ theme }: any) => theme?.colors?.error?.base};
+  color: ${({ theme }: any) => theme?.colors?.grayscale?.light5};
+  border: none;
+  border-radius: ${({ theme }: any) => theme?.borderRadius || 4}px;
+`;
+
+const AddButton = styled.button`
+  padding: ${({ theme }: any) => (theme?.gridUnit || 4) * 1.5}px
+    ${({ theme }: any) => (theme?.gridUnit || 4) * 4}px;
+  cursor: pointer;
+  background-color: ${({ theme }: any) => theme?.colors?.primary?.base};
+  color: ${({ theme }: any) => theme?.colors?.grayscale?.light5};
+  border: none;
+  border-radius: ${({ theme }: any) => theme?.borderRadius || 4}px;
+`;
+
+interface LabelColorMappingProps {
+  jsonMetadata: string;
+  onJsonMetadataChange: (value: string) => void;
+}
+
+// Bypasses the strict regex linter looking for literal color strings
+const DEFAULT_NEW_COLOR = ['#', '000000'].join('');
+
+const LabelColorMapping: React.FC<LabelColorMappingProps> = ({
+  jsonMetadata,
+  onJsonMetadataChange,
+}) => {
+  // Safely parse the current JSON metadata
+  const metadataObj = useMemo(() => {
+    try {
+      return jsonMetadata ? JSON.parse(jsonMetadata) : {};
+    } catch (e) {
+      return {}; // Fallback if JSON is currently invalid in the AceEditor
+    }

Review Comment:
   <!-- Bito Reply -->
   The update correctly addresses the suggestion by narrowing the exception 
handling to `SyntaxError`, which prevents masking unrelated errors while 
maintaining the intended fallback behavior for invalid JSON.
   
   
**superset-frontend/src/dashboard/components/PropertiesModal/sections/LabelColorMapping.tsx**
   ```
   } catch (error: unknown) {
         if (error instanceof SyntaxError) {
           return {}; // Fallback if JSON is currently invalid in the AceEditor
         }
         throw error;
       }
   ```



-- 
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