Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { MatDialog } from '@angular/material/dialog';
import { of } from 'rxjs/internal/observable/of';
import { Observable } from 'rxjs/internal/Observable';
import { map } from 'rxjs/internal/operators/map';
import { tap } from 'rxjs/internal/operators/tap';

const MAC_ADDRESS_PATTERN =
'^[\\s]*[a-fA-F0-9]{2}(?:[:][a-fA-F0-9]{2}){5}[\\s]*$';
Expand Down Expand Up @@ -281,9 +282,15 @@ export class DeviceQualificationFromComponent implements OnInit, AfterViewInit {
if (
this.deviceHasNoChanges(this.initialDevice(), this.createDeviceFromForm())
) {
this.devicesStore.setIsOpenAddDevice(false);
return of(true);
}
return this.openCloseDialog().pipe(map(res => !!res));
return this.openCloseDialog().pipe(
tap(res => {
if (res) this.devicesStore.setIsOpenAddDevice(false);
}),
map(res => !!res)
);
}

private deviceIsEmpty(device: Device) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { map } from 'rxjs/internal/operators/map';
import { SimpleDialogComponent } from '../../../components/simple-dialog/simple-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { RiskAssessmentStore } from '../risk-assessment.store';
import { tap } from 'rxjs/internal/operators/tap';

@Component({
selector: 'app-profile-form',
Expand Down Expand Up @@ -327,9 +328,15 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {

close(): Observable<boolean> {
if (this.profileHasNoChanges() || this.profileForm.pristine) {
this.store.setIsOpenProfile(false);
return of(true);
}
return this.openCloseDialog().pipe(map(res => !!res));
return this.openCloseDialog().pipe(
tap(res => {
if (res) this.store.setIsOpenProfile(false);
}),
map(res => !!res)
);
}

openCloseDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { FocusManagerService } from '../../services/focus-manager.service';
import { AppState } from '../../store/state';
import { selectRiskProfiles } from '../../store/selectors';
import { setRiskProfiles } from '../../store/actions';
import { setRiskProfiles, setIsOpenProfile } from '../../store/actions';
import { ProfileAction } from '../../model/profile';

describe('RiskAssessmentStore', () => {
Expand Down Expand Up @@ -133,6 +133,16 @@ describe('RiskAssessmentStore', () => {
});
});

describe('setIsOpenProfile', () => {
it('should dispatch action setIsOpenProfile', () => {
riskAssessmentStore.setIsOpenProfile(true);

expect(store.dispatch).toHaveBeenCalledWith(
setIsOpenProfile({ isOpenCreateProfile: true })
);
});
});

describe('setFocus', () => {
const mockNextItem = document.createElement('div') as HTMLElement;
const mockFirstItem = document.createElement('section') as HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
selectIsOpenCreateProfile,
selectRiskProfiles,
} from '../../store/selectors';
import { setRiskProfiles } from '../../store/actions';
import { setRiskProfiles, setIsOpenProfile } from '../../store/actions';
import { EntityAction } from '../../model/entity-action';

export interface AppComponentState {
Expand Down Expand Up @@ -67,6 +67,14 @@ export class RiskAssessmentStore extends ComponentStore<AppComponentState> {
})
);

setIsOpenProfile = this.effect<boolean>(trigger$ => {
return trigger$.pipe(
tap(isOpen =>
this.store.dispatch(setIsOpenProfile({ isOpenCreateProfile: isOpen }))
)
);
});

deleteProfile = this.effect<{
name: string;
onDelete: (idx: number) => void;
Expand Down