Skip to content

Commit 57fc867

Browse files
Jakob Schlanstedtwerererer
authored andcommitted
fix(note_autocomplete): fix attributes not linking
1 parent 89c1415 commit 57fc867

File tree

3 files changed

+70
-69
lines changed

3 files changed

+70
-69
lines changed

apps/client/src/services/note_autocomplete.ts

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -463,65 +463,103 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
463463

464464
// TODO: Types fail due to "autocomplete:selected" not being registered in type definitions.
465465
($el as any).on("autocomplete:selected", async (event: Event, suggestion: Suggestion) => {
466+
$el.setSelectedNotePath(suggestion.notePath);
467+
$el.setSelectedExternalLink(null);
468+
$el.autocomplete("val", suggestion.noteTitle);
469+
466470
switch (suggestion.action) {
467471
case SuggestionAction.Command: {
468-
$el.autocomplete("close");
469-
$el.trigger("autocomplete:commandselected", [suggestion]);
470472
break;
471473
}
472474

473475
case SuggestionAction.ExternalLink: {
474-
$el.setSelectedNotePath(null);
475-
$el.setSelectedExternalLink(suggestion.externalLink);
476-
$el.autocomplete("val", suggestion.externalLink);
477-
$el.autocomplete("close");
478-
$el.trigger("autocomplete:externallinkselected", [suggestion]);
479476
break;
480477
}
481478

482-
case SuggestionAction.CreateNoteIntoInbox:
483-
case SuggestionAction.CreateAndLinkNoteIntoInbox: {
479+
// --- CREATE NOTE INTO INBOX ---
480+
case SuggestionAction.CreateNoteIntoInbox: {
484481
const { note } = await noteCreateService.createNote(
485482
{
486483
target: "inbox",
487484
title: suggestion.noteTitle,
488485
activate: true,
489486
promptForType: true,
490-
} as CreateNoteIntoInboxOpts
487+
}
491488
);
492489

493-
if (!note) return;
490+
if (!note)
491+
break;
494492

495493
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
496494
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
497-
498-
$el.trigger("autocomplete:noteselected", [suggestion]);
499-
$el.autocomplete("close");
500495
break;
501496
}
502497

503-
case SuggestionAction.CreateNoteIntoPath:
504-
case SuggestionAction.CreateAndLinkNoteIntoPath: {
505-
if (!suggestion.parentNoteId) return;
498+
case SuggestionAction.CreateAndLinkNoteIntoInbox: {
499+
const { note } = await noteCreateService.createNote(
500+
{
501+
target: "inbox",
502+
title: suggestion.noteTitle,
503+
activate: false,
504+
promptForType: true,
505+
}
506+
);
507+
508+
if (!note)
509+
break;
510+
511+
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
512+
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
513+
514+
$el.autocomplete("close");
515+
$el.trigger("autocomplete:noteselected", [suggestion]);
516+
return;
517+
}
506518

519+
case SuggestionAction.CreateNoteIntoPath: {
520+
if (!suggestion.parentNoteId) {
521+
console.warn("Missing parentNoteId for CreateNoteIntoPath");
522+
return;
523+
}
507524
const { note } = await noteCreateService.createNote(
508525
{
509-
parentNoteUrl: suggestion.parentNoteId,
510526
target: "into",
527+
parentNoteUrl: suggestion.parentNoteId,
511528
title: suggestion.noteTitle,
512529
activate: true,
513530
promptForType: true,
514531
},
515532
);
516533

517-
if (!note) return;
534+
if (!note) break;
518535

519536
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
520537
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
538+
break;
539+
}
521540

522-
$el.trigger("autocomplete:noteselected", [suggestion]);
541+
case SuggestionAction.CreateAndLinkNoteIntoPath: {
542+
if (!suggestion.parentNoteId) {
543+
console.warn("Missing parentNoteId for CreateNoteIntoPath");
544+
return;
545+
}
546+
const { note } = await noteCreateService.createNote(
547+
{
548+
target: "into",
549+
parentNoteUrl: suggestion.parentNoteId,
550+
title: suggestion.noteTitle,
551+
activate: false,
552+
promptForType: true,
553+
}
554+
);
555+
556+
if (!note) break;
557+
558+
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
559+
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
523560
$el.autocomplete("close");
524-
break;
561+
$el.trigger("autocomplete:noteselected", [suggestion]);
562+
return;
525563
}
526564

527565
case SuggestionAction.SearchNotes: {
@@ -531,13 +569,12 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
531569
}
532570

533571
default: {
534-
$el.setSelectedNotePath(suggestion.notePath);
535-
$el.setSelectedExternalLink(null);
536-
$el.autocomplete("val", suggestion.noteTitle);
537-
$el.autocomplete("close");
538-
$el.trigger("autocomplete:noteselected", [suggestion]);
539572
}
540573
}
574+
if (suggestion.notePath) {
575+
$el.trigger("autocomplete:noteselected", [suggestion]);
576+
}
577+
$el.autocomplete("close");
541578
});
542579

543580
$el.on("autocomplete:closed", () => {

apps/client/src/widgets/ribbon/components/AttributeEditor.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,26 +258,26 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
258258
parentNotePath: string | undefined,
259259
action: CreateNoteAction
260260
): Promise<string> => {
261-
if (!parentNotePath) {
262-
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
263-
return "";
264-
}
265-
266261
switch (action) {
267262
case CreateNoteAction.CreateNoteIntoInbox:
268263
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
269264
const { note } = await note_create.createNote(
270265
{
271266
target: "inbox",
272267
title,
273-
activate: false
268+
activate: false,
269+
promptForType: true,
274270
}
275271
);
276272
return note?.getBestNotePathString() ?? "";
277273
}
278274

279275
case CreateNoteAction.CreateNoteIntoPath:
280276
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
277+
if (!parentNotePath) {
278+
console.warn("Missing parentNotePath in createNoteFromCkEditor()");
279+
return "";
280+
}
281281
const resp = await note_create.createNote(
282282
{
283283
target: "into",

apps/client/src/widgets/type_widgets/editable_text.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -500,42 +500,6 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
500500
): Promise<string> {
501501
try {
502502
switch (action) {
503-
// --- Create note INTO inbox ---
504-
case CreateNoteAction.CreateNoteIntoInbox: {
505-
const { note } = await note_create.createNote(
506-
{
507-
target: "inbox",
508-
title,
509-
activate: true,
510-
promptForType: true,
511-
}
512-
);
513-
514-
return note?.getBestNotePathString() ?? "";
515-
}
516-
517-
// --- Create note INTO current path ---
518-
case CreateNoteAction.CreateNoteIntoPath: {
519-
// This should be impossible but we must specify it anyways
520-
// because it might cause bugs, which the type-check from
521-
// createNote already catches
522-
if (!parentNotePath) {
523-
console.error("Cannot create note: parentNotePath is undefined.");
524-
return "";
525-
}
526-
const { note } = await note_create.createNote(
527-
{
528-
target: "into",
529-
parentNoteUrl: parentNotePath,
530-
title,
531-
activate: true,
532-
promptForType: true,
533-
}
534-
)
535-
536-
return note?.getBestNotePathString() ?? "";
537-
}
538-
539503
// --- Create & link note INTO inbox ---
540504
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
541505
const { note } = await noteCreateService.createNote(
@@ -570,7 +534,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
570534
}
571535

572536
default:
573-
console.warn("Unknown CreateNoteAction:", action);
537+
console.warn("impossible CreateNoteAction state:", action);
574538
return "";
575539
}
576540
} catch (err) {

0 commit comments

Comments
 (0)