Skip to content

Commit 7613e6b

Browse files
committed
🐛(frontend) include top parent in search
When searching for documents, the top parent document is now included in the search results if it matches the search query.
1 parent 7021c0f commit 7613e6b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { createDoc, randomName, verifyDocName } from './utils-common';
3+
import { createDoc, verifyDocName } from './utils-common';
44
import { createRootSubPage } from './utils-sub-pages';
55

66
test.beforeEach(async ({ page }) => {
@@ -163,20 +163,12 @@ test.describe('Document search', () => {
163163
await verifyDocName(page, firstDocTitle);
164164

165165
// Create a new doc - for the moment without children
166-
await page.getByRole('button', { name: 'New doc' }).click();
167-
await verifyDocName(page, '');
168-
await page.getByRole('textbox', { name: 'doc title input' }).click();
169-
await page
170-
.getByRole('textbox', { name: 'doc title input' })
171-
.press('ControlOrMeta+a');
172-
const [secondDocTitle] = randomName(
166+
const [secondDocTitle] = await createDoc(
167+
page,
173168
'My second sub page search',
174169
browserName,
175170
1,
176171
);
177-
await page
178-
.getByRole('textbox', { name: 'doc title input' })
179-
.fill(secondDocTitle);
180172

181173
const searchButton = page
182174
.getByTestId('left-panel-desktop')
@@ -199,16 +191,23 @@ test.describe('Document search', () => {
199191
await page.getByRole('button', { name: 'close' }).click();
200192

201193
// Create a sub page
202-
await createRootSubPage(page, browserName, secondDocTitle);
194+
const { name: secondChildDocTitle } = await createRootSubPage(
195+
page,
196+
browserName,
197+
'second - Child doc',
198+
);
203199
await searchButton.click();
204200
await page
205201
.getByRole('combobox', { name: 'Quick search input' })
206-
.fill('sub page search');
202+
.fill('second');
207203

208204
// Now there is a sub page - expect to have the focus on the current doc
209205
await expect(
210206
page.getByRole('presentation').getByLabel(secondDocTitle),
211207
).toBeVisible();
208+
await expect(
209+
page.getByRole('presentation').getByLabel(secondChildDocTitle),
210+
).toBeVisible();
212211
await expect(
213212
page.getByRole('presentation').getByLabel(firstDocTitle),
214213
).toBeHidden();

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export const DocSearchSubPageContent = ({
4545
const docsData: QuickSearchData<Doc> = useMemo(() => {
4646
const subDocs = subDocsData?.pages.flatMap((page) => page.results) || [];
4747

48+
if (
49+
treeContext?.root &&
50+
treeContext.root.title?.toLowerCase().includes(search.toLowerCase())
51+
) {
52+
subDocs.unshift(treeContext.root);
53+
}
54+
4855
return {
4956
groupName: subDocs.length > 0 ? t('Select a page') : '',
5057
elements: search ? subDocs : [],
@@ -57,7 +64,13 @@ export const DocSearchSubPageContent = ({
5764
]
5865
: [],
5966
};
60-
}, [search, subDocsData, subDocsFetchNextPage, subDocsHasNextPage]);
67+
}, [
68+
search,
69+
subDocsData?.pages,
70+
subDocsFetchNextPage,
71+
subDocsHasNextPage,
72+
treeContext?.root,
73+
]);
6174

6275
useEffect(() => {
6376
onLoadingChange?.(loading);

0 commit comments

Comments
 (0)