Resolved PR comments

This commit is contained in:
mpetrov 2025-02-04 17:57:05 +02:00
parent 555acff6b4
commit d185b78427
5 changed files with 44 additions and 37 deletions

View File

@ -87,19 +87,24 @@
(click)="manageArgument($event, button, $index)"
[matTooltip]="'action.edit' | translate"
matTooltipPosition="above">
<mat-icon class="opacity-55">edit</mat-icon>
@if (argumentsFormArray.dirty
&& group.get('refEntityKey').get('type').value === ArgumentType.Rolling
&& calculatedFieldType() === CalculatedFieldType.SIMPLE) {
<tb-error class="edit-hint absolute right-0 top-0" [error]="'*'"/>
}
<mat-icon
[matBadgeHidden]="!(argumentsFormArray.dirty
&& group.get('refEntityKey').get('type').value === ArgumentType.Rolling
&& calculatedFieldType() === CalculatedFieldType.SIMPLE)"
matBadgeColor="warn"
matBadgeSize="small"
matBadge="!"
class="field-action"
>
edit
</mat-icon>
</button>
<button type="button"
mat-icon-button
(click)="onDelete($index)"
[matTooltip]="'action.delete' | translate"
matTooltipPosition="above">
<mat-icon class="opacity-55">delete</mat-icon>
<mat-icon class="field-action">delete</mat-icon>
</button>
</div>
</div>

View File

@ -19,9 +19,10 @@
font-size: 14px;
}
}
.edit-hint {
.mat-mdc-form-field-error {
font-size: 16px;
}
}
:host {
.field-action {
color: rgba(0, 0, 0, 0.54);
}
}

View File

@ -36,7 +36,6 @@ import { EntityType } from '@shared/models/entity-type.models';
import { map, startWith } from 'rxjs/operators';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ScriptLanguage } from '@shared/models/rule-node.models';
import { merge } from 'rxjs';
@Component({
selector: 'tb-calculated-field-dialog',
@ -60,10 +59,10 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
}),
});
functionArgs$ = merge(this.configFormGroup.get('arguments').valueChanges, this.fieldFormGroup.get('type').valueChanges)
functionArgs$ = this.configFormGroup.get('arguments').valueChanges
.pipe(
startWith(null),
map(() => Object.keys(this.configFormGroup.get('arguments').value ?? this.data.value.configuration.arguments))
startWith(this.data.value?.configuration?.arguments ?? {}),
map(argumentsObj => Object.keys(argumentsObj))
);
readonly OutputTypeTranslations = OutputTypeTranslations;

View File

@ -25,7 +25,8 @@ import {
ArgumentType,
ArgumentTypeTranslations,
CalculatedFieldArgumentValue,
CalculatedFieldType
CalculatedFieldType,
getCalculatedFieldCurrentEntityFilter
} from '@shared/models/calculated-field.models';
import { debounceTime, distinctUntilChanged, filter } from 'rxjs/operators';
import { EntityType } from '@shared/models/entity-type.models';
@ -110,7 +111,7 @@ export class CalculatedFieldArgumentPanelComponent implements OnInit {
ngOnInit(): void {
this.argumentFormGroup.patchValue(this.argument, {emitEvent: false});
this.currentEntityFilter = this.getCurrentEntityFilter();
this.currentEntityFilter = getCalculatedFieldCurrentEntityFilter(this.entityName, this.entityId);
this.updateEntityFilter(this.argument.refEntityId?.entityType, true);
this.toggleByEntityKeyType(this.argument.refEntityKey?.type);
this.setInitialEntityKeyType();
@ -169,26 +170,6 @@ export class CalculatedFieldArgumentPanelComponent implements OnInit {
this.cd.markForCheck();
}
private getCurrentEntityFilter(): EntityFilter {
switch (this.entityId.entityType) {
case EntityType.ASSET_PROFILE:
return {
assetTypes: [this.entityName],
type: AliasFilterType.assetType
};
case EntityType.DEVICE_PROFILE:
return {
deviceTypes: [this.entityName],
type: AliasFilterType.deviceType
};
default:
return {
type: AliasFilterType.singleEntity,
singleEntity: this.entityId,
};
}
}
private observeEntityFilterChanges(): void {
merge(
this.refEntityIdFormGroup.get('entityType').valueChanges,

View File

@ -20,6 +20,7 @@ import { CalculatedFieldId } from '@shared/models/id/calculated-field-id';
import { EntityId } from '@shared/models/id/entity-id';
import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
import { EntityType } from '@shared/models/entity-type.models';
import { AliasFilterType } from '@shared/models/alias.models';
export interface CalculatedField extends Omit<BaseData<CalculatedFieldId>, 'label'>, HasVersion, HasTenantId {
debugSettings?: EntityDebugSettings;
@ -133,3 +134,23 @@ export const ArgumentEntityTypeParamsMap =new Map<ArgumentEntityType, ArgumentEn
[ArgumentEntityType.Asset, { title: 'calculated-fields.asset-name', entityType: EntityType.ASSET }],
[ArgumentEntityType.Customer, { title: 'calculated-fields.customer-name', entityType: EntityType.CUSTOMER }],
])
export const getCalculatedFieldCurrentEntityFilter = (entityName: string, entityId: EntityId) => {
switch (entityId.entityType) {
case EntityType.ASSET_PROFILE:
return {
assetTypes: [entityName],
type: AliasFilterType.assetType
};
case EntityType.DEVICE_PROFILE:
return {
deviceTypes: [entityName],
type: AliasFilterType.deviceType
};
default:
return {
type: AliasFilterType.singleEntity,
singleEntity: entityId,
};
}
}