From ead757bf81596f7dc7e24c4547eced67b2c1edf2 Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Sat, 7 Oct 2023 16:23:38 +0200 Subject: [PATCH 1/2] =?UTF-8?q?fix(app,dashboard):=20fix=20temporaire=20de?= =?UTF-8?q?s=20duplicatas=20de=20dossier=20m=C3=A9dical?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/recoil/selectors.js | 28 ++++++++++++++++++++++++++-- dashboard/src/recoil/selectors.js | 21 ++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/app/src/recoil/selectors.js b/app/src/recoil/selectors.js index 89afa40f2..48d0d8698 100644 --- a/app/src/recoil/selectors.js +++ b/app/src/recoil/selectors.js @@ -93,7 +93,7 @@ export const itemsGroupedByPersonSelector = selector({ const comments = get(commentsState); const consultations = get(consultationsState); const treatments = get(treatmentsState); - const medicalFiles = get(medicalFileState); + const medicalFiles = [...get(medicalFileState)].sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); const relsPersonPlace = get(relsPersonPlaceState); const places = get(placesObjectSelector); const rencontres = get(rencontresState); @@ -173,7 +173,31 @@ export const itemsGroupedByPersonSelector = selector({ } for (const medicalFile of medicalFiles) { if (!personsObject[medicalFile.person]) continue; - personsObject[medicalFile.person].medicalFile = medicalFile; + if (personsObject[medicalFile.person].medicalFile) { + const nextDocuments = {}; + const nextComments = {}; + const existingMedicalFile = personsObject[medicalFile.person].medicalFile; + for (const document of medicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const document of existingMedicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const comment of medicalFile.comments || []) { + nextComments[comment._id] = comment; + } + for (const comment of existingMedicalFile.comments || []) { + nextComments[comment._id] = comment; + } + personsObject[medicalFile.person].medicalFile = { + ...medicalFile, + ...personsObject[medicalFile.person].medicalFile, + documents: Object.values(nextDocuments), + comments: Object.values(nextComments), + }; + } else { + personsObject[medicalFile.person].medicalFile = medicalFile; + } } // we don't use passages in the app - no use, no load // but we keep it here just to be aware of that app specificity diff --git a/dashboard/src/recoil/selectors.js b/dashboard/src/recoil/selectors.js index 5f8634faf..12ba91d40 100644 --- a/dashboard/src/recoil/selectors.js +++ b/dashboard/src/recoil/selectors.js @@ -122,7 +122,7 @@ export const itemsGroupedByPersonSelector = selector({ const comments = get(commentsState); const consultations = get(consultationsState); const treatments = get(treatmentsState); - const medicalFiles = get(medicalFileState); + const medicalFiles = [...get(medicalFileState)].sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); const passages = get(passagesState); const relsPersonPlace = get(relsPersonPlaceState); const places = get(placesObjectSelector); @@ -260,11 +260,26 @@ export const itemsGroupedByPersonSelector = selector({ for (const medicalFile of medicalFiles) { if (!personsObject[medicalFile.person]) continue; if (personsObject[medicalFile.person].medicalFile) { + const nextDocuments = {}; + const nextComments = {}; + const existingMedicalFile = personsObject[medicalFile.person].medicalFile; + for (const document of medicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const document of existingMedicalFile.documents || []) { + nextDocuments[document._id] = document; + } + for (const comment of medicalFile.comments || []) { + nextComments[comment._id] = comment; + } + for (const comment of existingMedicalFile.comments || []) { + nextComments[comment._id] = comment; + } personsObject[medicalFile.person].medicalFile = { ...medicalFile, ...personsObject[medicalFile.person].medicalFile, - documents: [...(medicalFile?.documents || []), ...(personsObject[medicalFile.person].medicalFile?.documents || [])], - comments: [...(medicalFile?.comments || []), ...(personsObject[medicalFile.person].medicalFile?.comments || [])], + documents: Object.values(nextDocuments), + comments: Object.values(nextComments), }; } else { personsObject[medicalFile.person].medicalFile = medicalFile; From 6275ea01331b3d075757fe5d140f936d05aefabf Mon Sep 17 00:00:00 2001 From: Arnaud AMBROSELLI Date: Sat, 7 Oct 2023 20:21:45 +0200 Subject: [PATCH 2/2] fix: test --- e2e/restricted-role_V2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/restricted-role_V2.spec.ts b/e2e/restricted-role_V2.spec.ts index 49fc31d35..25a7b1f3b 100644 --- a/e2e/restricted-role_V2.spec.ts +++ b/e2e/restricted-role_V2.spec.ts @@ -145,7 +145,7 @@ test("test", async ({ page }) => { await page.getByLabel("Nom de l'action").fill("Action"); // à ne pas voir concernant les actions - await expect(page.getByLabel("Description")).not.toBeVisible(); + await expect(page.getByLabel("Description", { exact: true })).not.toBeVisible(); await expect(page.getByRole("heading", { name: "Commentaires" })).not.toBeVisible(); await expect(page.getByRole("button", { name: "Supprimer" })).not.toBeVisible(); await page.getByRole("button", { name: "Sauvegarder" }).click();