|
14 | 14 | limitations under the License.
|
15 | 15 | *@
|
16 | 16 |
|
| 17 | +@namespace Synapse.Dashboard.Components |
17 | 18 | @using Json.Schema
|
18 | 19 | @using Neuroglia.Data.Infrastructure.ResourceOriented.Properties
|
19 | 20 | @using ServerlessWorkflow.Sdk
|
20 | 21 | @using ServerlessWorkflow.Sdk.Models
|
21 | 22 | @using System.Xml.Schema
|
22 | 23 | @using Synapse.Core.Infrastructure.Services
|
23 | 24 | @using System.Text.Json.Nodes
|
24 |
| -@namespace Synapse.Dashboard.Components |
25 | 25 | @inject MonacoInterop MonacoInterop
|
26 | 26 | @inject IExternalResourceProvider ExternalResourceProvider
|
27 | 27 | @inject IJsonSerializer JsonSerializer
|
|
38 | 38 | </Content>
|
39 | 39 | </Tab>
|
40 | 40 | }
|
41 |
| - <Tab Title="Text"> |
| 41 | + <Tab Title="Raw"> |
42 | 42 | <Content>
|
43 | 43 | <div class="pt-3">
|
44 | 44 | <MonacoEditor OnTextChanged="OnTextChanged" ModelName="@modelName" Document="input" />
|
|
49 | 49 |
|
50 | 50 | <Accordion class="py-3">
|
51 | 51 | <AccordionItem Title="Advanced Settings">
|
52 |
| - <Content> |
53 |
| - @if (Operators != null && Operators.Count() > 0) |
54 |
| - { |
55 |
| - <label for="operator">Select an Operator to run the Workflow:</label> |
56 |
| - <select id="operator" class="form-select" @onchange="OnSelectOperatorChanged"> |
57 |
| - <option value="">Any Operator</option> |
58 |
| - @foreach (var op in Operators) |
59 |
| - { |
60 |
| - var name = op.GetName() + "." + op.GetNamespace(); |
61 |
| - <option value="@name" selected="@(name == operatorName)">@name</option> |
62 |
| - } |
63 |
| - </select> |
64 |
| - } |
| 52 | + <Content> |
| 53 | + <div> |
| 54 | + @if (Operators != null && Operators.Count() > 0) |
| 55 | + { |
| 56 | + <label for="operator" class="fw-bolder mb-2">Run on:</label> |
| 57 | + <select id="operator" class="form-select" @onchange="(e) => SetOperator(e.Value?.ToString())"> |
| 58 | + <option value="">Any Operator</option> |
| 59 | + @foreach (var op in Operators) |
| 60 | + { |
| 61 | + var name = op.GetName() + "." + op.GetNamespace(); |
| 62 | + <option value="@name" selected="@(name == operatorName)">@name</option> |
| 63 | + } |
| 64 | + </select> |
| 65 | + } |
| 66 | + </div> |
| 67 | + <div class="mt-4"> |
| 68 | + <DictionaryEditor Title="Labels" |
| 69 | + KeyPlaceholder="Enter label key" |
| 70 | + ValuePlaceholder="Enter label value" |
| 71 | + Entries="parameters.Labels" |
| 72 | + OnAddEntry="(kvp) => AddLabel(kvp.Key, kvp.Value)" |
| 73 | + OnRemoveEntry="RemoveLabel" /> |
| 74 | + </div> |
| 75 | + <div class="mt-4"> |
| 76 | + <DictionaryEditor Title="Annotations" |
| 77 | + KeyPlaceholder="Enter annotation key" |
| 78 | + ValuePlaceholder="Enter annotation value" |
| 79 | + Entries="parameters.Annotations" |
| 80 | + OnAddEntry="(kvp) => AddAnnotation(kvp.Key, kvp.Value)" |
| 81 | + OnRemoveEntry="RemoveAnnotation" /> |
| 82 | + </div> |
65 | 83 | </Content>
|
66 | 84 | </AccordionItem>
|
67 | 85 | </Accordion>
|
|
77 | 95 |
|
78 | 96 | WorkflowDefinition? workflowDefinition;
|
79 | 97 | JsonSchema? schema;
|
80 |
| - string payload = string.Empty; |
81 | 98 | string modelName = string.Empty;
|
82 | 99 | EquatableDictionary<string, object>? input;
|
| 100 | + CreateWorkflowInstanceParameters parameters = new(); |
83 | 101 | string? operatorName;
|
84 | 102 |
|
85 | 103 | [Parameter] public WorkflowDefinition? WorkflowDefinition { get; set; }
|
86 | 104 | [Parameter] public IEnumerable<Operator> Operators { get; set; } = [];
|
87 |
| - [Parameter] public string? OperatorName { get; set; } = null; |
88 | 105 | [Parameter] public EquatableDictionary<string, object>? Input { get; set; }
|
| 106 | + [Parameter] public EquatableDictionary<string, string>? Labels { get; set; } |
| 107 | + [Parameter] public EquatableDictionary<string, string>? Annotations { get; set; } |
89 | 108 | [Parameter] public EventCallback<CreateWorkflowInstanceParameters> OnCreate { get; set; }
|
90 | 109 | [Parameter] public EventCallback<ProblemDetails> OnProblem { get; set; }
|
91 | 110 |
|
92 | 111 | void OnValueChanged(object? value)
|
93 | 112 | {
|
94 |
| - payload = value == null ? string.Empty : JsonSerializer.SerializeToText(value); |
| 113 | + parameters.Input = value == null ? string.Empty : JsonSerializer.SerializeToText(value); |
95 | 114 | }
|
96 | 115 |
|
97 | 116 | void OnTextChanged(string value)
|
98 | 117 | {
|
99 |
| - payload = value; |
| 118 | + parameters.Input = value; |
100 | 119 | }
|
101 | 120 |
|
102 | 121 | protected override async Task OnParametersSetAsync()
|
103 | 122 | {
|
104 | 123 | await base.OnParametersSetAsync();
|
105 | 124 | if (input != Input) input = Input;
|
106 |
| - if (operatorName != OperatorName) operatorName = OperatorName; |
| 125 | + if (Labels != null && Labels.Count > 0) SetLabels(Labels); |
| 126 | + else SetLabels(null); |
| 127 | + if (Annotations != null && Annotations.Count > 0) SetAnnotations(Annotations); |
| 128 | + else SetAnnotations(null); |
107 | 129 | if (workflowDefinition != WorkflowDefinition)
|
108 | 130 | {
|
109 | 131 | workflowDefinition = WorkflowDefinition;
|
|
116 | 138 | }
|
117 | 139 | }
|
118 | 140 |
|
119 |
| - protected void OnSelectOperatorChanged(ChangeEventArgs e) |
| 141 | + protected void SetLabels(EquatableDictionary<string, string>? labels) |
| 142 | + { |
| 143 | + parameters.Labels = labels != null ? [.. labels] : []; |
| 144 | + if (labels != null) operatorName = labels.TryGetValue(SynapseDefaults.Resources.Labels.Operator, out var label) ? label : null; |
| 145 | + } |
| 146 | + |
| 147 | + protected void AddLabel(string key, string value) |
| 148 | + { |
| 149 | + if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) |
| 150 | + { |
| 151 | + return; |
| 152 | + } |
| 153 | + if (parameters.Labels.ContainsKey(key)) |
| 154 | + { |
| 155 | + parameters.Labels.Remove(key); |
| 156 | + } |
| 157 | + parameters.Labels.Add(key, value); |
| 158 | + } |
| 159 | + |
| 160 | + protected void RemoveLabel(string key) |
| 161 | + { |
| 162 | + if (string.IsNullOrWhiteSpace(key)) |
| 163 | + { |
| 164 | + return; |
| 165 | + } |
| 166 | + if (parameters.Labels.ContainsKey(key)) |
| 167 | + { |
| 168 | + parameters.Labels.Remove(key); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + protected void SetOperator(string? operatorName) |
| 173 | + { |
| 174 | + if (string.IsNullOrEmpty(operatorName)) |
| 175 | + RemoveLabel(SynapseDefaults.Resources.Labels.Operator); |
| 176 | + else |
| 177 | + AddLabel(SynapseDefaults.Resources.Labels.Operator, operatorName); |
| 178 | + } |
| 179 | + |
| 180 | + protected void SetAnnotations(EquatableDictionary<string, string>? annotations) |
| 181 | + { |
| 182 | + parameters.Annotations = annotations != null ? [.. annotations] : []; |
| 183 | + } |
| 184 | + |
| 185 | + protected void AddAnnotation(string key, string value) |
| 186 | + { |
| 187 | + if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) |
| 188 | + { |
| 189 | + return; |
| 190 | + } |
| 191 | + if (parameters.Annotations.ContainsKey(key)) |
| 192 | + { |
| 193 | + parameters.Annotations.Remove(key); |
| 194 | + } |
| 195 | + parameters.Annotations.Add(key, value); |
| 196 | + } |
| 197 | + |
| 198 | + protected void RemoveAnnotation(string key) |
120 | 199 | {
|
121 |
| - operatorName = e.Value?.ToString(); |
| 200 | + if (string.IsNullOrWhiteSpace(key)) |
| 201 | + { |
| 202 | + return; |
| 203 | + } |
| 204 | + if (parameters.Annotations.ContainsKey(key)) |
| 205 | + { |
| 206 | + parameters.Annotations.Remove(key); |
| 207 | + } |
122 | 208 | }
|
123 | 209 |
|
124 | 210 | async Task OnStartAsync()
|
125 | 211 | {
|
126 | 212 | if (schema != null)
|
127 | 213 | {
|
128 |
| - var node = string.IsNullOrWhiteSpace(payload) ? null : JsonSerializer.Deserialize<JsonNode>(payload); |
| 214 | + var node = string.IsNullOrWhiteSpace(parameters.Input) ? null : JsonSerializer.Deserialize<JsonNode>(parameters.Input); |
129 | 215 | var evaluationOptions = new EvaluationOptions()
|
130 | 216 | {
|
131 | 217 | OutputFormat = OutputFormat.List
|
|
141 | 227 | }
|
142 | 228 | if (OnCreate.HasDelegate)
|
143 | 229 | {
|
144 |
| - await OnCreate.InvokeAsync(new CreateWorkflowInstanceParameters() { |
145 |
| - Input = payload, |
146 |
| - Operator = operatorName |
147 |
| - }); |
| 230 | + await OnCreate.InvokeAsync(parameters); |
148 | 231 | }
|
149 | 232 | }
|
150 | 233 |
|
|
0 commit comments