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_r180884288
 
 

 ##########
 File path: superset/assets/javascripts/dashboard/reducers/index.js
 ##########
 @@ -0,0 +1,116 @@
+import { combineReducers } from 'redux';
+import shortid from 'shortid';
+
+import charts, { chart } from '../../chart/chartReducer';
+import dashboardReducer from './dashboard';
+import datasourcesReducer from './datasources';
+import allSlices, { initAllSlices } from './allSlices';
+import layoutReducer from '../v2/reducers/index';
+import messageToasts from '../v2/reducers/messageToasts';
+import { getParam } from '../../modules/utils';
+import layoutConverter from '../util/dashboardLayoutConverter';
+import { applyDefaultFormData } from '../../explore/stores/store';
+import { getColorFromScheme } from '../../modules/colors';
+
+export function getInitialState(bootstrapData) {
+  const { user_id, datasources, common } = bootstrapData;
+  delete common.locale;
+  delete common.language_pack;
+
+  const dashboard = { ...bootstrapData.dashboard_data };
+  let filters = {};
+  try {
+    // allow request parameter overwrite dashboard metadata
+    filters = JSON.parse(getParam('preselect_filters') || 
dashboard.metadata.default_filters);
+  } catch (e) {
+    //
+  }
+
+  // Priming the color palette with user's label-color mapping provided in
+  // the dashboard's JSON metadata
+  if (dashboard.metadata && dashboard.metadata.label_colors) {
+    const colorMap = dashboard.metadata.label_colors;
+    for (const label in colorMap) {
+      getColorFromScheme(label, null, colorMap[label]);
+    }
+  }
+
+  // dashboard layout
+  const position_json = dashboard.position_json;
+  let layout;
+  if (!position_json || !position_json['DASHBOARD_ROOT_ID']) {
+    layout = layoutConverter(dashboard);
+  } else {
+    layout = position_json;
+  }
+
+  const dashboardLayout = {
+    past: [],
+    present: layout,
+    future: [],
+  };
+  delete dashboard.position_json;
+  delete dashboard.css;
+
+  // charts and slices
+  const initCharts = {};
+  const slices = {};
+  dashboard.slices.forEach((slice) => {
+    const chartKey = 'slice_' + slice.slice_id;
 
 Review comment:
   why not just use `slice.slice_id` to prevent having to encode/decode in a 
fragile way everywhere?

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