2024-07-28 09:20:00 +00:00
|
|
|
using AIStudio.Settings;
|
|
|
|
|
2024-05-04 09:08:18 +00:00
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
2024-08-21 06:30:01 +00:00
|
|
|
namespace AIStudio.Components;
|
2024-05-04 09:08:18 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Configuration component for selecting a value from a list.
|
|
|
|
/// </summary>
|
2025-07-11 20:29:59 +00:00
|
|
|
/// <typeparam name="TConfig">The type of the value to select.</typeparam>
|
|
|
|
public partial class ConfigurationSelect<TConfig> : ConfigurationBaseCore
|
2024-05-04 09:08:18 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The data to select from.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
2025-07-11 20:29:59 +00:00
|
|
|
public IEnumerable<ConfigurationSelectData<TConfig>> Data { get; set; } = [];
|
2024-05-04 09:08:18 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The selected value.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
2025-07-11 20:29:59 +00:00
|
|
|
public Func<TConfig> SelectedValue { get; set; } = () => default!;
|
2024-05-04 09:08:18 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// An action that is called when the selection changes.
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
2025-07-11 20:29:59 +00:00
|
|
|
public Action<TConfig> SelectionUpdate { get; set; } = _ => { };
|
2024-05-04 09:08:18 +00:00
|
|
|
|
2025-07-22 05:55:15 +00:00
|
|
|
#region Overrides of ConfigurationBase
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override bool Stretch => true;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override string Label => this.OptionDescription;
|
|
|
|
|
|
|
|
protected override Variant Variant => Variant.Outlined;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2025-07-11 20:29:59 +00:00
|
|
|
private async Task OptionChanged(TConfig updatedValue)
|
2024-05-04 09:08:18 +00:00
|
|
|
{
|
|
|
|
this.SelectionUpdate(updatedValue);
|
|
|
|
await this.SettingsManager.StoreSettings();
|
2024-07-24 13:17:45 +00:00
|
|
|
await this.InformAboutChange();
|
2024-05-04 09:08:18 +00:00
|
|
|
}
|
|
|
|
}
|