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

     1  import {
     2    DashboardLayoutNode,
     3    DashboardPanelType,
     4    PanelDefinition,
     5  } from "../../../../types";
     6  import { getComponent } from "../../index";
     7  import { getNodeAndEdgeDataFormat } from "../../common/useNodeAndEdgeData";
     8  import { NodeAndEdgeProperties } from "../../common/types";
     9  
    10  type ChildProps = {
    11    layoutDefinition: DashboardLayoutNode;
    12    panelDefinition: PanelDefinition;
    13    parentType: DashboardPanelType;
    14    showPanelControls?: boolean;
    15  };
    16  
    17  const Child = ({
    18    layoutDefinition,
    19    panelDefinition,
    20    parentType,
    21    showPanelControls = true,
    22  }: ChildProps) => {
    23    const Panel = getComponent("panel");
    24    switch (layoutDefinition.panel_type) {
    25      case "benchmark":
    26      case "control":
    27        const Benchmark = getComponent("benchmark");
    28        return (
    29          <Benchmark
    30            {...(layoutDefinition as PanelDefinition)}
    31            showControls={showPanelControls}
    32          />
    33        );
    34      case "card":
    35        const Card = getComponent("card");
    36        return (
    37          <Panel
    38            definition={panelDefinition}
    39            parentType={parentType}
    40            showControls={showPanelControls}
    41            showPanelStatus={false}
    42          >
    43            <Card {...panelDefinition} />
    44          </Panel>
    45        );
    46      case "chart":
    47        const Chart = getComponent("chart");
    48        return (
    49          <Panel
    50            definition={panelDefinition}
    51            parentType={parentType}
    52            showControls={showPanelControls}
    53          >
    54            <Chart {...panelDefinition} />
    55          </Panel>
    56        );
    57      case "container":
    58        const Container = getComponent("container");
    59        return <Container layoutDefinition={layoutDefinition} />;
    60      case "dashboard":
    61        const Dashboard = getComponent("dashboard");
    62        return <Dashboard definition={panelDefinition} isRoot={false} />;
    63      case "error":
    64        const ErrorPanel = getComponent("error");
    65        return (
    66          <Panel
    67            definition={panelDefinition}
    68            parentType={parentType}
    69            showControls={showPanelControls}
    70          >
    71            <ErrorPanel {...panelDefinition} />
    72          </Panel>
    73        );
    74      case "flow": {
    75        const Flow = getComponent("flow");
    76        const format = getNodeAndEdgeDataFormat(
    77          panelDefinition.properties as NodeAndEdgeProperties
    78        );
    79        return (
    80          <Panel
    81            definition={panelDefinition}
    82            parentType={parentType}
    83            showPanelStatus={
    84              format === "LEGACY" ||
    85              panelDefinition.status === "cancelled" ||
    86              panelDefinition.status === "error"
    87            }
    88            // Node and edge format will show error info on the panel information
    89            showPanelError={format === "LEGACY"}
    90          >
    91            <Flow {...panelDefinition} />
    92          </Panel>
    93        );
    94      }
    95      case "graph": {
    96        const Graph = getComponent("graph");
    97        const format = getNodeAndEdgeDataFormat(
    98          panelDefinition.properties as NodeAndEdgeProperties
    99        );
   100        return (
   101          <Panel
   102            definition={panelDefinition}
   103            parentType={parentType}
   104            showControls={showPanelControls}
   105            showPanelStatus={
   106              format === "LEGACY" ||
   107              panelDefinition.status === "cancelled" ||
   108              panelDefinition.status === "error"
   109            }
   110            // Node and edge format will show error info on the panel information
   111            showPanelError={format === "LEGACY"}
   112          >
   113            <Graph {...panelDefinition} />
   114          </Panel>
   115        );
   116      }
   117      case "hierarchy": {
   118        const Hierarchy = getComponent("hierarchy");
   119        const format = getNodeAndEdgeDataFormat(
   120          panelDefinition.properties as NodeAndEdgeProperties
   121        );
   122        return (
   123          <Panel
   124            definition={panelDefinition}
   125            parentType={parentType}
   126            showPanelStatus={
   127              format === "LEGACY" ||
   128              panelDefinition.status === "cancelled" ||
   129              panelDefinition.status === "error"
   130            }
   131            // Node and edge format will show error info on the panel information
   132            showPanelError={format === "LEGACY"}
   133          >
   134            <Hierarchy {...panelDefinition} />
   135          </Panel>
   136        );
   137      }
   138      case "image":
   139        const Image = getComponent("image");
   140        return (
   141          <Panel
   142            definition={panelDefinition}
   143            parentType={parentType}
   144            showControls={showPanelControls}
   145          >
   146            <Image {...panelDefinition} />
   147          </Panel>
   148        );
   149      case "input":
   150        const Input = getComponent("input");
   151        return (
   152          <Panel
   153            definition={panelDefinition}
   154            parentType={parentType}
   155            showControls={
   156              showPanelControls &&
   157              (panelDefinition.title || panelDefinition.display_type === "table")
   158            }
   159            showPanelStatus={false}
   160          >
   161            <Input {...panelDefinition} />
   162          </Panel>
   163        );
   164      case "table":
   165        const Table = getComponent("table");
   166        return (
   167          <Panel
   168            definition={panelDefinition}
   169            parentType={parentType}
   170            showControls={showPanelControls}
   171          >
   172            <Table {...panelDefinition} />
   173          </Panel>
   174        );
   175      case "text":
   176        const Text = getComponent("text");
   177        return (
   178          <Panel
   179            definition={panelDefinition}
   180            parentType={parentType}
   181            showControls={false}
   182          >
   183            <Text {...panelDefinition} />
   184          </Panel>
   185        );
   186      default:
   187        return null;
   188    }
   189  };
   190  
   191  export default Child;