Azure / LogicAppsUX

https://learn.microsoft.com/azure/logic-apps
MIT License
77 stars 83 forks source link

Designer UI breaks when adding a default to switch statement #5702

Closed Andrew-Lahikainen closed 3 weeks ago

Andrew-Lahikainen commented 1 month ago

Describe the Bug with repro steps

It doesn't happen reliably, but:

  1. Create a new workflow
  2. Init a variable
  3. Switch on variable value
  4. Implement some actions for each case
  5. Add action to default case
  6. Hit save

EDIT: this seems to happen with multiple Response actions. So use a response inside the Default case and then add a Response directly after the switch statement.

EDIT2: I think this has something to do with the fact that actions get cached in some way. Often when I add an action of the same type, it will be named exactly the same as a previous action I created earlier (after renaming).

EDIT3: Sometimes hitting save multiple times can cause this too. I generally hit save 2-3 times because often any changes I make get reverted for some reason.

I think the cause might be that the runAfter property gets updated incorrectly. In my case it changed the Switch action to run after the new action inside the Default case. It even shuffled around all the actions inside the other cases.

image

What type of Logic App Is this happening in?

Standard (VSCode)

Which operating system are you using?

Windows

Are you using new designer or old designer

New Designer

Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Switch_(subdomain)": {
                "type": "Switch",
                "expression": "@toLower(triggerBody()?['subdomain'])",
                "default": {
                    "actions": {
                        "Response_(404_-_key_not_found)": {
                            "type": "Response",
                            "kind": "Http",
                            "inputs": {
                                "statusCode": 200
                            },
                            "runAfter": {
                                "Get_secret_(key1)": [
                                    "SUCCEEDED"
                                ]
                            }
                        },
                        "Terminate_(404_-_key_not_found)": {
                            "type": "Terminate",
                            "inputs": {
                                "runStatus": "Failed",
                                "runError": {
                                    "code": "404",
                                    "message": "Could not find api key in key vault"
                                }
                            },
                            "runAfter": {
                                "Response_(404_-_key_not_found)": [
                                    "SUCCEEDED"
                                ]
                            }
                        }
                    }
                },
                "cases": {
                    "Case_(dev)": {
                        "actions": {
                            "Get_secret_(key2)": {
                                "type": "ServiceProvider",
                                "inputs": {
                                    "parameters": {
                                        "secretName": "key2"
                                    },
                                    "serviceProviderConfiguration": {
                                        "connectionName": "keyVault",
                                        "operationId": "getSecret",
                                        "serviceProviderId": "/serviceProviders/keyVault"
                                    }
                                }
                            },
                            "Set_variable_(ApiKey)": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "ApiKey"
                                },
                                "runAfter": {
                                    "Get_secret_(key2)": [
                                        "SUCCEEDED"
                                    ]
                                }
                            }
                        },
                        "case": "dev"
                    },
                    "Case_(support)": {
                        "actions": {
                            "Get_secret_(key1)": {
                                "type": "ServiceProvider",
                                "inputs": {
                                    "parameters": {
                                        "secretName": "key1"
                                    },
                                    "serviceProviderConfiguration": {
                                        "connectionName": "keyVault",
                                        "operationId": "getSecret",
                                        "serviceProviderId": "/serviceProviders/keyVault"
                                    }
                                }
                            },
                            "Set_variable_(ApiKey2)": {
                                "type": "SetVariable",
                                "inputs": {
                                    "name": "ApiKey"
                                },
                                "runAfter": {
                                    "Response_(404_-_key_not_found)": [
                                        "SUCCEEDED"
                                    ]
                                }
                            },
                            "Response_(404_-_key_not_found)": {
                                "type": "Response",
                                "kind": "Http",
                                "inputs": {
                                    "statusCode": 200
                                },
                                "runAfter": {
                                    "Get_secret_(key1)": [
                                        "SUCCEEDED"
                                    ]
                                }
                            }
                        },
                        "case": "support"
                    }
                },
                "runAfter": {
                    "Initialize_variable_(ApiKey)": [
                        "SUCCEEDED"
                    ]
                }
            },
            "Initialize_variable_(ApiKey)": {
                "type": "InitializeVariable",
                "inputs": {
                    "variables": [
                        {
                            "name": "ApiKey",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {}
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "When_a_HTTP_request_is_received": {
                "type": "Request",
                "kind": "Http",
                "inputs": {
                    "method": "GET",
                    "schema": {
                        "type": "object",
                        "properties": {
                            "subdomain": {
                                "type": "string",
                                "enum": [
                                    "dev",
                                    "support"
                                ]
                            }
                        },
                        "required": [
                            "subdomain"
                        ]
                    }
                }
            }
        }
    },
    "kind": "Stateful"
}

Screenshots or Videos

No response

Browser

vscode

Additional context

No response

ccastrotrejo commented 1 month ago

Hey @Andrew-Lahikainen thanks for raising this issue. I have taken a look at your workflow definition and found out a couple of things.

I will take a look, try to repro it an see why this is happening

image
Andrew-Lahikainen commented 1 month ago

Thanks for taking a look, yeah that's my problem, there seems to be duplicates being added when I add another action of the same type even if I rename it.

I'll create a new action (let's say Response) and it will immediately inherit the name of the last Response action I used. I will then change the new Response's name (before saving). After I hit save, it will revert back to the initial name (which is the same as the previous Response action) and then it messes up the ui.

It's kinda hard to reproduce reliably, but I do encounter it quite often.

ccastrotrejo commented 1 month ago

Hi @Andrew-Lahikainen I tried to repro the issue with different types of actions and scenarios, but I wasn't able to do it. I know there was a new deployment with fixes last week, those fixes might have solved this. I will keep trying to repro it and keep this issue open for the next week. Please let me know if this keeps happening.

Andrew-Lahikainen commented 1 month ago

If I reproduce on my end next week, would it be helpful to set up a Teams meeting so you can have a look?

I have not run into the issue this week, but I have been extremely careful to not break it.

The issue stems from creating an action of the same type in the same “session” (I.e. not closing the designer tab). Have you ever encountered the problem where the new action uses the name of the last action when you create it? If you forget to rename one of these actions and then save, it will break. Usually the designer will validate the action name to prevent duplicates, but since the user doesn’t touch the name input, it seems the validation doesn’t run and allows it to be saved.

On Sat, 28 Sep 2024 at 5:17 AM, Carlos Emiliano Castro Trejo < @.***> wrote:

Hi @Andrew-Lahikainen https://github.com/Andrew-Lahikainen I tried to repro the issue with different types of actions and scenarios, but I wasn't able to do it. I know there was a new deployment with fixes last week, those fixes might have solved this. I will keep trying to repro it and keep this issue open for the next week. Please let me know if this keeps happening.

— Reply to this email directly, view it on GitHub https://github.com/Azure/LogicAppsUX/issues/5702#issuecomment-2379731868, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACQU4MIWYAL5ROFCBA7MFADZYWHJ3AVCNFSM6AAAAABOM2B62CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZZG4ZTCOBWHA . You are receiving this because you were mentioned.Message ID: @.***>

ccastrotrejo commented 1 month ago

@Andrew-Lahikainen Yes that would be great, let me know if you face it again and we can sync on a Teams meeting.

ccastrotrejo commented 1 month ago

Hi @Andrew-Lahikainen I will be closing this issue as it seems that is not happening anymore. Please let me know if its somehow is still repro on your end

Andrew-Lahikainen commented 4 weeks ago

This still happens for me

repro steps:

  1. Create new stateful workflow
  2. Create a Http request trigger
  3. Create a Initialize Variable action and change the action name to 'Initialize variable (A)', name the variable 'A', change the type to String, and assign it the value of triggerBody().
  4. Hit save
  5. Create a Initialize Variable action. You should notice that it inherits the name of the previous Initialize Variable action.
  6. Name the variable 'B' and use the same type and value as before but do not change the name of the action.
  7. Hit save.

The UI should now be messed up.

Another things I've noticed which you might want to add as separate issues:

a) The array select action automatically stringifies json values if you touch an input.

repro steps:

  1. Add a select action
  2. Switch to text mode
  3. Enter following JSON
{
 "a": {
    "aa": 1,
    "ab": true,
    "ac": "str"
  },
  "b": "str",
  "c": true
}
  1. Hit save
  2. On key value mode, click inside any input
  3. You should notice the value inside text mode got stringified:
{
 "a" : "{"aa":1,"ab":true,"ac":"str"}",
 "b" : "str",
 "c" : "true"
}

b) Pressing save after creating a Initialize variable action causes ui to look like it's loading

repro steps:

  1. Create an initialize variable action, fill out with whatever
  2. Without clicking outside the action details panel, hit save
  3. The ui should now look like it's in a loading state

c) Updating parameters.json with unsaved changes causes loss of work

repro steps:

  1. Create an Http request trigger
  2. Hit save
  3. Create any action
  4. Do not hit save
  5. Create a new parameter via parameters.json
  6. Save parameters.json
  7. Navigate back to designer
  8. Your unsaved action should be lost

d) Moving actions into a scope (and potentially for each, do until etc.) does not persist

repro steps:

  1. Create am Http request trigger
  2. Create a Scope action
  3. Create a init variable action inside Scope
  4. Create an init variable action after Scope
  5. Create another init variable action after Scope
  6. Hit save
  7. Try moving an action into the scope
  8. Hit save
  9. Try moving another action into the scope
  10. Hit save (this is where it did not persist my change during my test)
  11. Move an action outside of the scope
  12. Hit save (happened again here for me, but just try moving things around and saving each time).
ccastrotrejo commented 3 weeks ago

Hi @Andrew-Lahikainen thanks for the details, I reopend it and I will take a look at it gain.

ccastrotrejo commented 3 weeks ago

Hi @Andrew-Lahikainen. It tried to repro it but couldn't do it.

Is there any chance you can provide us your portal extension version when you open the designer? Here is a small guide on how you can do it Finding your session ID or portal extension version

ccastrotrejo commented 3 weeks ago

Here is a video on me couldn't repro it. I will take a look on the other issues as well

https://github.com/user-attachments/assets/5930a47e-6108-48db-89de-10fb357d8deb

Andrew-Lahikainen commented 3 weeks ago

I'm using vscode, testing in a workspace with custom code that was created using the wizard.

Andrew-Lahikainen commented 3 weeks ago

https://github.com/user-attachments/assets/6455fc1b-b7bb-4521-a85c-7d6660163e52

ccastrotrejo commented 3 weeks ago

ok ok, makes sense. I am able to repro the issue. I will take a look at it. Thanks!

ccastrotrejo commented 3 weeks ago

Hi @Andrew-Lahikainen this PR https://github.com/Azure/LogicAppsUX/pull/5888 will solve the initial issue and the b) issue. About the other issues:

A) - I will create a separate issue to track this. - https://github.com/Azure/LogicAppsUX/issues/5890 C) - This is expected by design for now. When user switches from the designer view into any file view and the user updates it we try to reload the content of the webview with the latest content of the files, in this case workflow.json, parameters.json, etc. There is an ongoing effort on making this smarter and keep the work done so far. Also, if the customer doesn't update any file, the work in progress will not be lost. D)- I will create a separate issue to track this. - https://github.com/Azure/LogicAppsUX/issues/5891

Thank you so much for being so proactive with letting us know all your issues, we really appreciate it.

Andrew-Lahikainen commented 3 weeks ago

Brilliant, thanks for your hard work mate!