github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/components/dashboards/layout/Dashboard/index.tsx (about)

     1  import Children from "../Children";
     2  import DashboardProgress from "./DashboardProgress";
     3  import DashboardTitle from "../../titles/DashboardTitle";
     4  import Grid from "../Grid";
     5  import PanelDetail from "../PanelDetail";
     6  import SnapshotRenderComplete from "../../../snapshot/SnapshotRenderComplete";
     7  import { DashboardDataModeLive, DashboardDefinition } from "../../../../types";
     8  import { registerComponent } from "../../index";
     9  import { useDashboard } from "../../../../hooks/useDashboard";
    10  
    11  type DashboardProps = {
    12    definition: DashboardDefinition;
    13    isRoot?: boolean;
    14    showPanelControls?: boolean;
    15    withPadding?: boolean;
    16  };
    17  
    18  type DashboardWrapperProps = {
    19    showPanelControls?: boolean;
    20  };
    21  
    22  // TODO allow full-screen of a panel
    23  const Dashboard = ({
    24    definition,
    25    isRoot = true,
    26    showPanelControls = true,
    27  }: DashboardProps) => {
    28    const grid = (
    29      <Grid name={definition.name} width={isRoot ? 12 : definition.width}>
    30        {isRoot && <DashboardTitle title={definition.title} />}
    31        <Children
    32          children={definition.children}
    33          parentType="dashboard"
    34          showPanelControls={showPanelControls}
    35        />
    36      </Grid>
    37    );
    38    return (
    39      <>
    40        {isRoot ? <DashboardProgress /> : null}
    41        {isRoot ? <div className="h-full overflow-y-auto p-4">{grid}</div> : grid}
    42      </>
    43    );
    44  };
    45  
    46  const DashboardWrapper = ({
    47    showPanelControls = true,
    48  }: DashboardWrapperProps) => {
    49    const { dashboard, dataMode, search, selectedDashboard, selectedPanel } =
    50      useDashboard();
    51  
    52    if (
    53      search.value ||
    54      !dashboard ||
    55      (!selectedDashboard && dataMode === DashboardDataModeLive)
    56    ) {
    57      return null;
    58    }
    59  
    60    if (selectedPanel) {
    61      return <PanelDetail definition={selectedPanel} />;
    62    }
    63  
    64    return (
    65      <>
    66        <Dashboard
    67          definition={dashboard}
    68          showPanelControls={showPanelControls}
    69          withPadding={true}
    70        />
    71        <SnapshotRenderComplete />
    72      </>
    73    );
    74  };
    75  
    76  registerComponent("dashboard", Dashboard);
    77  
    78  export default DashboardWrapper;
    79  
    80  export { Dashboard };