From 299f2a3be4184b674589c4737b888ecd4d5cb161 Mon Sep 17 00:00:00 2001 From: Paul Bui-Quang Date: Thu, 6 Jul 2023 19:15:45 +0200 Subject: [PATCH] fix(scopetree): limit expand to min scope type --- .../PopulationCard/PopulationCard.tsx | 5 ++-- .../components/PopulationRightPanel.tsx | 4 +-- src/components/ScopeTree/ScopeTree.tsx | 8 +++--- src/services/aphp/servicePerimeters.ts | 27 +++++++++---------- src/state/scope.ts | 10 +++---- src/types.ts | 8 ++++++ 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx b/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx index 42bc3831f..c8af6a6e9 100644 --- a/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx +++ b/src/components/CreationCohort/DiagramView/components/PopulationCard/PopulationCard.tsx @@ -14,8 +14,9 @@ import { buildCohortCreation, CohortCreationState } from 'state/cohortCreation' import { fetchScopesList, ScopeState } from 'state/scope' import { MeState } from 'state/me' -import { CriteriaNameType, ScopeTreeRow } from 'types' +import { CriteriaNameType, ScopeType, ScopeTreeRow } from 'types' import { getSelectedScopes } from 'utils/scopeTree' +import scopeTypes from 'data/scope_type.json' import useStyles from './styles' @@ -221,7 +222,7 @@ const PopulationCard: React.FC = (props) => { title={title} isAcceptEmptySelection={isAcceptEmptySelection} selectedPopulation={selectedItems} - executiveUnitType={form ?? undefined} + executiveUnitType={form ? (scopeTypes.criteriaType[form] as ScopeType) : undefined} onConfirm={_onSubmit} onClose={() => onChangeOpenDrawer(false)} /> diff --git a/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx b/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx index b28f05be9..e81e718e6 100644 --- a/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx +++ b/src/components/CreationCohort/DiagramView/components/PopulationCard/components/PopulationRightPanel.tsx @@ -5,7 +5,7 @@ import Drawer from '@mui/material/Drawer' import Typography from '@mui/material/Typography' import ScopeTree from 'components/ScopeTree/ScopeTree' -import { CriteriaNameType, ScopeTreeRow } from 'types' +import { ScopeType, ScopeTreeRow } from 'types' import useStyles from './styles' import ScopeSearchBar from 'components/Inputs/ScopeSearchBar/ScopeSearchBar' @@ -13,7 +13,7 @@ import ScopeSearchBar from 'components/Inputs/ScopeSearchBar/ScopeSearchBar' type PopulationRightPanelProps = { open: boolean title?: string - executiveUnitType?: CriteriaNameType + executiveUnitType?: ScopeType selectedPopulation: ScopeTreeRow[] isAcceptEmptySelection?: boolean onConfirm: (selectedPopulation: ScopeTreeRow[]) => void diff --git a/src/components/ScopeTree/ScopeTree.tsx b/src/components/ScopeTree/ScopeTree.tsx index e5eba67dd..f8c36e61d 100644 --- a/src/components/ScopeTree/ScopeTree.tsx +++ b/src/components/ScopeTree/ScopeTree.tsx @@ -21,7 +21,7 @@ import { import KeyboardArrowRightIcon from '@mui/icons-material/ChevronRight' import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' import EnhancedTable from 'components/ScopeTree/ScopeTreeTable' -import { CriteriaNameType, ScopeTreeRow, TreeElement } from 'types' +import { ScopeType, ScopeTreeRow, TreeElement } from 'types' import { useAppDispatch, useAppSelector } from 'state' import { expandScopeElement, fetchScopesList, ScopeState, updateScopeList } from 'state/scope' @@ -91,7 +91,7 @@ const ScopeTreeListItem: React.FC = (props) => { }} > - {row.subItems && row.subItems.length > 0 && ( + {row.subItems && row.subItems.length > 0 && row.type !== executiveUnitType && ( onExpand(row.id)} style={{ marginLeft: level * 35, padding: 0, marginRight: -30 }} @@ -150,7 +150,7 @@ type ScopeTreeProps = { defaultSelectedItems: ScopeTreeRow[] onChangeSelectedItem: (selectedItems: ScopeTreeRow[]) => void searchInput: string - executiveUnitType?: CriteriaNameType + executiveUnitType?: ScopeType } const ScopeTree: React.FC = ({ @@ -189,7 +189,7 @@ const ScopeTree: React.FC = ({ const isHeadIndetermined: boolean = !isAllSelected && selectedItems && selectedItems.length > 0 && rootRows && !isHeadChecked - const fetchScopeTree = async (executiveUnitType?: CriteriaNameType, signal?: AbortSignal) => { + const fetchScopeTree = async (executiveUnitType?: ScopeType, signal?: AbortSignal) => { return dispatch(fetchScopesList({ signal, type: executiveUnitType })).unwrap() } diff --git a/src/services/aphp/servicePerimeters.ts b/src/services/aphp/servicePerimeters.ts index 76430656c..491aa54e9 100644 --- a/src/services/aphp/servicePerimeters.ts +++ b/src/services/aphp/servicePerimeters.ts @@ -6,7 +6,7 @@ import { ScopeTreeRow, ScopeElement, ChartCode, - CriteriaNameType + ScopeType } from 'types' import { getAgeRepartitionMapAphp, @@ -74,7 +74,7 @@ export interface IServicePerimeters { defaultPerimetersIds?: string[], cohortIds?: string[], noPerimetersIdsFetch?: boolean, - type?: CriteriaNameType, + type?: ScopeType, signal?: AbortSignal ) => Promise @@ -89,7 +89,7 @@ export interface IServicePerimeters { * Retour: * - ScopeTreeRow[] */ - getScopePerimeters: (practitionerId: string, type?: CriteriaNameType, signal?: AbortSignal) => Promise + getScopePerimeters: (practitionerId: string, type?: ScopeType, signal?: AbortSignal) => Promise /** * Cette fonction retoune l'ensemble des périmètres enfant d'un périmètre passé en argument @@ -104,7 +104,7 @@ export interface IServicePerimeters { getScopesWithSubItems: ( subScopesIds: string | null | undefined, getSubItem?: boolean, - type?: CriteriaNameType, + type?: ScopeType, signal?: AbortSignal ) => Promise @@ -126,7 +126,7 @@ export interface IServicePerimeters { buildScopeTreeRowList: ( subScopes: ScopePage[], getSubItem?: boolean | undefined, - type?: CriteriaNameType, + type?: ScopeType, signal?: AbortSignal ) => Promise @@ -148,7 +148,7 @@ export interface IServicePerimeters { * construire la liste des types des périmètres en haut du type. Sinon tous les types. * @param type */ - getHigherTypes: (type?: CriteriaNameType) => string[] + getHigherTypes: (type?: ScopeType) => string[] } const servicesPerimeters: IServicePerimeters = { @@ -256,7 +256,7 @@ const servicesPerimeters: IServicePerimeters = { defaultPerimetersIds?: string[], cohortIds?: string[], noPerimetersIdsFetch?: boolean, - type?: CriteriaNameType, + type?: ScopeType, signal?: AbortSignal ) => { try { @@ -331,7 +331,7 @@ const servicesPerimeters: IServicePerimeters = { } }, - getScopePerimeters: async (practitionerId, type?: CriteriaNameType, signal?: AbortSignal) => { + getScopePerimeters: async (practitionerId, type?: ScopeType, signal?: AbortSignal) => { if (!practitionerId) return [] const scopeItemList: ScopePage[] = @@ -348,7 +348,7 @@ const servicesPerimeters: IServicePerimeters = { getScopesWithSubItems: async ( subScopesIds: string | null | undefined, getSubItem?: boolean, - type?: CriteriaNameType, + type?: ScopeType, signal?: AbortSignal ) => { if (!subScopesIds) return [] @@ -435,7 +435,7 @@ const servicesPerimeters: IServicePerimeters = { buildScopeTreeRowList: async ( subScopes: ScopePage[], getSubItem?: boolean | undefined, - type?: CriteriaNameType, + type?: ScopeType, signal?: AbortSignal ) => { let scopeRowList: ScopeTreeRow[] = [] @@ -485,18 +485,17 @@ const servicesPerimeters: IServicePerimeters = { return `${perimeterID} - ${perimeter.name}` }, - getHigherTypes: (type?: CriteriaNameType) => { + getHigherTypes: (type?: ScopeType) => { if (!type) { return scopeTypes.typeLevel.flat() } const higherTypes: string[] = [] - const scopeType = scopeTypes.criteriaType[type] - if (scopeType) { + if (type) { let isFoundValue = false for (const currentLevel of [...scopeTypes.typeLevel].reverse()) { for (const valueInTheSameLevel of currentLevel) { - if (valueInTheSameLevel === scopeType) { + if (valueInTheSameLevel === type) { isFoundValue = true } if (isFoundValue) { diff --git a/src/state/scope.ts b/src/state/scope.ts index a7007478c..deb5c9e9c 100644 --- a/src/state/scope.ts +++ b/src/state/scope.ts @@ -5,7 +5,7 @@ import { logout, login } from './me' import services from 'services/aphp' -import { CriteriaNameType, ScopeTreeRow } from 'types' +import { ScopeType, ScopeTreeRow } from 'types' export type ScopeState = { loading: boolean @@ -27,7 +27,7 @@ type FetchScopeListReturn = { } type FetchScopeListArgs = { - type?: CriteriaNameType + type?: ScopeType signal?: AbortSignal | undefined } @@ -58,7 +58,7 @@ const fetchScopesList = createAsyncThunk { + const replaceSubItems = async (items: ScopeTreeRow[], type?: ScopeType) => { let _items: ScopeTreeRow[] = [] for (let item of items) { // Replace sub items element by response of back-end diff --git a/src/types.ts b/src/types.ts index afbbaf85f..37cb323d1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -881,6 +881,14 @@ export type AgeRangeType = { days?: number } +export type ScopeType = + | 'AP-HP' + | 'Groupe hospitalier (GH)' + | 'GHU' + | 'Hôpital' + | 'Pôle/DMU' + | 'Unité Fonctionnelle (UF)' + export enum CriteriaName { Cim10 = 'cim10', Ccam = 'ccam',