Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correction et ajout de certains types manquants #1464

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions shared/types/src/elastic/modeles-de-courrier.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DocumentElasticWithSource } from "./common";
import { MailTemplateDoc } from "../hasura";

export type MailElasticDocument = DocumentElasticWithSource<
MailTemplateDoc,
"modeles_de_courriers"
>;
18 changes: 18 additions & 0 deletions shared/types/src/elastic/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DocumentElasticWithSource } from "./common";

export type ThemeElasticDocument = DocumentElasticWithSource<
ThemeElastic,
"themes"
>;

export type ThemeElastic = {
children: ThemeChildren[];
description?: string;
icon?: string;
position: number;
};

export type ThemeChildren = {
label: string;
slug: string;
};
17 changes: 12 additions & 5 deletions shared/types/src/hasura/modeles-de-courrier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ export type MailTemplate = HasuraDocument<
>;

export type MailTemplateDoc = {
meta_title: string;
date: string;
type: MailTemplateType;
html: string;
author: string;
filename: string;
filesize: number;
intro: string;
description: string;
references?: {
url: string;
title: string;
type: string;
}[];
references?: MailTemplateReference[];
};

export type MailTemplateReference = {
url: string;
title: string;
type: "external";
};

export type MailTemplateType = "lettre" | "fichier" | "document";
55 changes: 0 additions & 55 deletions targets/export-elasticsearch/src/ingester/buildThemes.js

This file was deleted.

2 changes: 1 addition & 1 deletion targets/export-elasticsearch/src/ingester/cdtnDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { logger } from "@shared/utils";
import { SOURCES } from "@socialgouv/cdtn-sources";

import { buildGetBreadcrumbs } from "./breadcrumbs";
import { buildThemes } from "./buildThemes";
import { buildThemes } from "./themes/buildThemes";
import {
getDocumentBySource,
getDocumentBySourceWithRelation,
Expand Down
74 changes: 74 additions & 0 deletions targets/export-elasticsearch/src/ingester/themes/buildThemes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Theme, ThemeContentRelation } from "../types/themes";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai migré le fichier buildTheme en typescript.

import { GetBreadcrumbsFn } from "../breadcrumbs";
import { ThemeElasticDocument } from "@socialgouv/cdtn-types/build/elastic/theme";
import { DocumentRef } from "@socialgouv/cdtn-types";

export function buildThemes(
themes: Theme[],
getBreadcrumbs: GetBreadcrumbsFn
): ThemeElasticDocument[] {
return themes.map(
({
cdtnId,
id,
slug,
source,
title,
document: { icon, description },
contentRelations,
parentRelations,
}) => {
const breadcrumbs = getBreadcrumbs(cdtnId);
return {
breadcrumbs: breadcrumbs.slice(0, -1),
cdtnId,
text: title,
excludeFromSearch: false,
metaDescription: `Explorez les contenus autour du thème ${title}`,
children: themes
.filter(
({ parentRelations }) => parentRelations[0].parentThemeId === cdtnId
)
.sort(
(
{ parentRelations: [{ position: positionA }] },
{ parentRelations: [{ position: positionB }] }
) => positionA - positionB
)
.map(({ slug, title }) => ({
label: title,
slug,
})),
description,
icon,
id,
isPublished: true,
position: parentRelations[0].position,
refs: getContentRelation(contentRelations, getBreadcrumbs),
slug,
source,
title,
};
}
);
}

const getContentRelation = (
contentRelations: ThemeContentRelation[],
getBreadcrumbs: GetBreadcrumbsFn
): DocumentRef[] => {
return contentRelations
.sort(
({ position: positionA }, { position: positionB }) =>
positionA - positionB
)
.map(({ content: { cdtnId, description, url, slug, source, title } }) => ({
cdtnId,
description,
url,
slug,
source,
title,
breadcrumbs: getBreadcrumbs(cdtnId),
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const graphQLThemesQuery = `
slug
source
title
document
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai modifié la requête hasura pour fetch les thèmes car elle récupérait les documents complets alors que l'on utilise que la description et l'url. Ca fait un json beaucoup plus léger !

description: document(path: "description")
url: document(path: "url")
}
position: data(path: "position")
}
Expand Down
9 changes: 6 additions & 3 deletions targets/export-elasticsearch/src/ingester/types/themes.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dommage qu'on ait pas pu repondre les types dans le package partagé

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce sont des types lié à la BDD. Actuellement, ils ne sont pas dans le shared. Il faudrait les ajouter en effet pour avoir chaque layer de dispo

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SourceRoute } from "@socialgouv/cdtn-sources";

export interface Data {
themes: Theme[];
}
Expand All @@ -6,7 +8,7 @@ export interface Theme {
cdtnId: string;
id: string;
slug: string;
source: string;
source: "themes";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On est dans un thème, la source ne peut être que themes.

title: string;
document: ThemeDocument;
contentRelations: ThemeContentRelation[];
Expand All @@ -27,9 +29,10 @@ export interface ThemeContentRelation {
export interface ThemeContent {
cdtnId: string;
slug: string;
source: string;
source: SourceRoute;
title: string;
document: unknown;
description: string;
url?: string;
}

export interface ThemeParentRelation {
Expand Down
22 changes: 14 additions & 8 deletions targets/frontend/src/modules/models/mapModelToDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { format, parseISO } from "date-fns";
import { generateCdtnId } from "@shared/utils";
import slugify from "@socialgouv/cdtn-slugify";
import { Model } from "../models";
import { HasuraDocument } from "@socialgouv/cdtn-types";
import {
HasuraDocument,
MailTemplateDoc,
MailTemplateReference,
} from "@socialgouv/cdtn-types";

export const mapModelToDocument = (
data: Model,
document?: HasuraDocument<any>
): HasuraDocument<any> => {
document?: HasuraDocument<MailTemplateDoc>
): HasuraDocument<MailTemplateDoc> => {
return {
cdtn_id: document?.cdtn_id ?? generateCdtnId(data.title),
initial_id: data.id!,
Expand All @@ -25,11 +29,13 @@ export const mapModelToDocument = (
date: format(parseISO(data.displayDate), "dd/MM/yyyy"),
author: "Ministère du Travail",
references: data.legiReferences
.map((item) => ({
url: `https://www.legifrance.gouv.fr/codes/article_lc/${item.legiArticle.cid}`,
title: item.legiArticle.label,
type: "external",
}))
.map(
(item): MailTemplateReference => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici j'ai du ajouter le type de retour car Typescript n'arrivait pas à matcher le typeavec external 🤷

url: `https://www.legifrance.gouv.fr/codes/article_lc/${item.legiArticle.cid}`,
title: item.legiArticle.label,
type: "external",
})
)
.concat(
data.otherReferences.map((item) => ({
url: item.url ?? "",
Expand Down
Loading