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

#10849 Liquid syntax support for CorrelateTask #12021

Merged
merged 14 commits into from
Jun 21, 2024

Conversation

lampersky
Copy link
Contributor

fixes #10849

this is how it works:

correlateTaskLiquid.mp4

/cc @Skrypt

@hishamco
Copy link
Member

Seems there's a breaking changes

@lampersky
Copy link
Contributor Author

Seems there's a breaking changes

@hishamco no, there is not

here you have recipe from OC before that PR, and you can test it with this PR, and see that, this feature has backward compatibility

Recipe.zip

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

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

I sincerely apologize for us taking so much time here. I checked out the PR, going over old ones, and this would be quite useful.

How about other activities, see this comment? #10849 (comment)

Is triage still needed here, @Skrypt? And do you also want to review this?

@Skrypt
Copy link
Contributor

Skrypt commented Mar 14, 2024

@Piedone maybe we should take a look more often to PR marked with "need triage" on thursday meetings. I've been trying to make @sebastienros to take a look at those by marking these with that tag. I think I had no comment to add on the PR and it just needed triage.

@Piedone
Copy link
Member

Piedone commented Mar 14, 2024

Sure, please bring them up. I think we only need to triage PRs on the meeting when there's something to discuss with the wider audience (this PR is like that, then?), i.e. you as a reviewer aren't sure.

Please keep to these @lampersky:

  • Apply code suggestions directly so the reviewer doesn't have to eyeball the changes. These resolve themselves after applying them, that's fine.
  • Don't resolve other conversations so it's easier to track for the reviewer. Then, the reviewer will resolve them.
  • Feel free to mark conversations that you addressed to keep track of them with an emoji or otherwise, just don't resolve them.
  • Please keep conversations happening in line comment in those convos, otherwise communication will be a mess. If you have trouble finding them, see this video.
  • Please click "Re-request review" in the top-right corner for each reviewer when you're ready for another round of review, so they know that you're done.

@lampersky lampersky requested a review from Piedone April 7, 2024 15:07
Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

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

@MikeAlhayek @sebastienros could you please check this during the next triage too?

var value = Syntax switch {
"Liquid" => await _expressionEvaluator.EvaluateAsync(Value, workflowContext, null),
"JavaScript" => (await _scriptEvaluator.EvaluateAsync(Value, workflowContext, null))?.Trim(),
_ => null
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_ => null
_ => throw new NotSupportedException($"The syntax {Syntax} isn't supported for CorrelateTask.")

@@ -28,14 +30,25 @@ public WorkflowExpression<string> Value
set => SetProperty(value);
}

public string Syntax
{
get => GetProperty(() => "JavaScript");
Copy link
Member

Choose a reason for hiding this comment

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

Why the property name here is Synax and the value is JavaScript? Shouldn't the default value be set in the display driver instead?

Copy link
Member

Choose a reason for hiding this comment

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

For preexisting Tasks we need "JavaScript" here, so they'll continue to run without any user interaction.

Copy link
Member

Choose a reason for hiding this comment

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

If enum is used, then we don't need this

@Piedone
Copy link
Member

Piedone commented Apr 10, 2024

When you're done addressing all feedback of a review, click "Re-request review" in the top-right corner for each reviewer when you're ready for another round of review, so they know that you're done.

@lampersky lampersky requested a review from hishamco April 10, 2024 21:25
@@ -10,12 +11,16 @@ namespace OrchardCore.Workflows.Activities
public class CorrelateTask : TaskActivity<CorrelateTask>
{
private readonly IWorkflowScriptEvaluator _scriptEvaluator;
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;
private readonly IWorkflowExpressionEvaluator _expressionEvaluator;

protected readonly IStringLocalizer S;

public CorrelateTask(IWorkflowScriptEvaluator scriptEvaluator, IStringLocalizer<CorrelateTask> localizer)
public CorrelateTask(IWorkflowScriptEvaluator scriptEvaluator,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public CorrelateTask(IWorkflowScriptEvaluator scriptEvaluator,
public CorrelateTask(
IWorkflowScriptEvaluator scriptEvaluator,

document.getElementById('@Html.IdFor(x => x.Syntax)').addEventListener("change", (e) => {
const syntax = e.target.value;

if (syntax == '@WorkflowScriptSyntax.JavaScript') {
Copy link
Member

Choose a reason for hiding this comment

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

nameof() if faster than .ToString()

Suggested change
if (syntax == '@WorkflowScriptSyntax.JavaScript') {
if (syntax == '@nameof(WorkflowScriptSyntax.JavaScript)') {

<div class="form-group mb-3" asp-validation-class-for="Syntax">
<label asp-for="Syntax" class="form-label">@T["Syntax"]</label>
<select asp-for="Syntax" class="form-select">
<option value="@WorkflowScriptSyntax.JavaScript">@T["JavaScript"]</option>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<option value="@WorkflowScriptSyntax.JavaScript">@T["JavaScript"]</option>
<option value="@nameof(WorkflowScriptSyntax.JavaScript)">@T["JavaScript"]</option>

<label asp-for="Syntax" class="form-label">@T["Syntax"]</label>
<select asp-for="Syntax" class="form-select">
<option value="@WorkflowScriptSyntax.JavaScript">@T["JavaScript"]</option>
<option value="@WorkflowScriptSyntax.Liquid">@T["Liquid"]</option>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<option value="@WorkflowScriptSyntax.Liquid">@T["Liquid"]</option>
<option value="@nameof(WorkflowScriptSyntax.Liquid)">@T["Liquid"]</option>

@@ -0,0 +1,8 @@
namespace OrchardCore.Workflows.Models
Copy link
Member

Choose a reason for hiding this comment

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

Can we please use file-scope name spaces?

using System;
using OrchardCore.Workflows.Models;

namespace OrchardCore.Workflows.Helpers;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
namespace OrchardCore.Workflows.Helpers;
namespace OrchardCore.Workflows.Helpers;

document.getElementById('liquid_hint').classList.add('d-none');
document.getElementById('javascript_hint').classList.remove('d-none');
} else {
editor.setOption('mode', 'liquid');
Copy link
Member

Choose a reason for hiding this comment

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

Is this a valid value for the editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it is

<div class="form-group mb-3" asp-validation-class-for="Syntax">
<label asp-for="Syntax" class="form-label">@T["Syntax"]</label>
<select asp-for="Syntax" class="form-select">
<option value="@WorkflowScriptSyntax.JavaScript">@T["JavaScript"]</option>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<option value="@WorkflowScriptSyntax.JavaScript">@T["JavaScript"]</option>
<option value="@nameof(WorkflowScriptSyntax.JavaScript)">@T["JavaScript"]</option>

<label asp-for="Syntax" class="form-label">@T["Syntax"]</label>
<select asp-for="Syntax" class="form-select">
<option value="@WorkflowScriptSyntax.JavaScript">@T["JavaScript"]</option>
<option value="@WorkflowScriptSyntax.Liquid">@T["Liquid"]</option>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<option value="@WorkflowScriptSyntax.Liquid">@T["Liquid"]</option>
<option value="@nameof(WorkflowScriptSyntax.Liquid)">@T["Liquid"]</option>

<option value="@WorkflowScriptSyntax.Liquid">@T["Liquid"]</option>
</select>
<span asp-validation-for="Syntax"></span>
<span class="hint">@T["Choose between Liquid or JavaScript syntax."]</span>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is useful and can we removed

Suggested change
<span class="hint">@T["Choose between Liquid or JavaScript syntax."]</span>

public enum WorkflowScriptSyntax
{
JavaScript,
Liquid
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Liquid
Liquid,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will be the first enum with such convention, I've just checked and all enums in the project are without comma after last item, so I will leave it as is

Copy link
Contributor

It seems that this pull request didn't really move for quite a while. Is this something you'd like to revisit any time soon or should we close? Please comment if you'd like to pick it up.

@github-actions github-actions bot added the stale label Jun 21, 2024
@Piedone
Copy link
Member

Piedone commented Jun 21, 2024

@MikeAlhayek this is waiting for your review.

@MikeAlhayek MikeAlhayek enabled auto-merge (squash) June 21, 2024 17:15
@MikeAlhayek MikeAlhayek merged commit f95dc8a into OrchardCMS:main Jun 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Correlate Task should support Liquid AND javascript parsing with separate editors
5 participants