Skip to content

Commit

Permalink
fix bug: Edge Model Edition - When adding a new module, module name a…
Browse files Browse the repository at this point in the history
…nd uri text box not available
  • Loading branch information
Sben65 committed Aug 19, 2022
1 parent 381d213 commit e4c10c5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void ClickOnSaveShouldPostEdgeModelData()

_ = this.mockSnackbarService
.Setup(c => c.Add(It.IsAny<string>(), Severity.Success, It.IsAny<Action<SnackbarOptions>>()))
.Returns((Snackbar)null);
.Returns(value: null);

// Act
var cut = RenderComponent<CreateEdgeModelsPage>();
Expand All @@ -77,7 +77,7 @@ public void WhenEdgeModelRequiredFieldEmptyClickOnSaveShouldProssessValidationEr

_ = this.mockSnackbarService
.Setup(c => c.Add(It.IsAny<string>(), Severity.Error, It.IsAny<Action<SnackbarOptions>>()))
.Returns((Snackbar)null);
.Returns(value: null);

// Act
var cut = RenderComponent<CreateEdgeModelsPage>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public async Task ClickOnDeleteButtonShouldCloseDialog()
.Setup(x => x.DeleteIoTEdgeModel(It.Is<string>(c => c.Equals(edgeModelId, StringComparison.Ordinal))))
.Returns(Task.CompletedTask);

_ = this.mockSnackbarService.Setup(c => c.Add(It.IsAny<string>(), Severity.Success, null)).Returns((Snackbar)null);
_ = this.mockSnackbarService
.Setup(c => c.Add(It.IsAny<string>(), Severity.Success, null))
.Returns(value: null);

var cut = RenderComponent<MudDialogProvider>();
var service = Services.GetService<IDialogService>() as DialogService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@
<MudTh Style="text-align: center">See detail</MudTh>
<MudTh Style="text-align: center">Delete</MudTh>
</HeaderContent>
<RowTemplate Context="CommandContext">
<RowTemplate Context="ModuleContext">
<MudTd DataLabel="Module Name" Style="word-break: break-all;">
<MudText >@CommandContext.ModuleName</MudText>
<MudTextField id="@(nameof(IoTEdgeModule.ModuleName))" @bind-Value="@ModuleContext.ModuleName" Margin="Margin.Dense" Label="Name" For="@(() => ModuleContext.ModuleName )" Variant="Variant.Outlined" Required="true"></MudTextField>
</MudTd>
<MudTd DataLabel="Image Uri" Style="word-break: break-all;">
<MudText >@CommandContext.ImageURI</MudText>
<MudTextField id="@(nameof(IoTEdgeModule.ImageURI))" @bind-Value="@ModuleContext.ImageURI" Margin="Margin.Dense" Label="ImageURI" For="@(() => ModuleContext.ImageURI )" Variant="Variant.Outlined" Required="true" />
</MudTd>
<MudTd DataLabel="See detail" Style="text-align: center;">
<MudButton Variant="Variant.Filled" id="editButton" OnClick="(async () => await ShowEditEdgeModuleDialog(CommandContext))">Edit</MudButton>
<MudButton Variant="Variant.Filled" id="editButton" OnClick="(async () => await ShowEditEdgeModuleDialog(ModuleContext))">Edit</MudButton>
</MudTd>
<MudTd DataLabel="Delete" Style="text-align: center">
<MudIconButton Color="Color.Default" Class="deleteModuleButton" OnClick="( () => DeleteModule(CommandContext))" Icon="@Icons.Material.Filled.Delete" Size="Size.Medium"></MudIconButton>
<MudIconButton Color="Color.Default" Class="deleteModuleButton" OnClick="( () => DeleteModule(ModuleContext))" Icon="@Icons.Material.Filled.Delete" Size="Size.Medium"></MudIconButton>
</MudTd>
</RowTemplate>
<FooterContent>
Expand Down Expand Up @@ -200,6 +200,24 @@
// Displays validation error message for each field
await form.Validate();

if (!edgeModelValidator.Validate(this.EdgeModel).IsValid)
{
Snackbar.Add("One or more validation errors occurred", Severity.Error);

isProcessing = false;

return;
}

if (this.EdgeModel.EdgeModules.Any() && !edgeModuleValidator.Validate(this.EdgeModel.EdgeModules).IsValid)
{
Snackbar.Add("One or more validation errors occurred with the module.", Severity.Error);

isProcessing = false;

return;
}

try
{
await this.EdgeModelService.UpdateIoTEdgeModel(EdgeModel);
Expand Down
6 changes: 3 additions & 3 deletions src/AzureIoTHub.Portal/Server/Services/EdgeModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task CreateEdgeModel(IoTEdgeModel edgeModel)
.GetEdgeDeviceTemplates()
.GetEntityAsync<TableEntity>(DefaultPartitionKey, edgeModel.ModelId);

throw new ResourceAlreadyExistsException($"The edge model with id {edgeModel.ModelId} already exists");
throw new ResourceAlreadyExistsException($"The edge model with id {edgeModel?.ModelId} already exists");
}
catch (RequestFailedException e)
{
Expand All @@ -116,7 +116,7 @@ public async Task CreateEdgeModel(IoTEdgeModel edgeModel)
var entity = new TableEntity()
{
PartitionKey = DefaultPartitionKey,
RowKey = string.IsNullOrEmpty(edgeModel.ModelId) ? Guid.NewGuid().ToString() : edgeModel.ModelId
RowKey = string.IsNullOrEmpty(edgeModel?.ModelId) ? Guid.NewGuid().ToString() : edgeModel.ModelId
};

await SaveEntity(entity, edgeModel);
Expand Down Expand Up @@ -155,7 +155,7 @@ public async Task DeleteEdgeModel(string edgeModelId)
.GetEdgeDeviceTemplates()
.DeleteEntityAsync(DefaultPartitionKey, edgeModelId);

var config = this.configService.GetIoTEdgeConfigurations().Result.FirstOrDefault(x => x.Id.StartsWith(edgeModelId));
var config = this.configService.GetIoTEdgeConfigurations().Result.FirstOrDefault(x => x.Id.StartsWith(edgeModelId, StringComparison.Ordinal));

if (config != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,17 @@ namespace AzureIoTHub.Portal.Shared.Models.v10.IoTEdgeModule

public class ConfigModule
{
[JsonProperty(PropertyName = "settings")]
public ModuleSettings Settings { get; set; }

[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

[JsonProperty(PropertyName = "env")]
public IDictionary<string, EnvironmentVariable>? EnvironmentVariables { get; set; }

[JsonProperty(PropertyName = "status")]
public string? Status { get; set; }

[JsonProperty(PropertyName = "restarPolicy")]
public string? RestarPolicy { get; set; }

[JsonProperty(PropertyName = "version")]
public string? Version { get; set; }

public ConfigModule()
Expand All @@ -34,10 +29,8 @@ public ConfigModule()

public class ModuleSettings
{
[JsonProperty(PropertyName = "image")]
public string Image { get; set; }

[JsonProperty(PropertyName = "createOptions")]
public string CreateOptions { get; set; }

public ModuleSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ namespace AzureIoTHub.Portal.Shared.Models.v10.IoTEdgeModule

public class EdgeAgentPropertiesDesired
{
[JsonProperty(PropertyName = "modules")]
public IDictionary<string, ConfigModule> Modules { get; set; }

[JsonProperty(PropertyName = "runtime")]
public Runtime Runtime { get; set; }

[JsonProperty(PropertyName = "schemaVersion")]
public string SchemaVersion { get; set; }

[JsonProperty(PropertyName = "systemModules")]
public SystemModules SystemModules { get; set; }

public EdgeAgentPropertiesDesired()
Expand All @@ -31,10 +27,8 @@ public EdgeAgentPropertiesDesired()

public class Runtime
{
[JsonProperty(PropertyName = "settings")]
public RuntimeSettings Settings { get; set; }

[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

public Runtime()
Expand All @@ -46,7 +40,6 @@ public Runtime()

public class RuntimeSettings
{
[JsonProperty(PropertyName = "minDockerVersion")]
public string MinDockerVersion { get; set; }

public RuntimeSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
namespace AzureIoTHub.Portal.Shared.Models.v10.IoTEdgeModule
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class EdgeHubPropertiesDesired
{
[JsonProperty(PropertyName = "routes")]
public IDictionary<string, object> Routes { get; set; }

[JsonProperty(PropertyName = "schemaVersion")]
public string SchemaVersion { get; set; }

[JsonProperty(PropertyName = "storeAndForwardConfiguration")]
public StoreAndForwardConfiguration StoreAndForwardConfiguration { get; set; }

public EdgeHubPropertiesDesired()
Expand All @@ -27,7 +23,6 @@ public EdgeHubPropertiesDesired()

public class StoreAndForwardConfiguration
{
[JsonProperty(PropertyName = "timeToLiveSecs")]
public int TimeToLiveSecs { get; set; }

public StoreAndForwardConfiguration()
Expand Down

0 comments on commit e4c10c5

Please sign in to comment.