williaster commented on a change in pull request #4791: apply new Dashboard 
builder to dashboard
URL: 
https://github.com/apache/incubator-superset/pull/4791#discussion_r180880942
 
 

 ##########
 File path: superset/assets/javascripts/dashboard/reducers/dashboard.js
 ##########
 @@ -0,0 +1,123 @@
+import d3 from 'd3';
+
+import * as actions from '../actions/dashboard';
+import { alterInArr, addToArr, removeFromArr } from '../../reduxUtils';
+
+export default function dashboard(state = {}, action) {
+  const actionHandlers = {
+    [actions.UPDATE_DASHBOARD_TITLE]() {
+      const newDashboard = { ...state.dashboard, dashboard_title: action.title 
};
+      return { ...state, dashboard: newDashboard };
+    },
+    [actions.ADD_SLICE]() {
+      const updatedSliceIds = new Set(state.dashboard.sliceIds);
+      updatedSliceIds.add(action.slice.slice_id);
+      return {
+        ...state,
+        dashboard: { ...state.dashboard, sliceIds: updatedSliceIds }
+      };
+    },
+    // [actions.UPDATE_DASHBOARD_LAYOUT]() {
+    //   const newDashboard = { ...state.dashboard, layout: action.layout };
+    //   return { ...state, dashboard: newDashboard };
+    // },
+    [actions.REMOVE_SLICE]() {
+      const sliceId = action.sliceId;
+      const updatedSliceIds = new Set(state.dashboard.sliceIds);
+      updatedSliceIds.delete(sliceId);
+
+      const key = String(sliceId);
+      // if this slice is a filter
+      const newFilter = { ...state.filters };
+      let refresh = false;
+      if (state.filters[key]) {
+        delete newFilter[key];
+        refresh = true;
+      }
+      return {
+        ...state,
+        dashboard: { ...state.dashboard, sliceIds: updatedSliceIds },
+        filters: newFilter,
+        refresh,
+      };
+    },
+    [actions.TOGGLE_FAVE_STAR]() {
+      return { ...state, isStarred: action.isStarred };
+    },
+    [actions.SET_EDIT_MODE]() {
+      return { ...state, editMode: action.editMode };
+    },
+    [actions.TOGGLE_BUILDER_PANE]() {
+      return { ...state, showBuilderPane: !state.showBuilderPane };
+    },
+    [actions.TOGGLE_EXPAND_SLICE]() {
+      const updatedExpandedSlices = { 
...state.dashboard.metadata.expanded_slices };
+      const sliceId = action.slice.slice_id;
+      if (action.isExpanded) {
+        updatedExpandedSlices[sliceId] = true;
+      } else {
+        delete updatedExpandedSlices[sliceId];
+      }
+      const metadata = { ...state.dashboard.metadata, expanded_slices: 
updatedExpandedSlices };
+      const newDashboard = { ...state.dashboard, metadata };
+      return { ...state, dashboard: newDashboard };
+    },
+    [actions.ON_CHANGE]() {
+      return { ...state, hasUnsavedChanges: true };
+    },
+    [actions.ON_SAVE]() {
+      return { ...state, hasUnsavedChanges: false };
+    },
+
+    // filters
+    [actions.ADD_FILTER]() {
+      const hasSelectedFilter = 
state.dashboard.sliceIds.has(action.chart.slice_id);
+      if (!hasSelectedFilter) {
+        return state;
+      }
+
+      let filters = state.filters;
+      const { chart, col, vals, merge, refresh } = action;
 
 Review comment:
   all of these should be under `action.payload`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to