2023-08-02 20:41:09 +05:30
|
|
|
import { ToggleGraphProps } from 'components/Graph/types';
|
2024-02-20 16:21:07 +05:30
|
|
|
import { getComponentForPanelType } from 'constants/panelTypes';
|
2023-07-25 16:25:36 +03:00
|
|
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
|
|
|
|
import { GRID_TABLE_CONFIG } from 'container/GridTableComponent/config';
|
2023-08-02 20:41:09 +05:30
|
|
|
import { FC, forwardRef, memo, useMemo } from 'react';
|
2023-07-25 16:25:36 +03:00
|
|
|
|
|
|
|
|
import { GridPanelSwitchProps, PropsTypePropsMap } from './types';
|
|
|
|
|
|
2023-08-02 20:41:09 +05:30
|
|
|
const GridPanelSwitch = forwardRef<
|
|
|
|
|
ToggleGraphProps | undefined,
|
|
|
|
|
GridPanelSwitchProps
|
|
|
|
|
>(
|
|
|
|
|
(
|
2024-02-20 16:21:07 +05:30
|
|
|
{
|
|
|
|
|
panelType,
|
|
|
|
|
data,
|
|
|
|
|
yAxisUnit,
|
|
|
|
|
panelData,
|
|
|
|
|
query,
|
|
|
|
|
options,
|
|
|
|
|
thresholds,
|
|
|
|
|
dataSource,
|
|
|
|
|
},
|
2023-08-02 20:41:09 +05:30
|
|
|
ref,
|
|
|
|
|
): JSX.Element | null => {
|
|
|
|
|
const currentProps: PropsTypePropsMap = useMemo(() => {
|
|
|
|
|
const result: PropsTypePropsMap = {
|
|
|
|
|
[PANEL_TYPES.TIME_SERIES]: {
|
|
|
|
|
data,
|
2023-11-15 15:33:45 +05:30
|
|
|
options,
|
2023-08-02 20:41:09 +05:30
|
|
|
ref,
|
|
|
|
|
},
|
|
|
|
|
[PANEL_TYPES.VALUE]: {
|
|
|
|
|
data,
|
|
|
|
|
yAxisUnit,
|
2023-11-15 17:14:09 +05:30
|
|
|
thresholds,
|
2023-08-02 20:41:09 +05:30
|
|
|
},
|
2023-11-23 15:32:06 +05:30
|
|
|
[PANEL_TYPES.TABLE]: {
|
|
|
|
|
...GRID_TABLE_CONFIG,
|
|
|
|
|
data: panelData,
|
|
|
|
|
query,
|
|
|
|
|
thresholds,
|
|
|
|
|
},
|
2024-04-02 16:40:41 +05:30
|
|
|
[PANEL_TYPES.LIST]: null,
|
2023-08-02 20:41:09 +05:30
|
|
|
[PANEL_TYPES.TRACE]: null,
|
2024-02-28 14:56:50 +05:30
|
|
|
[PANEL_TYPES.BAR]: {
|
|
|
|
|
data,
|
|
|
|
|
options,
|
|
|
|
|
ref,
|
|
|
|
|
},
|
2023-08-02 20:41:09 +05:30
|
|
|
[PANEL_TYPES.EMPTY_WIDGET]: null,
|
|
|
|
|
};
|
2023-07-25 16:25:36 +03:00
|
|
|
|
2023-08-02 20:41:09 +05:30
|
|
|
return result;
|
2024-04-02 16:40:41 +05:30
|
|
|
}, [data, options, ref, yAxisUnit, thresholds, panelData, query]);
|
2023-07-25 16:25:36 +03:00
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
const Component = getComponentForPanelType(panelType, dataSource) as FC<
|
2023-08-02 20:41:09 +05:30
|
|
|
PropsTypePropsMap[typeof panelType]
|
|
|
|
|
>;
|
|
|
|
|
const componentProps = useMemo(() => currentProps[panelType], [
|
|
|
|
|
panelType,
|
|
|
|
|
currentProps,
|
|
|
|
|
]);
|
2023-07-25 16:25:36 +03:00
|
|
|
|
2023-08-02 20:41:09 +05:30
|
|
|
if (!Component || !componentProps) return null;
|
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
|
return <Component {...componentProps} />;
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-07-25 16:25:36 +03:00
|
|
|
|
2023-08-02 20:41:09 +05:30
|
|
|
GridPanelSwitch.displayName = 'GridPanelSwitch';
|
2023-07-25 16:25:36 +03:00
|
|
|
|
|
|
|
|
export default memo(GridPanelSwitch);
|