Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 79 additions & 16 deletions src/DbcView.Web/Components/DbcCommandPalette.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<dialog class="dbc-palette"
data-testid="dbc-command-palette"
aria-label="Search messages and signals"
aria-label="Search messages, signals and commands"
@ref="_dialog"
@onclose="OnDialogClosed">
<div class="dbc-palette-body">
Expand All @@ -18,12 +18,12 @@
data-testid="dbc-palette-input"
type="text"
role="combobox"
aria-label="Search messages and signals"
aria-label="Search messages, signals and commands"
aria-expanded="@(Model.ResultCount > 0 ? "true" : "false")"
aria-controls="@(Model.ResultCount > 0 ? "dbc-palette-results" : null)"
aria-autocomplete="list"
aria-activedescendant="@ActiveDescendant"
placeholder="Search messages, signals, IDs, transmitter or receiver"
placeholder="Search messages, signals, IDs, or commands"
value="@Model.Query"
@oninput="OnInput"
@onkeydown="OnKeyDown" />
Expand All @@ -40,7 +40,7 @@
@if (!Model.HasQuery)
{
<p class="dbc-palette-hint" data-testid="dbc-palette-hint">
Type a message or signal name, a decimal/0x ID, a transmitter, or a receiver.
Type a message or signal name, a decimal/0x ID, or a command such as “check”.
</p>
}
else if (Model.ResultCount == 0)
Expand All @@ -53,6 +53,31 @@
class="dbc-palette-results"
role="listbox"
aria-label="Search results">
@if (Model.CommandResults.Count > 0)
{
<div role="group" aria-labelledby="dbc-palette-commands">
<div id="dbc-palette-commands" class="dbc-palette-group" role="presentation">
Commands
</div>
@for (var index = 0; index < Model.CommandResults.Count; index++)
{
var optionIndex = index;
var command = Model.CommandResults[index];
var active = optionIndex == _activeIndex;
<div id="@OptionId(optionIndex)"
role="option"
aria-selected="@(active ? "true" : "false")"
class="@(active ? "dbc-palette-option is-active" : "dbc-palette-option")"
data-testid="dbc-palette-command"
data-command-id="@command.Id"
@onclick="() => SelectCommandAsync(command)"
@onmouseenter="() => SetActive(optionIndex)">
<span class="dbc-palette-option-title">@command.Title</span>
<span class="dbc-palette-option-meta">@command.Detail</span>
</div>
}
</div>
}
@if (Model.MessageResults.Count > 0)
{
<div role="group" aria-labelledby="dbc-palette-messages">
Expand All @@ -61,7 +86,7 @@
</div>
@for (var index = 0; index < Model.MessageResults.Count; index++)
{
var optionIndex = index;
var optionIndex = Model.CommandResults.Count + index;
var result = Model.MessageResults[index];
var active = optionIndex == _activeIndex;
<div id="@OptionId(optionIndex)"
Expand Down Expand Up @@ -93,7 +118,9 @@
</div>
@for (var index = 0; index < Model.SignalResults.Count; index++)
{
var optionIndex = Model.MessageResults.Count + index;
var optionIndex = Model.CommandResults.Count
+ Model.MessageResults.Count
+ index;
var result = Model.SignalResults[index];
var active = optionIndex == _activeIndex;
<div id="@OptionId(optionIndex)"
Expand Down Expand Up @@ -121,7 +148,7 @@
}

<div class="dbc-palette-footer" aria-hidden="true">
↑↓ navigate · Enter jump · Esc close
↑↓ navigate · Enter run/jump · Esc close
</div>
<div class="dbc-sr-only" role="status" aria-live="polite">@Announcement</div>
</div>
Expand All @@ -143,31 +170,46 @@
[Parameter]
public EventCallback<DbcPaletteResult> OnSelected { get; set; }

[Parameter]
public EventCallback<DbcPaletteCommand> OnCommandSelected { get; set; }

[Parameter]
public EventCallback OnClosed { get; set; }

private DbcPaletteCommand? ActiveCommand
{
get
{
return _activeIndex >= 0 && _activeIndex < Model.CommandResults.Count
? Model.CommandResults[_activeIndex]
: null;
}
}

private DbcPaletteResult? ActiveResult
{
get
{
if (_activeIndex < 0)
var index = _activeIndex - Model.CommandResults.Count;
if (index < 0)
{
return null;
}

if (_activeIndex < Model.MessageResults.Count)
if (index < Model.MessageResults.Count)
{
return Model.MessageResults[_activeIndex];
return Model.MessageResults[index];
}

var signalIndex = _activeIndex - Model.MessageResults.Count;
var signalIndex = index - Model.MessageResults.Count;
return signalIndex < Model.SignalResults.Count
? Model.SignalResults[signalIndex]
: null;
}
}

private string? ActiveDescendant => ActiveResult is null ? null : OptionId(_activeIndex);
private string? ActiveDescendant =>
ActiveCommand is null && ActiveResult is null ? null : OptionId(_activeIndex);

private string Announcement
{
Expand All @@ -183,9 +225,14 @@
return "No matches.";
}

return Model.TotalMatchCount > Model.ResultCount
? $"{Model.ResultCount} results shown of {Model.TotalMatchCount} matches."
: $"{Model.ResultCount} results.";
if (Model.TotalMatchCount > Model.ResultCount)
{
return Model.ResultCount == 1
? $"1 result shown of {Model.TotalMatchCount} matches."
: $"{Model.ResultCount} results shown of {Model.TotalMatchCount} matches.";
}

return Model.ResultCount == 1 ? "1 result." : $"{Model.ResultCount} results.";
}
}

Expand Down Expand Up @@ -275,7 +322,11 @@

break;
case "Enter":
if (ActiveResult is { } result)
if (ActiveCommand is { } command)
{
await SelectCommandAsync(command);
}
else if (ActiveResult is { } result)
{
await SelectAsync(result);
}
Expand Down Expand Up @@ -310,6 +361,18 @@
await OnSelected.InvokeAsync(result);
}

private async Task SelectCommandAsync(DbcPaletteCommand command)
{
if (_closing)
{
return;
}

_closing = true;
await CloseDialogAsync();
await OnCommandSelected.InvokeAsync(command);
}

private async Task CloseAsync()
{
if (_closing)
Expand Down
41 changes: 11 additions & 30 deletions src/DbcView.Web/Components/DbcEditorPanel.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
@onclick="() => Model.SetMode(DbcEditorModel.ViewMode.Table)">Table</button>
</div>
<div class="dbc-editor-document-actions" role="group" aria-label="Document actions">
<button type="button"
class="dbc-action"
data-testid="dbc-check-document"
title="Check the current document (Ctrl+Enter)"
@onclick="OnCheck">Check</button>
<button type="button"
class="dbc-action"
data-testid="dbc-download"
Expand Down Expand Up @@ -100,35 +105,8 @@
</div>
}

@if (Model.ParseResult is { HasErrors: true } parseResult)
{
<div class="dbc-alert error" role="alert" data-testid="dbc-parse-errors">
<DbcIcon Name="error" Size="14" />
<div class="dbc-alert-body">
<p class="dbc-alert-title">
@(Model.LastSaveResult is not null
? $"Saved as an unvalidated draft ({parseResult.ErrorCount} DBC error(s)). Raw text was kept."
: $"This file contains {parseResult.ErrorCount} DBC error(s).")
</p>
<DbcDiagnosticList Diagnostics="parseResult.Diagnostics" />
</div>
</div>
}
else if (Model.ParseResult is { Diagnostics.Count: > 0 } withWarnings)
{
<div class="dbc-alert warning" role="status" data-testid="dbc-parse-warnings">
<DbcIcon Name="warning" Size="14" />
<div class="dbc-alert-body">
<p class="dbc-alert-title">
@(Model.LastSaveResult is not null
? $"Saved with {withWarnings.Diagnostics.Count} DBC warning(s)."
: $"{withWarnings.Diagnostics.Count} DBC warning(s) found; the document is still usable.")
</p>
<DbcDiagnosticList Diagnostics="withWarnings.Diagnostics" />
</div>
</div>
}
else if (Model.LastSaveResult is not null)
@if (Model.LastSaveResult is not null
&& Model.ParseResult is not { Diagnostics.Count: > 0 })
{
<div class="dbc-alert success" role="status" data-testid="dbc-save-success">
<DbcIcon Name="check" Size="14" />
Expand Down Expand Up @@ -169,7 +147,7 @@
<div class="dbc-empty-state">
<DbcIcon Name="warning" Size="22" />
<p class="dbc-empty-title">Table view is unavailable</p>
<p class="dbc-empty-hint">Fix the DBC errors above, then switch back to Table.</p>
<p class="dbc-empty-hint">Fix the DBC errors in Problems, then switch back to Table.</p>
</div>
}
else if (Model.Document!.Messages.Count == 0)
Expand Down Expand Up @@ -316,6 +294,9 @@
[Parameter]
public EventCallback<DbcSignal> OnSignalSelected { get; set; }

[Parameter]
public EventCallback OnCheck { get; set; }

protected override void OnInitialized()
{
if (Model is null)
Expand Down
125 changes: 125 additions & 0 deletions src/DbcView.Web/Components/DbcProblemsPanel.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
@namespace DbcView.Web.Components
@using System.Globalization
@using DbcView.Domain
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop

<div class="dbc-problems-panel"
data-testid="dbc-problems"
@ref="_root"
tabindex="-1">
<ResourceTable Columns="_columns"
ShowButton="false"
ShowRedoButton="false"
ResizableColumns="false"
ContainerCss="dbc-problems-table">
<TableBody>
@if (Diagnostics.Count == 0)
{
<tr>
<td class="dbc-problems-empty"
colspan="4"
data-testid="dbc-problems-empty">
@(DocumentKey is null
? "Open a .dbc file to check it for problems."
: "No problems found.")
</td>
</tr>
}
else
{
@foreach (var diagnostic in Diagnostics)
{
<tr class="dbc-problem-row"
data-testid="dbc-problem-row"
data-severity="@diagnostic.Severity.ToString().ToLowerInvariant()"
data-line="@diagnostic.LineNumber"
tabindex="0"
@onclick="() => LocateAsync(diagnostic)"
@onkeydown="args => HandleKeyDownAsync(args, diagnostic)">
<td class="dbc-problem-severity" data-testid="dbc-problem-severity">
@SeverityLabel(diagnostic)
</td>
<td class="dbc-problem-line" data-testid="dbc-problem-line">
@LineLabel(diagnostic)
</td>
<td class="dbc-problem-code" data-testid="dbc-problem-code">
@diagnostic.Code
</td>
<td class="dbc-problem-message"
data-testid="dbc-problem-message"
title="@diagnostic.Message">
@diagnostic.Message
</td>
</tr>
}
}
</TableBody>
</ResourceTable>
</div>

@code {
private ElementReference _root;

private static readonly TableColumn[] _columns =
{
new("Severity") { Key = "severity", Width = "84px", MinWidth = 72, Resizable = false },
new("Line") { Key = "line", Width = "60px", MinWidth = 56, Resizable = false },
new("Code") { Key = "code", Width = "88px", MinWidth = 72, Resizable = false },
new("Message") { Key = "message", MinWidth = 120, Resizable = false },
};

[Parameter]
public string? DocumentKey { get; set; }

[Parameter, EditorRequired]
public IReadOnlyList<DbcDiagnostic> Diagnostics { get; set; } = Array.Empty<DbcDiagnostic>();

[Parameter]
public EventCallback<int> OnLocate { get; set; }

public async ValueTask FocusAsync()
{
if (!OperatingSystem.IsBrowser())
{
return;
}

try
{
await _root.FocusAsync();
}
catch (JSDisconnectedException)
{
}
catch (JSException)
{
}
}

private static string SeverityLabel(DbcDiagnostic diagnostic)
{
return diagnostic.Severity == DbcDiagnosticSeverity.Error ? "Error" : "Warning";
}

private static string LineLabel(DbcDiagnostic diagnostic)
{
return diagnostic.LineNumber > 0
? diagnostic.LineNumber.ToString(CultureInfo.InvariantCulture)
: "—";
}

private Task LocateAsync(DbcDiagnostic diagnostic)
{
return diagnostic.LineNumber > 0
? OnLocate.InvokeAsync(diagnostic.LineNumber)
: Task.CompletedTask;
}

private Task HandleKeyDownAsync(KeyboardEventArgs args, DbcDiagnostic diagnostic)
{
return args.Key is "Enter" or " "
? LocateAsync(diagnostic)
: Task.CompletedTask;
}
}
Loading
Loading