Skip to content

Commit

Permalink
SM-634: Fix file extension bug on export (bitwarden#4964)
Browse files Browse the repository at this point in the history
* SM-634: Fix file extension bug on export

* SM-634: Refactor to use index for option selection
  • Loading branch information
coltonhurst authored Mar 9, 2023
1 parent 2b4a870 commit d68680a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -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"));
}

Expand Down

0 comments on commit d68680a

Please sign in to comment.