File tree Expand file tree Collapse file tree 3 files changed +20
-26
lines changed
Expand file tree Collapse file tree 3 files changed +20
-26
lines changed Original file line number Diff line number Diff line change 11"use client" ;
22import Link from "next/link" ;
33import { 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" ;
146import useWebSocket from "react-use-websocket" ;
157import { 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
3210export default function Instruments ( ) {
3311 const [ instrumentGroups , setInstrumentGroups ] = useState <
Original file line number Diff line number Diff line change 1- import { createInstrumentGroupsFromInstlist } from "@/app/instruments/page " ;
1+ import createInstrumentGroupsFromInstlist from "@/app/instruments/utils " ;
22import { instList } from "@/app/types" ;
33
44test ( "createInstrumentGroupsFromInstlist adds an instrument to a group if it has one" , ( ) => {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments