Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow clean up #5535

Merged
merged 11 commits into from
Nov 19, 2024
22 changes: 21 additions & 1 deletion packages/client/hmi-client/src/services/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Transform
} from '@/types/workflow';
import { useProjects } from '@/composables/project';
import useAuthStore from '@/stores/auth';
import dagre from 'dagre';

/**
Expand Down Expand Up @@ -134,7 +135,7 @@ export class WorkflowWrapper {
}
}

// New eleemnts
// New elements
[...updatedNodeMap.values()].forEach((node) => this.wf.nodes.push(node));
[...updatedEdgeMap.values()].forEach((edge) => this.wf.edges.push(edge));
}
Expand Down Expand Up @@ -211,6 +212,13 @@ export class WorkflowWrapper {
}

addNode(op: Operation, pos: Position, options: { size?: OperatorNodeSize; state?: any }) {
let currentUserName: string | undefined = '';
try {
currentUserName = useAuthStore().user?.username;
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
// do nothing
}
mwdchang marked this conversation as resolved.
Show resolved Hide resolved

const nodeSize: Size = getOperatorNodeSize(options.size ?? OperatorNodeSize.medium);

const node: WorkflowNode<any> = {
Expand All @@ -223,6 +231,9 @@ export class WorkflowWrapper {
x: pos.x,
y: pos.y,

createdBy: currentUserName,
createdAt: Date.now(),

active: null,
state: options.state ?? {},
uniqueInputs: op.uniqueInputs ?? false,
Expand Down Expand Up @@ -290,6 +301,13 @@ export class WorkflowWrapper {
*
* */
addEdge(sourceId: string, sourcePortId: string, targetId: string, targetPortId: string, points: Position[]) {
let currentUserName: string | undefined = '';
try {
currentUserName = useAuthStore().user?.username;
} catch (err) {
// do nothing
}

const sourceNode = this.wf.nodes.find((d) => d.id === sourceId);
const targetNode = this.wf.nodes.find((d) => d.id === targetId);
if (!sourceNode || !targetNode) return;
Expand Down Expand Up @@ -358,6 +376,8 @@ export class WorkflowWrapper {
sourcePortId,
target: targetId,
targetPortId,
createdBy: currentUserName,
createdAt: Date.now(),
points: _.cloneDeep(points)
};
this.wf.edges.push(edge);
Expand Down
4 changes: 4 additions & 0 deletions packages/client/hmi-client/src/types/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface WorkflowNode<S> {
workflowId: string;
isDeleted?: boolean;
version?: number;
createdBy?: string;
createdAt?: number;

displayName: string;
operationType: string;
Expand Down Expand Up @@ -128,6 +130,8 @@ export interface WorkflowEdge {
workflowId: string;
isDeleted?: boolean;
version?: number;
createdBy?: string;
createdAt?: number;

points: Position[];
source?: WorkflowNode<any>['id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class WorkflowEdge extends SupportAdditionalProperties implements Seriali
@TSIgnore
private Long version;

private String createdBy;
private Long createdAt;

private Boolean isDeleted;

private UUID source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class WorkflowNode<T> extends SupportAdditionalProperties implements Seri

private Boolean isDeleted;

private String createdBy;
private Long createdAt;

private String displayName;
private String operationType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,14 @@ public Optional<Workflow> updateAsset(
final JsonNode nodeContent = this.objectMapper.valueToTree(node);
final JsonNode dbNodeContent = this.objectMapper.valueToTree(dbNode);

// No changes, skip
if (nodeContent.equals(dbNodeContent)) {
nodeMap.remove(node.getId());
continue;
}

// FIXME: backwards compatibility for older workflows, remove in a few month.
// Aug 2024
if (dbNode.getVersion() == null) {
dbNode.setVersion(1L);
continue;
}

if (dbNode.getVersion().equals(node.getVersion())) {
// Only update if if node is not already deleted in the db
if (dbNode.getIsDeleted() == false && dbNode.getVersion().equals(node.getVersion())) {
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
node.setVersion(dbNode.getVersion() + 1L);
dbWorkflowNodes.set(index, node);
}
Expand All @@ -162,18 +157,14 @@ public Optional<Workflow> updateAsset(
final JsonNode edgeContent = this.objectMapper.valueToTree(edge);
final JsonNode dbEdgeContent = this.objectMapper.valueToTree(dbEdge);

// No changes, skip
if (edgeContent.equals(dbEdgeContent)) {
edgeMap.remove(edge.getId());
continue;
}

// FIXME: backwards compatibility for older workflows, remove in a few month.
// Aug 2024
if (dbEdge.getVersion() == null) {
dbEdge.setVersion(1L);
}

if (dbEdge.getVersion().equals(edge.getVersion())) {
// Only update if if edge is not already deleted in the db
if (dbEdge.getIsDeleted() == false && dbEdge.getVersion().equals(edge.getVersion())) {
edge.setVersion(dbEdge.getVersion() + 1L);
dbWorkflowEdges.set(index, edge);
}
Expand Down
Loading