import { useEffect, useState } from "preact/hooks"; import { EventData } from "../../components/app_context"; import { closeActiveDialog, openDialog } from "../../services/dialog"; import { t } from "../../services/i18n"; import Modal from "../react/Modal"; import ReactBasicWidget from "../react/ReactBasicWidget"; import "./bulk_actions.css"; import { BulkActionAffectedNotes } from "@triliumnext/commons"; import server from "../../services/server"; import FormCheckbox from "../react/FormCheckbox"; import Button from "../react/Button"; import bulk_action from "../../services/bulk_action"; import toast from "../../services/toast"; import RenameNoteBulkAction from "../bulk_actions/note/rename_note"; import { RawHtmlBlock } from "../react/RawHtml"; import FNote from "../../entities/fnote"; import froca from "../../services/froca"; import useTriliumEvent from "../react/hooks"; interface BulkActionProps { bulkActionNote?: FNote | null; selectedOrActiveNoteIds?: string[]; } function BulkActionComponent({ selectedOrActiveNoteIds, bulkActionNote }: BulkActionProps) { const [ includeDescendants, setIncludeDescendants ] = useState(false); const [ affectedNoteCount, setAffectedNoteCount ] = useState(0); const [ existingActions, setExistingActions ] = useState([]); if (!selectedOrActiveNoteIds || !bulkActionNote) { return; } useEffect(() => { server.post("bulk-action/affected-notes", { noteIds: selectedOrActiveNoteIds, includeDescendants }).then(({ affectedNoteCount }) => setAffectedNoteCount(affectedNoteCount)); }, [ selectedOrActiveNoteIds, includeDescendants ]); // Refresh is forced by the entities reloaded event outside React. useEffect(() => { setExistingActions(bulk_action.parseActions(bulkActionNote)); }, []); useTriliumEvent("entitiesReloaded", () => { console.log("Got entities reloaded."); }); return ( selectedOrActiveNoteIds && } onSubmit={async () => { await server.post("bulk-action/execute", { noteIds: selectedOrActiveNoteIds, includeDescendants }); toast.showMessage(t("bulk_actions.bulk_actions_executed"), 3000); closeActiveDialog(); }} >

{t("bulk_actions.affected_notes")}: {affectedNoteCount}

{t("bulk_actions.available_actions")}

{t("bulk_actions.chosen_actions")}

) } function AvailableActionsList() { return {bulk_action.ACTION_GROUPS.map((actionGroup) => { return ( {actionGroup.actions.map(({ actionName, actionTitle }) => ); })}
{ actionGroup.title }:
; } function ExistingActionsList({ existingActions }: { existingActions?: RenameNoteBulkAction[] }) { return ( { existingActions ? existingActions .map(action => { const renderedAction = action.render(); if (renderedAction) { return } else { return null; } }) .filter(renderedAction => renderedAction !== null) :

{t("bulk_actions.none_yet")}

}
); } export default class BulkActionsDialog extends ReactBasicWidget { private props: BulkActionProps = {}; get component() { return } async openBulkActionsDialogEvent({ selectedOrActiveNoteIds }: EventData<"openBulkActionsDialog">) { this.props = { selectedOrActiveNoteIds, bulkActionNote: await froca.getNote("_bulkAction") }; this.doRender(); openDialog(this.$widget); } }