Added hot reload for managed policies

This commit is contained in:
Thorsten Sommer 2026-01-31 21:30:15 +01:00
parent b35333a9b6
commit f9f73643b2
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -215,7 +215,7 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
this.policyDefinitionExpanded = !this.selectedPolicy?.IsProtected ?? true;
await base.OnInitializedAsync();
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED, Event.PLUGINS_RELOADED ]);
this.UpdateProviders();
this.ApplyPolicyPreselection(preferPolicyPreselection: true);
}
@ -484,6 +484,11 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
this.UpdateProviders();
this.StateHasChanged();
break;
case Event.PLUGINS_RELOADED:
this.HandlePluginsReloaded();
this.StateHasChanged();
break;
}
return Task.CompletedTask;
@ -491,6 +496,49 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<NoSettingsPan
#endregion
private void HandlePluginsReloaded()
{
// Check if the currently selected policy still exists after plugin reload:
if (this.selectedPolicy is not null)
{
var stillExists = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies
.Any(p => p.Id == this.selectedPolicy.Id);
if (!stillExists)
{
// Policy was removed, select a new one:
this.selectedPolicy = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies.FirstOrDefault();
}
else
{
// Policy still exists, update the reference to the potentially updated version:
this.selectedPolicy = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies
.First(p => p.Id == this.selectedPolicy.Id);
}
}
else
{
// No policy was selected, select the first one if available:
this.selectedPolicy = this.SettingsManager.ConfigurationData.DocumentAnalysis.Policies.FirstOrDefault();
}
// Update form values to reflect the current policy:
this.ResetForm();
// Update the expansion state based on the policy protection:
this.policyDefinitionExpanded = !this.selectedPolicy?.IsProtected ?? true;
// Update available providers:
this.UpdateProviders();
// Apply policy preselection:
this.ApplyPolicyPreselection(preferPolicyPreselection: true);
// Reset validation state:
this.form?.ResetValidation();
this.ClearInputIssues();
}
private string? ValidatePolicyDescription(string description)
{
if(string.IsNullOrWhiteSpace(description))