diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts index 8f967b68ce..1125406484 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts @@ -43,8 +43,9 @@ import { CalculatedFieldDebugDialogData, CalculatedFieldDialogData, CalculatedFieldRollingValueArgumentAutocomplete, - CalculatedFieldSingleValueArgumentAutocomplete, CalculatedFieldTestScriptDialogData, + CalculatedFieldAttributeValueArgumentAutocomplete, + CalculatedFieldLatestTelemetryArgumentAutocomplete, } from '@shared/models/calculated-field.models'; import { CalculatedFieldDebugDialogComponent, @@ -302,9 +303,17 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig): TbEditorCompleter { return new TbEditorCompleter(Object.keys(argumentsObj).reduce((acc, key) => { - acc[key] = argumentsObj[key].refEntityKey.type === ArgumentType.Rolling - ? CalculatedFieldRollingValueArgumentAutocomplete - : CalculatedFieldSingleValueArgumentAutocomplete; + switch (argumentsObj[key].refEntityKey.type) { + case ArgumentType.Attribute: + acc[key] = CalculatedFieldAttributeValueArgumentAutocomplete; + break; + case ArgumentType.LatestTelemetry: + acc[key] = CalculatedFieldLatestTelemetryArgumentAutocomplete; + break; + case ArgumentType.Rolling: + acc[key] = CalculatedFieldRollingValueArgumentAutocomplete; + break; + } return acc; }, {})) } diff --git a/ui-ngx/src/app/shared/components/js-func.component.ts b/ui-ngx/src/app/shared/components/js-func.component.ts index 57c15a5484..3f5417c2d0 100644 --- a/ui-ngx/src/app/shared/components/js-func.component.ts +++ b/ui-ngx/src/app/shared/components/js-func.component.ts @@ -184,6 +184,9 @@ export class JsFuncComponent implements OnInit, OnChanges, OnDestroy, ControlVal this.updateFunctionArgsString(); this.updateFunctionLabel(); } + if (changes.editorCompleter) { + this.updateCompleters(); + } } ngOnInit(): void { diff --git a/ui-ngx/src/app/shared/models/calculated-field.models.ts b/ui-ngx/src/app/shared/models/calculated-field.models.ts index e9ae6f08b8..4abc2e8a9e 100644 --- a/ui-ngx/src/app/shared/models/calculated-field.models.ts +++ b/ui-ngx/src/app/shared/models/calculated-field.models.ts @@ -213,10 +213,28 @@ export type CalculatedFieldArgumentEventValue = CalculatedF export type CalculatedFieldEventArguments = Record>; -export const CalculatedFieldSingleValueArgumentAutocomplete = { +export const CalculatedFieldLatestTelemetryArgumentAutocomplete = { meta: 'object', type: '{ ts: number; value: any; }', - description: 'Calculated field single value argument.', + description: 'Calculated field latest telemetry value argument.', + children: { + ts: { + meta: 'number', + type: 'number', + description: 'Time stamp', + }, + value: { + meta: 'any', + type: 'any', + description: 'Value', + } + }, +}; + +export const CalculatedFieldAttributeValueArgumentAutocomplete = { + meta: 'object', + type: '{ ts: number; value: any; }', + description: 'Calculated field attribute value argument.', children: { ts: { meta: 'number',