From 4b11290077070fe3a5f7698fff3fd8bc2b07dace Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Fri, 8 Sep 2023 12:03:50 +0200 Subject: [PATCH] chore: rename variables and files reltaed to person history --- app/src/recoil/persons.js | 4 +- app/src/scenes/Persons/Person.js | 4 +- .../Persons/PersonsOutOfActiveListReason.js | 4 +- dashboard/src/components/PersonName.js | 13 +- dashboard/src/recoil/persons.ts | 4 +- .../src/scenes/person/MergeTwoPersons.js | 4 +- .../src/scenes/person/OutOfActiveList.js | 2 +- .../src/scenes/person/components/EditModal.js | 6 +- .../src/scenes/person/components/History.js | 118 ----------------- .../scenes/person/components/PersonHistory.js | 123 ++++++++++++++++++ dashboard/src/scenes/person/view.js | 2 +- 11 files changed, 141 insertions(+), 143 deletions(-) delete mode 100644 dashboard/src/scenes/person/components/History.js create mode 100644 dashboard/src/scenes/person/components/PersonHistory.js diff --git a/app/src/recoil/persons.js b/app/src/recoil/persons.js index 4a36fe69b..9ddf13e53 100644 --- a/app/src/recoil/persons.js +++ b/app/src/recoil/persons.js @@ -80,8 +80,8 @@ export const personFieldsIncludingCustomFieldsSelector = selector({ }, }); -export const allowedFieldsInHistorySelector = selector({ - key: 'allowedFieldsInHistorySelector', +export const allowedPersonFieldsInHistorySelector = selector({ + key: 'allowedPersonFieldsInHistorySelector', get: ({ get }) => { const allFields = get(personFieldsIncludingCustomFieldsSelector); return allFields.map((f) => f.name).filter((f) => f !== 'history'); diff --git a/app/src/scenes/Persons/Person.js b/app/src/scenes/Persons/Person.js index 1651916fa..71c2a4631 100644 --- a/app/src/scenes/Persons/Person.js +++ b/app/src/scenes/Persons/Person.js @@ -11,7 +11,7 @@ import Tabs from '../../components/Tabs'; import colors from '../../utils/colors'; import { useFocusEffect, useIsFocused } from '@react-navigation/native'; import { - allowedFieldsInHistorySelector, + allowedPersonFieldsInHistorySelector, personsState, usePreparePersonForEncryption, flattenedCustomFieldsPersonsSelector, @@ -38,7 +38,7 @@ const cleanValue = (value) => { const Person = ({ route, navigation }) => { const flattenedCustomFieldsPersons = useRecoilValue(flattenedCustomFieldsPersonsSelector); - const allowedFieldsInHistory = useRecoilValue(allowedFieldsInHistorySelector); + const allowedFieldsInHistory = useRecoilValue(allowedPersonFieldsInHistorySelector); const preparePersonForEncryption = usePreparePersonForEncryption(); const [refreshTrigger, setRefreshTrigger] = useRecoilState(refreshTriggerState); const [persons, setPersons] = useRecoilState(personsState); diff --git a/app/src/scenes/Persons/PersonsOutOfActiveListReason.js b/app/src/scenes/Persons/PersonsOutOfActiveListReason.js index d91ae83c5..d250123ea 100644 --- a/app/src/scenes/Persons/PersonsOutOfActiveListReason.js +++ b/app/src/scenes/Persons/PersonsOutOfActiveListReason.js @@ -7,7 +7,7 @@ import ScreenTitle from '../../components/ScreenTitle'; import ScrollContainer from '../../components/ScrollContainer'; import OutOfActiveListReasonMultiCheckBox from '../../components/Selects/OutOfActiveListReasonMultiCheckBox'; import { userState } from '../../recoil/auth'; -import { allowedFieldsInHistorySelector, personsState, usePreparePersonForEncryption } from '../../recoil/persons'; +import { allowedPersonFieldsInHistorySelector, personsState, usePreparePersonForEncryption } from '../../recoil/persons'; import API from '../../services/api'; import { itemsGroupedByPersonSelector } from '../../recoil/selectors'; @@ -16,7 +16,7 @@ const PersonsOutOfActiveListReason = ({ navigation, route }) => { const [submitting, setSubmitting] = useState(false); const setPersons = useSetRecoilState(personsState); const personsObject = useRecoilValue(itemsGroupedByPersonSelector); - const allowedFieldsInHistory = useRecoilValue(allowedFieldsInHistorySelector); + const allowedFieldsInHistory = useRecoilValue(allowedPersonFieldsInHistorySelector); const preparePersonForEncryption = usePreparePersonForEncryption(); const user = useRecoilValue(userState); diff --git a/dashboard/src/components/PersonName.js b/dashboard/src/components/PersonName.js index c115ed736..7791b8207 100644 --- a/dashboard/src/components/PersonName.js +++ b/dashboard/src/components/PersonName.js @@ -1,5 +1,4 @@ import React from 'react'; -import styled from 'styled-components'; import { useHistory } from 'react-router-dom'; import { useRecoilValue } from 'recoil'; import { personsObjectSelector } from '../recoil/selectors'; @@ -9,20 +8,14 @@ export default function PersonName({ item, onClick = null, redirectToTab = 'Rés const persons = useRecoilValue(personsObjectSelector); const personName = item?.personPopulated?.name || persons[item.person]?.name; return ( - { e.stopPropagation(); if (onClick) return onClick(); if (item.person) history.push(`/person/${item.person}?tab=${redirectToTab}`); }}> {personName} - + ); } - -const BoldOnHover = styled.span` - &:hover { - background-color: yellow; - cursor: zoom-in; - } -`; diff --git a/dashboard/src/recoil/persons.ts b/dashboard/src/recoil/persons.ts index 18e534bcf..146ab1d32 100644 --- a/dashboard/src/recoil/persons.ts +++ b/dashboard/src/recoil/persons.ts @@ -83,8 +83,8 @@ export const personFieldsIncludingCustomFieldsSelector = selector({ }, }); -export const allowedFieldsInHistorySelector = selector({ - key: 'allowedFieldsInHistorySelector', +export const allowedPersonFieldsInHistorySelector = selector({ + key: 'allowedPersonFieldsInHistorySelector', get: ({ get }) => { const allFields = get(personFieldsIncludingCustomFieldsSelector); return allFields.map((f) => f.name).filter((f) => f !== 'history'); diff --git a/dashboard/src/scenes/person/MergeTwoPersons.js b/dashboard/src/scenes/person/MergeTwoPersons.js index 7bcee2650..f83846314 100644 --- a/dashboard/src/scenes/person/MergeTwoPersons.js +++ b/dashboard/src/scenes/person/MergeTwoPersons.js @@ -7,7 +7,7 @@ import { toast } from 'react-toastify'; import dayjs from 'dayjs'; import ButtonCustom from '../../components/ButtonCustom'; import { - allowedFieldsInHistorySelector, + allowedPersonFieldsInHistorySelector, personFieldsIncludingCustomFieldsSelector, personsState, usePreparePersonForEncryption, @@ -87,7 +87,7 @@ const MergeTwoPersons = ({ person }) => { const [personToMergeAndDelete, setPersonToMergeAndDelete] = useState(null); const allFields = useRecoilValue(personFieldsIncludingCustomFieldsSelector); - const allowedFieldsInHistory = useRecoilValue(allowedFieldsInHistorySelector); + const allowedFieldsInHistory = useRecoilValue(allowedPersonFieldsInHistorySelector); const personsToMergeWith = useMemo(() => persons.filter((p) => p._id !== originPerson?._id), [persons, originPerson]); diff --git a/dashboard/src/scenes/person/OutOfActiveList.js b/dashboard/src/scenes/person/OutOfActiveList.js index d0a5eaef5..f11d21203 100644 --- a/dashboard/src/scenes/person/OutOfActiveList.js +++ b/dashboard/src/scenes/person/OutOfActiveList.js @@ -9,7 +9,7 @@ import { fieldsPersonsCustomizableOptionsSelector, personsState, usePreparePerso import API from '../../services/api'; import { outOfBoundariesDate } from '../../services/date'; import SelectCustom from '../../components/SelectCustom'; -import { cleanHistory } from './components/History'; +import { cleanHistory } from './components/PersonHistory'; import DatePicker from '../../components/DatePicker'; const OutOfActiveList = ({ person }) => { diff --git a/dashboard/src/scenes/person/components/EditModal.js b/dashboard/src/scenes/person/components/EditModal.js index 4a35f090a..cfdc41e0e 100644 --- a/dashboard/src/scenes/person/components/EditModal.js +++ b/dashboard/src/scenes/person/components/EditModal.js @@ -1,7 +1,7 @@ import { Col, FormGroup, Input, Label, Modal, ModalBody, ModalHeader, Row } from 'reactstrap'; import SelectAsInput from '../../../components/SelectAsInput'; import { - allowedFieldsInHistorySelector, + allowedPersonFieldsInHistorySelector, customFieldsPersonsSelector, flattenedCustomFieldsPersonsSelector, personFieldsSelector, @@ -18,7 +18,7 @@ import ButtonCustom from '../../../components/ButtonCustom'; import { Formik } from 'formik'; import { toast } from 'react-toastify'; import API from '../../../services/api'; -import { cleanHistory } from './History'; +import { cleanHistory } from './PersonHistory'; import DatePicker from '../../../components/DatePicker'; import { customFieldsMedicalFileSelector, medicalFileState, prepareMedicalFileForEncryption } from '../../../recoil/medicalFiles'; @@ -27,7 +27,7 @@ export default function EditModal({ person, selectedPanel, onClose, isMedicalFil const user = useRecoilValue(userState); const customFieldsPersons = useRecoilValue(customFieldsPersonsSelector); const flattenedCustomFieldsPersons = useRecoilValue(flattenedCustomFieldsPersonsSelector); - const allowedFieldsInHistory = useRecoilValue(allowedFieldsInHistorySelector); + const allowedFieldsInHistory = useRecoilValue(allowedPersonFieldsInHistorySelector); const team = useRecoilValue(currentTeamState); const [persons, setPersons] = useRecoilState(personsState); const customFieldsMedicalFile = useRecoilValue(customFieldsMedicalFileSelector); diff --git a/dashboard/src/scenes/person/components/History.js b/dashboard/src/scenes/person/components/History.js deleted file mode 100644 index 81dbd0f3a..000000000 --- a/dashboard/src/scenes/person/components/History.js +++ /dev/null @@ -1,118 +0,0 @@ -import { useMemo } from 'react'; -import { Col, Row } from 'reactstrap'; -import { useRecoilValue } from 'recoil'; -import { Title } from '../../../components/header'; -import UserName from '../../../components/UserName'; -import { teamsState } from '../../../recoil/auth'; -import { personFieldsIncludingCustomFieldsSelector } from '../../../recoil/persons'; -import { formatDateWithFullMonth, dayjsInstance } from '../../../services/date'; - -// FIX: there was a bug in history at some point, where the whole person was saved in the history -// this function removes those entries -export const cleanHistory = (history = []) => { - return history.filter((h) => { - if (JSON.stringify(h.data).includes('encryptedEntityKey')) return false; - return true; - }); -}; - -const History = ({ person }) => { - const personFieldsIncludingCustomFields = useRecoilValue(personFieldsIncludingCustomFieldsSelector); - const teams = useRecoilValue(teamsState); - const history = useMemo(() => cleanHistory(person.history || []).reverse(), [person.history]); - - return ( -
- - - Historique - - - - - - - - - - - - {history.map((h) => { - return ( - - - - - - ); - })} - -
DateUtilisateurDonnée
{dayjsInstance(h.date).format('DD/MM/YYYY HH:mm')} - - - {Object.entries(h.data).map(([key, value]) => { - const personField = personFieldsIncludingCustomFields.find((f) => f.name === key); - if (key === 'merge') { - return ( -

- - Fusion avec : "{value.name}" - - - Identifiant: "{value._id}" - -

- ); - } - if (key === 'assignedTeams') { - return ( -

- {personField?.label} : - "{(value.oldValue || []).map((teamId) => teams.find((t) => t._id === teamId)?.name).join(', ')}" - - "{(value.newValue || []).map((teamId) => teams.find((t) => t._id === teamId)?.name).join(', ')}" -

- ); - } - if (key === 'outOfActiveListReasons') { - if (!value.newValue.length) return null; - return ( -

- {personField?.label}: - {value.newValue.join(', ')} -

- ); - } - if (key === 'outOfActiveList') { - return ( -

- {value.newValue === true ? 'Sortie de file active' : 'Réintégration dans la file active'} -

- ); - } - if (key === 'outOfActiveListDate') { - if (!value.newValue) return null; - return ( -

- {formatDateWithFullMonth(value.newValue)} -

- ); - } - - return ( -

- {personField?.label || 'Champs personnalisé supprimé'} :
- {JSON.stringify(value.oldValue || '')}{JSON.stringify(value.newValue)} -

- ); - })} -
-
- ); -}; - -export default History; diff --git a/dashboard/src/scenes/person/components/PersonHistory.js b/dashboard/src/scenes/person/components/PersonHistory.js new file mode 100644 index 000000000..f16b73c24 --- /dev/null +++ b/dashboard/src/scenes/person/components/PersonHistory.js @@ -0,0 +1,123 @@ +import { useMemo } from 'react'; +import { useRecoilValue } from 'recoil'; +import UserName from '../../../components/UserName'; +import { teamsState } from '../../../recoil/auth'; +import { personFieldsIncludingCustomFieldsSelector } from '../../../recoil/persons'; +import { formatDateWithFullMonth, dayjsInstance } from '../../../services/date'; + +// FIX: there was a bug in history at some point, where the whole person was saved in the history +// this function removes those entries +export const cleanHistory = (history = []) => { + return history.filter((h) => { + if (JSON.stringify(h.data).includes('encryptedEntityKey')) return false; + return true; + }); +}; + +export default function PersonHistory({ person }) { + const personFieldsIncludingCustomFields = useRecoilValue(personFieldsIncludingCustomFieldsSelector); + const teams = useRecoilValue(teamsState); + const history = useMemo(() => cleanHistory(person.history || []).reverse(), [person.history]); + + return ( +
+
+

Historique

+
+ {!history?.length ? ( +
+

Cette personne n'a pas encore d'historique.

+

+ Lorsqu'une personne est modifiée, les changements sont enregistrés dans un historique, +
+ que vous pourrez ainsi retrouver sur cette page. +

+
+ ) : ( + + + + + + + + + + {history.map((h) => { + return ( + + + + + + ); + })} + +
DateUtilisateurDonnée
{dayjsInstance(h.date).format('DD/MM/YYYY HH:mm')} + + + {Object.entries(h.data).map(([key, value]) => { + const personField = personFieldsIncludingCustomFields.find((f) => f.name === key); + if (key === 'merge') { + return ( +

+ + Fusion avec : "{value.name}" + + + Identifiant: "{value._id}" + +

+ ); + } + if (key === 'assignedTeams') { + return ( +

+ {personField?.label} : + "{(value.oldValue || []).map((teamId) => teams.find((t) => t._id === teamId)?.name).join(', ')}" + + "{(value.newValue || []).map((teamId) => teams.find((t) => t._id === teamId)?.name).join(', ')}" +

+ ); + } + if (key === 'outOfActiveListReasons') { + if (!value.newValue.length) return null; + return ( +

+ {personField?.label}: + {value.newValue.join(', ')} +

+ ); + } + if (key === 'outOfActiveList') { + return ( +

+ {value.newValue === true ? 'Sortie de file active' : 'Réintégration dans la file active'} +

+ ); + } + if (key === 'outOfActiveListDate') { + if (!value.newValue) return null; + return ( +

+ {formatDateWithFullMonth(value.newValue)} +

+ ); + } + + return ( +

+ {personField?.label || 'Champs personnalisé supprimé'} :
+ {JSON.stringify(value.oldValue || '')}{JSON.stringify(value.newValue)} +

+ ); + })} +
+ )} +
+ ); +} diff --git a/dashboard/src/scenes/person/view.js b/dashboard/src/scenes/person/view.js index 1e1e28ff9..2bd50f862 100644 --- a/dashboard/src/scenes/person/view.js +++ b/dashboard/src/scenes/person/view.js @@ -5,7 +5,7 @@ import Places from './Places'; import { itemsGroupedByPersonSelector } from '../../recoil/selectors'; import API from '../../services/api'; import { formatDateWithFullMonth } from '../../services/date'; -import History from './components/History'; +import History from './components/PersonHistory'; import MedicalFile from './components/MedicalFile'; import Summary from './components/Summary'; import BackButton from '../../components/backButton';