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

     1  import { LeafNodeData, Width } from "../components/dashboards/common";
     2  import { Ref } from "react";
     3  import { Theme } from "../hooks/useTheme";
     4  
     5  export type IDashboardContext = {
     6    versionMismatchCheck: boolean;
     7    metadata: DashboardMetadata | null;
     8    availableDashboardsLoaded: boolean;
     9  
    10    closePanelDetail(): void;
    11    dispatch(action: DashboardAction): void;
    12  
    13    dataMode: DashboardDataMode;
    14    snapshotId: string | null;
    15  
    16    refetchDashboard: boolean;
    17  
    18    error: any;
    19  
    20    panelsLog: PanelsLog;
    21    panelsMap: PanelsMap;
    22  
    23    execution_id: string | null;
    24  
    25    dashboards: AvailableDashboard[];
    26    dashboardsMap: AvailableDashboardsDictionary;
    27    dashboard: DashboardDefinition | null;
    28  
    29    selectedPanel: PanelDefinition | null;
    30    selectedDashboard: AvailableDashboard | null;
    31    selectedDashboardInputs: DashboardInputs;
    32    lastChangedInput: string | null;
    33  
    34    dashboardTags: DashboardTags;
    35  
    36    search: DashboardSearch;
    37  
    38    breakpointContext: IBreakpointContext;
    39    themeContext: IThemeContext;
    40  
    41    components: ComponentsMap;
    42  
    43    progress: number;
    44    state: DashboardRunState;
    45    render: {
    46      headless: boolean;
    47      snapshotCompleteDiv: boolean;
    48    };
    49  
    50    snapshot: DashboardSnapshot | null;
    51    snapshotFileName: string | null;
    52  };
    53  
    54  export type IBreakpointContext = {
    55    currentBreakpoint: string | null;
    56    maxBreakpoint(breakpointAndDown: string): boolean;
    57    minBreakpoint(breakpointAndUp: string): boolean;
    58    width: number;
    59  };
    60  
    61  export type IThemeContext = {
    62    theme: Theme;
    63    setTheme(theme: string): void;
    64    wrapperRef: Ref<null>;
    65  };
    66  
    67  export const DashboardDataModeLive = "live";
    68  export const DashboardDataModeCLISnapshot = "cli_snapshot";
    69  export const DashboardDataModeCloudSnapshot = "cloud_snapshot";
    70  
    71  export type DashboardDataMode = "live" | "cli_snapshot" | "cloud_snapshot";
    72  
    73  export type SocketURLFactory = () => Promise<string>;
    74  
    75  export type IActions = {
    76    [type: string]: string;
    77  };
    78  
    79  export type ReceivedSocketMessagePayload = {
    80    action: string;
    81    [key: string]: any;
    82  };
    83  
    84  export type ComponentsMap = {
    85    [name: string]: any;
    86  };
    87  
    88  export type PanelLog = {
    89    error?: string | null;
    90    executionTime?: number;
    91    isDependency?: boolean;
    92    prefix?: string;
    93    status: DashboardRunState;
    94    timestamp: string;
    95    title: string;
    96  };
    97  
    98  export type PanelsLog = {
    99    [name: string]: PanelLog[];
   100  };
   101  
   102  export type PanelsMap = {
   103    [name: string]: PanelDefinition;
   104  };
   105  
   106  export type DashboardRunState =
   107    | "initialized"
   108    | "blocked"
   109    | "running"
   110    | "cancelled"
   111    | "error"
   112    | "complete";
   113  
   114  export const DashboardActions: IActions = {
   115    AVAILABLE_DASHBOARDS: "available_dashboards",
   116    CLEAR_DASHBOARD_INPUTS: "clear_dashboard_inputs",
   117    CONTROL_COMPLETE: "control_complete",
   118    CONTROL_ERROR: "control_error",
   119    CONTROLS_UPDATED: "controls_updated",
   120    DASHBOARD_METADATA: "dashboard_metadata",
   121    DELETE_DASHBOARD_INPUT: "delete_dashboard_input",
   122    EXECUTION_COMPLETE: "execution_complete",
   123    EXECUTION_ERROR: "execution_error",
   124    EXECUTION_STARTED: "execution_started",
   125    INPUT_VALUES_CLEARED: "input_values_cleared",
   126    LEAF_NODE_COMPLETE: "leaf_node_complete",
   127    LEAF_NODE_UPDATED: "leaf_node_updated",
   128    LEAF_NODES_COMPLETE: "leaf_nodes_complete",
   129    LEAF_NODES_UPDATED: "leaf_nodes_updated",
   130    SELECT_DASHBOARD: "select_dashboard",
   131    SELECT_PANEL: "select_panel",
   132    SET_DASHBOARD: "set_dashboard",
   133    SET_DASHBOARD_INPUT: "set_dashboard_input",
   134    SET_DASHBOARD_INPUTS: "set_dashboard_inputs",
   135    SET_DASHBOARD_SEARCH_VALUE: "set_dashboard_search_value",
   136    SET_DASHBOARD_SEARCH_GROUP_BY: "set_dashboard_search_group_by",
   137    SET_DASHBOARD_TAG_KEYS: "set_dashboard_tag_keys",
   138    SET_DATA_MODE: "set_data_mode",
   139    SET_REFETCH_DASHBOARD: "set_refetch_dashboard",
   140    WORKSPACE_ERROR: "workspace_error",
   141  };
   142  
   143  type DashboardExecutionEventSchemaVersion =
   144    | "20220614"
   145    | "20220929"
   146    | "20221222";
   147  
   148  type DashboardExecutionStartedEventSchemaVersion = "20220614" | "20221222";
   149  
   150  type DashboardExecutionCompleteEventSchemaVersion =
   151    | "20220614"
   152    | "20220929"
   153    | "20221222";
   154  
   155  type DashboardSnapshotSchemaVersion = "20220614" | "20220929" | "20221222";
   156  
   157  export type DashboardExecutionStartedEvent = {
   158    action: "execution_started";
   159    execution_id: string;
   160    inputs: DashboardInputs;
   161    layout: DashboardLayoutNode;
   162    panels: PanelsMap;
   163    variables: DashboardVariables;
   164    schema_version: DashboardExecutionStartedEventSchemaVersion;
   165    start_time: string;
   166  };
   167  
   168  export type DashboardExecutionEventWithSchema = {
   169    schema_version: DashboardExecutionEventSchemaVersion;
   170    [key: string]: any;
   171  };
   172  
   173  export type DashboardExecutionCompleteEvent = {
   174    action: string;
   175    schema_version: DashboardExecutionCompleteEventSchemaVersion;
   176    execution_id: string;
   177    snapshot: DashboardSnapshot;
   178  };
   179  
   180  // https://github.com/microsoft/TypeScript/issues/28046
   181  export type ElementType<T extends ReadonlyArray<unknown>> =
   182    T extends ReadonlyArray<infer ElementType> ? ElementType : never;
   183  
   184  const dashboardActions = Object.values(DashboardActions);
   185  
   186  export type DashboardActionType = ElementType<typeof dashboardActions>;
   187  
   188  export type DashboardAction = {
   189    type: DashboardActionType;
   190    [key: string]: any;
   191  };
   192  
   193  type DashboardSearchGroupByMode = "mod" | "tag";
   194  
   195  type DashboardSearchGroupBy = {
   196    value: DashboardSearchGroupByMode;
   197    tag: string | null;
   198  };
   199  
   200  export type DashboardSearch = {
   201    value: string;
   202    groupBy: DashboardSearchGroupBy;
   203  };
   204  
   205  export type DashboardTags = {
   206    keys: string[];
   207  };
   208  
   209  export type SelectedDashboardStates = {
   210    dashboard_name: string | undefined;
   211    dataMode: DashboardDataMode;
   212    refetchDashboard: boolean;
   213    search: DashboardSearch;
   214    searchParams: URLSearchParams;
   215    selectedDashboard: AvailableDashboard | null;
   216    selectedDashboardInputs: DashboardInputs;
   217  };
   218  
   219  export type DashboardInputs = {
   220    [name: string]: string;
   221  };
   222  
   223  type DashboardVariables = {
   224    [name: string]: any;
   225  };
   226  
   227  export type ModDashboardMetadata = {
   228    title: string;
   229    full_name: string;
   230    short_name: string;
   231  };
   232  
   233  type InstalledModsDashboardMetadata = {
   234    [key: string]: ModDashboardMetadata;
   235  };
   236  
   237  type CliDashboardMetadata = {
   238    version: string;
   239  };
   240  
   241  export type CloudDashboardActorMetadata = {
   242    id: string;
   243    handle: string;
   244  };
   245  
   246  export type CloudDashboardIdentityMetadata = {
   247    id: string;
   248    handle: string;
   249    type: "org" | "user";
   250  };
   251  
   252  export type CloudDashboardWorkspaceMetadata = {
   253    id: string;
   254    handle: string;
   255  };
   256  
   257  type CloudDashboardMetadata = {
   258    actor: CloudDashboardActorMetadata;
   259    identity: CloudDashboardIdentityMetadata;
   260    workspace: CloudDashboardWorkspaceMetadata;
   261  };
   262  
   263  export type DashboardMetadata = {
   264    mod: ModDashboardMetadata;
   265    installed_mods?: InstalledModsDashboardMetadata;
   266    cli?: CliDashboardMetadata;
   267    cloud?: CloudDashboardMetadata;
   268    telemetry: "info" | "none";
   269  };
   270  
   271  export type DashboardLayoutNode = {
   272    name: string;
   273    panel_type: DashboardPanelType;
   274    children?: DashboardLayoutNode[];
   275  };
   276  
   277  export type DashboardPanelType =
   278    | "benchmark"
   279    | "benchmark_tree"
   280    | "card"
   281    | "chart"
   282    | "container"
   283    | "control"
   284    | "dashboard"
   285    | "edge"
   286    | "error"
   287    | "flow"
   288    | "graph"
   289    | "hierarchy"
   290    | "image"
   291    | "input"
   292    | "node"
   293    | "table"
   294    | "text"
   295    | "with";
   296  
   297  export type DashboardSnapshot = {
   298    schema_version: DashboardSnapshotSchemaVersion;
   299    layout: DashboardLayoutNode;
   300    panels: PanelsMap;
   301    inputs: DashboardInputs;
   302    variables: DashboardVariables;
   303    search_path: string[];
   304    start_time: string;
   305    end_time: string;
   306  };
   307  
   308  type AvailableDashboardTags = {
   309    [key: string]: string;
   310  };
   311  
   312  type AvailableDashboardType = "benchmark" | "dashboard" | "snapshot";
   313  
   314  export type AvailableDashboard = {
   315    full_name: string;
   316    short_name: string;
   317    mod_full_name?: string;
   318    tags: AvailableDashboardTags;
   319    title: string;
   320    is_top_level: boolean;
   321    type: AvailableDashboardType;
   322    children?: AvailableDashboard[];
   323    trunks?: string[][];
   324  };
   325  
   326  export type AvailableDashboardsDictionary = {
   327    [key: string]: AvailableDashboard;
   328  };
   329  
   330  export type ContainerDefinition = {
   331    name: string;
   332    panel_type?: string;
   333    data?: LeafNodeData;
   334    title?: string;
   335    width?: number;
   336    children?: (ContainerDefinition | PanelDefinition)[];
   337  };
   338  
   339  export type PanelProperties = {
   340    [key: string]: any;
   341  };
   342  
   343  export type DependencyPanelProperties = {
   344    name: string;
   345  };
   346  
   347  export type PanelDefinition = {
   348    name: string;
   349    args?: any[];
   350    display?: string;
   351    display_type?: string;
   352    panel_type: DashboardPanelType;
   353    title?: string;
   354    description?: string;
   355    documentation?: string;
   356    width?: Width;
   357    sql?: string;
   358    data?: LeafNodeData;
   359    source_definition?: string;
   360    status?: DashboardRunState;
   361    error?: string;
   362    properties?: PanelProperties;
   363    dashboard: string;
   364    children?: DashboardLayoutNode[];
   365    dependencies?: string[];
   366  };
   367  
   368  export type PanelDependenciesByStatus = {
   369    [status: string]: PanelDefinition[];
   370  };
   371  
   372  export type DashboardDefinition = {
   373    artificial: boolean;
   374    name: string;
   375    panel_type: string;
   376    title?: string;
   377    width?: number;
   378    children?: (ContainerDefinition | PanelDefinition)[];
   379    dashboard: string;
   380  };
   381  
   382  export type DashboardsCollection = {
   383    dashboards: AvailableDashboard[];
   384    dashboardsMap: AvailableDashboardsDictionary;
   385  };
   386  
   387  export type DashboardDataOptions = {
   388    dataMode: DashboardDataMode;
   389    snapshotId?: string;
   390  };
   391  
   392  export type DashboardRenderOptions = {
   393    headless?: boolean;
   394  };