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

on-save plumbing for model operator #4962

Merged
merged 20 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
21 changes: 17 additions & 4 deletions packages/client/hmi-client/src/components/model/tera-model.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
@click="onReset"
:disabled="!(hasChanged && hasEditPermission)"
/>
<Button label="Save as" severity="secondary" outlined @click="onSaveAs" :disabled="!hasEditPermission" />
<Button
:label="`Save ${isWorkflow ? 'for re-use' : 'as'}`"
severity="secondary"
outlined
@click="onSaveAs"
:disabled="!hasEditPermission"
/>
<Button label="Save" @click="onSave" :disabled="!(hasChanged && hasEditPermission)" />
</aside>
</template>
Expand All @@ -64,7 +70,7 @@
:asset-type="AssetType.Model"
:initial-name="temporaryModel?.header.name"
:is-visible="showSaveModal"
:open-on-save="true"
:open-on-save="isWorkflow ? false : true"
@close-modal="showSaveModal = false"
@on-save="onModalSave"
/>
Expand Down Expand Up @@ -96,10 +102,14 @@ const props = defineProps({
featureConfig: {
type: Object as PropType<FeatureConfig>,
default: { isPreview: false } as FeatureConfig
},
isWorkflow: {
type: Boolean,
default: false
}
});

const emit = defineEmits(['close-preview']);
const emit = defineEmits(['close-preview', 'on-save']);

// Listen for the task completion event
useClientEvent(ClientEventType.TaskGollmModelCard, (event: ClientEvent<TaskResponse>) => {
Expand Down Expand Up @@ -136,8 +146,11 @@ function onSaveAs() {
}

// Save modal
function onModalSave() {
function onModalSave(event: any) {
showSaveModal.value = false;
if (props.isWorkflow) {
emit('on-save', event);
}
}

// User menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import model from '@assets/svg/operator-images/model.svg';

export interface ModelOperationState extends BaseState {
modelId: string | null;
modelConfigurationIds: string[];
}

export const ModelOperation: Operation = {
Expand All @@ -18,8 +17,7 @@ export const ModelOperation: Operation = {

initState: () => {
const init: ModelOperationState = {
modelId: null,
modelConfigurationIds: []
modelId: null
};
return init;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@
@update-state="(state: any) => emit('update-state', state)"
>
<tera-drilldown-section>
<tera-model v-if="node.state.modelId" :asset-id="node.state.modelId" />
<tera-model v-if="node.state.modelId" :asset-id="node.state.modelId" :is-workflow="true" @on-save="onSaveEvent" />
</tera-drilldown-section>
</tera-drilldown>
</template>

<script setup lang="ts">
import { cloneDeep } from 'lodash';
import { WorkflowNode } from '@/types/workflow';
import { ModelOperationState } from '@/components/workflow/ops/model/model-operation';
import TeraModel from '@/components/model/tera-model.vue';
import TeraDrilldown from '@/components/drilldown/tera-drilldown.vue';
import TeraDrilldownSection from '@/components/drilldown/tera-drilldown-section.vue';
import operator from '@/services/operator';

defineProps<{
const props = defineProps<{
node: WorkflowNode<ModelOperationState>;
}>();

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

const onSaveEvent = (event: any) => {
const state = cloneDeep(props.node.state);
state.modelId = event.id;
emit('update-state', state);

// Update the output with the new model
const output = operator.getActiveOutput(props.node);
if (!output) return;
output.state = state;
emit('update-output', output);
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<tera-model-diagram
v-if="view === ModelNodeView.Diagram"
:model="model"
:key="model.id"
:feature-config="{ isPreview: true }"
/>
<tera-model-equation v-else-if="view === ModelNodeView.Equation" :model="model" :is-editable="false" />
Expand All @@ -33,7 +34,7 @@

<script setup lang="ts">
import _ from 'lodash';
import { onMounted, ref, computed } from 'vue';
import { onMounted, ref, computed, watch } from 'vue';
import { getModel } from '@/services/model';
import { canPropagateResource } from '@/services/workflow';
import Dropdown from 'primevue/dropdown';
Expand Down Expand Up @@ -93,6 +94,16 @@ onMounted(async () => {
await getModelById(state.modelId);
}
});

watch(
() => props.node.active,
async () => {
const newModelId = props.node.outputs.find((d) => d.id === props.node.active)?.value?.[0];
if (newModelId) {
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
model.value = await getModel(newModelId);
}
}
);
</script>

<style scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
:node="node"
@append-output="(event: any) => appendOutput(node, event)"
@append-input-port="(event: any) => appendInputPort(node, event)"
@update-state="(event: any) => updateWorkflowNodeState(node, event)"
@open-drilldown="addOperatorToRoute(node.id)"
@update-state="(event: any) => updateWorkflowNodeState(node, event)"
/>
</template>
</tera-operator>
Expand Down Expand Up @@ -159,11 +159,11 @@
:downstream-operators-nav="downstreamOperatorsNav"
:spawn-animation="drilldownSpawnAnimation"
@append-output="(event: any) => appendOutput(currentActiveNode, event)"
@close="addOperatorToRoute(null)"
@select-output="(event: any) => selectOutput(currentActiveNode, event)"
@update-output="(event: any) => updateOutput(currentActiveNode, event)"
@update-state="(event: any) => updateWorkflowNodeState(currentActiveNode, event)"
@update-status="(status: OperatorStatus) => updateWorkflowNodeStatus(currentActiveNode, status)"
@select-output="(event: any) => selectOutput(currentActiveNode, event)"
@close="addOperatorToRoute(null)"
@update-output-port="(event: any) => updateOutputPort(currentActiveNode, event)"
YohannParis marked this conversation as resolved.
Show resolved Hide resolved
/>
</Teleport>
</template>
Expand Down Expand Up @@ -409,9 +409,9 @@ function selectOutput(node: WorkflowNode<any> | null, selectedOutputId: string)
saveWorkflowHandler();
}

function updateOutputPort(node: WorkflowNode<any> | null, workflowOutput: WorkflowOutput<any>) {
function updateOutput(node: WorkflowNode<any> | null, workflowOutput: WorkflowOutput<any>) {
if (!node) return;
workflowService.updateOutputPort(node, workflowOutput);
workflowService.updateOutput(node, workflowOutput);
saveWorkflowHandler();
}

Expand Down Expand Up @@ -780,7 +780,7 @@ const dist2 = (a: Position, b: Position) => (a.x - b.x) * (a.x - b.x) + (a.y - b
const threshold2 = 5.0 * 5.0;

/*
* Relink edges that have become detatched
* Relink edges that have become detached
*
* [output-port](edge source => edge target)[input-port]
*
Expand Down Expand Up @@ -1008,30 +1008,30 @@ onUnmounted(() => {

<style scoped>
.toolbar {
align-items: center;
background-color: var(--surface-transparent);
border-bottom: 1px solid var(--surface-border-light);
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0.5rem 1rem;
border-bottom: 1px solid var(--surface-border-light);
padding: var(--gap-2) var(--gap-4);
z-index: 900;
background-color: var(--surface-transparent);
}

.glass {
backdrop-filter: blur(10px);
}

.button-group {
display: flex;
align-items: center;
display: flex;
flex-direction: row;
gap: var(--gap-small);
gap: var(--gap-2);
}

.rename-workflow {
display: flex;
align-items: center;
display: flex;
flex-wrap: nowrap;
}
</style>
9 changes: 5 additions & 4 deletions packages/client/hmi-client/src/services/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,11 @@ export function getActiveOutput(node: WorkflowNode<any>) {
return node.outputs.find((o) => o.id === node.active);
}

export function updateOutputPort(node: WorkflowNode<any>, updatedOutputPort: WorkflowOutput<any>) {
let outputPort = node.outputs.find((port) => port.id === updatedOutputPort.id);
if (!outputPort) return;
outputPort = Object.assign(outputPort, updatedOutputPort);
/** Update the output of the operator */
export function updateOutput(node: WorkflowNode<any>, updatedOutput: WorkflowOutput<any>) {
let output = node.outputs.find((o) => o.id === updatedOutput.id);
if (!output) return;
output = Object.assign(output, updatedOutput);
}

// Check if the current-state matches that of the output-state.
Expand Down