Refactor ReportViewer for reusability and dynamic updates
Refactored `ReportViewer.razor` to improve maintainability and ensure dynamic updates to the `DxReportViewer` component. - Added `@key` attribute bound to `ViewerKey` to trigger re-renders. - Introduced `CreateReportInstance` and `CreateSignedReportInstance` helper methods to encapsulate report creation logic. - Updated `OnInitializedAsync`, `ClearSignatureAsync`, and `ApplySignatureAsync` to use the new helper methods. - Incremented `ViewerKey` in relevant methods to ensure proper re-rendering of the `DxReportViewer` component. - Replaced `ApplySignatureToReport` with `CreateSignedReportInstance`. These changes improve code modularity, readability, and ensure the UI reflects the latest state of the report.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
@if(Report is not null) {
|
||||
<DxReportViewer @ref="reportViewer" Report="Report" RootCssClasses="w-100 h-100" />
|
||||
<DxReportViewer @key="ViewerKey" @ref="reportViewer" Report="Report" RootCssClasses="w-100 h-100" />
|
||||
}
|
||||
|
||||
@code {
|
||||
@@ -37,11 +37,10 @@
|
||||
XtraReport? Report;
|
||||
bool SignatureApplied;
|
||||
string? SignatureValidationMessage;
|
||||
int ViewerKey;
|
||||
|
||||
protected override async Task OnInitializedAsync() {
|
||||
Report = ReportStorage.TryGetReport("LargeDatasetReport", out var savedReport)
|
||||
? savedReport
|
||||
: PredefinedReports.ReportsFactory.GetReport("LargeDatasetReport");
|
||||
Report = CreateReportInstance();
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
@@ -55,12 +54,8 @@
|
||||
await JSRuntime.InvokeVoidAsync("receiverSignature.clear", "receiver-signature-pad");
|
||||
SignatureApplied = false;
|
||||
SignatureValidationMessage = null;
|
||||
Report = ReportStorage.TryGetReport("LargeDatasetReport", out var savedReport)
|
||||
? savedReport
|
||||
: PredefinedReports.ReportsFactory.GetReport("LargeDatasetReport");
|
||||
|
||||
if(reportViewer is not null)
|
||||
await reportViewer.OpenReportAsync(Report);
|
||||
Report = CreateReportInstance();
|
||||
ViewerKey++;
|
||||
}
|
||||
|
||||
async Task ApplySignatureAsync() {
|
||||
@@ -73,11 +68,9 @@
|
||||
}
|
||||
|
||||
SignatureValidationMessage = null;
|
||||
ApplySignatureToReport(signatureDataUrl);
|
||||
Report = CreateSignedReportInstance(signatureDataUrl);
|
||||
SignatureApplied = true;
|
||||
|
||||
if(reportViewer is not null)
|
||||
await reportViewer.OpenReportAsync(Report);
|
||||
ViewerKey++;
|
||||
}
|
||||
|
||||
async Task ExportSignedPdfAsync() {
|
||||
@@ -89,6 +82,18 @@
|
||||
await reportViewer.ExportToAsync(ExportFormat.Pdf);
|
||||
}
|
||||
|
||||
XtraReport CreateReportInstance() {
|
||||
return ReportStorage.TryGetReport("LargeDatasetReport", out var savedReport)
|
||||
? savedReport
|
||||
: PredefinedReports.ReportsFactory.GetReport("LargeDatasetReport");
|
||||
}
|
||||
|
||||
XtraReport CreateSignedReportInstance(string signatureDataUrl) {
|
||||
var report = CreateReportInstance();
|
||||
AddSignature(report, signatureDataUrl);
|
||||
return report;
|
||||
}
|
||||
|
||||
void ApplySignatureToReport(string signatureDataUrl) {
|
||||
Report ??= ReportStorage.TryGetReport("LargeDatasetReport", out var savedReport)
|
||||
? savedReport
|
||||
|
||||
Reference in New Issue
Block a user