Skip to content

Commit 2864669

Browse files
committed
🚸(frontend) do not show comments button on resources
The comments does not seems to work on resources (images, pdf, ...), so we hide the button when the selected block is not a text block.
1 parent 7dae3a3 commit 2864669

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ test.beforeEach(async ({ page }) => {
2424
});
2525

2626
test.describe('Doc Editor', () => {
27-
test('it checks default toolbar buttons are displayed', async ({
27+
test('it checks toolbar buttons are displayed', async ({
2828
page,
2929
browserName,
3030
}) => {
3131
await createDoc(page, 'doc-toolbar', browserName, 1);
3232

33-
const editor = page.locator('.ProseMirror');
34-
await editor.click();
35-
await editor.fill('test content');
33+
const editor = await writeInEditor({ page, text: 'test content' });
3634

3735
await editor
3836
.getByText('test content', {
@@ -41,6 +39,9 @@ test.describe('Doc Editor', () => {
4139
.selectText();
4240

4341
const toolbar = page.locator('.bn-formatting-toolbar');
42+
await expect(
43+
toolbar.locator('button[data-test="comment-toolbar-button"]'),
44+
).toBeVisible();
4445
await expect(toolbar.locator('button[data-test="bold"]')).toBeVisible();
4546
await expect(toolbar.locator('button[data-test="italic"]')).toBeVisible();
4647
await expect(
@@ -63,6 +64,53 @@ test.describe('Doc Editor', () => {
6364
await expect(
6465
toolbar.locator('button[data-test="createLink"]'),
6566
).toBeVisible();
67+
await expect(
68+
toolbar.locator('button[data-test="ai-actions"]'),
69+
).toBeVisible();
70+
await expect(
71+
toolbar.locator('button[data-test="convertMarkdown"]'),
72+
).toBeVisible();
73+
74+
await page.keyboard.press('Escape');
75+
76+
await page.locator('.bn-block-outer').last().click();
77+
78+
await page.keyboard.press('Enter');
79+
80+
const fileChooserPromise = page.waitForEvent('filechooser');
81+
await page.locator('.bn-block-outer').last().fill('/');
82+
await page.getByText('Resizable image with caption').click();
83+
await page.getByText('Upload image').click();
84+
85+
const fileChooser = await fileChooserPromise;
86+
await fileChooser.setFiles(
87+
path.join(__dirname, 'assets/logo-suite-numerique.png'),
88+
);
89+
90+
const image = page
91+
.locator('.--docs--editor-container img.bn-visual-media')
92+
.first();
93+
94+
await expect(image).toHaveAttribute('role', 'presentation');
95+
96+
await image.dblclick();
97+
98+
await expect(
99+
toolbar.locator('button[data-test="comment-toolbar-button"]'),
100+
).toBeHidden();
101+
await expect(
102+
toolbar.locator('button[data-test="ai-actions"]'),
103+
).toBeHidden();
104+
await expect(
105+
toolbar.locator('button[data-test="convertMarkdown"]'),
106+
).toBeHidden();
107+
108+
await expect(
109+
toolbar.locator('button[data-test="editcaption"]'),
110+
).toBeVisible();
111+
await expect(
112+
toolbar.locator('button[data-test="downloadfile"]'),
113+
).toBeVisible();
66114
});
67115

68116
/**

src/frontend/apps/impress/src/features/docs/doc-editor/components/comments/CommentToolbarButton.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { useBlockNoteEditor, useComponentsContext } from '@blocknote/react';
1+
import {
2+
useBlockNoteEditor,
3+
useComponentsContext,
4+
useSelectedBlocks,
5+
} from '@blocknote/react';
6+
import { useMemo } from 'react';
27
import { useTranslation } from 'react-i18next';
38
import { css } from 'styled-components';
49

@@ -24,7 +29,18 @@ export const CommentToolbarButton = () => {
2429
DocsStyleSchema
2530
>();
2631

27-
if (!editor.isEditable || !Components || !currentDoc?.abilities.comment) {
32+
const selectedBlocks = useSelectedBlocks(editor);
33+
34+
const show = useMemo(() => {
35+
return !!selectedBlocks.find((block) => block.content !== undefined);
36+
}, [selectedBlocks]);
37+
38+
if (
39+
!show ||
40+
!editor.isEditable ||
41+
!Components ||
42+
!currentDoc?.abilities.comment
43+
) {
2844
return null;
2945
}
3046

@@ -34,8 +50,10 @@ export const CommentToolbarButton = () => {
3450
className="bn-button"
3551
onClick={() => {
3652
editor.comments?.startPendingComment();
53+
editor.formattingToolbar.closeMenu();
3754
}}
3855
aria-haspopup="dialog"
56+
data-test="comment-toolbar-button"
3957
>
4058
<Box
4159
$direction="row"

0 commit comments

Comments
 (0)