Skip to content

Commit

Permalink
feat(information): utilisation de tiptap sur les pages infos
Browse files Browse the repository at this point in the history
  • Loading branch information
m-maillot committed Dec 12, 2024
1 parent d8a3257 commit c066714
Show file tree
Hide file tree
Showing 7 changed files with 3,678 additions and 10 deletions.
4 changes: 4 additions & 0 deletions targets/frontend/src/components/forms/EditionField/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const Editor = ({
disabled,
isError = false,
}: EditorProps) => {
const [currentContent, setCurrentContent] = useState(content);
const [focus, setFocus] = useState(false);
const [isClient, setIsClient] = useState(false);
const editor = useEditor({
Expand Down Expand Up @@ -77,6 +78,7 @@ export const Editor = ({
],
onUpdate: ({ editor }) => {
const html = editor.getHTML();
setCurrentContent(html);
onUpdate(html !== emptyHtml ? html : "");
},
});
Expand Down Expand Up @@ -104,6 +106,7 @@ export const Editor = ({
focus={focus}
isError={isError}
disabled={disabled}
htmlFor={label}
>
<MenuStyle editor={editor} />
<MenuSpecial editor={editor} />
Expand All @@ -115,6 +118,7 @@ export const Editor = ({
onBlur={() => setFocus(false)}
disabled={disabled}
/>
<input type="hidden" id={label} value={currentContent} />
</TitleBox>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack, FormControl } from "@mui/material";
import { FormControl, Stack } from "@mui/material";
import React from "react";
import { FormTextField } from "src/components/forms";
import { FormEditionField } from "src/components/forms";
import { Control } from "react-hook-form";

export type InformationBlockTextProps = {
Expand All @@ -21,14 +21,11 @@ export const InformationsBlockText = ({
spacing={2}
>
<FormControl>
<FormTextField
<FormEditionField
label="Texte"
name={`${name}.content`}
control={control}
label="Texte"
rules={{ required: true }}
multiline
fullWidth
labelFixed
/>
</FormControl>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { render, screen, waitFor } from "@testing-library/react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import React from "react";
import { fireEvent } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import { InformationsForm } from "../InformationsForm";
import { InformationsResult } from "../Informations.query";
import { ClipboardEventMock, DragEventMock } from "./richeTextUtils";

const information: InformationsResult = {
id: "cafaf8d6-af91-4901-a18d-e70921788088",
Expand Down Expand Up @@ -47,6 +47,9 @@ const information: InformationsResult = {

const onSubmit = jest.fn(() => Promise.resolve());

(global as any).ClipboardEvent = ClipboardEventMock;
(global as any).DragEvent = DragEventMock;

describe("InformationForm", () => {
afterEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export class ClipboardDataMock {
getData: jest.Mock<string, [string]>;
setData: jest.Mock<void, [string, string]>;

constructor() {
this.getData = jest.fn();
this.setData = jest.fn();
}
}

export class ClipboardEventMock extends Event {
clipboardData: ClipboardDataMock;

constructor(type: string, options?: EventInit) {
super(type, options);
this.clipboardData = new ClipboardDataMock();
}
}

export class DataTransferMock {
data: { [key: string]: string };

constructor() {
this.data = {};
}

setData(format: string, data: string): void {
this.data[format] = data;
}

getData(format: string): string {
return this.data[format] || "";
}
}

export class DragEventMock extends Event {
dataTransfer: DataTransferMock;

constructor(type: string, options?: EventInit) {
super(type, options);
this.dataTransfer = new DataTransferMock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const mapInformationToDocument = async (
blocks: await Promise.all(
blocks.map(async (block) => {
const htmlWithGlossary = await getGlossaryContent(
"markdown",
"html",
block.content ?? ""
);
return {
Expand Down
Loading

0 comments on commit c066714

Please sign in to comment.