Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Fix previous item type switch field value stash/reapply alias flag (#2457)

Leendert de Borste9c8dd2971da
diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
index c0955070c..cedeaccf0 100644
--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemAddEdit.tsx
@@ -996,10 +996,10 @@ const ItemAddEdit: React.FC = () => {
setInitiallyVisibleFields(prev => new Set([...prev].filter(applies)));
}
- // Reset alias generated flag, so alias fields will be filled (again) if they are shown by the new type
- aliasGeneratedRef.current = false;
- aliasRequestedByTypeChangeRef.current = isEditMode && oldType !== newType && newType === ItemTypes.Alias &&
- ['alias.first_name', 'alias.last_name', 'alias.gender', 'alias.birthdate'].every(key => !((nextValues[key] as string) ?? '').trim());
+ // Reset alias generated flag, so empty alias fields will be filled (again) if they are shown by the new type
+ const aliasFieldsEmpty = ['alias.first_name', 'alias.last_name', 'alias.gender', 'alias.birthdate'].every(key => !((nextValues[key] as string) ?? '').trim());
+ aliasGeneratedRef.current = !aliasFieldsEmpty;
+ aliasRequestedByTypeChangeRef.current = isEditMode && oldType !== newType && newType === ItemTypes.Alias && aliasFieldsEmpty;
/*
* Update email field mode based on new item type
diff --git a/apps/browser-extension/tests/fixtures/TestClient.ts b/apps/browser-extension/tests/fixtures/TestClient.ts
index f77daf75a..16d981369 100644
--- a/apps/browser-extension/tests/fixtures/TestClient.ts
+++ b/apps/browser-extension/tests/fixtures/TestClient.ts
@@ -284,6 +284,15 @@ export class TestClient {
return this;
}
+ /**
+ * Switch the item type on the add/edit form.
+ */
+ async switchItemType(type: 'Login' | 'Alias' | 'CreditCard' | 'Note'): Promise<this> {
+ await this.popup.click(ButtonSelectors.ITEM_TYPE_SELECTOR);
+ await this.popup.click(`button#item-type-option-${type}`);
+ return this;
+ }
+
/**
* Fill a field in the credential form.
*/
diff --git a/apps/browser-extension/tests/fixtures/selectors.ts b/apps/browser-extension/tests/fixtures/selectors.ts
index 410a59162..35868226b 100644
--- a/apps/browser-extension/tests/fixtures/selectors.ts
+++ b/apps/browser-extension/tests/fixtures/selectors.ts
@@ -89,4 +89,5 @@ export const ButtonSelectors = {
EDIT_ITEM: 'button[title="Edit Item"]',
SAVE: 'button#save-credential',
ADD_FIELD_MENU: 'button#add-field-menu',
+ ITEM_TYPE_SELECTOR: 'button#item-type-selector',
} as const;
diff --git a/apps/mobile-app/components/items/AddEditItemScreen.tsx b/apps/mobile-app/components/items/AddEditItemScreen.tsx
index fa7fcc4f3..aaaa159ed 100644
--- a/apps/mobile-app/components/items/AddEditItemScreen.tsx
+++ b/apps/mobile-app/components/items/AddEditItemScreen.tsx
@@ -619,10 +619,10 @@ export default function AddEditItemScreen({ editRef }: AddEditItemScreenProps):
}
}
- // Reset alias generated flag
- aliasGeneratedRef.current = false;
- aliasRequestedByTypeChangeRef.current = isEditMode && oldType !== newType && newType === ItemTypes.Alias &&
- ['alias.first_name', 'alias.last_name', 'alias.gender', 'alias.birthdate'].every(key => !((nextValues[key] as string) ?? '').trim());
+ // Reset alias generated flag, so empty alias fields will be filled (again) if they are shown by the new type
+ const aliasFieldsEmpty = ['alias.first_name', 'alias.last_name', 'alias.gender', 'alias.birthdate'].every(key => !((nextValues[key] as string) ?? '').trim());
+ aliasGeneratedRef.current = !aliasFieldsEmpty;
+ aliasRequestedByTypeChangeRef.current = isEditMode && oldType !== newType && newType === ItemTypes.Alias && aliasFieldsEmpty;
setItem({
...item,