Skip to content

Commit

Permalink
use the correct fallback values for widget signals determination (#302)
Browse files Browse the repository at this point in the history
* use the correct fallback values for widget signals determination

- closes #237

* rm key again
  • Loading branch information
foxriver76 authored Jan 11, 2024
1 parent cca536e commit 9e45204
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ E.g., if it was used in a menu and the menu is red, the circle would be red.
### **WORK IN PROGRESS**
-->
## Changelog
### **WORK IN PROGRESS**
* (foxriver76) use the correct fallback values for widget signals determination

### 2.9.15 (2024-01-09)
* (foxriver76) fixed issue with BulkEditor

Expand Down
63 changes: 32 additions & 31 deletions src/src/Vis/visRxWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -652,75 +652,76 @@ class VisRxWidget<TRxData extends Record<string, any>> extends VisBaseWidget {
});
}

isSignalVisible(index: number, val?: any) {
isSignalVisible(index: number) {
const oid = this.state.rxData[`signals-oid-${index}`];

if (oid) {
if (val === undefined || val === null) {
val = this.state.values[`${oid}.val`];
}
/** The state value */
let val = this.state.values[`${oid}.val`];

const condition = this.state.rxData[`signals-cond-${index}`];
let value = this.state.rxData[`signals-val-${index}`];
const condition = this.state.rxData[`signals-cond-${index}`] ?? '==';
/** The value the state value needs to match */
let targetValue = this.state.rxData[`signals-val-${index}`] ?? 'true';

if (val === undefined || val === null) {
return condition === 'not exist';
}

if (!condition || value === undefined || value === null) {
if (!condition || targetValue === undefined || targetValue === null) {
return condition === 'not exist';
}

if (val === 'null' && condition !== 'exist' && condition !== 'not exist') {
return false;
}

const t = typeof val;
if (t === 'boolean' || val === 'false' || val === 'true') {
value = value === 'true' || value === true || value === 1 || value === '1';
} else if (t === 'number') {
value = parseFloat(value);
} else if (t === 'object') {
const valueType = typeof val;

if (valueType === 'boolean' || val === 'false' || val === 'true') {
targetValue = targetValue === 'true' || targetValue === true || targetValue === 1 || targetValue === '1';
} else if (valueType === 'number') {
targetValue = parseFloat(targetValue);
} else if (valueType === 'object') {
val = JSON.stringify(val);
}

switch (condition) {
case '==':
value = value.toString();
targetValue = targetValue.toString();
val = val.toString();
if (val === '1') val = 'true';
if (value === '1') value = 'true';
if (targetValue === '1') targetValue = 'true';
if (val === '0') val = 'false';
if (value === '0') value = 'false';
return value === val;
if (targetValue === '0') targetValue = 'false';
return targetValue === val;
case '!=':
value = value.toString();
targetValue = targetValue.toString();
val = val.toString();
if (val === '1') val = 'true';
if (value === '1') value = 'true';
if (targetValue === '1') targetValue = 'true';
if (val === '0') val = 'false';
if (value === '0') value = 'false';
return value !== val;
if (targetValue === '0') targetValue = 'false';
return targetValue !== val;
case '>=':
return val >= value;
return val >= targetValue;
case '<=':
return val <= value;
return val <= targetValue;
case '>':
return val > value;
return val > targetValue;
case '<':
return val < value;
return val < targetValue;
case 'consist':
value = value.toString();
targetValue = targetValue.toString();
val = val.toString();
return val.toString().includes(value);
return val.toString().includes(targetValue);
case 'not consist':
value = value.toString();
targetValue = targetValue.toString();
val = val.toString();
return !val.toString().includes(value);
return !val.toString().includes(targetValue);
case 'exist':
return value !== 'null';
return targetValue !== 'null';
case 'not exist':
return value === 'null';
return targetValue === 'null';
default:
console.log(`Unknown signals condition for ${this.props.id}: ${condition}`);
return false;
Expand Down

0 comments on commit 9e45204

Please sign in to comment.