1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

add fallback for navigating the user back when the browser is in a popout (#10024)

This commit is contained in:
Nick Krantz
2024-07-11 17:32:53 -05:00
committed by GitHub
parent 9dda29fb9c
commit 66f432d6e0
5 changed files with 51 additions and 7 deletions

View File

@@ -1,11 +1,16 @@
<popup-page> <popup-page>
<popup-header slot="header" [pageTitle]="headerText" showBackButton> </popup-header> <popup-header
slot="header"
[pageTitle]="headerText"
[backAction]="handleBackButton.bind(this)"
showBackButton
></popup-header>
<vault-cipher-form <vault-cipher-form
*ngIf="!loading" *ngIf="!loading"
formId="cipherForm" formId="cipherForm"
[config]="config" [config]="config"
(cipherSaved)="onCipherSaved($event)" (cipherSaved)="onCipherSaved()"
[submitBtn]="submitBtn" [submitBtn]="submitBtn"
> >
<app-open-attachments <app-open-attachments

View File

@@ -2,14 +2,13 @@ import { CommonModule, Location } from "@angular/common";
import { Component } from "@angular/core"; import { Component } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormsModule } from "@angular/forms"; import { FormsModule } from "@angular/forms";
import { ActivatedRoute, Params } from "@angular/router"; import { ActivatedRoute, Params, Router } from "@angular/router";
import { map, switchMap } from "rxjs"; import { map, switchMap } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module"; import { JslibModule } from "@bitwarden/angular/jslib.module";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherId, CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CipherId, CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherType } from "@bitwarden/common/vault/enums";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { AsyncActionsModule, ButtonModule, SearchModule } from "@bitwarden/components"; import { AsyncActionsModule, ButtonModule, SearchModule } from "@bitwarden/components";
import { import {
CipherFormConfig, CipherFormConfig,
@@ -112,11 +111,29 @@ export class AddEditV2Component {
private location: Location, private location: Location,
private i18nService: I18nService, private i18nService: I18nService,
private addEditFormConfigService: CipherFormConfigService, private addEditFormConfigService: CipherFormConfigService,
private router: Router,
) { ) {
this.subscribeToParams(); this.subscribeToParams();
} }
onCipherSaved(savedCipher: CipherView) { /**
* Navigates to previous view or view-cipher path
* depending on the history length.
*
* This can happen when history is lost due to the extension being
* forced into a popout window.
*/
async handleBackButton() {
if (history.length === 1) {
await this.router.navigate(["/view-cipher"], {
queryParams: { cipherId: this.originalCipherId },
});
} else {
this.location.back();
}
}
onCipherSaved() {
this.location.back(); this.location.back();
} }

View File

@@ -1,5 +1,10 @@
<popup-page> <popup-page>
<popup-header slot="header" [pageTitle]="'attachments' | i18n" showBackButton> <popup-header
slot="header"
[pageTitle]="'attachments' | i18n"
showBackButton
[backAction]="handleBackButton.bind(this)"
>
<app-pop-out slot="end" /> <app-pop-out slot="end" />
</popup-header> </popup-header>

View File

@@ -26,6 +26,7 @@ import { CipherAttachmentsComponent } from "./cipher-attachments/cipher-attachme
}) })
class MockPopupHeaderComponent { class MockPopupHeaderComponent {
@Input() pageTitle: string; @Input() pageTitle: string;
@Input() backAction: () => void;
} }
@Component({ @Component({

View File

@@ -1,4 +1,4 @@
import { CommonModule } from "@angular/common"; import { CommonModule, Location } from "@angular/common";
import { Component } from "@angular/core"; import { Component } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { ActivatedRoute, Router } from "@angular/router"; import { ActivatedRoute, Router } from "@angular/router";
@@ -41,6 +41,7 @@ export class AttachmentsV2Component {
constructor( constructor(
private router: Router, private router: Router,
private cipherService: CipherService, private cipherService: CipherService,
private location: Location,
route: ActivatedRoute, route: ActivatedRoute,
) { ) {
route.queryParams.pipe(takeUntilDestroyed(), first()).subscribe(({ cipherId }) => { route.queryParams.pipe(takeUntilDestroyed(), first()).subscribe(({ cipherId }) => {
@@ -48,6 +49,21 @@ export class AttachmentsV2Component {
}); });
} }
/**
* Navigates to previous view or edit-cipher path
* depending on the history length.
*
* This can happen when history is lost due to the extension being
* forced into a popout window.
*/
async handleBackButton() {
if (history.length === 1) {
await this.navigateToEditScreen();
} else {
this.location.back();
}
}
/** Navigate the user back to the edit screen after uploading an attachment */ /** Navigate the user back to the edit screen after uploading an attachment */
async navigateToEditScreen() { async navigateToEditScreen() {
const cipherDomain = await this.cipherService.get(this.cipherId); const cipherDomain = await this.cipherService.get(this.cipherId);