1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× | /* global notify */ import $ from 'jquery'; import { getExploreUrlAndPayload } 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, refresh = true) { return { type: REMOVE_FILTER, sliceId, col, vals, refresh }; } 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(); }) ); } 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 { url, payload } = getExploreUrlAndPayload({ formData: slice.form_data, endpointType: 'base', force: false, curUrl: null, requestParams: sliceParams, }); return $.ajax({ url, type: 'POST', data: { form_data: JSON.stringify(payload), }, 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"); }, }); }; } const FAVESTAR_BASE_URL = '/superset/favstar/Dashboard'; export const TOGGLE_FAVE_STAR = 'TOGGLE_FAVE_STAR'; export function toggleFaveStar(isStarred) { return { type: TOGGLE_FAVE_STAR, isStarred }; } export const FETCH_FAVE_STAR = 'FETCH_FAVE_STAR'; export function fetchFaveStar(id) { return function (dispatch) { const url = `${FAVESTAR_BASE_URL}/${id}/count`; return $.get(url) .done((data) => { if (data.count > 0) { dispatch(toggleFaveStar(true)); } }); }; } export const SAVE_FAVE_STAR = 'SAVE_FAVE_STAR'; export function saveFaveStar(id, isStarred) { return function (dispatch) { const urlSuffix = isStarred ? 'unselect' : 'select'; const url = `${FAVESTAR_BASE_URL}/${id}/${urlSuffix}/`; $.get(url); dispatch(toggleFaveStar(!isStarred)); }; } export const TOGGLE_EXPAND_SLICE = 'TOGGLE_EXPAND_SLICE'; export function toggleExpandSlice(slice, isExpanded) { return { type: TOGGLE_EXPAND_SLICE, slice, isExpanded }; } export const SET_EDIT_MODE = 'SET_EDIT_MODE'; export function setEditMode(editMode) { return { type: SET_EDIT_MODE, editMode }; } |