Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-13818] Allow user to edit self-hosted url during registration #11790

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form [formGroup]="formGroup" *ngIf="!hideEnvSelector">
<bit-form-field>
<bit-label>{{ "creatingAccountOn" | i18n }}</bit-label>
<bit-select formControlName="selectedRegion">
<bit-select formControlName="selectedRegion" (closed)="onSelectClosed($event)">
<bit-option
*ngFor="let regionConfig of availableRegionConfigs"
[value]="regionConfig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

import { SelfHostedEnvConfigDialogComponent } from "../../self-hosted-env-config-dialog/self-hosted-env-config-dialog.component";

/**
* Type for the selected region in the registration env selector.
*/
type RegionSelection = RegionConfig | Region.SelfHosted | null;

/**
* Component for selecting the environment to register with in the email verification registration flow.
* Outputs the selected region to the parent component so it can respond as necessary.
Expand Down Expand Up @@ -109,6 +114,9 @@
.subscribe();
}

/**
* Listens for changes to the selected region and updates the form value and emits the selected region.
*/
private listenForSelectedRegionChanges() {
this.selectedRegion.valueChanges
.pipe(
Expand All @@ -124,16 +132,12 @@
return of(null);
}

if (selectedRegion === Region.SelfHosted) {
return from(SelfHostedEnvConfigDialogComponent.open(this.dialogService)).pipe(
tap((result: boolean | undefined) =>
this.handleSelfHostedEnvConfigDialogResult(result, prevSelectedRegion),
),
);
if (selectedRegion !== Region.SelfHosted) {
this.selectedRegionChange.emit(selectedRegion);
return from(this.environmentService.setEnvironment(selectedRegion.key));

Check warning on line 137 in libs/auth/src/angular/registration/registration-env-selector/registration-env-selector.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/registration/registration-env-selector/registration-env-selector.component.ts#L136-L137

Added lines #L136 - L137 were not covered by tests
}

this.selectedRegionChange.emit(selectedRegion);
return from(this.environmentService.setEnvironment(selectedRegion.key));
return of(null);

Check warning on line 140 in libs/auth/src/angular/registration/registration-env-selector/registration-env-selector.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/registration/registration-env-selector/registration-env-selector.component.ts#L140

Added line #L140 was not covered by tests
},
),
takeUntil(this.destroy$),
Expand Down Expand Up @@ -170,6 +174,17 @@
}
}

/**
* 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(selection: RegionSelection) {
if (selection === Region.SelfHosted) {
const result = await SelfHostedEnvConfigDialogComponent.open(this.dialogService);
return this.handleSelfHostedEnvConfigDialogResult(result, selection);

Check warning on line 184 in libs/auth/src/angular/registration/registration-env-selector/registration-env-selector.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/auth/src/angular/registration/registration-env-selector/registration-env-selector.component.ts#L183-L184

Added lines #L183 - L184 were not covered by tests
}
}

ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
Expand Down
1 change: 1 addition & 0 deletions libs/components/src/select/select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(blur)="onBlur()"
[labelForId]="labelForId"
[clearable]="false"
(close)="onClose()"
appendTo="body"
>
<ng-template ng-option-tmp let-item="item">
Expand Down
12 changes: 12 additions & 0 deletions libs/components/src/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
QueryList,
Self,
ViewChild,
Output,
EventEmitter,
} from "@angular/core";
import { ControlValueAccessor, NgControl, Validators } from "@angular/forms";
import { NgSelectComponent } from "@ng-select/ng-select";
Expand All @@ -31,10 +33,12 @@
/** Optional: Options can be provided using an array input or using `bit-option` */
@Input() items: Option<T>[] = [];
@Input() placeholder = this.i18nService.t("selectPlaceholder");
@Output() closed = new EventEmitter<T>();

Check warning on line 36 in libs/components/src/select/select.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/select/select.component.ts#L36

Added line #L36 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Output() closed = new EventEmitter<T>();
@Output() closed = new EventEmitter();


protected selectedValue: T;
protected selectedOption: Option<T>;
protected searchInputId = `bit-select-search-input-${nextId++}`;
protected userSelectedValue: T;

private notifyOnChange?: (value: T) => void;
private notifyOnTouched?: () => void;
Expand Down Expand Up @@ -100,6 +104,7 @@
return;
}

this.userSelectedValue = option?.value;
this.notifyOnChange(option?.value);
}

Expand Down Expand Up @@ -156,4 +161,11 @@
private findSelectedOption(items: Option<T>[], value: T): Option<T> | undefined {
return items.find((item) => item.value === value);
}

/**
* Emits the last selected value when the select is closed.
*/
protected onClose() {
this.closed.emit(this.userSelectedValue);

Check warning on line 169 in libs/components/src/select/select.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/select/select.component.ts#L169

Added line #L169 was not covered by tests
}
}
Loading