mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
chore: Move link actions to their own module and inline link checks
This commit is contained in:
23 files changed
+226
-223
No files matched your search
@@ -7,7 +7,6 @@ import {
|
||||
EditIcon,
|
||||
ExportIcon,
|
||||
ImportIcon,
|
||||
LinkIcon,
|
||||
SortManualIcon,
|
||||
NewDocumentIcon,
|
||||
PadlockIcon,
|
||||
@@ -32,7 +31,6 @@ import ConfirmationDialog from "~/components/ConfirmationDialog";
|
||||
import { DialogTitle } from "~/components/DialogTitle";
|
||||
import DynamicCollectionIcon from "~/components/Icons/CollectionIcon";
|
||||
import { ImportDocumentDialog } from "~/components/ImportDocumentDialog";
|
||||
import { openAddLinkDialog } from "~/components/Sidebar/components/LinkDialog";
|
||||
import { getHeaderExpandedKey } from "~/components/Sidebar/components/Header";
|
||||
import {
|
||||
createAction,
|
||||
@@ -560,25 +558,6 @@ export const createDocument = createInternalLinkAction({
|
||||
},
|
||||
});
|
||||
|
||||
export const addLinkToCollection = createAction({
|
||||
name: ({ t }) => `${t("Add link")}…`,
|
||||
analyticsName: "Add link",
|
||||
section: ActiveCollectionSection,
|
||||
icon: <LinkIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ getActiveModel, getActivePolicies }) =>
|
||||
!!getActiveModel(Collection)?.documents &&
|
||||
getActivePolicies(Collection).some(
|
||||
(policy) => policy.abilities.createDocument
|
||||
),
|
||||
perform: ({ getActiveModel, stores, t }) => {
|
||||
const collection = getActiveModel(Collection);
|
||||
if (collection) {
|
||||
openAddLinkDialog({ stores, t, collection, index: 0 });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const createTemplate = createInternalLinkAction({
|
||||
name: ({ t }) => t("New template"),
|
||||
analyticsName: "New template",
|
||||
|
||||
@@ -42,7 +42,6 @@ import {
|
||||
IndentIcon,
|
||||
InsertAboveIcon,
|
||||
InsertBelowIcon,
|
||||
LinkIcon,
|
||||
} from "outline-icons";
|
||||
import { toast } from "sonner";
|
||||
import { showPublicLinkCopiedToast } from "~/components/Sharing/components/toasts";
|
||||
@@ -56,9 +55,7 @@ import {
|
||||
} from "@shared/types";
|
||||
import { isMobile } from "@shared/utils/browser";
|
||||
import { Week } from "@shared/utils/time";
|
||||
import type Collection from "~/models/Collection";
|
||||
import type UserMembership from "~/models/UserMembership";
|
||||
import { openAddLinkDialog } from "~/components/Sidebar/components/LinkDialog";
|
||||
import Document from "~/models/Document";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import DocumentDelete from "~/scenes/DocumentDelete";
|
||||
@@ -261,7 +258,7 @@ export const createDraftDocument = createInternalLinkAction({
|
||||
* @param document - the document to find the index of.
|
||||
* @returns the index of the document among its siblings, or -1 if not found.
|
||||
*/
|
||||
function findDocumentSiblingIndex(
|
||||
export function findDocumentSiblingIndex(
|
||||
stores: ActionContext["stores"],
|
||||
document: {
|
||||
id: string;
|
||||
@@ -294,7 +291,7 @@ function findDocumentSiblingIndex(
|
||||
* @param document - the document to create a sibling of.
|
||||
* @returns true if the user can create a sibling.
|
||||
*/
|
||||
function canCreateSiblingDocument(
|
||||
export function canCreateSiblingDocument(
|
||||
stores: ActionContext["stores"],
|
||||
document: Document
|
||||
): boolean {
|
||||
@@ -510,142 +507,6 @@ export const starDocument = createAction({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns the active document and its collection when a link can be added
|
||||
* next to or inside it. Links live in the collection structure, so the
|
||||
* document must be published in a collection whose structure is loaded.
|
||||
*
|
||||
* @param stores - the root stores.
|
||||
* @param activeDocumentId - the id of the active document.
|
||||
* @returns the document and collection, or undefined.
|
||||
*/
|
||||
function getLinkLocation(
|
||||
stores: ActionContext["stores"],
|
||||
activeDocumentId: string | undefined
|
||||
): { document: Document; collection: Collection } | undefined {
|
||||
const document = activeDocumentId
|
||||
? stores.documents.get(activeDocumentId)
|
||||
: undefined;
|
||||
if (!document?.collectionId || document.isDraft || document.isDeleted) {
|
||||
return undefined;
|
||||
}
|
||||
const collection = stores.collections.get(document.collectionId);
|
||||
return collection?.documents ? { document, collection } : undefined;
|
||||
}
|
||||
|
||||
const canAddLinkBeside = (
|
||||
stores: ActionContext["stores"],
|
||||
activeDocumentId: string | undefined
|
||||
) => {
|
||||
const location = getLinkLocation(stores, activeDocumentId);
|
||||
return (
|
||||
!!location?.collection.isManualSort &&
|
||||
canCreateSiblingDocument(stores, location.document)
|
||||
);
|
||||
};
|
||||
|
||||
const canAddLinkInside = (
|
||||
stores: ActionContext["stores"],
|
||||
activeDocumentId: string | undefined
|
||||
) => {
|
||||
const location = getLinkLocation(stores, activeDocumentId);
|
||||
return (
|
||||
!!location &&
|
||||
stores.policies.abilities(location.document.id).createChildDocument
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an action handler that opens the dialog to add a link at the given
|
||||
* position relative to the active document.
|
||||
*
|
||||
* @param position - where to add the link.
|
||||
* @returns the action handler.
|
||||
*/
|
||||
const addLinkAt =
|
||||
(position: "above" | "below" | "inside") =>
|
||||
({ activeDocumentId, stores, t }: ActionContext) => {
|
||||
const location = getLinkLocation(stores, activeDocumentId);
|
||||
if (!location) {
|
||||
return;
|
||||
}
|
||||
const { collection, document } = location;
|
||||
const index = findDocumentSiblingIndex(stores, document);
|
||||
|
||||
openAddLinkDialog({
|
||||
stores,
|
||||
t,
|
||||
collection,
|
||||
...(position === "inside"
|
||||
? { parentDocumentId: document.id }
|
||||
: {
|
||||
parentDocumentId: document.parentDocumentId ?? undefined,
|
||||
index: position === "above" ? Math.max(0, index) : index + 1,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const addLinkAbove = createAction({
|
||||
name: ({ t, isMenu }) =>
|
||||
isMenu ? `${t("Above")}…` : `${t("Add link above")}…`,
|
||||
analyticsName: "Add link above",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <InsertAboveIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
canAddLinkBeside(stores, activeDocumentId),
|
||||
perform: addLinkAt("above"),
|
||||
});
|
||||
|
||||
const addLinkBelow = createAction({
|
||||
name: ({ t, isMenu }) =>
|
||||
isMenu ? `${t("Below")}…` : `${t("Add link below")}…`,
|
||||
analyticsName: "Add link below",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <InsertBelowIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
canAddLinkBeside(stores, activeDocumentId),
|
||||
perform: addLinkAt("below"),
|
||||
});
|
||||
|
||||
const addNestedLink = createAction({
|
||||
name: ({ t, isMenu }) =>
|
||||
isMenu ? `${t("Inside")}…` : `${t("Add nested link")}…`,
|
||||
analyticsName: "Add nested link",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <IndentIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
canAddLinkInside(stores, activeDocumentId),
|
||||
perform: addLinkAt("inside"),
|
||||
});
|
||||
|
||||
export const addLink = createActionWithChildren({
|
||||
name: ({ t }) => t("Add link"),
|
||||
analyticsName: "Add link",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <LinkIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
!!getLinkLocation(stores, activeDocumentId)?.collection.isManualSort &&
|
||||
(canAddLinkBeside(stores, activeDocumentId) ||
|
||||
canAddLinkInside(stores, activeDocumentId)),
|
||||
children: [addLinkAbove, addLinkBelow, addNestedLink],
|
||||
});
|
||||
|
||||
export const addLinkInAlphabeticalCollection = createAction({
|
||||
name: ({ t }) => `${t("Add link")}…`,
|
||||
analyticsName: "Add nested link",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <LinkIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
getLinkLocation(stores, activeDocumentId)?.collection.isManualSort ===
|
||||
false && canAddLinkInside(stores, activeDocumentId),
|
||||
perform: addLinkAt("inside"),
|
||||
});
|
||||
|
||||
export const unstarDocument = createAction({
|
||||
name: ({ t }) => t("Unstar"),
|
||||
analyticsName: "Unstar document",
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import {
|
||||
IndentIcon,
|
||||
InsertAboveIcon,
|
||||
InsertBelowIcon,
|
||||
LinkIcon,
|
||||
} from "outline-icons";
|
||||
import { createAction, createActionWithChildren } from "~/actions";
|
||||
import {
|
||||
ActiveCollectionSection,
|
||||
ActiveDocumentSection,
|
||||
} from "~/actions/sections";
|
||||
import { openAddLinkDialog } from "~/components/Sidebar/components/LinkDialog";
|
||||
import Collection from "~/models/Collection";
|
||||
import type Document from "~/models/Document";
|
||||
import type { ActionContext } from "~/types";
|
||||
import {
|
||||
canCreateSiblingDocument,
|
||||
findDocumentSiblingIndex,
|
||||
} from "./documents";
|
||||
|
||||
export const addLinkToCollection = createAction({
|
||||
name: ({ t }) => `${t("Add link")}…`,
|
||||
analyticsName: "Add link",
|
||||
section: ActiveCollectionSection,
|
||||
icon: <LinkIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ getActiveModel, getActivePolicies }) =>
|
||||
!!getActiveModel(Collection)?.documents &&
|
||||
getActivePolicies(Collection).some(
|
||||
(policy) => policy.abilities.createDocument
|
||||
),
|
||||
perform: ({ getActiveModel, stores, t }) => {
|
||||
const collection = getActiveModel(Collection);
|
||||
if (collection) {
|
||||
openAddLinkDialog({ stores, t, collection, index: 0 });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns the active document and its collection when a link can be added
|
||||
* next to or inside it. Links live in the collection structure, so the
|
||||
* document must be published in a collection whose structure is loaded.
|
||||
*
|
||||
* @param stores - the root stores.
|
||||
* @param activeDocumentId - the id of the active document.
|
||||
* @returns the document and collection, or undefined.
|
||||
*/
|
||||
function getLinkLocation(
|
||||
stores: ActionContext["stores"],
|
||||
activeDocumentId: string | undefined
|
||||
): { document: Document; collection: Collection } | undefined {
|
||||
const document = activeDocumentId
|
||||
? stores.documents.get(activeDocumentId)
|
||||
: undefined;
|
||||
if (!document?.collectionId || document.isDraft || document.isDeleted) {
|
||||
return undefined;
|
||||
}
|
||||
const collection = stores.collections.get(document.collectionId);
|
||||
return collection?.documents ? { document, collection } : undefined;
|
||||
}
|
||||
|
||||
const canAddLinkBeside = (
|
||||
stores: ActionContext["stores"],
|
||||
activeDocumentId: string | undefined
|
||||
) => {
|
||||
const location = getLinkLocation(stores, activeDocumentId);
|
||||
return (
|
||||
!!location?.collection.isManualSort &&
|
||||
canCreateSiblingDocument(stores, location.document)
|
||||
);
|
||||
};
|
||||
|
||||
const canAddLinkInside = (
|
||||
stores: ActionContext["stores"],
|
||||
activeDocumentId: string | undefined
|
||||
) => {
|
||||
const location = getLinkLocation(stores, activeDocumentId);
|
||||
return (
|
||||
!!location &&
|
||||
stores.policies.abilities(location.document.id).createChildDocument
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an action handler that opens the dialog to add a link at the given
|
||||
* position relative to the active document.
|
||||
*
|
||||
* @param position - where to add the link.
|
||||
* @returns the action handler.
|
||||
*/
|
||||
const addLinkAt =
|
||||
(position: "above" | "below" | "inside") =>
|
||||
({ activeDocumentId, stores, t }: ActionContext) => {
|
||||
const location = getLinkLocation(stores, activeDocumentId);
|
||||
if (!location) {
|
||||
return;
|
||||
}
|
||||
const { collection, document } = location;
|
||||
const index = findDocumentSiblingIndex(stores, document);
|
||||
|
||||
openAddLinkDialog({
|
||||
stores,
|
||||
t,
|
||||
collection,
|
||||
...(position === "inside"
|
||||
? { parentDocumentId: document.id }
|
||||
: {
|
||||
parentDocumentId: document.parentDocumentId ?? undefined,
|
||||
index: position === "above" ? Math.max(0, index) : index + 1,
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
const addLinkAbove = createAction({
|
||||
name: ({ t, isMenu }) =>
|
||||
isMenu ? `${t("Above")}…` : `${t("Add link above")}…`,
|
||||
analyticsName: "Add link above",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <InsertAboveIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
canAddLinkBeside(stores, activeDocumentId),
|
||||
perform: addLinkAt("above"),
|
||||
});
|
||||
|
||||
const addLinkBelow = createAction({
|
||||
name: ({ t, isMenu }) =>
|
||||
isMenu ? `${t("Below")}…` : `${t("Add link below")}…`,
|
||||
analyticsName: "Add link below",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <InsertBelowIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
canAddLinkBeside(stores, activeDocumentId),
|
||||
perform: addLinkAt("below"),
|
||||
});
|
||||
|
||||
const addNestedLink = createAction({
|
||||
name: ({ t, isMenu }) =>
|
||||
isMenu ? `${t("Inside")}…` : `${t("Add nested link")}…`,
|
||||
analyticsName: "Add nested link",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <IndentIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
canAddLinkInside(stores, activeDocumentId),
|
||||
perform: addLinkAt("inside"),
|
||||
});
|
||||
|
||||
export const addLink = createActionWithChildren({
|
||||
name: ({ t }) => t("Add link"),
|
||||
analyticsName: "Add link",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <LinkIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
!!getLinkLocation(stores, activeDocumentId)?.collection.isManualSort &&
|
||||
(canAddLinkBeside(stores, activeDocumentId) ||
|
||||
canAddLinkInside(stores, activeDocumentId)),
|
||||
children: [addLinkAbove, addLinkBelow, addNestedLink],
|
||||
});
|
||||
|
||||
export const addLinkInAlphabeticalCollection = createAction({
|
||||
name: ({ t }) => `${t("Add link")}…`,
|
||||
analyticsName: "Add nested link",
|
||||
section: ActiveDocumentSection,
|
||||
icon: <LinkIcon />,
|
||||
keywords: "url bookmark",
|
||||
visible: ({ activeDocumentId, stores }) =>
|
||||
getLinkLocation(stores, activeDocumentId)?.collection.isManualSort ===
|
||||
false && canAddLinkInside(stores, activeDocumentId),
|
||||
perform: addLinkAt("inside"),
|
||||
});
|
||||
@@ -5,7 +5,6 @@ import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import useShare from "@shared/hooks/useShare";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { flattenTree } from "@shared/utils/tree";
|
||||
import { createAction } from "~/actions";
|
||||
import { RecentSection, SearchResultsSection } from "~/actions/sections";
|
||||
@@ -29,7 +28,8 @@ const serverSearchDelay = 350;
|
||||
* document for document shares – only the latter are searchable.
|
||||
*/
|
||||
const isDocumentNode = (node: NavigationNode) =>
|
||||
node.type !== NavigationNodeType.Collection && !isLinkNode(node);
|
||||
node.type !== NavigationNodeType.Collection &&
|
||||
node.type !== NavigationNodeType.Link;
|
||||
|
||||
/**
|
||||
* Registers search result actions in the command bar scoped to a public share.
|
||||
|
||||
@@ -116,8 +116,6 @@ function EditableTitle({
|
||||
setValue(value);
|
||||
setIsEditing(true);
|
||||
|
||||
// The error is shown here, callers are event handlers that cannot
|
||||
// handle it.
|
||||
toast.error(errToString(error));
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
|
||||
@@ -4,8 +4,8 @@ import { noop } from "es-toolkit/compat";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import scrollIntoView from "scroll-into-view-if-needed";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { isLinkNode, sortNavigationNodes } from "@shared/utils/collections";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import { sortNavigationNodes } from "@shared/utils/collections";
|
||||
import {
|
||||
flattenExpandedTree,
|
||||
type FlattenedTreeNode,
|
||||
@@ -214,7 +214,7 @@ export const DocumentTree = observer(function DocumentTree({
|
||||
const getNavigationItems = React.useCallback(
|
||||
() =>
|
||||
rows
|
||||
.filter((row) => !isLinkNode(row.node))
|
||||
.filter((row) => row.node.type !== NavigationNodeType.Link)
|
||||
.map((row) => ({
|
||||
id: row.node.id,
|
||||
url: row.node.url,
|
||||
@@ -255,7 +255,7 @@ export const DocumentTree = observer(function DocumentTree({
|
||||
<React.Fragment key={item.key}>
|
||||
{gap > 0 && <div style={{ height: gap }} />}
|
||||
<div data-index={item.index} ref={virtualizer.measureElement}>
|
||||
{isLinkNode(row.node) ? (
|
||||
{row.node.type === NavigationNodeType.Link ? (
|
||||
<ExternalLink
|
||||
node={row.node}
|
||||
collection={collection}
|
||||
|
||||
@@ -2,8 +2,7 @@ import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Icon from "@shared/components/Icon";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import type Collection from "~/models/Collection";
|
||||
import type Document from "~/models/Document";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -157,7 +156,7 @@ const ObservedDocumentLink = observer(DocumentLink);
|
||||
* A row in the sidebar of a public share, for a document or a link.
|
||||
*/
|
||||
export function SharedDocumentLink(props: Props) {
|
||||
return isLinkNode(props.node) ? (
|
||||
return props.node.type === NavigationNodeType.Link ? (
|
||||
<ExternalLink node={props.node} depth={props.depth} />
|
||||
) : (
|
||||
<ObservedDocumentLink {...props} />
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import { useActiveSidebarContext } from "~/hooks/useActiveSidebarContext";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import useStores from "~/hooks/useStores";
|
||||
@@ -169,7 +168,7 @@ function lastDocumentDescendant(
|
||||
): NavigationNode | undefined {
|
||||
for (let i = nodes.length - 1; i >= 0; i--) {
|
||||
const node = nodes[i];
|
||||
if (!isLinkNode(node)) {
|
||||
if (node.type !== NavigationNodeType.Link) {
|
||||
return lastDocumentDescendant(node.children) ?? node;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ import {
|
||||
subscribeCollection,
|
||||
unsubscribeCollection,
|
||||
createDocument,
|
||||
addLinkToCollection,
|
||||
exportCollection,
|
||||
importDocument,
|
||||
openCollectionInSplit,
|
||||
sortCollection,
|
||||
} from "~/actions/definitions/collections";
|
||||
import { renameActionFactory } from "~/actions/definitions/common";
|
||||
import { addLinkToCollection } from "~/actions/definitions/links";
|
||||
import { ActiveCollectionSection } from "~/actions/sections";
|
||||
|
||||
type Props = {
|
||||
|
||||
@@ -40,7 +40,6 @@ function getCollectionTree(collection: Collection): NavigationNode {
|
||||
};
|
||||
|
||||
root.children = annotateNodes(
|
||||
// Links are not documents, so they cannot be a destination or be selected.
|
||||
collection.documentNodes ?? [],
|
||||
collection.sort,
|
||||
root
|
||||
|
||||
@@ -13,8 +13,6 @@ import {
|
||||
shareDocument,
|
||||
createNewDocument,
|
||||
createNewDocumentInAlphabeticalCollection,
|
||||
addLink,
|
||||
addLinkInAlphabeticalCollection,
|
||||
importDocument,
|
||||
createTemplateFromDocument,
|
||||
duplicateDocument,
|
||||
@@ -39,6 +37,10 @@ import {
|
||||
toggleDocumentStats,
|
||||
} from "~/actions/definitions/documents";
|
||||
import { renameActionFactory } from "~/actions/definitions/common";
|
||||
import {
|
||||
addLink,
|
||||
addLinkInAlphabeticalCollection,
|
||||
} from "~/actions/definitions/links";
|
||||
import { ActiveDocumentSection } from "~/actions/sections";
|
||||
import useMobile from "./useMobile";
|
||||
import type Template from "~/models/Template";
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
import {
|
||||
filterNavigationNodes,
|
||||
insertNavigationNode,
|
||||
isLinkNode,
|
||||
moveNavigationNode,
|
||||
sortNavigationNodes,
|
||||
updateNavigationNode,
|
||||
@@ -206,7 +205,10 @@ export default class Collection extends ParanoidModel {
|
||||
@computed
|
||||
get documentNodes(): NavigationNode[] | undefined {
|
||||
return this.documents
|
||||
? filterNavigationNodes(this.documents, (node) => !isLinkNode(node))
|
||||
? filterNavigationNodes(
|
||||
this.documents,
|
||||
(node) => node.type !== NavigationNodeType.Link
|
||||
)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -534,7 +536,7 @@ export default class Collection extends ParanoidModel {
|
||||
*/
|
||||
getChildDocumentsForDocument(documentId: string) {
|
||||
return this.getChildrenForDocument(documentId).filter(
|
||||
(node) => !isLinkNode(node)
|
||||
(node) => node.type !== NavigationNodeType.Link
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
import { DocumentPreferenceDefaults } from "@shared/constants";
|
||||
import { ProsemirrorDataHelper } from "@shared/utils/ProsemirrorDataHelper";
|
||||
import Storage from "@shared/utils/Storage";
|
||||
import { isLinkNode } from "@shared/utils/collections";
|
||||
import { isRTL } from "@shared/utils/rtl";
|
||||
import type DocumentsStore from "~/stores/DocumentsStore";
|
||||
import User from "~/models/User";
|
||||
@@ -737,7 +736,7 @@ export default class Document extends ArchivableModel implements Searchable {
|
||||
collection?.getChildrenForDocument(this.id) ??
|
||||
membership?.getChildrenForDocument(this.id) ??
|
||||
[]
|
||||
).filter((node) => !isLinkNode(node));
|
||||
).filter((node) => node.type !== NavigationNodeType.Link);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,8 +16,8 @@ import ReferenceListItem, {
|
||||
NewChildReferenceListItem,
|
||||
} from "./ReferenceListItem";
|
||||
import useShare from "@shared/hooks/useShare";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import { findNavigationNode, isLinkNode } from "@shared/utils/collections";
|
||||
import { NavigationNodeType, type NavigationNode } from "@shared/types";
|
||||
import { findNavigationNode } from "@shared/utils/collections";
|
||||
import { flattenTree } from "@shared/utils/tree";
|
||||
|
||||
type Props = {
|
||||
@@ -171,7 +171,7 @@ function useChildren(
|
||||
|
||||
const children =
|
||||
findNavigationNode([sharedTree], document.id)?.node.children ?? [];
|
||||
return children.filter((node) => !isLinkNode(node));
|
||||
return children.filter((node) => node.type !== NavigationNodeType.Link);
|
||||
}, [document.id, document.children, sharedTree]);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user