Skip to content

Commit 5d79af6

Browse files
committed
feat: add code editor to properly display json
1 parent 9055656 commit 5d79af6

File tree

5 files changed

+88
-57
lines changed

5 files changed

+88
-57
lines changed

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Amazon.Lambda.TestTool.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
2020
<PackageReference Include="Blazored.Modal" Version="7.3.1" />
2121
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.11" />
22+
<PackageReference Include="BlazorMonaco" Version="3.2.0" />
2223
</ItemGroup>
2324

2425
<ItemGroup>

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Components/App.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<Routes @rendermode="InteractiveServer" />
1717
<script src="_framework/blazor.web.js"></script>
1818
<script src="bootstrap/js/bootstrap.bundle.min.js"></script>
19+
<script src="_content/BlazorMonaco/jsInterop.js"></script>
20+
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js"></script>
21+
<script src="_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js"></script>
1922
</body>
2023

2124
</html>

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Components/Pages/Home.razor

Lines changed: 75 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,40 @@
2323
</div>
2424

2525
<div class="row">
26-
<div class="col-sm-6">
27-
<h3>Queue Event:</h3>
28-
<label class="" for="sample-requests">Example Requests:</label>
29-
<select class="control" id="sample-requests" @bind="SelectedSampleRequestName">
30-
<option id="@NO_SAMPLE_SELECTED_ID"> -- select a request -- </option>
31-
@if (@SampleRequests.ContainsKey(SampleRequestManager.SavedRequestGroup))
32-
{
33-
<optgroup id="saved-select-request-group" label="@SampleRequestManager.SavedRequestGroup">
34-
@foreach (var request in SampleRequests[SampleRequestManager.SavedRequestGroup])
35-
{
36-
<option value="@request.Filename">@request.Name</option>
37-
}
38-
</optgroup>
39-
}
40-
@foreach (var group in SampleRequests.Keys)
41-
{
42-
@if (!string.Equals(group, SampleRequestManager.SavedRequestGroup))
26+
<div class="col-sm-6 gap-2 d-flex flex-column">
27+
<h4>Queue Event</h4>
28+
<div class="form-floating">
29+
<select class="form-select" id="sample-requests" @bind="SelectedSampleRequestName">
30+
<option value="@NoSampleSelectedId">Select a request</option>
31+
@if (@SampleRequests.ContainsKey(SampleRequestManager.SavedRequestGroup))
4332
{
44-
<optgroup label="@group">
45-
@foreach (var request in SampleRequests[group])
33+
<optgroup id="saved-select-request-group" label="@SampleRequestManager.SavedRequestGroup">
34+
@foreach (var request in SampleRequests[SampleRequestManager.SavedRequestGroup])
4635
{
4736
<option value="@request.Filename">@request.Name</option>
4837
}
4938
</optgroup>
5039
}
51-
}
52-
</select>
53-
<label class="col-xs-3 control-label" for="function-payload">Function Input:</label>
54-
<textarea class="form-control" style="margin: 5px" rows="20" @bind="FunctionInput" placeholder="JSON document as input to Lambda Function. Plain strings must be wrapped in quotes."></textarea>
55-
<div class="col-sm form-group">
40+
@foreach (var group in SampleRequests.Keys)
41+
{
42+
@if (!string.Equals(group, SampleRequestManager.SavedRequestGroup))
43+
{
44+
<optgroup label="@group">
45+
@foreach (var request in SampleRequests[group])
46+
{
47+
<option value="@request.Filename">@request.Name</option>
48+
}
49+
</optgroup>
50+
}
51+
}
52+
</select>
53+
<label for="sample-requests">Example Requests</label>
54+
</div>
55+
<div class="mt-1">
56+
<label class="form-label" for="function-payload">Function Input</label>
57+
<StandaloneCodeEditor @ref="_editor" ConstructionOptions="EditorConstructionOptions" CssClass="rounded-4 overflow-hidden border"/>
58+
</div>
59+
<div class="form-group">
5660
<button class="btn btn-primary btn-sm" @onclick="OnAddEventClick">Queue Event</button>
5761
</div>
5862
</div>
@@ -66,7 +70,7 @@
6670
{
6771
<div>
6872
<div style="cursor: pointer" @onclick="() => OnRequeue(RuntimeApiModel.ActiveEvent.AwsRequestId)">
69-
@((MarkupString)REBOOT_ICON)
73+
@((MarkupString)RebootIcon)
7074
</div>
7175
<p><b>Request ID:</b> @RuntimeApiModel.ActiveEvent.AwsRequestId</p>
7276
<p><b>Status:</b> <span style="@GetStatusStyle(RuntimeApiModel.ActiveEvent.EventStatus)">@RuntimeApiModel.ActiveEvent.EventStatus</span></p>
@@ -106,7 +110,7 @@
106110
<div class="event-label">Last Updated:</div><div class="event-value">@evnt.LastUpdated</div>
107111
</div>
108112
<div class="col-sm-1 " style="cursor: pointer" @onclick="() => OnDeleteEvent(evnt.AwsRequestId)">
109-
@((MarkupString)CLOSE_ICON)
113+
@((MarkupString)CloseIcon)
110114
</div>
111115
</div>
112116
<div class="row" style="padding: 2px">
@@ -124,15 +128,15 @@
124128
<div class="event-list-item">
125129
<div class="row" style="padding: 2px">
126130
<div class="col-sm-1 " style="cursor: pointer" @onclick="() => OnRequeue(evnt.AwsRequestId)">
127-
@((MarkupString)REBOOT_ICON)
131+
@((MarkupString)RebootIcon)
128132
</div>
129133
<div class="col-sm-10 row">
130134
<div class="event-label">Request ID:</div><div class="event-value"> @evnt.AwsRequestId</div>
131135
<div class="event-label">Status:</div><div class="event-value" style="@GetStatusStyle(evnt.EventStatus)">@evnt.EventStatus</div>
132136
<div class="event-label">Last Updated:</div><div class="event-value">@evnt.LastUpdated</div>
133137
</div>
134138
<div class="col-sm-1 " style="cursor: pointer" @onclick="() => OnDeleteEvent(evnt.AwsRequestId)">
135-
@((MarkupString)CLOSE_ICON)
139+
@((MarkupString)CloseIcon)
136140
</div>
137141
</div>
138142
<div class="row" style="padding: 2px">
@@ -163,21 +167,23 @@
163167

164168

165169
@code {
166-
private const string REBOOT_ICON = @"
170+
private StandaloneCodeEditor _editor = null!;
171+
172+
private const string RebootIcon = @"
167173
<svg xmlns=""http://www.w3.org/2000/svg"" width=""16"" height=""16"" fill=""currentColor"" class=""bi bi-bootstrap-reboot"" viewBox=""0 0 16 16"">
168174
<path d=""M1.161 8a6.84 6.84 0 1 0 6.842-6.84.58.58 0 1 1 0-1.16 8 8 0 1 1-6.556 3.412l-.663-.577a.58.58 0 0 1 .227-.997l2.52-.69a.58.58 0 0 1 .728.633l-.332 2.592a.58.58 0 0 1-.956.364l-.643-.56A6.812 6.812 0 0 0 1.16 8z""/>
169175
</svg>
170176
";
171177

172-
private const string CLOSE_ICON = @"
178+
private const string CloseIcon = @"
173179
<svg xmlns=""http://www.w3.org/2000/svg"" width=""16"" height=""16"" fill=""currentColor"" class=""bi bi-x"" viewBox=""0 0 16 16"">
174180
<path d=""M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z""/>
175181
</svg>
176182
";
177183

178184
[CascadingParameter] public IModalService Modal { get; set; } = default!;
179185

180-
private const string NO_SAMPLE_SELECTED_ID = "void-select-request";
186+
private const string NoSampleSelectedId = "void-select-request";
181187

182188
private string FunctionInput { get; set; } = "";
183189

@@ -186,22 +192,25 @@
186192
string? _selectedSampleRequestName;
187193
string? SelectedSampleRequestName
188194
{
189-
get => this._selectedSampleRequestName;
195+
get => _selectedSampleRequestName;
190196
set
191197
{
192198
if (SampleRequestManager == null)
193199
return;
194200

195-
this._selectedSampleRequestName = value;
196-
if (string.IsNullOrEmpty(this._selectedSampleRequestName))
201+
_selectedSampleRequestName = value;
202+
if (string.IsNullOrEmpty(_selectedSampleRequestName) ||
203+
string.Equals(value, NoSampleSelectedId))
197204
{
198-
this.FunctionInput = string.Empty;
205+
FunctionInput = string.Empty;
199206
}
200-
else if (!string.Equals(value, NO_SAMPLE_SELECTED_ID))
207+
else
201208
{
202-
this.FunctionInput = SampleRequestManager.GetRequest(this._selectedSampleRequestName);
209+
FunctionInput = SampleRequestManager.GetRequest(_selectedSampleRequestName);
203210
}
204-
this.StateHasChanged();
211+
212+
_editor.SetValue(FunctionInput);
213+
StateHasChanged();
205214
}
206215
}
207216

@@ -210,58 +219,58 @@
210219
protected override void OnInitialized()
211220
{
212221
RuntimeApiModel.StateChange += RuntimeApiModelOnStateChange;
213-
this.SampleRequestManager = new SampleRequestManager(DirectoryManager.GetCurrentDirectory());
214-
this.SampleRequests = SampleRequestManager.GetSampleRequests();
222+
SampleRequestManager = new SampleRequestManager(DirectoryManager.GetCurrentDirectory());
223+
SampleRequests = SampleRequestManager.GetSampleRequests();
215224
}
216225

217226
private void RuntimeApiModelOnStateChange(object? sender, EventArgs e)
218227
{
219-
this.InvokeAsync(this.StateHasChanged);
228+
InvokeAsync(this.StateHasChanged);
220229
}
221230

222231
void OnAddEventClick()
223232
{
224-
RuntimeApiModel.QueueEvent(this.FunctionInput);
225-
this.FunctionInput = "";
226-
this.SelectedSampleRequestName = NO_SAMPLE_SELECTED_ID;
227-
this.StateHasChanged();
233+
RuntimeApiModel.QueueEvent(FunctionInput);
234+
FunctionInput = "";
235+
SelectedSampleRequestName = NoSampleSelectedId;
236+
StateHasChanged();
228237
}
229238

230239
void OnClearQueued()
231240
{
232-
this.RuntimeApiModel.ClearQueued();
233-
this.StateHasChanged();
241+
RuntimeApiModel.ClearQueued();
242+
StateHasChanged();
234243
}
235244

236245
void OnClearExecuted()
237246
{
238-
this.RuntimeApiModel.ClearExecuted();
239-
this.StateHasChanged();
247+
RuntimeApiModel.ClearExecuted();
248+
StateHasChanged();
240249
}
241250

242251
void OnRequeue(string awsRequestId)
243252
{
244253
EventContainer? evnt = null;
245-
if (string.Equals(this.RuntimeApiModel.ActiveEvent?.AwsRequestId, awsRequestId))
254+
if (string.Equals(RuntimeApiModel.ActiveEvent?.AwsRequestId, awsRequestId))
246255
{
247-
evnt = this.RuntimeApiModel.ActiveEvent;
256+
evnt = RuntimeApiModel.ActiveEvent;
248257
}
249258
else
250259
{
251-
evnt = this.RuntimeApiModel.ExecutedEvents.FirstOrDefault(x => string.Equals(x.AwsRequestId, awsRequestId));
260+
evnt = RuntimeApiModel.ExecutedEvents.FirstOrDefault(x => string.Equals(x.AwsRequestId, awsRequestId));
252261
}
253262

254263
if (evnt == null)
255264
return;
256265

257-
this.RuntimeApiModel.QueueEvent(evnt.EventJson);
258-
this.StateHasChanged();
266+
RuntimeApiModel.QueueEvent(evnt.EventJson);
267+
StateHasChanged();
259268
}
260269

261270
void OnDeleteEvent(string awsRequestId)
262271
{
263-
this.RuntimeApiModel.DeleteEvent(awsRequestId);
264-
this.StateHasChanged();
272+
RuntimeApiModel.DeleteEvent(awsRequestId);
273+
StateHasChanged();
265274
}
266275

267276
string GetStatusStyle(EventContainer.Status status) => status switch
@@ -308,4 +317,14 @@
308317
parameters.Add(ExpandedTextDialog.PARAMETER_NAME_FULL_TEXT, text);
309318
Modal.Show<ExpandedTextDialog>(title, parameters);
310319
}
320+
321+
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
322+
{
323+
return new StandaloneEditorConstructionOptions
324+
{
325+
Language = "json",
326+
GlyphMargin = true,
327+
Theme = "vs-dark"
328+
};
329+
}
311330
}

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Components/_Imports.razor

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@
1010
@using Amazon.Lambda.TestTool.Components
1111

1212
@using Blazored.Modal
13-
@using Blazored.Modal.Services
13+
@using Blazored.Modal.Services
14+
15+
@using BlazorMonaco
16+
@using BlazorMonaco.Editor
17+
@using BlazorMonaco.Languages

Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/wwwroot/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ h1:focus {
4949
.darker-border-checkbox.form-check-input {
5050
border-color: #929292;
5151
}
52+
53+
.monaco-editor-container {
54+
height: 500px;
55+
}

0 commit comments

Comments
 (0)