Skip to content

Commit

Permalink
refactor: refacto some selectors with same result but different refer…
Browse files Browse the repository at this point in the history
…ence - Ref gestion-de-projet#2410
  • Loading branch information
Mehdi-BOUYAHIA authored Dec 11, 2023
1 parent 501d4e6 commit b30ec03
Show file tree
Hide file tree
Showing 40 changed files with 103 additions and 280 deletions.
19 changes: 3 additions & 16 deletions src/components/CohortsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ import ModalEditCohort from 'components/Requests/Modals/ModalEditCohort/ModalEdi
import ExportModal from 'components/Dashboard/ExportModal/ExportModal'

import { useAppSelector, useAppDispatch } from 'state'
import { CohortState, deleteCohort, editCohort, setSelectedCohort as setSelectedCohortState } from 'state/cohort'

import { MeState } from 'state/me'
import { deleteCohort, editCohort, setSelectedCohort as setSelectedCohortState } from 'state/cohort'

import { Cohort, CohortJobStatus } from 'types'

Expand Down Expand Up @@ -97,19 +95,8 @@ const ResearchTable: React.FC<ResearchTableProps> = ({
const [anchorEl, setAnchorEl] = React.useState(null)
const openMenuItem = Boolean(anchorEl)

const { cohortState } = useAppSelector<{
cohortState: CohortState
}>((state) => ({
cohortState: state.cohort
}))
const selectedCohortState = cohortState.selectedCohort

const { meState } = useAppSelector<{
meState: MeState
}>((state) => ({
meState: state.me
}))

const selectedCohortState = useAppSelector((state) => state.cohort.selectedCohort)
const meState = useAppSelector((state) => state.me)
const maintenanceIsActive = meState?.maintenance?.active

const onClickRow = (row: any) => {
Expand Down
4 changes: 1 addition & 3 deletions src/components/CreationCohort/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
unbuildCohortCreation,
addActionToNavHistory
} from 'state/cohortCreation'
import { MeState } from 'state/me'

import { CohortCreationCounterType, CurrentSnapshot, RequestType, SimpleStatus, Snapshot } from 'types'

Expand Down Expand Up @@ -91,8 +90,7 @@ const ControlPanel: React.FC<{
uuid: ''
})

const { meState } = useAppSelector<{ meState: MeState }>((state) => ({ meState: state.me }))
const maintenanceIsActive = meState?.maintenance?.active
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active ?? false)

const cohortLimit = shortCohortLimit ?? SHORT_COHORT_LIMIT

Expand Down
5 changes: 1 addition & 4 deletions src/components/CreationCohort/DiagramView/DiagramView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import TemporalConstraintCard from './components/TemporalConstraintCard/Temporal
import CohortCreationBreadcrumbs from './components/Breadcrumbs/Breadcrumbs'

import { useAppSelector } from 'state'
import { MeState } from 'state/me'

import useStyles from './styles'

const DiagramView: React.FC = () => {
const { selectedPopulation = [] } = useAppSelector((state) => state.cohortCreation.request || {})
const { meState } = useAppSelector<{ meState: MeState }>((state) => ({ meState: state.me }))

const maintenanceIsActive = meState?.maintenance?.active
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active ?? false)

const { classes } = useStyles()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,10 @@ const CohortCreationBreadcrumbs: React.FC = () => {
const theme = useTheme()
const dispatch = useAppDispatch()

const {
request: { requestId, currentSnapshot },
projects = [],
requests = []
} = useAppSelector(
(state) =>
({
request: state.cohortCreation.request,
projects: state.project.projectsList,
requests: state.request.requestsList
} || {
request: { requestId: null, currentSnapshot: [] },
projects: [],
requests: []
})
)
const { requestId, currentSnapshot } = useAppSelector((state) => state.cohortCreation.request || {})
const projects = useAppSelector((state) => state.project.projectsList || [])
const requests = useAppSelector((state) => state.request.requestsList || [])

const [projectName, setProjectName] = useState('Projet de recherche')
const [requestName, setRequestName] = useState('Requête')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'

import { useAppSelector } from 'state'
import { MeState } from 'state/me'

import useStyles from './styles'
import { criteriasAsArray } from 'utils/requestCriterias'
Expand All @@ -29,10 +28,8 @@ type CriteriaCardProps = {
const CriteriaCard = ({ criterion, duplicateCriteria, editCriteria, deleteCriteria }: CriteriaCardProps) => {
const { classes } = useStyles()

const { meState } = useAppSelector<{ meState: MeState }>((state) => ({ meState: state.me }))
const { criteria } = useAppSelector((state) => state.cohortCreation)

const maintenanceIsActive = meState?.maintenance?.active
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active || false)

const [needCollapse, setNeedCollapse] = useState(false)
const [openCollapse, setOpenCollapse] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
suspendCount,
unsuspendCount
} from 'state/cohortCreation'
import { MeState } from 'state/me'

import useStyles from './styles'
import { SelectedCriteriaType } from 'types/requestCriterias'
Expand All @@ -50,8 +49,7 @@ const OperatorItem: React.FC<OperatorItemProps> = ({
const { request } = useAppSelector((state) => state.cohortCreation || {})
const { loading = false, criteriaGroup = [], selectedCriteria = [] } = request

const { meState } = useAppSelector<{ meState: MeState }>((state) => ({ meState: state.me }))
const maintenanceIsActive = meState?.maintenance?.active
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active ?? false)

const displayingItem = criteriaGroup.filter((_criteriaGroup: CriteriaGroupType) => _criteriaGroup.id === itemId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ const RequestForm: React.FC<CriteriaDrawerComponentProps> = ({ parentId, goBack
const { classes } = useStyles()
const dispatch = useAppDispatch()

const { projectState, requestState } = useAppSelector((state) => ({
projectState: state.project,
requestState: state.request
}))

const projectsList = projectState.projectsList ?? []
const requestsList = requestState.requestsList ?? []
const projectsList = useAppSelector((state) => state.project.projectsList || [])
const requestsList = useAppSelector((state) => state.request.requestsList || [])

const [selectedRequestId, setSelectedRequest] = useState<string | null>(null)
const [error, setError] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import ModalRightError from './components/ModalRightError'
import PopulationRightPanel from './components/PopulationRightPanel'

import { useAppDispatch, useAppSelector } from 'state'
import { buildCohortCreation, CohortCreationState } from 'state/cohortCreation'
import { fetchScopesList, ScopeState } from 'state/scope'
import { MeState } from 'state/me'
import { buildCohortCreation } from 'state/cohortCreation'
import { fetchScopesList } from 'state/scope'

import { CriteriaNameType, ScopeType, ScopeTreeRow } from 'types'
import scopeTypes from 'data/scope_type.json'
Expand All @@ -37,21 +36,9 @@ const PopulationCard: React.FC<PopulationCardPropsType> = (props) => {
const dispatch = useAppDispatch()
const isRendered = useRef<boolean>(false)

const {
request: { selectedPopulation = [], ...requestState },
scopeState,
meState
} = useAppSelector<{
request: CohortCreationState
scopeState: ScopeState
meState: MeState
}>((state) => ({
request: state.cohortCreation.request || {},
scopeState: state.scope || {},
meState: state.me
}))

const maintenanceIsActive = meState?.maintenance?.active
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active ?? false)
const scopeState = useAppSelector((state) => state.scope || {})
const { selectedPopulation = [], ...requestState } = useAppSelector((state) => state.cohortCreation.request || {})

const isExecutiveUnit: boolean = !!(form ? (scopeTypes.criteriaType[form] as ScopeType) : undefined) ?? false
const scopesList = getCurrentScopeList(scopeState.scopesList, isExecutiveUnit) ?? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import DialogContentText from '@mui/material/DialogContentText'
import DialogTitle from '@mui/material/DialogTitle'

import { useAppSelector } from 'state'
import { MeState } from 'state/me'

type ModalRightErrorProps = {
open: boolean
handleClose: () => void
}
const ModalRightError: React.FC<ModalRightErrorProps> = ({ open, handleClose }) => {
const { meState } = useAppSelector<{ meState: MeState }>((state) => ({ meState: state.me }))
const maintenanceIsActive = meState?.maintenance?.active
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active ?? false)

const navigate = useNavigate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Button, Badge, Tooltip } from '@mui/material'

import { buildCohortCreation, deleteTemporalConstraint } from 'state/cohortCreation'
import { useAppSelector, useAppDispatch } from 'state'
import { MeState } from 'state/me'

import TemporalConstraintModal from './components/TemporalConstraintModal/TemporalConstraintModal'

Expand All @@ -16,15 +15,13 @@ const TemporalConstraint: React.FC = () => {
const [temporalConstraintExist, setTemporalConstraintExist] = useState(false)
const [disableTemporalConstraint, setDisableTemporalConstraint] = useState(false)

const { meState } = useAppSelector<{ meState: MeState }>((state) => ({ meState: state.me }))
const maintenanceIsActive = useAppSelector((state) => state.me?.maintenance?.active ?? false)
const {
criteriaGroup = [],
temporalConstraints,
selectedCriteria
} = useAppSelector((state) => state.cohortCreation.request)

const maintenanceIsActive = meState?.maintenance?.active || false

const findInitialStateRadio = temporalConstraints.find(({ idList }) => idList[0] === 'All')
const temporalConstraintsNumber =
findInitialStateRadio?.constraintType === TemporalConstraintsKind.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { RequestType } from 'types'
import services from 'services/aphp'

import { useAppSelector, useAppDispatch } from 'state'
import { ProjectState, fetchProjects } from 'state/project'
import { RequestState, fetchRequests, addRequest, editRequest, deleteRequest } from 'state/request'
import { fetchProjects } from 'state/project'
import { fetchRequests, addRequest, editRequest, deleteRequest } from 'state/request'
import { fetchRequestCohortCreation } from 'state/cohortCreation'

const ERROR_TITLE = 'error_title'
Expand All @@ -37,16 +37,11 @@ const ModalCreateNewRequest: React.FC<{
}> = ({ onClose }) => {
const navigate = useNavigate()
const dispatch = useAppDispatch()
const { projectState, requestState } = useAppSelector<{
projectState: ProjectState
requestState: RequestState
}>((state) => ({
projectState: state.project,
requestState: state.request
}))

const requestState = useAppSelector((state) => state.request)
const _projectsList = useAppSelector((state) => state.project.projectsList)

const { requestsList, selectedRequest } = requestState
const { projectsList } = projectState

const isEdition = selectedRequest ? selectedRequest.uuid : false

Expand All @@ -71,8 +66,8 @@ const ModalCreateNewRequest: React.FC<{

const _fetchProject = async () => {
let projectsList = []
if (projectState && projectState.projectsList && projectState.projectsList.length > 0) {
projectsList = projectState.projectsList
if (_projectsList && _projectsList.length > 0) {
projectsList = _projectsList
} else {
const myProjects = (await dispatch(fetchProjects()).unwrap()) || []
projectsList = myProjects.projectsList
Expand Down Expand Up @@ -200,11 +195,11 @@ const ModalCreateNewRequest: React.FC<{
error={error}
projectName={projectName}
onChangeProjectName={onChangeProjectName}
projectList={projectsList}
projectList={_projectsList}
/>
) : (
<RequestList
projectList={projectsList}
projectList={_projectsList}
requestsList={requestsList}
selectedItem={openRequest}
onSelectedItem={(newOpenRequest: string) =>
Expand Down
25 changes: 10 additions & 15 deletions src/components/CreationCohort/Requeteur.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@ import { setCriteriaData } from 'state/criteria'

const Requeteur = () => {
const {
request: {
loading = false,
requestId = '',
currentSnapshot = {} as CurrentSnapshot,
navHistory,
selectedCriteria = [],
count = {},
json = '',
allowSearchIpp = false
},
criteriaData
} = useAppSelector((state) => ({
request: state.cohortCreation.request || {},
criteriaData: state.cohortCreation.criteria || {}
}))
loading = false,
requestId = '',
currentSnapshot = {} as CurrentSnapshot,
navHistory,
selectedCriteria = [],
count = {},
json = '',
allowSearchIpp = false
} = useAppSelector((state) => state.cohortCreation.request || {})
const criteriaData = useAppSelector((state) => state.cohortCreation.criteria || {})

const params = useParams<{
requestId: string
Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorView/CohortNoPatient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CohortNoPatient = () => {
const { classes, cx } = useStyles()
const navigate = useNavigate()

const { openDrawer } = useAppSelector((state) => ({ openDrawer: state.drawer }))
const openDrawer = useAppSelector((state) => state.drawer)

return (
<Grid
Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorView/PatientNotExist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const PatientNotExist = () => {
const { classes, cx } = useStyles()
const navigate = useNavigate()

const { openDrawer } = useAppSelector((state) => ({ openDrawer: state.drawer }))
const openDrawer = useAppSelector((state) => state.drawer)

return (
<Grid
Expand Down
4 changes: 1 addition & 3 deletions src/components/Patient/PatientBiology/PatientBiology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ type PatientBiologyProps = {
const PatientBiology = ({ groupId }: PatientBiologyProps) => {
const { classes } = useStyles()
const dispatch = useAppDispatch()
const { patient } = useAppSelector((state) => ({
patient: state.patient
}))
const patient = useAppSelector((state) => state.patient)
const [toggleModal, setToggleModal] = useState(false)

const [loadingStatus, setLoadingStatus] = useState(LoadingStatus.FETCHING)
Expand Down
4 changes: 1 addition & 3 deletions src/components/Patient/PatientDocs/PatientDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ import NdaFilter from 'components/Filters/NdaFilter'
const PatientDocs: React.FC<PatientTypes> = ({ groupId }) => {
const dispatch = useAppDispatch()
const [toggleModal, setToggleModal] = useState(false)
const { patient } = useAppSelector((state) => ({
patient: state.patient
}))
const patient = useAppSelector((state) => state.patient)
const searchResults = {
deidentified: patient?.deidentified || false,
totalDocs: patient?.documents?.count ?? 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ const PatientTitle: React.FC<PatientTitleProps> = ({ firstName, lastName }) => {
const search = new URLSearchParams(location.search)
const groupId = search.get('groupId') ?? undefined

const { cohort } = useAppSelector((state) => ({
cohort: state.exploredCohort
}))
const cohort = useAppSelector((state) => state.exploredCohort)
const [anchorEl, setAnchorEl] = useState(null)

const handleMenuClose = () => setAnchorEl(null)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Patient/PatientImaging/PatientImaging.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { FilterKeys } from 'types/searchCriterias'
const PatientImaging: React.FC<PatientTypes> = ({ groupId }) => {
const dispatch = useAppDispatch()

const { patient } = useAppSelector((state) => ({ patient: state.patient }))
const patient = useAppSelector((state) => state.patient)
const [loadingStatus, setLoadingStatus] = useState(LoadingStatus.FETCHING)
const [toggleModal, setToggleModal] = useState(false)
const [modalitiesList, setModalitiesList] = useState<HierarchyElement[]>([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ const PatientMedication = ({ groupId }: PatientMedicationProps) => {
const [toggleModal, setToggleModal] = useState(false)

const dispatch = useAppDispatch()
const { patient } = useAppSelector((state) => ({
patient: state.patient
}))
const patient = useAppSelector((state) => state.patient)

const [loadingStatus, setLoadingStatus] = useState(LoadingStatus.FETCHING)
const [page, setPage] = useState(1)
Expand Down
4 changes: 1 addition & 3 deletions src/components/Patient/PatientPMSI/PatientPMSI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ const PatientPMSI = ({ groupId }: PatientPMSIProps) => {
const [loadingStatus, setLoadingStatus] = useState(LoadingStatus.FETCHING)

/* TODO => enlever l'appel de redux */
const { patient } = useAppSelector((state) => ({
patient: state.patient
}))
const patient = useAppSelector((state) => state.patient)
const searchResults = {
deidentified: patient?.deidentified || false,
list: patient?.pmsi?.[selectedTab.id]?.list || [],
Expand Down
Loading

0 comments on commit b30ec03

Please sign in to comment.