;
+ private selectedOrActiveNoteIds: string[] | null = null;
+
doRender() {
this.$widget = $(TPL);
this.$includeDescendants = this.$widget.find(".include-descendants");
@@ -79,9 +88,11 @@ export default class BulkActionsDialog extends BasicWidget {
this.$widget.on("click", "[data-action-add]", async (event) => {
const actionName = $(event.target).attr("data-action-add");
+ if (!actionName) {
+ return;
+ }
await bulkActionService.addAction("_bulkAction", actionName);
-
await this.refresh();
});
@@ -93,7 +104,6 @@ export default class BulkActionsDialog extends BasicWidget {
});
toastService.showMessage(t("bulk_actions.bulk_actions_executed"), 3000);
-
utils.closeActiveDialog();
});
}
@@ -101,21 +111,28 @@ export default class BulkActionsDialog extends BasicWidget {
async refresh() {
this.renderAvailableActions();
+ if (!this.selectedOrActiveNoteIds) {
+ return;
+ }
+
const { affectedNoteCount } = await server.post("bulk-action/affected-notes", {
noteIds: this.selectedOrActiveNoteIds,
includeDescendants: this.$includeDescendants.is(":checked")
- });
+ }) as { affectedNoteCount: number };
this.$affectedNoteCount.text(affectedNoteCount);
const bulkActionNote = await froca.getNote("_bulkAction");
+ if (!bulkActionNote) {
+ return;
+ }
const actions = bulkActionService.parseActions(bulkActionNote);
this.$existingActionList.empty();
if (actions.length > 0) {
- this.$existingActionList.append(...actions.map((action) => action.render()));
+ this.$existingActionList.append(...actions.map((action) => action.render()).filter((action) => action !== null));
} else {
this.$existingActionList.append($("").text(t("bulk_actions.none_yet")));
}
@@ -138,7 +155,7 @@ export default class BulkActionsDialog extends BasicWidget {
}
}
- entitiesReloadedEvent({ loadResults }) {
+ entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
// only refreshing deleted attrs, otherwise components update themselves
if (loadResults.getAttributeRows().find((row) => row.type === "label" && row.name === "action" && row.noteId === "_bulkAction" && row.isDeleted)) {
// this may be triggered from e.g., sync without open widget, then no need to refresh the widget
@@ -148,12 +165,11 @@ export default class BulkActionsDialog extends BasicWidget {
}
}
- async openBulkActionsDialogEvent({ selectedOrActiveNoteIds }) {
+ async openBulkActionsDialogEvent({ selectedOrActiveNoteIds }: EventData<"openBulkActionsDialog">) {
this.selectedOrActiveNoteIds = selectedOrActiveNoteIds;
this.$includeDescendants.prop("checked", false);
await this.refresh();
-
utils.openDialog(this.$widget);
}
}
From 43ef9415d21e83f841bee390c0e25e640e2a8658 Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Wed, 19 Mar 2025 14:27:33 +0100
Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Port=20clone=5Ft?=
=?UTF-8?q?o=20to=20ts?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/public/app/components/app_context.ts | 3 ++
.../dialogs/{clone_to.js => clone_to.ts} | 41 ++++++++++++++-----
2 files changed, 33 insertions(+), 11 deletions(-)
rename src/public/app/widgets/dialogs/{clone_to.js => clone_to.ts} (82%)
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts
index 8b50a8101..53e64085e 100644
--- a/src/public/app/components/app_context.ts
+++ b/src/public/app/components/app_context.ts
@@ -371,6 +371,9 @@ type EventMappings = {
openBulkActionsDialog: {
selectedOrActiveNoteIds: string[];
};
+ cloneNoteIdsTo: {
+ noteIds: string[];
+ };
};
diff --git a/src/public/app/widgets/dialogs/clone_to.js b/src/public/app/widgets/dialogs/clone_to.ts
similarity index 82%
rename from src/public/app/widgets/dialogs/clone_to.js
rename to src/public/app/widgets/dialogs/clone_to.ts
index 0098f340a..3f51942d6 100644
--- a/src/public/app/widgets/dialogs/clone_to.js
+++ b/src/public/app/widgets/dialogs/clone_to.ts
@@ -7,6 +7,8 @@ import branchService from "../../services/branches.js";
import appContext from "../../components/app_context.js";
import BasicWidget from "../basic_widget.js";
import { t } from "../../services/i18n.js";
+import type { EventData } from "../../components/app_context.js";
+
const TPL = `
@@ -48,10 +50,14 @@ const TPL = `
`;
export default class CloneToDialog extends BasicWidget {
+ private $form!: JQuery;
+ private $noteAutoComplete!: JQuery;
+ private $clonePrefix!: JQuery;
+ private $noteList!: JQuery;
+ private clonedNoteIds: string[] | null = null;
+
constructor() {
super();
-
- this.clonedNoteIds = null;
}
doRender() {
@@ -66,7 +72,6 @@ export default class CloneToDialog extends BasicWidget {
if (notePath) {
this.$widget.modal("hide");
-
this.cloneNotesTo(notePath);
} else {
logError(t("clone_to.no_path_to_clone_to"));
@@ -76,9 +81,9 @@ export default class CloneToDialog extends BasicWidget {
});
}
- async cloneNoteIdsToEvent({ noteIds }) {
+ async cloneNoteIdsToEvent({ noteIds }: EventData<"cloneNoteIdsTo">) {
if (!noteIds || noteIds.length === 0) {
- noteIds = [appContext.tabManager.getActiveContextNoteId()];
+ noteIds = [appContext.tabManager.getActiveContextNoteId() ?? ""];
}
this.clonedNoteIds = [];
@@ -90,14 +95,14 @@ export default class CloneToDialog extends BasicWidget {
}
utils.openDialog(this.$widget);
-
this.$noteAutoComplete.val("").trigger("focus");
-
this.$noteList.empty();
for (const noteId of this.clonedNoteIds) {
const note = await froca.getNote(noteId);
-
+ if (!note) {
+ continue;
+ }
this.$noteList.append($("").text(note.title));
}
@@ -105,15 +110,29 @@ export default class CloneToDialog extends BasicWidget {
noteAutocompleteService.showRecentNotes(this.$noteAutoComplete);
}
- async cloneNotesTo(notePath) {
+ async cloneNotesTo(notePath: string) {
const { noteId, parentNoteId } = treeService.getNoteIdAndParentIdFromUrl(notePath);
+ if (!noteId || !parentNoteId) {
+ return;
+ }
+
const targetBranchId = await froca.getBranchId(parentNoteId, noteId);
+ if (!targetBranchId || !this.clonedNoteIds) {
+ return;
+ }
for (const cloneNoteId of this.clonedNoteIds) {
- await branchService.cloneNoteToBranch(cloneNoteId, targetBranchId, this.$clonePrefix.val());
+ await branchService.cloneNoteToBranch(cloneNoteId, targetBranchId, this.$clonePrefix.val() as string);
const clonedNote = await froca.getNote(cloneNoteId);
- const targetNote = await froca.getBranch(targetBranchId).getNote();
+ const targetBranch = froca.getBranch(targetBranchId);
+ if (!clonedNote || !targetBranch) {
+ continue;
+ }
+ const targetNote = await targetBranch.getNote();
+ if (!targetNote) {
+ continue;
+ }
toastService.showMessage(t("clone_to.note_cloned", { clonedTitle: clonedNote.title, targetTitle: targetNote.title }));
}
From a0c025014c1e48376d8c3f8f7574ccc4dbd0b414 Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Wed, 19 Mar 2025 15:14:17 +0100
Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20right=20click?=
=?UTF-8?q?=20behavior?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix the bug that when right click on unactive note and do move and clone
command, it still gonna move and clone the active note
---
src/public/app/components/main_tree_executors.ts | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/src/public/app/components/main_tree_executors.ts b/src/public/app/components/main_tree_executors.ts
index 78251d67c..b5473ffe4 100644
--- a/src/public/app/components/main_tree_executors.ts
+++ b/src/public/app/components/main_tree_executors.ts
@@ -1,4 +1,4 @@
-import appContext from "./app_context.js";
+import appContext, { type EventData } from "./app_context.js";
import noteCreateService from "../services/note_create.js";
import treeService from "../services/tree.js";
import hoistedNoteService from "../services/hoisted_note.js";
@@ -14,23 +14,19 @@ export default class MainTreeExecutors extends Component {
return appContext.noteTreeWidget;
}
- async cloneNotesToCommand() {
+ async cloneNotesToCommand({ selectedOrActiveNoteIds }: EventData<"cloneNotesTo">) {
if (!this.tree) {
return;
}
- const selectedOrActiveNoteIds = this.tree.getSelectedOrActiveNodes().map((node) => node.data.noteId);
-
this.triggerCommand("cloneNoteIdsTo", { noteIds: selectedOrActiveNoteIds });
}
- async moveNotesToCommand() {
+ async moveNotesToCommand({ selectedOrActiveBranchIds }: EventData<"moveNotesTo">) {
if (!this.tree) {
return;
}
- const selectedOrActiveBranchIds = this.tree.getSelectedOrActiveNodes().map((node) => node.data.branchId);
-
this.triggerCommand("moveBranchIdsTo", { branchIds: selectedOrActiveBranchIds });
}