mirror of
https://github.com/suitenumerique/docs
synced 2026-04-21 13:37:20 +00:00
✨(frontend) add duplicate action to doc tree
We added a duplicate action to the document tree.
This commit is contained in:
parent
500d4ea5ac
commit
22ef6e0e40
2 changed files with 47 additions and 1 deletions
|
|
@ -482,6 +482,22 @@ test.describe('Doc Header', () => {
|
|||
await expect(
|
||||
page.getByTestId('doc-tree').getByText(duplicateDuplicateTitle),
|
||||
).toBeVisible();
|
||||
|
||||
const docTree = page.getByTestId('doc-tree');
|
||||
|
||||
await docTree.getByText(duplicateDuplicateTitle).hover();
|
||||
await docTree
|
||||
.getByText(duplicateDuplicateTitle)
|
||||
.getByRole('button', { name: 'add_box' })
|
||||
.click();
|
||||
|
||||
await page.getByRole('menuitem', { name: 'Duplicate' }).click();
|
||||
|
||||
const duplicateDuplicateDuplicateTitle =
|
||||
'Copy of ' + duplicateDuplicateTitle;
|
||||
await expect(
|
||||
page.getByTestId('doc-tree').getByText(duplicateDuplicateDuplicateTitle),
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ import {
|
|||
DropdownMenuOption,
|
||||
useTreeContext,
|
||||
} from '@gouvfr-lasuite/ui-kit';
|
||||
import { useModal } from '@openfun/cunningham-react';
|
||||
import {
|
||||
VariantType,
|
||||
useModal,
|
||||
useToastProvider,
|
||||
} from '@openfun/cunningham-react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { Fragment } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
|
@ -16,6 +20,7 @@ import {
|
|||
ModalRemoveDoc,
|
||||
Role,
|
||||
useCopyDocLink,
|
||||
useDuplicateDoc,
|
||||
} from '../../doc-management';
|
||||
import { useCreateChildrenDoc } from '../api/useCreateChildren';
|
||||
import { useDetachDoc } from '../api/useDetach';
|
||||
|
|
@ -45,6 +50,19 @@ export const DocTreeItemActions = ({
|
|||
const { isCurrentParent } = useTreeUtils(doc);
|
||||
const { mutate: detachDoc } = useDetachDoc();
|
||||
const treeContext = useTreeContext<Doc>();
|
||||
const { toast } = useToastProvider();
|
||||
const { mutate: duplicateDoc } = useDuplicateDoc({
|
||||
onSuccess: () => {
|
||||
toast(t('Document duplicated successfully!'), VariantType.SUCCESS, {
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
onError: () => {
|
||||
toast(t('Failed to duplicate the document...'), VariantType.ERROR, {
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const handleDetachDoc = () => {
|
||||
if (!treeContext?.root) {
|
||||
|
|
@ -89,6 +107,18 @@ export const DocTreeItemActions = ({
|
|||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: t('Duplicate'),
|
||||
icon: <Icon $variation="600" iconName="content_copy" />,
|
||||
isDisabled: !doc.abilities.duplicate,
|
||||
callback: () => {
|
||||
duplicateDoc({
|
||||
docId: doc.id,
|
||||
with_accesses: false,
|
||||
canSave: doc.abilities.partial_update,
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t('Delete'),
|
||||
isDisabled: !doc.abilities.destroy,
|
||||
|
|
|
|||
Loading…
Reference in a new issue