All files / src/hooks PinchHooks.ts

75% Statements 24/32
25% Branches 1/4
66.66% Functions 8/12
77.41% Lines 24/31

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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136                  1608x 1608x     1608x                                         1608x 1608x                                       7x 7x     7x                 269x 269x     269x                 7x 7x     7x                                 106x   106x         106x   106x                   161x 161x     161x         130x 130x     130x  
import { StreamDataProjectRead, usePinchPinchinputListQuery, usePinchPinchoptionsListQuery, usePinchPinchoutputListQuery, usePinchStreamDataProjectListQuery, usePinchSegmentListQuery, usePinchPinchutilityListQuery, useGraphicsgroupingsZonesRetrieveQuery } from "@/api/apiStore.gen";
import { useProjectId } from "@/hooks/project";
import { useSearchParam } from "@/hooks/searchParams";
 
/**
 * Gets all the 'StreamDataProject' objects related to the currently active flowsheet.
 * @returns Array of Projects - Type StreamDataProjectRead.
 */
export function useStreamDataProjects() {
    const flowsheetId: number = useProjectId();
    const { data: projects, isLoading, isError } = usePinchStreamDataProjectListQuery({
        flowsheet: flowsheetId,
    });
    return { projects: projects as StreamDataProjectRead[], isLoading, isError };
}
 
/**
 * Provides a function to query current StreamDataProjects by ID.
 * @returns Function taking an id parameter which returns the project of type StreamDataProjectRead.
 */
export function useStreamDataProject() {
    const { projects, isLoading, isError } = useStreamDataProjects();
    return {
        getStreamDataProject: (projectID: number) => projects.find(project => project.id === projectID),
        isLoading,
        isError,
    };
}
 
/**
 * Provides the current selected StreamDataProject ID
 * @returns ID of current StreamDataProject
 */
export function useCurrentStreamDataProjectID() {
    const { projects, isLoading, isError } = useStreamDataProjects()
    return projects?.[0].id
}
 
/**
 * Gets the currently selected StreamDataProject.
 * @returns Currently selected StreamDataProject of type StreamDataProjectRead.
 */
export function useCurrentStreamDataProject() {
    const currentProject = useCurrentStreamDataProjectID();
    const { getStreamDataProject, isLoading, isError } = useStreamDataProject();
    const project = currentProject ? getStreamDataProject(+currentProject) : undefined;
    return { project, isLoading, isError };
}
 
/**
 * Gets the inputs related to the current selected flowsheet.
 * TODO: Migrate to multi-project per flowsheet (by pinch search parameter).
 * @returns Selected StreamDataProjects input of type PinchInputRead
 */
export function useCurrentPinchInputs() {
    const project = useCurrentStreamDataProjectID();
    const {data: inputs, isLoading, isError} = usePinchPinchinputListQuery({
        projectOwner: +project,
    }, {skip: !project});
    return{ inputs, isLoading, isError};
}
 
/**
 * Gets the streams related to the current selected flowsheet.
 * TODO: Migrate to multi-project per flowsheet (by pinch search parameter).
 * @returns Selected StreamDataProjects stream of type SegmentRead[]
 */
export function useCurrentSegments() {
    const project = useCurrentStreamDataProjectID();
    const {data: streams, isLoading, isError} = usePinchSegmentListQuery({
       projectOwner: +project,
    }, {skip: !project});
    return{ streams, isLoading, isError};
}
 
/**
 * Gets the utilities related to the current selected flowsheet.
 * TODO: Migrate to multi-project per flowsheet (by pinch search parameter).
 * @returns Selected StreamDataProjects utilities of type PinchUtilitiyRead[]
 */
export function useCurrentPinchUtilities() {
    const project = useCurrentStreamDataProjectID();
    const {data: utilities, isLoading, isError} = usePinchPinchutilityListQuery({
        projectOwner: +project,
    }, {skip: !project});
    return{ utilities, isLoading, isError};
}
 
/**
 * Gets the options related to the current selected flowsheet.
 * TODO: Migrate to multi-project per flowsheet (by pinch search parameter).
 * @returns Selected StreamDataProjects options of type MainOptionsRead[]
 */
// export function useCurrentPinchOptions() {
//     const project = useCurrentStreamDataProjectID();
//     const {data: options, isLoading, isError} = usePinchPinchoptionsListQuery({
//         projectOwner: +project,
//     }, {skip: !project});
//     return{ options, isLoading, isError};
// }
 
export function useCurrentPinchOptions() {
    const project = useCurrentStreamDataProjectID();
 
    const queryResult = usePinchPinchoptionsListQuery(
        { projectOwner: +project },
        { skip: !project }
    );
 
    const { data: options, isLoading, isError } = queryResult || {};
 
    return { options, isLoading, isError };
}
 
 
/**
 * Gets the outputs related to the current selected flowsheet.
 * TODO: Migrate to multi-project per flowsheet (by pinch search parameter).
 * @returns Selected StreamDataProjects outputs of type PinchOutputsRead[]
 */
export function useCurrentPinchOutputs() {
    const project = useCurrentStreamDataProjectID();
    const {data: outputs, isLoading, isError} = usePinchPinchoutputListQuery({
        projectOwner: +project,
    }, {skip: !project});
    return{ outputs, isLoading, isError};
}
 
 
export function useCurrentStreamDataZones(){
    const project = useCurrentStreamDataProjectID();
    const {data: zones, isLoading, isError} = useGraphicsgroupingsZonesRetrieveQuery({
       projectOwner: +project,
    }, {skip: !project});
    return {zones, isLoading, isError};
}