Skip to content

Commit 9d28147

Browse files
committed
♻️(frontend) search on all docs if no children
When searching for documents, if no children are found, the search will now include all documents instead of just those with children.
1 parent d12b608 commit 9d28147

File tree

8 files changed

+61
-36
lines changed

8 files changed

+61
-36
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './useCollaboration';
22
export * from './useCopyDocLink';
3+
export * from './useDocUtils';
34
export * from './useIsCollaborativeEditable';
45
export * from './useTrans';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Doc } from '@/docs/doc-management';
2+
3+
export const useDocUtils = (doc: Doc) => {
4+
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: !!(
9+
doc.ancestors_link_reach &&
10+
doc.ancestors_link_role &&
11+
(doc.computed_link_reach !== doc.ancestors_link_reach ||
12+
doc.computed_link_role !== doc.ancestors_link_role)
13+
),
14+
} as const;
15+
};

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
@@ -22,9 +22,9 @@ import {
2222
LinkReach,
2323
LinkRole,
2424
getDocLinkReach,
25+
useDocUtils,
2526
useUpdateDocLink,
2627
} from '@/docs/doc-management';
27-
import { useTreeUtils } from '@/docs/doc-tree';
2828
import { useResponsiveStore } from '@/stores';
2929

3030
import { useTranslatedShareSettings } from '../hooks/';
@@ -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 } = useTreeUtils(doc);
50+
const { isDesyncronized } = useDocUtils(doc);
5151

5252
const { linkModeTranslations, linkReachChoices, linkReachTranslations } =
5353
useTranslatedShareSettings();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { useTranslation } from 'react-i18next';
1010
import { css } from 'styled-components';
1111

1212
import { Box, BoxButton, Icon } from '@/components';
13-
1413
import {
1514
Doc,
1615
ModalRemoveDoc,
1716
Role,
1817
useCopyDocLink,
19-
} from '../../doc-management';
18+
useDocUtils,
19+
} from '@/docs/doc-management';
20+
2021
import { useCreateChildrenDoc } from '../api/useCreateChildren';
2122
import { useDetachDoc } from '../api/useDetach';
2223
import MoveDocIcon from '../assets/doc-extract-bold.svg';
23-
import { useTreeUtils } from '../hooks';
2424

2525
type DocTreeItemActionsProps = {
2626
doc: Doc;
@@ -42,7 +42,7 @@ export const DocTreeItemActions = ({
4242
const deleteModal = useModal();
4343

4444
const copyLink = useCopyDocLink(doc.id);
45-
const { isCurrentParent } = useTreeUtils(doc);
45+
const { isParent } = useDocUtils(doc);
4646
const { mutate: detachDoc } = useDetachDoc();
4747
const treeContext = useTreeContext<Doc>();
4848

@@ -71,7 +71,7 @@ export const DocTreeItemActions = ({
7171
icon: <Icon iconName="link" $size="24px" />,
7272
callback: copyLink,
7373
},
74-
...(!isCurrentParent
74+
...(!isParent
7575
? [
7676
{
7777
label: t('Move to my docs'),

src/frontend/apps/impress/src/features/docs/doc-tree/hooks/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/frontend/apps/impress/src/features/docs/doc-tree/hooks/useTreeUtils.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './api';
2-
export * from './hooks';
32
export * from './utils';

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

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ 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';
67
import { DocSearchModal, DocSearchTarget } from '@/docs/doc-search/';
78
import { useAuth } from '@/features/auth';
89
import { useCmdK } from '@/hook/useCmdK';
@@ -12,10 +13,10 @@ import { useLeftPanelStore } from '../stores';
1213
import { LeftPanelHeaderButton } from './LeftPanelHeaderButton';
1314

1415
export const LeftPanelHeader = ({ children }: PropsWithChildren) => {
16+
const { currentDoc } = useDocStore();
17+
const isDoc = !!currentDoc;
1518
const router = useRouter();
1619
const { authenticated } = useAuth();
17-
const isDoc = router.pathname === '/docs/[id]';
18-
1920
const [isSearchModalOpen, setIsSearchModalOpen] = useState(false);
2021

2122
const openSearchModal = useCallback(() => {
@@ -77,16 +78,45 @@ export const LeftPanelHeader = ({ children }: PropsWithChildren) => {
7778
</SeparatedSection>
7879
{children}
7980
</Box>
80-
{isSearchModalOpen && (
81-
<DocSearchModal
81+
{isSearchModalOpen && isDoc && (
82+
<LeftPanelSearchModalFilter
8283
onClose={closeSearchModal}
8384
isOpen={isSearchModalOpen}
84-
showFilters={isDoc}
85-
defaultFilters={{
86-
target: isDoc ? DocSearchTarget.CURRENT : undefined,
87-
}}
85+
doc={currentDoc}
8886
/>
8987
)}
88+
{isSearchModalOpen && !isDoc && (
89+
<DocSearchModal onClose={closeSearchModal} isOpen={isSearchModalOpen} />
90+
)}
9091
</>
9192
);
9293
};
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)