Skip to content

Commit c6c9958

Browse files
committed
✨(frontend) add duplicate action to doc tree
We added a duplicate action to the document tree.
1 parent 42c44fc commit c6c9958

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,19 @@ test.describe('Doc Header', () => {
472472
await editor.click();
473473
await editor.fill('Hello Duplicated World');
474474

475-
await page.getByLabel('Open the document options').click();
475+
const duplicateTitle = 'Copy of ' + childTitle;
476+
const docTree = page.getByTestId('doc-tree');
476477

477-
await page.getByRole('menuitem', { name: 'Duplicate' }).click();
478-
await expect(
479-
page.getByText('Document duplicated successfully!'),
480-
).toBeVisible();
478+
const child = docTree
479+
.getByRole('treeitem')
480+
.locator('.--docs-sub-page-item')
481+
.filter({
482+
hasText: childTitle,
483+
});
484+
await child.hover();
485+
await child.getByText(`more_horiz`).click();
481486

482-
const duplicateTitle = 'Copy of ' + childTitle;
487+
await page.getByRole('menuitem', { name: 'Duplicate' }).click();
483488

484489
await verifyDocName(page, duplicateTitle);
485490

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTreeItemActions.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import { useTranslation } from 'react-i18next';
1010
import { css } from 'styled-components';
1111

1212
import { Box, BoxButton, Icon } from '@/components';
13-
1413
import {
1514
Doc,
1615
ModalRemoveDoc,
1716
Role,
1817
useCopyDocLink,
19-
} from '../../doc-management';
18+
useDuplicateDoc,
19+
} from '@/docs/doc-management';
20+
2021
import { useCreateChildrenDoc } from '../api/useCreateChildren';
2122
import { useDetachDoc } from '../api/useDetach';
2223
import MoveDocIcon from '../assets/doc-extract-bold.svg';
@@ -45,6 +46,11 @@ export const DocTreeItemActions = ({
4546
const { isCurrentParent } = useTreeUtils(doc);
4647
const { mutate: detachDoc } = useDetachDoc();
4748
const treeContext = useTreeContext<Doc>();
49+
const { mutate: duplicateDoc } = useDuplicateDoc({
50+
onSuccess: (data) => {
51+
void router.push(`/docs/${data.id}`);
52+
},
53+
});
4854

4955
const handleDetachDoc = () => {
5056
if (!treeContext?.root) {
@@ -89,6 +95,18 @@ export const DocTreeItemActions = ({
8995
},
9096
]
9197
: []),
98+
{
99+
label: t('Duplicate'),
100+
icon: <Icon $variation="600" iconName="content_copy" />,
101+
isDisabled: !doc.abilities.duplicate,
102+
callback: () => {
103+
duplicateDoc({
104+
docId: doc.id,
105+
with_accesses: false,
106+
canSave: doc.abilities.partial_update,
107+
});
108+
},
109+
},
92110
{
93111
label: t('Delete'),
94112
isDisabled: !doc.abilities.destroy,

0 commit comments

Comments
 (0)