Skip to content

Commit

Permalink
feat(ui): enable multiples move in workflow - WF-148
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Dec 20, 2024
1 parent 2ccf662 commit f478b11
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ui/src/builder/builderManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, ref, Ref, watch } from "vue";
import { computed, ref, Ref } from "vue";
import { Component, ClipboardOperation } from "@/writerTypes";

export const CANDIDATE_CONFIRMATION_DELAY_MS = 1500;
Expand Down
18 changes: 13 additions & 5 deletions src/ui/src/builder/useComponentActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,11 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
if (!component) return;

const transactionId = `change-${componentId}-coordinates`;
ssbm.openMutationTransaction(transactionId, "Change coordinates", false);
ssbm.openMutationTransaction(
transactionId,
"Change coordinates",
false,
);
ssbm.registerPreMutation(component);

component.x = Math.floor(x);
Expand All @@ -821,14 +825,18 @@ export function useComponentActions(wf: Core, ssbm: BuilderManager) {
* Change the coordinates of multiple components.
*/
function changeCoordinatesMultiple(
coordinates: Record<Component["id"], {x: number, y: number}>
coordinates: Record<Component["id"], { x: number; y: number }>,
) {
const transactionId = "change-multiple-coordinates";
ssbm.openMutationTransaction(transactionId, "Change coordinates", false);
ssbm.openMutationTransaction(
transactionId,
"Change coordinates",
false,
);

const entries = Object.entries(coordinates);
const entries = Object.entries(coordinates);
if (entries.length == 0) return;
entries.forEach(([componentId, {x, y}]) => {
entries.forEach(([componentId, { x, y }]) => {
const component = wf.getComponentById(componentId);
if (!component) return;
ssbm.registerPreMutation(component);
Expand Down
41 changes: 29 additions & 12 deletions src/ui/src/components/workflows/WorkflowsWorkflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
:is-selected="selectedArrow == arrowId"
:is-engaged="
selectedArrow == arrowId ||
wfbm.isComponentIdSelected(arrow.fromNodeId) ||
wfbm.isComponentIdSelected(arrow.toNodeId)
wfbm.getSelectedId() == arrow.fromNodeId ||
wfbm.getSelectedId() == arrow.toNodeId
"
@click="handleArrowClick($event, arrowId)"
@delete="handleArrowDeleteClick(arrow)"
Expand Down Expand Up @@ -137,6 +137,7 @@ import {
onMounted,
onUnmounted,
ref,
shallowRef,

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.9)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.9)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.9)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.10)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.11)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.11)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.11)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.12)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.12)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 140 in src/ui/src/components/workflows/WorkflowsWorkflow.vue

View workflow job for this annotation

GitHub Actions / build (3.12)

'shallowRef' is defined but never used. Allowed unused vars must match /^_/u
} from "vue";
import { useComponentActions } from "@/builder/useComponentActions";
import { useDragDropComponent } from "@/builder/useDragDropComponent";
Expand Down Expand Up @@ -170,7 +171,6 @@ const {
createAndInsertComponent,
addOut,
removeOut,
changeCoordinates,
changeCoordinatesMultiple,
} = useComponentActions(wf, wfbm);
const { getComponentInfoFromDrag } = useDragDropComponent(wf);
Expand Down Expand Up @@ -484,12 +484,8 @@ function clearActiveOperations() {
}
function saveNodeMove() {
const { nodeId } = activeNodeMove.value;
const tempXY = temporaryNodeCoordinates.value?.[nodeId];
if (!tempXY) return;
const { x, y } = tempXY;
changeCoordinates(nodeId, x, y);
temporaryNodeCoordinates.value[nodeId] = null;
changeCoordinatesMultiple(temporaryNodeCoordinates.value);
temporaryNodeCoordinates.value = {};
}
function moveNode(ev: MouseEvent) {
Expand All @@ -500,9 +496,30 @@ function moveNode(ev: MouseEvent) {
const newX = Math.floor(x - offset.x);
const newY = Math.floor(y - offset.y);
temporaryNodeCoordinates.value[nodeId] = {
x: newX,
y: newY,
const component = wf.getComponentById(nodeId);
const translationX = newX - component.x;
const translationY = newY - component.y;
// apply the same vector to other selected components
const otherSelectedComponents = wfbm
.getSelection()
.map((c) => wf.getComponentById(c.componentId))
.filter(
(c) => c.id !== nodeId && c.x !== undefined && c.y !== undefined,
)
.reduce<Record<string, { x: number; y: number }>>((acc, component) => {
acc[component.id] = {
x: component.x + translationX,
y: component.y + translationY,
};
return acc;
}, {});
temporaryNodeCoordinates.value = {
...temporaryNodeCoordinates.value,
...otherSelectedComponents,
[nodeId]: { x: newX, y: newY },
};
}
Expand Down

0 comments on commit f478b11

Please sign in to comment.