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

Transcribe workflow-service to hmi-server - Part 1 #5979

Merged
merged 38 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6f4eaa4
transcribe selectOutput to server-side
mwdchang Jan 7, 2025
834b670
java fixes
mwdchang Jan 7, 2025
df65a54
transcribe append-output
mwdchang Jan 7, 2025
b36a68f
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 7, 2025
647f980
remove unused generic
mwdchang Jan 7, 2025
8896143
update
mwdchang Jan 7, 2025
352f3a3
controller apis
mwdchang Jan 8, 2025
9fa7ff6
improved messages
mwdchang Jan 8, 2025
ed58378
wiring
mwdchang Jan 8, 2025
c39ae47
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 8, 2025
04c77cb
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 8, 2025
182eba7
wiring up to hmi-server workflow service
mwdchang Jan 8, 2025
07ca340
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 8, 2025
0fe7c8e
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 8, 2025
6ce2214
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 8, 2025
81cd8d7
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 9, 2025
cd4e224
resolve potential conflicts with scenario templates
mwdchang Jan 9, 2025
2fcb097
uuid equals
mwdchang Jan 9, 2025
b21e6a9
plumbing
mwdchang Jan 9, 2025
7ffddb1
plumbing
mwdchang Jan 9, 2025
a2cd3f2
plumbing and clean up
mwdchang Jan 9, 2025
b3bdd36
clean up
mwdchang Jan 9, 2025
f095b76
update state when appending output, as this seems to be a very common…
mwdchang Jan 9, 2025
7d8af64
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 9, 2025
4ccf698
remove multiple edges/nodes, tombstone fix
mwdchang Jan 9, 2025
7d173fe
invalid cascade
mwdchang Jan 9, 2025
0220813
tweak computed
mwdchang Jan 9, 2025
58e831c
update
mwdchang Jan 9, 2025
ff62945
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 9, 2025
7438e5a
stratify node state bug fix
mwdchang Jan 10, 2025
41df8b8
broadcast
mwdchang Jan 10, 2025
edd9809
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 10, 2025
6447d62
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 10, 2025
e53dde1
Send SSE workflow to all users
Tom-Szendrey Jan 10, 2025
ad34520
Merge remote-tracking branch 'origin/main' into transcribe-select-wor…
mwdchang Jan 10, 2025
d413066
Merge remote-tracking branch 'origin' into transcribe-select-workflow…
mwdchang Jan 10, 2025
57f2c9a
Update packages/server/src/main/java/software/uncharted/terarium/hmis…
mwdchang Jan 10, 2025
19c9f99
better param names
mwdchang Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const props = defineProps<{
node: WorkflowNode<CompareDatasetsState>;
}>();

const emit = defineEmits(['update-state', 'update-status', 'close']);
const emit = defineEmits(['update-state', 'close']);

const compareOptions: { label: string; value: CompareValue }[] = [
{ label: 'Compare the impact of interventions', value: CompareValue.IMPACT },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ const interventionEventHandler = async (event: ClientEvent<TaskResponse>) => {
useClientEvent(ClientEventType.TaskGollmInterventionsFromDocument, interventionEventHandler);

const isLoading = computed(() => taskIds.value.length > 0);

const modelInput = props.node.inputs.find((input) => input.type === 'modelId');
const isModelInputConnected = computed(() => modelInput?.status === WorkflowPortStatus.CONNECTED);
const isModelInputConnected = ref(false);

const groupedOutputParameters = computed(() =>
Object.fromEntries(
Expand Down Expand Up @@ -97,6 +95,11 @@ watch(
const modelId = inputs.find((input) => input.type === 'modelId')?.value?.[0];
const state = cloneDeep(props.node.state);

const modelInputs = inputs.filter((input) => input.type === 'modelId');
if (modelInputs[0].status === WorkflowPortStatus.CONNECTED) {
isModelInputConnected.value = true;
}
mwdchang marked this conversation as resolved.
Show resolved Hide resolved

if (!modelId || modelId === state.interventionPolicy?.modelId) return;

// Reset previous model cache
Expand All @@ -106,7 +109,7 @@ watch(
};
emit('update-state', state);
},
{ deep: true }
{ immediate: true, deep: true }
);

watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ useClientEvent(ClientEventType.TaskGollmConfigureModelFromDataset, configModelEv

const isLoading = computed(() => modelConfigTaskIds.value.length > 0);

const modelInput = props.node.inputs.find((input) => input.type === 'modelId');
const isModelInputConnected = computed(() => modelInput?.status === WorkflowPortStatus.CONNECTED);
const isModelInputConnected = ref(false);

// Update the node with the new input ports
watch(
Expand All @@ -66,7 +65,11 @@ watch(
const documentInputs = inputs.filter((input) => input.type === 'documentId');
const datasetInputs = inputs.filter((input) => input.type === 'datasetId');
const modelInputs = inputs.filter((input) => input.type === 'modelId');
const modelId = modelInputs?.[0]?.value?.[0];
const modelId = modelInputs[0]?.value?.[0];

if (modelInputs[0].status === WorkflowPortStatus.CONNECTED) {
isModelInputConnected.value = true;
}

// If all document inputs are connected, add a new document input port
if (documentInputs.every((input) => input.status === WorkflowPortStatus.CONNECTED)) {
Expand Down Expand Up @@ -106,7 +109,7 @@ watch(
}
}
},
{ deep: true }
{ immediate: true, deep: true }
);

watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</template>

<script setup lang="ts">
import { cloneDeep } from 'lodash';
import { ref, watch } from 'vue';
import { WorkflowNode } from '@/types/workflow';
import TeraOperatorPlaceholder from '@/components/operator/tera-operator-placeholder.vue';
Expand Down Expand Up @@ -45,7 +46,11 @@ watch(
emit('append-output', {
type: StratifyMiraOperation.outputs[0].type,
label: modelName ?? 'Default Model',
value: modelId
value: modelId,
state: {
strataGroup: cloneDeep(props.node.state.strataGroup),
strataCodeHistory: cloneDeep(props.node.state.strataCodeHistory)
}
});
}
},
Expand Down
117 changes: 66 additions & 51 deletions packages/client/hmi-client/src/components/workflow/tera-workflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@
</template>

<script setup lang="ts">
import { cloneDeep, isArray, isEmpty, intersection, debounce } from 'lodash';
import { computed, onMounted, onUnmounted, ref, watch, nextTick } from 'vue';
import { cloneDeep, isArray, intersection, debounce } from 'lodash';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import TeraInfiniteCanvas from '@/components/widgets/tera-infinite-canvas.vue';
import TeraCanvasItem from '@/components/widgets/tera-canvas-item.vue';
import type { Position } from '@/types/common';
Expand Down Expand Up @@ -183,7 +183,6 @@ import { v4 as uuidv4 } from 'uuid';

import TeraProgressSpinner from '@/components/widgets/tera-progress-spinner.vue';

import { logger } from '@/utils/logger';
import { useRouter, useRoute } from 'vue-router';
import { MenuItem } from 'primevue/menuitem';
import * as EventService from '@/services/event';
Expand Down Expand Up @@ -306,7 +305,7 @@ const saveWorkflowHandler = () => {
* output as selected, and revert the selection status of
* existing outputs
* */
function appendOutput(
async function appendOutput(
node: WorkflowNode<any> | null,
port: {
type: string;
Expand All @@ -318,9 +317,6 @@ function appendOutput(
) {
if (!node) return;

// We assume that if we can produce an output, the status is okay
node.status = OperatorStatus.SUCCESS;

const uuid = uuidv4();
const outputPort: WorkflowOutput<any> = {
id: uuid,
Expand All @@ -332,18 +328,12 @@ function appendOutput(
state: port.state,
isSelected: true,
timestamp: new Date(),
operatorStatus: node.status
// We assume that if we can produce an output, the status is okay
operatorStatus: OperatorStatus.SUCCESS
};

// Append and set active
node.outputs.push(outputPort);
node.active = uuid;

// Filter out temporary outputs where value is null
node.outputs = node.outputs.filter((d) => d.value);

selectOutput(node, uuid);
saveWorkflowHandler();
const updatedWorkflow = await workflowService.appendOutput(wf.value.getId(), node.id, outputPort, node.state);
wf.value.update(updatedWorkflow, false);
}

function updateWorkflowNodeState(node: WorkflowNode<any> | null, state: any) {
Expand All @@ -358,10 +348,9 @@ function updateWorkflowNodeStatus(node: WorkflowNode<any> | null, status: Operat
saveWorkflowHandler();
}

function selectOutput(node: WorkflowNode<any> | null, selectedOutputId: string) {
if (!node) return;
wf.value.selectOutput(node, selectedOutputId);
saveWorkflowHandler();
async function selectOutput(node: WorkflowNode<any> | null, selectedOutputId: string) {
const updatedWorkflow = await workflowService.selectOutput(wf.value.getId(), node!.id, selectedOutputId);
wf.value.update(updatedWorkflow, false);
}

function updateOutput(node: WorkflowNode<any> | null, workflowOutput: WorkflowOutput<any>) {
Expand Down Expand Up @@ -402,9 +391,9 @@ const closeDrilldown = async () => {
);
};

const removeNode = (nodeId: string) => {
wf.value.removeNode(nodeId);
saveWorkflowHandler();
const removeNode = async (nodeId: string) => {
const updatedWorkflow = await workflowService.removeNodes(wf.value.getId(), [nodeId]);
wf.value.update(updatedWorkflow, false);
};

const duplicateBranch = (nodeId: string) => {
Expand Down Expand Up @@ -441,11 +430,13 @@ const cloneNoteBookSessions = async () => {

const addOperatorToWorkflow: Function =
(operator: OperatorImport, nodeSize: OperatorNodeSize = OperatorNodeSize.medium) =>
() => {
const node = wf.value.addNode(operator.operation, newNodePosition, {
async () => {
const node = workflowService.newOperator(wf.value.getId(), operator.operation, newNodePosition, {
size: nodeSize
});
saveWorkflowHandler();
const updatedWorkflow = await workflowService.addNode(wf.value.getId(), node);
wf.value.update(updatedWorkflow, false);

return node;
};

Expand All @@ -460,7 +451,7 @@ async function onMenuSelection(operatorType: string, menuNode: WorkflowNode<any>
newNodePosition.y = menuNode.y;

if (name && operation && node && drilldown) {
const newNode: WorkflowNode<any> = addOperatorToWorkflow({ name, operation, node, drilldown })();
const newNode: WorkflowNode<any> = await addOperatorToWorkflow({ name, operation, node, drilldown })();

// The split('|') is for complex types - [modelId|modelConfigId] or [datasetId|simulationId]
const portTypes = port.type.split('|');
Expand All @@ -477,15 +468,21 @@ async function onMenuSelection(operatorType: string, menuNode: WorkflowNode<any>
return;
}

// Wait for the DOM to load new node before adding edge
await nextTick();

wf.value.addEdge(menuNode.id, port.id, newNode.id, inputPorts[0].id, [
{ x: currentPortPosition.x, y: currentPortPosition.y },
{ x: currentPortPosition.x, y: currentPortPosition.y }
]);
const edgePayload: WorkflowEdge = {
id: uuidv4(),
workflowId: wf.value.getId(),
source: menuNode.id,
sourcePortId: port.id,
target: newNode.id,
targetPortId: inputPorts[0].id,
points: [
{ x: currentPortPosition.x, y: currentPortPosition.y },
{ x: currentPortPosition.x, y: currentPortPosition.y }
]
};

saveWorkflowHandler();
const updatedWorkflow = await workflowService.addEdge(wf.value.getId(), edgePayload);
wf.value.update(updatedWorkflow, false);
}
}

Expand Down Expand Up @@ -591,7 +588,7 @@ const showAddComponentMenu = () => {

const { getDragData } = useDragEvent();

function onDrop(event: DragEvent) {
async function onDrop(event: DragEvent) {
const { assetId, assetType } = getDragData('initAssetNode') as {
assetId: string;
assetType: AssetType;
Expand Down Expand Up @@ -619,7 +616,9 @@ function onDrop(event: DragEvent) {
default:
return;
}
wf.value.addNode(operation, newNodePosition, { state });
const operator = workflowService.newOperator(wf.value.getId(), operation, newNodePosition, { state });
const updatedWorkflow = await workflowService.addNode(wf.value.getId(), operator);
wf.value.update(updatedWorkflow, false);
}
}

Expand All @@ -644,7 +643,7 @@ function saveTransform(newTransform: { k: number; x: number; y: number }) {

const isCreatingNewEdge = computed(() => newEdge.value && newEdge.value.points && newEdge.value.points.length === 2);

function createNewEdge(node: WorkflowNode<any>, port: WorkflowPort, direction: WorkflowDirection) {
async function createNewEdge(node: WorkflowNode<any>, port: WorkflowPort, direction: WorkflowDirection) {
if (!isCreatingNewEdge.value) {
newEdge.value = {
id: 'new edge',
Expand All @@ -660,23 +659,38 @@ function createNewEdge(node: WorkflowNode<any>, port: WorkflowPort, direction: W
direction
};
} else {
wf.value.addEdge(
newEdge.value!.source ?? node.id,
newEdge.value!.sourcePortId ?? port.id,
newEdge.value!.target ?? node.id,
newEdge.value!.targetPortId ?? port.id,
newEdge.value!.points
);
const edgePayload: WorkflowEdge = {
id: uuidv4(),
workflowId: wf.value.getId(),
source: newEdge.value!.source ?? node.id,
sourcePortId: newEdge.value!.sourcePortId ?? port.id,
target: newEdge.value!.target ?? node.id,
targetPortId: newEdge.value!.targetPortId ?? port.id,
points: newEdge.value!.points
};
if (edgePayload.source === edgePayload.target) {
cancelNewEdge();
return;
}

const updatedWorkflow = await workflowService.addEdge(wf.value.getId(), edgePayload);
wf.value.update(updatedWorkflow, false);
cancelNewEdge();
saveWorkflowHandler();
}
}

function removeEdges(portId: string) {
async function removeEdges(portId: string) {
const edges = wf.value
.getEdges()
.filter(({ targetPortId, sourcePortId }) => targetPortId === portId || sourcePortId === portId);

const updatedWorkflow = await workflowService.removeEdges(
wf.value.getId(),
edges.map((e) => e.id)
);
wf.value.update(updatedWorkflow, false);

/*
// Build a traversal map before we do actual removal
const nodeMap = new Map<WorkflowNode<any>['id'], WorkflowNode<any>>(
wf.value.getNodes().map((node) => [node.id, node])
Expand Down Expand Up @@ -704,6 +718,7 @@ function removeEdges(portId: string) {
workflowService.cascadeInvalidateDownstream(nodeMap.get(startingNodeId) as WorkflowNode<any>, nodeCache);
}
saveWorkflowHandler();
*/
}

function onCanvasClick() {
Expand Down Expand Up @@ -856,7 +871,7 @@ const pathFn = d3
const drawPath = (v: any) => pathFn(v) as string;

const unloadCheck = () => {
saveWorkflowHandler();
workflowService.saveWorkflow(wf.value.dump());
};

const handleDrilldown = () => {
Expand Down Expand Up @@ -909,7 +924,7 @@ watch(
async (newId, oldId) => {
// Save previous workflow, if applicable
if (newId !== oldId && oldId) {
saveWorkflowHandler();
workflowService.saveWorkflow(wf.value.dump());
workflowService.setLocalStorageTransform(wf.value.getId(), canvasTransform);
}

Expand Down Expand Up @@ -955,7 +970,7 @@ onMounted(() => {
});

onUnmounted(() => {
saveWorkflowHandler();
workflowService.saveWorkflow(wf.value.dump());
if (saveTimer) {
clearInterval(saveTimer);
}
Expand Down
Loading