mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 00:33:44 +00:00
[PM-24305] Only enable the cipher form when it is disabled (#16259)
* only enable the cipher form when it is disabled * switch to tracking the last emitted state for disabled rather than the form status. The form status can be changed if any child control changes
This commit is contained in:
@@ -122,4 +122,33 @@ describe("CipherFormComponent", () => {
|
|||||||
expect(component["updatedCipherView"]?.login.fido2Credentials).toBeNull();
|
expect(component["updatedCipherView"]?.login.fido2Credentials).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("enableFormFields", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// disable the form so enabling occurs
|
||||||
|
component.disableFormFields();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("only enables the form when it is disabled", () => {
|
||||||
|
jest.spyOn(component["cipherForm"], "enable");
|
||||||
|
component.enableFormFields();
|
||||||
|
|
||||||
|
expect(component["cipherForm"].enable).toHaveBeenCalled();
|
||||||
|
|
||||||
|
component.enableFormFields();
|
||||||
|
component.enableFormFields();
|
||||||
|
|
||||||
|
// enable is only called once
|
||||||
|
expect(component["cipherForm"].enable).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("emits formStatusChange$", (done) => {
|
||||||
|
component.formStatusChange$.subscribe((status) => {
|
||||||
|
expect(status).toBe("enabled");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.enableFormFields();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { FormBuilder, FormGroup, ReactiveFormsModule } from "@angular/forms";
|
import { FormBuilder, FormGroup, ReactiveFormsModule } from "@angular/forms";
|
||||||
import { Subject } from "rxjs";
|
import { BehaviorSubject, Subject } from "rxjs";
|
||||||
|
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { CipherType, SecureNoteType } from "@bitwarden/common/vault/enums";
|
import { CipherType, SecureNoteType } from "@bitwarden/common/vault/enums";
|
||||||
@@ -115,7 +115,7 @@ export class CipherFormComponent implements AfterViewInit, OnInit, OnChanges, Ci
|
|||||||
/**
|
/**
|
||||||
* Emitted when the form is enabled
|
* Emitted when the form is enabled
|
||||||
*/
|
*/
|
||||||
private formStatusChangeSubject = new Subject<"enabled" | "disabled">();
|
private formStatusChangeSubject = new BehaviorSubject<"enabled" | "disabled" | null>(null);
|
||||||
@Output() formStatusChange$ = this.formStatusChangeSubject.asObservable();
|
@Output() formStatusChange$ = this.formStatusChangeSubject.asObservable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -161,10 +161,18 @@ export class CipherFormComponent implements AfterViewInit, OnInit, OnChanges, Ci
|
|||||||
this.formStatusChangeSubject.next("disabled");
|
this.formStatusChangeSubject.next("disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the form, only when it is currently disabled.
|
||||||
|
* Child forms could have disabled some of their controls based on
|
||||||
|
* other factors. Enabling the form from this level should only occur
|
||||||
|
* when the form was disabled at this level.
|
||||||
|
*/
|
||||||
enableFormFields(): void {
|
enableFormFields(): void {
|
||||||
|
if (this.formStatusChangeSubject.getValue() === "disabled") {
|
||||||
this.cipherForm.enable({ emitEvent: false });
|
this.cipherForm.enable({ emitEvent: false });
|
||||||
this.formStatusChangeSubject.next("enabled");
|
this.formStatusChangeSubject.next("enabled");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a child form group with the parent form group. Used by child components to add their form groups to
|
* Registers a child form group with the parent form group. Used by child components to add their form groups to
|
||||||
|
|||||||
Reference in New Issue
Block a user