Skip to content

Commit

Permalink
feat(page CC): affichage seulement des liens vers les contribs sur le…
Browse files Browse the repository at this point in the history
…s pages CC (#1404)
carolineBda authored Jun 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 305cb46 commit 10a11e9
Showing 9 changed files with 437 additions and 124 deletions.
17 changes: 11 additions & 6 deletions shared/types/src/elastic/agreements.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { AgreementDoc } from "../hasura";
import { DocumentElasticWithSource } from "./common";
import { ContributionElasticDocument } from "./contributions";

export type ElasticAgreement = DocumentElasticWithSource<AgreementDoc> & {
articlesByTheme: ArticleByTheme[];
source: "conventions_collectives";
description: string;
answers: ExportAnswer[];
answers: AnswerByTheme[];
contributions: boolean;
};

// Type pour les réponses
export type ExportAnswer = ContributionElasticDocument & {
theme?: string;
infoMessage: string;
export type AnswerByTheme = {
theme: string;
answers: ExportAnswer[];
};

export type ExportAnswer = {
theme: string;
slug: string;
question: string;
questionIndex: number;
};

// Types pour les Kali-Blocks
5 changes: 0 additions & 5 deletions shared/types/src/elastic/contributions.ts
Original file line number Diff line number Diff line change
@@ -125,8 +125,3 @@ export type ElasticSearchContributionConventionnelle =
export type ElasticSearchContribution =
| ElasticSearchContributionGeneric
| ElasticSearchContributionConventionnelle;

export type ElasticSearchContributionWithInfoMessage =
ElasticSearchContribution & {
infoMessage: string;
};
273 changes: 273 additions & 0 deletions targets/export-elasticsearch/src/ingester/__fixtures__/data.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { generateAgreements } from "../index";
import { CCN, contribs } from "../../__fixtures__/data";

jest.mock("@shared/utils");
jest.mock("../getAgreementsArticlesByTheme");

describe("generateAgreements", () => {
it("should map and group contributions", async () => {
// @ts-ignore
const pagesCCs = await generateAgreements(CCN, contribs);

expect(pagesCCs.length).toEqual(2);
expect(pagesCCs[0].slug).toEqual(
"1875-veterinaires-personnel-salarie-des-cabinets-et-cliniques-veterinaires"
);
expect(pagesCCs[0].answers.length).toEqual(0);

expect(pagesCCs[1].slug).toEqual(
"5571-convention-dentreprise-fondation-dauteuil"
);
expect(pagesCCs[1].answers).toEqual([
{
answers: [
{
questionIndex: 44,
slug: "1486-quelle-est-la-duree-du-conge-de-maternite",
theme: "Congés et repos",
question: "Quelle est la durée du congé de maternité ?",
},
],
theme: "Congés et repos",
},
{
answers: [
{
questionIndex: 47,
slug: "1351-en-cas-de-maladie-le-salarie-a-t-il-droit-a-une-garantie-demploi",
theme: "Santé, sécurité et conditions de travail",
question:
"En cas de maladie, le salarié a-t-il droit à une garantie d’emploi ?",
},
],
theme: "Santé, sécurité et conditions de travail",
},
]);
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { groupByTheme } from "../groupByTheme";
import { ExportAnswer } from "@socialgouv/cdtn-types";

describe("contributionsByTheme", () => {
it("should throw if a contrib has no theme", () => {
expect(() => {
groupByTheme([
{ slug: "hello", questionIndex: 1, question: "contrib" },
]);
}).toThrow("Contribution [1] - hello has no theme.");
});

it("returns the first breadcrumb label", () => {
const data: ExportAnswer[] = [
{ slug: "contrib-1", questionIndex: 1, theme: "A", question: "contrib" },
{ slug: "contrib-1", questionIndex: 1, theme: "C", question: "contrib" },
{ slug: "contrib-1", questionIndex: 1, theme: "B", question: "contrib" },
{ slug: "contrib-2", questionIndex: 2, theme: "A", question: "contrib" },
];

expect(groupByTheme(data)).toEqual([
{
"answers": [
{
"questionIndex": 1,
"slug": "contrib-1",
"theme": "A",
"question": "contrib"
},
{
"questionIndex": 2,
"slug": "contrib-2",
"theme": "A",
"question": "contrib"
}
],
"theme": "A"
},
{
"answers": [
{
"questionIndex": 1,
"slug": "contrib-1",
"theme": "B",
"question": "contrib"
}
],
"theme": "B"
},
{
"answers": [
{
"questionIndex": 1,
"slug": "contrib-1",
"theme": "C",
"question": "contrib"
}
],
"theme": "C"
}
]);
});
});
32 changes: 13 additions & 19 deletions targets/export-elasticsearch/src/ingester/agreements/generate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {
AgreementDoc,
ElasticAgreement,
ContributionElasticDocument,
ExportAnswer,
DocumentElasticWithSource,
ElasticAgreement,
} from "@socialgouv/cdtn-types";
import { SOURCES } from "@socialgouv/cdtn-sources";
import { getIDCCs } from "./getIdcc";
import getAgreementsArticlesByTheme from "./getAgreementsArticlesByTheme";
import { getTheme } from "./getTheme";
import { getInfoMessage } from "./getInfoMessage";
import pMap from "p-map";
import { groupByTheme } from "./groupByTheme";

const DESCRIPTION =
"Retrouvez les questions-réponses les plus fréquentes organisées par thème et élaborées par le ministère du Travail vous concernant.";
@@ -30,35 +29,30 @@ export const generateAgreements = async (
})
.filter((item) => item.contentType !== "UNKNOWN");

const answers: ExportAnswer[] = contributionByIdccNotUnknown
.map((data) => {
return {
...data,
theme: getTheme(data),
infoMessage: getInfoMessage(data),
};
})
.sort(
// On ordonne les questions par index
(a: ExportAnswer, b: ExportAnswer) =>
a.questionIndex - b.questionIndex
);
const answers = contributionByIdccNotUnknown.map((data) => {
return {
slug: data.slug,
question: data.questionName,
questionIndex: data.questionIndex,
theme: getTheme(data),
};
});

const articlesByTheme = await getAgreementsArticlesByTheme(cc.num);

const agreementGenerated: ElasticAgreement = {
...cc,
answers,
answers: groupByTheme(answers),
articlesByTheme,
contributions: contribIDCCs.has(cc.num),
description: DESCRIPTION, // On affiche la nouvelle description s'il n'y a plus d'anciennes réponses conventionnelles
description: DESCRIPTION,
source: SOURCES.CCN,
};

return agreementGenerated;
},
{
concurrency: 5,
concurrency: 10,
}
);
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { AnswerByTheme, ExportAnswer } from "@socialgouv/cdtn-types";

export function groupByTheme(
contributions: (Omit<ExportAnswer, "theme"> & { theme?: string })[]
): AnswerByTheme[] {
return contributions
.reduce((grouped: AnswerByTheme[], answer): AnswerByTheme[] => {
if (!answer.theme) {
throw new Error(
`Contribution [${answer.questionIndex}] - ${answer.slug} has no theme.`
);
}
const group = grouped.find((g) => g.theme === answer.theme);
if (group) {
group.answers.push(answer as ExportAnswer);
} else {
grouped.push({ theme: answer.theme, answers: [answer as ExportAnswer] });
}
return grouped;
}, [])
.map((group) => {
group.answers = group.answers.sort(
(a, b) => a.questionIndex - b.questionIndex
);
return group;
})
.sort((a, b) => {
return a.theme.localeCompare(b.theme);
});
}

0 comments on commit 10a11e9

Please sign in to comment.