mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 10:18:40 +00:00
Added preview feature configuration (#227)
This commit is contained in:
1 parent
e2859b3d76
commit
55d7895f58
26 files changed
+270
-41
No files matched your search
@@ -0,0 +1,23 @@
|
||||
@inherits ConfigurationBase
|
||||
@typeparam T
|
||||
|
||||
<MudSelectExtended
|
||||
T="T"
|
||||
MultiSelection="@true"
|
||||
MultiSelectionTextFunc="@this.GetMultiSelectionText"
|
||||
SelectedValues="@this.SelectedValues()"
|
||||
Strict="@true"
|
||||
Disabled="@this.Disabled()"
|
||||
Margin="Margin.Dense"
|
||||
Label="@this.OptionDescription"
|
||||
Class="@GetClass"
|
||||
Variant="Variant.Outlined"
|
||||
HelperText="@this.OptionHelp"
|
||||
SelectedValuesChanged="@this.OptionChanged">
|
||||
@foreach (var data in this.Data)
|
||||
{
|
||||
<MudSelectItemExtended Value="@data.Value">
|
||||
@data.Name
|
||||
</MudSelectItemExtended>
|
||||
}
|
||||
</MudSelectExtended>
|
||||
@@ -0,0 +1,54 @@
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration component for selecting many values from a list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the value to select.</typeparam>
|
||||
public partial class ConfigurationMultiSelect<T> : ConfigurationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// The data to select from.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public IEnumerable<ConfigurationSelectData<T>> Data { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The selected values.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Func<HashSet<T>> SelectedValues { get; set; } = () => [];
|
||||
|
||||
/// <summary>
|
||||
/// An action that is called when the selection changes.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public Action<HashSet<T>> SelectionUpdate { get; set; } = _ => { };
|
||||
|
||||
private async Task OptionChanged(IEnumerable<T?>? updatedValues)
|
||||
{
|
||||
if(updatedValues is null)
|
||||
this.SelectionUpdate([]);
|
||||
else
|
||||
this.SelectionUpdate(updatedValues.Where(n => n is not null).ToHashSet()!);
|
||||
|
||||
await this.SettingsManager.StoreSettings();
|
||||
await this.InformAboutChange();
|
||||
}
|
||||
|
||||
private static string GetClass => $"{MARGIN_CLASS} rounded-lg";
|
||||
|
||||
private string GetMultiSelectionText(List<T?>? selectedValues)
|
||||
{
|
||||
if(selectedValues is null || selectedValues.Count == 0)
|
||||
return "No preview features selected.";
|
||||
|
||||
if(selectedValues.Count == 1)
|
||||
return $"You have selected 1 preview feature.";
|
||||
|
||||
return $"You have selected {selectedValues.Count} preview features.";
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
@inherits ConfigurationBase
|
||||
@typeparam T
|
||||
|
||||
<MudSelect T="T" Value="@this.SelectedValue()" Strict="@true" Disabled="@this.Disabled()" Margin="Margin.Dense" Label="@this.OptionDescription" Class="@GetClass" Variant="Variant.Outlined" HelperText="@this.OptionHelp" ValueChanged="@this.OptionChanged">
|
||||
<MudSelect T="T" Value="@this.SelectedValue()" Strict="@true" ShrinkLabel="@true" Disabled="@this.Disabled()" Margin="Margin.Dense" Label="@this.OptionDescription" Class="@GetClass" Variant="Variant.Outlined" HelperText="@this.OptionHelp" ValueChanged="@this.OptionChanged">
|
||||
@foreach (var data in this.Data)
|
||||
{
|
||||
<MudSelectItem Value="@data.Value">
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@using AIStudio
|
||||
@using AIStudio.Tools
|
||||
@using MudBlazor
|
||||
@using MudBlazor
|
||||
@using MudExtensions
|
||||
Reference in new issue
Block a user