mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 04:29:01 +01:00
refactor(bulk_action): add basic type safety for client
This commit is contained in:
parent
0d3de92890
commit
409638151c
@ -16,6 +16,7 @@ import RenameNoteBulkAction from "../widgets/bulk_actions/note/rename_note.js";
|
||||
import { t } from "./i18n.js";
|
||||
import type FNote from "../entities/fnote.js";
|
||||
import toast from "./toast.js";
|
||||
import { BulkAction } from "@triliumnext/commons";
|
||||
|
||||
const ACTION_GROUPS = [
|
||||
{
|
||||
@ -90,7 +91,7 @@ function parseActions(note: FNote) {
|
||||
.filter((action) => !!action);
|
||||
}
|
||||
|
||||
export async function executeBulkActions(parentNoteId: string, actions: {}[]) {
|
||||
export async function executeBulkActions(parentNoteId: string, actions: BulkAction[]) {
|
||||
await server.post("bulk-action/execute", {
|
||||
noteIds: [ parentNoteId ],
|
||||
includeDescendants: true,
|
||||
|
||||
@ -5,52 +5,7 @@ import branchService from "./branches.js";
|
||||
import { randomString } from "./utils.js";
|
||||
import eraseService from "./erase.js";
|
||||
import type BNote from "../becca/entities/bnote.js";
|
||||
|
||||
type ActionHandlers = {
|
||||
addLabel: {
|
||||
labelName: string;
|
||||
labelValue?: string;
|
||||
},
|
||||
addRelation: {
|
||||
relationName: string;
|
||||
targetNoteId: string;
|
||||
},
|
||||
deleteNote: {},
|
||||
deleteRevisions: {},
|
||||
deleteLabel: {
|
||||
labelName: string;
|
||||
},
|
||||
deleteRelation: {
|
||||
relationName: string;
|
||||
},
|
||||
renameNote: {
|
||||
newTitle: string;
|
||||
},
|
||||
renameLabel: {
|
||||
oldLabelName: string;
|
||||
newLabelName: string;
|
||||
},
|
||||
renameRelation: {
|
||||
oldRelationName: string;
|
||||
newRelationName: string;
|
||||
},
|
||||
updateLabelValue: {
|
||||
labelName: string;
|
||||
labelValue: string;
|
||||
},
|
||||
updateRelationTarget: {
|
||||
relationName: string;
|
||||
targetNoteId: string;
|
||||
},
|
||||
moveNote: {
|
||||
targetParentNoteId: string;
|
||||
},
|
||||
executeScript: {
|
||||
script: string;
|
||||
}
|
||||
};
|
||||
|
||||
type BulkActionData<T extends keyof ActionHandlers> = ActionHandlers[T] & { name: T };
|
||||
import { ActionHandlers, BulkAction, BulkActionData } from "@triliumnext/commons";
|
||||
|
||||
type ActionHandler<T> = (action: T, note: BNote) => void;
|
||||
|
||||
@ -58,8 +13,6 @@ type ActionHandlerMap = {
|
||||
[K in keyof ActionHandlers]: ActionHandler<BulkActionData<K>>;
|
||||
};
|
||||
|
||||
export type BulkAction = BulkActionData<keyof ActionHandlers>;
|
||||
|
||||
const ACTION_HANDLERS: ActionHandlerMap = {
|
||||
addLabel: (action, note) => {
|
||||
note.addLabel(action.labelName, action.labelValue);
|
||||
|
||||
@ -5,3 +5,4 @@ export * from "./lib/hidden_subtree.js";
|
||||
export * from "./lib/rows.js";
|
||||
export * from "./lib/test-utils.js";
|
||||
export * from "./lib/mime_type.js";
|
||||
export * from "./lib/bulk_actions.js";
|
||||
|
||||
47
packages/commons/src/lib/bulk_actions.ts
Normal file
47
packages/commons/src/lib/bulk_actions.ts
Normal file
@ -0,0 +1,47 @@
|
||||
export type ActionHandlers = {
|
||||
addLabel: {
|
||||
labelName: string;
|
||||
labelValue?: string;
|
||||
},
|
||||
addRelation: {
|
||||
relationName: string;
|
||||
targetNoteId: string;
|
||||
},
|
||||
deleteNote: {},
|
||||
deleteRevisions: {},
|
||||
deleteLabel: {
|
||||
labelName: string;
|
||||
},
|
||||
deleteRelation: {
|
||||
relationName: string;
|
||||
},
|
||||
renameNote: {
|
||||
newTitle: string;
|
||||
},
|
||||
renameLabel: {
|
||||
oldLabelName: string;
|
||||
newLabelName: string;
|
||||
},
|
||||
renameRelation: {
|
||||
oldRelationName: string;
|
||||
newRelationName: string;
|
||||
},
|
||||
updateLabelValue: {
|
||||
labelName: string;
|
||||
labelValue: string;
|
||||
},
|
||||
updateRelationTarget: {
|
||||
relationName: string;
|
||||
targetNoteId: string;
|
||||
},
|
||||
moveNote: {
|
||||
targetParentNoteId: string;
|
||||
},
|
||||
executeScript: {
|
||||
script: string;
|
||||
}
|
||||
};
|
||||
|
||||
export type BulkActionData<T extends keyof ActionHandlers> = ActionHandlers[T] & { name: T };
|
||||
|
||||
export type BulkAction = BulkActionData<keyof ActionHandlers>;
|
||||
Loading…
x
Reference in New Issue
Block a user