From 2afb7fd07190a62f706686d287a59ea16247c13e Mon Sep 17 00:00:00 2001 From: Shawn Yama Date: Wed, 14 Aug 2024 10:52:11 -0400 Subject: [PATCH 1/6] use notebook service for code save --- .../model-config/model-config-operation.ts | 10 ++---- .../tera-model-config-drilldown.vue | 33 ++++++++----------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts b/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts index 3cd33d48fb..4d5d3cdd2e 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts @@ -1,18 +1,14 @@ import { WorkflowOperationTypes } from '@/types/workflow'; import type { Operation, BaseState } from '@/types/workflow'; import type { ModelConfiguration } from '@/types/Types'; +import { NotebookHistory } from '@/services/notebook'; import configureModel from '@assets/svg/operator-images/configure-model.svg'; export const name = 'ModelConfigOperation'; -export interface ModelEditCode { - code: string; - timestamp: number; -} - export interface ModelConfigOperationState extends BaseState { transientModelConfig: ModelConfiguration; - modelEditCodeHistory: ModelEditCode[]; + notebookHistory: NotebookHistory[]; hasCodeBeenRun: boolean; } @@ -43,7 +39,7 @@ export const ModelConfigOperation: Operation = { action: async () => ({}), initState: () => { const init: ModelConfigOperationState = { - modelEditCodeHistory: [], + notebookHistory: [], hasCodeBeenRun: false, transientModelConfig: blankModelConfig }; diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue index 837ce624f0..cadc6964f0 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue @@ -135,8 +135,7 @@ - -
+
@@ -187,11 +187,7 @@ @@ -379,7 +375,10 @@ const runFromCode = () => { if (!data.content) return; knobs.value.transientModelConfig = data.content; - if (executedCode) updateCodeState(executedCode, true); + if (executedCode) { + updateCodeState(executedCode, true); + createConfiguration(); + } }) .register('any_execute_reply', (data) => { let status = OperatorStatus.DEFAULT; From e89cae7e7a5a3461e403e0e5f3ae95988f801946 Mon Sep 17 00:00:00 2001 From: Shawn Yama Date: Wed, 14 Aug 2024 11:32:57 -0400 Subject: [PATCH 3/6] rename hasCodeBeenRun --- .../workflow/ops/model-config/model-config-operation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts b/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts index 4d5d3cdd2e..c8d2494e3b 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/model-config-operation.ts @@ -9,7 +9,7 @@ export const name = 'ModelConfigOperation'; export interface ModelConfigOperationState extends BaseState { transientModelConfig: ModelConfiguration; notebookHistory: NotebookHistory[]; - hasCodeBeenRun: boolean; + hasCodeRun: boolean; } export const blankModelConfig: ModelConfiguration = { @@ -39,9 +39,9 @@ export const ModelConfigOperation: Operation = { action: async () => ({}), initState: () => { const init: ModelConfigOperationState = { + transientModelConfig: blankModelConfig, notebookHistory: [], - hasCodeBeenRun: false, - transientModelConfig: blankModelConfig + hasCodeRun: false }; return init; } From 9d8e31b14b8d09ae1ff0db0f2b233a37f853fee9 Mon Sep 17 00:00:00 2001 From: Shawn Yama Date: Wed, 14 Aug 2024 13:17:54 -0400 Subject: [PATCH 4/6] fix prev config from being empty --- .../tera-intervention-policy-drilldown.vue | 4 +--- .../model-config/tera-model-config-drilldown.vue | 14 ++++---------- .../dataservice/ModelConfigurationController.java | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue index c993f6600a..4361001a64 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/intervention-policy/tera-intervention-policy-drilldown.vue @@ -240,10 +240,8 @@ const initialize = async () => { if (state.interventionPolicy?.id) { // copy the state into the knobs if it exists selectedPolicy.value = await getInterventionPolicyById(state.interventionPolicy.id); - knobs.value.transientInterventionPolicy = cloneDeep(state.interventionPolicy); - } else { - knobs.value.transientInterventionPolicy = cloneDeep(state.interventionPolicy); } + knobs.value.transientInterventionPolicy = cloneDeep(state.interventionPolicy); }; const applyInterventionPolicy = (interventionPolicy: InterventionPolicy) => { diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue index f8f0dc01ee..8dbe321a21 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue @@ -174,7 +174,7 @@ - + @@ -491,22 +491,19 @@ const createConfiguration = async () => { if (!model.value || isSaveDisabled.value) return; const state = cloneDeep(props.node.state); - const modelConfig = cloneDeep(knobs.value.transientModelConfig); const data = await createModelConfiguration(modelConfig); - if (!data) { logger.error('Failed to create model configuration'); return; } knobs.value.transientModelConfig = cloneDeep(data); - state.transientModelConfig = knobs.value.transientModelConfig; useToastService().success('', 'Created model configuration'); emit('append-output', { type: ModelConfigOperation.outputs[0].type, - label: state.transientModelConfig.name, + label: data.name, value: data.id, isSelected: false, state @@ -567,7 +564,6 @@ const onSelectConfiguration = (config: ModelConfiguration) => { }; const applyConfigValues = (config: ModelConfiguration) => { - const state = cloneDeep(props.node.state); knobs.value.transientModelConfig = cloneDeep(config); // Update output port: @@ -585,7 +581,7 @@ const applyConfigValues = (config: ModelConfiguration) => { // If the output does not already exist else { // Append this config to the output. - state.transientModelConfig = knobs.value.transientModelConfig; + const state = cloneDeep(props.node.state); emit('append-output', { type: ModelConfigOperation.outputs[0].type, label: config.name, @@ -613,9 +609,7 @@ const resetConfiguration = () => { message: 'This will reset all values original values of the configuration.', accept: () => { const originalConfig = suggestedConfigurationContext.value.tableData.find((c) => c.id === selectedConfigId.value); - if (originalConfig) { - applyConfigValues(originalConfig); - } + if (originalConfig) applyConfigValues(originalConfig); }, acceptLabel: 'Confirm', rejectLabel: 'Cancel' diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java index 04f6945e55..327713c982 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/ModelConfigurationController.java @@ -350,7 +350,7 @@ public ResponseEntity createModelConfiguration( } return ResponseEntity.status(HttpStatus.CREATED).body( - modelConfigurationService.createAsset(modelConfiguration, projectId, permission) + modelConfigurationService.createAsset(modelConfiguration.clone(), projectId, permission) ); } catch (final IOException e) { log.error("Unable to get model configuration from postgres db", e); From 4b7fd338bd92dce3d0a33a3cfe2cb175c98f7490 Mon Sep 17 00:00:00 2001 From: Shawn Yama Date: Wed, 14 Aug 2024 13:33:10 -0400 Subject: [PATCH 5/6] tighten --- .../ops/model-config/tera-model-config-drilldown.vue | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue index 8dbe321a21..c8c9ec8892 100644 --- a/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue +++ b/packages/client/hmi-client/src/components/workflow/ops/model-config/tera-model-config-drilldown.vue @@ -489,8 +489,6 @@ const downloadConfiguredModel = async (configuration: ModelConfiguration = knobs const createConfiguration = async () => { if (!model.value || isSaveDisabled.value) return; - - const state = cloneDeep(props.node.state); const modelConfig = cloneDeep(knobs.value.transientModelConfig); const data = await createModelConfiguration(modelConfig); @@ -506,7 +504,7 @@ const createConfiguration = async () => { label: data.name, value: data.id, isSelected: false, - state + state: cloneDeep(props.node.state) }); }; @@ -581,13 +579,12 @@ const applyConfigValues = (config: ModelConfiguration) => { // If the output does not already exist else { // Append this config to the output. - const state = cloneDeep(props.node.state); emit('append-output', { type: ModelConfigOperation.outputs[0].type, label: config.name, value: config.id, isSelected: false, - state + state: cloneDeep(props.node.state) }); } logger.success(`Configuration applied ${config.name}`); From 0cc088535e3c4e6af24e267b282c01a83cff165f Mon Sep 17 00:00:00 2001 From: Shawn Yama Date: Wed, 14 Aug 2024 14:51:14 -0400 Subject: [PATCH 6/6] update comment --- packages/client/hmi-client/src/services/notebook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/hmi-client/src/services/notebook.ts b/packages/client/hmi-client/src/services/notebook.ts index 5f8294d7fd..a250a2100a 100644 --- a/packages/client/hmi-client/src/services/notebook.ts +++ b/packages/client/hmi-client/src/services/notebook.ts @@ -9,7 +9,7 @@ export interface NotebookHistory { } // A common pattern used to save code from a notebook within an operator -// This is ready to be ported to nodes such as tera-model-config and tera-stratify-mira +// One more operator to port this to: tera-stratify-mira // Not ported yet since this will ruin the states of the nodes that already exist due to their differently named properties export const saveCodeToState = ( node: WorkflowNode,