-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explore] Split large reducer logic in ExploreViewContainer (#3088)
* split reducer logic for ExploreViewContainer * fix saveModal component and unit tests * revert changes in SaveModal_spec. will make another commit just to improve test coverage for SaveModal component. * remove comment-out code * fix merge confilicts
- Loading branch information
1 parent
08b7e89
commit b3107bb
Showing
14 changed files
with
364 additions
and
329 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
superset/assets/javascripts/explore/actions/chartActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { getExploreUrl } from '../exploreUtils'; | ||
import { getFormDataFromControls } from '../stores/store'; | ||
import { QUERY_TIMEOUT_THRESHOLD } from '../../constants'; | ||
import { triggerQuery } from './exploreActions'; | ||
|
||
const $ = window.$ = require('jquery'); | ||
|
||
export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED'; | ||
export function chartUpdateStarted(queryRequest, latestQueryFormData) { | ||
return { type: CHART_UPDATE_STARTED, queryRequest, latestQueryFormData }; | ||
} | ||
|
||
export const CHART_UPDATE_SUCCEEDED = 'CHART_UPDATE_SUCCEEDED'; | ||
export function chartUpdateSucceeded(queryResponse) { | ||
return { type: CHART_UPDATE_SUCCEEDED, queryResponse }; | ||
} | ||
|
||
export const CHART_UPDATE_STOPPED = 'CHART_UPDATE_STOPPED'; | ||
export function chartUpdateStopped(queryRequest) { | ||
if (queryRequest) { | ||
queryRequest.abort(); | ||
} | ||
return { type: CHART_UPDATE_STOPPED }; | ||
} | ||
|
||
export const CHART_UPDATE_TIMEOUT = 'CHART_UPDATE_TIMEOUT'; | ||
export function chartUpdateTimeout(statusText) { | ||
return { type: CHART_UPDATE_TIMEOUT, statusText }; | ||
} | ||
|
||
export const CHART_UPDATE_FAILED = 'CHART_UPDATE_FAILED'; | ||
export function chartUpdateFailed(queryResponse) { | ||
return { type: CHART_UPDATE_FAILED, queryResponse }; | ||
} | ||
|
||
export const UPDATE_CHART_STATUS = 'UPDATE_CHART_STATUS'; | ||
export function updateChartStatus(status) { | ||
return { type: UPDATE_CHART_STATUS, status }; | ||
} | ||
|
||
export const CHART_RENDERING_FAILED = 'CHART_RENDERING_FAILED'; | ||
export function chartRenderingFailed(error) { | ||
return { type: CHART_RENDERING_FAILED, error }; | ||
} | ||
|
||
export const RUN_QUERY = 'RUN_QUERY'; | ||
export function runQuery(formData, force = false) { | ||
return function (dispatch, getState) { | ||
const { explore } = getState(); | ||
const lastQueryFormData = getFormDataFromControls(explore.controls); | ||
const url = getExploreUrl(formData, 'json', force); | ||
const queryRequest = $.ajax({ | ||
url, | ||
dataType: 'json', | ||
success(queryResponse) { | ||
dispatch(chartUpdateSucceeded(queryResponse)); | ||
}, | ||
error(err) { | ||
if (err.statusText === 'timeout') { | ||
dispatch(chartUpdateTimeout(err.statusText)); | ||
} else if (err.statusText !== 'abort') { | ||
dispatch(chartUpdateFailed(err.responseJSON)); | ||
} | ||
}, | ||
timeout: QUERY_TIMEOUT_THRESHOLD, | ||
}); | ||
dispatch(chartUpdateStarted(queryRequest, lastQueryFormData)); | ||
dispatch(triggerQuery(false)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
superset/assets/javascripts/explore/actions/saveModalActions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const $ = window.$ = require('jquery'); | ||
|
||
export const FETCH_DASHBOARDS_SUCCEEDED = 'FETCH_DASHBOARDS_SUCCEEDED'; | ||
export function fetchDashboardsSucceeded(choices) { | ||
return { type: FETCH_DASHBOARDS_SUCCEEDED, choices }; | ||
} | ||
|
||
export const FETCH_DASHBOARDS_FAILED = 'FETCH_DASHBOARDS_FAILED'; | ||
export function fetchDashboardsFailed(userId) { | ||
return { type: FETCH_DASHBOARDS_FAILED, userId }; | ||
} | ||
|
||
export function fetchDashboards(userId) { | ||
return function (dispatch) { | ||
const url = '/dashboardmodelviewasync/api/read?_flt_0_owners=' + userId; | ||
return $.ajax({ | ||
type: 'GET', | ||
url, | ||
success: (data) => { | ||
const choices = []; | ||
for (let i = 0; i < data.pks.length; i++) { | ||
choices.push({ value: data.pks[i], label: data.result[i].dashboard_title }); | ||
} | ||
dispatch(fetchDashboardsSucceeded(choices)); | ||
}, | ||
error: () => { | ||
dispatch(fetchDashboardsFailed(userId)); | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
export const SAVE_SLICE_FAILED = 'SAVE_SLICE_FAILED'; | ||
export function saveSliceFailed() { | ||
return { type: SAVE_SLICE_FAILED }; | ||
} | ||
export const SAVE_SLICE_SUCCESS = 'SAVE_SLICE_SUCCESS'; | ||
export function saveSliceSuccess(data) { | ||
return { type: SAVE_SLICE_SUCCESS, data }; | ||
} | ||
|
||
export const REMOVE_SAVE_MODAL_ALERT = 'REMOVE_SAVE_MODAL_ALERT'; | ||
export function removeSaveModalAlert() { | ||
return { type: REMOVE_SAVE_MODAL_ALERT }; | ||
} | ||
|
||
export function saveSlice(url) { | ||
return function (dispatch) { | ||
return $.get(url, (data, status) => { | ||
if (status === 'success') { | ||
dispatch(saveSliceSuccess(data)); | ||
} else { | ||
dispatch(saveSliceFailed()); | ||
} | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.