Skip to content

Commit

Permalink
Fetch files status upon Downloads dialog load
Browse files Browse the repository at this point in the history
See #2350
  • Loading branch information
matiasgarciaisaia committed Oct 2, 2024
1 parent a2fa8a1 commit 3137cba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
22 changes: 22 additions & 0 deletions assets/js/actions/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions assets/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
10 changes: 9 additions & 1 deletion assets/js/components/respondents/RespondentIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ class RespondentIndex extends Component<Props, State> {
)
}

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)
Expand Down Expand Up @@ -713,7 +721,7 @@ class RespondentIndex extends Component<Props, State> {
__html: "<style> body { overflow-y: auto !important; color: black}</style>",
}}
/>
<MainAction text="Downloads" icon="get_app" onClick={() => $('#downloadCSV').modal("open")}/>
<MainAction text="Downloads" icon="get_app" onClick={() => this.showDownloadsModal()} />
{this.downloadModal()}
{this.renderColumnPickerModal()}
{this.respondentsFilter()}
Expand Down

0 comments on commit 3137cba

Please sign in to comment.