Skip to content

Commit

Permalink
better workflow save/update timing (#4490)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwdchang authored Aug 19, 2024
1 parent 9706adb commit 0c4d361
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defineProps<{
style: { width: string; top: string; left: string };
}>();
const emit = defineEmits(['dragging']);
const emit = defineEmits(['dragging', 'dragstart', 'dragend']);
const canvasItem = ref();
Expand All @@ -28,6 +28,7 @@ const startDrag = (evt: MouseEvent) => {
tempX = evt.x;
tempY = evt.y;
isDragging = true;
emit('dragstart');
};
const drag = (evt: MouseEvent) => {
Expand All @@ -46,6 +47,7 @@ const stopDrag = (/* evt: MouseEvent */) => {
tempX = 0;
tempY = 0;
isDragging = false;
emit('dragend');
};
onMounted(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@
top: `${node.y}px`,
left: `${node.x}px`
}"
@dragstart="nodeDragging = true"
@dragging="(event) => updatePosition(node, event)"
@dragend="nodeDragging = false"
>
<tera-operator
ref="teraOperatorRefs"
Expand Down Expand Up @@ -256,6 +258,7 @@ let currentPortPosition: Position = { x: 0, y: 0 };
let isMouseOverPort: boolean = false;
let saveTimer: any = null;
const nodeDragging = ref<boolean>(false);
let workflowDirty: boolean = false;
let startTime: number = 0;
Expand Down Expand Up @@ -880,10 +883,13 @@ const handleDrilldown = () => {
};
watch(
() => [props.assetId],
async () => {
// Save previous location
setLocalStorageTransform(wf.value.getId(), canvasTransform);
() => props.assetId,
async (newId, oldId) => {
if (newId !== oldId && oldId) {
// Save previous
if (workflowDirty) workflowService.updateWorkflow(wf.value.dump());
setLocalStorageTransform(wf.value.getId(), canvasTransform);
}
isRenamingWorkflow.value = false; // Closes rename input if opened in previous workflow
if (wf.value && workflowDirty) {
Expand Down Expand Up @@ -918,7 +924,7 @@ onMounted(() => {
document.addEventListener('mousemove', mouseUpdate);
window.addEventListener('beforeunload', unloadCheck);
saveTimer = setInterval(async () => {
if (workflowDirty && useProjects().hasEditPermission()) {
if (workflowDirty && useProjects().hasEditPermission() && nodeDragging.value === false) {
const updated = await workflowService.updateWorkflow(wf.value.dump());
wf.value.update(updated);
workflowDirty = false;
Expand Down

0 comments on commit 0c4d361

Please sign in to comment.