♻️(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.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export * from './useCollaboration';
|
||||
export * from './useCopyDocLink';
|
||||
export * from './useDocUtils';
|
||||
export * from './useIsCollaborativeEditable';
|
||||
export * from './useTrans';
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Doc } from '@/docs/doc-management';
|
||||
|
||||
export const useTreeUtils = (doc: Doc) => {
|
||||
export const useDocUtils = (doc: Doc) => {
|
||||
return {
|
||||
isTopRoot: doc.depth === 1,
|
||||
isChild: doc.depth > 1,
|
||||
hasChildren: doc.numchild > 0,
|
||||
isDesynchronized: !!(
|
||||
doc.ancestors_link_reach &&
|
||||
(doc.computed_link_reach !== doc.ancestors_link_reach ||
|
||||
@@ -7,9 +7,9 @@ import { useDebouncedCallback } from 'use-debounce';
|
||||
|
||||
import { Box } from '@/components';
|
||||
import { QuickSearch } from '@/components/quick-search';
|
||||
import { Doc, useDocUtils } from '@/docs/doc-management';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
import { Doc } from '../../doc-management';
|
||||
import EmptySearchIcon from '../assets/illustration-docs-empty.png';
|
||||
|
||||
import { DocSearchContent } from './DocSearchContent';
|
||||
@@ -20,18 +20,18 @@ import {
|
||||
} from './DocSearchFilters';
|
||||
import { DocSearchSubPageContent } from './DocSearchSubPageContent';
|
||||
|
||||
type DocSearchModalProps = {
|
||||
type DocSearchModalGlobalProps = {
|
||||
onClose: () => void;
|
||||
isOpen: boolean;
|
||||
showFilters?: boolean;
|
||||
defaultFilters?: DocSearchFiltersValues;
|
||||
};
|
||||
|
||||
export const DocSearchModal = ({
|
||||
const DocSearchModalGlobal = ({
|
||||
showFilters = false,
|
||||
defaultFilters,
|
||||
...modalProps
|
||||
}: DocSearchModalProps) => {
|
||||
}: DocSearchModalGlobalProps) => {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
@@ -126,3 +126,42 @@ export const DocSearchModal = ({
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
type DocSearchModalDetailProps = DocSearchModalGlobalProps & {
|
||||
doc: Doc;
|
||||
};
|
||||
|
||||
const DocSearchModalDetail = ({
|
||||
doc,
|
||||
...modalProps
|
||||
}: DocSearchModalDetailProps) => {
|
||||
const { hasChildren, isChild } = useDocUtils(doc);
|
||||
const isWithChildren = isChild || hasChildren;
|
||||
|
||||
let defaultFilters = DocSearchTarget.ALL;
|
||||
let showFilters = false;
|
||||
if (isWithChildren) {
|
||||
defaultFilters = DocSearchTarget.CURRENT;
|
||||
showFilters = true;
|
||||
}
|
||||
|
||||
return (
|
||||
<DocSearchModalGlobal
|
||||
{...modalProps}
|
||||
showFilters={showFilters}
|
||||
defaultFilters={{ target: defaultFilters }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
type DocSearchModalProps = DocSearchModalGlobalProps & {
|
||||
doc?: Doc;
|
||||
};
|
||||
|
||||
export const DocSearchModal = ({ doc, ...modalProps }: DocSearchModalProps) => {
|
||||
if (doc) {
|
||||
return <DocSearchModalDetail doc={doc} {...modalProps} />;
|
||||
}
|
||||
|
||||
return <DocSearchModalGlobal {...modalProps} />;
|
||||
};
|
||||
|
||||
@@ -17,9 +17,9 @@ import {
|
||||
LinkReach,
|
||||
LinkRole,
|
||||
getDocLinkReach,
|
||||
useDocUtils,
|
||||
useUpdateDocLink,
|
||||
} from '@/docs/doc-management';
|
||||
import { useTreeUtils } from '@/docs/doc-tree';
|
||||
import { useResponsiveStore } from '@/stores';
|
||||
|
||||
import { useTranslatedShareSettings } from '../hooks/';
|
||||
@@ -37,7 +37,7 @@ export const DocVisibility = ({ doc }: DocVisibilityProps) => {
|
||||
const canManage = doc.abilities.accesses_manage;
|
||||
const docLinkReach = getDocLinkReach(doc);
|
||||
const docLinkRole = doc.computed_link_role ?? LinkRole.READER;
|
||||
const { isDesynchronized } = useTreeUtils(doc);
|
||||
const { isDesynchronized } = useDocUtils(doc);
|
||||
const { linkModeTranslations, linkReachChoices, linkReachTranslations } =
|
||||
useTranslatedShareSettings();
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './useTreeUtils';
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './api';
|
||||
export * from './components';
|
||||
export * from './hooks';
|
||||
export * from './utils';
|
||||
|
||||
@@ -3,7 +3,8 @@ import { useRouter } from 'next/router';
|
||||
import { PropsWithChildren, useCallback, useState } from 'react';
|
||||
|
||||
import { Box, Icon, SeparatedSection } from '@/components';
|
||||
import { DocSearchModal, DocSearchTarget } from '@/docs/doc-search/';
|
||||
import { useDocStore } from '@/docs/doc-management';
|
||||
import { DocSearchModal } from '@/docs/doc-search/';
|
||||
import { useAuth } from '@/features/auth';
|
||||
import { useCmdK } from '@/hook/useCmdK';
|
||||
|
||||
@@ -12,10 +13,9 @@ import { useLeftPanelStore } from '../stores';
|
||||
import { LeftPanelHeaderButton } from './LeftPanelHeaderButton';
|
||||
|
||||
export const LeftPanelHeader = ({ children }: PropsWithChildren) => {
|
||||
const { currentDoc } = useDocStore();
|
||||
const router = useRouter();
|
||||
const { authenticated } = useAuth();
|
||||
const isDoc = router.pathname === '/docs/[id]';
|
||||
|
||||
const [isSearchModalOpen, setIsSearchModalOpen] = useState(false);
|
||||
|
||||
const openSearchModal = useCallback(() => {
|
||||
@@ -81,10 +81,7 @@ export const LeftPanelHeader = ({ children }: PropsWithChildren) => {
|
||||
<DocSearchModal
|
||||
onClose={closeSearchModal}
|
||||
isOpen={isSearchModalOpen}
|
||||
showFilters={isDoc}
|
||||
defaultFilters={{
|
||||
target: isDoc ? DocSearchTarget.CURRENT : undefined,
|
||||
}}
|
||||
doc={currentDoc}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user