Skip to content

Commit

Permalink
BasicBulb treat empty string in same logic as undefined previously (#246
Browse files Browse the repository at this point in the history
)

- closes #243
  • Loading branch information
foxriver76 authored Dec 11, 2023
1 parent db9d953 commit 9133a3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,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) fixed issues with Bulb widget if min/max was once filled

### 2.9.5 (2023-12-10)
* (foxriver76) open new views at the beginning
* (foxriver76) fixed crash case if signals are used
Expand Down
32 changes: 16 additions & 16 deletions src/src/Vis/Widgets/Basic/BasicBulb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ export default class BasicBulb extends VisRxWidget<RxData> {
urlFalse, oidFalse,
} = this.state.rxData;

let finalMin: string | boolean = min;
let finalMax: string | boolean = max;
let oidTrueValueFinal: string | boolean | number = oidTrueValue;
let oidFalseValueFinal: string | boolean | number = oidFalseValue;
let finalMin: string | boolean = min ?? '';
let finalMax: string | boolean = max ?? '';
let oidTrueValueFinal: string | boolean | number = oidTrueValue ?? '';
let oidFalseValueFinal: string | boolean | number = oidFalseValue ?? '';

if (oidTrue || urlTrue) {
if (!oidFalse && oidTrue) oidFalse = oidTrue;
if (!urlFalse && urlTrue) urlFalse = urlTrue;

if (finalMax !== undefined) {
if (finalMax !== '') {
if (finalMax === 'true') finalMax = true;
if (finalMax === 'false') finalMax = false;
if (val === 'true') val = true;
Expand All @@ -118,12 +118,12 @@ export default class BasicBulb extends VisRxWidget<RxData> {
}
val = !val; // invert

if (finalMin === undefined || finalMin === 'false' || finalMin === null) finalMin = false;
if (finalMax === undefined || finalMax === 'true' || finalMax === null) finalMax = true;
if (finalMin === '' || finalMin === 'false' || finalMin === null) finalMin = false;
if (finalMax === '' || finalMax === 'true' || finalMax === null) finalMax = true;

if (oidTrue) {
if (val) {
if (oidTrueValueFinal === undefined || oidTrueValueFinal === null) oidTrueValueFinal = finalMax;
if (oidTrueValueFinal === '') oidTrueValueFinal = finalMax;
if (oidTrueValueFinal === 'false') oidTrueValueFinal = false;
if (oidTrueValueFinal === 'true') oidTrueValueFinal = true;
if (typeof oidTrueValueFinal === 'string') {
Expand All @@ -132,7 +132,7 @@ export default class BasicBulb extends VisRxWidget<RxData> {
}
this.props.context.setValue(oidTrue, oidTrueValueFinal);
} else {
if (oidFalseValueFinal === undefined || oidFalseValueFinal === null) oidFalseValueFinal = finalMin;
if (oidFalseValueFinal === '') oidFalseValueFinal = finalMin;
if (oidFalseValueFinal === 'false') oidFalseValueFinal = false;
if (oidFalseValueFinal === 'true') oidFalseValueFinal = true;
if (typeof oidFalseValueFinal === 'string') {
Expand All @@ -150,16 +150,16 @@ export default class BasicBulb extends VisRxWidget<RxData> {
this.props.socket.getRawSocket().emit('httpGet', urlFalse);
}
}
} else if ((finalMin === undefined && (val === null || val === '' || val === undefined || val === false || val === 'false')) ||
(finalMin !== undefined && finalMin === val)) {
this.props.context.setValue(oid, finalMax !== undefined ? finalMax : true);
} else if ((finalMin === '' && (val === null || val === '' || val === undefined || val === false || val === 'false')) ||
(finalMin !== '' && finalMin === val)) {
this.props.context.setValue(oid, finalMax !== '' ? finalMax : true);
} else
if ((finalMax === undefined && (val === true || val === 'true')) ||
(finalMax !== undefined && val === finalMax)) {
this.props.context.setValue(oid, finalMin !== undefined ? finalMin : false);
if ((finalMax === '' && (val === true || val === 'true')) ||
(finalMax !== '' && val === finalMax)) {
this.props.context.setValue(oid, finalMin !== '' ? finalMin : false);
} else {
val = parseFloat(val);
if (finalMin !== undefined && finalMax !== undefined) {
if (finalMin !== '' && finalMax !== '') {
if (val >= (parseFloat(finalMax) - parseFloat(finalMin)) / 2) {
val = finalMin;
} else {
Expand Down

0 comments on commit 9133a3e

Please sign in to comment.