From 3137cba5095cda15e878f7505eb378f4cc8d23fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Garc=C3=ADa=20Isa=C3=ADa?= Date: Wed, 2 Oct 2024 18:08:07 -0300 Subject: [PATCH] Fetch files status upon Downloads dialog load See #2350 --- assets/js/actions/survey.js | 22 +++++++++++++++++++ assets/js/api.js | 3 +++ .../respondents/RespondentIndex.jsx | 10 ++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/assets/js/actions/survey.js b/assets/js/actions/survey.js index 087aba8c9..5a1f683d5 100644 --- a/assets/js/actions/survey.js +++ b/assets/js/actions/survey.js @@ -45,6 +45,8 @@ export const DELETE_LINK = "SURVEY_DELETE_LINK" export const RECEIVE_SURVEY_STATS = "RECEIVE_SURVEY_STATS" export const RECEIVE_SURVEY_RETRIES_HISTOGRAMS = "RECEIVE_SURVEY_RETRIES_HISTOGRAMS" export const GENERATING_FILE = "GENERATING_FILE" +export const FETCHING_FILES_STATUS = "FETCHING_FILES_STATUS" +export const RECEIVE_FILES_STATUS = "RECEIVE_FILES_STATUS" export const createSurvey = (projectId: number, folderId?: number) => (dispatch: Function, getState: () => Store) => @@ -455,6 +457,26 @@ export const deleteDispositionHistoryLink = }) } +export const fetchingRespondentFilesStatus = (projectId: number, surveyId: number) => ({ + type: FETCHING_FILES_STATUS, + projectId, + surveyId, +}) + +export const receiveRespondentsFilesStatus = (projectId: number, surveyId: number, files) => ({ + type: RECEIVE_FILES_STATUS, + projectId, + surveyId, + files, +}) + +export const fetchRespondentsFilesStatus = (projectId: number, surveyId: number, filter?: string) => (dispatch: Function) => { + dispatch(fetchingRespondentFilesStatus(projectId, surveyId)) + api.fetchRespondentsFilesStatus(projectId, surveyId, filter).then((response) => { + dispatch(receiveRespondentsFilesStatus(projectId, surveyId, response.files)) + }) +} + export const generateResultsFile = (projectId: number, surveyId: number, filter?: string) => (dispatch: Function) => { api.generateResults(projectId, surveyId, filter).then((response) => { diff --git a/assets/js/api.js b/assets/js/api.js index 253bb76ce..2c841b15f 100644 --- a/assets/js/api.js +++ b/assets/js/api.js @@ -711,6 +711,9 @@ export const generateIncentives = (projectId, surveyId) => export const generateInteractions = (projectId, surveyId) => apiPostJSON(`projects/${projectId}/surveys/${surveyId}/respondents/interactions`, null, null) +export const fetchRespondentsFilesStatus = (projectId, surveyId, filter) => + apiFetch(`projects/${projectId}/surveys/${surveyId}/respondents/files?q=${filter}`).then((response) => response.json()) + export const startSimulation = (projectId, questionnaireId, mode) => { return apiPutOrPostJSONWithCallback( `projects/${projectId}/questionnaires/${questionnaireId}/simulation`, diff --git a/assets/js/components/respondents/RespondentIndex.jsx b/assets/js/components/respondents/RespondentIndex.jsx index fff846b1b..a49e26efc 100644 --- a/assets/js/components/respondents/RespondentIndex.jsx +++ b/assets/js/components/respondents/RespondentIndex.jsx @@ -111,6 +111,14 @@ class RespondentIndex extends Component { ) } + showDownloadsModal() { + const { projectId, surveyId, filter } = this.props + + // FIXME: don't fetch if we're already fetching + this.props.surveyActions.fetchRespondentsFilesStatus(projectId, surveyId, filter) + $('#downloadCSV').modal("open") + } + nextPage() { const { pageNumber } = this.props this.fetchRespondents(pageNumber + 1) @@ -713,7 +721,7 @@ class RespondentIndex extends Component { __html: "", }} /> - $('#downloadCSV').modal("open")}/> + this.showDownloadsModal()} /> {this.downloadModal()} {this.renderColumnPickerModal()} {this.respondentsFilter()}