Skip to content

Commit

Permalink
feat(contributions): transformation des H3 et H4 des contributions en…
Browse files Browse the repository at this point in the history
… titre et sous-titres (#1259)
  • Loading branch information
carolineBda authored Feb 6, 2024
1 parent 335bf4f commit f1fdaa1
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 48 deletions.
4 changes: 2 additions & 2 deletions scripts/connect_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion targets/export-elasticsearch/src/ingester/cdtnDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@ type AnswerCheck = {
const contentTypes = {
ANSWER: {
description: "Afficher la réponse",
icon: (
<DescriptionIcon
fontSize="small"
style={{
color: fr.colors.decisions.artwork.major.greenEmeraude.active,
}}
/>
),
icon: <DescriptionIcon fontSize="small" />,
},
NOTHING: {
description: "La convention collective ne prévoit rien",
Expand Down
15 changes: 14 additions & 1 deletion targets/frontend/src/components/forms/EditionField/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,6 +73,7 @@ export const Editor = ({
},
}),
Alert,
Title,
],
onUpdate: ({ editor }) => {
const html = editor.getHTML();
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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"
>
<FormatListBulletedIcon />
</button>
<button
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"
>
<FormatListNumberedIcon />
</button>
Expand All @@ -56,15 +56,15 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
}
className={editor.isActive("orderedList") ? "is-active" : ""}
type="button"
title="Ajouter tableau"
title="Tableau"
>
<GridOnIcon />
</button>
<button
onClick={() => editor.chain().focus().setDetails().run()}
className={editor.isActive("details") ? "is-active" : ""}
type="button"
title="Ajouter un accordéon"
title="Accordéon"
>
<StorageIcon />
</button>
Expand All @@ -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"
>
<InfoIcon />
</button>
Expand Down
37 changes: 13 additions & 24 deletions targets/frontend/src/components/forms/EditionField/MenuStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,22 @@ export const MenuStyle = ({ editor }: { editor: Editor | null }) => {
editor={editor}
>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
className={editor.isActive("heading", { level: 2 }) ? "is-active" : ""}
type="button"
title="Titre H2"
>
<BubbleMenuText>H2</BubbleMenuText>
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
className={editor.isActive("heading", { level: 3 }) ? "is-active" : ""}
disabled={editor.isActive("details")}
onClick={() => editor.chain().focus().toggleTitle({ level: "title" }).run()}

className={editor.isActive("title", { level: "title" }) ? "is-active" : ""}
type="button"
title="Titre H3"
title="Titre"
>
<BubbleMenuText>H3</BubbleMenuText>
<BubbleMenuText>T</BubbleMenuText>
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 4 }).run()}
className={editor.isActive("heading", { level: 4 }) ? "is-active" : ""}
disabled={
(!editor.getHTML().includes("<h3>") && !editor.isActive("details")) ||
editor.isActive("heading", { level: 3 })
}
onClick={() => editor.chain().focus().toggleTitle({ level: "sub-title" }).run()}
className={editor.isActive("title", { level: "sub-title" }) ? "is-active" : ""}
disabled={ !editor.getHTML().includes("\"title\"") }
type="button"
title="Titre H4"
title="Sous-titre"
>
<BubbleMenuText>H4</BubbleMenuText>
<BubbleMenuText>ST</BubbleMenuText>
</button>
<button
onClick={() => editor.chain().focus().toggleBold().run()}
Expand All @@ -91,7 +80,7 @@ export const MenuStyle = ({ editor }: { editor: Editor | null }) => {
}}
className={editor.isActive("details") ? "is-active" : ""}
type="button"
title="Placer dans un accordéon"
title="Accordéon"
>
<StorageIcon />
</button>
Expand All @@ -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"
>
<LinkIcon />
</button>
Expand All @@ -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")}
>
<InfoIcon />
Expand Down
14 changes: 7 additions & 7 deletions targets/frontend/src/components/forms/EditionField/MenuTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,55 @@ 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"
>
<InsertColumnLeft width={24} fill="white" />
</button>
<button
onClick={() => editor.chain().focus().addColumnAfter().run()}
disabled={!editor.can().addColumnAfter()}
type="button"
title="Ajouter colonne à droite"
title="Ajouter une colonne à droite"
>
<InsertColumnRight width={24} fill="white" />
</button>
<button
onClick={() => editor.chain().focus().deleteColumn().run()}
disabled={!editor.can().deleteColumn()}
type="button"
title="Supprimer colonne"
title="Supprimer la colonne"
>
<DeleteColumn width={24} fill="white" />
</button>
<button
onClick={() => editor.chain().focus().addRowBefore().run()}
disabled={!editor.can().addRowBefore()}
type="button"
title="Ajouter ligne au dessus"
title="Ajouter une ligne au dessus"
>
<InsertRowTop width={24} fill="white" />
</button>
<button
onClick={() => editor.chain().focus().addRowAfter().run()}
disabled={!editor.can().addRowAfter()}
type="button"
title="Ajouter ligne en dessous"
title="Ajouter une ligne en dessous"
>
<InsertRowBottom width={24} fill="white" />
</button>
<button
onClick={() => editor.chain().focus().deleteRow().run()}
disabled={!editor.can().deleteRow()}
type="button"
title="Supprimer ligne"
title="Supprimer la ligne"
>
<DeleteRow width={24} fill="white" />
</button>
<button
onClick={() => editor.chain().focus().deleteTable().run()}
disabled={!editor.can().deleteTable()}
type="button"
title="Supprimer tableau"
title="Supprimer le tableau"
>
<Delete />
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { mergeAttributes, Node, textblockTypeInputRule } from "@tiptap/core";

export type Level = "title" | "sub-title";

export interface TitleOptions {
levels: Level[];
HTMLAttributes: Record<string, any>;
}

declare module "@tiptap/core" {
interface Commands<ReturnType> {
title: {
setTitle: (attributes: { level: Level }) => ReturnType;
toggleTitle: (attributes: { level: Level }) => ReturnType;
unsetTitle: () => ReturnType;
};
}
}

export const Title = Node.create<TitleOptions>({
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,
},
});
});
},
});
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Alert";
export * from "./Titles";
Empty file.
Loading

0 comments on commit f1fdaa1

Please sign in to comment.