Skip to content

Commit fb9f78c

Browse files
committed
bar
1 parent ba139e3 commit fb9f78c

File tree

7 files changed

+73
-53
lines changed

7 files changed

+73
-53
lines changed

app/components/Block.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ export default function Block({
2323
}
2424
if (pv.value != currentValue) {
2525
setCurrentValue(pv.value);
26-
// Let the user know a change has occurred by lighting up the green dot next to the value
27-
const pvChangedIndicator = document.getElementById(
28-
pv.human_readable_name + "_CIRCLE",
29-
);
30-
if (!pvChangedIndicator) return;
31-
if (pvChangedIndicator.classList.contains("text-green-500")) return;
32-
pvChangedIndicator.classList.remove("text-transparent");
33-
pvChangedIndicator.classList.add("text-green-500");
34-
setTimeout(() => {
35-
pvChangedIndicator.classList.remove("text-green-500");
36-
pvChangedIndicator.classList.add("text-transparent");
37-
}, 2000);
3826
}
3927

4028
const minimum_date_to_be_shown = 631152000; // This is what PVWS thinks epoch time is for some reason. don't bother showing it as the instrument wasn't running EPICS on 01/01/1990
@@ -71,15 +59,6 @@ export default function Block({
7159
{showAdvanced && "Readback: "}
7260
{pv.value} {pv.units != null && pv.units}
7361
</span>
74-
<svg
75-
id={pv.human_readable_name + "_CIRCLE"}
76-
className="min-w-2 min-h-2 max-w-2 max-h-2 transition-all text-transparent"
77-
xmlns="http://www.w3.org/2000/svg"
78-
fill="currentColor"
79-
viewBox="0 0 24 24"
80-
>
81-
<circle cx="12" cy="12" r="12" />
82-
</svg>
8362
</div>
8463

8564
{showAdvanced && (

app/components/CheckToggle.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Dispatch, SetStateAction } from "react";
1+
import { Dispatch, SetStateAction, useCallback } from "react";
2+
import { memo } from "react";
23

3-
export default function CheckToggle({
4+
const CheckToggle = memo(function CheckToggle({
45
checked,
56
setChecked,
67
text,
@@ -11,20 +12,24 @@ export default function CheckToggle({
1112
text: string;
1213
textColour?: string;
1314
}) {
15+
const callback = useCallback(() => {
16+
setChecked(!checked);
17+
}, [checked, setChecked]);
18+
1419
return (
1520
<div className="pt-4">
1621
<label className="inline-flex items-center cursor-pointer">
1722
<input
1823
type="checkbox"
1924
checked={checked}
20-
onChange={() => {
21-
setChecked(!checked);
22-
}}
25+
onChange={callback}
2326
className="sr-only peer"
2427
/>
2528
<div className="relative w-11 h-6 bg-gray-200 rounded-full peer peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-0.5 after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
2629
<span className={"ms-3 text-sm font-medium " + textColour}>{text}</span>
2730
</label>
2831
</div>
2932
);
30-
}
33+
});
34+
35+
export default CheckToggle;

app/components/Group.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import Block from "./Block";
22
import { checkIfAllBlocksInGroupAreHidden } from "./GroupUtils";
33

44
import { tBlockMapping } from "@/app/types";
5+
import { memo } from "react";
56

6-
export default function Group({
7+
const Group = memo(function Group({
78
group,
89
blocks,
910
instName,
@@ -51,4 +52,6 @@ export default function Group({
5152
</table>
5253
</div>
5354
);
54-
}
55+
});
56+
57+
export default Group;

app/components/Instrument.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ export class Instrument {
161161
);
162162
}
163163

164+
clone(): Instrument {
165+
let cloned = new Instrument(this.prefix);
166+
cloned.groups = structuredClone(this.groups);
167+
cloned.runInfoPVs = structuredClone(this.runInfoPVs);
168+
cloned.dashboard = structuredClone(this.dashboard);
169+
return cloned;
170+
}
171+
164172
getAllBlockPVs(): Array<string> {
165173
const blocksPerGroup = Array.from(this.groups.values());
166174
return Array.from(blocksPerGroup)

app/components/InstrumentData.tsx

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import {useEffect, useRef, useState} from "react";
2+
import { RefObject, useEffect, useRef, useState } from "react";
33
import { IfcPVWSMessage, IfcPVWSRequest, PVWSRequestType } from "@/app/types";
44
import {
55
findPVInGroups,
@@ -46,7 +46,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
4646
}
4747
}, [instName]);
4848

49-
let messageQueue = useRef([]);
49+
let messageQueue: RefObject<Array<MessageEvent>> = useRef([]);
5050

5151
const {
5252
sendJsonMessage,
@@ -67,6 +67,7 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
6767
const prefix = getPrefix(instListFromBytes(updatedPVbytes), instName);
6868
const instrument = new Instrument(prefix);
6969
setCurrentInstrument(instrument);
70+
messageQueue.current = [];
7071

7172
// subscribe to dashboard and run info PVs
7273
sendJsonMessage({
@@ -78,29 +79,29 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
7879
return;
7980
}
8081

81-
if (!currentInstrument) {
82-
return;
83-
}
84-
8582
if (
83+
currentInstrument &&
8684
updatedPVName == `${currentInstrument.prefix}${CONFIG_DETAILS}` &&
8785
updatedPVbytes != null
8886
) {
8987
// config change, reset instrument groups
90-
if (updatedPVbytes == lastUpdate) {
88+
if (updatedPVbytes == lastUpdate || !currentInstrument) {
9189
// config hasnt actually changed so do nothing
9290
return;
9391
}
94-
setLastUpdate(updatedPVbytes);
95-
currentInstrument.groups = getGroupsWithBlocksFromConfigOutput(
96-
currentInstrument.prefix,
92+
let newInstrument = currentInstrument.clone();
93+
newInstrument.groups = getGroupsWithBlocksFromConfigOutput(
94+
newInstrument.prefix,
9795
JSON.parse(dehex_and_decompress(atob(updatedPVbytes))),
9896
);
9997

10098
sendJsonMessage({
10199
type: PVWSRequestType.subscribe,
102-
pvs: currentInstrument.getAllBlockPVs(),
100+
pvs: newInstrument.getAllBlockPVs(),
103101
});
102+
103+
setLastUpdate(updatedPVbytes);
104+
setCurrentInstrument(newInstrument);
104105
} else {
105106
messageQueue.current.push(m);
106107
}
@@ -118,9 +119,17 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
118119

119120
useEffect(() => {
120121
const interval = setInterval(() => {
121-
console.log("Process " + messageQueue.current.length + " queued messages");
122+
if (currentInstrument == null) {
123+
return;
124+
}
125+
console.log(
126+
"Process " + messageQueue.current.length + " queued messages",
127+
);
128+
129+
let newInstrument = currentInstrument.clone();
130+
122131
while (true) {
123-
const m = messageQueue.current.pop();
132+
const m = messageQueue.current.shift();
124133
if (m === undefined) {
125134
break;
126135
}
@@ -130,15 +139,18 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
130139
const pvVal = getPvValue(updatedPV);
131140

132141
if (pvVal == undefined) {
133-
console.debug(`initial/blank message from ${updatedPVName}`);
134-
return;
142+
console.debug(
143+
`initial/blank message from ${updatedPVName}: ${m.data}`,
144+
);
145+
continue;
135146
}
136147

137148
// Check if this is a dashboard, run info, or block PV update.
138149
const pv =
139-
currentInstrument.dashboard.get(updatedPVName) ||
140-
currentInstrument.runInfoPVs.get(updatedPVName) ||
141-
findPVInGroups(currentInstrument.groups, updatedPVName);
150+
newInstrument.dashboard.get(updatedPVName) ||
151+
newInstrument.runInfoPVs.get(updatedPVName) ||
152+
findPVInGroups(newInstrument.groups, updatedPVName);
153+
142154
if (pv) {
143155
storePrecision(updatedPV, pv);
144156
pv.value = toPrecision(pv, pvVal);
@@ -150,21 +162,21 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
150162
// its object such as its run control status or SP:RBV
151163
if (updatedPVName.endsWith(RC_INRANGE)) {
152164
const underlyingBlock = findPVInGroups(
153-
currentInstrument.groups,
165+
newInstrument.groups,
154166
updatedPVName.replace(RC_INRANGE, ""),
155167
);
156168
if (underlyingBlock)
157169
underlyingBlock.runcontrol_inrange = yesToBoolean(pvVal);
158170
} else if (updatedPVName.endsWith(RC_ENABLE)) {
159171
const underlyingBlock = findPVInGroups(
160-
currentInstrument.groups,
172+
newInstrument.groups,
161173
updatedPVName.replace(RC_ENABLE, ""),
162174
);
163175
if (underlyingBlock)
164176
underlyingBlock.runcontrol_enabled = yesToBoolean(pvVal);
165177
} else if (updatedPVName.endsWith(SP_RBV)) {
166178
const underlyingBlock = findPVInGroups(
167-
currentInstrument.groups,
179+
newInstrument.groups,
168180
updatedPVName.replace(SP_RBV, ""),
169181
);
170182
if (underlyingBlock)
@@ -176,7 +188,8 @@ export function InstrumentData({ instrumentName }: { instrumentName: string }) {
176188
}
177189
}
178190
}
179-
}, 5000);
191+
setCurrentInstrument(newInstrument);
192+
}, 1000);
180193
return () => clearInterval(interval);
181194
}, [currentInstrument]);
182195

app/components/TopBar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66

77
import { tBlockMapping } from "@/app/types";
88
import { DASHBOARD } from "@/app/components/Instrument";
9+
import { memo } from "react";
910

1011
export const runStateStr = "Run state";
1112
export const configName = "Config name";
@@ -18,7 +19,7 @@ export function getRunstate(prefix: string, runInfoPVs: tBlockMapping): string {
1819
return UNREACHABLE;
1920
}
2021

21-
export default function TopBar({
22+
const TopBar = memo(function TopBar({
2223
dashboard,
2324
instName,
2425
runInfoPVs,
@@ -151,4 +152,6 @@ export default function TopBar({
151152
</div>
152153
</div>
153154
);
154-
}
155+
});
156+
157+
export default TopBar;

next.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ const nextConfig: NextConfig = {
66
images: {
77
unoptimized: true,
88
},
9+
// compress: false,
10+
// webpack(webpackConfig) {
11+
// return {
12+
// ...webpackConfig,
13+
// optimization: {
14+
// minimize: false,
15+
// },
16+
// };
17+
// },
918
};
1019

1120
module.exports = nextConfig;

0 commit comments

Comments
 (0)