A platform for community discussion. Free, open, simple.
PERF: persists node position at the end of drag (#41973)
Joffrey JAFFEUXd9ff033a79a3
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjsindex 8d0bbdd2976..c15a95a119b 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/index.gjs@@ -69,6 +69,7 @@ export default class WorkflowCanvas extends Component {#pendingInsertHighlights = new Set();#syncedNodeClientIds = null;#outsideClickAbort = null;+ #pendingDragPositions = new Map();#ZOOM_STEP = 0.1;#ZOOM_MIN = 0.25;#ZOOM_MAX = 4;@@ -292,7 +293,11 @@ export default class WorkflowCanvas extends Component {#reteCallbacks() {return {- onNodeDragged: (...a) => this.args.onUpdateNodePosition?.(...a),+ onNodeDragged: (clientId, position) =>+ this.#pendingDragPositions.set(clientId, {+ x: position.x,+ y: position.y,+ }),onNodePicked: () => this.selectionVersion++,onCanvasPointerDown: () => {this.selectionVersion++;@@ -302,7 +307,10 @@ export default class WorkflowCanvas extends Component {},onSelectionDragFinished: (selectionRect) =>this.#selectStickyNotesInRect(selectionRect),- onNodeDragEnd: () => this.args.onNodeDragEnd?.(),+ onNodeDragEnd: () => {+ this.#flushPendingDragPositions();+ this.args.onNodeDragEnd?.();+ },onConnectionCreated: (...a) => this.args.onCreateConnection?.(...a),onNodeDelete: (clientId) => this.args.onRemoveNodes?.([clientId]),onManualTrigger: (clientId) => this.#handleManualTrigger(clientId),@@ -312,6 +320,16 @@ export default class WorkflowCanvas extends Component {};}+ #flushPendingDragPositions() {+ if (this.#pendingDragPositions.size === 0) {+ return;+ }++ const positions = this.#pendingDragPositions;+ this.#pendingDragPositions = new Map();+ this.args.onUpdateNodePositions?.(positions);+ }+#nodes() {return this.args.nodes || [];}diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjsindex 9f575cfe744..6d3dc395b31 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs@@ -701,13 +701,13 @@ export default class WorkflowsEditor extends Component {}@action- updateNodePosition(clientId, position) {+ updateNodePositions(positions) {+ if (!positions?.size) {+ return;+ }+this.#captureUndo();- const nodes = this.formApi.get("nodes");- this.formApi.set(- "nodes",- nodes.map((n) => (n.clientId === clientId ? { ...n, position } : n))- );+ this.#applyNodePositions(positions);}@action@@ -1485,7 +1485,7 @@ export default class WorkflowsEditor extends Component {@stickyNotes={{transientData.stickyNotes}}@workflowId={{@workflow.id}}@autoArrangeRequest={{this.autoArrangeRequest}}- @onUpdateNodePosition={{this.updateNodePosition}}+ @onUpdateNodePositions={{this.updateNodePositions}}@onEditNode={{this.editNode}}@onRemoveNodes={{this.removeNodes}}@onCreateConnection={{this.createConnection}}