Skip to content

Commit

Permalink
chore: rename variables and files reltaed to person history
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud AMBROSELLI committed Sep 8, 2023
1 parent 5a96764 commit 4b11290
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 143 deletions.
4 changes: 2 additions & 2 deletions app/src/recoil/persons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions app/src/scenes/Persons/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions app/src/scenes/Persons/PersonsOutOfActiveListReason.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand Down
13 changes: 3 additions & 10 deletions dashboard/src/components/PersonName.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<BoldOnHover
<span
className="hover:tw-cursor-zoom-in hover:tw-bg-yellow-400"
onClick={(e) => {
e.stopPropagation();
if (onClick) return onClick();
if (item.person) history.push(`/person/${item.person}?tab=${redirectToTab}`);
}}>
{personName}
</BoldOnHover>
</span>
);
}

const BoldOnHover = styled.span`
&:hover {
background-color: yellow;
cursor: zoom-in;
}
`;
4 changes: 2 additions & 2 deletions dashboard/src/recoil/persons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/scenes/person/MergeTwoPersons.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { toast } from 'react-toastify';
import dayjs from 'dayjs';
import ButtonCustom from '../../components/ButtonCustom';
import {
allowedFieldsInHistorySelector,
allowedPersonFieldsInHistorySelector,
personFieldsIncludingCustomFieldsSelector,
personsState,
usePreparePersonForEncryption,
Expand Down Expand Up @@ -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]);

Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/scenes/person/OutOfActiveList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/scenes/person/components/EditModal.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';

Expand All @@ -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);
Expand Down
118 changes: 0 additions & 118 deletions dashboard/src/scenes/person/components/History.js

This file was deleted.

123 changes: 123 additions & 0 deletions dashboard/src/scenes/person/components/PersonHistory.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<div className="tw-my-10 tw-flex tw-items-center tw-gap-2">
<h3 className="tw-mb-0 tw-flex tw-items-center tw-gap-5 tw-text-xl tw-font-extrabold">Historique</h3>
</div>
{!history?.length ? (
<div className="tw-py-10 tw-text-center tw-text-gray-300">
<p className="tw-text-lg tw-font-bold">Cette personne n'a pas encore d'historique.</p>
<p className="tw-mt-2 tw-text-sm">
Lorsqu'une personne est modifiée, les changements sont enregistrés dans un historique,
<br />
que vous pourrez ainsi retrouver sur cette page.
</p>
</div>
) : (
<table className="table table-striped table-bordered">
<thead>
<tr className="tw-cursor-default">
<th>Date</th>
<th>Utilisateur</th>
<th>Donnée</th>
</tr>
</thead>
<tbody className="small">
{history.map((h) => {
return (
<tr key={h.date} className="tw-cursor-default">
<td>{dayjsInstance(h.date).format('DD/MM/YYYY HH:mm')}</td>
<td>
<UserName id={h.user} />
</td>
<td className="tw-max-w-prose">
{Object.entries(h.data).map(([key, value]) => {
const personField = personFieldsIncludingCustomFields.find((f) => f.name === key);
if (key === 'merge') {
return (
<p className="tw-flex tw-flex-col" key={key}>
<span>
Fusion avec : <code>"{value.name}"</code>
</span>
<small className="tw-opacity-30">
Identifiant: <code>"{value._id}"</code>
</small>
</p>
);
}
if (key === 'assignedTeams') {
return (
<p className="tw-flex tw-flex-col" key={key}>
<span>{personField?.label} : </span>
<code>"{(value.oldValue || []).map((teamId) => teams.find((t) => t._id === teamId)?.name).join(', ')}"</code>
<span></span>
<code>"{(value.newValue || []).map((teamId) => teams.find((t) => t._id === teamId)?.name).join(', ')}"</code>
</p>
);
}
if (key === 'outOfActiveListReasons') {
if (!value.newValue.length) return null;
return (
<p className="tw-flex tw-flex-col" key={key}>
<span>{personField?.label}: </span>
<code>{value.newValue.join(', ')}</code>
</p>
);
}
if (key === 'outOfActiveList') {
return (
<p className="tw-flex tw-flex-col" key={key}>
<span>{value.newValue === true ? 'Sortie de file active' : 'Réintégration dans la file active'}</span>
</p>
);
}
if (key === 'outOfActiveListDate') {
if (!value.newValue) return null;
return (
<p className="tw-flex tw-flex-col" key={key}>
<span>{formatDateWithFullMonth(value.newValue)}</span>
</p>
);
}

return (
<p
key={key}
data-test-id={`${personField?.label || 'Champs personnalisé supprimé'}: ${JSON.stringify(
value.oldValue || ''
)}${JSON.stringify(value.newValue)}`}>
{personField?.label || 'Champs personnalisé supprimé'} : <br />
<code>{JSON.stringify(value.oldValue || '')}</code><code>{JSON.stringify(value.newValue)}</code>
</p>
);
})}
</td>
</tr>
);
})}
</tbody>
</table>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion dashboard/src/scenes/person/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 4b11290

Please sign in to comment.