You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by gi...@git.apache.org on 2017/10/12 23:24:36 UTC

[GitHub] mistercrunch commented on a change in pull request #3581: Dashboard refactory

mistercrunch commented on a change in pull request #3581: Dashboard refactory
URL: https://github.com/apache/incubator-superset/pull/3581#discussion_r144432255
 
 

 ##########
 File path: superset/assets/javascripts/dashboard/actions.js
 ##########
 @@ -0,0 +1,171 @@
+/* global notify */
+import $ from 'jquery';
+import { getExploreUrl } from '../explore/exploreUtils';
+
+export const ADD_FILTER = 'ADD_FILTER';
+export function addFilter(sliceId, col, vals, merge = true, refresh = true) {
+  return { type: ADD_FILTER, sliceId, col, vals, merge, refresh };
+}
+
+export const CLEAR_FILTER = 'CLEAR_FILTER';
+export function clearFilter(sliceId) {
+  return { type: CLEAR_FILTER, sliceId };
+}
+
+export const REMOVE_FILTER = 'REMOVE_FILTER';
+export function removeFilter(sliceId, col, vals) {
+  return { type: REMOVE_FILTER, sliceId, col, vals };
+}
+
+export const UPDATE_DASHBOARD_LAYOUT = 'UPDATE_DASHBOARD_LAYOUT';
+export function updateDashboardLayout(layout) {
+  return { type: UPDATE_DASHBOARD_LAYOUT, layout };
+}
+
+export const UPDATE_DASHBOARD_TITLE = 'UPDATE_DASHBOARD_TITLE';
+export function updateDashboardTitle(title) {
+  return { type: UPDATE_DASHBOARD_TITLE, title };
+}
+
+export function addSlicesToDashboard(dashboardId, sliceIds) {
+  return () => (
+    $.ajax({
+      type: 'POST',
+      url: `/superset/add_slices/${dashboardId}/`,
+      data: {
+        data: JSON.stringify({ slice_ids: sliceIds }),
+      },
+    }))
+    .done(() => {
+      // Refresh page to allow for slices to re-render
+      window.location.reload();
+    })
+    .fail(error => (error));
+}
+
+export const REMOVE_SLICE = 'REMOVE_SLICE';
+export function removeSlice(slice) {
+  return { type: REMOVE_SLICE, slice };
+}
+
+export const UPDATE_SLICE_NAME = 'UPDATE_SLICE_NAME';
+export function updateSliceName(slice, sliceName) {
+  return { type: UPDATE_SLICE_NAME, slice, sliceName };
+}
+export function saveSlice(slice, sliceName) {
+  const oldName = slice.slice_name;
+  return (dispatch) => {
+    const sliceParams = {};
+    sliceParams.slice_id = slice.slice_id;
+    sliceParams.action = 'overwrite';
+    sliceParams.slice_name = sliceName;
+    const saveUrl = getExploreUrl(slice.form_data, 'base', false, null, sliceParams);
+    return $.ajax({
+      url: saveUrl,
+      type: 'GET',
+      success: () => {
+        dispatch(updateSliceName(slice, sliceName));
+        notify.success('This slice name was saved successfully.');
+      },
+      error: () => {
+        // if server-side reject the overwrite action,
+        // revert to old state
+        dispatch(updateSliceName(slice, oldName));
+        notify.error('You don\'t have the rights to alter this slice');
+      },
+    });
+  };
+}
+
+export const UPDATE_SLICE_SQLQUERYVIEW = 'UPDATE_SLICE_SQLQUERYVIEW';
+export function updateSliceSqlQueryView(slice) {
+  return { type: UPDATE_SLICE_SQLQUERYVIEW, slice };
+}
+
+export const FETCH_SLICE_STARTED = 'FETCH_SLICE_STARTED';
+export function fetchSliceStarted(slice) {
+  return { type: FETCH_SLICE_STARTED, slice };
+}
+export const FETCH_SLICE_SUCCESS = 'FETCH_SLICE_SUCCESS';
+export function fetchSliceSuccess(slice, queryResponse) {
+  return { type: FETCH_SLICE_SUCCESS, slice, queryResponse };
+}
+export const FETCH_SLICE_FAIL = 'FETCH_SLICE_FAIL';
+export function fetchSliceFail(slice, errorResponse) {
+  return { type: FETCH_SLICE_FAIL, slice, errorResponse };
+}
+export const FETCH_SLICE_TIMEOUT = 'FETCH_SLICE_TIMEOUT';
+export function fetchSliceTimeout(slice, timeout) {
+  return { type: FETCH_SLICE_TIMEOUT, slice, timeout };
+}
+
+export function fetchSlice(slice, sliceUrl, timeout) {
 
 Review comment:
   We should share code with this location here:
   https://github.com/apache/incubator-superset/blob/master/superset/assets/javascripts/explore/actions/chartActions.js#L51
   
   Arguably all of chartActions and chartReducer should be in sync here.
   
   Ideally the components, actions, reducers and state are all bound together and reused in all places. The idea of refactoring `chartActions` out of `explore/actions` and `chartReducer` was that it could be reused here and wherever the ChartComponent is used
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services