fix(core): disable creating linked doc in sidebar when show linked is off (#13191)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* The "add linked page" icon button in the navigation panel is now only
visible if enabled in your app settings.

* **Enhancements**
* The navigation panel dynamically updates the available operations
based on your sidebar settings.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Cats Juice
2025-07-14 16:02:16 +08:00
committed by GitHub
parent 3948b8eada
commit 7b53641a94

View File

@@ -7,6 +7,7 @@ import {
} from '@affine/component'; } from '@affine/component';
import { usePageHelper } from '@affine/core/blocksuite/block-suite-page-list/utils'; import { usePageHelper } from '@affine/core/blocksuite/block-suite-page-list/utils';
import { Guard } from '@affine/core/components/guard'; import { Guard } from '@affine/core/components/guard';
import { useAppSettingHelper } from '@affine/core/components/hooks/affine/use-app-setting-helper';
import { useBlockSuiteMetaHelper } from '@affine/core/components/hooks/affine/use-block-suite-meta-helper'; import { useBlockSuiteMetaHelper } from '@affine/core/components/hooks/affine/use-block-suite-meta-helper';
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks'; import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
import { IsFavoriteIcon } from '@affine/core/components/pure/icons'; import { IsFavoriteIcon } from '@affine/core/components/pure/icons';
@@ -56,6 +57,7 @@ export const useNavigationPanelDocNodeOperations = (
const [addLinkedPageLoading, setAddLinkedPageLoading] = useState(false); const [addLinkedPageLoading, setAddLinkedPageLoading] = useState(false);
const docRecord = useLiveData(docsService.list.doc$(docId)); const docRecord = useLiveData(docsService.list.doc$(docId));
const { appSettings } = useAppSettingHelper();
const { createPage } = usePageHelper( const { createPage } = usePageHelper(
workspaceService.workspace.docCollection workspaceService.workspace.docCollection
@@ -149,6 +151,8 @@ export const useNavigationPanelDocNodeOperations = (
return useMemo( return useMemo(
() => [ () => [
...(appSettings.showLinkedDocInSidebar
? [
{ {
index: 0, index: 0,
inline: true, inline: true,
@@ -156,13 +160,17 @@ export const useNavigationPanelDocNodeOperations = (
<IconButton <IconButton
size="16" size="16"
icon={<PlusIcon />} icon={<PlusIcon />}
tooltip={t['com.affine.rootAppSidebar.explorer.doc-add-tooltip']()} tooltip={t[
'com.affine.rootAppSidebar.explorer.doc-add-tooltip'
]()}
onClick={handleAddLinkedPage} onClick={handleAddLinkedPage}
loading={addLinkedPageLoading} loading={addLinkedPageLoading}
disabled={addLinkedPageLoading} disabled={addLinkedPageLoading}
/> />
), ),
}, },
]
: []),
{ {
index: 50, index: 50,
view: ( view: (
@@ -258,6 +266,7 @@ export const useNavigationPanelDocNodeOperations = (
], ],
[ [
addLinkedPageLoading, addLinkedPageLoading,
appSettings.showLinkedDocInSidebar,
docId, docId,
favorite, favorite,
handleAddLinkedPage, handleAddLinkedPage,