Skip to content

Commit fd033f3

Browse files
committed
✨(frontend) add create sub-documents button
We added a sub button to create sub-documents from the New button. This sub button is only visible when the user is in a document, and it allows them to create a new document that is a child of the current document.
1 parent 460fa83 commit fd033f3

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ test.describe('Doc Create', () => {
3131
await expect(docsGrid.getByText(docTitle)).toBeVisible();
3232
});
3333

34+
test('it creates a sub doc from the submenu "New" button', async ({
35+
page,
36+
browserName,
37+
}) => {
38+
await createDoc(page, 'my-new-button-sub-doc', browserName, 1);
39+
40+
await page.getByLabel('Open new document options').click();
41+
await page.getByRole('menuitem', { name: 'New sub-doc' }).click();
42+
43+
const input = page.getByRole('textbox', { name: 'Document title' });
44+
await expect(input).toHaveText('', { timeout: 10000 });
45+
await expect(
46+
page.locator('.c__tree-view--row-content').getByText('Untitled document'),
47+
).toBeVisible();
48+
});
49+
3450
test('it creates a sub doc from slash menu editor', async ({
3551
page,
3652
browserName,
Lines changed: 10 additions & 0 deletions
Loading

src/frontend/apps/impress/src/features/docs/doc-management/components/NewDocButton.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import { useTranslation } from 'react-i18next';
77
import { Text } from '@/components';
88
import { useConfig } from '@/core/config/api/useConfig';
99
import ArrowDownIcon from '@/icons/arrow-drop-down.svg';
10+
import SubDocIcon from '@/icons/doc-new-subdoc.svg';
1011
import PlusIcon from '@/icons/doc-plus.svg';
1112
import UploadIcon from '@/icons/upload-arrow.svg';
1213

14+
import { useCreateChildDoc } from '../api/useCreateChildDoc';
1315
import { useImport } from '../hooks/useImport';
16+
import { useDocStore } from '../stores/useDocStore';
1417

1518
interface NewDocButtonProps {
1619
onClose?: () => void;
@@ -55,6 +58,7 @@ export const NewDocButton = ({ onClose }: NewDocButtonProps) => {
5558
export function DropdownArrow() {
5659
const router = useRouter();
5760
const [isMenuOpen, setIsMenuOpen] = useState(false);
61+
const { currentDoc } = useDocStore();
5862
const { t } = useTranslation();
5963
const {
6064
getInputProps,
@@ -66,21 +70,38 @@ export function DropdownArrow() {
6670
void router.push(`/docs/${doc.id}/`);
6771
},
6872
});
73+
const { mutate: createChildDoc } = useCreateChildDoc({
74+
onSuccess: (newDoc) => {
75+
void router.push(`/docs/${newDoc.id}`);
76+
},
77+
});
6978

7079
const toggleMenu = useCallback(() => {
7180
setIsMenuOpen((open) => !open);
7281
}, []);
7382

7483
const options = useMemo<DropdownMenuItem[]>(
7584
() => [
85+
{
86+
label: t('New sub-doc'),
87+
icon: <SubDocIcon aria-hidden="true" width="24" height="24" />,
88+
callback: () => {
89+
if (currentDoc) {
90+
createChildDoc({
91+
parentId: currentDoc.id,
92+
});
93+
}
94+
},
95+
isHidden: !currentDoc,
96+
},
7697
{
7798
label: t('Import a document'),
7899
icon: <UploadIcon aria-hidden="true" width="24" height="24" />,
79100
callback: openImport,
80101
isHidden: !isImportEnabled,
81102
},
82103
],
83-
[t, openImport, isImportEnabled],
104+
[t, openImport, currentDoc, createChildDoc, isImportEnabled],
84105
);
85106

86107
return (

0 commit comments

Comments
 (0)