Skip to content

Commit

Permalink
Add functionality is now working (#17578)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyndsiWilliams authored and AAfghahi committed Mar 22, 2022
1 parent 0814326 commit 4e8fc02
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions superset-frontend/src/reports/reducers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
/* eslint-disable camelcase */
// eslint-disable-next-line import/no-extraneous-dependencies
import { report } from 'process';
// import { allowCrossDomain } from 'src/utils/hostNamesConfig';
import {
SET_REPORT,
ADD_REPORT,
Expand Down Expand Up @@ -78,49 +77,43 @@ export default function reportsReducer(state = {}, action) {
},

[ADD_REPORT]() {
// Grab first matching report by matching dashboard id
const reportWithDashboard = action.json.result.find(
report => !!report.dashboard_id,
);
// Assign the report's id
reportWithDashboard.id = action.json.id;
const { result, id } = action.json;
const report = { ...result, id };

// Grab first matching report by matching chart id
const reportWithChart = action.json.result.find(
report => !!report.chart.id,
);
// Assign the report's id
reportWithChart.id = action.json.id;

// This adds the report by its type, dashboard or chart
if (reportWithDashboard) {
if (result.dashboard) {
return {
...state,
dashboards: {
...state.dashboards,
[reportWithDashboard.dashboard_id]: report,
[report.id]: report,
},
};
}
if (result.chart) {
return {
...state,
charts: {
...state.chart,
[report.id]: report,
},
};
}
return {
...state,
charts: {
...state.chart,
[reportWithChart.chart.id]: report,
},
};
},

[EDIT_REPORT]() {
// Grab first matching report by matching dashboard id
const reportWithDashboard = action.json.result.find(
// FIX THESE, THEY'RE OBJECTS, NOT ARRAYS, NO FIND
const reportWithDashboard = action.json.result?.find(
report => !!report.dashboard_id,
);
// Assign the report's id
reportWithDashboard.id = action.json.id;

// Grab first matching report by matching chart id
const reportWithChart = action.json.result.find(
const reportWithChart = action.json.result?.find(
report => !!report.chart.id,
);
// Assign the report's id
Expand Down Expand Up @@ -148,7 +141,7 @@ export default function reportsReducer(state = {}, action) {
[DELETE_REPORT]() {
// Grabs the first report with a dashboard id that
// matches the parameter report's dashboard_id
const reportWithDashboard = action.report.result.find(
const reportWithDashboard = action.report.result?.find(
report => !!report.dashboard_id,
);

Expand Down

0 comments on commit 4e8fc02

Please sign in to comment.