Skip to content

Commit fb0528b

Browse files
committed
🩹(frontend) refresh tree after duplicate
After duplicating a document, the tree is now refreshed to reflect the new structure. This ensures that the user sees the updated document tree immediately after the duplication action.
1 parent 0a10642 commit fb0528b

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
mockedInvitations,
1010
verifyDocName,
1111
} from './common';
12+
import { createRootSubPage } from './sub-pages-utils';
1213

1314
test.beforeEach(async ({ page }) => {
1415
await page.goto('/');
@@ -456,6 +457,32 @@ test.describe('Doc Header', () => {
456457
await page.getByText(duplicateDuplicateTitle).click();
457458
await expect(page.getByText('Hello Duplicated World')).toBeVisible();
458459
});
460+
461+
test('it duplicates a child document', async ({ page, browserName }) => {
462+
await createDoc(page, `Duplicate doc`, browserName);
463+
464+
const { name: childTitle } = await createRootSubPage(
465+
page,
466+
browserName,
467+
'Duplicate doc - child',
468+
);
469+
470+
const editor = page.locator('.ProseMirror');
471+
await editor.click();
472+
await editor.fill('Hello Duplicated World');
473+
474+
await page.getByLabel('Open the document options').click();
475+
476+
await page.getByRole('menuitem', { name: 'Duplicate' }).click();
477+
await expect(
478+
page.getByText('Document duplicated successfully!'),
479+
).toBeVisible();
480+
481+
const duplicateDuplicateTitle = 'Copy of ' + childTitle;
482+
await expect(
483+
page.getByTestId('doc-tree').getByText(duplicateDuplicateTitle),
484+
).toBeVisible();
485+
});
459486
});
460487

461488
test.describe('Documents Header mobile', () => {

src/frontend/apps/impress/src/features/docs/doc-management/api/useDuplicateDoc.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Y from 'yjs';
77

88
import { APIError, errorCauses, fetchAPI } from '@/api';
99
import { toBase64 } from '@/docs/doc-editor';
10+
import { KEY_DOC_TREE } from '@/docs/doc-tree';
1011
import { KEY_LIST_DOC_VERSIONS } from '@/docs/doc-versioning';
1112

1213
import { useProviderStore } from '../stores';
@@ -85,6 +86,9 @@ export function useDuplicateDoc(options: DuplicateDocOptions) {
8586
void queryClient.resetQueries({
8687
queryKey: [KEY_LIST_DOC],
8788
});
89+
void queryClient.resetQueries({
90+
queryKey: [KEY_DOC_TREE],
91+
});
8892
void options.onSuccess?.(data, variables, context);
8993
},
9094
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './useCreateChildren';
22
export * from './useDocChildren';
3+
export * from './useDocTree';
34
export * from './useMove';

src/frontend/apps/impress/src/features/docs/doc-tree/api/useDocTree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const getDocTree = async ({ docId }: DocsTreeParams): Promise<Doc> => {
2525
return response.json() as Promise<Doc>;
2626
};
2727

28-
export const KEY_LIST_DOC_CHILDREN = 'doc-tree';
28+
export const KEY_DOC_TREE = 'doc-tree';
2929

3030
export function useDocTree(
3131
params: DocsTreeParams,
@@ -35,7 +35,7 @@ export function useDocTree(
3535
>,
3636
) {
3737
return useQuery<Doc, APIError, Doc>({
38-
queryKey: [KEY_LIST_DOC_CHILDREN, params],
38+
queryKey: [KEY_DOC_TREE, params],
3939
queryFn: () => getDocTree(params),
4040
staleTime: 0,
4141
refetchOnWindowFocus: false,

0 commit comments

Comments
 (0)