Skip to content

Commit

Permalink
Removed SelectItem
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Oct 3, 2024
1 parent f7687db commit bd4ba95
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 58 deletions.
13 changes: 0 additions & 13 deletions src/Inc.TeamAssistant.WebUI/Components/SelectItem.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@
};

private LoadingState _state = LoadingState.Done();
private IReadOnlyCollection<SelectItem<NavRoute>> _breadcrumbs = Array.Empty<SelectItem<NavRoute>>();
private IReadOnlyDictionary<string, string> _breadcrumbs = new Dictionary<string, string>();
private IReadOnlyCollection<StoryDto> _items = Array.Empty<StoryDto>();

protected override async Task OnParametersSetAsync()
{
if (Enum.TryParse<AssessmentType>(View, ignoreCase: true, out var value))
_currentView = value;

_breadcrumbs =
[
new(Resources[Messages.GUI_AssessmentSession], NavRouter.CreateRoute($"assessment-session/{TeamId:N}")),
new(Date, NavRouter.CreateRoute($"assessment-history/{TeamId:N}/{Date}"))
];

_breadcrumbs = new Dictionary<string, string>
{
[Resources[Messages.GUI_AssessmentSession]] = NavRouter.CreateRoute($"assessment-session/{TeamId:N}"),
[Date] = NavRouter.CreateRoute($"assessment-history/{TeamId:N}/{Date}")
};

await Load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
};

private LoadingState _state = LoadingState.Done();
private IReadOnlyCollection<SelectItem<NavRoute>> _breadcrumbs = Array.Empty<SelectItem<NavRoute>>();
private IReadOnlyDictionary<string, string> _breadcrumbs = new Dictionary<string, string>();
private GetActiveStoryResult _item = new(string.Empty, string.Empty, Story: null);
private IAsyncDisposable? _eventListener;

Expand All @@ -96,11 +96,11 @@
_currentView = value;

var date = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd");
_breadcrumbs =
[
new(Resources[Messages.GUI_AssessmentSession], NavRouter.CreateRoute($"assessment-session/{Id:N}")),
new(date, NavRouter.CreateRoute($"assessment-history/{Id:N}/{date}"))
];
_breadcrumbs = new Dictionary<string, string>
{
[Resources[Messages.GUI_AssessmentSession]] = NavRouter.CreateRoute($"assessment-session/{Id:N}"),
[date] = NavRouter.CreateRoute($"assessment-history/{Id:N}/{date}")
};

await Load();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
{
<li class="breadcrumbs__item">
<RouterLink Href="@item.Value" IsDark="true">
<Content>@item.Title</Content>
<Content>@item.Key</Content>
</RouterLink>
</li>
}
</ol>

@code {
[Parameter, EditorRequired]
public IReadOnlyCollection<SelectItem<NavRoute>> Items { get; set; } = Array.Empty<SelectItem<NavRoute>>();
public IReadOnlyDictionary<string, string> Items { get; set; } = new Dictionary<string, string>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,24 @@
<Content>
@foreach (var settingItem in settingSection.SettingItems)
{
var property = _formModel.Properties.SingleOrDefault(p => p.Title.Equals(
settingItem.PropertyName,
StringComparison.InvariantCultureIgnoreCase));
if (property is null)
continue;

<FormFieldSet
FieldId="@settingItem.PropertyName"
Label="@Resources[settingItem.LabelMessageId]">
<Content>
<InputSelectList
FieldId="@settingItem.PropertyName"
Value="property.Value"
ValueExpression="@(() => property.Value)"
ValueChanged="@((string v) => property.Value = v)"
Items="settingItem.Values"
TitleSelector="i => Resources[i.MessageId]"
ValueSelector="i => i.Value" />
<ValidationMessage For="@(() => property.Value)"/>
</Content>
</FormFieldSet>
if (_formModel.Properties.TryGetValue(settingItem.PropertyName, out var value))
{
<FormFieldSet
FieldId="@settingItem.PropertyName"
Label="@Resources[settingItem.LabelMessageId]">
<Content>
<InputSelectList
FieldId="@settingItem.PropertyName"
Value="value"
ValueExpression="@(() => value)"
ValueChanged="@((string v) => _formModel.ChangeProperty(settingItem.PropertyName, v))"
Items="settingItem.Values"
TitleSelector="i => Resources[i.MessageId]"
ValueSelector="i => i.Value" />
<ValidationMessage For="@(() => value)"/>
</Content>
</FormFieldSet>
}
}
</Content>
</FormSection>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Inc.TeamAssistant.Primitives.FeatureProperties;
using Inc.TeamAssistant.WebUI.Components;

namespace Inc.TeamAssistant.WebUI.Features.Constructor.Stages.Stage3;

Expand All @@ -11,12 +10,22 @@ public sealed class SetSettingsFormModel
private readonly List<string> _supportedLanguages = new();
public IReadOnlyCollection<string> SupportedLanguages => _supportedLanguages;

private readonly List<SelectItem<string>> _properties = new();
public IReadOnlyCollection<SelectItem<string>> Properties => _properties;
private readonly Dictionary<string, string> _properties = new(StringComparer.InvariantCultureIgnoreCase);
public IReadOnlyDictionary<string, string> Properties => _properties;

private readonly Dictionary<string, IReadOnlyCollection<SettingSection>> _availableProperties = new(StringComparer.InvariantCultureIgnoreCase);
public IReadOnlyDictionary<string, IReadOnlyCollection<SettingSection>> AvailableProperties => _availableProperties;

public SetSettingsFormModel ChangeProperty(string key, string value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(key);
ArgumentException.ThrowIfNullOrWhiteSpace(value);

_properties[key] = value;

return this;
}

public SetSettingsFormModel Apply(StagesState stagesState)
{
ArgumentNullException.ThrowIfNull(stagesState);
Expand All @@ -28,10 +37,8 @@ public SetSettingsFormModel Apply(StagesState stagesState)
_supportedLanguages.AddRange(stagesState.SupportedLanguages);

_properties.Clear();
_properties.AddRange(stagesState.SelectedFeatures
.SelectMany(f => f.Properties.Select(v => new SelectItem<string>(
v,
stagesState.Properties.GetValueOrDefault(v, string.Empty)))));
foreach (var property in stagesState.SelectedFeatures.SelectMany(f => f.Properties))
_properties.Add(property, stagesState.Properties.GetValueOrDefault(property, string.Empty));

_availableProperties.Clear();
foreach (var availableProperty in stagesState.AvailableProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SetSettingsFormModelValidator(ResourcesManager resources)
RuleForEach(e => e.Properties)
.ChildRules(c =>
{
c.RuleFor(e => e.Title)
c.RuleFor(e => e.Key)
.NotEmpty();

c.RuleFor(e => e.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public StagesState Apply(SetSettingsFormModel formModel)

_properties.Clear();
foreach (var property in formModel.Properties)
_properties.Add(property.Title, property.Value);
_properties.Add(property.Key, property.Value);

_supportedLanguages.Clear();
_supportedLanguages.AddRange(formModel.SupportedLanguages);
Expand Down

0 comments on commit bd4ba95

Please sign in to comment.