Skip to content

Commit 3e50e35

Browse files
committed
Applied PR comments
1 parent fe80a8a commit 3e50e35

File tree

7 files changed

+96
-43
lines changed

7 files changed

+96
-43
lines changed

src/core/Synapse.Application/Commands/Correlations/v1/V1CorrelateEventCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ public virtual async Task<IOperationResult> HandleAsync(V1CorrelateEventCommand
117117
this.Logger.LogInformation("Correlation context with id '{contextId}' successfully created", matchingContext.Id);
118118
this.Logger.LogInformation("Event successfully correlated to context with id '{contextId}'", matchingContext.Id);
119119
}
120-
else
121-
{
122-
await this.CorrelateAsync(correlation, matchingContext, command.Event, matchingFilter, cancellationToken);
123-
}
120+
await this.CorrelateAsync(correlation, matchingContext, command.Event, matchingFilter, cancellationToken);
124121
break;
125122
case V1CorrelationLifetime.Transient:
126123
matchingContext = matchingContexts.FirstOrDefault();

src/dashboard/Synapse.Dashboard/Features/Shared/KeyValuePairEditor/KeyValuePairEditor.razor

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
@namespace Synapse.Dashboard
22

3-
<tr>
4-
<td>
5-
<input type="text" value="@key" placeholder="Key" class="form-control" @onchange="e => OnPropertyChanged((editor) => editor.key = (string?)e.Value ?? string.Empty)" />
6-
</td>
7-
<td>
8-
<input class="form-control" placeholder="Value" type="text" value="@value" @onchange="e => OnPropertyChanged((editor) => editor.value = (string?)e.Value ?? string.Empty)" />
9-
</td>
10-
<td>
11-
<button class="btn btn-outline-dark" type="button" @onclick="OnAddClicked"><small class="bi bi-plus-circle"></small></button>
12-
</td>
13-
</tr>
3+
@if(Kvp == null)
4+
{
5+
<table class="table table-striped">
6+
<tbody>
7+
<tr>
8+
<td>
9+
<input class="form-control" placeholder="Key" type="text" value="@key" @onchange="e => OnPropertyChanged((editor) => editor.key = (string?)e.Value ?? string.Empty)" />
10+
</td>
11+
<td>
12+
<input class="form-control" placeholder="Value" type="text" value="@value" @onchange="e => OnPropertyChanged((editor) => editor.value = (string?)e.Value ?? string.Empty)" />
13+
</td>
14+
<td>
15+
<button class="btn btn-outline-dark" type="button" @onclick="OnAddClicked"><small class="bi bi-plus-circle"></small></button>
16+
</td>
17+
</tr>
18+
</tbody>
19+
</table>
20+
}
21+
else
22+
{
23+
<input class="form-control" placeholder="Value" type="text" value="@value" @onchange="e => OnPropertyChanged((editor) => editor.value = (string?)e.Value ?? string.Empty)" />
24+
}
25+
1426

1527
@code {
1628
private string key = "";
@@ -40,4 +52,4 @@
4052
this.key = "";
4153
this.value = "";
4254
}
43-
}
55+
}

src/dashboard/Synapse.Dashboard/Features/Shared/PublishEventModal/PublishEventModal.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
private ExtensionAttribute extensionAttribute = new();
120120

121121
private V1Event? cloudEvent;
122-
[Parameter] public V1Event? CloudEvent{ get; set; }
122+
[Parameter] public V1Event? CloudEvent { get; set; }
123123

124124
protected override async Task OnParametersSetAsync()
125125
{
@@ -145,7 +145,7 @@
145145
private async Task OnPayloadEditorInit(MonacoEditorBase editor)
146146
{
147147
await this.SetPayloadEditorLanguageAsync();
148-
var text = "{ }";
148+
var text = "{}";
149149
if (this.cloudEvent?.Data != null)
150150
text = await this.JsonSerializer.SerializeAsync(this.cloudEvent.Data);
151151
if (this.MonacoEditorHelper.PreferedLanguage == PreferedLanguage.YAML)

src/dashboard/Synapse.Dashboard/Pages/Correlations/Create/View.razor

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ else
114114
<h5>Condition @(conditionIndex + 1)</h5>
115115
</div>
116116
<div class="col-2">
117-
<button @onclick="e => OnRemoveCondition(condition)" title="Remove condition" class="btn btn-danger d-flex ms-auto"><span class="bi bi-trash-fill"></span></button>
117+
<button @onclick="e => OnRemoveCondition(condition)" title="Remove condition" class="btn btn-danger d-flex ms-auto"><small class="bi bi-trash-fill"></small></button>
118118
</div>
119119
</div>
120120
</Header>
121121
<Body>
122122
<div title="The filters the correlation condition is made out of">
123-
<h6>Filters</h6>
123+
<h5>Filters</h5>
124124
@for (int j = 0; j < condition.Filters.Count; j++)
125125
{
126126
var filterIndex = j;
@@ -129,65 +129,55 @@ else
129129
<Header>
130130
<div class="row">
131131
<div class="col-10">
132-
Filter @(filterIndex + 1)
132+
<h6>Filter @(filterIndex + 1)</h6>
133133
</div>
134134
<div class="col-2">
135-
<button @onclick="e => OnRemoveFilterFromCondition(condition, filter)" title="Remove filter" class="btn btn-danger d-flex ms-auto"><span class="bi bi-trash-fill"></span></button>
135+
<button @onclick="e => OnRemoveFilterFromCondition(condition, filter)" title="Remove filter" class="btn btn-danger d-flex ms-auto"><small class="bi bi-trash-fill"></small></button>
136136
</div>
137137
</div>
138138
</Header>
139139
<Body>
140-
<h5>Context Attributes</h5>
140+
<b>Context Attributes</b>
141+
<KeyValuePairEditor OnAdd="((e) => OnAddOrUpdateConditionFilterAttribute(condition, filter, e.Key, e.Value))" />
142+
<hr />
141143
<table class="table table-striped">
142-
<thead>
143-
<tr>
144-
<th>Attribute</th>
145-
<th>Value</th>
146-
</tr>
147-
</thead>
148144
<tbody>
149145
@if (filter.Attributes != null
150146
&& filter.Attributes.Any())
151147
{
152148
foreach (var attr in filter.Attributes)
153149
{
154150
<tr>
155-
<td>@attr.Key</td>
151+
<td><input type="text" value="@attr.Key" readonly class="form-control" /></td>
156152
<td>
157-
<input type="text" value="@attr.Value" @onchange="e => OnAddOrUpdateConditionFilterAttribute(condition, filter, attr.Key, (string)e.Value!)" placeholder="Value" title="The value of the context attribute to filter events by. Supports regular expressions" class="form-control" />
153+
<KeyValuePairEditor Kvp="attr" OnChange="((e) => OnAddOrUpdateConditionFilterAttribute(condition, filter, attr.Key, e.Value))" />
158154
</td>
159155
<td><button @onclick="e => OnRemoveAttributeFromConditionFilter(condition, filter, attr.Key)" class="btn btn-danger"><small class="bi bi-trash-fill"></small></button></td>
160156
</tr>
161157
}
162158
}
163-
<KeyValuePairEditor OnAdd="((e) => OnAddOrUpdateConditionFilterAttribute(condition, filter, e.Key, e.Value))" />
164159
</tbody>
165160
</table>
166161

167-
<h5>Correlation Mappings</h5>
162+
<b>Correlation Mappings</b>
163+
<KeyValuePairEditor OnAdd="((e) => OnAddOrUpdateConditionFilterCorrelationMapping(condition, filter, e.Key, e.Value))" />
164+
<hr />
168165
<table class="table table-striped">
169-
<thead>
170-
<tr>
171-
<th>Attribute</th>
172-
<th>Value</th>
173-
</tr>
174-
</thead>
175166
<tbody>
176167
@if (filter.CorrelationMappings != null
177168
&& filter.CorrelationMappings.Any())
178169
{
179170
foreach (var mapping in filter.CorrelationMappings)
180171
{
181172
<tr>
182-
<td>@mapping.Key</td>
173+
<td><input type="text" value="@mapping.Key" readonly class="form-control" /></td>
183174
<td>
184-
<input type="text" value="@mapping.Value" @onchange="e => OnAddOrUpdateConditionFilterCorrelationMapping(condition, filter, mapping.Key, (string)e.Value!)" placeholder="Value" title="The value of the context attribute used to correlate filtered cloud events. Supports regular expressions" class="form-control" />
175+
<KeyValuePairEditor Kvp="mapping" OnChange="((e) => OnAddOrUpdateConditionFilterCorrelationMapping(condition, filter, mapping.Key, e.Value))" />
185176
</td>
186177
<td><button @onclick="e => OnRemoveCorrelationMappingFromConditionFilter(condition, filter, mapping.Key)" class="btn btn-danger"><small class="bi bi-trash-fill"></small></button></td>
187178
</tr>
188179
}
189180
}
190-
<KeyValuePairEditor OnAdd="((e) => OnAddOrUpdateConditionFilterCorrelationMapping(condition, filter, e.Key, e.Value))" />
191181
</tbody>
192182
</table>
193183
</Body>

src/dashboard/Synapse.Dashboard/Pages/Correlations/View/Actions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public ShowPublishCloudEventModal(V1CorrelationCondition condition)
9494
}
9595
foreach (var attribute in filter.CorrelationMappings)
9696
{
97+
if (e.Attributes.ContainsKey(attribute.Key) && string.IsNullOrWhiteSpace(attribute.Value)) continue;
9798
e.SetAttribute(attribute.Key, attribute.Value);
9899
}
99100
}
@@ -129,6 +130,36 @@ public HidePublishCloudEventModal(bool reset = false)
129130

130131
}
131132

133+
/// <summary>
134+
/// Represents the Flux action used to delete an existing <see cref="V1Correlation"/>
135+
/// </summary>
136+
public class DeleteCorrelation
137+
{
138+
139+
/// <summary>
140+
/// Initializes a new <see cref="DeleteCorrelation"/>
141+
/// </summary>
142+
/// <param name="correlationId">The id of the <see cref="V1Correlation"/> to delete</param>
143+
public DeleteCorrelation(string correlationId)
144+
{
145+
this.CorrelationId = correlationId;
146+
}
147+
148+
/// <summary>
149+
/// Gets the id of the <see cref="V1Correlation"/> to delete
150+
/// </summary>
151+
public string CorrelationId { get; }
152+
153+
}
154+
155+
/// <summary>
156+
/// Represents the Flux action used to handle the differed result of a <see cref="DeleteCorrelation"/> action
157+
/// </summary>
158+
public class HandleDeleteCorrelationResult
159+
{
160+
161+
}
162+
132163
/// <summary>
133164
/// Represents the Flux action used to delete a <see cref="V1Correlation"/>'s <see cref="V1CorrelationContext"/>
134165
/// </summary>

src/dashboard/Synapse.Dashboard/Pages/Correlations/View/Effects.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
using Microsoft.AspNetCore.Components;
1718
using Neuroglia.Data.Flux;
1819
using Synapse.Apis.Management;
1920

@@ -46,6 +47,27 @@ public static async Task On(GetCorrelationById action, IEffectContext context)
4647
}
4748
}
4849

50+
/// <summary>
51+
/// Handles the specified <see cref="DeleteCorrelation"/>
52+
/// </summary>
53+
/// <param name="action">The <see cref="DeleteCorrelation"/> to handle</param>
54+
/// <param name="context">The current <see cref="IEffectContext"/></param>
55+
/// <returns>A new awaitable <see cref="Task"/></returns>
56+
public static async Task On(DeleteCorrelation action, IEffectContext context)
57+
{
58+
var api = context.Services.GetRequiredService<ISynapseManagementApi>();
59+
try
60+
{
61+
await api.DeleteCorrelationAsync(action.CorrelationId);
62+
context.Dispatcher.Dispatch(new HandleDeleteCorrelationResult());
63+
context.Services.GetRequiredService<NavigationManager>().NavigateTo("/correlations");
64+
}
65+
catch (Exception ex)
66+
{
67+
context.Services.GetRequiredService<ILogger<GetCorrelationById>>().LogError("An error occured while deleting the correlation with id '{correlationId}': {ex}", action.CorrelationId, ex);
68+
}
69+
}
70+
4971
/// <summary>
5072
/// Handles the specified <see cref="DeleteCorrelationContext"/>
5173
/// </summary>

src/dashboard/Synapse.Dashboard/Pages/Correlations/View/View.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ else
347347

348348
private void OnDeleteCorrelation()
349349
{
350-
350+
if (this.correlation == null) return;
351+
this.Dispatcher.Dispatch(new DeleteCorrelation(this.correlation.Id));
351352
}
352353

353354
private void OnDeleteCorrelationContext(V1CorrelationContext context)

0 commit comments

Comments
 (0)