SM-634: Fix file extension bug on export (#4964)

* SM-634: Fix file extension bug on export

* SM-634: Refactor to use index for option selection
This commit is contained in:
Colton Hurst 2023-03-09 13:56:29 -05:00 committed by GitHub
parent 2b4a8705da
commit d68680a789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -10,7 +10,9 @@
<bit-form-field class="tw-max-w-sm">
<bit-label>{{ "fileFormat" | i18n }}</bit-label>
<select bitInput formControlName="format">
<option *ngFor="let format of exportFormats" [ngValue]="format">{{ format }}</option>
<option *ngFor="let format of exportFormats; let i = index" [value]="i">
{{ format.name }}
</option>
</select>
</bit-form-field>

View File

@ -14,6 +14,11 @@ import { UserVerificationPromptComponent } from "@bitwarden/web-vault/app/compon
import { SecretsManagerPortingApiService } from "../services/sm-porting-api.service";
import { SecretsManagerPortingService } from "../services/sm-porting.service";
type ExportFormat = {
name: string;
fileExtension: string;
};
@Component({
selector: "sm-export",
templateUrl: "./sm-export.component.html",
@ -23,10 +28,10 @@ export class SecretsManagerExportComponent implements OnInit, OnDestroy {
protected orgName: string;
protected orgId: string;
protected exportFormats: string[] = ["Bitwarden (json)"];
protected exportFormats: ExportFormat[] = [{ name: "Bitwarden (json)", fileExtension: "json" }];
protected formGroup = new FormGroup({
format: new FormControl("Bitwarden (json)", [Validators.required]),
format: new FormControl(0, [Validators.required]),
});
constructor(
@ -76,12 +81,10 @@ export class SecretsManagerExportComponent implements OnInit, OnDestroy {
};
private async doExport() {
const exportData = await this.secretsManagerApiService.export(
this.orgId,
this.formGroup.get("format").value
);
const fileExtension = this.exportFormats[this.formGroup.get("format").value].fileExtension;
const exportData = await this.secretsManagerApiService.export(this.orgId, fileExtension);
await this.downloadFile(exportData, this.formGroup.get("format").value);
await this.downloadFile(exportData, fileExtension);
this.platformUtilsService.showToast("success", null, this.i18nService.t("dataExportSuccess"));
}