Skip to content

Commit 0eb8802

Browse files
committed
fixup! ♻️(frontend) search on all docs if no children
1 parent 82a3bf2 commit 0eb8802

File tree

5 files changed

+53
-49
lines changed

5 files changed

+53
-49
lines changed

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: 41 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,40 @@ 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+
if (isWithChildren) {
143+
defaultFilters = DocSearchTarget.CURRENT;
144+
}
145+
146+
return (
147+
<DocSearchModalGlobal
148+
{...modalProps}
149+
showFilters={true}
150+
defaultFilters={{ target: defaultFilters }}
151+
/>
152+
);
153+
};
154+
155+
type DocSearchModalProps = DocSearchModalGlobalProps & {
156+
doc?: Doc;
157+
};
158+
159+
export const DocSearchModal = ({ doc, ...modalProps }: DocSearchModalProps) => {
160+
if (doc) {
161+
return <DocSearchModalDetail doc={doc} {...modalProps} />;
162+
}
163+
164+
return <DocSearchModalGlobal {...modalProps} />;
165+
};

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)