From 9143118be2ae94bdd6075e6aaaa3c16ce74266b6 Mon Sep 17 00:00:00 2001 From: Eric Wu <95886809+Eric-B-Wu@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:32:09 -0400 Subject: [PATCH] fix(Designer): Copy Paste Fixes (#4725) * fixScopePaste * remove logs * fix test * fix tests * i forgot to update the original one --- __mocks__/workflows/Conditionals.json | 4 +-- e2e/designer/mock-copypastescope.spec.ts | 8 +++--- .../bjsworkflow/operationdeserializer.ts | 26 ++++++++++++------- .../parsers/BJSWorkflow/BJSDeserializer.ts | 9 +++++-- .../src/lib/core/utils/parameters/helper.ts | 4 +-- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/__mocks__/workflows/Conditionals.json b/__mocks__/workflows/Conditionals.json index e1822485bf8..0c968176f5d 100644 --- a/__mocks__/workflows/Conditionals.json +++ b/__mocks__/workflows/Conditionals.json @@ -46,13 +46,13 @@ { "not": { "endsWith": [ - "@{concat(concat(concat(concat())))}", + "@concat(concat(concat(concat())))", "@variables('goalOwner')" ] } }, { - "equals": [null, "@variables('goalOwner')"] + "equals": ["", "@variables('goalOwner')"] } ] } diff --git a/e2e/designer/mock-copypastescope.spec.ts b/e2e/designer/mock-copypastescope.spec.ts index c8eec0039aa..1b1a11e9db6 100644 --- a/e2e/designer/mock-copypastescope.spec.ts +++ b/e2e/designer/mock-copypastescope.spec.ts @@ -54,11 +54,11 @@ const verificationWorkflow = { and: [ { not: { - endsWith: ['@{concat(concat(concat(concat())))}', "@variables('goalOwner')"], + endsWith: ['@concat(concat(concat(concat())))', "@variables('goalOwner')"], }, }, { - equals: [null, "@variables('goalOwner')"], + equals: ['', "@variables('goalOwner')"], }, ], }, @@ -122,11 +122,11 @@ const verificationWorkflow = { and: [ { not: { - endsWith: ['@{concat(concat(concat(concat())))}', "@variables('goalOwner')"], + endsWith: ['@concat(concat(concat(concat())))', "@variables('goalOwner')"], }, }, { - equals: [null, "@variables('goalOwner')"], + equals: ['', "@variables('goalOwner')"], }, ], }, diff --git a/libs/designer/src/lib/core/actions/bjsworkflow/operationdeserializer.ts b/libs/designer/src/lib/core/actions/bjsworkflow/operationdeserializer.ts index edc8ea0f2d5..b02bc0f68c4 100644 --- a/libs/designer/src/lib/core/actions/bjsworkflow/operationdeserializer.ts +++ b/libs/designer/src/lib/core/actions/bjsworkflow/operationdeserializer.ts @@ -376,17 +376,19 @@ const updateTokenMetadataInParameters = ( const allParameters = getAllInputParameters(nodeInputs); const repetitionInfo = getRecordEntry(repetitionInfos, id) ?? { repetitionReferences: [] }; for (const parameter of allParameters) { - const segments = parameter.value; + const { value: segments, editorViewModel, type } = parameter; let error = ''; + let hasToken = false; if (segments && segments.length) { parameter.value = segments.map((segment) => { let updatedSegment = segment; if (isTokenValueSegment(segment)) { if (pasteParams) { - const result = updateScopePasteTokenMetadata(segment, pasteParams); - updatedSegment = result.updatedSegment; - error = result.error; + const { updatedTokenSegment, tokenError } = updateScopePasteTokenMetadata(segment, pasteParams); + updatedSegment = updatedTokenSegment; + error = tokenError; + hasToken = true; } return updateTokenMetadata( updatedSegment, @@ -397,20 +399,24 @@ const updateTokenMetadataInParameters = ( operations, workflowParameters, nodesMetadata, - parameter.type + type ); } return updatedSegment; }); } - if (error) { - parameter.validationErrors = [error]; + if (pasteParams) { + if (hasToken) { + parameter.preservedValue = undefined; + } + if (error) { + parameter.validationErrors = [error]; + } } - const viewModel = parameter.editorViewModel; - if (viewModel) { + if (editorViewModel) { flattenAndUpdateViewModel( repetitionInfo, - viewModel, + editorViewModel, actionNodes, triggerNodeId, nodesData, diff --git a/libs/designer/src/lib/core/parsers/BJSWorkflow/BJSDeserializer.ts b/libs/designer/src/lib/core/parsers/BJSWorkflow/BJSDeserializer.ts index f738663ab85..faaee5dcbad 100644 --- a/libs/designer/src/lib/core/parsers/BJSWorkflow/BJSDeserializer.ts +++ b/libs/designer/src/lib/core/parsers/BJSWorkflow/BJSDeserializer.ts @@ -193,8 +193,11 @@ export const buildGraphFromActions = ( for (let [runAfterAction, runAfterValue] of Object.entries(action.runAfter ?? {})) { // update the run after with the updated ids if (pasteScopeParams && action.runAfter) { - runAfterAction = pasteScopeParams.renamedNodes[runAfterAction] ?? runAfterAction; + // delete existing runAfter action first delete action.runAfter[runAfterAction]; + // get the new id from the renamed nodes + runAfterAction = pasteScopeParams.renamedNodes[runAfterAction] ?? runAfterAction; + // add the new id to the runAfter object action.runAfter[runAfterAction] = runAfterValue; } edges.push(createWorkflowEdge(runAfterAction, actionName)); @@ -494,7 +497,9 @@ export const getAllActionNames = (actions: LogicAppsV2.Actions | undefined, name } if (action.cases) { for (const [caseName, caseAction] of Object.entries(action.cases)) { - names.push(caseName); + if (includeCase) { + names.push(caseName); + } if (caseAction.actions) { names.push(...getAllActionNames(caseAction.actions, [], includeCase)); } diff --git a/libs/designer/src/lib/core/utils/parameters/helper.ts b/libs/designer/src/lib/core/utils/parameters/helper.ts index 49c69e0407e..b13ae593d9c 100644 --- a/libs/designer/src/lib/core/utils/parameters/helper.ts +++ b/libs/designer/src/lib/core/utils/parameters/helper.ts @@ -3020,7 +3020,7 @@ export const flattenAndUpdateViewModel = ( export const updateScopePasteTokenMetadata = ( valueSegment: ValueSegment, pasteParams: PasteScopeAdditionalParams -): { updatedSegment: ValueSegment; error: string } => { +): { updatedTokenSegment: ValueSegment; tokenError: string } => { let error = ''; let token = valueSegment?.token; if (token) { @@ -3069,7 +3069,7 @@ export const updateScopePasteTokenMetadata = ( } valueSegment.token = token; } - return { updatedSegment: valueSegment, error: error }; + return { updatedTokenSegment: valueSegment, tokenError: error }; }; export function updateTokenMetadata(