From 8d526e88c563d50eb91b2bc4128f74a53caa2c52 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Thu, 15 Feb 2024 08:24:19 +0100 Subject: [PATCH 1/5] feat: createdat in new reports --- dashboard/src/components/ActionModal.js | 4 +- .../src/components/ActionsSortableList.js | 15 +- .../ActionsOrConsultationsReport.js | 156 ++++++++++++++++-- dashboard/src/scenes/report/view.js | 61 +++++-- 4 files changed, 198 insertions(+), 38 deletions(-) diff --git a/dashboard/src/components/ActionModal.js b/dashboard/src/components/ActionModal.js index 30b728d2f..3fe7b02c8 100644 --- a/dashboard/src/components/ActionModal.js +++ b/dashboard/src/components/ActionModal.js @@ -4,7 +4,7 @@ import { useRecoilValue, useSetRecoilState } from 'recoil'; import { useHistory, useLocation } from 'react-router-dom'; import { actionsState, allowedActionFieldsInHistory, CANCEL, DONE, prepareActionForEncryption, TODO } from '../recoil/actions'; import { currentTeamState, organisationState, teamsState, userState } from '../recoil/auth'; -import { dayjsInstance, now, outOfBoundariesDate } from '../services/date'; +import { dayjsInstance, formatDateWithNameOfDay, now, outOfBoundariesDate } from '../services/date'; import API from '../services/api'; import SelectPerson from './SelectPerson'; import SelectStatus from './SelectStatus'; @@ -350,7 +350,7 @@ function ActionContent({ onClose, action, personId = null, personIds = null, isM ` (créée par ${name})`} + wrapper={(name) => ` (créée par ${name} le ${formatDateWithNameOfDay(action.createdAt)})`} /> )} diff --git a/dashboard/src/components/ActionsSortableList.js b/dashboard/src/components/ActionsSortableList.js index 7e380a8c2..e0db4d041 100644 --- a/dashboard/src/components/ActionsSortableList.js +++ b/dashboard/src/components/ActionsSortableList.js @@ -20,7 +20,7 @@ import useSearchParamState from '../services/useSearchParamState'; import DescriptionIcon from './DescriptionIcon'; import { AgendaMutedIcon } from '../assets/icons/AgendaMutedIcon'; -const ActionsSortableList = ({ data, limit }) => { +const ActionsSortableList = ({ data, limit, showCreatedAt }) => { useTitle('Agenda'); const history = useHistory(); const user = useRecoilValue(userState); @@ -154,7 +154,18 @@ const ActionsSortableList = ({ data, limit }) => { ); }, }, - ]} + { + title: 'Créée le', + dataKey: 'createdAt', + onSortOrder: setSortOrder, + onSortBy: setSortBy, + sortBy, + sortOrder, + render: (action) => { + return ; + }, + }, + ].filter((e) => showCreatedAt || e.dataKey !== 'createdAt')} /> {limit > 0 && setPage(page, true)} />} diff --git a/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js b/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js index 420c96c03..2d8074e55 100644 --- a/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js +++ b/dashboard/src/scenes/report/components/ActionsOrConsultationsReport.js @@ -11,14 +11,46 @@ import { useRecoilValue } from 'recoil'; import { userState } from '../../../recoil/auth'; import { dayjsInstance } from '../../../services/date'; -export const ActionsOrConsultationsReport = ({ actions, consultations, period }) => { +const formatEcheanceLabelPeriod = (period) => { + if (!!period.startDate && !!period.endDate) { + const start = dayjsInstance(period.startDate); + const end = dayjsInstance(period.endDate); + const today = dayjsInstance(); + const showYear = start.year() !== end.year() || start.year() !== today.year(); + const startFormatted = dayjsInstance(period.startDate).format(showYear ? 'D MMM YYYY' : 'D MMM'); + const endFormatted = dayjsInstance(period.endDate).format(showYear ? 'D MMM YYYY' : 'D MMM'); + if (startFormatted === endFormatted) return `le ${startFormatted}`; + return `entre le ${startFormatted} et le ${endFormatted}`; + } + return ''; +}; + +export const ActionsOrConsultationsReport = ({ + actionsDueOrCompletedAt, + actionsCreatedAt, + consultationsDueOrCompletedAt, + consultationsCreatedAt, + period, +}) => { const [activeTab, setActiveTab] = useLocalStorage('reports-actions-consultation-toggle', 'Actions'); const [fullScreen, setFullScreen] = useState(false); - const [filterStatus, setFilterStatus] = useState([]); - const filteredActions = actions.filter((item) => !filterStatus.length || filterStatus.includes(item.status)); - const filteredConsultations = consultations.filter((item) => !filterStatus.length || filterStatus.includes(item.status)); + const [switchCreatedAt, setSwitchCreatedAt] = useLocalStorage('reports-actions-switch-created-at', 'dueOrCompletedAt'); // 'createdAt' or 'dueOrCompletedAt' + const [filterStatus, setFilterStatus] = useLocalStorage('reports-actions-filter-status', []); + + const actions = switchCreatedAt === 'createdAt' ? actionsCreatedAt : actionsDueOrCompletedAt; + const consultations = switchCreatedAt === 'createdAt' ? consultationsCreatedAt : consultationsDueOrCompletedAt; const data = activeTab.includes('Actions') ? actions : consultations; + + const filteredActionsDueOrCompletedAt = actionsDueOrCompletedAt.filter((item) => !filterStatus.length || filterStatus.includes(item.status)); + const filteredActionsCreatedAt = actionsCreatedAt.filter((item) => !filterStatus.length || filterStatus.includes(item.status)); + const filteredConsultationsDueOrCompletedAt = consultationsDueOrCompletedAt.filter( + (item) => !filterStatus.length || filterStatus.includes(item.status) + ); + const filteredConsultationsCreatedAt = consultationsCreatedAt.filter((item) => !filterStatus.length || filterStatus.includes(item.status)); + const filteredActions = switchCreatedAt === 'createdAt' ? filteredActionsCreatedAt : filteredActionsDueOrCompletedAt; + const filteredConsultations = switchCreatedAt === 'createdAt' ? filteredConsultationsCreatedAt : filteredConsultationsDueOrCompletedAt; const filteredData = activeTab.includes('Actions') ? filteredActions : filteredConsultations; + const history = useHistory(); const user = useRecoilValue(userState); @@ -67,8 +99,15 @@ export const ActionsOrConsultationsReport = ({ actions, consultations, period }) -
- +
+
@@ -78,7 +117,30 @@ export const ActionsOrConsultationsReport = ({ actions, consultations, period }) aria-hidden="true" className="printonly tw-flex tw-h-full tw-flex-col tw-overflow-hidden tw-rounded-lg tw-border tw-border-zinc-200 tw-shadow">
-

Actions ({filteredActions.length})

+

+ Actions À FAIRE/FAITE/ANNULÉE {formatEcheanceLabelPeriod(period)} ({filteredActionsDueOrCompletedAt.length}) +

+ {filterStatus.length > 0 && ( +

+ Filtrées par status:{' '} + {mappedIdsToLabels + .filter((s) => filterStatus.includes(s._id)) + .map((status) => status.name) + .join(', ')} +

+ )} +
+
+ +
+ + + + setFullScreen(false)}> setFullScreen(false)}> -
- +
+
- +
- +
-
+
{' '} + if (activeTab.includes('Action') return
-
+
-
{' '} - if (activeTab.includes('Action') return +
- - + {canSeeMedicalData && ( + <> + + + + )} setFullScreen(false)}> setFullScreen(false)}> -
+
- {' '} - if (activeTab.includes('Action') return +
- -
-
- -
- - - - {canSeeMedicalData && ( - <> - - - - )} setFullScreen(false)}> - setFullScreen(false)}> + setFullScreen(false)}>
- +
- + + diff --git a/dashboard/src/scenes/report/view.js b/dashboard/src/scenes/report/view.js index feeee5787..dfb7e90c3 100644 --- a/dashboard/src/scenes/report/view.js +++ b/dashboard/src/scenes/report/view.js @@ -5,7 +5,7 @@ import { HeaderStyled, Title as HeaderTitle } from '../../components/header'; import { ModalBody, ModalContainer, ModalFooter, ModalHeader } from '../../components/tailwind/Modal'; import dayjs from 'dayjs'; -import { TODO } from '../../recoil/actions'; +import { CANCEL, TODO, DONE } from '../../recoil/actions'; import ButtonCustom from '../../components/ButtonCustom'; import { currentTeamState, organisationState, teamsState, userState } from '../../recoil/auth'; import { reportsState } from '../../recoil/reports'; @@ -67,9 +67,11 @@ const itemsForReportsSelector = selectorFamily({ const personsCreated = {}; const personsUpdated = {}; - const actionsDueOrCompletedAt = {}; + const actionsCompletedAt = {}; + const actionsCanceledAt = {}; const actionsCreatedAt = {}; - const consultationsDueOrCompletedAt = {}; + const consultationsCompletedAt = {}; + const consultationsCanceledAt = {}; const consultationsCreatedAt = {}; const comments = {}; const commentsMedical = {}; @@ -99,25 +101,33 @@ const itemsForReportsSelector = selectorFamily({ for (const action of person.actions || []) { if (!filterItemByTeam(action, 'teams')) continue; if (Array.isArray(action.teams)) { - let isDueOrCompletedAt = false; + let isDoneAt = false; + let isCanceledAt = false; let isCreatedAt = false; for (const team of action.teams) { const { isoStartDate, isoEndDate } = selectedTeamsObjectWithOwnPeriod[team] ?? defaultIsoDates; - if (action.status !== TODO && action.completedAt >= isoStartDate && action.completedAt < isoEndDate) { - isDueOrCompletedAt = true; + if (action.completedAt >= isoStartDate && action.completedAt < isoEndDate) { + if (action.status === CANCEL) { + isCanceledAt = true; + continue; + } + if (action.status === DONE) { + isDoneAt = true; + continue; + } continue; } if (action.createdAt >= isoStartDate && action.createdAt < isoEndDate) { - isCreatedAt = true; + if (action.status === TODO) { + isCreatedAt = true; + continue; + } } - // if (action.status !== TODO) continue; - // if (action.dueAt >= isoStartDate && action.dueAt < isoEndDate) { - // isDueOrCompletedAt = true; - // continue; - // } } - if (isDueOrCompletedAt) { - actionsDueOrCompletedAt[action._id] = action; + if (isDoneAt) { + actionsCompletedAt[action._id] = action; + } else if (isCanceledAt) { + actionsCanceledAt[action._id] = action; } else if (isCreatedAt) { actionsCreatedAt[action._id] = action; } @@ -126,24 +136,33 @@ const itemsForReportsSelector = selectorFamily({ for (const consultation of person.consultations || []) { if (!filterItemByTeam(consultation, 'teams')) continue; if (Array.isArray(consultation.teams)) { - let isDueOrCompletedAt = false; + let isDoneAt = false; + let isCanceledAt = false; let isCreatedAt = false; for (const team of consultation.teams) { const { isoStartDate, isoEndDate } = selectedTeamsObjectWithOwnPeriod[team] ?? defaultIsoDates; - if (consultation.status !== TODO && consultation.completedAt >= isoStartDate && consultation.completedAt < isoEndDate) { - isDueOrCompletedAt = true; + if (consultation.completedAt >= isoStartDate && consultation.completedAt < isoEndDate) { + if (consultation.status === CANCEL) { + isCanceledAt = true; + continue; + } + if (consultation.status === DONE) { + isDoneAt = true; + continue; + } continue; } if (consultation.createdAt >= isoStartDate && consultation.createdAt < isoEndDate) { - isCreatedAt = true; + if (consultation.status === TODO) { + isCreatedAt = true; + continue; + } } - // if (consultation.status !== TODO) continue; - // if (consultation.dueAt >= isoStartDate && consultation.dueAt < isoEndDate) { - // isDueOrCompletedAt = true; - // } } - if (isDueOrCompletedAt) { - consultationsDueOrCompletedAt[consultation._id] = consultation; + if (isDoneAt) { + consultationsCompletedAt[consultation._id] = consultation; + } else if (isCanceledAt) { + consultationsCanceledAt[consultation._id] = consultation; } else if (isCreatedAt) { consultationsCreatedAt[consultation._id] = consultation; } @@ -206,9 +225,11 @@ const itemsForReportsSelector = selectorFamily({ return { personsCreated: Object.values(personsCreated), personsUpdated: Object.values(personsUpdated), - actionsDueOrCompletedAt: Object.values(actionsDueOrCompletedAt), + actionsCompletedAt: Object.values(actionsCompletedAt), + actionsCanceledAt: Object.values(actionsCanceledAt), actionsCreatedAt: Object.values(actionsCreatedAt), - consultationsDueOrCompletedAt: Object.values(consultationsDueOrCompletedAt), + consultationsCompletedAt: Object.values(consultationsCompletedAt), + consultationsCanceledAt: Object.values(consultationsCanceledAt), consultationsCreatedAt: Object.values(consultationsCreatedAt), comments: Object.values(comments), commentsMedical: Object.values(commentsMedical), @@ -265,9 +286,11 @@ const View = () => { const { personsCreated, - actionsDueOrCompletedAt, + actionsCompletedAt, + actionsCanceledAt, actionsCreatedAt, - consultationsDueOrCompletedAt, + consultationsCompletedAt, + consultationsCanceledAt, consultationsCreatedAt, comments, commentsMedical, @@ -390,9 +413,11 @@ const View = () => {