1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-01 04:37:40 +02:00

[EC-650] Revert observable usage from ImportComponent (#4010)

This commit is contained in:
Rui Tomé 2022-11-08 17:35:15 +00:00 committed by GitHub
parent 6851f406ef
commit aac33d32b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 19 deletions

View File

@ -1,7 +1,7 @@
<div class="page-header"> <div class="page-header">
<h1>{{ "importData" | i18n }}</h1> <h1>{{ "importData" | i18n }}</h1>
</div> </div>
<app-callout type="info" *ngIf="importBlockedByPolicy$ | async"> <app-callout type="info" *ngIf="importBlockedByPolicy">
{{ "personalOwnershipPolicyInEffectImports" | i18n }} {{ "personalOwnershipPolicyInEffectImports" | i18n }}
</app-callout> </app-callout>
<form #form (ngSubmit)="submit()" ngNativeValidate> <form #form (ngSubmit)="submit()" ngNativeValidate>
@ -14,7 +14,7 @@
name="Format" name="Format"
[(ngModel)]="format" [(ngModel)]="format"
class="form-control" class="form-control"
[disabled]="importBlockedByPolicy$ | async" [disabled]="importBlockedByPolicy"
required required
> >
<option *ngFor="let o of featuredImportOptions" [ngValue]="o.id">{{ o.name }}</option> <option *ngFor="let o of featuredImportOptions" [ngValue]="o.id">{{ o.name }}</option>
@ -296,7 +296,7 @@
id="file" id="file"
class="form-control-file" class="form-control-file"
name="file" name="file"
[disabled]="importBlockedByPolicy$ | async" [disabled]="importBlockedByPolicy"
/> />
</div> </div>
</div> </div>
@ -308,14 +308,14 @@
class="form-control" class="form-control"
name="FileContents" name="FileContents"
[(ngModel)]="fileContents" [(ngModel)]="fileContents"
[disabled]="importBlockedByPolicy$ | async" [disabled]="importBlockedByPolicy"
></textarea> ></textarea>
</div> </div>
<button <button
type="submit" type="submit"
class="btn btn-primary btn-submit" class="btn btn-primary btn-submit"
[disabled]="loading || (importBlockedByPolicy$ | async)" [disabled]="loading || importBlockedByPolicy"
[ngClass]="{ manual: importBlockedByPolicy$ | async }" [ngClass]="{ manual: importBlockedByPolicy }"
> >
<i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i> <i class="bwi bwi-spinner bwi-spin" title="{{ 'loading' | i18n }}" aria-hidden="true"></i>
<span>{{ "importData" | i18n }}</span> <span>{{ "importData" | i18n }}</span>

View File

@ -1,7 +1,7 @@
import { Component, OnDestroy, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import * as JSZip from "jszip"; import * as JSZip from "jszip";
import { firstValueFrom, Subject } from "rxjs"; import { firstValueFrom } from "rxjs";
import Swal, { SweetAlertIcon } from "sweetalert2"; import Swal, { SweetAlertIcon } from "sweetalert2";
import { ModalService } from "@bitwarden/angular/services/modal.service"; import { ModalService } from "@bitwarden/angular/services/modal.service";
@ -20,22 +20,18 @@ import { FilePasswordPromptComponent } from "./file-password-prompt.component";
selector: "app-import", selector: "app-import",
templateUrl: "import.component.html", templateUrl: "import.component.html",
}) })
export class ImportComponent implements OnInit, OnDestroy { export class ImportComponent implements OnInit {
featuredImportOptions: ImportOption[]; featuredImportOptions: ImportOption[];
importOptions: ImportOption[]; importOptions: ImportOption[];
format: ImportType = null; format: ImportType = null;
fileContents: string; fileContents: string;
formPromise: Promise<ImportError>; formPromise: Promise<ImportError>;
loading = false; loading = false;
importBlockedByPolicy$ = this.policyService.policyAppliesToActiveUser$( importBlockedByPolicy = false;
PolicyType.PersonalOwnership
);
protected organizationId: string = null; protected organizationId: string = null;
protected successNavigate: any[] = ["vault"]; protected successNavigate: any[] = ["vault"];
private destroy$ = new Subject<void>();
constructor( constructor(
protected i18nService: I18nService, protected i18nService: I18nService,
protected importService: ImportService, protected importService: ImportService,
@ -48,15 +44,14 @@ export class ImportComponent implements OnInit, OnDestroy {
async ngOnInit() { async ngOnInit() {
this.setImportOptions(); this.setImportOptions();
}
ngOnDestroy(): void { this.importBlockedByPolicy = await firstValueFrom(
this.destroy$.next(); this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership)
this.destroy$.complete(); );
} }
async submit() { async submit() {
if (await firstValueFrom(this.importBlockedByPolicy$)) { if (this.importBlockedByPolicy) {
this.platformUtilsService.showToast( this.platformUtilsService.showToast(
"error", "error",
null, null,