github.com/minio/console@v1.4.1/web-app/src/screens/Console/Dashboard/Prometheus/Widgets/MergedWidgetsRenderer.tsx (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2021 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  import React from "react";
    18  import { componentToUse } from "../widgetUtils";
    19  import { IDashboardPanel } from "../types";
    20  import MergedWidgets from "../MergedWidgets";
    21  import EntityStateItemRenderer from "./EntityStateItemRenderer";
    22  import NetworkItem from "./NetworkItem";
    23  import DashboardItemBox from "../../DashboardItemBox";
    24  
    25  const MergedWidgetsRenderer = ({
    26    info,
    27    timeStart,
    28    timeEnd,
    29    loading,
    30    apiPrefix,
    31  }: {
    32    info: IDashboardPanel;
    33    timeStart: any;
    34    timeEnd: any;
    35    loading: boolean;
    36    apiPrefix: string;
    37  }) => {
    38    const { mergedPanels = [], title = "", id } = info;
    39    const [leftPanel, rightPanel] = mergedPanels;
    40  
    41    const renderById = () => {
    42      if ([500, 501].includes(id)) {
    43        return (
    44          <DashboardItemBox>
    45            <EntityStateItemRenderer
    46              info={info}
    47              timeStart={timeStart}
    48              timeEnd={timeEnd}
    49              apiPrefix={apiPrefix}
    50            />
    51          </DashboardItemBox>
    52        );
    53      }
    54  
    55      if (id === 502) {
    56        return (
    57          <DashboardItemBox>
    58            <NetworkItem
    59              apiPrefix={apiPrefix}
    60              timeEnd={timeEnd}
    61              timeStart={timeStart}
    62              value={info}
    63            />
    64          </DashboardItemBox>
    65        );
    66      }
    67  
    68      return (
    69        <MergedWidgets
    70          title={title}
    71          leftComponent={componentToUse(
    72            leftPanel,
    73            timeStart,
    74            timeEnd,
    75            loading,
    76            apiPrefix,
    77          )}
    78          rightComponent={componentToUse(
    79            rightPanel,
    80            timeStart,
    81            timeEnd,
    82            loading,
    83            apiPrefix,
    84          )}
    85        />
    86      );
    87    };
    88  
    89    return renderById();
    90  };
    91  
    92  export default MergedWidgetsRenderer;