From 6e7e6ab126056a2fc53ff53240f51544c854d291 Mon Sep 17 00:00:00 2001 From: mourads <111437871+mouradsellam2@users.noreply.github.com> Date: Wed, 10 May 2023 15:34:10 +0200 Subject: [PATCH] fix: update urls and job status - Ref gestion-de-projet#2002 (#767) --- .../CreationCohort/ControlPanel/ControlPanel.tsx | 3 ++- .../ProjectTable/VersionRow/VersionRow.tsx | 8 +++++--- .../SavedResearch/ResearchTable/ResearchTable.tsx | 3 ++- src/services/aphp/serviceCohortCreation.ts | 2 +- src/state/cohort.ts | 5 +++-- src/state/cohortCreation.ts | 15 ++++++++++----- src/utils/constants.ts | 5 +++++ 7 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 src/utils/constants.ts diff --git a/src/components/CreationCohort/ControlPanel/ControlPanel.tsx b/src/components/CreationCohort/ControlPanel/ControlPanel.tsx index 38aa6dded..3e3e841a6 100644 --- a/src/components/CreationCohort/ControlPanel/ControlPanel.tsx +++ b/src/components/CreationCohort/ControlPanel/ControlPanel.tsx @@ -40,6 +40,7 @@ import useStyle from './styles' import displayDigit from 'utils/displayDigit' import { SHORT_COHORT_LIMIT } from '../../../constants' +import { JobStatus } from '../../../utils/constants' const ControlPanel: React.FC<{ onExecute?: (cohortName: string, cohortDescription: string, globalCount: boolean) => void @@ -150,7 +151,7 @@ const ControlPanel: React.FC<{ useEffect(() => { const interval = setInterval(() => { - if (count && count.status && (count.status === 'pending' || count.status === 'started')) { + if (count && count.status && (count.status === JobStatus.pending || count.status === JobStatus.new)) { dispatch(countCohortCreation({ uuid: count.uuid })) } else { clearInterval(interval) diff --git a/src/components/MyProjects/ProjectTable/VersionRow/VersionRow.tsx b/src/components/MyProjects/ProjectTable/VersionRow/VersionRow.tsx index faecdcf49..642768a36 100644 --- a/src/components/MyProjects/ProjectTable/VersionRow/VersionRow.tsx +++ b/src/components/MyProjects/ProjectTable/VersionRow/VersionRow.tsx @@ -33,6 +33,7 @@ import displayDigit from 'utils/displayDigit' import { ODD_EXPORT } from '../../../../constants' import useStyles from '../styles' +import { JobStatus } from '../../../../utils/constants' const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ requestId, cohortsList }) => { const classes = useStyles() @@ -104,8 +105,8 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re const isError = !historyRow.fhir_group_id || - historyRow.request_job_status === 'pending' || - historyRow.request_job_status === 'started' || + historyRow.request_job_status === JobStatus.pending || + historyRow.request_job_status === JobStatus.new || !!historyRow.request_job_fail_msg const canExportThisCohort = @@ -143,7 +144,8 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re {historyRow.fhir_group_id ? ( - ) : historyRow.request_job_status === 'pending' || historyRow.request_job_status === 'started' ? ( + ) : historyRow.request_job_status === JobStatus.pending || + historyRow.request_job_status === JobStatus.new ? ( ) : historyRow.request_job_fail_msg ? ( diff --git a/src/components/SavedResearch/ResearchTable/ResearchTable.tsx b/src/components/SavedResearch/ResearchTable/ResearchTable.tsx index 8c8bafe9b..1d0e7d91a 100644 --- a/src/components/SavedResearch/ResearchTable/ResearchTable.tsx +++ b/src/components/SavedResearch/ResearchTable/ResearchTable.tsx @@ -50,6 +50,7 @@ import displayDigit from 'utils/displayDigit' import { ODD_EXPORT } from '../../../constants' import useStyles from './styles' +import { JobStatus } from '../../../utils/constants' type FavStarProps = { favorite?: boolean @@ -284,7 +285,7 @@ const ResearchTable: React.FC = ({ _onClickRow(row)} align="center"> {row.request_job_status === 'finished' ? ( - ) : row.request_job_status === 'pending' || row.request_job_status === 'started' ? ( + ) : row.request_job_status === JobStatus.pending || row.request_job_status === JobStatus.new ? ( ) : row.request_job_status === 'long_pending' ? ( diff --git a/src/services/aphp/serviceCohortCreation.ts b/src/services/aphp/serviceCohortCreation.ts index 489a9d177..820da1e61 100644 --- a/src/services/aphp/serviceCohortCreation.ts +++ b/src/services/aphp/serviceCohortCreation.ts @@ -142,7 +142,7 @@ const servicesCohortCreation: IServiceCohortCreation = { } else { if (!requeteurJson || !snapshotId || !requestId) return null - const measureResult = await apiBack.post('/cohort/dated-measures/create-unique/', { + const measureResult = await apiBack.post('/cohort/dated-measures/', { request_query_snapshot_id: snapshotId, request_id: requestId }) diff --git a/src/state/cohort.ts b/src/state/cohort.ts index 5466c582e..7907ddc57 100644 --- a/src/state/cohort.ts +++ b/src/state/cohort.ts @@ -4,6 +4,7 @@ import { Cohort, CohortFilters, Sort } from 'types' import { logout, login } from './me' import services from 'services/aphp' +import { JobStatus } from '../utils/constants' export type CohortState = { loading: boolean @@ -65,7 +66,7 @@ const fetchCohorts = createAsyncThunk !cohortList.fhir_group_id && - (cohortList.request_job_status === 'pending' || cohortList.request_job_status === 'started') + (cohortList.request_job_status === JobStatus.pending || cohortList.request_job_status === JobStatus.new) ) if (forceRefresh) { @@ -122,7 +123,7 @@ const fetchCohortInBackGround = createAsyncThunk< cohortsList?.some( (cohort) => !cohort.fhir_group_id && - (cohort.request_job_status === 'pending' || cohort.request_job_status === 'started') + (cohort.request_job_status === JobStatus.pending || cohort.request_job_status === JobStatus.new) ) ) { const newResult = await services.projects.fetchCohortsList(filters, searchInput, sort, limit, offset) diff --git a/src/state/cohortCreation.ts b/src/state/cohortCreation.ts index 13de65e48..356fd938d 100644 --- a/src/state/cohortCreation.ts +++ b/src/state/cohortCreation.ts @@ -17,6 +17,7 @@ import { deleteProject } from './project' import services from 'services/aphp' import { SHORT_COHORT_LIMIT } from '../constants' +import { JobStatus } from '../utils/constants' export type CohortCreationState = { loading: boolean @@ -642,8 +643,8 @@ const cohortCreationSlice = createSlice({ state.count = { ...(state.count || {}), status: - (state.count || {}).status === 'pending' || - (state.count || {}).status === 'started' || + (state.count || {}).status === JobStatus.pending || + (state.count || {}).status === JobStatus.new || (state.count || {}).status === 'suspended' ? 'suspended' : (state.count || {}).status @@ -652,7 +653,7 @@ const cohortCreationSlice = createSlice({ unsuspendCount: (state: CohortCreationState) => { state.count = { ...state.count, - status: 'pending' + status: JobStatus.pending } } }, @@ -672,11 +673,15 @@ const cohortCreationSlice = createSlice({ builder.addCase(saveJson.fulfilled, (state, { payload }) => ({ ...state, ...payload, saveLoading: false })) builder.addCase(saveJson.rejected, (state) => ({ ...state, saveLoading: false })) // countCohortCreation - builder.addCase(countCohortCreation.pending, (state) => ({ ...state, status: 'pending', countLoading: true })) + builder.addCase(countCohortCreation.pending, (state) => ({ + ...state, + status: JobStatus.pending, + countLoading: true + })) builder.addCase(countCohortCreation.fulfilled, (state, { payload }) => ({ ...state, ...payload, - countLoading: payload?.count?.status === 'pending' || payload?.count?.status === 'started' + countLoading: payload?.count?.status === JobStatus.pending || payload?.count?.status === JobStatus.new })) builder.addCase(countCohortCreation.rejected, (state) => ({ ...state, diff --git a/src/utils/constants.ts b/src/utils/constants.ts new file mode 100644 index 000000000..086e35f32 --- /dev/null +++ b/src/utils/constants.ts @@ -0,0 +1,5 @@ +export enum JobStatus { + new = 'new', + pending = 'pending', + suspended = 'suspended' +}