Skip to content

Commit

Permalink
Ajout de "Créée le" dans les filtres des actions et des consultations…
Browse files Browse the repository at this point in the history
… des comptes rendus (#17)
  • Loading branch information
rap2hpoutre committed Feb 20, 2024
1 parent daaf4de commit 93cdcd2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { mappedIdsToLabels } from '../../../recoil/actions';
import { CANCEL, DONE, TODO, mappedIdsToLabels } from '../../../recoil/actions';
import { useHistory } from 'react-router-dom';
import SelectCustom from '../../../components/SelectCustom';
import { ModalHeader, ModalBody, ModalContainer, ModalFooter } from '../../../components/tailwind/Modal';
Expand All @@ -11,12 +11,29 @@ import { useRecoilValue } from 'recoil';
import { userState } from '../../../recoil/auth';
import { dayjsInstance } from '../../../services/date';

export const ActionsOrConsultationsReport = ({ actions, consultations, period }) => {
export const ActionsOrConsultationsReport = ({ actions, consultations, actionsCreated, consultationsCreated, period }) => {
const [activeTab, setActiveTab] = useLocalStorage('reports-actions-consultation-toggle', 'Actions');
const [fullScreen, setFullScreen] = useState(false);
const [filterStatus, setFilterStatus] = useState([]);
const [filterStatus, setFilterStatus] = useState([TODO, DONE, CANCEL]);

const hasCreatedAtFilter = filterStatus.includes('CREATED');
const filteredActions = actions.filter((item) => !filterStatus.length || filterStatus.includes(item.status));
if (hasCreatedAtFilter || !filterStatus.length) {
for (const action of actionsCreated) {
if (!filteredActions.find((a) => a._id === action._id)) {
filteredActions.push(action);
}
}
}
const filteredConsultations = consultations.filter((item) => !filterStatus.length || filterStatus.includes(item.status));
if (hasCreatedAtFilter || !filterStatus.length) {
for (const consultation of consultationsCreated) {
if (!filteredConsultations.find((c) => c._id === consultation._id)) {
filteredConsultations.push(consultation);
}
}
}

const data = activeTab.includes('Actions') ? actions : consultations;
const filteredData = activeTab.includes('Actions') ? filteredActions : filteredConsultations;
const history = useHistory();
Expand Down Expand Up @@ -67,7 +84,7 @@ export const ActionsOrConsultationsReport = ({ actions, consultations, period })
</button>
</div>
</div>
<div className="w-full tw-max-w-lg tw-bg-white tw-px-7 tw-pb-1">
<div className="tw-w-full tw-px-7 tw-pb-2">
<ActionsOrConsultationsFilters setFilterStatus={setFilterStatus} filterStatus={filterStatus} disabled={!data.length} />
</div>
<div className="tw-grow tw-overflow-y-auto tw-border-t tw-border-main tw-border-opacity-20">
Expand Down Expand Up @@ -142,25 +159,31 @@ export const ActionsOrConsultationsReport = ({ actions, consultations, period })
};

const ActionsOrConsultationsFilters = ({ setFilterStatus, filterStatus, disabled }) => {
const options = [
{ _id: TODO, name: 'À faire' },
{ _id: DONE, name: 'Faite' },
{ _id: CANCEL, name: 'Annulée' },
{ _id: 'CREATED', name: 'Créée' },
];
return (
<>
<div className="tw-flex tw-justify-between">
<div className="tw-flex tw-w-full tw-shrink-0 tw-grow tw-items-center tw-pl-1 tw-pr-2">
<label htmlFor="action-select-status-filter" className="tw-text-xs">
Filtrer par statut
<div className="tw-flex tw-w-full tw-shrink-0 tw-grow tw-content-center tw-items-center tw-pl-1 tw-pr-2">
<label htmlFor="action-select-status-filter" className="tw-mr-2 tw-mt-2 tw-text-sm">
Filtrer
</label>
<div className="tw-w-full">
<SelectCustom
inputId="action-select-status-filter"
options={mappedIdsToLabels}
options={options}
getOptionValue={(s) => s._id}
getOptionLabel={(s) => s.name}
name="status"
onChange={(s) => setFilterStatus(s.map((s) => s._id))}
isClearable
isDisabled={disabled}
isMulti
value={mappedIdsToLabels.filter((s) => filterStatus.includes(s._id))}
value={options.filter((s) => filterStatus.includes(s._id))}
/>
</div>
</div>
Expand Down
32 changes: 30 additions & 2 deletions dashboard/src/scenes/report/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const itemsForReportsSelector = selectorFamily({
const personsCreated = {};
const personsUpdated = {};
const actions = {};
const actionsCreated = {};
const consultations = {};
const consultationsCreated = {};
const comments = {};
const commentsMedical = {};
const passages = {};
Expand Down Expand Up @@ -99,6 +101,9 @@ const itemsForReportsSelector = selectorFamily({
let isIncluded = false;
for (const team of action.teams) {
const { isoStartDate, isoEndDate } = selectedTeamsObjectWithOwnPeriod[team] ?? defaultIsoDates;
if (action.createdAt >= isoStartDate && action.createdAt < isoEndDate) {
actionsCreated[action._id] = action;
}
if (action.completedAt >= isoStartDate && action.completedAt < isoEndDate) {
isIncluded = true;
continue;
Expand All @@ -118,6 +123,9 @@ const itemsForReportsSelector = selectorFamily({
let isIncluded = false;
for (const team of consultation.teams) {
const { isoStartDate, isoEndDate } = selectedTeamsObjectWithOwnPeriod[team] ?? defaultIsoDates;
if (consultation.createdAt >= isoStartDate && consultation.createdAt < isoEndDate) {
consultationsCreated[consultation._id] = consultation;
}
if (consultation.completedAt >= isoStartDate && consultation.completedAt < isoEndDate) {
isIncluded = true;
continue;
Expand Down Expand Up @@ -189,7 +197,9 @@ const itemsForReportsSelector = selectorFamily({
personsCreated: Object.values(personsCreated),
personsUpdated: Object.values(personsUpdated),
actions: Object.values(actions),
actionsCreated: Object.values(actionsCreated),
consultations: Object.values(consultations),
consultationsCreated: Object.values(consultationsCreated),
comments: Object.values(comments),
commentsMedical: Object.values(commentsMedical),
passages: Object.values(passages).sort((a, b) => (a.date >= b.date ? -1 : 1)),
Expand Down Expand Up @@ -242,7 +252,19 @@ const View = () => {
return teamsIdsObject;
}, [selectedTeams, period]);

const { personsCreated, actions, consultations, comments, commentsMedical, passages, rencontres, observations, reports } = useRecoilValue(
const {
personsCreated,
actions,
consultations,
comments,
commentsMedical,
passages,
rencontres,
observations,
reports,
actionsCreated,
consultationsCreated,
} = useRecoilValue(
itemsForReportsSelector({
period,
viewAllOrganisationData,
Expand Down Expand Up @@ -356,7 +378,13 @@ const View = () => {
].join(' ')}>
<div className="tw-mb-12 tw-min-h-1/2 tw-basis-6/12 tw-overflow-auto print:tw-min-h-0 print:tw-basis-full">
<div className="tw-mb-4 tw-h-[60vh] tw-overflow-hidden tw-rounded-lg tw-border tw-border-zinc-200 tw-shadow print:tw-h-auto print:tw-border-none print:tw-shadow-none">
<ActionsOrConsultationsReport actions={actions} consultations={consultations} period={period} />
<ActionsOrConsultationsReport
actions={actions}
consultations={consultations}
actionsCreated={actionsCreated}
consultationsCreated={consultationsCreated}
period={period}
/>
</div>
{canSeeComments && (
<div className="tw-mb-4 tw-h-[60vh] tw-overflow-hidden tw-rounded-lg tw-border tw-border-zinc-200 tw-shadow print:tw-h-auto print:tw-border-none print:tw-shadow-none">
Expand Down

0 comments on commit 93cdcd2

Please sign in to comment.