Browse Source

[PROD-3656] [FIX] refactoring

pull/11012/head
mpetrov 2 years ago
parent
commit
8895d9a82e
  1. 2
      ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector-templates.component.html
  2. 30
      ui-ngx/src/app/shared/pipe/key-value-not-empty.pipe.ts

2
ui-ngx/src/app/modules/home/components/widget/lib/gateway/gateway-service-rpc-connector-templates.component.html

@ -32,7 +32,7 @@
</mat-expansion-panel-header>
<ng-container
*ngFor="let config of template.config | keyValueIsNotEmpty | keyvalue : originalOrder"
*ngFor="let config of template.config | keyValueIsNotEmpty : originalOrder"
[ngTemplateOutlet]="RPCTemplateRef"
[ngTemplateOutletContext]="{ $implicit: config, innerValue: false }">
</ng-container>

30
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<string, unknown>): Record<string, unknown> {
return Object.fromEntries(
Object.entries(obj).filter(([_, value]) => value !== null && value !== undefined)
);
export class KeyValueIsNotEmptyPipe extends KeyValuePipe implements PipeTransform {
private difference!: KeyValueDiffer<any, any>;
constructor(private readonly keyValueDiffers: KeyValueDiffers) {
super(keyValueDiffers);
}
transform<ValueType>(
input: Record<string, ValueType>,
compareFn?: (a: KeyValue<string, ValueType>, b: KeyValue<string, ValueType>) => number
): KeyValue<string, ValueType>[] & null {
super.transform(input, compareFn);
this.difference ??= this.keyValueDiffers.find(input).create();
const differChanges: KeyValueChanges<string, ValueType> | 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<string, ValueType>(filteredEntries), compareFn) as KeyValue<string, ValueType>[] & null;
}
}
}

Loading…
Cancel
Save