Skip to content

Commit d901bab

Browse files
author
Jakob Schlanstedt
committed
refactor(url -> link): let link refer to url and path.
before there was polysemy in word url that is now resolved by making link hypernym to url and path.
1 parent 12f47e1 commit d901bab

File tree

19 files changed

+52
-51
lines changed

19 files changed

+52
-51
lines changed

apps/client/src/components/app_context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import TouchBarComponent from "./touch_bar.js";
2828
import type { CKTextEditor } from "@triliumnext/ckeditor5";
2929
import type CodeMirror from "@triliumnext/codemirror";
3030
import { StartupChecks } from "./startup_checks.js";
31-
import type { CreateNoteOpts, CreateNoteWithUrlOpts } from "../services/note_create.js";
31+
import type { CreateNoteOpts, CreateNoteWithLinkOpts } from "../services/note_create.js";
3232
import { ColumnComponent } from "tabulator-tables";
3333
import { ChooseNoteTypeCallback } from "../widgets/dialogs/note_type_chooser.jsx";
3434
import type RootContainer from "../widgets/containers/root_container.js";
@@ -357,7 +357,7 @@ export type CommandMappings = {
357357

358358
// Table view
359359
addNewRow: CommandData & {
360-
customOpts?: CreateNoteWithUrlOpts;
360+
customOpts?: CreateNoteWithLinkOpts;
361361
};
362362
addNewTableColumn: CommandData & {
363363
columnToEdit?: ColumnComponent;

apps/client/src/components/main_tree_executors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class MainTreeExecutors extends Component {
5151
await noteCreateService.createNote(
5252
{
5353
target: "into",
54-
parentNoteUrl: activeNoteContext.notePath,
54+
parentNoteLink: activeNoteContext.notePath,
5555
isProtected: activeNoteContext.note.isProtected,
5656
saveSelection: false,
5757
promptForType: false,
@@ -80,7 +80,7 @@ export default class MainTreeExecutors extends Component {
8080
await noteCreateService.createNote(
8181
{
8282
target: "after",
83-
parentNoteUrl: parentNotePath,
83+
parentNoteLink: parentNotePath,
8484
targetBranchId: node.data.branchId,
8585
isProtected: isProtected,
8686
saveSelection: false

apps/client/src/components/root_command_executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class RootCommandExecutor extends Component {
4646
}
4747

4848
async searchInSubtreeCommand({ notePath }: CommandListenerData<"searchInSubtree">) {
49-
const noteId = treeService.getNoteIdFromUrl(notePath);
49+
const noteId = treeService.getNoteIdFromLink(notePath);
5050

5151
this.searchNotesCommand({ ancestorNoteId: noteId });
5252
}
@@ -235,7 +235,7 @@ export default class RootCommandExecutor extends Component {
235235

236236
const result = await noteCreateService.createNote(
237237
{
238-
parentNoteUrl: rootNoteId,
238+
parentNoteLink: rootNoteId,
239239
target: "into",
240240
title: "New AI Chat",
241241
type: "aiChat",

apps/client/src/components/tab_manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export default class TabManager extends Component {
7474

7575
// preload all notes at once
7676
await froca.getNotes([...noteContextsToOpen.flatMap((tab: NoteContextState) =>
77-
[treeService.getNoteIdFromUrl(tab.notePath), tab.hoistedNoteId])], true);
77+
[treeService.getNoteIdFromLink(tab.notePath), tab.hoistedNoteId])], true);
7878

7979
const filteredNoteContexts = noteContextsToOpen.filter((openTab: NoteContextState) => {
80-
const noteId = treeService.getNoteIdFromUrl(openTab.notePath);
80+
const noteId = treeService.getNoteIdFromLink(openTab.notePath);
8181
if (!noteId || !(noteId in froca.notes)) {
8282
// note doesn't exist so don't try to open tab for it
8383
return false;

apps/client/src/menus/tree_context_menu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
277277
noteCreateService.createNote(
278278
{
279279
target: "after",
280-
parentNoteUrl: parentNotePath,
280+
parentNoteLink: parentNotePath,
281281
targetBranchId: this.node.data.branchId,
282282
type: type,
283283
isProtected: isProtected,
@@ -291,7 +291,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
291291
noteCreateService.createNote(
292292
{
293293
target: "into",
294-
parentNoteUrl: parentNotePath,
294+
parentNoteLink: parentNotePath,
295295
type: type,
296296
isProtected: this.node.data.isProtected,
297297
templateNoteId: templateNoteId,

apps/client/src/services/content_renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HT
127127
renderMathInElement($renderedContent[0], { trust: true });
128128
}
129129

130-
const getNoteIdFromLink = (el: HTMLElement) => treeService.getNoteIdFromUrl($(el).attr("href") || "");
130+
const getNoteIdFromLink = (el: HTMLElement) => treeService.getNoteIdFromLink($(el).attr("href") || "");
131131
const referenceLinks = $renderedContent.find("a.reference-link");
132132
const noteIdsToPrefetch = referenceLinks.map((i, el) => getNoteIdFromLink(el));
133133
await froca.getNotes(noteIdsToPrefetch);

apps/client/src/services/hoisted_note.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function checkNoteAccess(notePath: string, noteContext: NoteContext) {
5050
const hoistedNoteId = noteContext.hoistedNoteId;
5151

5252
if (!resolvedNotePath.includes(hoistedNoteId) && (!resolvedNotePath.includes("_hidden") || resolvedNotePath.includes("_lbBookmarks"))) {
53-
const noteId = treeService.getNoteIdFromUrl(resolvedNotePath);
53+
const noteId = treeService.getNoteIdFromLink(resolvedNotePath);
5454
if (!noteId) {
5555
return false;
5656
}

apps/client/src/services/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export function parseNavigationStateFromUrl(url: string | undefined) {
256256

257257
return {
258258
notePath,
259-
noteId: treeService.getNoteIdFromUrl(notePath),
259+
noteId: treeService.getNoteIdFromLink(notePath),
260260
ntxId,
261261
hoistedNoteId,
262262
viewScope,

apps/client/src/services/note_create.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,26 @@ type CreateNoteBase = {
8484
* Serves as a base for "into", "before", and "after" variants,
8585
* sharing common URL-related fields.
8686
*/
87-
export type CreateNoteWithUrlOpts =
87+
export type CreateNoteWithLinkOpts =
8888
| (CreateNoteBase & {
8989
target: "into";
90-
parentNoteUrl?: string;
90+
parentNoteLink?: string;
9191
// No branch ID needed for "into"
9292
})
9393
| (CreateNoteBase & {
9494
target: "before" | "after";
95-
parentNoteUrl?: string;
95+
// Either an Url or a Path
96+
parentNoteLink?: string;
9697
// Required for "before"/"after"
9798
targetBranchId: string;
9899
});
99100

100101
export type CreateNoteIntoDefaultOpts = CreateNoteBase & {
101102
target: "default";
102-
parentNoteUrl?: never;
103+
parentNoteLink?: never;
103104
};
104105

105-
export type CreateNoteOpts = CreateNoteWithUrlOpts | CreateNoteIntoDefaultOpts;
106+
export type CreateNoteOpts = CreateNoteWithLinkOpts | CreateNoteIntoDefaultOpts;
106107

107108
interface Response {
108109
// TODO: Deduplicate with server once we have client/server architecture.
@@ -139,7 +140,7 @@ async function createNote(
139140
case "into":
140141
case "before":
141142
case "after":
142-
return createNoteWithUrl(resolvedOptions);
143+
return createNoteWithLink(resolvedOptions);
143144
}
144145
}
145146

@@ -148,7 +149,7 @@ async function createNoteFromAction(
148149
action: CreateNoteAction,
149150
promptForType: boolean,
150151
title: string | undefined,
151-
parentNoteUrl: string | undefined,
152+
parentNoteLink: string | undefined,
152153
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
153154
switch (action) {
154155
case CreateNoteAction.CreateNote: {
@@ -174,15 +175,15 @@ async function createNoteFromAction(
174175
return resp;
175176
}
176177
case CreateNoteAction.CreateChildNote: {
177-
if (!parentNoteUrl) {
178+
if (!parentNoteLink) {
178179
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
179180
return { note: null, branch: undefined };
180181
}
181182

182183
const resp = await createNote(
183184
{
184185
target: "into",
185-
parentNoteUrl,
186+
parentNoteLink,
186187
title,
187188
activate: true,
188189
promptForType: true,
@@ -191,14 +192,14 @@ async function createNoteFromAction(
191192
return resp
192193
}
193194
case CreateNoteAction.CreateAndLinkChildNote: {
194-
if (!parentNoteUrl) {
195+
if (!parentNoteLink) {
195196
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
196197
return { note: null, branch: undefined };
197198
}
198199
const resp = await createNote(
199200
{
200201
target: "into",
201-
parentNoteUrl: parentNoteUrl,
202+
parentNoteLink: parentNoteLink,
202203
title,
203204
activate: false,
204205
promptForType: promptForType,
@@ -233,7 +234,7 @@ async function promptForType(
233234
resolvedOptions = {
234235
...resolvedOptions,
235236
target: "into",
236-
parentNoteUrl: notePath,
237+
parentNoteLink: notePath,
237238
};
238239
}
239240

@@ -247,8 +248,8 @@ async function promptForType(
247248
* @param options - Note creation options
248249
* @returns A promise resolving with the created note and its branch.
249250
*/
250-
async function createNoteWithUrl(
251-
options: CreateNoteWithUrlOpts
251+
async function createNoteWithLink(
252+
options: CreateNoteWithLinkOpts
252253
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
253254
options = Object.assign(
254255
{
@@ -273,8 +274,8 @@ async function createNoteWithUrl(
273274
[options.title, options.content] = parseSelectedHtml(options.textEditor.getSelectedHtml());
274275
}
275276

276-
const parentNoteUrl = options.parentNoteUrl;
277-
const parentNoteId = treeService.getNoteIdFromUrl(parentNoteUrl);
277+
const parentNoteLink = options.parentNoteLink;
278+
const parentNoteId = treeService.getNoteIdFromLink(parentNoteLink);
278279

279280
if (options.type === "mermaid" && !options.content && !options.templateNoteId) {
280281
options.content = `graph TD;
@@ -348,11 +349,11 @@ async function createNoteIntoDefaultLocation(
348349
inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable();
349350
}
350351

351-
const result = await createNoteWithUrl(
352+
const result = await createNoteWithLink(
352353
{
353354
...options,
354355
target: "into",
355-
parentNoteUrl: inboxNote.noteId,
356+
parentNoteLink: inboxNote.noteId,
356357
}
357358
);
358359

@@ -385,7 +386,7 @@ function parseSelectedHtml(selectedHtml: string) {
385386
}
386387

387388
async function duplicateSubtree(noteId: string, parentNotePath: string) {
388-
const parentNoteId = treeService.getNoteIdFromUrl(parentNotePath);
389+
const parentNoteId = treeService.getNoteIdFromLink(parentNotePath);
389390
const { note } = await server.post<DuplicateResponse>(`notes/${noteId}/duplicate/${parentNoteId}`);
390391

391392
await ws.waitForMaxKnownEntityChangeId();

apps/client/src/services/tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root
9292
if (effectivePathSegments.includes(hoistedNoteId)) {
9393
return effectivePathSegments;
9494
} else {
95-
const noteId = getNoteIdFromUrl(notePath);
95+
const noteId = getNoteIdFromLink(notePath);
9696
if (!noteId) {
9797
throw new Error(`Unable to find note with ID: ${noteId}.`);
9898
}
@@ -129,7 +129,7 @@ function getParentProtectedStatus(node: Fancytree.FancytreeNode) {
129129
return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected;
130130
}
131131

132-
function getNoteIdFromUrl(urlOrNotePath: string | null | undefined) {
132+
function getNoteIdFromLink(urlOrNotePath: string | null | undefined) {
133133
if (!urlOrNotePath) {
134134
return null;
135135
}
@@ -306,7 +306,7 @@ export default {
306306
getParentProtectedStatus,
307307
getNotePath,
308308
getNotePathTitleComponents,
309-
getNoteIdFromUrl,
309+
getNoteIdFromLink,
310310
getNoteIdAndParentIdFromUrl,
311311
getBranchIdFromUrl,
312312
getNoteTitle,

0 commit comments

Comments
 (0)