fix(ui): use signals in OIDC test connection (#2417)
This commit is contained in:
+11
-11
@@ -250,14 +250,14 @@
|
||||
|
||||
<div class="provider-actions-row">
|
||||
<div class="test-results-inline">
|
||||
@if (testConnectionResult) {
|
||||
@if (testConnectionResult()) {
|
||||
<div class="test-results-toggle"
|
||||
[style.border-radius]="showTestDetails ? '6px 6px 0 0' : '6px'"
|
||||
[style.border-radius]="showTestDetails() ? '6px 6px 0 0' : '6px'"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
(click)="showTestDetails = !showTestDetails"
|
||||
(keydown.enter)="showTestDetails = !showTestDetails">
|
||||
@if (testConnectionResult.success) {
|
||||
(click)="toggleTestDetails()"
|
||||
(keydown.enter)="toggleTestDetails()">
|
||||
@if (testConnectionResult()?.success) {
|
||||
<i class="pi pi-check-circle text-emerald-700 dark:text-emerald-300"></i>
|
||||
<span>{{ t('testConnection.passed') }}</span>
|
||||
} @else {
|
||||
@@ -265,9 +265,9 @@
|
||||
<span>{{ t('testConnection.failed') }}</span>
|
||||
}
|
||||
<span style="color: var(--p-text-muted-color); font-size: 0.75rem;">
|
||||
({{ testConnectionResult.checks.length }} {{ t('testConnection.checks') }})
|
||||
({{ testConnectionResult()?.checks?.length ?? 0 }} {{ t('testConnection.checks') }})
|
||||
</span>
|
||||
<i class="pi pi-chevron-right toggle-chevron" [class.expanded]="showTestDetails"></i>
|
||||
<i class="pi pi-chevron-right toggle-chevron" [class.expanded]="showTestDetails()"></i>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -275,11 +275,11 @@
|
||||
<p-button
|
||||
[outlined]="true"
|
||||
[label]="t('testConnection.button')"
|
||||
[icon]="isTestingConnection ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
|
||||
[icon]="isTestingConnection() ? 'pi pi-spin pi-spinner' : 'pi pi-bolt'"
|
||||
severity="info"
|
||||
size="small"
|
||||
(click)="testConnection()"
|
||||
[disabled]="!oidcProvider.issuerUri || isTestingConnection">
|
||||
[disabled]="!oidcProvider.issuerUri || isTestingConnection()">
|
||||
</p-button>
|
||||
<p-button
|
||||
[outlined]="true"
|
||||
@@ -292,9 +292,9 @@
|
||||
</p-button>
|
||||
</div>
|
||||
</div>
|
||||
@if (testConnectionResult && showTestDetails) {
|
||||
@if (testConnectionResult() && showTestDetails()) {
|
||||
<div class="test-results-details">
|
||||
@for (check of testConnectionResult.checks; track check.name) {
|
||||
@for (check of testConnectionResult()?.checks; track check.name) {
|
||||
<div class="test-check-row">
|
||||
@switch (check.status) {
|
||||
@case ('PASS') {
|
||||
|
||||
+4
-4
@@ -495,12 +495,12 @@ describe('AuthenticationSettingsComponent', () => {
|
||||
|
||||
component.testConnection();
|
||||
|
||||
expect(component.isTestingConnection).toBe(false);
|
||||
expect(component.testConnectionResult).toEqual({
|
||||
expect(component.isTestingConnection()).toBe(false);
|
||||
expect(component.testConnectionResult()).toEqual({
|
||||
success: true,
|
||||
checks: [{name: 'issuer', status: 'PASS', message: 'ok'}],
|
||||
});
|
||||
expect(component.showTestDetails).toBe(true);
|
||||
expect(component.showTestDetails()).toBe(true);
|
||||
|
||||
appSettingsService.testOidcConnection.mockReturnValueOnce(
|
||||
throwError(() => new HttpErrorResponse({status: 500}))
|
||||
@@ -508,7 +508,7 @@ describe('AuthenticationSettingsComponent', () => {
|
||||
|
||||
component.testConnection();
|
||||
|
||||
expect(component.isTestingConnection).toBe(false);
|
||||
expect(component.isTestingConnection()).toBe(false);
|
||||
expect(messageService.add).toHaveBeenCalledWith(expect.objectContaining({
|
||||
severity: 'error',
|
||||
detail: 'settingsAuth.testConnection.error',
|
||||
|
||||
+14
-10
@@ -1,5 +1,5 @@
|
||||
import {HttpErrorResponse} from '@angular/common/http';
|
||||
import {Component, effect, inject, signal} from '@angular/core';
|
||||
import {Component, effect, inject, signal, WritableSignal} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputText} from '@openng/optimus-ui/inputtext';
|
||||
import {Button} from '@openng/optimus-ui/button';
|
||||
@@ -99,9 +99,9 @@ export class AuthenticationSettingsComponent {
|
||||
];
|
||||
|
||||
// Test connection
|
||||
isTestingConnection = false;
|
||||
testConnectionResult: OidcTestResult | null = null;
|
||||
showTestDetails = false;
|
||||
readonly isTestingConnection = signal(false);
|
||||
readonly testConnectionResult: WritableSignal<OidcTestResult | null> = signal(null);
|
||||
readonly showTestDetails = signal(false);
|
||||
|
||||
// Group mapping
|
||||
readonly groupSyncMode = signal('DISABLED');
|
||||
@@ -450,14 +450,18 @@ export class AuthenticationSettingsComponent {
|
||||
return this.allLibraries.find(l => l.id === id)?.name ?? `#${id}`;
|
||||
}
|
||||
|
||||
toggleTestDetails(): void {
|
||||
this.showTestDetails.update(s => !s)
|
||||
}
|
||||
|
||||
testConnection(): void {
|
||||
this.isTestingConnection = true;
|
||||
this.testConnectionResult = null;
|
||||
this.isTestingConnection.set(true);
|
||||
this.testConnectionResult.set(null);
|
||||
this.appSettingsService.testOidcConnection(this.oidcProvider).subscribe({
|
||||
next: (result) => {
|
||||
this.testConnectionResult = result;
|
||||
this.showTestDetails = true;
|
||||
this.isTestingConnection = false;
|
||||
this.testConnectionResult.set(result);
|
||||
this.showTestDetails.set(true);
|
||||
this.isTestingConnection.set(false);
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({
|
||||
@@ -465,7 +469,7 @@ export class AuthenticationSettingsComponent {
|
||||
summary: this.t.translate('common.error'),
|
||||
detail: this.t.translate('settingsAuth.testConnection.error')
|
||||
});
|
||||
this.isTestingConnection = false;
|
||||
this.isTestingConnection.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user