From f1fdaa1f75923cae09517bc65bb716345275d3d7 Mon Sep 17 00:00:00 2001
From: Caroline <4971715+carolineBda@users.noreply.github.com>
Date: Tue, 6 Feb 2024 17:30:47 +0100
Subject: [PATCH] feat(contributions): transformation des H3 et H4 des
contributions en titre et sous-titres (#1259)
---
scripts/connect_db.sh | 4 +-
.../src/ingester/cdtnDocuments.ts | 6 +-
.../questions/EditQuestionAnswerList.tsx | 9 +-
.../components/forms/EditionField/Editor.tsx | 15 ++-
.../forms/EditionField/MenuSpecial.tsx | 10 +-
.../forms/EditionField/MenuStyle.tsx | 37 +++----
.../forms/EditionField/MenuTable.tsx | 14 +--
.../forms/EditionField/extensions/Titles.ts | 96 +++++++++++++++++++
.../forms/EditionField/extensions/index.ts | 1 +
.../1705675302544_move_hn_contribs/down.sql | 0
.../1705675302544_move_hn_contribs/up.sql | 69 +++++++++++++
11 files changed, 213 insertions(+), 48 deletions(-)
create mode 100644 targets/frontend/src/components/forms/EditionField/extensions/Titles.ts
create mode 100644 targets/hasura/migrations/default/1705675302544_move_hn_contribs/down.sql
create mode 100644 targets/hasura/migrations/default/1705675302544_move_hn_contribs/up.sql
diff --git a/scripts/connect_db.sh b/scripts/connect_db.sh
index 78582ef15..bcaa689aa 100755
--- a/scripts/connect_db.sh
+++ b/scripts/connect_db.sh
@@ -104,11 +104,11 @@ fi
pg_pods=$(kubectl -n $namespace get po --selector=cnpg.io/podRole=instance -o=custom-columns="NAME:.metadata.name,ROLE:.metadata.labels.role")
pg_pods_filtered=$(kubectl -n $namespace get po --selector=cnpg.io/podRole=instance -o=custom-columns="NAME:.metadata.name,ROLE:.metadata.labels.role" | grep "$pg_type")
-pod=$(echo "$pg_pods_filtered" | awk '{print $1}')
+pod=$(echo "$pg_pods_filtered" | awk 'NR==1{print $1}')
if [ -z "$pod" ]; then
echo -e "${RED}Erreur, impossible de trouver le pod cnpg $pg_type dans le namespace ${YELLOW}$namespace${RED}.${NC}"
- echo -e "${RED}Voci les pods trouvés:\n$pg_pods\n$pg_pods_filtered${NC}"
+ echo -e "${RED}Voici les pods trouvés:\n$pg_pods\n$pg_pods_filtered${NC}"
exit 1
fi
diff --git a/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts b/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts
index 97cf376d0..50b0857d8 100644
--- a/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts
+++ b/targets/export-elasticsearch/src/ingester/cdtnDocuments.ts
@@ -272,9 +272,13 @@ export async function* cdtnDocumentsGen() {
...newGeneratedContributions,
...oldGeneratedContributions,
];
+
if (generatedContributions.length < 1998) {
- throw Error("Le nombre de contributions est inférieur à celui attendu");
+ throw Error(
+ `Le nombre de contributions (${generatedContributions.length}) est inférieur à celui attendu (1998)`
+ );
}
+
yield {
documents: generatedContributions,
source: SOURCES.CONTRIBUTIONS,
diff --git a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx
index 96dc49600..7761df139 100644
--- a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx
+++ b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx
@@ -32,14 +32,7 @@ type AnswerCheck = {
const contentTypes = {
ANSWER: {
description: "Afficher la réponse",
- icon: (
-
- ),
+ icon: ,
},
NOTHING: {
description: "La convention collective ne prévoit rien",
diff --git a/targets/frontend/src/components/forms/EditionField/Editor.tsx b/targets/frontend/src/components/forms/EditionField/Editor.tsx
index 116f4ae73..d41e6fba2 100644
--- a/targets/frontend/src/components/forms/EditionField/Editor.tsx
+++ b/targets/frontend/src/components/forms/EditionField/Editor.tsx
@@ -17,7 +17,7 @@ import { DetailsSummary } from "@tiptap-pro/extension-details-summary";
import { DetailsContent } from "@tiptap-pro/extension-details-content";
import { Placeholder } from "@tiptap/extension-placeholder";
import { Link } from "@tiptap/extension-link";
-import { Alert } from "./extensions";
+import { Alert, Title } from "./extensions";
export type EditorProps = {
label: string;
@@ -73,6 +73,7 @@ export const Editor = ({
},
}),
Alert,
+ Title,
],
onUpdate: ({ editor }) => {
const html = editor.getHTML();
@@ -140,6 +141,18 @@ const StyledEditorContent = styled(EditorContent)(() => {
"a::after": {
display: "none",
},
+ "span.title": {
+ fontSize: "1.75rem",
+ fontWeight: 700,
+ display: "block",
+ padding: "O.5rem 0",
+ },
+ "span.sub-title": {
+ fontSize: "1.5rem",
+ fontWeight: 700,
+ display: "block",
+ padding: "O.5rem 0",
+ },
".alert": {
marginBottom: "1.6rem",
padding: "1.6rem 2rem",
diff --git a/targets/frontend/src/components/forms/EditionField/MenuSpecial.tsx b/targets/frontend/src/components/forms/EditionField/MenuSpecial.tsx
index b304bb64f..4400330e6 100644
--- a/targets/frontend/src/components/forms/EditionField/MenuSpecial.tsx
+++ b/targets/frontend/src/components/forms/EditionField/MenuSpecial.tsx
@@ -30,7 +30,7 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().toggleBulletList().run()}
className={editor.isActive("bulletList") ? "is-active" : ""}
type="button"
- title="Ajouter liste"
+ title="Liste"
>
@@ -38,7 +38,7 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().toggleOrderedList().run()}
className={editor.isActive("orderedList") ? "is-active" : ""}
type="button"
- title="Ajouter liste numérotée"
+ title="Liste numérotée"
>
@@ -56,7 +56,7 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
}
className={editor.isActive("orderedList") ? "is-active" : ""}
type="button"
- title="Ajouter tableau"
+ title="Tableau"
>
@@ -64,7 +64,7 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().setDetails().run()}
className={editor.isActive("details") ? "is-active" : ""}
type="button"
- title="Ajouter un accordéon"
+ title="Accordéon"
>
@@ -74,7 +74,7 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
}}
className={editor.isActive("alert") ? "is-active" : ""}
type="button"
- title="Ajouter une section d'alerte"
+ title="Section d'alerte"
>
diff --git a/targets/frontend/src/components/forms/EditionField/MenuStyle.tsx b/targets/frontend/src/components/forms/EditionField/MenuStyle.tsx
index bd7ef7800..fae944453 100644
--- a/targets/frontend/src/components/forms/EditionField/MenuStyle.tsx
+++ b/targets/frontend/src/components/forms/EditionField/MenuStyle.tsx
@@ -41,33 +41,22 @@ export const MenuStyle = ({ editor }: { editor: Editor | null }) => {
editor={editor}
>
-
@@ -101,7 +90,7 @@ export const MenuStyle = ({ editor }: { editor: Editor | null }) => {
}}
className={editor.isActive("link") ? "is-active" : ""}
type="button"
- title="Faire un lien"
+ title="Lien"
>
@@ -111,7 +100,7 @@ export const MenuStyle = ({ editor }: { editor: Editor | null }) => {
}}
className={editor.isActive("alert") ? "is-active" : ""}
type="button"
- title="Mettre en section d'alerte"
+ title="Section d'alerte"
disabled={editor.isActive("alert")}
>
diff --git a/targets/frontend/src/components/forms/EditionField/MenuTable.tsx b/targets/frontend/src/components/forms/EditionField/MenuTable.tsx
index 3cc9541d8..f51a1bd8f 100644
--- a/targets/frontend/src/components/forms/EditionField/MenuTable.tsx
+++ b/targets/frontend/src/components/forms/EditionField/MenuTable.tsx
@@ -25,7 +25,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().addColumnBefore().run()}
disabled={!editor.can().addColumnBefore()}
type="button"
- title="Ajouter colonne à gauche"
+ title="Ajouter une colonne à gauche"
>
@@ -33,7 +33,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().addColumnAfter().run()}
disabled={!editor.can().addColumnAfter()}
type="button"
- title="Ajouter colonne à droite"
+ title="Ajouter une colonne à droite"
>
@@ -41,7 +41,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().deleteColumn().run()}
disabled={!editor.can().deleteColumn()}
type="button"
- title="Supprimer colonne"
+ title="Supprimer la colonne"
>
@@ -49,7 +49,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().addRowBefore().run()}
disabled={!editor.can().addRowBefore()}
type="button"
- title="Ajouter ligne au dessus"
+ title="Ajouter une ligne au dessus"
>
@@ -57,7 +57,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().addRowAfter().run()}
disabled={!editor.can().addRowAfter()}
type="button"
- title="Ajouter ligne en dessous"
+ title="Ajouter une ligne en dessous"
>
@@ -65,7 +65,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().deleteRow().run()}
disabled={!editor.can().deleteRow()}
type="button"
- title="Supprimer ligne"
+ title="Supprimer la ligne"
>
@@ -73,7 +73,7 @@ export const MenuTable = ({ editor }: { editor: Editor | null }) => {
onClick={() => editor.chain().focus().deleteTable().run()}
disabled={!editor.can().deleteTable()}
type="button"
- title="Supprimer tableau"
+ title="Supprimer le tableau"
>
diff --git a/targets/frontend/src/components/forms/EditionField/extensions/Titles.ts b/targets/frontend/src/components/forms/EditionField/extensions/Titles.ts
new file mode 100644
index 000000000..4e11dc70f
--- /dev/null
+++ b/targets/frontend/src/components/forms/EditionField/extensions/Titles.ts
@@ -0,0 +1,96 @@
+import { mergeAttributes, Node, textblockTypeInputRule } from "@tiptap/core";
+
+export type Level = "title" | "sub-title";
+
+export interface TitleOptions {
+ levels: Level[];
+ HTMLAttributes: Record;
+}
+
+declare module "@tiptap/core" {
+ interface Commands {
+ title: {
+ setTitle: (attributes: { level: Level }) => ReturnType;
+ toggleTitle: (attributes: { level: Level }) => ReturnType;
+ unsetTitle: () => ReturnType;
+ };
+ }
+}
+
+export const Title = Node.create({
+ name: "title",
+
+ addOptions() {
+ return {
+ levels: ["title", "sub-title"],
+ HTMLAttributes: {},
+ };
+ },
+
+ content: "inline*",
+
+ group: "block",
+
+ defining: true,
+
+ addAttributes() {
+ return {
+ level: {
+ default: "title",
+ rendered: false,
+ },
+ };
+ },
+
+ parseHTML() {
+ return this.options.levels.map((level: Level) => ({
+ tag: `span`,
+ attrs: { level },
+ }));
+ },
+
+ renderHTML({ node, HTMLAttributes }) {
+ const hasLevel = this.options.levels.includes(node.attrs.level);
+ const level = hasLevel ? node.attrs.level : this.options.levels[0];
+
+ return ["span", mergeAttributes({ class: `${level}` }, HTMLAttributes), 0];
+ },
+
+ addCommands() {
+ return {
+ setTitle:
+ (attributes) =>
+ ({ commands }) => {
+ if (!this.options.levels.includes(attributes.level)) {
+ return false;
+ }
+
+ return commands.setNode(this.name, attributes);
+ },
+ toggleTitle:
+ (attributes) =>
+ ({ commands }) => {
+ if (!this.options.levels.includes(attributes.level)) {
+ return false;
+ }
+
+ return commands.toggleNode(this.name, "paragraph", attributes);
+ },
+ unsetTitle: () => ({ commands }) => {
+ return commands.lift(this.name)
+ },
+ };
+ },
+
+ addInputRules() {
+ return this.options.levels.map((level) => {
+ return textblockTypeInputRule({
+ find: new RegExp(`^(#{${level}})\\s$`),
+ type: this.type,
+ getAttributes: {
+ level,
+ },
+ });
+ });
+ },
+});
diff --git a/targets/frontend/src/components/forms/EditionField/extensions/index.ts b/targets/frontend/src/components/forms/EditionField/extensions/index.ts
index b8e17a03c..7f9a73ca3 100644
--- a/targets/frontend/src/components/forms/EditionField/extensions/index.ts
+++ b/targets/frontend/src/components/forms/EditionField/extensions/index.ts
@@ -1 +1,2 @@
export * from "./Alert";
+export * from "./Titles";
diff --git a/targets/hasura/migrations/default/1705675302544_move_hn_contribs/down.sql b/targets/hasura/migrations/default/1705675302544_move_hn_contribs/down.sql
new file mode 100644
index 000000000..e69de29bb
diff --git a/targets/hasura/migrations/default/1705675302544_move_hn_contribs/up.sql b/targets/hasura/migrations/default/1705675302544_move_hn_contribs/up.sql
new file mode 100644
index 000000000..d2ee5c344
--- /dev/null
+++ b/targets/hasura/migrations/default/1705675302544_move_hn_contribs/up.sql
@@ -0,0 +1,69 @@
+-- remplace tous les H4 par H3 si pas de H3 présent
+UPDATE contribution.answers
+SET content = REPLACE(
+ REPLACE(content, '', ''),
+ '
',
+ ''
+)
+WHERE "content" LIKE '%>'content', '', ''),
+ '
',
+ ''
+ )
+ )
+)
+WHERE source = 'contributions'
+AND "document"->>'idcc' IS NOT NULL
+AND "document"->>'content' IS NOT NULL
+AND "document"->>'content' LIKE '%>'content' NOT LIKE '%', ''),
+ '
',
+ ''
+ ),
+ '',
+ ''
+ ),
+ '
',
+ ''
+);
+
+-- idem dans la table documents pour les docs déjà publiés
+UPDATE public.documents
+SET document = jsonb_set(
+ document,
+ '{content}',
+ to_jsonb(
+ REPLACE(
+ REPLACE(
+ REPLACE(
+ REPLACE("document"->>'content', '', ''),
+ '
',
+ ''
+ ),
+ '',
+ ''
+ ),
+ '
',
+ ''
+ )
+ )
+)
+WHERE source = 'contributions'
+AND "document"->>'idcc' IS NOT NULL
+AND "document"->>'content' IS NOT NULL;