Skip to content

Commit 834f18a

Browse files
authored
Merge pull request #14 from neuroglia-io/fix-correlations-kvp-editor
fix(Dashboard): added key value pair editor
2 parents 12be4cc + cdd6082 commit 834f18a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@namespace Synapse.Dashboard
2+
3+
<div>
4+
@if (Kvp == null)
5+
{
6+
<input class="form-control" placeholder="Key" type="text" value="@key" @onchange="e => OnPropertyChanged((editor) => editor.key = (string?)e.Value ?? string.Empty)" />
7+
}
8+
<input class="form-control" placeholder="Value" type="text" value="@value" @onchange="e => OnPropertyChanged((editor) => editor.value = (string?)e.Value ?? string.Empty)" />
9+
@if (Kvp == null)
10+
{
11+
<button class="btn btn-outline-dark" type="button" @onclick="OnAddClicked">Add</button>
12+
}
13+
</div>
14+
15+
@code {
16+
private string key = "";
17+
private string value = "";
18+
[Parameter] public KeyValuePair<string, string>? Kvp { get; set; }
19+
[Parameter] public EventCallback<KeyValuePair<string, string>> OnAdd { get; set; }
20+
[Parameter] public EventCallback<KeyValuePair<string, string>> OnChange { get; set; }
21+
22+
protected override void OnParametersSet()
23+
{
24+
if (this.Kvp.HasValue && (this.Kvp.Value.Key != this.key || this.Kvp.Value.Value != this.value))
25+
{
26+
this.key = this.Kvp.Value.Key;
27+
this.value = this.Kvp.Value.Value;
28+
}
29+
}
30+
31+
private void OnPropertyChanged(Action<KeyValuePairEditor> patch)
32+
{
33+
patch(this);
34+
this.OnChange.InvokeAsync(new KeyValuePair<string, string>(this.key, this.value));
35+
}
36+
37+
private void OnAddClicked()
38+
{
39+
this.OnAdd.InvokeAsync(new KeyValuePair<string, string>(this.key, this.value));
40+
this.key = "";
41+
this.value = "";
42+
}
43+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ else
138138
</Header>
139139
<Body>
140140
<h5>Context Attributes</h5>
141+
<KeyValuePairEditor OnAdd="((e) => OnAddOrUpdateConditionFilterAttribute(condition, filter, e.Key, e.Value))" />
141142
<table class="table table-striped">
142143
<thead>
143144
<tr>
@@ -164,6 +165,7 @@ else
164165
</table>
165166

166167
<h5>Correlation Mappings</h5>
168+
<KeyValuePairEditor OnAdd="((e) => OnAddOrUpdateConditionFilterCorrelationMapping(condition, filter, e.Key, e.Value))" />
167169
<table class="table table-striped">
168170
<thead>
169171
<tr>

0 commit comments

Comments
 (0)