Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use the correct fallback values for widget signals determination #302

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading