AAfghahi commented on code in PR #19130:
URL: https://github.com/apache/superset/pull/19130#discussion_r868213846


##########
superset-frontend/src/reports/reducers/reports.js:
##########
@@ -17,32 +17,64 @@
  * under the License.
  */
 /* eslint-disable camelcase */
+// eslint-disable-next-line import/no-extraneous-dependencies
 import { SET_REPORT, ADD_REPORT, EDIT_REPORT } from '../actions/reports';
 
 export default function reportsReducer(state = {}, action) {
   const actionHandlers = {
     [SET_REPORT]() {
-      return {
-        ...action.report.result.reduce(
-          (obj, report) => ({ ...obj, [report.id]: report }),
-          {},
-        ),
-      };
+      const { report, resourceId, creationMethod, filterField } = action;
+      // For now report count should only be one, but we are checking in case
+      // functionality changes.
+      const reportObject = report.result?.find(
+        report => report[filterField] === resourceId,
+      );
+
+      if (reportObject) {
+        return {
+          ...state,
+          [creationMethod]: {
+            ...state[creationMethod],
+            [resourceId]: reportObject,
+          },
+        };
+      }
+      if (state?.[creationMethod]?.[resourceId]) {
+        // remove the empty report from state
+        const newState = { ...state };
+        delete newState[creationMethod][resourceId];
+        return newState;
+      }
+      return { ...state };
     },
+
     [ADD_REPORT]() {
-      const report = action.json.result;
-      report.id = action.json.id;
+      const { result, id } = action.json;
+      const report = { ...result, id };
+      const reportId = report.dashboard || report.chart;

Review Comment:
   yes I think that we need to rename it. 



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