feat(client): migrate PartOperationFilterPanel to API clients

This commit is contained in:
Joseph Doherty
2026-01-06 10:35:33 -05:00
parent 251e2f910f
commit 828034d0e2
@@ -1,5 +1,6 @@
@* Part operation/MIS filter panel with upload/download/clear functionality *@ @* Part operation/MIS filter panel with upload/download/clear functionality *@
@inject IFileService FileService @using JdeScoping.Core.ApiContracts
@inject IFileApiClient FileApi
@inject DialogService DialogService @inject DialogService DialogService
@inject NotificationService NotificationService @inject NotificationService NotificationService
@@ -49,7 +50,15 @@
private async Task DownloadTemplateAsync() private async Task DownloadTemplateAsync()
{ {
await FileService.DownloadTemplateAsync("partoperations", PartOperations); var result = await FileApi.DownloadPartOperationsTemplateAsync(PartOperations.AsReadOnly());
result.Switch(
bytes => { _ = JSRuntime.InvokeVoidAsync("downloadFile", "partoperations_template.xlsx", bytes); },
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Template not found."); },
validation => { NotificationService.Notify(NotificationSeverity.Error, "Error", string.Join("; ", validation.FieldErrors.SelectMany(e => e.Value))); },
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Session expired."); },
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Access denied."); },
error => { NotificationService.Notify(NotificationSeverity.Error, "Error", error.Message); }
);
} }
private async Task TriggerFileInput() private async Task TriggerFileInput()
@@ -65,19 +74,22 @@
try try
{ {
using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024); // 10MB max
var result = await FileService.UploadAsync<PartOperationViewModel>("partoperations", stream, e.File.Name); var result = await FileApi.UploadPartOperationsAsync(stream, e.File.Name);
if (result.WasSuccessful) result.Switch(
{ partOperations =>
PartOperations.Clear(); {
PartOperations.AddRange(result.Data); PartOperations.Clear();
await PartOperationsChanged.InvokeAsync(PartOperations); PartOperations.AddRange(partOperations);
NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {result.Data.Count} part operations."); _ = PartOperationsChanged.InvokeAsync(PartOperations);
} NotificationService.Notify(NotificationSeverity.Success, "Upload Complete", $"Loaded {partOperations.Count} part operations.");
else },
{ _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Upload endpoint not found."); },
NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", result.ErrorMessage); validation => { NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", string.Join("; ", validation.FieldErrors.SelectMany(e => e.Value))); },
} _ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Session expired."); },
_ => { NotificationService.Notify(NotificationSeverity.Error, "Error", "Access denied."); },
error => { NotificationService.Notify(NotificationSeverity.Error, "Upload Failed", error.Message); }
);
} }
catch (Exception ex) catch (Exception ex)
{ {