Skip to content

Commit

Permalink
fix: update urls and job status - Ref gestion-de-projet#2002 (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
mouradsellam2 authored May 10, 2023
1 parent ad327ef commit 6e7e6ab
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/components/CreationCohort/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -143,7 +144,8 @@ const VersionRow: React.FC<{ requestId: string; cohortsList: Cohort[] }> = ({ re
<TableCell align="center">
{historyRow.fhir_group_id ? (
<Chip label="Terminé" style={{ backgroundColor: '#28a745', color: 'white' }} />
) : historyRow.request_job_status === 'pending' || historyRow.request_job_status === 'started' ? (
) : historyRow.request_job_status === JobStatus.pending ||
historyRow.request_job_status === JobStatus.new ? (
<Chip label="En cours" style={{ backgroundColor: '#ffc107', color: 'black' }} />
) : historyRow.request_job_fail_msg ? (
<Tooltip title={historyRow.request_job_fail_msg}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/SavedResearch/ResearchTable/ResearchTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -284,7 +285,7 @@ const ResearchTable: React.FC<ResearchTableProps> = ({
<TableCell onClick={() => _onClickRow(row)} align="center">
{row.request_job_status === 'finished' ? (
<Chip label="Terminé" size="small" style={{ backgroundColor: '#28a745', color: 'white' }} />
) : row.request_job_status === 'pending' || row.request_job_status === 'started' ? (
) : row.request_job_status === JobStatus.pending || row.request_job_status === JobStatus.new ? (
<Chip label="En cours" size="small" style={{ backgroundColor: '#ffc107', color: 'black' }} />
) : row.request_job_status === 'long_pending' ? (
<Tooltip title="Cohorte volumineuse: sa création est plus complexe et nécessite d'être placée dans une file d'attente. Un mail vous sera envoyé quand celle-ci sera disponible.">
Expand Down
2 changes: 1 addition & 1 deletion src/services/aphp/serviceCohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const servicesCohortCreation: IServiceCohortCreation = {
} else {
if (!requeteurJson || !snapshotId || !requestId) return null

const measureResult = await apiBack.post<any>('/cohort/dated-measures/create-unique/', {
const measureResult = await apiBack.post('/cohort/dated-measures/', {
request_query_snapshot_id: snapshotId,
request_id: requestId
})
Expand Down
5 changes: 3 additions & 2 deletions src/state/cohort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +66,7 @@ const fetchCohorts = createAsyncThunk<FetchCohortListReturn, FetchCohortsParams,
const forceRefresh = cohorts?.results?.some(
(cohortList) =>
!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) {
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions src/state/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -652,7 +653,7 @@ const cohortCreationSlice = createSlice({
unsuspendCount: (state: CohortCreationState) => {
state.count = {
...state.count,
status: 'pending'
status: JobStatus.pending
}
}
},
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum JobStatus {
new = 'new',
pending = 'pending',
suspended = 'suspended'
}

0 comments on commit 6e7e6ab

Please sign in to comment.