eschutho commented on a change in pull request #18131:
URL: https://github.com/apache/superset/pull/18131#discussion_r806346370



##########
File path: superset-frontend/src/reports/reducers/reports.js
##########
@@ -18,74 +18,33 @@
  */
 /* eslint-disable camelcase */
 // eslint-disable-next-line import/no-extraneous-dependencies
-import { report } from 'process';
-import {
-  SET_REPORT,
-  ADD_REPORT,
-  EDIT_REPORT,
-  DELETE_REPORT,
-} from '../actions/reports';
-
-/* -- Report schema --
-reports: {
-  dashboards: {
-    [dashboardId]: {...reportObject}
-  },
-  charts: {
-    [chartId]: {...reportObject}
-  },
-}
-*/
+import { SET_REPORT, ADD_REPORT, EDIT_REPORT } from '../actions/reports';
 
 export default function reportsReducer(state = {}, action) {
   const actionHandlers = {
     [SET_REPORT]() {
-      // Grabs the first report with a dashboard id that
-      // matches the parameter report's dashboard_id
-      const reportWithDashboard = action.report.result?.find(
-        report => !!report.dashboard_id,
-      );
-      // Grabs the first report with a chart id that
-      // matches the parameter report's chart.id
-      const reportWithChart = action.report.result?.find(
-        report => !!report.chart?.id,
-      );
+      const { report, resourceId, creationMethod } = action;
+
+      const reportObject = report.result?.find(report => !!report[resourceId]);
 
-      // This organizes report by its type, dashboard or chart
-      // and indexes it by the dashboard/chart id
-      if (reportWithDashboard) {
-        return {
-          ...state,
-          dashboards: {
-            ...state.dashboards,
-            [reportWithDashboard.dashboard_id]: reportWithDashboard,
-          },
-        };
-      }
-      if (reportWithChart) {
-        return {
-          ...state,
-          charts: {
-            ...state.chart,
-            [reportWithChart.chart.id]: reportWithChart,
-          },
-        };
-      }
       return {
         ...state,
+        [creationMethod]: {
+          ...state[creationMethod],
+          [resourceId]: reportObject,
+        },

Review comment:
       this looks much better!




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