Skip to content

Commit

Permalink
add static open method for folder dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-livefront committed Dec 20, 2024
1 parent b20827e commit 1b442f6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ export class NewItemDropdownV2Component implements OnInit {
}

openFolderDialog() {
this.dialogService.open(AddEditFolderDialogComponent);
AddEditFolderDialogComponent.open(this.dialogService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ describe("FoldersV2Component", () => {
let component: FoldersV2Component;
let fixture: ComponentFixture<FoldersV2Component>;
const folderViews$ = new BehaviorSubject<FolderView[]>([]);
const open = jest.fn();
const open = jest.spyOn(AddEditFolderDialogComponent, "open");
const mockDialogService = { open: jest.fn() };

beforeEach(async () => {
open.mockClear();
Expand All @@ -64,7 +65,7 @@ describe("FoldersV2Component", () => {
imports: [MockPopupHeaderComponent, MockPopupFooterComponent],
},
})
.overrideProvider(DialogService, { useValue: { open } })
.overrideProvider(DialogService, { useValue: mockDialogService })
.compileComponents();

fixture = TestBed.createComponent(FoldersV2Component);
Expand Down Expand Up @@ -97,9 +98,7 @@ describe("FoldersV2Component", () => {

editButton.triggerEventHandler("click");

expect(open).toHaveBeenCalledWith(AddEditFolderDialogComponent, {
data: { editFolderConfig: { folder } },
});
expect(open).toHaveBeenCalledWith(mockDialogService, { editFolderConfig: { folder } });
});

it("opens add dialog for new folder when there are no folders", () => {
Expand All @@ -110,6 +109,6 @@ describe("FoldersV2Component", () => {

addButton.triggerEventHandler("click");

expect(open).toHaveBeenCalledWith(AddEditFolderDialogComponent, { data: {} });
expect(open).toHaveBeenCalledWith(mockDialogService, {});
});
});
10 changes: 2 additions & 8 deletions apps/browser/src/vault/popup/settings/folders-v2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import {
DialogService,
IconButtonModule,
} from "@bitwarden/components";
import {
AddEditFolderDialogComponent,
AddEditFolderDialogData,
VaultIcons,
} from "@bitwarden/vault";
import { AddEditFolderDialogComponent, VaultIcons } from "@bitwarden/vault";

import { ItemGroupComponent } from "../../../../../../libs/components/src/item/item-group.component";
import { ItemModule } from "../../../../../../libs/components/src/item/item.module";
Expand Down Expand Up @@ -67,8 +63,6 @@ export class FoldersV2Component {
// If a folder is provided, the edit variant should be shown
const editFolderConfig = folder ? { folder } : undefined;

this.dialogService.open<unknown, AddEditFolderDialogData>(AddEditFolderDialogComponent, {
data: { editFolderConfig },
});
AddEditFolderDialogComponent.open(this.dialogService, { editFolderConfig });
}
}
12 changes: 4 additions & 8 deletions apps/web/src/app/vault/individual-vault/vault.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import { ServiceUtils } from "@bitwarden/common/vault/service-utils";
import { DialogService, Icons, ToastService } from "@bitwarden/components";
import {
AddEditFolderDialogComponent,
AddEditFolderDialogData,
AddEditFolderDialogResult,
CipherFormConfig,
CollectionAssignmentResult,
Expand Down Expand Up @@ -572,16 +571,13 @@ export class VaultComponent implements OnInit, OnDestroy {
}

addFolder = (): void => {
this.dialogService.open(AddEditFolderDialogComponent);
AddEditFolderDialogComponent.open(this.dialogService);
};

editFolder = async (folder: FolderFilter): Promise<void> => {
const dialogRef = this.dialogService.open<AddEditFolderDialogResult, AddEditFolderDialogData>(
AddEditFolderDialogComponent,
{
data: { editFolderConfig: { folder } },
},
);
const dialogRef = AddEditFolderDialogComponent.open(this.dialogService, {
editFolderConfig: { folder },
});

const result = await lastValueFrom(dialogRef.closed);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,11 @@ export class AddEditFolderDialogComponent implements AfterViewInit, OnInit {
private close(result: AddEditFolderDialogResult) {
this.dialogRef.close(result);
}

static open(dialogService: DialogService, data?: AddEditFolderDialogData) {
return dialogService.open<AddEditFolderDialogResult, AddEditFolderDialogData>(
AddEditFolderDialogComponent,
{ data },
);
}
}

0 comments on commit 1b442f6

Please sign in to comment.