diff --git a/shared/types/contributions.ts b/shared/types/contributions.ts index 05561d85b..6dc262592 100644 --- a/shared/types/contributions.ts +++ b/shared/types/contributions.ts @@ -1,3 +1,6 @@ +import { FicheServicePublicDoc } from "./index"; +import { Document } from "./documents"; + export type ContributionsAnswers = { id: string; content: string | null; @@ -6,7 +9,7 @@ export type ContributionsAnswers = { kali_references: ContributionKaliReferences[]; legi_references: ContributionLegiReferences[]; other_references: ContributionOtherReferences[]; - cdtn_references: ContributionCdtnReferences[]; + cdtn_references: Partial[]; content_fiche_sp: ContributionContentFicheSp | null; message_block_generic_no_CDT: string | null; agreement: ContributionAgreement; @@ -42,14 +45,15 @@ export type ContributionAgreement = { }; export type ContributionCdtnReferences = { - document: { - cdtn_id: string; - }; + cdtn_id: string; + answer: ContributionsAnswers; + answer_id: string; + document: Partial>; }; export type ContributionContentFicheSp = { initial_id: string; - document: Record; + document: FicheServicePublicDoc; }; export type ContributionLegiReferences = { diff --git a/shared/types/index.ts b/shared/types/index.ts index 1e588ea3b..a7b519f1e 100644 --- a/shared/types/index.ts +++ b/shared/types/index.ts @@ -322,6 +322,7 @@ export type DocumentInfo = Pick & { }; export type DocumentInfoWithCdtnRef = DocumentInfo & { ref: Pick; + url?: string; }; /** Fiche travail alert changes */ diff --git a/targets/alert-cli/src/ccn-list.ts b/targets/alert-cli/src/ccn-list.ts deleted file mode 100644 index 937704844..000000000 --- a/targets/alert-cli/src/ccn-list.ts +++ /dev/null @@ -1,52 +0,0 @@ -export const ccns = [ - { id: "KALICONT000005635624", num: 16 }, - { id: "KALICONT000005635234", num: 29 }, - { id: "KALICONT000005635613", num: 44 }, - { id: "KALICONT000005635630", num: 86 }, - { id: "KALICONT000005635184", num: 176 }, - { id: "KALICONT000005635872", num: 275 }, - { id: "KALICONT000005635856", num: 292 }, - { id: "KALICONT000005635407", num: 413 }, - { id: "KALICONT000005635373", num: 573 }, - { id: "KALICONT000005635842", num: 650 }, - { id: "KALICONT000005635617", num: 675 }, - { id: "KALICONT000005635826", num: 787 }, - { id: "KALICONT000005635886", num: 843 }, - { id: "KALICONT000005635953", num: 1043 }, - { id: "KALICONT000005635191", num: 1090 }, - { id: "KALICONT000005635409", num: 1147 }, - { id: "KALICONT000005635418", num: 1266 }, - { id: "KALICONT000005635405", num: 1351 }, - { id: "KALICONT000005635653", num: 1404 }, - { id: "KALICONT000005635444", num: 1480 }, - { id: "KALICONT000005635594", num: 1483 }, - { id: "KALICONT000005635173", num: 1486 }, - { id: "KALICONT000005635596", num: 1501 }, - { id: "KALICONT000005635421", num: 1505 }, - { id: "KALICONT000005635435", num: 1516 }, - { id: "KALICONT000005635870", num: 1517 }, - { id: "KALICONT000005635177", num: 1518 }, - { id: "KALICONT000005635413", num: 1527 }, - { id: "KALICONT000005635221", num: 1596 }, - { id: "KALICONT000005635220", num: 1597 }, - { id: "KALICONT000005635871", num: 1606 }, - { id: "KALICONT000005635918", num: 1672 }, - { id: "KALICONT000005635467", num: 1702 }, - { id: "KALICONT000005635534", num: 1979 }, - { id: "KALICONT000005635528", num: 1996 }, - { id: "KALICONT000005635550", num: 2098 }, - { id: "KALICONT000005635792", num: 2111 }, - { id: "KALICONT000005635780", num: 2120 }, - { id: "KALICONT000005635557", num: 2148 }, - { id: "KALICONT000005635085", num: 2216 }, - { id: "KALICONT000005635813", num: 2264 }, - { id: "KALICONT000005635807", num: 2395 }, - { id: "KALICONT000017941839", num: 2420 }, - { id: "KALICONT000017577652", num: 2511 }, - { id: "KALICONT000018563755", num: 2596 }, - { id: "KALICONT000018773893", num: 2609 }, - { id: "KALICONT000018926209", num: 2614 }, - { id: "KALICONT000025805800", num: 2941 }, - { id: "KALICONT000027172335", num: 3043 }, - { id: "KALICONT000027084096", num: 3127 }, -]; diff --git a/targets/alert-cli/src/diff/dila/CompareDilaContent.ts b/targets/alert-cli/src/diff/dila/CompareDilaContent.ts index 81add38da..8d8da4958 100644 --- a/targets/alert-cli/src/diff/dila/CompareDilaContent.ts +++ b/targets/alert-cli/src/diff/dila/CompareDilaContent.ts @@ -19,8 +19,8 @@ import type { import parents from "unist-util-parents"; import { selectAll } from "unist-util-select"; -import type { AgreementFileChange } from "./Agreement/types"; -import type { CodeFileChange } from "./Code/types"; +import type { AgreementFileChange } from "./kali/types"; +import type { CodeFileChange } from "./legi/types"; import type { Article, ArticleWithParent, diff --git a/targets/alert-cli/src/diff/dila/ReleventDocuments.ts b/targets/alert-cli/src/diff/dila/RelevantDocuments.ts similarity index 80% rename from targets/alert-cli/src/diff/dila/ReleventDocuments.ts rename to targets/alert-cli/src/diff/dila/RelevantDocuments.ts index e57aa0878..7f3c6e3ea 100644 --- a/targets/alert-cli/src/diff/dila/ReleventDocuments.ts +++ b/targets/alert-cli/src/diff/dila/RelevantDocuments.ts @@ -1,7 +1,7 @@ -import getContribReferences from "../../extractDilaReferences/contribution"; -import getEditorialContentReferences from "../../extractDilaReferences/editorialContents"; -import getTravailEmploiReferences from "../../extractDilaReferences/ficheTravailEmploi"; -import getMailTemplateReferences from "../../extractDilaReferences/mailTemplates"; +import getContribReferences from "./extractReferences/contribution"; +import getEditorialContentReferences from "./extractReferences/editorialContents"; +import getTravailEmploiReferences from "./extractReferences/ficheTravailEmploi"; +import getMailTemplateReferences from "./extractReferences/mailTemplates"; import { DilaChanges } from "./types"; import { DocumentReferences } from "@shared/types"; diff --git a/targets/alert-cli/src/diff/__tests__/RelevantDocumentsExtractorStub.ts b/targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts similarity index 81% rename from targets/alert-cli/src/diff/__tests__/RelevantDocumentsExtractorStub.ts rename to targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts index 49a8579a1..fb145695d 100644 --- a/targets/alert-cli/src/diff/__tests__/RelevantDocumentsExtractorStub.ts +++ b/targets/alert-cli/src/diff/dila/__tests__/RelevantDocumentsExtractorStub.ts @@ -1,4 +1,4 @@ -import { RelevantDocumentsExtractor } from "../dila/ReleventDocuments"; +import { RelevantDocumentsExtractor } from "../RelevantDocuments"; import { DilaChanges, DocumentReferences } from "@shared/types"; export class RelevantDocumentsExtractorStub diff --git a/targets/alert-cli/src/__tests__/relevantContent.test.ts b/targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts similarity index 90% rename from targets/alert-cli/src/__tests__/relevantContent.test.ts rename to targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts index fac42e405..659edf07b 100644 --- a/targets/alert-cli/src/__tests__/relevantContent.test.ts +++ b/targets/alert-cli/src/diff/dila/__tests__/relevantContent.test.ts @@ -1,11 +1,11 @@ import { describe, expect, it } from "@jest/globals"; import type { DilaChanges } from "@shared/types"; -import { RelevantDocumentsExtractorImpl } from "../diff/dila/ReleventDocuments"; +import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments"; -jest.mock("../extractDilaReferences/ficheTravailEmploi", () => () => []); -jest.mock("../extractDilaReferences/mailTemplates", () => () => []); -jest.mock("../extractDilaReferences/editorialContents", () => () => []); -jest.mock("../extractDilaReferences/contribution", () => () => [ +jest.mock("../extractReferences/ficheTravailEmploi", () => () => []); +jest.mock("../extractReferences/mailTemplates", () => () => []); +jest.mock("../extractReferences/editorialContents", () => () => []); +jest.mock("../extractReferences/contribution", () => () => [ { document: { id: "id-generic", diff --git a/targets/alert-cli/src/extractDilaReferences/__tests__/editorialContents.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/editorialContents.test.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/__tests__/editorialContents.test.ts rename to targets/alert-cli/src/diff/dila/extractReferences/__tests__/editorialContents.test.ts diff --git a/targets/alert-cli/src/extractDilaReferences/__tests__/ficheTravailEmploi.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/ficheTravailEmploi.test.ts similarity index 98% rename from targets/alert-cli/src/extractDilaReferences/__tests__/ficheTravailEmploi.test.ts rename to targets/alert-cli/src/diff/dila/extractReferences/__tests__/ficheTravailEmploi.test.ts index e5e015474..87ebdca82 100644 --- a/targets/alert-cli/src/extractDilaReferences/__tests__/ficheTravailEmploi.test.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/ficheTravailEmploi.test.ts @@ -3,7 +3,7 @@ import { expect, test } from "@jest/globals"; import type { FicheTravail } from "../ficheTravailEmploi"; import main, { extractFicheTravailEmploiRef } from "../ficheTravailEmploi"; -jest.mock("../getAllDocumentsBySource", () => { +jest.mock("../../../shared/getAllDocumentsBySource", () => { return { getAllDocumentsBySource: () => mockFiches, }; diff --git a/targets/alert-cli/src/extractDilaReferences/__tests__/mailTemplates.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mailTemplates.test.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/__tests__/mailTemplates.test.ts rename to targets/alert-cli/src/diff/dila/extractReferences/__tests__/mailTemplates.test.ts diff --git a/targets/alert-cli/src/extractDilaReferences/__tests__/mocks/editorialContent.payload.json b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mocks/editorialContent.payload.json similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/__tests__/mocks/editorialContent.payload.json rename to targets/alert-cli/src/diff/dila/extractReferences/__tests__/mocks/editorialContent.payload.json diff --git a/targets/alert-cli/src/extractDilaReferences/__tests__/mocks/mailTemplate.payload.json b/targets/alert-cli/src/diff/dila/extractReferences/__tests__/mocks/mailTemplate.payload.json similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/__tests__/mocks/mailTemplate.payload.json rename to targets/alert-cli/src/diff/dila/extractReferences/__tests__/mocks/mailTemplate.payload.json diff --git a/targets/alert-cli/src/extractDilaReferences/contribution/__tests__/getContributionsReferences.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/__tests__/getContributionsReferences.test.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/contribution/__tests__/getContributionsReferences.test.ts rename to targets/alert-cli/src/diff/dila/extractReferences/contribution/__tests__/getContributionsReferences.test.ts diff --git a/targets/alert-cli/src/extractDilaReferences/contribution/__tests__/getOldContrib.test.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/__tests__/getOldContrib.test.ts similarity index 98% rename from targets/alert-cli/src/extractDilaReferences/contribution/__tests__/getOldContrib.test.ts rename to targets/alert-cli/src/diff/dila/extractReferences/contribution/__tests__/getOldContrib.test.ts index 72613ca66..ef48778f0 100644 --- a/targets/alert-cli/src/extractDilaReferences/contribution/__tests__/getOldContrib.test.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/contribution/__tests__/getOldContrib.test.ts @@ -3,7 +3,7 @@ import { expect, test } from "@jest/globals"; import type { Contrib } from "../getOldContribRef"; import { extractContributionsRef, getOldContribRef } from "../getOldContribRef"; -jest.mock("../../getAllDocumentsBySource", () => { +jest.mock("../../../../shared/getAllDocumentsBySource", () => { return { getAllDocumentsBySource: () => mockContributions, }; diff --git a/targets/alert-cli/src/extractDilaReferences/contribution/getContributionsReferences.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/getContributionsReferences.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/contribution/getContributionsReferences.ts rename to targets/alert-cli/src/diff/dila/extractReferences/contribution/getContributionsReferences.ts diff --git a/targets/alert-cli/src/extractDilaReferences/contribution/getOldContribRef.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/getOldContribRef.ts similarity index 96% rename from targets/alert-cli/src/extractDilaReferences/contribution/getOldContribRef.ts rename to targets/alert-cli/src/diff/dila/extractReferences/contribution/getOldContribRef.ts index 0ef5bbe60..96bd8d49b 100644 --- a/targets/alert-cli/src/extractDilaReferences/contribution/getOldContribRef.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/contribution/getOldContribRef.ts @@ -5,7 +5,7 @@ import type { } from "@shared/types"; import { SOURCES } from "@socialgouv/cdtn-sources"; -import { getAllDocumentsBySource } from "../getAllDocumentsBySource"; +import { getAllDocumentsBySource } from "../../../shared/getAllDocumentsBySource"; export type Contrib = Pick< ContributionComplete | ContributionFiltered, diff --git a/targets/alert-cli/src/extractDilaReferences/contribution/index.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/index.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/contribution/index.ts rename to targets/alert-cli/src/diff/dila/extractReferences/contribution/index.ts diff --git a/targets/alert-cli/src/extractDilaReferences/contribution/queryContributionsReferences.ts b/targets/alert-cli/src/diff/dila/extractReferences/contribution/queryContributionsReferences.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/contribution/queryContributionsReferences.ts rename to targets/alert-cli/src/diff/dila/extractReferences/contribution/queryContributionsReferences.ts diff --git a/targets/alert-cli/src/extractDilaReferences/editorialContents.ts b/targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts similarity index 94% rename from targets/alert-cli/src/extractDilaReferences/editorialContents.ts rename to targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts index 86a913d27..282d96cf9 100644 --- a/targets/alert-cli/src/extractDilaReferences/editorialContents.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/editorialContents.ts @@ -12,8 +12,8 @@ import { DilaApiClient } from "@socialgouv/dila-api-client"; import memoizee from "memoizee"; import pMap from "p-map"; -import { getAllDocumentsBySource } from "./getAllDocumentsBySource"; -import { WarningRepository } from "../repositories/WarningRepository"; +import { getAllDocumentsBySource } from "../../shared/getAllDocumentsBySource"; +import { WarningRepository } from "../../../repositories/WarningRepository"; import { gqlClient } from "@shared/utils"; export type EditorialContentSubset = Pick< diff --git a/targets/alert-cli/src/extractDilaReferences/ficheTravailEmploi.ts b/targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts similarity index 94% rename from targets/alert-cli/src/extractDilaReferences/ficheTravailEmploi.ts rename to targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts index e37136985..6893d7467 100644 --- a/targets/alert-cli/src/extractDilaReferences/ficheTravailEmploi.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/ficheTravailEmploi.ts @@ -2,7 +2,7 @@ import type { DocumentReferences, FicheTravailEmploi } from "@shared/types"; import { SOURCES } from "@socialgouv/cdtn-sources"; import memoizee from "memoizee"; -import { getAllDocumentsBySource } from "./getAllDocumentsBySource"; +import { getAllDocumentsBySource } from "../../shared/getAllDocumentsBySource"; let references: DocumentReferences[] = []; diff --git a/targets/alert-cli/src/extractDilaReferences/mailTemplates.ts b/targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts similarity index 92% rename from targets/alert-cli/src/extractDilaReferences/mailTemplates.ts rename to targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts index c253746ca..f01f36eed 100644 --- a/targets/alert-cli/src/extractDilaReferences/mailTemplates.ts +++ b/targets/alert-cli/src/diff/dila/extractReferences/mailTemplates.ts @@ -8,8 +8,8 @@ import { DilaApiClient } from "@socialgouv/dila-api-client"; import memoizee from "memoizee"; import pMap from "p-map"; -import { getAllDocumentsBySource } from "./getAllDocumentsBySource"; -import { WarningRepository } from "../repositories/WarningRepository"; +import { getAllDocumentsBySource } from "../../shared/getAllDocumentsBySource"; +import { WarningRepository } from "../../../repositories/WarningRepository"; import { gqlClient } from "@shared/utils"; export type MailTemplateSubset = Pick< diff --git a/targets/alert-cli/src/diff/dila/index.ts b/targets/alert-cli/src/diff/dila/index.ts index 54afe1f52..3da4b3403 100644 --- a/targets/alert-cli/src/diff/dila/index.ts +++ b/targets/alert-cli/src/diff/dila/index.ts @@ -1,3 +1,3 @@ -export * from "./Agreement"; -export * from "./Code"; +export * from "./kali"; +export * from "./legi"; export * from "./CompareDilaContent"; diff --git a/targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementChanges.ts b/targets/alert-cli/src/diff/dila/kali/ProcessAgreementChanges.ts similarity index 96% rename from targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementChanges.ts rename to targets/alert-cli/src/diff/dila/kali/ProcessAgreementChanges.ts index 5daafc768..8cf4407ce 100644 --- a/targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementChanges.ts +++ b/targets/alert-cli/src/diff/dila/kali/ProcessAgreementChanges.ts @@ -8,7 +8,7 @@ import { } from "../CompareDilaContent"; import type { Diff, DilaChanges } from "../types"; import type { AgreementFileChange } from "./types"; -import { RelevantDocumentsExtractor } from "../ReleventDocuments"; +import { RelevantDocumentsExtractor } from "../RelevantDocuments"; function extractChanges(fileChange: AgreementFileChange): { changes: Diff; diff --git a/targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementDataDiff.ts b/targets/alert-cli/src/diff/dila/kali/ProcessAgreementDataDiff.ts similarity index 87% rename from targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementDataDiff.ts rename to targets/alert-cli/src/diff/dila/kali/ProcessAgreementDataDiff.ts index b82097bae..f7e93fcc4 100644 --- a/targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementDataDiff.ts +++ b/targets/alert-cli/src/diff/dila/kali/ProcessAgreementDataDiff.ts @@ -1,7 +1,7 @@ -import type { DataDiffFunction } from "../../type"; +import type { DataDiffFunction } from "../../../types"; import processAgreementChanges from "./ProcessAgreementChanges"; import processAgreementFileChanges from "./ProcessAgreementFileChanges"; -import { RelevantDocumentsExtractorImpl } from "../ReleventDocuments"; +import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments"; const processAgreementDataDiff: DataDiffFunction = async ({ tag, diff --git a/targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementFileChanges.ts b/targets/alert-cli/src/diff/dila/kali/ProcessAgreementFileChanges.ts similarity index 90% rename from targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementFileChanges.ts rename to targets/alert-cli/src/diff/dila/kali/ProcessAgreementFileChanges.ts index f070d01c8..3fb4ecf41 100644 --- a/targets/alert-cli/src/diff/dila/Agreement/ProcessAgreementFileChanges.ts +++ b/targets/alert-cli/src/diff/dila/kali/ProcessAgreementFileChanges.ts @@ -1,8 +1,8 @@ import type { Agreement } from "@socialgouv/kali-data-types"; -import { createToJson, getFilename } from "../../../node-git.helpers"; +import { createToJson, getFilename } from "../../../utils/node-git.helpers"; import type { AgreementFileChange } from "./types"; -import { Diff, DiffFile, LoadFileFn } from "../../type"; +import { Diff, DiffFile, LoadFileFn } from "../../../types"; import { GitTagData } from "../../../types"; const agreementFileChange = async ( diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_added.json b/targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_added.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_added.json rename to targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_added.json diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_irrevelant_changes.json b/targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_irrevelant_changes.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_irrevelant_changes.json rename to targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_irrevelant_changes.json diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_no_changes.json b/targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_no_changes.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_no_changes.json rename to targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_no_changes.json diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_removed.json b/targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_removed.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_removed.json rename to targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_removed.json diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_revelant_changes.json b/targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_revelant_changes.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/dataset/filechanges_kali_agreement_revelant_changes.json rename to targets/alert-cli/src/diff/dila/kali/__tests__/dataset/filechanges_kali_agreement_revelant_changes.json diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dilaDataDiff.spec.ts b/targets/alert-cli/src/diff/dila/kali/__tests__/dilaDataDiff.spec.ts similarity index 97% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/dilaDataDiff.spec.ts rename to targets/alert-cli/src/diff/dila/kali/__tests__/dilaDataDiff.spec.ts index a75b21aae..c2eb21623 100644 --- a/targets/alert-cli/src/diff/dila/Agreement/__tests__/dilaDataDiff.spec.ts +++ b/targets/alert-cli/src/diff/dila/kali/__tests__/dilaDataDiff.spec.ts @@ -8,7 +8,7 @@ import noChanges from "./dataset/filechanges_kali_agreement_no_changes.json"; import removed from "./dataset/filechanges_kali_agreement_removed.json"; import revelantChanges from "./dataset/filechanges_kali_agreement_revelant_changes.json"; import { Commit } from "../../../../types"; -import { RelevantDocumentsExtractorStub } from "../../../__tests__/RelevantDocumentsExtractorStub"; +import { RelevantDocumentsExtractorStub } from "../../__tests__/RelevantDocumentsExtractorStub"; describe("Calcul des différences sur les conventions collectives (kali-data)", () => { describe("Aucun changement dans une convention collective", () => { diff --git a/targets/alert-cli/src/diff/dila/Agreement/__tests__/processAgreementFileChanges.spec.ts b/targets/alert-cli/src/diff/dila/kali/__tests__/processAgreementFileChanges.spec.ts similarity index 97% rename from targets/alert-cli/src/diff/dila/Agreement/__tests__/processAgreementFileChanges.spec.ts rename to targets/alert-cli/src/diff/dila/kali/__tests__/processAgreementFileChanges.spec.ts index 76f251fee..e26a465f6 100644 --- a/targets/alert-cli/src/diff/dila/Agreement/__tests__/processAgreementFileChanges.spec.ts +++ b/targets/alert-cli/src/diff/dila/kali/__tests__/processAgreementFileChanges.spec.ts @@ -1,7 +1,7 @@ import { describe, expect } from "@jest/globals"; import processAgreementFileChanges from "../ProcessAgreementFileChanges"; -import { DiffFile, LoadFileFn, PatchStatus } from "../../../type"; +import { DiffFile, LoadFileFn, PatchStatus } from "../../../../types"; describe("Creation des AgreementFileChange à partir d'un patch", () => { const createPatch = (status: PatchStatus): DiffFile => { diff --git a/targets/alert-cli/src/diff/dila/Agreement/index.ts b/targets/alert-cli/src/diff/dila/kali/index.ts similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/index.ts rename to targets/alert-cli/src/diff/dila/kali/index.ts diff --git a/targets/alert-cli/src/diff/dila/Agreement/types.ts b/targets/alert-cli/src/diff/dila/kali/types.ts similarity index 100% rename from targets/alert-cli/src/diff/dila/Agreement/types.ts rename to targets/alert-cli/src/diff/dila/kali/types.ts diff --git a/targets/alert-cli/src/diff/dila/Code/ProcessCodeChanges.ts b/targets/alert-cli/src/diff/dila/legi/ProcessCodeChanges.ts similarity index 94% rename from targets/alert-cli/src/diff/dila/Code/ProcessCodeChanges.ts rename to targets/alert-cli/src/diff/dila/legi/ProcessCodeChanges.ts index 59e019ad1..33b06296f 100644 --- a/targets/alert-cli/src/diff/dila/Code/ProcessCodeChanges.ts +++ b/targets/alert-cli/src/diff/dila/legi/ProcessCodeChanges.ts @@ -4,7 +4,7 @@ import type { GitTagData } from "../../../types"; import { compareDilaContent } from "../CompareDilaContent"; import type { DilaChanges } from "../types"; import type { CodeFileChange } from "./types"; -import { RelevantDocumentsExtractor } from "../ReleventDocuments"; +import { RelevantDocumentsExtractor } from "../RelevantDocuments"; const processCodeChanges = async ( tag: GitTagData, diff --git a/targets/alert-cli/src/diff/dila/Code/ProcessCodeDataDiff.ts b/targets/alert-cli/src/diff/dila/legi/ProcessCodeDataDiff.ts similarity index 87% rename from targets/alert-cli/src/diff/dila/Code/ProcessCodeDataDiff.ts rename to targets/alert-cli/src/diff/dila/legi/ProcessCodeDataDiff.ts index b43090e8e..ddfef4fa9 100644 --- a/targets/alert-cli/src/diff/dila/Code/ProcessCodeDataDiff.ts +++ b/targets/alert-cli/src/diff/dila/legi/ProcessCodeDataDiff.ts @@ -1,7 +1,7 @@ -import type { DataDiffFunction } from "../../type"; +import type { DataDiffFunction } from "../../../types"; import processCodeChanges from "./ProcessCodeChanges"; import processCodeFileChanges from "./ProcessCodeFileChanges"; -import { RelevantDocumentsExtractorImpl } from "../ReleventDocuments"; +import { RelevantDocumentsExtractorImpl } from "../RelevantDocuments"; const processCodeDataDiff: DataDiffFunction = async ({ tag, diff --git a/targets/alert-cli/src/diff/dila/Code/ProcessCodeFileChanges.ts b/targets/alert-cli/src/diff/dila/legi/ProcessCodeFileChanges.ts similarity index 88% rename from targets/alert-cli/src/diff/dila/Code/ProcessCodeFileChanges.ts rename to targets/alert-cli/src/diff/dila/legi/ProcessCodeFileChanges.ts index d9f10333c..790c10b11 100644 --- a/targets/alert-cli/src/diff/dila/Code/ProcessCodeFileChanges.ts +++ b/targets/alert-cli/src/diff/dila/legi/ProcessCodeFileChanges.ts @@ -1,8 +1,8 @@ import type { Code } from "@socialgouv/legi-data-types"; -import { createToJson } from "../../../node-git.helpers"; +import { createToJson } from "../../../utils/node-git.helpers"; import type { CodeFileChange } from "./types"; -import { Diff, DiffFile, LoadFileFn } from "../../type"; +import { Diff, DiffFile, LoadFileFn } from "../../../types"; import { GitTagData } from "../../../types"; const codeFileChanges = async ( diff --git a/targets/alert-cli/src/diff/dila/Code/__tests__/dataset/filechanges_legi_code_irrevelant_changes.json b/targets/alert-cli/src/diff/dila/legi/__tests__/dataset/filechanges_legi_code_irrevelant_changes.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Code/__tests__/dataset/filechanges_legi_code_irrevelant_changes.json rename to targets/alert-cli/src/diff/dila/legi/__tests__/dataset/filechanges_legi_code_irrevelant_changes.json diff --git a/targets/alert-cli/src/diff/dila/Code/__tests__/dataset/filechanges_legi_code_no_changes.json b/targets/alert-cli/src/diff/dila/legi/__tests__/dataset/filechanges_legi_code_no_changes.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Code/__tests__/dataset/filechanges_legi_code_no_changes.json rename to targets/alert-cli/src/diff/dila/legi/__tests__/dataset/filechanges_legi_code_no_changes.json diff --git a/targets/alert-cli/src/diff/dila/Code/__tests__/dataset/filechanges_legi_code_revelant_changes.json b/targets/alert-cli/src/diff/dila/legi/__tests__/dataset/filechanges_legi_code_revelant_changes.json similarity index 100% rename from targets/alert-cli/src/diff/dila/Code/__tests__/dataset/filechanges_legi_code_revelant_changes.json rename to targets/alert-cli/src/diff/dila/legi/__tests__/dataset/filechanges_legi_code_revelant_changes.json diff --git a/targets/alert-cli/src/diff/dila/Code/__tests__/dilaDataDiff.spec.ts b/targets/alert-cli/src/diff/dila/legi/__tests__/dilaDataDiff.spec.ts similarity index 96% rename from targets/alert-cli/src/diff/dila/Code/__tests__/dilaDataDiff.spec.ts rename to targets/alert-cli/src/diff/dila/legi/__tests__/dilaDataDiff.spec.ts index aa4d229cd..ab15288c8 100644 --- a/targets/alert-cli/src/diff/dila/Code/__tests__/dilaDataDiff.spec.ts +++ b/targets/alert-cli/src/diff/dila/legi/__tests__/dilaDataDiff.spec.ts @@ -6,7 +6,7 @@ import irrevelantChanges from "./dataset/filechanges_legi_code_irrevelant_change import noChanges from "./dataset/filechanges_legi_code_no_changes.json"; import revelantChanges from "./dataset/filechanges_legi_code_revelant_changes.json"; import { Commit } from "../../../../types"; -import { RelevantDocumentsExtractorStub } from "../../../__tests__/RelevantDocumentsExtractorStub"; +import { RelevantDocumentsExtractorStub } from "../../__tests__/RelevantDocumentsExtractorStub"; describe("Calcul des différences sur les code (legi-data)", () => { describe("Aucun changement", () => { diff --git a/targets/alert-cli/src/diff/dila/Code/index.ts b/targets/alert-cli/src/diff/dila/legi/index.ts similarity index 100% rename from targets/alert-cli/src/diff/dila/Code/index.ts rename to targets/alert-cli/src/diff/dila/legi/index.ts diff --git a/targets/alert-cli/src/diff/dila/Code/types.ts b/targets/alert-cli/src/diff/dila/legi/types.ts similarity index 100% rename from targets/alert-cli/src/diff/dila/Code/types.ts rename to targets/alert-cli/src/diff/dila/legi/types.ts diff --git a/targets/alert-cli/src/diff/dila/types.ts b/targets/alert-cli/src/diff/dila/types.ts index c088acfba..136ad662e 100644 --- a/targets/alert-cli/src/diff/dila/types.ts +++ b/targets/alert-cli/src/diff/dila/types.ts @@ -13,8 +13,8 @@ import type { } from "@socialgouv/kali-data-types"; import type { CodeArticle, CodeSection } from "@socialgouv/legi-data-types"; -import type { AgreementFileChange } from "./Agreement/types"; -import type { CodeFileChange } from "./Code/types"; +import type { AgreementFileChange } from "./kali/types"; +import type { CodeFileChange } from "./legi/types"; export type DilaChanges = CommonDilaChanges & { file: string; diff --git a/targets/alert-cli/src/diff/index.ts b/targets/alert-cli/src/diff/index.ts index 4893226ce..cf1ce0578 100644 --- a/targets/alert-cli/src/diff/index.ts +++ b/targets/alert-cli/src/diff/index.ts @@ -1,11 +1,11 @@ -import { ccns } from "../ccn-list"; -import { DataDiffFunction } from "./type"; +import { DataDiffFunction } from "../types"; import { processAgreementDataDiff, processCodeDataDiff } from "./dila"; -import { processVddDiff } from "./fiches-vdd"; -import { processTravailDataDiff } from "./fiches-travail-data"; +import { processVddDiff } from "./sp"; +import { processTravailDataDiff } from "./travail-data"; import { GitTagData } from "../types"; import { AlertChanges } from "@shared/types"; -import { GithubApi } from "../APIs/api"; +import { GithubApi } from "../utils/github"; +import { getAgreements } from "./shared/getAgreements"; export class AlertDetector { githubApi: GithubApi; @@ -19,6 +19,7 @@ export class AlertDetector { private async getFileFilter( repository: string ): Promise<(path: string) => boolean> { + const ccns = await getAgreements(); switch (repository) { case "socialgouv/legi-data": // only code-du-travail @@ -26,7 +27,7 @@ export class AlertDetector { case "socialgouv/kali-data": // only a ccn matching our list return (path: string) => - ccns.some((ccn) => new RegExp(ccn.id).test(path)); + ccns.some((ccn) => new RegExp(ccn.kali_id).test(path)); case "socialgouv/fiches-vdd": { /** @type {string[]} */ const ficheVddIDs = this.fichesServicePublicIds; diff --git a/targets/alert-cli/src/diff/pre-qualified-relevant-content.ts b/targets/alert-cli/src/diff/pre-qualified-relevant-content.ts deleted file mode 100644 index 0f06f24bf..000000000 --- a/targets/alert-cli/src/diff/pre-qualified-relevant-content.ts +++ /dev/null @@ -1,117 +0,0 @@ -import type { - DocumentInfo, - DocumentInfoWithCdtnRef, - TravailDataChanges, - VddChanges, -} from "@shared/types"; -import { SOURCES } from "@socialgouv/cdtn-sources"; -import memoizee from "memoizee"; - -import { getDocumentsWithRelationsBySource } from "../extractDilaReferences/getAllDocumentsBySource"; - -export async function _getDocumentsWithRelations(): Promise< - Map -> { - const documents = await getDocumentsWithRelationsBySource([ - SOURCES.PREQUALIFIED, - SOURCES.THEMES, - ]); - const prequalifiedMap = new Map(); - for (const document of documents) { - for (const doc of document.contentRelations) { - const requestDocs = prequalifiedMap.get(doc.document.initialId); - if (requestDocs) { - requestDocs.push({ - id: document.cdtnId, - source: document.source, - title: document.title, - }); - } else { - prequalifiedMap.set(doc.document.initialId, [ - { - id: document.cdtnId, - source: document.source, - title: document.title, - }, - ]); - } - } - } - return prequalifiedMap; -} - -const getDocumentsWithRelations = memoizee(_getDocumentsWithRelations, { - promise: true, -}); - -export async function vddPrequalifiedRelevantDocuments({ - modified, - removed, -}: Pick): Promise< - DocumentInfoWithCdtnRef[] -> { - const themeOrPrequalifiedDocs = await getDocumentsWithRelations(); - return modified - .flatMap((doc) => { - const documents = themeOrPrequalifiedDocs.get(doc.id); - if (documents) { - return documents.map((requestInfo) => { - return { - ...requestInfo, - ref: { id: doc.id, title: doc.title }, - }; - }); - } - return []; - }) - .concat( - removed.flatMap((doc) => { - const documents = themeOrPrequalifiedDocs.get(doc.id); - if (documents) { - return documents.map((requestInfo) => { - return { - ...requestInfo, - ref: { id: doc.id, title: doc.title }, - }; - }); - } - return []; - }) - ); -} - -export async function ficheTravailPrequalifiedRelevantDocuments({ - modified, - removed, -}: Pick): Promise< - DocumentInfoWithCdtnRef[] -> { - const themeOrPrequalifiedDocs = await getDocumentsWithRelations(); - return modified - .flatMap((doc) => { - const documents = themeOrPrequalifiedDocs.get(doc.pubId); - if (documents) { - return documents.map((requestInfo) => { - return { - ...requestInfo, - ref: { id: doc.pubId, title: doc.title }, - }; - }); - } - return []; - }) - .concat( - removed.flatMap((doc) => { - const documents = themeOrPrequalifiedDocs.get(doc.pubId); - if (documents) { - return documents.map((requestInfo) => { - return { - ...requestInfo, - ref: { id: doc.pubId, title: doc.title }, - }; - }); - } - return []; - }) - ); -} diff --git a/targets/alert-cli/src/__tests__/pre-qualified-relevant-content.test.ts b/targets/alert-cli/src/diff/shared/__tests__/getDocumentsWithRelations.test.ts similarity index 83% rename from targets/alert-cli/src/__tests__/pre-qualified-relevant-content.test.ts rename to targets/alert-cli/src/diff/shared/__tests__/getDocumentsWithRelations.test.ts index a22572f54..71b190d76 100644 --- a/targets/alert-cli/src/__tests__/pre-qualified-relevant-content.test.ts +++ b/targets/alert-cli/src/diff/shared/__tests__/getDocumentsWithRelations.test.ts @@ -1,8 +1,9 @@ import { describe, expect, it } from "@jest/globals"; -import { _getDocumentsWithRelations } from "../diff/pre-qualified-relevant-content"; +import { getDocumentsWithRelations } from "../getDocumentsWithRelations"; +import { SOURCES } from "@socialgouv/cdtn-sources"; -jest.mock("../extractDilaReferences/getAllDocumentsBySource", () => ({ +jest.mock("../getAllDocumentsBySource", () => ({ getDocumentsWithRelationsBySource: async () => Promise.resolve([ { @@ -49,9 +50,12 @@ jest.mock("../extractDilaReferences/getAllDocumentsBySource", () => ({ ]), })); -describe("_getDocumentsWithRelations", () => { +describe("getDocumentsWithRelations", () => { it("should return a list of documents which are in relation with a prequalified or a themes", async () => { - const result = await _getDocumentsWithRelations(); + const result = await getDocumentsWithRelations([ + SOURCES.PREQUALIFIED, + SOURCES.THEMES, + ]); expect(result.size).toEqual(2); expect(result.get("F2839")).toEqual([ { diff --git a/targets/alert-cli/src/diff/shared/getAgreements.ts b/targets/alert-cli/src/diff/shared/getAgreements.ts new file mode 100644 index 000000000..0ada4ac83 --- /dev/null +++ b/targets/alert-cli/src/diff/shared/getAgreements.ts @@ -0,0 +1,27 @@ +import { gqlClient } from "@shared/utils"; +import { PublicAgreement } from "../../types"; + +const fetchAgreements = ` +query getAgreements { + agreements { + id + kali_id + } +} +`; + +interface HasuraReturn { + agreements: PublicAgreement[]; +} + +export async function getAgreements(): Promise { + const res = await gqlClient() + .query(fetchAgreements) + .toPromise(); + if (res.error || !res.data) { + throw new Error( + "Erreur lors de la requête pour récupérer les conventions collectives sur la db" + ); + } + return res.data.agreements; +} diff --git a/targets/alert-cli/src/extractDilaReferences/getAllDocumentsBySource.ts b/targets/alert-cli/src/diff/shared/getAllDocumentsBySource.ts similarity index 97% rename from targets/alert-cli/src/extractDilaReferences/getAllDocumentsBySource.ts rename to targets/alert-cli/src/diff/shared/getAllDocumentsBySource.ts index 566591ce9..4a6d7e91c 100644 --- a/targets/alert-cli/src/extractDilaReferences/getAllDocumentsBySource.ts +++ b/targets/alert-cli/src/diff/shared/getAllDocumentsBySource.ts @@ -2,7 +2,7 @@ import { gqlClient } from "@shared/utils"; import type { SourceValues } from "@socialgouv/cdtn-sources"; import memoizee from "memoizee"; -import { batchPromises } from "../batchPromises"; +import { batchPromises } from "../../utils/batch-promises"; import type { AllDocumentsBySourceResult, AllDocumentsWithRelationBySourceResult, diff --git a/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts b/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts new file mode 100644 index 000000000..d7c0b84d3 --- /dev/null +++ b/targets/alert-cli/src/diff/shared/getContributionsCdtnReferences.ts @@ -0,0 +1,44 @@ +import { ContributionsAnswers } from "@shared/types"; +import { gqlClient } from "@shared/utils"; + +const getContribCdtnReferences = ` +query getContribCdtnReferences($ids: [String!]) { + contribution_answers(where: {cdtn_references: {document: {initial_id: {_in: $ids}}}}) { + id + question { + id + content + order + } + cdtn_references { + cdtn_id + document { + initial_id + document + } + } + } +} +`; + +interface ContributionsHasuraResult { + contribution_answers: Required< + Pick + >[]; +} + +export async function getContributionsCdtnReferences( + ids: string[] +): Promise { + const res = await gqlClient() + .query(getContribCdtnReferences, { ids }) + .toPromise(); + + if (res.error || !res.data) { + throw new Error( + "Erreur de récupération des références des contributions au niveau des cdtn_references" + ); + } + + return res.data.contribution_answers; +} diff --git a/targets/alert-cli/src/extractDilaReferences/getDocumentQuery.gql.ts b/targets/alert-cli/src/diff/shared/getDocumentQuery.gql.ts similarity index 100% rename from targets/alert-cli/src/extractDilaReferences/getDocumentQuery.gql.ts rename to targets/alert-cli/src/diff/shared/getDocumentQuery.gql.ts diff --git a/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts b/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts new file mode 100644 index 000000000..f376bd2f5 --- /dev/null +++ b/targets/alert-cli/src/diff/shared/getDocumentsWithRelations.ts @@ -0,0 +1,32 @@ +import type { DocumentInfo } from "@shared/types"; +import { SourceValues } from "@socialgouv/cdtn-sources"; + +import { getDocumentsWithRelationsBySource } from "./getAllDocumentsBySource"; + +export async function getDocumentsWithRelations( + sources: SourceValues[] +): Promise> { + const documents = await getDocumentsWithRelationsBySource(sources); + const docMapped = new Map(); + for (const document of documents) { + for (const doc of document.contentRelations) { + const requestDocs = docMapped.get(doc.document.initialId); + if (requestDocs) { + requestDocs.push({ + id: document.cdtnId, + source: document.source, + title: document.title, + }); + } else { + docMapped.set(doc.document.initialId, [ + { + id: document.cdtnId, + source: document.source, + title: document.title, + }, + ]); + } + } + } + return docMapped; +} diff --git a/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts b/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts new file mode 100644 index 000000000..325254154 --- /dev/null +++ b/targets/alert-cli/src/diff/sp/getContributionsWithFicheSp.ts @@ -0,0 +1,43 @@ +import { ContributionsAnswers } from "@shared/types"; +import { gqlClient } from "@shared/utils"; + +const queryGetContributionsWithRefs = ` +query getContribsWithSp($ficheSpIds: [String!]) { + contribution_answers(where: {document: {initial_id: {_in: $ficheSpIds}}}) { + id + question { + id + content + order + } + content_fiche_sp: document { + initial_id + document + } + } +} +`; + +interface ContributionsHasuraResult { + contribution_answers: Required< + Pick + >[]; +} + +export async function getContributionsWithFicheSp( + ficheSpIds: string[] +): Promise { + const res = await gqlClient() + .query(queryGetContributionsWithRefs, { + ficheSpIds, + }) + .toPromise(); + + if (res.error || !res.data) { + throw new Error( + "Erreur de récupération des références des contributions au sein de queryContributionsReferences" + ); + } + + return res.data.contribution_answers; +} diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/__tests__/contributions.test.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/__tests__/contributions.test.ts new file mode 100644 index 000000000..bae989853 --- /dev/null +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/__tests__/contributions.test.ts @@ -0,0 +1,80 @@ +import { getRelevantSpDocumentsContributions } from "../contributions"; + +jest.mock("../../getContributionsWithFicheSp", () => ({ + getContributionsWithFicheSp: () => + Promise.resolve([ + { + id: "c1", + question: { + id: "1", + title: "Modified 1", + content: "Nom question 1", + }, + content_fiche_sp: { initial_id: "pubId1", document: { url: "url1" } }, + }, + { + id: "c2", + question: { + id: "2", + title: "Modified 2", + content: "Nom question 2", + }, + content_fiche_sp: { initial_id: "pubId3", document: { url: "url3" } }, + }, + ]), +})); + +jest.mock("../../../shared/getContributionsCdtnReferences", () => ({ + getContributionsCdtnReferences: () => + Promise.resolve([ + { + id: "c3", + question: { + id: "3", + title: "Modified 3", + content: "Nom question 3", + }, + cdtn_references: [{ document: { initial_id: "pubId2" } }], + }, + ]), +})); + +// Tests + +describe("getRelevantSpDocumentsContributions", () => { + it("should return empty array if no modified/removed docs", async () => { + const result = await getRelevantSpDocumentsContributions({ + modified: [], + removed: [], + }); + expect(result).toEqual([]); + }); + + it("should only return contributions referencing modified/removed docs", async () => { + // Mock data + const modified: any = [{ id: "pubId1", title: "Modified 1" }]; + const removed: any = [{ id: "pubId2", title: "Removed 2" }]; + + const expected = [ + { + ref: { id: "pubId1", title: "Modified 1" }, + id: "c1", + title: "Nom question 1", + source: "contributions", + url: "url1", + }, + { + ref: { id: "pubId2", title: "Removed 2" }, + id: "c3", + title: "Nom question 3", + source: "contributions", + }, + ]; + + const result = await getRelevantSpDocumentsContributions({ + modified, + removed, + }); + expect(result).toEqual(expected); + }); +}); diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts new file mode 100644 index 000000000..38167d4b8 --- /dev/null +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/contributions.ts @@ -0,0 +1,65 @@ +import type { DocumentInfoWithCdtnRef, VddChanges } from "@shared/types"; + +import { getContributionsWithFicheSp } from "./../getContributionsWithFicheSp"; +import { getContributionsCdtnReferences } from "../../shared/getContributionsCdtnReferences"; + +export async function getRelevantSpDocumentsContributions({ + modified, + removed, +}: Pick): Promise< + DocumentInfoWithCdtnRef[] +> { + const modifiedAndRemoved = [...modified, ...removed]; + + const ficheSpIdsInModifiedAndRemoved = modifiedAndRemoved.map( + (doc) => doc.id + ); + const contributionsGenericUsingSp = await getContributionsWithFicheSp( + ficheSpIdsInModifiedAndRemoved + ); + const contributionsRelevantDocGenericUsingSp = + contributionsGenericUsingSp.flatMap((item) => { + if (!item.content_fiche_sp) { + return []; + } + const doc = modifiedAndRemoved.find( + (node) => node.id === item.content_fiche_sp!.initial_id + ); + if (!doc) { + return []; + } + const res: DocumentInfoWithCdtnRef = { + ref: { id: doc.id, title: doc.title }, + id: item.id, + title: item.question.content, + source: "contributions", + url: item.content_fiche_sp.document.url, + }; + return [res]; + }); + + const contributionsCdtnReferences = await getContributionsCdtnReferences( + ficheSpIdsInModifiedAndRemoved + ); + const contributionsRelevantDocCdtnReferences: DocumentInfoWithCdtnRef[] = []; + contributionsCdtnReferences.forEach((item) => { + item.cdtn_references.forEach((cdtnRef) => { + const doc = modifiedAndRemoved.find( + (node) => node.id === cdtnRef.document!.initial_id + ); + if (doc) { + contributionsRelevantDocCdtnReferences.push({ + ref: { id: doc.id, title: doc.title }, + id: item.id, + title: item.question.content, + source: "contributions", + }); + } + }); + }); + + return [ + ...contributionsRelevantDocGenericUsingSp, + ...contributionsRelevantDocCdtnReferences, + ]; +} diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts new file mode 100644 index 000000000..75be1c5b2 --- /dev/null +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/index.ts @@ -0,0 +1,18 @@ +import type { DocumentInfoWithCdtnRef, VddChanges } from "@shared/types"; +import { getRelevantSpDocumentsThemeAndPrequalified } from "./themesAndPrequalified"; +import { getRelevantSpDocumentsContributions } from "./contributions"; + +export async function getRelevantSpDocuments({ + modified, + removed, +}: Pick): Promise< + DocumentInfoWithCdtnRef[] +> { + const themeAndPrequalifiedDocs = + await getRelevantSpDocumentsThemeAndPrequalified({ modified, removed }); + const contributions = await getRelevantSpDocumentsContributions({ + modified, + removed, + }); + return [...themeAndPrequalifiedDocs, ...contributions]; +} diff --git a/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts b/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts new file mode 100644 index 000000000..b8ed277c0 --- /dev/null +++ b/targets/alert-cli/src/diff/sp/getRelevantDocument/themesAndPrequalified.ts @@ -0,0 +1,32 @@ +import type { DocumentInfoWithCdtnRef, VddChanges } from "@shared/types"; +import { SOURCES } from "@socialgouv/cdtn-sources"; + +import { getDocumentsWithRelations } from "../../shared/getDocumentsWithRelations"; + +export async function getRelevantSpDocumentsThemeAndPrequalified({ + modified, + removed, +}: Pick): Promise< + DocumentInfoWithCdtnRef[] +> { + const modifiedAndRemoved = [...modified, ...removed]; + + const themeAndPrequalifiedDocs = await getDocumentsWithRelations([ + SOURCES.PREQUALIFIED, + SOURCES.THEMES, + ]); + const themeAndPrequaliedRelevantDoc = modifiedAndRemoved.flatMap((doc) => { + const documents = themeAndPrequalifiedDocs.get(doc.id); + if (documents) { + return documents.map((requestInfo) => { + return { + ...requestInfo, + ref: { id: doc.id, title: doc.title }, + }; + }); + } + return []; + }); + + return themeAndPrequaliedRelevantDoc; +} diff --git a/targets/alert-cli/src/diff/fiches-vdd.ts b/targets/alert-cli/src/diff/sp/index.ts similarity index 95% rename from targets/alert-cli/src/diff/fiches-vdd.ts rename to targets/alert-cli/src/diff/sp/index.ts index 4cca0f577..3644b36d0 100644 --- a/targets/alert-cli/src/diff/fiches-vdd.ts +++ b/targets/alert-cli/src/diff/sp/index.ts @@ -1,14 +1,14 @@ import type { FicheVddInfo, VddChanges } from "@shared/types"; -import { createToJson } from "../node-git.helpers"; +import { createToJson } from "../../utils/node-git.helpers"; import type { FicheVdd, FicheVddIndex, FicheVddNode, GitTagData, -} from "../types"; -import { vddPrequalifiedRelevantDocuments } from "./pre-qualified-relevant-content"; -import type { DataDiffFunction, DiffFile, LoadFileFn } from "./type"; +} from "../../types"; +import type { DataDiffFunction, DiffFile, LoadFileFn } from "../../types"; +import { getRelevantSpDocuments } from "./getRelevantDocument"; export const processVddDiff: DataDiffFunction = async ({ tag, @@ -126,7 +126,7 @@ export const processVddDiff: DataDiffFunction = async ({ ) { return []; } - const documents = await vddPrequalifiedRelevantDocuments(changes); + const documents = await getRelevantSpDocuments(changes); console.log(`${tag.ref} ${documents.length} prequalified/themes found`); return [ { diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/__tests__/contributions.test.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/__tests__/contributions.test.ts new file mode 100644 index 000000000..e62c9ed21 --- /dev/null +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/__tests__/contributions.test.ts @@ -0,0 +1,58 @@ +import { getRelevantMtDocumentsContributions } from "../contributions"; + +jest.mock("../../../shared/getContributionsCdtnReferences", () => ({ + getContributionsCdtnReferences: () => + Promise.resolve([ + { + id: "c1", + question: { + id: "1", + title: "Modified 1", + content: "Nom question 1", + }, + cdtn_references: [{ document: { initial_id: "pubId1" } }], + }, + { + id: "c2", + question: { + id: "2", + title: "Modified 2", + content: "Nom question 2", + }, + cdtn_references: [{ document: { initial_id: "pubId3" } }], + }, + ]), +})); + +// Tests + +describe("getRelevantMtDocumentsContributions", () => { + it("should return empty array if no modified/removed docs", async () => { + const result = await getRelevantMtDocumentsContributions({ + modified: [], + removed: [], + }); + expect(result).toEqual([]); + }); + + it("should only return contributions referencing modified/removed docs", async () => { + // Mock data + const modified: any = [{ pubId: "pubId1", title: "Modified 1" }]; + const removed: any = [{ pubId: "pubId2", title: "Removed 2" }]; + + const expected = [ + { + ref: { id: "pubId1", title: "Modified 1" }, + id: "c1", + title: "Nom question 1", + source: "contributions", + }, + ]; + + const result = await getRelevantMtDocumentsContributions({ + modified, + removed, + }); + expect(result).toEqual(expected); + }); +}); diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts new file mode 100644 index 000000000..afec2a73a --- /dev/null +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/contributions.ts @@ -0,0 +1,41 @@ +import type { + DocumentInfoWithCdtnRef, + TravailDataChanges, +} from "@shared/types"; + +import { getContributionsCdtnReferences } from "../../shared/getContributionsCdtnReferences"; + +export async function getRelevantMtDocumentsContributions({ + modified, + removed, +}: Pick): Promise< + DocumentInfoWithCdtnRef[] +> { + const modifiedAndRemoved = [...modified, ...removed]; + + const ficheMtIdsInModifiedAndRemoved = modifiedAndRemoved.map( + (doc) => doc.pubId + ); + + const contributionsCdtnReferences = await getContributionsCdtnReferences( + ficheMtIdsInModifiedAndRemoved + ); + + const contributionsRelevantDocCdtnReferences: DocumentInfoWithCdtnRef[] = []; + contributionsCdtnReferences.forEach((item) => { + item.cdtn_references.forEach((cdtnRef) => { + const doc = modifiedAndRemoved.find( + (node) => node.pubId === cdtnRef.document!.initial_id + ); + if (doc) { + contributionsRelevantDocCdtnReferences.push({ + ref: { id: doc.pubId, title: doc.title }, + id: item.id, + title: item.question.content, + source: "contributions", + }); + } + }); + }); + return contributionsRelevantDocCdtnReferences; +} diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts new file mode 100644 index 000000000..74b941891 --- /dev/null +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/index.ts @@ -0,0 +1,21 @@ +import type { + DocumentInfoWithCdtnRef, + TravailDataChanges, +} from "@shared/types"; +import { getRelevantMtDocumentsThemeAndPrequalified } from "./themesAndPrequalified"; +import { getRelevantMtDocumentsContributions } from "./contributions"; + +export async function getRelevantMtDocuments({ + modified, + removed, +}: Pick): Promise< + DocumentInfoWithCdtnRef[] +> { + const themeAndPrequalifiedDocs = + await getRelevantMtDocumentsThemeAndPrequalified({ modified, removed }); + const contributions = await getRelevantMtDocumentsContributions({ + modified, + removed, + }); + return [...themeAndPrequalifiedDocs, ...contributions]; +} diff --git a/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts new file mode 100644 index 000000000..460c8d84c --- /dev/null +++ b/targets/alert-cli/src/diff/travail-data/getRelevantDocument/themesAndPrequalified.ts @@ -0,0 +1,35 @@ +import type { + DocumentInfoWithCdtnRef, + TravailDataChanges, +} from "@shared/types"; +import { SOURCES } from "@socialgouv/cdtn-sources"; + +import { getDocumentsWithRelations } from "../../shared/getDocumentsWithRelations"; + +export async function getRelevantMtDocumentsThemeAndPrequalified({ + modified, + removed, +}: Pick): Promise< + DocumentInfoWithCdtnRef[] +> { + const modifiedAndRemoved = [...modified, ...removed]; + + const themeAndPrequalifiedDocs = await getDocumentsWithRelations([ + SOURCES.PREQUALIFIED, + SOURCES.THEMES, + ]); + const themeAndPrequaliedRelevantDoc = modifiedAndRemoved.flatMap((doc) => { + const documents = themeAndPrequalifiedDocs.get(doc.pubId); + if (documents) { + return documents.map((requestInfo) => { + return { + ...requestInfo, + ref: { id: doc.pubId, title: doc.title }, + }; + }); + } + return []; + }); + + return themeAndPrequaliedRelevantDoc; +} diff --git a/targets/alert-cli/src/diff/fiches-travail-data.ts b/targets/alert-cli/src/diff/travail-data/index.ts similarity index 93% rename from targets/alert-cli/src/diff/fiches-travail-data.ts rename to targets/alert-cli/src/diff/travail-data/index.ts index 6c8ac1f2f..305345e7a 100644 --- a/targets/alert-cli/src/diff/fiches-travail-data.ts +++ b/targets/alert-cli/src/diff/travail-data/index.ts @@ -4,9 +4,9 @@ import type { } from "@shared/types"; import type { FicheTravailEmploi } from "@socialgouv/fiches-travail-data-types"; -import { createToJson } from "../node-git.helpers"; -import { ficheTravailPrequalifiedRelevantDocuments } from "./pre-qualified-relevant-content"; -import type { DataDiffFunction } from "./type"; +import { createToJson } from "../../utils/node-git.helpers"; +import type { DataDiffFunction } from "../../types"; +import { getRelevantMtDocuments } from "./getRelevantDocument"; export const processTravailDataDiff: DataDiffFunction = async ({ tag, @@ -26,9 +26,7 @@ export const processTravailDataDiff: DataDiffFunction = async ({ toAst(patch, patches.from), ]); const changes = getChanges(prevAst, currAst); - changes.documents = await ficheTravailPrequalifiedRelevantDocuments( - changes - ); + changes.documents = await getRelevantMtDocuments(changes); console.log( `${tag.ref} ${changes.documents.length} prequalified/themes found` ); diff --git a/targets/alert-cli/src/diff/type.ts b/targets/alert-cli/src/diff/type.ts deleted file mode 100644 index bcdf3efca..000000000 --- a/targets/alert-cli/src/diff/type.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { - DilaAlertChanges, - TravailDataAlertChanges, - VddAlertChanges, -} from "@shared/types"; -import { GitTagData } from "../types"; - -export interface Diff { - from: GitTagData; - to: GitTagData; - files: DiffFile[]; -} - -export type PatchStatus = "added" | "modified" | "removed"; - -export interface DiffFile { - filename: string; - status: PatchStatus; -} - -export type LoadFileFn = (file: DiffFile, tag: GitTagData) => Promise; - -export interface DataDiffParams { - repositoryId: string; - tag: GitTagData; - patches: Diff; - fileFilter: (path: string) => boolean; - loadFile: LoadFileFn; -} - -export type DataDiffFunction = ( - params: DataDiffParams -) => Promise< - DilaAlertChanges[] | TravailDataAlertChanges[] | VddAlertChanges[] ->; diff --git a/targets/alert-cli/src/index.ts b/targets/alert-cli/src/index.ts index b117e950c..62206f0c5 100644 --- a/targets/alert-cli/src/index.ts +++ b/targets/alert-cli/src/index.ts @@ -1,5 +1,5 @@ import { gqlClient } from "@shared/utils"; -import { GithubApi } from "./APIs/api"; +import { GithubApi } from "./utils/github"; import { SourcesRepository } from "./repositories/SourcesRepository"; import { AlertRepository } from "./repositories/AlertRepository"; import { AlertDetector } from "./diff"; diff --git a/targets/alert-cli/src/repositories/AlertRepository.ts b/targets/alert-cli/src/repositories/AlertRepository.ts index 1dfdc772b..ee2ca5709 100644 --- a/targets/alert-cli/src/repositories/AlertRepository.ts +++ b/targets/alert-cli/src/repositories/AlertRepository.ts @@ -1,6 +1,6 @@ import { Client } from "@urql/core/dist/types/client"; import { AlertChanges, AlertInfo, HasuraAlert } from "@shared/types"; -import { batchPromises } from "../batchPromises"; +import { batchPromises } from "../utils/batch-promises"; import { DaresAlertInsert } from "../dares/types"; const insertAlertsMutation = ` diff --git a/targets/alert-cli/src/types.ts b/targets/alert-cli/src/types.ts index 922edc7be..1aa24f65c 100644 --- a/targets/alert-cli/src/types.ts +++ b/targets/alert-cli/src/types.ts @@ -1,4 +1,43 @@ -import type { AlertChanges } from "@shared/types"; +import type { + AlertChanges, + DilaAlertChanges, + TravailDataAlertChanges, + VddAlertChanges, +} from "@shared/types"; + +export interface PublicAgreement { + id: string; + kali_id: string; +} + +export interface Diff { + from: GitTagData; + to: GitTagData; + files: DiffFile[]; +} + +export type PatchStatus = "added" | "modified" | "removed"; + +export interface DiffFile { + filename: string; + status: PatchStatus; +} + +export type LoadFileFn = (file: DiffFile, tag: GitTagData) => Promise; + +export interface DataDiffParams { + repositoryId: string; + tag: GitTagData; + patches: Diff; + fileFilter: (path: string) => boolean; + loadFile: LoadFileFn; +} + +export type DataDiffFunction = ( + params: DataDiffParams +) => Promise< + DilaAlertChanges[] | TravailDataAlertChanges[] | VddAlertChanges[] +>; export interface Source { repository: string; diff --git a/targets/alert-cli/src/APIs/__tests__/api.raw.test.ts b/targets/alert-cli/src/utils/__tests__/api.raw.test.ts similarity index 94% rename from targets/alert-cli/src/APIs/__tests__/api.raw.test.ts rename to targets/alert-cli/src/utils/__tests__/api.raw.test.ts index d1d8fb074..8511ec5b4 100644 --- a/targets/alert-cli/src/APIs/__tests__/api.raw.test.ts +++ b/targets/alert-cli/src/utils/__tests__/api.raw.test.ts @@ -1,4 +1,4 @@ -import { GithubApi } from "../api"; +import { GithubApi } from "../github"; const apiResponse = "raw file content"; diff --git a/targets/alert-cli/src/APIs/__tests__/api.tags.test.ts b/targets/alert-cli/src/utils/__tests__/api.tags.test.ts similarity index 99% rename from targets/alert-cli/src/APIs/__tests__/api.tags.test.ts rename to targets/alert-cli/src/utils/__tests__/api.tags.test.ts index 920ad5602..55b7104ae 100644 --- a/targets/alert-cli/src/APIs/__tests__/api.tags.test.ts +++ b/targets/alert-cli/src/utils/__tests__/api.tags.test.ts @@ -1,4 +1,4 @@ -import { GithubApi } from "../api"; +import { GithubApi } from "../github"; const apiResponse = [ { diff --git a/targets/alert-cli/src/diff/__tests__/get-diff.test.ts b/targets/alert-cli/src/utils/__tests__/get-diff.test.ts similarity index 100% rename from targets/alert-cli/src/diff/__tests__/get-diff.test.ts rename to targets/alert-cli/src/utils/__tests__/get-diff.test.ts diff --git a/targets/alert-cli/src/batchPromises.ts b/targets/alert-cli/src/utils/batch-promises.ts similarity index 100% rename from targets/alert-cli/src/batchPromises.ts rename to targets/alert-cli/src/utils/batch-promises.ts diff --git a/targets/alert-cli/src/diff/get-diff.ts b/targets/alert-cli/src/utils/get-diff.ts similarity index 97% rename from targets/alert-cli/src/diff/get-diff.ts rename to targets/alert-cli/src/utils/get-diff.ts index e0a22cc2a..62816fcbd 100644 --- a/targets/alert-cli/src/diff/get-diff.ts +++ b/targets/alert-cli/src/utils/get-diff.ts @@ -1,4 +1,4 @@ -import { GithubDiffFile } from "../APIs/api"; +import { GithubDiffFile } from "./github"; import { simpleGit } from "simple-git"; import { parsePatch } from "diff"; import fs from "fs"; diff --git a/targets/alert-cli/src/APIs/api.ts b/targets/alert-cli/src/utils/github.ts similarity index 98% rename from targets/alert-cli/src/APIs/api.ts rename to targets/alert-cli/src/utils/github.ts index 2f6119d4c..05c8de612 100644 --- a/targets/alert-cli/src/APIs/api.ts +++ b/targets/alert-cli/src/utils/github.ts @@ -1,6 +1,6 @@ import { Commit, GitTagData } from "../types"; -import { Diff } from "../diff/type"; -import { getDiff } from "../diff/get-diff"; +import { Diff } from "../types"; +import { getDiff } from "./get-diff"; export type Tags = GitTagData[]; diff --git a/targets/alert-cli/src/node-git.helpers.ts b/targets/alert-cli/src/utils/node-git.helpers.ts similarity index 76% rename from targets/alert-cli/src/node-git.helpers.ts rename to targets/alert-cli/src/utils/node-git.helpers.ts index c80ce9dad..b40e24d0c 100644 --- a/targets/alert-cli/src/node-git.helpers.ts +++ b/targets/alert-cli/src/utils/node-git.helpers.ts @@ -1,5 +1,5 @@ -import { DiffFile, LoadFileFn } from "./diff/type"; -import { GitTagData } from "./types"; +import { DiffFile, LoadFileFn } from "../types"; +import { GitTagData } from "../types"; export function getFilename(patch: DiffFile): string { return patch.filename; diff --git a/targets/alert-cli/tsconfig.json b/targets/alert-cli/tsconfig.json index f91997117..898102d09 100644 --- a/targets/alert-cli/tsconfig.json +++ b/targets/alert-cli/tsconfig.json @@ -5,12 +5,7 @@ "module": "es2015", "moduleResolution": "node", "allowJs": true, - "lib": [ - "DOM" - ] + "lib": ["DOM"] }, - "include": [ - "src", - "@types" - ], + "include": ["src", "@types"] } diff --git a/targets/frontend/src/components/changes/ChangeGroup.tsx b/targets/frontend/src/components/changes/ChangeGroup.tsx index d22956b24..f77091883 100644 --- a/targets/frontend/src/components/changes/ChangeGroup.tsx +++ b/targets/frontend/src/components/changes/ChangeGroup.tsx @@ -524,6 +524,8 @@ function FicheLink({ change, documents = [] }: FicheLinkProps) { color: theme.colors.muted, fontSize: theme.fontSizes.xsmall, lineHeight: 1, + marginTop: "15px", + marginBottom: "15px", }} > Contenus liés : {jsxJoin(linkedDocuments, ", ")} @@ -549,6 +551,8 @@ function FicheLink({ change, documents = [] }: FicheLinkProps) { color: theme.colors.muted, fontSize: theme.fontSizes.xsmall, lineHeight: 1, + marginTop: "15px", + marginBottom: "15px", }} > Contenus liés : {jsxJoin(linkedDocuments, ", ")} diff --git a/targets/frontend/src/components/changes/ChangesFiche.tsx b/targets/frontend/src/components/changes/ChangesFiche.tsx new file mode 100644 index 000000000..750757e8a --- /dev/null +++ b/targets/frontend/src/components/changes/ChangesFiche.tsx @@ -0,0 +1,84 @@ +import { Chip } from "@mui/material"; +import { DocumentInfoWithCdtnRef } from "@shared/types"; +import slugify from "@socialgouv/cdtn-slugify"; +import { getRouteBySource } from "@socialgouv/cdtn-sources"; +import { theme } from "src/theme"; +import { styled } from "@mui/system"; + +type Props = { + documents: DocumentInfoWithCdtnRef[]; + type: "vdd" | "travail-data"; +}; + +export function ChangesFiche({ documents, type }: Props): JSX.Element { + return ( +
+ {documents.map((doc) => ( + + + + + {doc.title} + + + + {doc.ref.id} - {doc.ref.title} + + + + ))} +
+ ); +} + +const palettes = { + contributions: "#5bc0eb", + prequalified: "#fde74c", + themes: "#9bc53d", +} as const; + +const DocumentContainer = styled("div")({ + marginBottom: "1rem", + display: "flex", + flexDirection: "row", + alignItems: "center", +}); + +const DocumentChip: any = styled(Chip)(({ source }: any) => ({ + backgroundColor: palettes[source as keyof typeof palettes], + width: "125px", +})); + +const LinkContainer = styled("div")({ + display: "flex", + flexDirection: "column", + marginLeft: "20px", +}); + +const DocumentLink = styled("a")({ + marginBottom: "10px", + width: "fit-content", +}); + +const ReferenceLink = styled("a")({ + color: theme.colors.muted, + fontSize: "0.8rem", + width: "fit-content", +}); diff --git a/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts b/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts index 4ab7713c3..54199c3cb 100644 --- a/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts +++ b/targets/frontend/src/modules/contribution/__tests__/mapContributionToDocument.test.ts @@ -111,24 +111,16 @@ describe("mapContributionToDocument", () => { ], cdtn_references: [ { - document: { - cdtn_id: "abcdef", - }, + cdtn_id: "abcdef", }, { - document: { - cdtn_id: "ijhgt", - }, + cdtn_id: "ijhgt", }, { - document: { - cdtn_id: "klmnop", - }, + cdtn_id: "klmnop", }, { - document: { - cdtn_id: "ijhgt", - }, + cdtn_id: "ijhgt", }, ], content_fiche_sp: null, diff --git a/targets/frontend/src/modules/contribution/api/query.ts b/targets/frontend/src/modules/contribution/api/query.ts index 354445cd0..39cad9a4e 100644 --- a/targets/frontend/src/modules/contribution/api/query.ts +++ b/targets/frontend/src/modules/contribution/api/query.ts @@ -38,9 +38,7 @@ export const getContributionAnswerById = gql` url } cdtn_references { - document { - cdtn_id - } + cdtn_id } content_fiche_sp: document { initial_id diff --git a/targets/frontend/src/modules/contribution/mapContributionToDocument.ts b/targets/frontend/src/modules/contribution/mapContributionToDocument.ts index 379f71206..45e986366 100644 --- a/targets/frontend/src/modules/contribution/mapContributionToDocument.ts +++ b/targets/frontend/src/modules/contribution/mapContributionToDocument.ts @@ -73,7 +73,7 @@ export const mapContributionToDocument = async ( ...baseDoc, contentType: data.content_type, linkedContent: data.cdtn_references.map((v) => ({ - cdtnId: v.document.cdtn_id, + cdtnId: v.cdtn_id!, })), references: getReferences(data), questionIndex: data.question.order, diff --git a/targets/frontend/src/pages/alerts/[[...params]].tsx b/targets/frontend/src/pages/alerts/[[...params]].tsx index f20e1c00b..e002b3646 100644 --- a/targets/frontend/src/pages/alerts/[[...params]].tsx +++ b/targets/frontend/src/pages/alerts/[[...params]].tsx @@ -24,6 +24,7 @@ import { Card, CardContent } from "@mui/material"; import { FixedSnackBar } from "../../components/utils/SnackBar"; import { theme } from "src/theme"; import { AlertWarning } from "../../components/alerts/warning/AlertWarning"; +import { ChangesFiche } from "src/components/changes/ChangesFiche"; const getAlertQuery = ` query getAlerts($status: String!, $repository: String!, $limit: Int!, $offset: Int!) { @@ -171,6 +172,20 @@ export function AlertPage(): JSX.Element { ); } + if ( + alert.changes.documents.length > 0 && + (alert.changes.type === "vdd" || + alert.changes.type === "travail-data") + ) { + accordionItems.push( + + + + ); + } if (alert.changes.added.length > 0) { accordionItems.push(