refactor(create-note-naming): simplify naming

This commit is contained in:
Jakob Schlanstedt 2025-11-05 16:06:08 +01:00
parent 547cdff510
commit 8fc8f97879
5 changed files with 37 additions and 38 deletions

View File

@ -46,10 +46,10 @@ export enum SuggestionAction {
// This overlap ensures that when a suggestion triggers a note creation callback, // This overlap ensures that when a suggestion triggers a note creation callback,
// the receiving features (e.g. note creation handlers, CKEditor mentions) can interpret // the receiving features (e.g. note creation handlers, CKEditor mentions) can interpret
// the action type consistently // the action type consistently
CreateNoteIntoInbox = CreateNoteAction.CreateNoteIntoInbox, CreateNote = CreateNoteAction.CreateNote,
CreateNoteIntoPath = CreateNoteAction.CreateNoteIntoPath, CreateChildNote = CreateNoteAction.CreateChildNote,
CreateAndLinkNoteIntoInbox = CreateNoteAction.CreateAndLinkNoteIntoInbox, CreateAndLinkNote = CreateNoteAction.CreateAndLinkNote,
CreateAndLinkNoteIntoPath = CreateNoteAction.CreateAndLinkNoteIntoPath, CreateAndLinkChildNote = CreateNoteAction.CreateAndLinkChildNote,
SearchNotes = "search-notes", SearchNotes = "search-notes",
ExternalLink = "external-link", ExternalLink = "external-link",
@ -182,16 +182,16 @@ async function autocompleteSource(
case CreateMode.CreateOnly: { case CreateMode.CreateOnly: {
results = [ results = [
{ {
action: SuggestionAction.CreateNoteIntoInbox, action: SuggestionAction.CreateNote,
noteTitle: trimmedTerm, noteTitle: trimmedTerm,
parentNoteId: "inbox", parentNoteId: "inbox",
highlightedNotePathTitle: t("note_autocomplete.create-note-into-inbox", { term: trimmedTerm }), highlightedNotePathTitle: t("note_autocomplete.create-note", { term: trimmedTerm }),
}, },
{ {
action: SuggestionAction.CreateNoteIntoPath, action: SuggestionAction.CreateChildNote,
noteTitle: trimmedTerm, noteTitle: trimmedTerm,
parentNoteId: activeNoteId || "root", parentNoteId: activeNoteId || "root",
highlightedNotePathTitle: t("note_autocomplete.create-note-into-path", { term: trimmedTerm }), highlightedNotePathTitle: t("note_autocomplete.create-child-note", { term: trimmedTerm }),
}, },
...results, ...results,
]; ];
@ -201,16 +201,16 @@ async function autocompleteSource(
case CreateMode.CreateAndLink: { case CreateMode.CreateAndLink: {
results = [ results = [
{ {
action: SuggestionAction.CreateAndLinkNoteIntoInbox, action: SuggestionAction.CreateAndLinkNote,
noteTitle: trimmedTerm, noteTitle: trimmedTerm,
parentNoteId: "inbox", parentNoteId: "inbox",
highlightedNotePathTitle: t("note_autocomplete.create-and-link-note-into-inbox", { term: trimmedTerm }), highlightedNotePathTitle: t("note_autocomplete.create-and-link-note", { term: trimmedTerm }),
}, },
{ {
action: SuggestionAction.CreateAndLinkNoteIntoPath, action: SuggestionAction.CreateAndLinkChildNote,
noteTitle: trimmedTerm, noteTitle: trimmedTerm,
parentNoteId: activeNoteId || "root", parentNoteId: activeNoteId || "root",
highlightedNotePathTitle: t("note_autocomplete.create-and-link-note-into-path", { term: trimmedTerm }), highlightedNotePathTitle: t("note_autocomplete.create-and-link-child-note", { term: trimmedTerm }),
}, },
...results, ...results,
]; ];
@ -316,11 +316,11 @@ function renderNoteSuggestion(s: Suggestion): string {
switch (s.action) { switch (s.action) {
case SuggestionAction.SearchNotes: case SuggestionAction.SearchNotes:
return "bx bx-search"; return "bx bx-search";
case SuggestionAction.CreateAndLinkNoteIntoInbox: case SuggestionAction.CreateAndLinkNote:
case SuggestionAction.CreateNoteIntoInbox: case SuggestionAction.CreateNote:
return "bx bx-plus"; return "bx bx-plus";
case SuggestionAction.CreateAndLinkNoteIntoPath: case SuggestionAction.CreateAndLinkChildNote:
case SuggestionAction.CreateNoteIntoPath: case SuggestionAction.CreateChildNote:
return "bx bx-plus"; return "bx bx-plus";
case SuggestionAction.ExternalLink: case SuggestionAction.ExternalLink:
return "bx bx-link-external"; return "bx bx-link-external";
@ -477,7 +477,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
} }
// --- CREATE NOTE INTO INBOX --- // --- CREATE NOTE INTO INBOX ---
case SuggestionAction.CreateNoteIntoInbox: { case SuggestionAction.CreateNote: {
const { note } = await noteCreateService.createNote( const { note } = await noteCreateService.createNote(
{ {
target: "inbox", target: "inbox",
@ -495,7 +495,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
break; break;
} }
case SuggestionAction.CreateAndLinkNoteIntoInbox: { case SuggestionAction.CreateAndLinkNote: {
const { note } = await noteCreateService.createNote( const { note } = await noteCreateService.createNote(
{ {
target: "inbox", target: "inbox",
@ -516,7 +516,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
return; return;
} }
case SuggestionAction.CreateNoteIntoPath: { case SuggestionAction.CreateChildNote: {
if (!suggestion.parentNoteId) { if (!suggestion.parentNoteId) {
console.warn("Missing parentNoteId for CreateNoteIntoPath"); console.warn("Missing parentNoteId for CreateNoteIntoPath");
return; return;
@ -538,7 +538,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
break; break;
} }
case SuggestionAction.CreateAndLinkNoteIntoPath: { case SuggestionAction.CreateAndLinkChildNote: {
if (!suggestion.parentNoteId) { if (!suggestion.parentNoteId) {
console.warn("Missing parentNoteId for CreateNoteIntoPath"); console.warn("Missing parentNoteId for CreateNoteIntoPath");
return; return;

View File

@ -1897,14 +1897,13 @@
}, },
"note_autocomplete": { "note_autocomplete": {
"search-for": "Search for \"{{term}}\"", "search-for": "Search for \"{{term}}\"",
"create-note-into-path": "Create child note \"{{term}}\"", "create-child-note": "Create child note \"{{term}}\"",
"create-note-into-inbox": "Create in Inbox note \"{{term}}\"", "create-note": "Create note \"{{term}}\"",
"create-and-link-note-into-path": "Create and link child note \"{{term}}\"", "create-and-link-child-note": "Create and link child note \"{{term}}\"",
"create-and-link-note-into-inbox": "Create in Inbox and link note \"{{term}}\"", "create-and-link-note": "Create and link note \"{{term}}\"",
"insert-external-link": "Insert external link to \"{{term}}\"", "insert-external-link": "Insert external link to \"{{term}}\"",
"clear-text-field": "Clear text field", "clear-text-field": "Clear text field",
"show-recent-notes": "Show recent notes", "show-recent-notes": "Show recent notes"
"full-text-search": "Full text search"
}, },
"note_tooltip": { "note_tooltip": {
"note-has-been-deleted": "Note has been deleted.", "note-has-been-deleted": "Note has been deleted.",

View File

@ -254,8 +254,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
action: CreateNoteAction action: CreateNoteAction
): Promise<string> => { ): Promise<string> => {
switch (action) { switch (action) {
case CreateNoteAction.CreateNoteIntoInbox: case CreateNoteAction.CreateNote:
case CreateNoteAction.CreateAndLinkNoteIntoInbox: { case CreateNoteAction.CreateAndLinkNote: {
const { note } = await note_create.createNote( const { note } = await note_create.createNote(
{ {
target: "inbox", target: "inbox",
@ -267,8 +267,8 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
return note?.getBestNotePathString() ?? ""; return note?.getBestNotePathString() ?? "";
} }
case CreateNoteAction.CreateNoteIntoPath: case CreateNoteAction.CreateChildNote:
case CreateNoteAction.CreateAndLinkNoteIntoPath: { case CreateNoteAction.CreateAndLinkChildNote: {
if (!parentNotePath) { if (!parentNotePath) {
console.warn("Missing parentNotePath in createNoteFromCkEditor()"); console.warn("Missing parentNotePath in createNoteFromCkEditor()");
return ""; return "";

View File

@ -59,10 +59,10 @@ class CustomMentionCommand extends Command {
}); });
} }
else if ( else if (
mention.action === CreateNoteAction.CreateNoteIntoInbox || mention.action === CreateNoteAction.CreateNote ||
mention.action === CreateNoteAction.CreateNoteIntoPath || mention.action === CreateNoteAction.CreateChildNote ||
mention.action === CreateNoteAction.CreateAndLinkNoteIntoInbox || mention.action === CreateNoteAction.CreateAndLinkNote ||
mention.action === CreateNoteAction.CreateAndLinkNoteIntoPath mention.action === CreateNoteAction.CreateAndLinkChildNote
) { ) {
const editorEl = this.editor.editing.view.getDomRoot(); const editorEl = this.editor.editing.view.getDomRoot();
const component = glob.getComponentByEl<EditorComponent>(editorEl); const component = glob.getComponentByEl<EditorComponent>(editorEl);

View File

@ -1,6 +1,6 @@
export enum CreateNoteAction { export enum CreateNoteAction {
CreateNoteIntoInbox = "create-note-into-inbox", CreateNote = "create-note",
CreateNoteIntoPath = "create-note-into-path", CreateChildNote = "create-child-note",
CreateAndLinkNoteIntoInbox = "create-and-link-note-into-inbox", CreateAndLinkNote = "create-and-link-note",
CreateAndLinkNoteIntoPath = "create-and-link-note-into-path" CreateAndLinkChildNote = "create-and-link-child-note"
} }