Skip to content

Commit

Permalink
Fix #694 [Reference Data] Parameter types - UI problems + #696 Tab te…
Browse files Browse the repository at this point in the history
…xt update (#704)
  • Loading branch information
joao4all authored Jul 17, 2024
1 parent e494cd6 commit 00af25e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
19 changes: 19 additions & 0 deletions COMETwebapp/Components/Common/SelectedDataItemForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public abstract partial class SelectedDataItemForm : DisposableComponent
/// </summary>
protected EditContext EditFormContext { get; set; }

/// <summary>
/// Gets or sets the custom validation fields names that will be validated immediately
/// </summary>
protected virtual IEnumerable<string> ImmediateValidationFields { get; } = Enumerable.Empty<string>();

/// <summary>
/// Method that is executed when the cancel button is clicked
/// </summary>
Expand Down Expand Up @@ -124,6 +129,20 @@ private void InitializeEditContext(EditContext editFormContext)
this.EditFormContext = editFormContext;
this.MapOfValidationMessages.Clear();
this.EditFormContext.OnFieldChanged += this.OnFieldChangedHandler;

this.ValidateCustomFields();
}

/// <summary>
/// Validate the custom fields contained by the collection <see cref="ImmediateValidationFields" />
/// </summary>
private void ValidateCustomFields()
{
foreach (var fieldStr in this.ImmediateValidationFields)
{
var fieldIdentifier = this.EditFormContext.Field(fieldStr);
this.MapOfValidationMessages[fieldIdentifier] = this.EditFormContext.GetValidationMessages(fieldIdentifier);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace COMETwebapp.Components.ReferenceData.ParameterTypes
{
using System.ComponentModel.DataAnnotations;

using CDP4Common.SiteDirectoryData;

using COMETwebapp.Components.Common;
using COMETwebapp.ViewModels.Components.ReferenceData.ParameterTypes;

Expand All @@ -43,6 +45,17 @@ public partial class ParameterTypeForm : SelectedDataItemForm
[Required]
public IParameterTypeTableViewModel ViewModel { get; set; }

/// <summary>
/// Gets or sets the custom validation fields names that will be validated immediately
/// </summary>
protected override IEnumerable<string> ImmediateValidationFields =>
[
nameof(DerivedQuantityKind.QuantityKindFactor),
nameof(EnumerationParameterType.ValueDefinition),
nameof(SampledFunctionParameterType.DependentParameterType),
nameof(SampledFunctionParameterType.IndependentParameterType)
];

/// <summary>
/// Method that is executed when there is a valid submit
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion COMETwebapp/Components/Tabs/TabsPanelComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@key="tab"/>
}

<TabComponent Text="Open Model"
<TabComponent Text="Select Model"
Icon="typeof(FeatherPlus)"
OnClick="@(() => this.OnOpenTabClick.Invoke())"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ParameterQuantityKindValidator(IValidationService validationService)
this.Include(new ParameterTypeValidator(validationService));
this.RuleFor(x => x.DefaultScale).NotEmpty().Validate(validationService, nameof(QuantityKind.DefaultScale));
this.RuleFor(x => x.QuantityDimensionSymbol).NotEmpty().Validate(validationService, nameof(QuantityKind.QuantityDimensionSymbol));
this.RuleFor(x => x.PossibleScale).NotEmpty().Validate(validationService, nameof(QuantityKind.PossibleScale));
this.RuleFor(x => x.PossibleScale).Validate(validationService, nameof(QuantityKind.PossibleScale));
}
}
}

0 comments on commit 00af25e

Please sign in to comment.