Skip to content

Commit 72456ce

Browse files
committed
fixup! ♻️(frontend) search on all docs if no children
1 parent 4c798f2 commit 72456ce

File tree

6 files changed

+86
-85
lines changed

6 files changed

+86
-85
lines changed

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

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -99,64 +99,60 @@ test.describe('Document search', () => {
9999
).toBeHidden();
100100
});
101101

102-
test("it checks we don't see filters in search modal", async ({ page }) => {
103-
const searchButton = page
104-
.getByTestId('left-panel-desktop')
105-
.getByRole('button', { name: 'search' });
106-
107-
await expect(searchButton).toBeVisible();
108-
await page.getByRole('button', { name: 'search', exact: true }).click();
109-
await expect(
110-
page.getByRole('combobox', { name: 'Quick search input' }),
111-
).toBeVisible();
112-
await expect(page.getByTestId('doc-search-filters')).toBeHidden();
113-
});
114-
});
115-
116-
test.describe('Sub page search', () => {
117102
test('it check the presence of filters in search modal', async ({
118103
page,
119104
browserName,
120105
}) => {
121-
await page.goto('/');
122-
const [doc1Title] = await createDoc(
123-
page,
124-
'My sub page search',
125-
browserName,
126-
1,
127-
);
128-
await verifyDocName(page, doc1Title);
106+
// Doc grid filters are not visible
129107
const searchButton = page
130108
.getByTestId('left-panel-desktop')
131109
.getByRole('button', { name: 'search', exact: true });
132-
await searchButton.click();
110+
133111
const filters = page.getByTestId('doc-search-filters');
134-
await expect(filters).toBeVisible();
135-
await filters.click();
136-
await filters.getByRole('button', { name: 'All docs' }).click();
112+
113+
await searchButton.click();
137114
await expect(
138-
page.getByRole('menuitem', { name: 'All docs' }),
115+
page.getByRole('combobox', { name: 'Quick search input' }),
139116
).toBeVisible();
117+
await expect(filters).toBeHidden();
118+
119+
await page.getByRole('button', { name: 'close' }).click();
120+
121+
// Create a doc without children for the moment
122+
// and check that filters are not visible
123+
const [doc1Title] = await createDoc(page, 'My page search', browserName, 1);
124+
await verifyDocName(page, doc1Title);
125+
126+
await searchButton.click();
140127
await expect(
141-
page.getByRole('menuitem', { name: 'Current doc' }),
128+
page.getByRole('combobox', { name: 'Quick search input' }),
142129
).toBeVisible();
143-
await page.getByRole('menuitem', { name: 'Current doc' }).click();
144-
145-
await expect(page.getByRole('button', { name: 'Reset' })).toBeVisible();
130+
await expect(filters).toBeHidden();
146131

147132
await page.getByRole('button', { name: 'close' }).click();
148133

134+
// Create a sub page
135+
// and check that filters are visible
149136
await createRootSubPage(page, browserName, 'My sub page search');
150137

151138
await searchButton.click();
139+
140+
await expect(filters).toBeVisible();
141+
142+
await filters.click();
143+
await filters.getByRole('button', { name: 'Current doc' }).click();
144+
await expect(
145+
page.getByRole('menuitem', { name: 'All docs' }),
146+
).toBeVisible();
152147
await expect(
153-
filters.getByRole('button', { name: 'Current doc' }),
148+
page.getByRole('menuitem', { name: 'Current doc' }),
154149
).toBeVisible();
150+
await page.getByRole('menuitem', { name: 'All docs' }).click();
151+
152+
await expect(page.getByRole('button', { name: 'Reset' })).toBeVisible();
155153
});
156154

157155
test('it searches sub pages', async ({ page, browserName }) => {
158-
await page.goto('/');
159-
160156
// First doc
161157
const [firstDocTitle] = await createDoc(
162158
page,
@@ -187,7 +183,6 @@ test.describe('Sub page search', () => {
187183
.getByRole('button', { name: 'search' });
188184

189185
await searchButton.click();
190-
await expect(page.getByRole('button', { name: 'All docs' })).toBeVisible();
191186
await page.getByRole('combobox', { name: 'Quick search input' }).click();
192187
await page
193188
.getByRole('combobox', { name: 'Quick search input' })

src/frontend/apps/impress/src/features/docs/doc-management/hooks/useDocUtils.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Doc } from '@/docs/doc-management';
22

33
export const useDocUtils = (doc: Doc) => {
44
return {
5-
isParent: doc.depth === 1, // it is a parent
6-
isChild: doc.depth > 1, // it is a child
7-
hasChildren: doc.numchild > 0, // it has children
8-
isDesyncronized: !!(
5+
isTopRoot: doc.depth === 1,
6+
isChild: doc.depth > 1,
7+
hasChildren: doc.numchild > 0,
8+
isDesynchronized: !!(
99
doc.ancestors_link_reach &&
1010
doc.ancestors_link_role &&
1111
(doc.computed_link_reach !== doc.ancestors_link_reach ||

src/frontend/apps/impress/src/features/docs/doc-search/components/DocSearchModal.tsx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { useDebouncedCallback } from 'use-debounce';
77

88
import { Box } from '@/components';
99
import { QuickSearch } from '@/components/quick-search';
10+
import { Doc, useDocUtils } from '@/docs/doc-management';
1011
import { useResponsiveStore } from '@/stores';
1112

12-
import { Doc } from '../../doc-management';
1313
import EmptySearchIcon from '../assets/illustration-docs-empty.png';
1414

1515
import { DocSearchContent } from './DocSearchContent';
@@ -20,18 +20,18 @@ import {
2020
} from './DocSearchFilters';
2121
import { DocSearchSubPageContent } from './DocSearchSubPageContent';
2222

23-
type DocSearchModalProps = {
23+
type DocSearchModalGlobalProps = {
2424
onClose: () => void;
2525
isOpen: boolean;
2626
showFilters?: boolean;
2727
defaultFilters?: DocSearchFiltersValues;
2828
};
2929

30-
export const DocSearchModal = ({
30+
const DocSearchModalGlobal = ({
3131
showFilters = false,
3232
defaultFilters,
3333
...modalProps
34-
}: DocSearchModalProps) => {
34+
}: DocSearchModalGlobalProps) => {
3535
const { t } = useTranslation();
3636
const [loading, setLoading] = useState(false);
3737

@@ -126,3 +126,42 @@ export const DocSearchModal = ({
126126
</Modal>
127127
);
128128
};
129+
130+
type DocSearchModalDetailProps = DocSearchModalGlobalProps & {
131+
doc: Doc;
132+
};
133+
134+
const DocSearchModalDetail = ({
135+
doc,
136+
...modalProps
137+
}: DocSearchModalDetailProps) => {
138+
const { hasChildren, isChild } = useDocUtils(doc);
139+
const isWithChildren = isChild || hasChildren;
140+
141+
let defaultFilters = DocSearchTarget.ALL;
142+
let showFilters = false;
143+
if (isWithChildren) {
144+
defaultFilters = DocSearchTarget.CURRENT;
145+
showFilters = true;
146+
}
147+
148+
return (
149+
<DocSearchModalGlobal
150+
{...modalProps}
151+
showFilters={showFilters}
152+
defaultFilters={{ target: defaultFilters }}
153+
/>
154+
);
155+
};
156+
157+
type DocSearchModalProps = DocSearchModalGlobalProps & {
158+
doc?: Doc;
159+
};
160+
161+
export const DocSearchModal = ({ doc, ...modalProps }: DocSearchModalProps) => {
162+
if (doc) {
163+
return <DocSearchModalDetail doc={doc} {...modalProps} />;
164+
}
165+
166+
return <DocSearchModalGlobal {...modalProps} />;
167+
};

src/frontend/apps/impress/src/features/docs/doc-share/components/DocVisibility.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const DocVisibility = ({ doc, canEdit = true }: DocVisibilityProps) => {
4747
const [docLinkRole, setDocLinkRole] = useState<LinkRole>(
4848
doc.computed_link_role ?? LinkRole.READER,
4949
);
50-
const { isDesyncronized } = useDocUtils(doc);
50+
const { isDesynchronized } = useDocUtils(doc);
5151

5252
const { linkModeTranslations, linkReachChoices, linkReachTranslations } =
5353
useTranslatedShareSettings();
@@ -165,7 +165,7 @@ export const DocVisibility = ({ doc, canEdit = true }: DocVisibilityProps) => {
165165
<Text $weight="700" $size="sm" $variation="700">
166166
{t('Link parameters')}
167167
</Text>
168-
{isDesyncronized && (
168+
{isDesynchronized && (
169169
<Box
170170
$background={colorsTokens['primary-100']}
171171
$padding="3xs"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const DocTreeItemActions = ({
4343
const deleteModal = useModal();
4444

4545
const copyLink = useCopyDocLink(doc.id);
46-
const { isParent } = useDocUtils(doc);
46+
const { isTopRoot } = useDocUtils(doc);
4747
const { mutate: detachDoc } = useDetachDoc();
4848
const treeContext = useTreeContext<Doc>();
4949
const { mutate: duplicateDoc } = useDuplicateDoc({
@@ -77,7 +77,7 @@ export const DocTreeItemActions = ({
7777
icon: <Icon iconName="link" $size="24px" />,
7878
callback: copyLink,
7979
},
80-
...(!isParent
80+
...(!isTopRoot
8181
? [
8282
{
8383
label: t('Move to my docs'),

src/frontend/apps/impress/src/features/left-panel/components/LeftPanelHeader.tsx

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { useRouter } from 'next/router';
33
import { PropsWithChildren, useCallback, useState } from 'react';
44

55
import { Box, Icon, SeparatedSection } from '@/components';
6-
import { Doc, useDocStore, useDocUtils } from '@/docs/doc-management';
7-
import { DocSearchModal, DocSearchTarget } from '@/docs/doc-search/';
6+
import { useDocStore } from '@/docs/doc-management';
7+
import { DocSearchModal } from '@/docs/doc-search/';
88
import { useAuth } from '@/features/auth';
99
import { useCmdK } from '@/hook/useCmdK';
1010

@@ -14,7 +14,6 @@ import { LeftPanelHeaderButton } from './LeftPanelHeaderButton';
1414

1515
export const LeftPanelHeader = ({ children }: PropsWithChildren) => {
1616
const { currentDoc } = useDocStore();
17-
const isDoc = !!currentDoc;
1817
const router = useRouter();
1918
const { authenticated } = useAuth();
2019
const [isSearchModalOpen, setIsSearchModalOpen] = useState(false);
@@ -78,45 +77,13 @@ export const LeftPanelHeader = ({ children }: PropsWithChildren) => {
7877
</SeparatedSection>
7978
{children}
8079
</Box>
81-
{isSearchModalOpen && isDoc && (
82-
<LeftPanelSearchModalFilter
80+
{isSearchModalOpen && (
81+
<DocSearchModal
8382
onClose={closeSearchModal}
8483
isOpen={isSearchModalOpen}
8584
doc={currentDoc}
8685
/>
8786
)}
88-
{isSearchModalOpen && !isDoc && (
89-
<DocSearchModal onClose={closeSearchModal} isOpen={isSearchModalOpen} />
90-
)}
9187
</>
9288
);
9389
};
94-
95-
interface LeftPanelSearchModalProps {
96-
doc: Doc;
97-
isOpen: boolean;
98-
onClose: () => void;
99-
}
100-
101-
const LeftPanelSearchModalFilter = ({
102-
doc,
103-
isOpen,
104-
onClose,
105-
}: LeftPanelSearchModalProps) => {
106-
const { hasChildren, isChild } = useDocUtils(doc);
107-
const isWithChildren = isChild || hasChildren;
108-
109-
let defaultFilters = DocSearchTarget.ALL;
110-
if (isWithChildren) {
111-
defaultFilters = DocSearchTarget.CURRENT;
112-
}
113-
114-
return (
115-
<DocSearchModal
116-
onClose={onClose}
117-
isOpen={isOpen}
118-
showFilters={true}
119-
defaultFilters={{ target: defaultFilters }}
120-
/>
121-
);
122-
};

0 commit comments

Comments
 (0)