mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-14 10:26:19 +01:00
[PM-13818] Allow user to edit self-hosted url during registration (#11790)
* Trigger self hosted settings dialog on select close * Simplify triggering self hosted env config dialog * Always emit selected value * Update variable naming of lastSelectedValue to userSelectedValue to better reflect purpose * Add comment for userSelectedValue variable * Remove userSelectedValue and simply emit a closed event * Remove passing selectedRegion in closed event
This commit is contained in:
parent
4cc562c228
commit
619651ca55
@ -1,7 +1,7 @@
|
|||||||
<form [formGroup]="formGroup" *ngIf="!hideEnvSelector">
|
<form [formGroup]="formGroup" *ngIf="!hideEnvSelector">
|
||||||
<bit-form-field>
|
<bit-form-field>
|
||||||
<bit-label>{{ "creatingAccountOn" | i18n }}</bit-label>
|
<bit-label>{{ "creatingAccountOn" | i18n }}</bit-label>
|
||||||
<bit-select formControlName="selectedRegion">
|
<bit-select formControlName="selectedRegion" (closed)="onSelectClosed()">
|
||||||
<bit-option
|
<bit-option
|
||||||
*ngFor="let regionConfig of availableRegionConfigs"
|
*ngFor="let regionConfig of availableRegionConfigs"
|
||||||
[value]="regionConfig"
|
[value]="regionConfig"
|
||||||
|
@ -109,6 +109,9 @@ export class RegistrationEnvSelectorComponent implements OnInit, OnDestroy {
|
|||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for changes to the selected region and updates the form value and emits the selected region.
|
||||||
|
*/
|
||||||
private listenForSelectedRegionChanges() {
|
private listenForSelectedRegionChanges() {
|
||||||
this.selectedRegion.valueChanges
|
this.selectedRegion.valueChanges
|
||||||
.pipe(
|
.pipe(
|
||||||
@ -124,16 +127,12 @@ export class RegistrationEnvSelectorComponent implements OnInit, OnDestroy {
|
|||||||
return of(null);
|
return of(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedRegion === Region.SelfHosted) {
|
if (selectedRegion !== Region.SelfHosted) {
|
||||||
return from(SelfHostedEnvConfigDialogComponent.open(this.dialogService)).pipe(
|
this.selectedRegionChange.emit(selectedRegion);
|
||||||
tap((result: boolean | undefined) =>
|
return from(this.environmentService.setEnvironment(selectedRegion.key));
|
||||||
this.handleSelfHostedEnvConfigDialogResult(result, prevSelectedRegion),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectedRegionChange.emit(selectedRegion);
|
return of(null);
|
||||||
return from(this.environmentService.setEnvironment(selectedRegion.key));
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
takeUntil(this.destroy$),
|
takeUntil(this.destroy$),
|
||||||
@ -170,6 +169,17 @@ export class RegistrationEnvSelectorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the event when the select is closed.
|
||||||
|
* If the selected region is self-hosted, opens the self-hosted environment settings dialog.
|
||||||
|
*/
|
||||||
|
protected async onSelectClosed() {
|
||||||
|
if (this.selectedRegion.value === Region.SelfHosted) {
|
||||||
|
const result = await SelfHostedEnvConfigDialogComponent.open(this.dialogService);
|
||||||
|
return this.handleSelfHostedEnvConfigDialogResult(result, this.selectedRegion.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
(blur)="onBlur()"
|
(blur)="onBlur()"
|
||||||
[labelForId]="labelForId"
|
[labelForId]="labelForId"
|
||||||
[clearable]="false"
|
[clearable]="false"
|
||||||
|
(close)="onClose()"
|
||||||
appendTo="body"
|
appendTo="body"
|
||||||
>
|
>
|
||||||
<ng-template ng-option-tmp let-item="item">
|
<ng-template ng-option-tmp let-item="item">
|
||||||
|
@ -7,6 +7,8 @@ import {
|
|||||||
QueryList,
|
QueryList,
|
||||||
Self,
|
Self,
|
||||||
ViewChild,
|
ViewChild,
|
||||||
|
Output,
|
||||||
|
EventEmitter,
|
||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import { ControlValueAccessor, NgControl, Validators } from "@angular/forms";
|
import { ControlValueAccessor, NgControl, Validators } from "@angular/forms";
|
||||||
import { NgSelectComponent } from "@ng-select/ng-select";
|
import { NgSelectComponent } from "@ng-select/ng-select";
|
||||||
@ -31,6 +33,7 @@ export class SelectComponent<T> implements BitFormFieldControl, ControlValueAcce
|
|||||||
/** Optional: Options can be provided using an array input or using `bit-option` */
|
/** Optional: Options can be provided using an array input or using `bit-option` */
|
||||||
@Input() items: Option<T>[] = [];
|
@Input() items: Option<T>[] = [];
|
||||||
@Input() placeholder = this.i18nService.t("selectPlaceholder");
|
@Input() placeholder = this.i18nService.t("selectPlaceholder");
|
||||||
|
@Output() closed = new EventEmitter();
|
||||||
|
|
||||||
protected selectedValue: T;
|
protected selectedValue: T;
|
||||||
protected selectedOption: Option<T>;
|
protected selectedOption: Option<T>;
|
||||||
@ -156,4 +159,9 @@ export class SelectComponent<T> implements BitFormFieldControl, ControlValueAcce
|
|||||||
private findSelectedOption(items: Option<T>[], value: T): Option<T> | undefined {
|
private findSelectedOption(items: Option<T>[], value: T): Option<T> | undefined {
|
||||||
return items.find((item) => item.value === value);
|
return items.find((item) => item.value === value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Emits the closed event. */
|
||||||
|
protected onClose() {
|
||||||
|
this.closed.emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user