From fcc8805c014e47b3b985ba62b1718e153f151de9 Mon Sep 17 00:00:00 2001 From: Jack Harper Date: Thu, 12 Sep 2024 13:41:03 +0100 Subject: [PATCH] formatting --- app/NavBar.tsx | 3 -- app/_app.tsx | 2 +- app/components/Group.tsx | 4 +- app/components/GroupUtils.test.ts | 2 +- app/components/IfcGroup.ts | 6 +-- app/components/InstList.ts | 13 +++-- app/components/Instrument.ts | 8 +-- app/components/InstrumentData.tsx | 62 ++++++++++++++-------- app/components/InstrumentWallCard.tsx | 4 +- app/components/TopBar.tsx | 26 +++++++-- app/layout.tsx | 14 +++-- app/page.tsx | 2 +- app/wall/IfcInstrumentStatus.ts | 6 +-- app/wall/page.tsx | 76 +++++++++++++-------------- 14 files changed, 127 insertions(+), 101 deletions(-) diff --git a/app/NavBar.tsx b/app/NavBar.tsx index 0863450..dd5de5f 100644 --- a/app/NavBar.tsx +++ b/app/NavBar.tsx @@ -2,8 +2,6 @@ import Link from "next/link"; import Image from "next/image"; export default function NavBar() { - - return (
-
); diff --git a/app/_app.tsx b/app/_app.tsx index bda571c..4979847 100644 --- a/app/_app.tsx +++ b/app/_app.tsx @@ -2,6 +2,6 @@ import "./globals.css"; import { AppProps } from "next/app"; -export default function App({ Component, pageProps } :AppProps) { +export default function App({ Component, pageProps }: AppProps) { return ; } diff --git a/app/components/Group.tsx b/app/components/Group.tsx index 3c1e55b..26dbea3 100644 --- a/app/components/Group.tsx +++ b/app/components/Group.tsx @@ -23,7 +23,9 @@ export default function Group({ return (
-

{group.name}

+

+ {group.name} +

diff --git a/app/components/GroupUtils.test.ts b/app/components/GroupUtils.test.ts index 1c8a847..3e0d17b 100644 --- a/app/components/GroupUtils.test.ts +++ b/app/components/GroupUtils.test.ts @@ -3,7 +3,7 @@ import { IfcGroup } from "./IfcGroup"; class MockGroup implements IfcGroup { blocks: MockBlock[]; - name:string; + name: string; constructor(blocks: Array) { this.blocks = blocks; this.name = "test"; diff --git a/app/components/IfcGroup.ts b/app/components/IfcGroup.ts index b0cd8ad..12ed097 100644 --- a/app/components/IfcGroup.ts +++ b/app/components/IfcGroup.ts @@ -1,4 +1,4 @@ export interface IfcGroup { - name:string; - blocks:Array -} \ No newline at end of file + name: string; + blocks: Array; +} diff --git a/app/components/InstList.ts b/app/components/InstList.ts index 36b3972..9e35bf9 100644 --- a/app/components/InstList.ts +++ b/app/components/InstList.ts @@ -1,4 +1,3 @@ - import useWebSocket from "react-use-websocket"; import { dehex_and_decompress } from "./dehex_and_decompress"; @@ -15,14 +14,14 @@ export default function InstList() { let instList = null; - if (lastJsonMessage) { - if (lastJsonMessage.b64byt && typeof lastJsonMessage.b64byt == "string") { - const response: any = dehex_and_decompress(atob(lastJsonMessage.b64byt)); - if (typeof response == "string") { - instList = JSON.parse(response); - } + if (lastJsonMessage) { + if (lastJsonMessage.b64byt && typeof lastJsonMessage.b64byt == "string") { + const response: any = dehex_and_decompress(atob(lastJsonMessage.b64byt)); + if (typeof response == "string") { + instList = JSON.parse(response); } } + } if (!instList) { return; diff --git a/app/components/Instrument.ts b/app/components/Instrument.ts index 07bcf57..83b83f1 100644 --- a/app/components/Instrument.ts +++ b/app/components/Instrument.ts @@ -12,7 +12,7 @@ export class Instrument { runInfoPVs: Map; configname: string; groups: Array; - constructor(prefix:string) { + constructor(prefix: string) { this.prefix = prefix; this.dashboard_prefix = `${this.prefix}${DASHBOARD}`; @@ -20,7 +20,7 @@ export class Instrument { Object.entries({ [`${this.prefix}DAE:TITLE`]: "Title:", [`${this.prefix}DAE:_USERNAME`]: "Users:", - }) + }), ); this.dictLongerInstPVs = new Map( @@ -31,7 +31,7 @@ export class Instrument { [`${this.dashboard_prefix}1:2:LABEL`]: `${this.dashboard_prefix}1:2:VALUE`, [`${this.dashboard_prefix}2:2:LABEL`]: `${this.dashboard_prefix}2:2:VALUE`, [`${this.dashboard_prefix}3:2:LABEL`]: `${this.dashboard_prefix}3:2:VALUE`, - }) + }), ); // PV name: [human readable name, column in top bar(null is monitor but don't show)] @@ -67,7 +67,7 @@ export class Instrument { [`${this.prefix}DAE:RUNDURATION_PD`]: "Period Run Time", [`${this.prefix}DAE:PERIODSEQ`]: "Period Sequence", [`${this.prefix}DAE:DAEMEMORYUSED`]: "DAE Memory Used", - }) + }), ); // (label) PV address : [row, col, label, value] diff --git a/app/components/InstrumentData.tsx b/app/components/InstrumentData.tsx index d19aff9..e8237d5 100644 --- a/app/components/InstrumentData.tsx +++ b/app/components/InstrumentData.tsx @@ -1,4 +1,4 @@ -"use client" +"use client"; import React from "react"; import TopBar from "./TopBar"; import Groups from "./Groups"; @@ -6,25 +6,38 @@ import { useEffect, useState } from "react"; import useWebSocket from "react-use-websocket"; import { dehex_and_decompress } from "./dehex_and_decompress"; import { Instrument } from "./Instrument"; -import {PV} from "./PV"; +import { PV } from "./PV"; import { PVWSMessage } from "./IfcPVWSMessage"; let lastUpdate: string = ""; -export default function InstrumentData({instrumentName}: {instrumentName:string} ) { +export default function InstrumentData({ + instrumentName, +}: { + instrumentName: string; +}) { // set up the different states for the instrument data - const socketURL = process.env.NEXT_PUBLIC_WS_URL || "ws://localhost:8080/pvws/pv"; + const socketURL = + process.env.NEXT_PUBLIC_WS_URL || "ws://localhost:8080/pvws/pv"; - const instName = instrumentName ; + const instName = instrumentName; - const { sendJsonMessage, lastJsonMessage }: {sendJsonMessage:any,lastJsonMessage:PVWSMessage} = useWebSocket(socketURL, { - shouldReconnect: (closeEvent) => true, - }); + const { + sendJsonMessage, + lastJsonMessage, + }: { sendJsonMessage: any; lastJsonMessage: PVWSMessage } = useWebSocket( + socketURL, + { + shouldReconnect: (closeEvent) => true, + }, + ); const CONFIG_DETAILS = "CS:BLOCKSERVER:GET_CURR_CONFIG_DETAILS"; - const [instlist, setInstlist] = useState|null>(null); - const [currentInstrument, setCurrentInstrument] = useState(null); + const [instlist, setInstlist] = useState | null>(null); + const [currentInstrument, setCurrentInstrument] = useState( + null, + ); useEffect(() => { sendJsonMessage({ @@ -32,8 +45,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} pvs: ["CS:INSTLIST"], }); - - if (instName == "" || instName == null || instlist == null ) { + if (instName == "" || instName == null || instlist == null) { return; } @@ -81,10 +93,10 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} } const updatedPV: PVWSMessage = lastJsonMessage; const updatedPVName: string = updatedPV.pv; - const updatedPVbytes: string|null|undefined = updatedPV.b64byt; + const updatedPVbytes: string | null | undefined = updatedPV.b64byt; if (updatedPVName == "CS:INSTLIST" && updatedPVbytes != null) { - const dehexedInstList = dehex_and_decompress(atob(updatedPVbytes)) + const dehexedInstList = dehex_and_decompress(atob(updatedPVbytes)); if (dehexedInstList != null && typeof dehexedInstList == "string") { setInstlist(JSON.parse(dehexedInstList)); } @@ -135,7 +147,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} }); for (const block of groupBlocks) { - const newBlock = blocks.find((b:any) => b.name === block); + const newBlock = blocks.find((b: any) => b.name === block); const completePV = new PV(newBlock.pv); completePV.human_readable_name = newBlock.name; @@ -181,7 +193,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} // This is a top bar label PV if (!currentInstrument.topBarPVs.has(updatedPVName) && updatedPV.text) { let prefixRemoved = updatedPVName.split( - currentInstrument.dashboard_prefix + currentInstrument.dashboard_prefix, )[1]; let row = prefixRemoved[0]; let col = prefixRemoved[2]; @@ -198,11 +210,15 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} pvs: [value_pv], }); } - } else if (currentInstrument.columnZeroPVs.has(updatedPVName) && updatedPVbytes != null ) { + } else if ( + currentInstrument.columnZeroPVs.has(updatedPVName) && + updatedPVbytes != null + ) { // this is a top bar column zero value const row = updatedPVName.endsWith("TITLE") ? 0 : 1; // if title, column 1 - // Both of these are base64 encoded. PVWS gives a null byte back if there is no value, so replace with null. - const value = atob(updatedPVbytes) != "\x00" ? atob(updatedPVbytes) : null; + // Both of these are base64 encoded. PVWS gives a null byte back if there is no value, so replace with null. + const value = + atob(updatedPVbytes) != "\x00" ? atob(updatedPVbytes) : null; currentInstrument.topBarPVs.set(updatedPVName, [ row, 0, @@ -211,7 +227,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} ]); } else if ( Array.from(currentInstrument.dictLongerInstPVs.values()).includes( - updatedPVName + updatedPVName, ) ) { // this is a top bar value @@ -223,7 +239,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} } else if (currentInstrument.runInfoMap.has(updatedPVName)) { currentInstrument.runInfoPVs.set( currentInstrument.runInfoMap.get(updatedPVName), - pvVal + pvVal, ); } else { // This is a block - check if in groups @@ -256,7 +272,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} } const pv = document.getElementById( - block.human_readable_name + "_CIRCLE" + block.human_readable_name + "_CIRCLE", ); if (!pv) return; @@ -287,7 +303,7 @@ export default function InstrumentData({instrumentName}: {instrumentName:string} setShowHiddenBlocks(!showHiddenBlocks); }; - if (!instName || instName==null|| !currentInstrument) { + if (!instName || instName == null || !currentInstrument) { return

Loading...

; } return ( diff --git a/app/components/InstrumentWallCard.tsx b/app/components/InstrumentWallCard.tsx index de2ee28..e7a5bc9 100644 --- a/app/components/InstrumentWallCard.tsx +++ b/app/components/InstrumentWallCard.tsx @@ -2,13 +2,13 @@ import Link from "next/link"; import { motion } from "framer-motion"; import { getForegroundColor, getStatusColor } from "./getRunstateColours"; -export default function WallCard({ instrument }: {instrument:any}) { +export default function WallCard({ instrument }: { instrument: any }) { return ( , instName:string, runInfoPVs:Map }) => { - if (!monitoredPVs || !monitoredPVs.size || !runInfoPVs || !runInfoPVs.size|| !instName) { +const TopBar = ({ + monitoredPVs, + instName, + runInfoPVs, +}: { + monitoredPVs: Map; + instName: string; + runInfoPVs: Map; +}) => { + if ( + !monitoredPVs || + !monitoredPVs.size || + !runInfoPVs || + !runInfoPVs.size || + !instName + ) { return (

Loading... @@ -56,7 +70,7 @@ const TopBar = ({ monitoredPVs, instName, runInfoPVs }: {monitoredPVs: Map

- {[0, 1, 2].map((index:number) => ( + {[0, 1, 2].map((index: number) => ( @@ -90,7 +104,7 @@ const TopBar = ({ monitoredPVs, instName, runInfoPVs }: {monitoredPVs: Map
{getMonitoredPVs(index, monitoredPVs)} {label} - {value!=null?value:"Hidden/unknown"} + + {value != null ? value : "Hidden/unknown"} + - {children}