1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-9111] Extension: persist add/edit form (#12236)

* remove todo

* Retrieve cache cipher for add-edit form

* user prefilled cipher for add-edit form

* add listener for clearing view cache

* clear local cache when clearing global state

* track initial value of cache for down stream logic that should only occur on non-cached values

* add feature flag for edit form persistence

* add tests for cipher form cache service

* fix optional initialValues

* add services to cipher form storybook

* fix strict types

* rename variables to be platform agnostic

* use deconstructed collectionIds variable to avoid them be overwritten

* use the originalCipherView for initial values

* add comment about signal equality

* prevent events from being emitted when adding uris to the existing form

- This stops other values from being overwrote in the initialization process

* add check for cached cipher when adding initial uris
This commit is contained in:
Nick Krantz
2025-01-22 10:49:07 -06:00
committed by GitHub
parent 1dfae06856
commit 5c32e5020d
22 changed files with 460 additions and 139 deletions

View File

@@ -130,8 +130,9 @@ export class AutofillOptionsComponent implements OnInit {
}
ngOnInit() {
if (this.cipherFormContainer.originalCipherView?.login) {
this.initFromExistingCipher(this.cipherFormContainer.originalCipherView.login);
const prefillCipher = this.cipherFormContainer.getInitialCipherView();
if (prefillCipher) {
this.initFromExistingCipher(prefillCipher.login);
} else {
this.initNewCipher();
}
@@ -142,17 +143,29 @@ export class AutofillOptionsComponent implements OnInit {
}
private initFromExistingCipher(existingLogin: LoginView) {
// The `uris` control is a FormArray which needs to dynamically
// add controls to the form. Doing this will trigger the `valueChanges` observable on the form
// and overwrite the `autofillOnPageLoad` value before it is set in the following `patchValue` call.
// Pass `false` to `addUri` to stop events from emitting when adding the URIs.
existingLogin.uris?.forEach((uri) => {
this.addUri({
uri: uri.uri,
matchDetection: uri.match,
});
this.addUri(
{
uri: uri.uri,
matchDetection: uri.match,
},
false,
false,
);
});
this.autofillOptionsForm.patchValue({
autofillOnPageLoad: existingLogin.autofillOnPageLoad,
});
if (this.cipherFormContainer.config.initialValues?.loginUri) {
// Only add the initial value when the cipher was not initialized from a cached state
if (
this.cipherFormContainer.config.initialValues?.loginUri &&
!this.cipherFormContainer.initializedWithCachedCipher()
) {
// Avoid adding the same uri again if it already exists
if (
existingLogin.uris?.findIndex(
@@ -197,9 +210,16 @@ export class AutofillOptionsComponent implements OnInit {
* Adds a new URI input to the form.
* @param uriFieldValue The initial value for the new URI input.
* @param focusNewInput If true, the new URI input will be focused after being added.
* @param emitEvent When false, prevents the `valueChanges` & `statusChanges` observables from firing.
*/
addUri(uriFieldValue: UriField = { uri: null, matchDetection: null }, focusNewInput = false) {
this.autofillOptionsForm.controls.uris.push(this.formBuilder.control(uriFieldValue));
addUri(
uriFieldValue: UriField = { uri: null, matchDetection: null },
focusNewInput = false,
emitEvent = true,
) {
this.autofillOptionsForm.controls.uris.push(this.formBuilder.control(uriFieldValue), {
emitEvent,
});
if (focusNewInput) {
this.focusOnNewInput$.next();