fisjac commented on code in PR #30903:
URL: https://github.com/apache/superset/pull/30903#discussion_r1882743223


##########
superset-frontend/src/components/Datasource/utils.js:
##########
@@ -40,3 +43,86 @@ export function recurseReactClone(children, type, 
propExtender) {
     return newChild;
   });
 }
+
+export function updateColumns(prevCols, newCols, addSuccessToast) {
+  // cols: Array<{column_name: string; is_dttm: boolean; type: string;}>
+  const databaseColumnNames = newCols.map(col => col.column_name);
+  const currentCols = prevCols.reduce((agg, col) => {
+    // eslint-disable-next-line no-param-reassign
+    agg[col.column_name] = col;
+    return agg;
+  }, {});
+  const columnChanges = {
+    added: [],
+    modified: [],
+    removed: prevCols
+      .map(col => col.column_name)
+      .filter(col => !databaseColumnNames.includes(col)),
+    finalColumns: [],
+  };
+  newCols.forEach(col => {
+    const currentCol = currentCols[col.column_name];
+    if (!currentCol) {
+      // new column
+      columnChanges.finalColumns.push({
+        id: nanoid(),
+        column_name: col.column_name,
+        type: col.type,
+        groupby: true,
+        filterable: true,
+        is_dttm: col.is_dttm,
+      });
+      columnChanges.added.push(col.column_name);
+    } else if (
+      currentCol.type !== col.type ||
+      currentCol.is_dttm !== col.is_dttm
+    ) {
+      // modified column
+      columnChanges.finalColumns.push({
+        ...currentCol,
+        type: col.type,
+        is_dttm: currentCol.is_dttm || col.is_dttm,
+      });
+      columnChanges.modified.push(col.column_name);
+    } else {
+      // unchanged
+      columnChanges.finalColumns.push(currentCol);
+    }
+  });
+  if (columnChanges.modified.length) {

Review Comment:
   agreed that showing each of the columns changed winds up being a bit of an 
overkill from a user standpoint. Should we just do away with the toasts 
altogether in favor of something like "columns updated"?



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