Skip to content

Commit

Permalink
Disable save button on save device #848
Browse files Browse the repository at this point in the history
  • Loading branch information
hocinehacherouf committed Jul 11, 2022
1 parent f122fd1 commit 1458060
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ public async Task ClickOnSaveShouldPostDeviceDetailsAsync()
.Setup(service => service.SetDeviceProperties(expectedDeviceDetails.DeviceID, It.IsAny<IList<DevicePropertyValue>>()))
.Returns(Task.CompletedTask);

var mockDialogReference = new DialogReference(Guid.NewGuid(), this.mockDialogService.Object);
_ = this.mockDialogService.Setup(c => c.Show<ProcessingDialog>("Processing", It.IsAny<DialogParameters>()))
.Returns(mockDialogReference);
_ = this.mockDialogService.Setup(c => c.Close(It.Is<DialogReference>(x => x == mockDialogReference)));

var cut = RenderComponent<CreateDevicePage>();
var saveButton = cut.WaitForElement("#SaveButton");

Expand Down Expand Up @@ -209,11 +204,6 @@ public async Task SaveShouldProcessProblemDetailsExceptionWhenIssueOccursOnCreat
.Setup(service => service.GetDeviceModelModelProperties(mockDeviceModel.ModelId))
.ReturnsAsync(new List<DeviceProperty>());

var mockDialogReference = new DialogReference(Guid.NewGuid(), this.mockDialogService.Object);
_ = this.mockDialogService.Setup(c => c.Show<ProcessingDialog>("Processing", It.IsAny<DialogParameters>()))
.Returns(mockDialogReference);
_ = this.mockDialogService.Setup(c => c.Close(It.Is<DialogReference>(x => x == mockDialogReference)));

// Act
var cut = RenderComponent<CreateDevicePage>();
var saveButton = cut.WaitForElement("#SaveButton");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@attribute [Authorize]
@inject ISnackbar Snackbar
@inject NavigationManager NavManager
@inject IDialogService DialogService
@inject IDeviceModelsClientService DeviceModelsClientService
@inject ILoRaWanDeviceModelsClientService LoRaWanDeviceModelsClientService
@inject IDeviceTagSettingsClientService DeviceTagSettingsClientService
Expand All @@ -33,7 +32,7 @@
</MudCardContent>
</MudCard>
<MudItem xs="12" Class="d-flex justify-center py-2 px-1 mt-4">
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="Save" id="SaveButton">Save Changes</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="Save" id="SaveButton" Disabled="isProcessing">Save Changes</MudButton>
</MudItem>
</MudItem>
<MudItem xs="12" sm="8" md="9">
Expand Down Expand Up @@ -259,6 +258,8 @@

private bool displayValidationErrorMessages = false;

private bool isProcessing;

protected override async Task OnInitializedAsync()
{
try
Expand Down Expand Up @@ -288,24 +289,24 @@
/// </summary>
public async void Save()
{
var parameters = new DialogParameters { { "ContentText", "Processing" } };
DialogReference processingDialog = DialogService.Show<ProcessingDialog>("Processing", parameters) as DialogReference;

try
{
isProcessing = true;

await form.Validate();
bool tagValidationError = CheckTagsError();

if (!standardValidator.Validate(Device).IsValid
|| (IsLoRa && !this.loraValidator.Validate(this.Device as LoRaDeviceDetails).IsValid)
|| tagValidationError)
{
DialogService.Close(processingDialog);
Snackbar.Add("One or more validation errors occurred", Severity.Error);

// Allows to display ValidationError messages for the MudAutocomplete field.
displayValidationErrorMessages = true;

isProcessing = false;

return;
}

Expand All @@ -329,7 +330,7 @@
}
finally
{
DialogService.Close(processingDialog);
isProcessing = false;
}
}

Expand Down

0 comments on commit 1458060

Please sign in to comment.