Skip to content

✨(frontend) add duplicate action to doc tree #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/frontend/apps/e2e/__tests__/app-impress/doc-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,6 +20,7 @@ import {
ModalRemoveDoc,
Role,
useCopyDocLink,
useDuplicateDoc,
} from '../../doc-management';
import { useCreateChildrenDoc } from '../api/useCreateChildren';
import { useDetachDoc } from '../api/useDetach';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
Loading