1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-26 01:23:24 +00:00

approach 1 of handling dialog close from menu item trigger

This commit is contained in:
Vicki League
2025-12-17 09:52:38 -05:00
parent e6062ec84e
commit 8ac1fb58db
9 changed files with 73 additions and 16 deletions

View File

@@ -49,6 +49,7 @@ import {
ItemModule,
ToastService,
CenterPositionStrategy,
DialogConfig,
} from "@bitwarden/components";
import {
AttachmentDialogCloseResult,
@@ -667,10 +668,15 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy {
* @param dialogService
* @param params
*/
static open(dialogService: DialogService, params: VaultItemDialogParams) {
static open(
dialogService: DialogService,
params: VaultItemDialogParams,
dialogConfig?: DialogConfig,
) {
return dialogService.open<VaultItemDialogResult, VaultItemDialogParams>(
VaultItemDialogComponent,
{
...dialogConfig,
data: params,
},
);

View File

@@ -1,5 +1,12 @@
import { CommonModule } from "@angular/common";
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from "@angular/core";
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
viewChild,
} from "@angular/core";
import { Router } from "@angular/router";
import { firstValueFrom, switchMap } from "rxjs";
@@ -56,6 +63,9 @@ export class VaultHeaderComponent {
protected CollectionDialogTabType = CollectionDialogTabType;
protected CipherType = CipherType;
/** Query for the NewCipherMenuComponent in the template */
readonly newCipherMenu = viewChild(NewCipherMenuComponent);
/**
* Boolean to determine the loading state of the header.
* Shows a loading spinner if set to true

View File

@@ -1,6 +1,15 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
import {
ChangeDetectorRef,
Component,
computed,
NgZone,
OnDestroy,
OnInit,
viewChild,
ViewChild,
} from "@angular/core";
import { ActivatedRoute, Params, Router } from "@angular/router";
import {
BehaviorSubject,
@@ -195,6 +204,12 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
// eslint-disable-next-line @angular-eslint/prefer-signals
@ViewChild("vaultItems", { static: false }) vaultItemsComponent: VaultItemsComponent<C>;
readonly vaultHeaderComponent = viewChild(VaultHeaderComponent);
readonly newButtonEl = computed(
() => this.vaultHeaderComponent()?.newCipherMenu()?.newCipherButton()?.el.nativeElement,
);
trashCleanupWarning: string = null;
kdfIterations: number;
activeFilter: VaultFilter = new VaultFilter();
@@ -861,7 +876,9 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
}
addFolder = (): void => {
AddEditFolderDialogComponent.open(this.dialogService);
AddEditFolderDialogComponent.open(this.dialogService, undefined, {
restoreFocus: this.newButtonEl(),
});
};
editFolder = async (folder: FolderFilter): Promise<void> => {
@@ -947,12 +964,18 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
formConfig: CipherFormConfig,
activeCollectionId?: CollectionId,
) {
this.vaultItemDialogRef = VaultItemDialogComponent.open(this.dialogService, {
mode,
formConfig,
activeCollectionId,
restore: this.restore,
});
this.vaultItemDialogRef = VaultItemDialogComponent.open(
this.dialogService,
{
mode,
formConfig,
activeCollectionId,
restore: this.restore,
},
{
restoreFocus: this.newButtonEl(),
},
);
const result = await lastValueFrom(this.vaultItemDialogRef.closed);
this.vaultItemDialogRef = undefined;
@@ -1098,6 +1121,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
showOrgSelector: true,
limitNestedCollections: true,
},
restoreFocus: this.newButtonEl(),
});
const result = await lastValueFrom(dialog.closed);
if (result.action === CollectionDialogAction.Saved) {
@@ -1121,6 +1145,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
initialTab: tab,
limitNestedCollections: true,
},
restoreFocus: this.newButtonEl(),
});
const result = await lastValueFrom(dialog.closed);