Skip to content

Commit 2b8be40

Browse files
authored
Merge pull request #126 from ChannelFinder/show-disconnected
Add option to show disconnected message for non-reachable PVs
2 parents fcbeef0 + 3ba60d0 commit 2b8be40

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ REACT_APP_PVWS_ALLOW_WAVEFORMS=false
121121
# if your recceiver instance is not working but the PVs themselves are alive and accessible.
122122
REACT_APP_PVWS_IGNORE_CF_PVSTATUS=false
123123

124+
# By default, PV Info shows "Disconnected" for PVs that are not connected to their IOC
125+
# Switch this to false to revert to the old behavior where instead the box is left blank
126+
# Somewhat goes in tandem with IGNORE_CF_PVSTATUS variable
127+
REACT_APP_SHOW_DISCONNECTED=true
128+
124129
######################################################################################
125130
# Archiver Web Viewer
126131
######################################################################################

src/components/home/queryresults/QueryResults.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ function QueryResults(props) {
9090
[firstRow, lastRow] = [parseInt(start) - 1, parseInt(end) - 1];
9191
}
9292
for (let i = firstRow; i <= lastRow; ++i) {
93-
updateCurrentChecked(i, event.target.checked);
93+
// only check mark active PVs, unless we are ignoring CF PV status
94+
// matters now that we show "Disconnected" for PVs that are not connected to their IOC
95+
if (import.meta.env.REACT_APP_PVWS_IGNORE_CF_PVSTATUS === "true" || pvs[i].pvStatus === "Active") {
96+
updateCurrentChecked(i, event.target.checked);
97+
}
9498
}
9599
return
96100
}, [updateCurrentChecked])

src/components/home/queryresults/value/Value.jsx

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ const propTypes = {
1313
}
1414

1515
function Value(props) {
16-
const [pvValue, setPVValue] = useState("");
16+
const [pvValue, setPVValue] = useState(null);
1717
const [pvSeverity, setPVSeverity] = useState("");
1818
const [pvUnit, setPVUnit] = useState("");
19+
// debounce the value display to avoid flashing "Disconnected" since web socket always sends message without value on connect
20+
const [show, setShow] = useState(false);
21+
const [startTimer, setStartTimer] = useState(false);
1922

2023
// https://github.com/robtaussig/react-use-websocket/issues/40#issuecomment-616676102
2124
// pattern for sharing web socket among components
@@ -24,19 +27,38 @@ function Value(props) {
2427
filter: message => JSON.parse(message.data).pv === props.pvName,
2528
});
2629

30+
31+
useEffect(() => {
32+
// wait to start timer until we get first message for this PV
33+
if (!startTimer) {
34+
return;
35+
}
36+
// the debouncing is only useful if we are showing "Disconnected" for non-reachable PVs
37+
if (import.meta.env.REACT_APP_SHOW_DISCONNECTED !== "true" || show) {
38+
return;
39+
}
40+
const timeout = setTimeout(() => {
41+
setShow(true)
42+
}, 500)
43+
44+
return () => clearTimeout(timeout);
45+
}, [show, startTimer])
46+
47+
2748
// parse web socket message. filter on useWebSocket above means we only parse messages for this PV
2849
useEffect(() => {
2950
const jsonMessage = api.PARSE_WEBSOCKET_MSG(lastJsonMessage, 2); // fix precision to 2 on the PV table
3051
if (jsonMessage === null) {
3152
return; // unable to parse, could be invalid message type, no PV name, null lastJsonMessage
3253
}
54+
setStartTimer(true);
3355
if ("severity" in jsonMessage) {
3456
setPVSeverity(jsonMessage.severity);
3557
}
3658
if ("units" in jsonMessage) {
3759
setPVUnit(jsonMessage.units);
3860
}
39-
if ("pv_value" in jsonMessage) {
61+
if (jsonMessage.pv_value !== null && "pv_value" in jsonMessage) {
4062
setPVValue(jsonMessage.pv_value);
4163
}
4264
}, [lastJsonMessage]);
@@ -59,7 +81,7 @@ function Value(props) {
5981
}
6082

6183
const severityName = pvSeverity === "UNDEFINED" || pvSeverity === "INVALID" ? ` (${pvSeverity})` : null
62-
if (pvValue !== undefined) {
84+
if (pvValue !== undefined && pvValue !== null) {
6385
if (Array.isArray(pvValue)) {
6486
return (
6587
<div style={{ color: textColor }}>{`[ ${pvValue.join(', ')} ] ${pvUnit}`}{severityName}</div>
@@ -70,11 +92,23 @@ function Value(props) {
7092
<div style={{ color: textColor }}>{`${pvValue} ${pvUnit}`}{severityName}</div>
7193
);
7294
}
73-
}
74-
else {
75-
return (
76-
null
77-
);
95+
} else {
96+
if (import.meta.env.REACT_APP_SHOW_DISCONNECTED !== "true") {
97+
return (
98+
<div></div>
99+
);
100+
} else {
101+
// debounce showing "Disconnected" to avoid flashing for PVs that are actually connected
102+
if (!show) {
103+
return (
104+
<div></div>
105+
);
106+
}
107+
textColor = colors.SEV_COLORS["UNDEFINED"];
108+
return (
109+
<div style={{ color: textColor }}>(DISCONNECTED)</div>
110+
);
111+
}
78112
}
79113
}
80114
}

src/components/home/queryresults/valuecheckbox/ValueCheckbox.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ function ValueCheckbox(props) {
3535
else if (props.recordType === "waveform" && import.meta.env.REACT_APP_PVWS_ALLOW_WAVEFORMS !== "true") {
3636
setEnabled(false);
3737
}
38-
}, [props.pvStatus, props.recordType])
38+
else {
39+
setEnabled(true);
40+
}
41+
}, [props.pvStatus, props.recordType, props.pvName])
3942

4043
// watch for changes in checked, if so send a subscribe message
4144
useEffect(() => {

src/components/pv/valuetable/ValueTable.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ function ValueTable(props) {
124124
}
125125
}
126126
if (message.pv_value === null) {
127+
setPVSeverity("DISCONNECTED");
128+
setAlarmColor(colors.SEV_COLORS["UNDEFINED"]);
127129
return; // only if no text, b64dbl, b64int, ..., value property found
128130
}
129131
if (!props.snapshot) {

0 commit comments

Comments
 (0)