{gap > 0 && }
- {isLinkNode(row.node) ? (
+ {row.node.type === NavigationNodeType.Link ? (
) : (
diff --git a/app/components/Sidebar/components/SidebarNavigation.tsx b/app/components/Sidebar/components/SidebarNavigation.tsx
index d9b5eefb85..d7dd85d6ac 100644
--- a/app/components/Sidebar/components/SidebarNavigation.tsx
+++ b/app/components/Sidebar/components/SidebarNavigation.tsx
@@ -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;
}
}
diff --git a/app/hooks/useCollectionMenuAction.tsx b/app/hooks/useCollectionMenuAction.tsx
index be361c3e27..45a2d8243a 100644
--- a/app/hooks/useCollectionMenuAction.tsx
+++ b/app/hooks/useCollectionMenuAction.tsx
@@ -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 = {
diff --git a/app/hooks/useCollectionTrees.ts b/app/hooks/useCollectionTrees.ts
index 2c9d723938..9dc5479e1b 100644
--- a/app/hooks/useCollectionTrees.ts
+++ b/app/hooks/useCollectionTrees.ts
@@ -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
diff --git a/app/hooks/useDocumentMenuAction.tsx b/app/hooks/useDocumentMenuAction.tsx
index e943e46c70..eefc1e0928 100644
--- a/app/hooks/useDocumentMenuAction.tsx
+++ b/app/hooks/useDocumentMenuAction.tsx
@@ -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";
diff --git a/app/models/Collection.ts b/app/models/Collection.ts
index 9d55acd325..3ba5ccb3db 100644
--- a/app/models/Collection.ts
+++ b/app/models/Collection.ts
@@ -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
);
}
diff --git a/app/models/Document.ts b/app/models/Document.ts
index 50cdd647a4..1bf115d44d 100644
--- a/app/models/Document.ts
+++ b/app/models/Document.ts
@@ -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);
}
/**
diff --git a/app/scenes/Document/components/References.tsx b/app/scenes/Document/components/References.tsx
index ffe9acd20c..61ffe0294f 100644
--- a/app/scenes/Document/components/References.tsx
+++ b/app/scenes/Document/components/References.tsx
@@ -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]);
}
diff --git a/server/models/Collection.ts b/server/models/Collection.ts
index 55dfb2a231..c014fdc530 100644
--- a/server/models/Collection.ts
+++ b/server/models/Collection.ts
@@ -55,7 +55,6 @@ import { UrlHelper } from "@shared/utils/UrlHelper";
import {
findNavigationNode,
insertNavigationNode,
- isLinkNode,
moveNavigationNode,
removeNavigationNode,
updateNavigationNode,
@@ -1258,7 +1257,7 @@ class Collection extends ParanoidModel<
const allDocumentIds: string[] = [];
const loopChildren = (node: NavigationNode) => {
- if (isLinkNode(node)) {
+ if (node.type === NavigationNodeType.Link) {
return;
}
allDocumentIds.push(node.id);
@@ -1281,7 +1280,7 @@ class Collection extends ParanoidModel<
linkId: string
): { node: NavigationNode; parentDocumentId?: string } | undefined => {
const result = findNavigationNode(this.documentStructure ?? [], linkId);
- return result && isLinkNode(result.node)
+ return result && result.node.type === NavigationNodeType.Link
? { node: result.node, parentDocumentId: result.parentId }
: undefined;
};
diff --git a/server/presenters/navigationNode.ts b/server/presenters/navigationNode.ts
index 96517fd477..3e37a1c7dd 100644
--- a/server/presenters/navigationNode.ts
+++ b/server/presenters/navigationNode.ts
@@ -1,7 +1,6 @@
import type { Team } from "@server/models";
import type { NavigationNode } from "@shared/types";
import { NavigationNodeType } from "@shared/types";
-import { isLinkNode } from "@shared/utils/collections";
export interface PresentedNavigationNode {
id: string;
@@ -30,7 +29,10 @@ export default function presentNavigationNode(
url: /^https?:\/\//.test(node.url)
? node.url
: new URL(node.url, team.url).href,
- type: isLinkNode(node) ? NavigationNodeType.Link : undefined,
+ type:
+ node.type === NavigationNodeType.Link
+ ? NavigationNodeType.Link
+ : undefined,
children: (node.children ?? []).map((child) =>
presentNavigationNode(team, child)
),
diff --git a/server/queues/tasks/ExportDocumentTreeTask.ts b/server/queues/tasks/ExportDocumentTreeTask.ts
index 3bb134b09a..a97a962170 100644
--- a/server/queues/tasks/ExportDocumentTreeTask.ts
+++ b/server/queues/tasks/ExportDocumentTreeTask.ts
@@ -3,8 +3,7 @@ import { escapeRegExp } from "es-toolkit/compat";
import type { ZipFile } from "yazl";
import { errToString } from "@shared/utils/error";
import type { NavigationNode } from "@shared/types";
-import { FileOperationFormat } from "@shared/types";
-import { isLinkNode } from "@shared/utils/collections";
+import { FileOperationFormat, NavigationNodeType } from "@shared/types";
import Logger from "@server/logging/Logger";
import type { Collection } from "@server/models";
import Attachment from "@server/models/Attachment";
@@ -440,7 +439,7 @@ export default abstract class ExportDocumentTreeTask extends ExportTask {
format: FileOperationFormat
) {
for (const node of nodes) {
- if (isLinkNode(node)) {
+ if (node.type === NavigationNodeType.Link) {
continue;
}
diff --git a/server/queues/tasks/ExportJSONTask.ts b/server/queues/tasks/ExportJSONTask.ts
index ba8b0b7662..9189c7c486 100644
--- a/server/queues/tasks/ExportJSONTask.ts
+++ b/server/queues/tasks/ExportJSONTask.ts
@@ -1,7 +1,6 @@
import type { ZipFile } from "yazl";
import { omit } from "es-toolkit/compat";
-import type { NavigationNode } from "@shared/types";
-import { isLinkNode } from "@shared/utils/collections";
+import { NavigationNodeType, type NavigationNode } from "@shared/types";
import env from "@server/env";
import type { Collection, FileOperation } from "@server/models";
import { Attachment, Document } from "@server/models";
@@ -99,7 +98,7 @@ export default class ExportJSONTask extends ExportTask {
const addDocumentTree = async (nodes: NavigationNode[]) => {
for (const node of nodes) {
- if (isLinkNode(node)) {
+ if (node.type === NavigationNodeType.Link) {
continue;
}
diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts
index 49c08b48ea..ad40cfcb62 100644
--- a/server/routes/api/documents/documents.ts
+++ b/server/routes/api/documents/documents.ts
@@ -11,7 +11,7 @@ import type { Filter } from "@shared/helpers/FilterHelper";
import { Op, Sequelize } from "sequelize";
import { randomUUID } from "node:crypto";
import type { DirectionFilter, SortFilter } from "@shared/types";
-import { type NavigationNode } from "@shared/types";
+import { NavigationNodeType, type NavigationNode } from "@shared/types";
import {
DocumentPermission,
ExportContentType,
@@ -19,7 +19,6 @@ import {
StatusFilter,
UserRole,
} from "@shared/types";
-import { isLinkNode } from "@shared/utils/collections";
import { subtractDate } from "@shared/utils/date";
import slugify from "@server/utils/slugify";
import { Day } from "@shared/utils/time";
@@ -291,7 +290,7 @@ router.post(
});
authorize(user, "readDocument", collection);
documentIds = (collection.documentStructure || [])
- .filter((node) => !isLinkNode(node))
+ .filter((node) => node.type !== NavigationNodeType.Link)
.slice(offset, offset + limit)
.map((node) => node.id);
where[Op.and].push({ id: documentIds });
diff --git a/server/utils/sitemap.ts b/server/utils/sitemap.ts
index bf6b8b804a..cccb886715 100644
--- a/server/utils/sitemap.ts
+++ b/server/utils/sitemap.ts
@@ -1,6 +1,5 @@
import { escape } from "es-toolkit/compat";
-import type { NavigationNode } from "@shared/types";
-import { isLinkNode } from "@shared/utils/collections";
+import { NavigationNodeType, type NavigationNode } from "@shared/types";
/**
* Converts a navigation tree to a sitemap XML string, by traversing the nodes.
@@ -17,7 +16,7 @@ export function navigationNodeToSitemap(
function collectUrls(node: NavigationNode, urls: string[]) {
// Links point to other pages, which are not part of the share.
- if (isLinkNode(node)) {
+ if (node.type === NavigationNodeType.Link) {
return;
}
urls.push(`${baseUrl}${node.url}`);
diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json
index 3381718bc6..673e5a741e 100644
--- a/shared/i18n/locales/en_US/translation.json
+++ b/shared/i18n/locales/en_US/translation.json
@@ -40,7 +40,6 @@
"Export": "Export",
"Export collection": "Export collection",
"New document": "New document",
- "Add link": "Add link",
"New template": "New template",
"Delete comment": "Delete comment",
"Mark as resolved": "Mark as resolved",
@@ -70,9 +69,6 @@
"New document below": "New document below",
"{{ count }} document starred": "{{ count }} document starred",
"{{ count }} document starred_plural": "{{ count }} documents starred",
- "Add link above": "Add link above",
- "Add link below": "Add link below",
- "Add nested link": "Add nested link",
"{{ count }} document unstarred": "{{ count }} document unstarred",
"{{ count }} document unstarred_plural": "{{ count }} documents unstarred",
"Publish": "Publish",
@@ -182,6 +178,10 @@
"{{userName}} was removed from the group": "{{userName}} was removed from the group",
"Disconnect": "Disconnect",
"Disconnect analytics": "Disconnect analytics",
+ "Add link": "Add link",
+ "Add link above": "Add link above",
+ "Add link below": "Add link below",
+ "Add nested link": "Add nested link",
"Home": "Home",
"Drafts": "Drafts",
"Search": "Search",
diff --git a/shared/utils/collections.test.ts b/shared/utils/collections.test.ts
index ca12ca034b..72fa2b2de4 100644
--- a/shared/utils/collections.test.ts
+++ b/shared/utils/collections.test.ts
@@ -3,7 +3,6 @@ import {
filterNavigationNodes,
findNavigationNode,
insertNavigationNode,
- isLinkNode,
moveNavigationNode,
removeNavigationNode,
updateNavigationNode,
@@ -143,13 +142,18 @@ describe("removeNavigationNode", () => {
describe("filterNavigationNodes", () => {
it("should remove links at every depth and keep unchanged nodes", () => {
const tree = [node("a", [node("a1"), link("l2")]), link("l1"), node("b")];
- const result = filterNavigationNodes(tree, (n) => !isLinkNode(n));
+ const result = filterNavigationNodes(
+ tree,
+ (n) => n.type !== NavigationNodeType.Link
+ );
expect(ids(result)).toEqual([["a", ["a1"]], "b"]);
expect(result[1]).toBe(tree[2]);
});
it("should return the same array when nothing is removed", () => {
const tree = [node("a", [node("a1")])];
- expect(filterNavigationNodes(tree, (n) => !isLinkNode(n))).toBe(tree);
+ expect(
+ filterNavigationNodes(tree, (n) => n.type !== NavigationNodeType.Link)
+ ).toBe(tree);
});
});
diff --git a/shared/utils/collections.ts b/shared/utils/collections.ts
index 78d631ee16..b1928b301b 100644
--- a/shared/utils/collections.ts
+++ b/shared/utils/collections.ts
@@ -1,4 +1,4 @@
-import { NavigationNodeType, type NavigationNode } from "../types";
+import type { NavigationNode } from "../types";
import shallowEqual from "./shallowEqual";
import naturalSort from "./naturalSort";
@@ -7,16 +7,6 @@ type Sort = {
direction: "asc" | "desc";
};
-/**
- * Returns whether the node is a link to an external location, rather than a
- * document.
- *
- * @param node The navigation node to check.
- * @returns true if the node is a link.
- */
-export const isLinkNode = (node: Pick): boolean =>
- node.type === NavigationNodeType.Link;
-
/**
* Inserts a node into a navigation tree.
*