Skip to content

Commit

Permalink
feat(contribs): publish contributions in the new format (#1025)
Browse files Browse the repository at this point in the history
* feat(contribs): publish contributions in the new format

* move more types

* put back dependency

* fix types

* fix all types

* move agreements ingest

* remove un-used dependencies

* format data after review with Martial

* Get content from fiche SP

* handle fiche ids in fiche sp publish

* clean-up

* clean-up après reviews des devs

* fix(comments ui): meilleur affiche des commentaires & changement de statuts dans les contribs (#1070)

* feat(contrib): désactivation du formulaire quand on soumet (#1083)

* feat(admin): ajout de la suppression d'un commentaire (#1081)

* fix: v1

* fix: delete com

* fix: restore

* show error

* fix: modif

---------

Co-authored-by: carolineBda <[email protected]>

* fix(alert-cli): mise à jour des identifiants PISTE (#1084)

* fix(frontend): ajout du titre dans le header (#1085)

* fix(alert-cli): add references from contributions (#1076)

* fix: merge

* fix: merge

* fix: build

* fix: build

* fix: build

* fix: url

* fix: types

* fix: expected by snapshot

* fix: test

* fix: test

* fix: test

---------

Co-authored-by: carolineBda <[email protected]>

---------

Co-authored-by: maxgfr <[email protected]>
  • Loading branch information
carolineBda and maxgfr authored Oct 24, 2023
1 parent e443d86 commit bfa0ac4
Show file tree
Hide file tree
Showing 52 changed files with 1,404 additions and 172,421 deletions.
10 changes: 5 additions & 5 deletions shared/elasticsearch-document-adapter/src/cdtnDocuments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
AgreementDoc,
ContributionCompleteDoc,
GenericContributionDoc,
CustomizedContributionDoc,
EditorialContentDoc,
FicheTravailEmploiDoc,
} from "@shared/types";
Expand Down Expand Up @@ -167,10 +168,9 @@ export async function* cdtnDocumentsGen() {
};

logger.info("=== Contributions ===");
const contributions = await getDocumentBySource<ContributionCompleteDoc>(
SOURCES.CONTRIBUTIONS,
getBreadcrumbs
);
const contributions = await getDocumentBySource<
GenericContributionDoc | CustomizedContributionDoc
>(SOURCES.CONTRIBUTIONS, getBreadcrumbs);

const ccnData = await getDocumentBySource<AgreementDoc>(SOURCES.CCN);

Expand Down
1 change: 1 addition & 0 deletions shared/graphql-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const client = createClient({
"x-hasura-admin-secret": HASURA_GRAPHQL_ADMIN_SECRET,
},
},
maskTypename: true,
requestPolicy: "network-only",
url: HASURA_GRAPHQL_ENDPOINT,
});
12 changes: 0 additions & 12 deletions shared/id-generator/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions shared/id-generator/src/index.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions shared/id-generator/tsconfig.json

This file was deleted.

97 changes: 42 additions & 55 deletions shared/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import type {
IndexedAgreement,
} from "@socialgouv/kali-data-types";
import type {
Prequalified,
Highlight,
EditorialContent,
Highlight,
Prequalified,
} from "./EditorialContent";
import type { BaseHasuraDocument } from "./Base";

export * from "./EditorialContent";
export * from "./utils";
import type { BaseHasuraDocument } from "./Base";

export enum DOCUMENT_SOURCE {
fiches_ministere_travail = "fiches_ministere_travail",
Expand All @@ -37,12 +38,12 @@ export type FicheTravailEmploi = BaseHasuraDocument & {

export type ContributionComplete = BaseHasuraDocument & {
source: "contributions";
document: ContributionCompleteDoc;
document: GenericContributionDoc;
};

export type ContributionFiltered = BaseHasuraDocument & {
source: "contributions";
document: ContributionFilteredDoc;
document: CustomizedContributionDoc;
};

export type LaborCodeArticle = BaseHasuraDocument & {
Expand Down Expand Up @@ -133,28 +134,17 @@ export interface TravailEmploiReference {
url: string;
}

export interface ContributionCompleteDoc {
index: number;
split: false;
export interface GenericContributionDoc {
description: string;
answers: CCMultipleAnswers;
answer: Answer;
agreementsWithAnswer: string[];
}

export interface ContributionFilteredDoc {
index: number;
split: true;
export interface CustomizedContributionDoc {
description: string;
answers: CCSingleAnswer;
}

export interface CCMultipleAnswers {
generic: GenericAnswer;
conventions: Answer[];
}

export interface CCSingleAnswer {
generic: GenericAnswer;
conventionAnswer: Answer;
answer: Answer;
idcc: string;
shortName: string;
}

export type LaborCodeDoc = Pick<CodeArticleData, "cid" | "dateDebut" | "id"> & {
Expand Down Expand Up @@ -203,7 +193,7 @@ export interface AgreementContribAnswer {
index: string;
answer: string;
question: string;
references: ContributionReference[];
references: LegalRef[];
}

export interface ArticleTheme {
Expand Down Expand Up @@ -330,10 +320,22 @@ export type DocumentReferences = {
references: DocumentReference[];
};

export type DocumentReference = Pick<
DilaRef,
"dila_cid" | "dila_container_id" | "dila_id" | "title" | "url"
>;
export type DocumentReference = KaliRef | LegiRef | DilaRef;

export type KaliRef = {
dila_cid: string;
dila_container_id: string;
dila_id: string;
title: string;
url: string;
};

export type LegiRef = {
dila_cid: string;
dila_id: string;
title: string;
url: string;
};

export type DocumentInfo = Pick<HasuraDocument, "source" | "title"> & {
id: string;
Expand Down Expand Up @@ -458,46 +460,31 @@ export interface ExportEsStatus {
user?: User;
}

export type Question = {
id: string;
index: number;
title: string;
answers: {
generic: GenericAnswer;
conventions: Answer[];
};
};

export type Answer = {
id: string;
idcc: string;
markdown: string;
references: ContributionReference[];
};

export type GenericAnswer = {
id: string;
markdown: string;
description: string;
text: string;
references: ContributionReference[];
content?: string;
contentType: string;
references: LegalRef[];
linkedContent: CdtnRelatedContent[];
};

export type ContributionReference = BaseRef | DilaRef;

export type DilaRef = {
category: "agreement" | "labor_code";
url: string;
title: string;
dila_id: string;
dila_cid: string;
dila_container_id: string;
};

export type BaseRef = {
category: null;
export type LegalRef = {
title: string;
url: string | null;
url?: string;
};

export type CdtnRelatedContent = {
source: string;
title: string;
slug: string;
};

export type State =
Expand Down
1 change: 1 addition & 0 deletions shared/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
File renamed without changes.
21 changes: 21 additions & 0 deletions shared/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@shared/utils",
"version": "2.19.1",
"dependencies": {
"@socialgouv/cdtn-utils": "^4.109.0",
"uuid": "^8.3.2",
"xxhashjs": "^0.2.2"
},
"private": true,
"main": "build/src/index.js",
"module": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"@types/uuid": "^9.0.5",
"@types/xxhashjs": "^0.2.2",
"typescript": "^5.2.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,22 @@ const H = XXH.h64(0x1e7f);
export const MAX_ID_LENGTH = 10;

// use xxhash to hash source + newly generated UUID
/**
*
* @param {string} content
* @param {number} maxIdLength
* @returns {string}
*/
export const generateCdtnId = (content, maxIdLength = MAX_ID_LENGTH) =>
export const generateCdtnId = (content: string, maxIdLength = MAX_ID_LENGTH) =>
// save 64bits hash as Hexa string up to maxIdLength chars (can be changed later in case of collision)
// as the xxhash function ensure distribution property
H.update(content).digest().toString(16).slice(0, maxIdLength);

export const generateInitialId = uuidv4;
export const generateInitialId = (): string => {
return uuidv4();
};

// Beware, you might be generating an already existing cdtn_id
/**
* @param {string} source
* @param {number} maxIdLength
* @returns {idGenerator.generatedId}
*/
export const generateIds = (source, maxIdLength = MAX_ID_LENGTH) => {
export const generateIds = (
source: string,
maxIdLength = MAX_ID_LENGTH
): {
cdtn_id: string;
initial_id: string;
} => {
const uuid = uuidv4();
return {
cdtn_id: generateCdtnId(source + uuid, maxIdLength),
Expand Down
2 changes: 2 additions & 0 deletions shared/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./id-generator";
export * from "./url-generator";
30 changes: 30 additions & 0 deletions shared/utils/src/url-generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { slugify } from "@socialgouv/cdtn-utils";

export const generateKaliRef = (kaliArticleId: string, agreementId: string) => {
return `https://legifrance.gouv.fr/conv_coll/id/${kaliArticleId}/?idConteneur=${agreementId}`;
};

export const generateLegiRef = (
legiArticleTitle: string,
withPrefix = true
) => {
return `${
withPrefix ? "https://code.travail.gouv.fr" : ""
}/code-du-travail/${slugify(legiArticleTitle)}`;
};

export const generateFichesSpRef = (
audience: "associations" | "particuliers" | "professionnels-entreprises",
ficheSpInitialId: string
) => {
return `https://www.service-public.fr/${audience}/vosdroits/${ficheSpInitialId}`;
};

export const generateFichesSpRefLocal = (
urlSlug: string,
withPrefix = true
) => {
return `${
withPrefix ? "https://code.travail.gouv.fr" : ""
}/fiche-service-public/${urlSlug}`;
};
22 changes: 22 additions & 0 deletions shared/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"lib": ["es2022"],
"module": "NodeNext",
"target": "es2022",
"moduleResolution": "NodeNext",
"declaration": true,
"outDir": "build",
"moduleDetection": "force",
"allowJs": true,
"noUncheckedIndexedAccess": true,
"sourceMap": true,
"composite": true,
"declarationMap": true
}
}
1 change: 0 additions & 1 deletion targets/alert-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ FROM deps AS build-graphql-client
COPY shared/graphql-client ./shared/graphql-client
RUN yarn workspace @shared/graphql-client build


FROM deps AS build-dila-resolver
COPY shared/types ./shared/types
COPY shared/dila-resolver ./shared/dila-resolver
Expand Down
2 changes: 1 addition & 1 deletion targets/alert-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"private": true,
"dependencies": {
"@shared/graphql-client": "workspace:^",
"@shared/utils": "workspace:^",
"@socialgouv/cdtn-slugify": "4.52.1",
"@socialgouv/cdtn-sources": "4.52.1",
"@socialgouv/dila-api-client": "1.2.4",
Expand All @@ -27,7 +28,6 @@
"@shared/dila-resolver": "workspace:^",
"@shared/eslint-config": "workspace:^",
"@shared/types": "workspace:^",
"@socialgouv/contributions-data-types": "3.27.0",
"@socialgouv/fiches-travail-data-types": "4.191.0",
"@socialgouv/kali-data-types": "2.127.0",
"@socialgouv/legi-data-types": "2.73.1",
Expand Down
Loading

0 comments on commit bfa0ac4

Please sign in to comment.