Skip to content

Commit

Permalink
NAS-124985 / 24.04 / Removing mutability of state object (#9167)
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanY147 authored Nov 10, 2023
1 parent b13b5e0 commit 0c4e658
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export class ConfigurationPreviewComponent {

protected topology$ = this.store.topology$.pipe(
map((topology) => {
if (this.store.isUsingDraidLayout(topology)) {
delete topology.spare;
const newTopology = { ...topology };
if (this.store.isUsingDraidLayout(newTopology)) {
delete newTopology.spare;
}
return topology;
return newTopology;
}),
);
protected totalCapacity$ = this.store.totalUsableCapacity$;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { ReactiveFormsModule } from '@angular/forms';
import { createComponentFactory, mockProvider, Spectator } from '@ngneat/spectator/jest';
import { MockComponents } from 'ng-mocks';
import { Subject } from 'rxjs';
import { of, Subject } from 'rxjs';
import { CreateVdevLayout, VdevType } from 'app/enums/v-dev-type.enum';
import { UnusedDisk } from 'app/interfaces/storage.interface';
import { IxSelectHarness } from 'app/modules/ix-forms/components/ix-select/ix-select.harness';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('AutomatedDiskSelection', () => {
mockProvider(PoolManagerStore, {
startOver$,
resetStep$,
isLoading$: of(false),
}),
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/c
import { FormControl, Validators } from '@angular/forms';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { merge, of } from 'rxjs';
import { filter } from 'rxjs/operators';
import { filter, take } from 'rxjs/operators';
import { CreateVdevLayout, vdevLayoutOptions, VdevType } from 'app/enums/v-dev-type.enum';
import { SelectOption } from 'app/interfaces/option.interface';
import { IxSimpleChanges } from 'app/interfaces/simple-changes.interface';
Expand Down Expand Up @@ -59,6 +59,16 @@ export class AutomatedDiskSelectionComponent implements OnChanges {
}

private updateStoreOnChanges(): void {
this.store.isLoading$.pipe(filter((isLoading) => !isLoading), take(1), untilDestroyed(this)).subscribe({
next: () => {
if (
(!this.canChangeLayout && !this.isDataVdev)
&& (this.type && this.limitLayouts.length)
) {
this.store.setTopologyCategoryLayout(this.type, this.limitLayouts[0]);
}
},
});
this.layoutControl.valueChanges.pipe(untilDestroyed(this)).subscribe((layout) => {
this.store.setTopologyCategoryLayout(this.type, layout);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</mat-step>

<mat-step
*ngIf="!(usesDraidLayout$ | async) && !alreadyHasSpare && state.topology[PoolCreationWizardStep.Spare]"
*ngIf="!(usesDraidLayout$ | async) && state.topology[PoolCreationWizardStep.Spare]"
ixStepActivation
[errorMessage]="getTopLevelErrorForStep(PoolCreationWizardStep.Spare)"
[hasError]="!!getTopLevelErrorForStep(PoolCreationWizardStep.Spare) && getWasStepActivated(PoolCreationWizardStep.Spare)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ describe('PoolManagerComponent – creating dRAID pool', () => {
],
cache: [],
dedup: [],
spares: [],
log: [],
special: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,15 @@ export class PoolManagerStore extends ComponentStore<PoolManagerState> {
}

readonly resetTopologyCategory = this.updater((state, category: VdevType) => {
const newCategory = { ...initialTopology[category] };
if (category === VdevType.Spare || category === VdevType.Cache) {
newCategory.layout = CreateVdevLayout.Stripe;
}
return {
...state,
topology: {
...state.topology,
[category]: initialTopology[category],
[category]: newCategory,
},
};
});
Expand Down

0 comments on commit 0c4e658

Please sign in to comment.