From 817b83c7bdb0d007494e94a27e40ebfb82d72705 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Tue, 14 Jan 2025 15:52:35 +0200 Subject: [PATCH 1/5] Added domain update request chaining --- .../domains/domain-table-config.resolver.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts index 8e1014a1da..95a260f9ba 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts @@ -32,7 +32,8 @@ import { DomainComponent } from '@home/pages/admin/oauth2/domains/domain.compone import { isEqual } from '@core/utils'; import { DomainTableHeaderComponent } from '@home/pages/admin/oauth2/domains/domain-table-header.component'; import { Direction } from '@app/shared/models/page/sort-order'; -import { map, mergeMap, Observable, of } from 'rxjs'; +import { map, of } from 'rxjs'; +import { switchMap } from 'rxjs/operators'; @Injectable() export class DomainTableConfigResolver { @@ -84,16 +85,16 @@ export class DomainTableConfigResolver { this.config.loadEntity = id => this.domainService.getDomainInfoById(id.id); this.config.saveEntity = (domain, originalDomain) => { const clientsIds = domain.oauth2ClientInfos as Array || []; - let clientsTask: Observable; - if (domain.id && !isEqual(domain.oauth2ClientInfos?.sort(), - originalDomain.oauth2ClientInfos?.map(info => info.id ? info.id.id : info).sort())) { - clientsTask = this.domainService.updateOauth2Clients(domain.id.id, clientsIds); - } else { - clientsTask = of(null); - } delete domain.oauth2ClientInfos; - return clientsTask.pipe( - mergeMap(() => this.domainService.saveDomain(domain, domain.id ? [] : clientsIds)), + + return this.domainService.saveDomain(domain, domain.id ? [] : clientsIds).pipe( + switchMap(savedDomain => { + const shouldUpdateClients = domain.id && !isEqual(domain.oauth2ClientInfos?.sort(), + originalDomain.oauth2ClientInfos?.map(info => info.id ? info.id.id : info).sort()); + return shouldUpdateClients + ? this.domainService.updateOauth2Clients(domain.id.id, clientsIds).pipe(map(() => savedDomain)) + : of(savedDomain); + }), map(savedDomain => { (savedDomain as DomainInfo).oauth2ClientInfos = clientsIds; return savedDomain; From a5fa699c458e744e370c39642364298b64595f67 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Tue, 14 Jan 2025 15:57:49 +0200 Subject: [PATCH 2/5] Save domain refactoring --- ui-ngx/src/app/core/http/domain.service.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/core/http/domain.service.ts b/ui-ngx/src/app/core/http/domain.service.ts index bb6cd4a16b..f20e30d1b1 100644 --- a/ui-ngx/src/app/core/http/domain.service.ts +++ b/ui-ngx/src/app/core/http/domain.service.ts @@ -33,8 +33,11 @@ export class DomainService { } public saveDomain(domain: Domain, oauth2ClientIds: Array, config?: RequestConfig): Observable { - return this.http.post(`/api/domain?oauth2ClientIds=${oauth2ClientIds.join(',')}`, - domain, defaultHttpOptionsFromConfig(config)); + let url = '/api/domain'; + if (oauth2ClientIds?.length) { + url += `?oauth2ClientIds=${oauth2ClientIds.join(',')}`; + } + return this.http.post(url, domain, defaultHttpOptionsFromConfig(config)); } public updateOauth2Clients(id: string, oauth2ClientIds: Array, config?: RequestConfig): Observable { From f8dd68226c01fa5f5db6ead7806ae4d49bcf9d51 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 16 Jan 2025 12:01:07 +0200 Subject: [PATCH 3/5] resolved comments --- ui-ngx/src/app/core/http/domain.service.ts | 2 +- .../pages/admin/oauth2/domains/domain-table-config.resolver.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/core/http/domain.service.ts b/ui-ngx/src/app/core/http/domain.service.ts index f20e30d1b1..fe05305c6f 100644 --- a/ui-ngx/src/app/core/http/domain.service.ts +++ b/ui-ngx/src/app/core/http/domain.service.ts @@ -32,7 +32,7 @@ export class DomainService { ) { } - public saveDomain(domain: Domain, oauth2ClientIds: Array, config?: RequestConfig): Observable { + public saveDomain(domain: Domain, oauth2ClientIds?: Array, config?: RequestConfig): Observable { let url = '/api/domain'; if (oauth2ClientIds?.length) { url += `?oauth2ClientIds=${oauth2ClientIds.join(',')}`; diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts index 95a260f9ba..4f0603545f 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts @@ -85,11 +85,12 @@ export class DomainTableConfigResolver { this.config.loadEntity = id => this.domainService.getDomainInfoById(id.id); this.config.saveEntity = (domain, originalDomain) => { const clientsIds = domain.oauth2ClientInfos as Array || []; + const newDomainClients = domain.oauth2ClientInfos; delete domain.oauth2ClientInfos; return this.domainService.saveDomain(domain, domain.id ? [] : clientsIds).pipe( switchMap(savedDomain => { - const shouldUpdateClients = domain.id && !isEqual(domain.oauth2ClientInfos?.sort(), + const shouldUpdateClients = domain.id && !isEqual(newDomainClients?.sort(), originalDomain.oauth2ClientInfos?.map(info => info.id ? info.id.id : info).sort()); return shouldUpdateClients ? this.domainService.updateOauth2Clients(domain.id.id, clientsIds).pipe(map(() => savedDomain)) From 7edba5edb6ff29fde453660627362cb84d2861d3 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 16 Jan 2025 16:26:53 +0200 Subject: [PATCH 4/5] refactoring --- .../domains/domain-table-config.resolver.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts index 4f0603545f..64861285a8 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts @@ -85,17 +85,15 @@ export class DomainTableConfigResolver { this.config.loadEntity = id => this.domainService.getDomainInfoById(id.id); this.config.saveEntity = (domain, originalDomain) => { const clientsIds = domain.oauth2ClientInfos as Array || []; - const newDomainClients = domain.oauth2ClientInfos; + const shouldUpdateClients = domain.id && !isEqual(domain.oauth2ClientInfos?.sort(), + originalDomain.oauth2ClientInfos?.map(info => info.id ? info.id.id : info).sort()); delete domain.oauth2ClientInfos; - return this.domainService.saveDomain(domain, domain.id ? [] : clientsIds).pipe( - switchMap(savedDomain => { - const shouldUpdateClients = domain.id && !isEqual(newDomainClients?.sort(), - originalDomain.oauth2ClientInfos?.map(info => info.id ? info.id.id : info).sort()); - return shouldUpdateClients - ? this.domainService.updateOauth2Clients(domain.id.id, clientsIds).pipe(map(() => savedDomain)) - : of(savedDomain); - }), + return this.domainService.saveDomain(domain, domain.id ? null : clientsIds).pipe( + switchMap(savedDomain => shouldUpdateClients + ? this.domainService.updateOauth2Clients(domain.id.id, clientsIds).pipe(map(() => savedDomain)) + : of(savedDomain) + ), map(savedDomain => { (savedDomain as DomainInfo).oauth2ClientInfos = clientsIds; return savedDomain; @@ -119,7 +117,7 @@ export class DomainTableConfigResolver { oauth2Enabled: !domain.oauth2Enabled }; - this.domainService.saveDomain(modifiedDomain, domain.oauth2ClientInfos.map(clientInfo => clientInfo.id.id), + this.domainService.saveDomain(modifiedDomain, null, {ignoreLoading: true}) .subscribe((result) => { domain.oauth2Enabled = result.oauth2Enabled; @@ -137,7 +135,7 @@ export class DomainTableConfigResolver { propagateToEdge: !domain.propagateToEdge }; - this.domainService.saveDomain(modifiedDomain, domain.oauth2ClientInfos.map(clientInfo => clientInfo.id.id), + this.domainService.saveDomain(modifiedDomain, null, {ignoreLoading: true}) .subscribe((result) => { domain.propagateToEdge = result.propagateToEdge; From 6cd2fdfe33fbbd09b92f75dc4f22a1b709393f46 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Thu, 16 Jan 2025 16:54:52 +0200 Subject: [PATCH 5/5] Removed oauth2ClientInfos for toggles --- .../oauth2/domains/domain-table-config.resolver.ts | 14 ++++---------- ui-ngx/src/app/shared/models/oauth2.models.ts | 6 +----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts index 64861285a8..8048fec885 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/oauth2/domains/domain-table-config.resolver.ts @@ -112,12 +112,9 @@ export class DomainTableConfigResolver { $event.stopPropagation(); } - const modifiedDomain: DomainInfo = { - ...domain, - oauth2Enabled: !domain.oauth2Enabled - }; + const { oauth2ClientInfos, oauth2Enabled, ...updatedDomain } = domain; - this.domainService.saveDomain(modifiedDomain, null, + this.domainService.saveDomain({ ...updatedDomain, oauth2Enabled: !oauth2Enabled }, null, {ignoreLoading: true}) .subscribe((result) => { domain.oauth2Enabled = result.oauth2Enabled; @@ -130,12 +127,9 @@ export class DomainTableConfigResolver { $event.stopPropagation(); } - const modifiedDomain: DomainInfo = { - ...domain, - propagateToEdge: !domain.propagateToEdge - }; + const { oauth2ClientInfos, propagateToEdge, ...updatedDomain } = domain; - this.domainService.saveDomain(modifiedDomain, null, + this.domainService.saveDomain({ ...updatedDomain, propagateToEdge: !propagateToEdge }, null, {ignoreLoading: true}) .subscribe((result) => { domain.propagateToEdge = result.propagateToEdge; diff --git a/ui-ngx/src/app/shared/models/oauth2.models.ts b/ui-ngx/src/app/shared/models/oauth2.models.ts index abc0ae1464..19a95a9788 100644 --- a/ui-ngx/src/app/shared/models/oauth2.models.ts +++ b/ui-ngx/src/app/shared/models/oauth2.models.ts @@ -80,11 +80,7 @@ export interface Domain extends BaseData, HasTenantId { propagateToEdge: boolean; } -export interface HasOauth2Clients { - oauth2ClientInfos?: Array | Array; -} - -export interface DomainInfo extends Domain, HasOauth2Clients { +export interface DomainInfo extends Domain { oauth2ClientInfos?: Array | Array; }