github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/hooks/usePanelDependenciesStatus.ts (about)

     1  import { PanelDefinition } from "../types";
     2  import { PanelDependencyStatuses } from "../components/dashboards/common/types";
     3  import { useMemo } from "react";
     4  import { usePanel } from "./usePanel";
     5  
     6  const usePanelDependenciesStatus = () => {
     7    const { dependenciesByStatus, inputPanelsAwaitingValue } = usePanel();
     8  
     9    return useMemo<PanelDependencyStatuses>(() => {
    10      const initializedPanels: PanelDefinition[] = [];
    11      const blockedPanels: PanelDefinition[] = [];
    12      const runningPanels: PanelDefinition[] = [];
    13      const cancelledPanels: PanelDefinition[] = [];
    14      const errorPanels: PanelDefinition[] = [];
    15      const completePanels: PanelDefinition[] = [];
    16      let total = 0;
    17      for (const panels of Object.values(dependenciesByStatus)) {
    18        for (const panel of panels) {
    19          total += 1;
    20          if (panel.status === "initialized") {
    21            initializedPanels.push(panel);
    22          } else if (panel.status === "blocked") {
    23            blockedPanels.push(panel);
    24          } else if (panel.status === "running") {
    25            runningPanels.push(panel);
    26          } else if (panel.status === "cancelled") {
    27            completePanels.push(panel);
    28          } else if (panel.status === "error") {
    29            errorPanels.push(panel);
    30          } else if (panel.status === "complete") {
    31            completePanels.push(panel);
    32          }
    33        }
    34      }
    35      const status = {
    36        initialized: {
    37          total: initializedPanels.length,
    38          panels: initializedPanels,
    39        },
    40        blocked: {
    41          total: blockedPanels.length,
    42          panels: blockedPanels,
    43        },
    44        running: {
    45          total: runningPanels.length,
    46          panels: runningPanels,
    47        },
    48        cancelled: {
    49          total: cancelledPanels.length,
    50          panels: cancelledPanels,
    51        },
    52        error: {
    53          total: errorPanels.length,
    54          panels: errorPanels,
    55        },
    56        complete: {
    57          total: completePanels.length,
    58          panels: completePanels,
    59        },
    60      };
    61      return {
    62        total,
    63        inputsAwaitingValue: inputPanelsAwaitingValue,
    64        status,
    65      };
    66    }, [dependenciesByStatus, inputPanelsAwaitingValue]);
    67  };
    68  
    69  export default usePanelDependenciesStatus;