From dec5c2db891f1282e01649e05309aed9e88322fd Mon Sep 17 00:00:00 2001 From: Daniel Chang Date: Mon, 19 Aug 2024 18:09:08 -0400 Subject: [PATCH] fix menuitem generation logic --- .../hmi-client/src/services/workflow.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/client/hmi-client/src/services/workflow.ts b/packages/client/hmi-client/src/services/workflow.ts index e2f5e2d585..1dd9718db0 100644 --- a/packages/client/hmi-client/src/services/workflow.ts +++ b/packages/client/hmi-client/src/services/workflow.ts @@ -813,11 +813,27 @@ export function getNodeMenu(operationMap: Map) { const inputMap = assetToOperation(operationMap); const outputMap = operationToAsset(operationMap); - const uniqInputMap: Map = new Map(); - inputMap.forEach((menuItem, key) => uniqInputMap.set(key, _.uniqBy(menuItem, 'type'))); - - outputMap.forEach((value, key) => { - menuOptions.set(key, uniqInputMap.get(value[0]) ?? []); + // Going from + // outputMap(Operator => assetId[]) => inputMap(assetId => Operator[]) ; + // + // For example + // Calibrate => [datasetId, modelConfig] => [Validate, Simulate, DataTransform...] + outputMap.forEach((assetTypes, operationKey) => { + const check = new Set(); + const menuItems: OperatorMenuItem[] = []; + + assetTypes.forEach((assetType) => { + const availableInputOperations = inputMap.get(assetType) ?? []; + + availableInputOperations.forEach((item) => { + if (!check.has(item.type)) { + check.add(item.type); + menuItems.push(item); + } + }); + }); + menuOptions.set(operationKey, menuItems); }); + return menuOptions; }