All files / src/hooks henHooks.ts

100% Statements 21/21
100% Branches 3/3
100% Functions 6/6
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                    48x           48x 33x   15x         123x 123x   123x 4x   4x 3x   3x       123x   7x 7x       123x               319x           319x           319x       392x 392x                
import React, { useState, useCallback, useRef } from "react";
import { useCurrentStreamDataProjectID } from "./PinchHooks";
import {
  usePinchHenNodeListQuery,
  usePinchStreamDataEntryListQuery,
  useUnitopsSimulationobjectsRetrieveQuery,
} from "@/api/apiStore.gen";
 
// getNodeObject but without searchParams
export function getNodeObject(objectId){
  const { data: object } = useUnitopsSimulationobjectsRetrieveQuery(
    {
      id: +objectId!,
    },
    { skip: !objectId },
  );
  if (!objectId) {
    return undefined;
  }
  return object;
}
 
// to getsizes 
export function useElementSize<T extends HTMLElement>() {
  const ref = useRef<T | null>(null);
  const [size, setSize] = useState({ width: 0, height: 0 });
 
  const setRef = useCallback((node: T | null) => {
    if (ref.current) observer.disconnect(); // cleanup previous
 
    if (node) {
      ref.current = node;
 
      observer.observe(node); // observe new
    }
  }, []);
 
  const observer = useRef<ResizeObserver>(
    new ResizeObserver(([entry]) => {
      const { width, height } = entry.contentRect;
      setSize({ width, height });
    })
  ).current;
 
  return [setRef, size] as const;
}
 
/**
 * Gets the input/output streams related to the selected flowsheet as one continuous stream.
 * @returns All StreamDataEntries of type StreamDataEntryRead[]
 */
export function useCurrentStreamDataEntries() {
  const project = useCurrentStreamDataProjectID();
  const {
    data: streams,
    isLoading,
    isError,
    refetch,
  } = usePinchStreamDataEntryListQuery(
    {
      streamDataProject: +project,
    },
    { skip: !project }
  );
  return { streams, isLoading, isError, refetch };
}
 
export function useCurrentHenNodes() {
  const project = useCurrentStreamDataProjectID();
  return usePinchHenNodeListQuery(
    {
      projectOwner: +project,
    },
    { skip: !project }
  );
}