Skip to content

Commit c98ebb2

Browse files
committed
move createInstrumentGroupsFromInstlist to separate file
1 parent 1ed10b5 commit c98ebb2

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

app/instruments/page.tsx

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
"use client";
22
import Link from "next/link";
33
import { useEffect, useState } from "react";
4-
import {
5-
IfcPVWSMessage,
6-
IfcPVWSRequest,
7-
instList,
8-
PVWSRequestType,
9-
} from "@/app/types";
10-
import {
11-
dehex_and_decompress,
12-
instListFromBytes,
13-
} from "@/app/components/dehex_and_decompress";
4+
import { IfcPVWSMessage, IfcPVWSRequest } from "@/app/types";
5+
import { instListFromBytes } from "@/app/components/dehex_and_decompress";
146
import useWebSocket from "react-use-websocket";
157
import { instListPV, instListSubscription, socketURL } from "@/app/commonVars";
16-
17-
export function createInstrumentGroupsFromInstlist(
18-
jsonInstList: instList,
19-
): Map<string, Array<string>> {
20-
let newInstrumentGroups: Map<string, Array<string>> = new Map();
21-
for (let inst of jsonInstList) {
22-
for (let group of inst["groups"]) {
23-
if (!newInstrumentGroups.has(group)) {
24-
newInstrumentGroups.set(group, []);
25-
}
26-
newInstrumentGroups.get(group)!.push(inst["name"]);
27-
}
28-
}
29-
return newInstrumentGroups;
30-
}
8+
import createInstrumentGroupsFromInstlist from "@/app/instruments/utils";
319

3210
export default function Instruments() {
3311
const [instrumentGroups, setInstrumentGroups] = useState<
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createInstrumentGroupsFromInstlist } from "@/app/instruments/page";
1+
import createInstrumentGroupsFromInstlist from "@/app/instruments/utils";
22
import { instList } from "@/app/types";
33

44
test("createInstrumentGroupsFromInstlist adds an instrument to a group if it has one", () => {

app/instruments/utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { instList } from "@/app/types";
2+
3+
export default function createInstrumentGroupsFromInstlist(
4+
jsonInstList: instList,
5+
): Map<string, Array<string>> {
6+
let newInstrumentGroups: Map<string, Array<string>> = new Map();
7+
for (let inst of jsonInstList) {
8+
for (let group of inst["groups"]) {
9+
if (!newInstrumentGroups.has(group)) {
10+
newInstrumentGroups.set(group, []);
11+
}
12+
newInstrumentGroups.get(group)!.push(inst["name"]);
13+
}
14+
}
15+
return newInstrumentGroups;
16+
}

0 commit comments

Comments
 (0)