diff --git a/app/instruments/page.tsx b/app/instruments/page.tsx index 858929e..a08832c 100644 --- a/app/instruments/page.tsx +++ b/app/instruments/page.tsx @@ -1,33 +1,11 @@ "use client"; import Link from "next/link"; import { useEffect, useState } from "react"; -import { - IfcPVWSMessage, - IfcPVWSRequest, - instList, - PVWSRequestType, -} from "@/app/types"; -import { - dehex_and_decompress, - instListFromBytes, -} from "@/app/components/dehex_and_decompress"; +import { IfcPVWSMessage, IfcPVWSRequest } from "@/app/types"; +import { instListFromBytes } from "@/app/components/dehex_and_decompress"; import useWebSocket from "react-use-websocket"; import { instListPV, instListSubscription, socketURL } from "@/app/commonVars"; - -export function createInstrumentGroupsFromInstlist( - jsonInstList: instList, -): Map> { - let newInstrumentGroups: Map> = new Map(); - for (let inst of jsonInstList) { - for (let group of inst["groups"]) { - if (!newInstrumentGroups.has(group)) { - newInstrumentGroups.set(group, []); - } - newInstrumentGroups.get(group)!.push(inst["name"]); - } - } - return newInstrumentGroups; -} +import createInstrumentGroupsFromInstlist from "@/app/instruments/utils"; export default function Instruments() { const [instrumentGroups, setInstrumentGroups] = useState< diff --git a/app/instruments/page.test.tsx b/app/instruments/utils.test.tsx similarity index 95% rename from app/instruments/page.test.tsx rename to app/instruments/utils.test.tsx index f4f8a81..c98d023 100644 --- a/app/instruments/page.test.tsx +++ b/app/instruments/utils.test.tsx @@ -1,4 +1,4 @@ -import { createInstrumentGroupsFromInstlist } from "@/app/instruments/page"; +import createInstrumentGroupsFromInstlist from "@/app/instruments/utils"; import { instList } from "@/app/types"; test("createInstrumentGroupsFromInstlist adds an instrument to a group if it has one", () => { diff --git a/app/instruments/utils.ts b/app/instruments/utils.ts new file mode 100644 index 0000000..4fd04a9 --- /dev/null +++ b/app/instruments/utils.ts @@ -0,0 +1,16 @@ +import { instList } from "@/app/types"; + +export default function createInstrumentGroupsFromInstlist( + jsonInstList: instList, +): Map> { + let newInstrumentGroups: Map> = new Map(); + for (let inst of jsonInstList) { + for (let group of inst["groups"]) { + if (!newInstrumentGroups.has(group)) { + newInstrumentGroups.set(group, []); + } + newInstrumentGroups.get(group)!.push(inst["name"]); + } + } + return newInstrumentGroups; +}