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


##########
superset-frontend/src/components/Datasource/utils/index.ts:
##########
@@ -248,3 +249,21 @@ export async function fetchSyncedColumns(
   const { json } = await SupersetClient.get({ endpoint, signal });
   return json as ColumnMetadata[];
 }
+
+/**
+ * Lift each column's certification out of its `extra` JSON into the flat
+ * fields the datasource editor binds to.
+ */
+export function withCertificationFields(columns: ColumnObject[] = []) {
+  return columns.map(column => {
+    const {
+      certification: { details = '', certified_by: certifiedBy = '' } = {},
+    } = JSON.parse(column.extra || '{}') || {};
+    return {
+      ...column,
+      certification_details: details || '',
+      certified_by: certifiedBy || '',
+      is_certified: details || certifiedBy,
+    };
+  });
+}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>JSON.parse crash on malformed extra</b></div>
   <div id="fix">
   
   `JSON.parse(column.extra || '{}')` has no try/catch, so a malformed `extra` 
string will throw and abort the entire `columns.map`. The sibling 
`hydrateMetricExtra` in `DatasourceEditor.tsx` explicitly catches parse errors 
and falls back to defaults — mirror that pattern here.
   </div>
   
   
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ````suggestion
   export function withCertificationFields(columns: ColumnObject[] = []) {
     return columns.map(column => {
       let parsedExtra = {};
       try {
         parsedExtra = JSON.parse(column.extra || '{}') || {};
       } catch (_) {
         parsedExtra = {};
       }
       const {
         certification: { details = '', certified_by: certifiedBy = '' } = {},
       } = parsedExtra;
       return {
         ...column,
         certification_details: column.certification_details || details || '',
         certified_by: column.certified_by || certifiedBy || '',
         is_certified: details || certifiedBy,
       };
     });
   }
   ````
   
   </div>
   </details>
   
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #6ff63f</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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