mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +02:00
feat(react/bulk_actions): port update relation target
This commit is contained in:
parent
6f6643d758
commit
18c6fe7ebd
@ -1,74 +0,0 @@
|
|||||||
import SpacedUpdate from "../../../services/spaced_update.js";
|
|
||||||
import AbstractBulkAction from "../abstract_bulk_action.js";
|
|
||||||
import noteAutocompleteService from "../../../services/note_autocomplete.js";
|
|
||||||
import { t } from "../../../services/i18n.js";
|
|
||||||
|
|
||||||
const TPL = /*html*/`
|
|
||||||
<tr>
|
|
||||||
<td colspan="2">
|
|
||||||
<div style="display: flex; align-items: center">
|
|
||||||
<div style="margin-right: 10px;" class="text-nowrap">${t("update_relation_target.update_relation")}</div>
|
|
||||||
|
|
||||||
<input type="text"
|
|
||||||
class="form-control relation-name"
|
|
||||||
placeholder="${t("update_relation_target.relation_name")}"
|
|
||||||
pattern="[\\p{L}\\p{N}_:]+"
|
|
||||||
style="flex-shrink: 3"
|
|
||||||
title="${t("update_relation_target.allowed_characters")}"/>
|
|
||||||
|
|
||||||
<div style="margin-right: 10px; margin-left: 10px;" class="text-nowrap">${t("update_relation_target.to")}</div>
|
|
||||||
|
|
||||||
<div class="input-group" style="flex-shrink: 2">
|
|
||||||
<input type="text" class="form-control target-note" placeholder="${t("update_relation_target.target_note")}"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="button-column">
|
|
||||||
<div class="dropdown help-dropdown">
|
|
||||||
<span class="bx bx-help-circle icon-action" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></span>
|
|
||||||
<div class="dropdown-menu dropdown-menu-right p-4">
|
|
||||||
<p>${t("update_relation_target.on_all_matched_notes")}:</p>
|
|
||||||
|
|
||||||
<ul style="margin-bottom: 0;">
|
|
||||||
<li>${t("update_relation_target.change_target_note")}</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span class="bx bx-x icon-action action-conf-del"></span>
|
|
||||||
</td>
|
|
||||||
</tr>`;
|
|
||||||
|
|
||||||
export default class UpdateRelationTargetBulkAction extends AbstractBulkAction {
|
|
||||||
static get actionName() {
|
|
||||||
return "updateRelationTarget";
|
|
||||||
}
|
|
||||||
static get actionTitle() {
|
|
||||||
return t("update_relation_target.update_relation_target");
|
|
||||||
}
|
|
||||||
|
|
||||||
doRender() {
|
|
||||||
const $action = $(TPL);
|
|
||||||
|
|
||||||
const $relationName = $action.find(".relation-name");
|
|
||||||
$relationName.val(this.actionDef.relationName || "");
|
|
||||||
|
|
||||||
const $targetNote = $action.find(".target-note");
|
|
||||||
noteAutocompleteService.initNoteAutocomplete($targetNote);
|
|
||||||
$targetNote.setNote(this.actionDef.targetNoteId);
|
|
||||||
|
|
||||||
$targetNote.on("autocomplete:closed", () => spacedUpdate.scheduleUpdate());
|
|
||||||
|
|
||||||
const spacedUpdate = new SpacedUpdate(async () => {
|
|
||||||
await this.saveAction({
|
|
||||||
relationName: $relationName.val(),
|
|
||||||
targetNoteId: $targetNote.getSelectedNoteId()
|
|
||||||
});
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
$relationName.on("input", () => spacedUpdate.scheduleUpdate());
|
|
||||||
$targetNote.on("input", () => spacedUpdate.scheduleUpdate());
|
|
||||||
|
|
||||||
return $action;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,60 @@
|
|||||||
|
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 NoteAutocomplete from "../../react/NoteAutocomplete.jsx";
|
||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
import { useSpacedUpdate } from "../../react/hooks.jsx";
|
||||||
|
|
||||||
|
function UpdateRelationTargetComponent({ bulkAction, actionDef }: { bulkAction: AbstractBulkAction, actionDef: ActionDefinition }) {
|
||||||
|
const [ relationName, setRelationName ] = useState(actionDef.relationName);
|
||||||
|
const [ targetNoteId, setTargetNoteId ] = useState(actionDef.targetNoteId);
|
||||||
|
const spacedUpdate = useSpacedUpdate(() => bulkAction.saveAction({ relationName, targetNoteId }));
|
||||||
|
useEffect(() => spacedUpdate.scheduleUpdate(), [ relationName, targetNoteId ]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BulkAction
|
||||||
|
bulkAction={bulkAction}
|
||||||
|
label={t("update_relation_target.update_relation")}
|
||||||
|
helpText={<>
|
||||||
|
<p>{t("update_relation_target.on_all_matched_notes")}:</p>
|
||||||
|
|
||||||
|
<ul style="margin-bottom: 0;">
|
||||||
|
<li>{t("update_relation_target.change_target_note")}</li>
|
||||||
|
</ul>
|
||||||
|
</>}
|
||||||
|
>
|
||||||
|
<FormTextBox
|
||||||
|
placeholder={t("update_relation_target.relation_name")}
|
||||||
|
pattern="[\\p{L}\\p{N}_:]+"
|
||||||
|
style={{ flexShrink: 3 }}
|
||||||
|
title={t("update_relation_target.allowed_characters")}
|
||||||
|
currentValue={relationName} onChange={setRelationName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<BulkActionText text={t("update_relation_target.to")} />
|
||||||
|
|
||||||
|
<NoteAutocomplete
|
||||||
|
placeholder={t("update_relation_target.target_note")}
|
||||||
|
containerStyle={{ flexShrink: 2 }}
|
||||||
|
noteId={targetNoteId} noteIdChanged={setTargetNoteId}
|
||||||
|
/>
|
||||||
|
</BulkAction>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class UpdateRelationTargetBulkAction extends AbstractBulkAction {
|
||||||
|
|
||||||
|
static get actionName() {
|
||||||
|
return "updateRelationTarget";
|
||||||
|
}
|
||||||
|
|
||||||
|
static get actionTitle() {
|
||||||
|
return t("update_relation_target.update_relation_target");
|
||||||
|
}
|
||||||
|
|
||||||
|
doRender() {
|
||||||
|
return <UpdateRelationTargetComponent bulkAction={this} actionDef={this.actionDef} />
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,12 +3,14 @@ import { t } from "../../services/i18n";
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import note_autocomplete, { Options, type Suggestion } from "../../services/note_autocomplete";
|
import note_autocomplete, { Options, type Suggestion } from "../../services/note_autocomplete";
|
||||||
import type { RefObject } from "preact";
|
import type { RefObject } from "preact";
|
||||||
|
import { CSSProperties } from "preact/compat";
|
||||||
|
|
||||||
interface NoteAutocompleteProps {
|
interface NoteAutocompleteProps {
|
||||||
inputRef?: RefObject<HTMLInputElement>;
|
inputRef?: RefObject<HTMLInputElement>;
|
||||||
text?: string;
|
text?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
container?: RefObject<HTMLDivElement>;
|
container?: RefObject<HTMLDivElement>;
|
||||||
|
containerStyle?: CSSProperties;
|
||||||
opts?: Omit<Options, "container">;
|
opts?: Omit<Options, "container">;
|
||||||
onChange?: (suggestion: Suggestion | null) => void;
|
onChange?: (suggestion: Suggestion | null) => void;
|
||||||
onTextChange?: (text: string) => void;
|
onTextChange?: (text: string) => void;
|
||||||
@ -16,7 +18,7 @@ interface NoteAutocompleteProps {
|
|||||||
noteId?: string;
|
noteId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, onChange, onTextChange, container, opts, noteId, noteIdChanged }: NoteAutocompleteProps) {
|
export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, onChange, onTextChange, container, containerStyle, opts, noteId, noteIdChanged }: NoteAutocompleteProps) {
|
||||||
const ref = _ref ?? useRef<HTMLInputElement>(null);
|
const ref = _ref ?? useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -67,7 +69,7 @@ export default function NoteAutocomplete({ inputRef: _ref, text, placeholder, on
|
|||||||
}, [text]);
|
}, [text]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="input-group">
|
<div className="input-group" style={containerStyle}>
|
||||||
<input
|
<input
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className="note-autocomplete form-control"
|
className="note-autocomplete form-control"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user