Skip to content

Commit 5534aa3

Browse files
authored
fix(alerting): urls correctes des fiches SP dans les alerts (#1420)
1 parent 1609584 commit 5534aa3

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ services:
9797
volumes:
9898
- elastic_data:/usr/share/elasticsearch/data
9999
environment:
100+
- ES_JAVA_OPTS=-Xmx4g
100101
- cluster.name=code-du-travail-data-elasticsearch
101102
- node.name=code-du-travail-data-elasticsearch-single-node
102103
- network.host=0.0.0.0

shared/types/src/utility.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ export type KeysToCamelCase<T> = {
77
? KeysToCamelCase<T[K]>
88
: T[K];
99
};
10+
11+
export type Audience = "associations" | "particuliers" | "professionnels"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { generateFichesSpRef } from "../url-generator";
2+
3+
describe("url-generator", () => {
4+
test("generateFichesSpRef with audience camel case", () => {
5+
expect(generateFichesSpRef("associations", "article")).toEqual("https://www.service-public.fr/associations/vosdroits/article");
6+
});
7+
});

shared/utils/src/url-generator.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { slugify } from "@socialgouv/cdtn-utils";
2+
import type { Audience } from "@socialgouv/cdtn-types";
23

34
export const generateKaliRef = (
45
kaliArticleId: string,
@@ -17,24 +18,15 @@ export const generateLegiRef = (
1718
};
1819

1920
export const generateFichesSpRef = (
20-
audience: "Associations" | "Particuliers" | "Professionnels",
21+
audience: Audience,
2122
ficheSpInitialId: string
22-
) => {
23+
): string => {
2324
switch (audience) {
24-
case "Associations":
25+
case "associations":
2526
return `https://www.service-public.fr/associations/vosdroits/${ficheSpInitialId}`;
26-
case "Particuliers":
27+
case "particuliers":
2728
return `https://www.service-public.fr/particuliers/vosdroits/${ficheSpInitialId}`;
28-
case "Professionnels":
29+
case "professionnels":
2930
return `https://entreprendre.service-public.fr/vosdroits/${ficheSpInitialId}`;
3031
}
3132
};
32-
33-
export const generateFichesSpRefLocal = (
34-
urlSlug: string,
35-
withPrefix = true
36-
) => {
37-
return `${
38-
withPrefix ? "https://code.travail.gouv.fr" : ""
39-
}/fiche-service-public/${urlSlug}`;
40-
};

targets/frontend/src/components/changes/ChangeGroup.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {
2-
AlertChanges,
2+
AlertChanges, Audience,
33
DilaAddedNode,
44
DilaAlertChanges,
55
DilaModifiedNode,
@@ -22,6 +22,7 @@ import { jsxJoin } from "../../lib/jsx";
2222
import { Stack } from "../layout/Stack";
2323
import { ViewDiff } from "./ViewDiff";
2424
import { theme } from "src/theme";
25+
import { generateFichesSpRef } from "@shared/utils";
2526

2627
type Props = {
2728
label: string;
@@ -536,14 +537,17 @@ function FicheLink({ change, documents = [] }: FicheLinkProps) {
536537
</>
537538
);
538539
}
539-
const url = `https://www.service-public.fr/${change.type}/vosdroits/${change.id}`;
540+
540541
return (
541542
<>
542543
<a
543544
target="_blank"
544545
aria-label={`${change.title} (nouvelle fenêtre)`}
545546
rel="noreferrer noopener"
546-
href={url}
547+
href={generateFichesSpRef(
548+
change.type.toLowerCase() as Audience,
549+
change.id
550+
)}
547551
>
548552
{change.title}
549553
</a>

targets/ingester/src/transform/fichesServicePublic/format.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { SOURCES } from "@socialgouv/cdtn-sources";
22
import type { RawJson } from "@socialgouv/fiches-vdd-types";
3-
import type { IndexedAgreement } from "@socialgouv/kali-data-types";
43

54
import type { FicheServicePublic } from "../..";
65
import type { ReferenceResolver } from "../../lib/referenceResolver";
76
import { parseReferences } from "./parseReference";
87
import { generateFichesSpRef } from "@shared/utils";
98
import { ShortAgreement } from "./fetchAgreementsWithKaliId";
9+
import { Audience } from "@socialgouv/cdtn-types";
1010

1111
function getChild(element: RawJson, name: string) {
1212
// RawJson children not exist on text node
@@ -53,10 +53,9 @@ export function format(
5353
const [year, month, day] = dateRaw.split(" ")[1].split("-");
5454
const date = `${day}/${month}/${year}`;
5555

56-
const audience = getText(getChild(publication, "Audience")) as
57-
| "Associations"
58-
| "Particuliers"
59-
| "Professionnels";
56+
const audience = getText(
57+
getChild(publication, "Audience")
58+
).toLowerCase() as Audience;
6059

6160
const url = generateFichesSpRef(audience, id);
6261

0 commit comments

Comments
 (0)