From 6f6643d7583aa7ba6cdb06cfb961108254d16b92 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 9 Aug 2025 20:09:27 +0300 Subject: [PATCH] feat(react/bulk_actions): port rename relation --- .../bulk_actions/relation/rename_relation.ts | 60 ------------------- .../bulk_actions/relation/rename_relation.tsx | 49 +++++++++++++++ 2 files changed, 49 insertions(+), 60 deletions(-) delete mode 100644 apps/client/src/widgets/bulk_actions/relation/rename_relation.ts create mode 100644 apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx diff --git a/apps/client/src/widgets/bulk_actions/relation/rename_relation.ts b/apps/client/src/widgets/bulk_actions/relation/rename_relation.ts deleted file mode 100644 index 3e2b4e6a6..000000000 --- a/apps/client/src/widgets/bulk_actions/relation/rename_relation.ts +++ /dev/null @@ -1,60 +0,0 @@ -import SpacedUpdate from "../../../services/spaced_update.js"; -import AbstractBulkAction from "../abstract_bulk_action.js"; -import { t } from "../../../services/i18n.js"; - -const TPL = /*html*/` - - -
-
${t("rename_relation.rename_relation_from")}
- - - -
${t("rename_relation.to")}
- - -
- - - - -`; - -export default class RenameRelationBulkAction extends AbstractBulkAction { - static get actionName() { - return "renameRelation"; - } - static get actionTitle() { - return t("rename_relation.rename_relation"); - } - - doRender() { - const $action = $(TPL); - - const $oldRelationName = $action.find(".old-relation-name"); - $oldRelationName.val(this.actionDef.oldRelationName || ""); - - const $newRelationName = $action.find(".new-relation-name"); - $newRelationName.val(this.actionDef.newRelationName || ""); - - const spacedUpdate = new SpacedUpdate(async () => { - await this.saveAction({ - oldRelationName: $oldRelationName.val(), - newRelationName: $newRelationName.val() - }); - }, 1000); - - $oldRelationName.on("input", () => spacedUpdate.scheduleUpdate()); - $newRelationName.on("input", () => spacedUpdate.scheduleUpdate()); - - return $action; - } -} diff --git a/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx b/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx new file mode 100644 index 000000000..b0ce54834 --- /dev/null +++ b/apps/client/src/widgets/bulk_actions/relation/rename_relation.tsx @@ -0,0 +1,49 @@ +import AbstractBulkAction, { ActionDefinition } from "../abstract_bulk_action.js"; +import { t } from "../../../services/i18n.js"; +import BulkAction, { BulkActionText } from "../BulkAction.jsx"; +import FormTextBox from "../../react/FormTextBox.jsx"; +import { useEffect, useState } from "preact/hooks"; +import { useSpacedUpdate } from "../../react/hooks.jsx"; + +function RenameRelationBulkActionComponent({ bulkAction, actionDef }: { bulkAction: AbstractBulkAction, actionDef: ActionDefinition }) { + const [ oldRelationName, setOldRelationName ] = useState(actionDef.oldRelationName); + const [ newRelationName, setNewRelationName ] = useState(actionDef.newRelationName); + const spacedUpdate = useSpacedUpdate(() => bulkAction.saveAction({ oldRelationName, newRelationName })); + useEffect(() => spacedUpdate.scheduleUpdate(), [ oldRelationName, newRelationName ]); + + return ( + + + + + + + + ) +} + +export default class RenameRelationBulkAction extends AbstractBulkAction { + static get actionName() { + return "renameRelation"; + } + static get actionTitle() { + return t("rename_relation.rename_relation"); + } + + doRender() { + return + } +}