Add manual critical table cell editor
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
|
||||
<section class="hero-panel">
|
||||
<span class="eyebrow">Minimal API</span>
|
||||
<h1 class="page-title">Endpoints for attack and critical lookups.</h1>
|
||||
<p class="lede">The Blazor UI uses the same lookup service that the API exposes, so this page doubles as the first integration contract.</p>
|
||||
<h1 class="page-title">Endpoints for attack, critical lookup, and manual critical-table curation.</h1>
|
||||
<p class="lede">The Blazor UI uses the same lookup service that the API exposes, so this page doubles as the first integration contract for both read and write workflows.</p>
|
||||
</section>
|
||||
|
||||
<div class="api-grid">
|
||||
@@ -50,4 +50,55 @@
|
||||
}</pre>
|
||||
<p class="panel-copy">Response now includes table metadata, roll-band bounds, raw imported cell text, parse status, and parsed JSON alongside the gameplay description.</p>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2 class="panel-title">Cell editor load</h2>
|
||||
<p class="panel-copy"><code>GET /api/tables/critical/{slug}/cells/{resultId}</code></p>
|
||||
<pre class="code-block">{
|
||||
"resultId": 412,
|
||||
"tableSlug": "slash",
|
||||
"tableName": "Slash Critical Strike Table",
|
||||
"rollBand": "66-70",
|
||||
"groupKey": null,
|
||||
"columnKey": "C",
|
||||
"rawCellText": "Original imported full cell text",
|
||||
"descriptionText": "Current curated prose",
|
||||
"rawAffixText": "+8H - 2S",
|
||||
"parseStatus": "verified",
|
||||
"parsedJson": "{}",
|
||||
"effects": [],
|
||||
"branches": []
|
||||
}</pre>
|
||||
<p class="panel-copy">Use this to retrieve the full editable result graph for one critical-table cell, including nested branches and normalized effects.</p>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<h2 class="panel-title">Cell editor save</h2>
|
||||
<p class="panel-copy"><code>PUT /api/tables/critical/{slug}/cells/{resultId}</code></p>
|
||||
<pre class="code-block">{
|
||||
"rawCellText": "Corrected imported text",
|
||||
"descriptionText": "Rewritten prose after manual review",
|
||||
"rawAffixText": "+10H - must parry 2 rnds",
|
||||
"parseStatus": "manually_curated",
|
||||
"parsedJson": "{\"reviewed\":true}",
|
||||
"effects": [
|
||||
{
|
||||
"effectCode": "direct_hits",
|
||||
"target": null,
|
||||
"valueInteger": 10,
|
||||
"valueDecimal": null,
|
||||
"valueExpression": null,
|
||||
"durationRounds": null,
|
||||
"perRound": null,
|
||||
"modifier": null,
|
||||
"bodyPart": null,
|
||||
"isPermanent": false,
|
||||
"sourceType": "symbol",
|
||||
"sourceText": "+10H"
|
||||
}
|
||||
],
|
||||
"branches": []
|
||||
}</pre>
|
||||
<p class="panel-copy">The save endpoint replaces the stored base result, branch rows, and effect rows for that cell with the submitted curated payload.</p>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@@ -117,9 +117,26 @@
|
||||
{
|
||||
foreach (var column in detail.Columns)
|
||||
{
|
||||
<td>
|
||||
@RenderCell(rollBand.Label, group.Key, column.Key)
|
||||
</td>
|
||||
@if (TryGetCell(rollBand.Label, group.Key, column.Key, out var groupedCell))
|
||||
{
|
||||
<td
|
||||
class="critical-table-cell is-editable"
|
||||
tabindex="0"
|
||||
title="Click to edit this cell"
|
||||
@onclick="() => OpenCellEditorAsync(groupedCell.ResultId)"
|
||||
@onkeydown="args => HandleCellKeyDownAsync(args, groupedCell.ResultId)">
|
||||
<CompactCriticalCell
|
||||
Description="@(groupedCell.Description ?? string.Empty)"
|
||||
Effects="@(groupedCell.Effects ?? Array.Empty<CriticalEffectLookupResponse>())"
|
||||
Branches="@(groupedCell.Branches ?? Array.Empty<CriticalBranchLookupResponse>())" />
|
||||
</td>
|
||||
}
|
||||
else
|
||||
{
|
||||
<td class="critical-table-cell">
|
||||
<span class="empty-cell">—</span>
|
||||
</td>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,9 +144,26 @@
|
||||
{
|
||||
foreach (var column in detail.Columns)
|
||||
{
|
||||
<td>
|
||||
@RenderCell(rollBand.Label, null, column.Key)
|
||||
</td>
|
||||
@if (TryGetCell(rollBand.Label, null, column.Key, out var cell))
|
||||
{
|
||||
<td
|
||||
class="critical-table-cell is-editable"
|
||||
tabindex="0"
|
||||
title="Click to edit this cell"
|
||||
@onclick="() => OpenCellEditorAsync(cell.ResultId)"
|
||||
@onkeydown="args => HandleCellKeyDownAsync(args, cell.ResultId)">
|
||||
<CompactCriticalCell
|
||||
Description="@(cell.Description ?? string.Empty)"
|
||||
Effects="@(cell.Effects ?? Array.Empty<CriticalEffectLookupResponse>())"
|
||||
Branches="@(cell.Branches ?? Array.Empty<CriticalBranchLookupResponse>())" />
|
||||
</td>
|
||||
}
|
||||
else
|
||||
{
|
||||
<td class="critical-table-cell">
|
||||
<span class="empty-cell">—</span>
|
||||
</td>
|
||||
}
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
@@ -164,6 +198,17 @@
|
||||
}
|
||||
</section>
|
||||
|
||||
@if (isEditorOpen)
|
||||
{
|
||||
<CriticalCellEditorDialog
|
||||
Model="editorModel"
|
||||
IsLoading="isEditorLoading"
|
||||
IsSaving="isEditorSaving"
|
||||
ErrorMessage="editorError"
|
||||
OnClose="CloseCellEditorAsync"
|
||||
OnSave="SaveCellEditorAsync" />
|
||||
}
|
||||
|
||||
@code {
|
||||
private LookupReferenceData? referenceData;
|
||||
private CriticalTableDetail? tableDetail;
|
||||
@@ -175,6 +220,12 @@
|
||||
private int tableLayoutVersion;
|
||||
private int appliedLayoutVersion = -1;
|
||||
private bool IsTableSelectionDisabled => isReferenceDataLoading || (referenceData?.CriticalTables.Count ?? 0) == 0;
|
||||
private bool isEditorOpen;
|
||||
private bool isEditorLoading;
|
||||
private bool isEditorSaving;
|
||||
private string? editorError;
|
||||
private int? editingResultId;
|
||||
private CriticalCellEditorModel? editorModel;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -252,25 +303,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
private RenderFragment RenderCell(string rollBand, string? groupKey, string columnKey) => builder =>
|
||||
{
|
||||
if (TryGetCell(rollBand, groupKey, columnKey, out var cell))
|
||||
{
|
||||
builder.OpenComponent(0, typeof(CompactCriticalCell));
|
||||
builder.AddAttribute(1, "Description", cell.Description ?? string.Empty);
|
||||
builder.AddAttribute(2, "Effects", cell.Effects ?? Array.Empty<CriticalEffectLookupResponse>());
|
||||
builder.AddAttribute(3, "Branches", cell.Branches ?? Array.Empty<CriticalBranchLookupResponse>());
|
||||
builder.CloseComponent();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.OpenElement(4, "span");
|
||||
builder.AddAttribute(5, "class", "empty-cell");
|
||||
builder.AddContent(6, "—");
|
||||
builder.CloseElement();
|
||||
}
|
||||
};
|
||||
|
||||
private bool TryGetCell(string rollBand, string? groupKey, string columnKey, [NotNullWhen(true)] out CriticalTableCellDetail? cell)
|
||||
{
|
||||
if (cellIndex is null)
|
||||
@@ -281,4 +313,91 @@
|
||||
|
||||
return cellIndex.TryGetValue((rollBand, groupKey, columnKey), out cell);
|
||||
}
|
||||
|
||||
private async Task OpenCellEditorAsync(int resultId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(selectedTableSlug))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isEditorOpen = true;
|
||||
isEditorLoading = true;
|
||||
isEditorSaving = false;
|
||||
editorError = null;
|
||||
editingResultId = resultId;
|
||||
|
||||
try
|
||||
{
|
||||
var response = await LookupService.GetCriticalCellEditorAsync(selectedTableSlug, resultId);
|
||||
if (response is null)
|
||||
{
|
||||
editorError = "The selected cell could not be loaded for editing.";
|
||||
editorModel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
editorModel = CriticalCellEditorModel.FromResponse(response);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
editorError = exception.Message;
|
||||
editorModel = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isEditorLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CloseCellEditorAsync()
|
||||
{
|
||||
isEditorOpen = false;
|
||||
isEditorLoading = false;
|
||||
isEditorSaving = false;
|
||||
editorError = null;
|
||||
editingResultId = null;
|
||||
editorModel = null;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private async Task SaveCellEditorAsync()
|
||||
{
|
||||
if (editorModel is null || string.IsNullOrWhiteSpace(selectedTableSlug) || editingResultId is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isEditorSaving = true;
|
||||
editorError = null;
|
||||
|
||||
try
|
||||
{
|
||||
var response = await LookupService.UpdateCriticalCellAsync(selectedTableSlug, editingResultId.Value, editorModel.ToRequest());
|
||||
if (response is null)
|
||||
{
|
||||
editorError = "The selected cell could not be saved.";
|
||||
return;
|
||||
}
|
||||
|
||||
editorModel = CriticalCellEditorModel.FromResponse(response);
|
||||
await LoadTableDetailAsync();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
editorError = exception.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isEditorSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleCellKeyDownAsync(KeyboardEventArgs args, int resultId)
|
||||
{
|
||||
if (args.Key is "Enter" or " ")
|
||||
{
|
||||
await OpenCellEditorAsync(resultId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user