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

App: Allow interpolation string as the only value on input-code interface #22318

Conversation

joselcvarela
Copy link
Member

Scope

When using Flows, there's cases that we just want to pass the response from previous operation to the next one.
For example, we might want to pass the payload of a Read Date operation to another flow using Trigger Flow operation.
For such cases we should be able to pass the following into the Payload option of Trigger Flow operation:

{{ $last }}

Although, the Code interface will complain because the Payload option is defined as JSON and this value is not a valid JSON so the linter will show an error.
Since this is a valid action to do (to pass {{ $last }}), in this PR we ignore the lint if the value is an interpolation, i.e., if the value starts with {{ and ends with }}.

What's changed:

  • Allow interpolation at root level of Code interface using JSON language

Potential Risks / Drawbacks

  • If the value used is not an interpolation but anything that starts with {{ and ends with }}, there will be no errors

Review Notes / Questions

  • This seems to be a nice first approach to this. Although we should also be able to validate the payload on the API. I have not did it since I didn't found any example on how to validate requests according to the entity.
    For example, we could try add some validation into OperationsService but the App send the operation data within a flow which will be handled by FlowService so no validation would be made

Comparision

Before After
Screen.Recording.2024-04-25.at.19.07.03.mov
Screen.Recording.2024-04-25.at.19.06.03.mov
In this case you can see that when using {{$last}} the Code interface shows an error. Although the Flow works as expected. When I type "{{ $last }}" the Flow throws an error. In this case you can see that using {{$last}} does not show any error any more and Flow works as expected. Although when typing "{{ $last }}" it will still throw an error as " are not removed and Flow will have double quotes conflicting.

Fixes #21263

Copy link

changeset-bot bot commented Apr 25, 2024

🦋 Changeset detected

Latest commit: 915abeb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@directus/app Patch
@directus/api Patch
directus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@paescuj paescuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only applicable in context of Flows, we should add an option to the interface that allows us to control this behavior.

app/src/interfaces/input-code/input-code.vue Outdated Show resolved Hide resolved
@paescuj
Copy link
Member

paescuj commented Apr 26, 2024

@joselcvarela Had another idea: How about auto switching to raw editor if a plain interpolation string is detected? Then we wouldn't have to touch the input-code interface and it might make it a bit clearer for the user.

@paescuj paescuj self-assigned this Apr 28, 2024
joselcvarela and others added 2 commits May 3, 2024 13:54
This is useful when want to pass the previous payload of an operation to the next operation within Flows
@paescuj paescuj force-pushed the app/interfaces/code/allow-root-interpolation branch from 5a6071d to b561a89 Compare May 3, 2024 12:59
Copy link
Member

@paescuj paescuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as intended 🚀

(On my previous idea: Would be a bigger changeover as the code interface currently only emits when value is valid... Not worth it at the moment.)

@paescuj paescuj enabled auto-merge (squash) May 3, 2024 13:05
@paescuj paescuj merged commit 4de6079 into directus:main May 3, 2024
4 checks passed
@github-actions github-actions bot added this to the Next Release milestone May 3, 2024
@joselcvarela joselcvarela deleted the app/interfaces/code/allow-root-interpolation branch May 6, 2024 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Code block in "trigger flow" sends variable with quotes
2 participants