From 8895d9a82e08f9feb8a8eab41416748b1d2c4009 Mon Sep 17 00:00:00 2001 From: mpetrov Date: Fri, 14 Jun 2024 17:44:29 +0300 Subject: [PATCH] [PROD-3656] [FIX] refactoring --- ...ice-rpc-connector-templates.component.html | 2 +- .../shared/pipe/key-value-not-empty.pipe.ts | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector-templates.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector-templates.component.html index 035a5c6317..dc9da182ef 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector-templates.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector-templates.component.html @@ -32,7 +32,7 @@ diff --git a/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts b/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts index 320afd1dc4..16c5ad29b0 100644 --- a/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts +++ b/ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts @@ -14,15 +14,31 @@ /// limitations under the License. /// -import { Pipe, PipeTransform } from '@angular/core'; +import { KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Pipe, PipeTransform } from '@angular/core'; +import { KeyValue, KeyValuePipe } from "@angular/common"; @Pipe({ - name: 'keyValueIsNotEmpty' + name: 'keyValueIsNotEmpty', }) -export class KeyValueIsNotEmptyPipe implements PipeTransform { - transform(obj: Record): Record { - return Object.fromEntries( - Object.entries(obj).filter(([_, value]) => value !== null && value !== undefined) - ); +export class KeyValueIsNotEmptyPipe extends KeyValuePipe implements PipeTransform { + private difference!: KeyValueDiffer; + + constructor(private readonly keyValueDiffers: KeyValueDiffers) { + super(keyValueDiffers); + } + + transform( + input: Record, + compareFn?: (a: KeyValue, b: KeyValue) => number + ): KeyValue[] & null { + super.transform(input, compareFn); + this.difference ??= this.keyValueDiffers.find(input).create(); + const differChanges: KeyValueChanges | null = this.difference.diff(input as any); + if (differChanges) { + console.log(differChanges) + const filteredEntries = [...Object.entries(input)] + .filter(([_, value]) => value !== null && value !== undefined); + return super.transform(new Map(filteredEntries), compareFn) as KeyValue[] & null; + } } }