import { Button } from 'antd'; import { ToggleGraphProps } from 'components/Graph/types'; import Spinner from 'components/Spinner'; import TimePreference from 'components/TimePreferenceDropDown'; import GridPanelSwitch from 'container/GridPanelSwitch'; import { timeItems, timePreferance, } from 'container/NewWidget/RightContainer/timeItems'; import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange'; import { useStepInterval } from 'hooks/queryBuilder/useStepInterval'; import { useChartMutable } from 'hooks/useChartMutable'; import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables'; import getChartData from 'lib/getChartData'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useSelector } from 'react-redux'; import { AppState } from 'store/reducers'; import { GlobalReducer } from 'types/reducer/globalTime'; import { toggleGraphsVisibilityInChart } from '../utils'; import { PANEL_TYPES_VS_FULL_VIEW_TABLE } from './contants'; import GraphManager from './GraphManager'; import { GraphContainer, TimeContainer } from './styles'; import { FullViewProps } from './types'; import { getIsGraphLegendToggleAvailable } from './utils'; function FullView({ widget, fullViewOptions = true, onClickHandler, name, yAxisUnit, onDragSelect, isDependedDataLoaded = false, graphsVisibilityStates, onToggleModelHandler, }: FullViewProps): JSX.Element { const { selectedTime: globalSelectedTime } = useSelector< AppState, GlobalReducer >((state) => state.globalTime); const getSelectedTime = useCallback( () => timeItems.find((e) => e.enum === (widget?.timePreferance || 'GLOBAL_TIME')), [widget], ); const canModifyChart = useChartMutable({ panelType: widget.panelTypes, panelTypeAndGraphManagerVisibility: PANEL_TYPES_VS_FULL_VIEW_TABLE, }); const lineChartRef = useRef(); useEffect(() => { if (graphsVisibilityStates && canModifyChart && lineChartRef.current) { toggleGraphsVisibilityInChart({ graphsVisibilityStates, lineChartRef, }); } }, [graphsVisibilityStates, canModifyChart]); const [selectedTime, setSelectedTime] = useState({ name: getSelectedTime()?.name || '', enum: widget?.timePreferance || 'GLOBAL_TIME', }); const queryKey = useMemo( () => `FullViewGetMetricsQueryRange-${selectedTime.enum}-${globalSelectedTime}-${widget.id}`, [selectedTime, globalSelectedTime, widget], ); const updatedQuery = useStepInterval(widget?.query); const response = useGetQueryRange( { selectedTime: selectedTime.enum, graphType: widget.panelTypes, query: updatedQuery, globalSelectedInterval: globalSelectedTime, variables: getDashboardVariables(), }, { queryKey, enabled: !isDependedDataLoaded, }, ); const chartDataSet = useMemo( () => getChartData({ queryData: [ { queryData: response?.data?.payload?.data?.result || [], }, ], }), [response], ); const isGraphLegendToggleAvailable = getIsGraphLegendToggleAvailable( widget.panelTypes, ); if (response.isFetching) { return ; } return ( <> {fullViewOptions && ( )} {canModifyChart && ( )} ); } FullView.defaultProps = { fullViewOptions: undefined, onClickHandler: undefined, yAxisUnit: undefined, onDragSelect: undefined, isDependedDataLoaded: undefined, }; FullView.displayName = 'FullView'; export default FullView;