-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
>; |
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; | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Theme, ThemeContentRelation } from "../types/themes"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
---|---|---|
|
@@ -18,7 +18,8 @@ const graphQLThemesQuery = ` | |
slug | ||
source | ||
title | ||
document | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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é There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[]; | ||
} | ||
|
@@ -6,7 +8,7 @@ export interface Theme { | |
cdtnId: string; | ||
id: string; | ||
slug: string; | ||
source: string; | ||
source: "themes"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[]; | ||
|
@@ -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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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!, | ||
|
@@ -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 => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 ?? "", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌