UI: Add help to function 'Get Dashboard State with Parameters'

This commit is contained in:
Vladyslav_Prykhodko 2025-01-29 19:08:11 +02:00
parent 8b7bf4a633
commit c6bb337d23
3 changed files with 49 additions and 1 deletions

View File

@ -145,7 +145,7 @@
[globalVariables]="functionScopeVariables" [globalVariables]="functionScopeVariables"
[functionArgs]="['data']" [functionArgs]="['data']"
functionTitle="{{ 'widgets.value-action.parse-value-function' | translate }}" functionTitle="{{ 'widgets.value-action.parse-value-function' | translate }}"
helpId="widget/lib/rpc/parse_value_fn"> [helpId]="getParseValueFunctionHelpId()">
</tb-js-func> </tb-js-func>
<div *ngIf="valueType === ValueType.BOOLEAN" class="tb-form-row align-start no-gap column-xs"> <div *ngIf="valueType === ValueType.BOOLEAN" class="tb-form-row align-start no-gap column-xs">
<div class="fixed-title-width fixed-title-height">{{ 'widgets.value-action.state-when-result-is' | translate:{state: stateLabel} }}</div> <div class="fixed-title-width fixed-title-height">{{ 'widgets.value-action.state-when-result-is' | translate:{state: stateLabel} }}</div>

View File

@ -167,6 +167,14 @@ export class GetValueActionSettingsPanelComponent extends PageComponent implemen
this.getValueSettingsApplied.emit(getValueSettings); this.getValueSettingsApplied.emit(getValueSettings);
} }
getParseValueFunctionHelpId(): string {
const action: GetValueAction = this.getValueSettingsFormGroup.get('action').value;
if (action === GetValueAction.GET_DASHBOARD_STATE_WITH_PARAMS) {
return 'widget/config/parse_value_get_dashboard_state_with_params_fn';
}
return 'widget/lib/rpc/parse_value_fn';
}
private updateValidators() { private updateValidators() {
const action: GetValueAction = this.getValueSettingsFormGroup.get('action').value; const action: GetValueAction = this.getValueSettingsFormGroup.get('action').value;
let dataToValueType: DataToValueType = this.getValueSettingsFormGroup.get('dataToValue').get('type').value; let dataToValueType: DataToValueType = this.getValueSettingsFormGroup.get('dataToValue').get('type').value;

View File

@ -0,0 +1,40 @@
#### Parse value function
<div class="divider"></div>
<br/>
*function (data): boolean*
A JavaScript function that converts the current dashboard state and parameters into a boolean value.
**Parameters:**
<ul>
<li><b>data:</b> <a href="https://github.com/thingsboard/thingsboard/blob/master/ui-ngx/src/app/core/api/widget-api.models.ts#L150" target="_blank">StateObject</a> - the current dashboard state object.
</li>
</ul>
**Returns:**
`true` if the widget should be in an activated state, `false` otherwise.
<div class="divider"></div>
##### Examples
* Check if the current dashboard state ID is "default":
```javascript
return data.id === 'default' ? true : false;
{:copy-code}
```
* Check if the current dashboard state parameters are empty:
```javascript
return Object.keys(data.params).length ? true : false;
{:copy-code}
```
<br>
<br>