2023-11-15 15:33:45 +05:30
|
|
|
import './WidgetFullView.styles.scss';
|
|
|
|
|
|
2024-09-20 16:36:35 +05:30
|
|
|
import {
|
|
|
|
|
LoadingOutlined,
|
|
|
|
|
SearchOutlined,
|
|
|
|
|
SyncOutlined,
|
|
|
|
|
} from '@ant-design/icons';
|
|
|
|
|
import { Button, Input, Spin } from 'antd';
|
2024-02-20 16:21:07 +05:30
|
|
|
import cx from 'classnames';
|
2023-08-02 20:41:09 +05:30
|
|
|
import { ToggleGraphProps } from 'components/Graph/types';
|
2021-09-23 15:43:43 +05:30
|
|
|
import Spinner from 'components/Spinner';
|
|
|
|
|
import TimePreference from 'components/TimePreferenceDropDown';
|
2024-03-01 14:51:50 +05:30
|
|
|
import { DEFAULT_ENTITY_VERSION } from 'constants/app';
|
2024-04-02 16:40:41 +05:30
|
|
|
import { QueryParams } from 'constants/query';
|
2024-02-20 16:21:07 +05:30
|
|
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
2021-09-23 15:43:43 +05:30
|
|
|
import {
|
|
|
|
|
timeItems,
|
|
|
|
|
timePreferance,
|
|
|
|
|
} from 'container/NewWidget/RightContainer/timeItems';
|
2024-04-02 16:40:41 +05:30
|
|
|
import PanelWrapper from 'container/PanelWrapper/PanelWrapper';
|
2023-07-18 08:55:01 +05:30
|
|
|
import { useGetQueryRange } from 'hooks/queryBuilder/useGetQueryRange';
|
2023-08-02 20:41:09 +05:30
|
|
|
import { useChartMutable } from 'hooks/useChartMutable';
|
2025-02-14 08:24:49 +04:30
|
|
|
import { useSafeNavigate } from 'hooks/useSafeNavigate';
|
2024-04-02 16:40:41 +05:30
|
|
|
import useUrlQuery from 'hooks/useUrlQuery';
|
2023-07-18 08:55:01 +05:30
|
|
|
import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables';
|
2024-04-02 16:40:41 +05:30
|
|
|
import { GetQueryResultsProps } from 'lib/dashboard/getQueryResults';
|
|
|
|
|
import GetMinMax from 'lib/getMinMax';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { useDashboard } from 'providers/Dashboard/Dashboard';
|
2024-03-08 14:11:38 +05:30
|
|
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
2024-04-02 16:40:41 +05:30
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
|
import { useLocation } from 'react-router-dom';
|
|
|
|
|
import { UpdateTimeInterval } from 'store/actions';
|
2021-09-23 15:43:43 +05:30
|
|
|
import { AppState } from 'store/reducers';
|
2022-01-26 21:46:59 +05:30
|
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
2024-04-02 16:40:41 +05:30
|
|
|
import { getGraphType } from 'utils/getGraphType';
|
2024-02-28 14:56:50 +05:30
|
|
|
import { getSortedSeriesData } from 'utils/getSortedSeriesData';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2024-03-08 14:11:38 +05:30
|
|
|
import { getLocalStorageGraphVisibilityState } from '../utils';
|
2023-08-02 20:41:09 +05:30
|
|
|
import { PANEL_TYPES_VS_FULL_VIEW_TABLE } from './contants';
|
|
|
|
|
import { GraphContainer, TimeContainer } from './styles';
|
|
|
|
|
import { FullViewProps } from './types';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
function FullView({
|
2021-10-20 09:24:55 +05:30
|
|
|
widget,
|
|
|
|
|
fullViewOptions = true,
|
2024-03-04 10:15:43 +05:30
|
|
|
version,
|
2024-01-22 16:36:03 +05:30
|
|
|
originalName,
|
2024-05-24 15:54:36 +05:30
|
|
|
tableProcessedDataRef,
|
2023-07-18 08:55:01 +05:30
|
|
|
isDependedDataLoaded = false,
|
2023-08-02 20:41:09 +05:30
|
|
|
onToggleModelHandler,
|
2022-03-22 12:10:31 +05:30
|
|
|
}: FullViewProps): JSX.Element {
|
2025-02-14 08:24:49 +04:30
|
|
|
const { safeNavigate } = useSafeNavigate();
|
2023-07-18 08:55:01 +05:30
|
|
|
const { selectedTime: globalSelectedTime } = useSelector<
|
2022-01-26 21:46:59 +05:30
|
|
|
AppState,
|
|
|
|
|
GlobalReducer
|
|
|
|
|
>((state) => state.globalTime);
|
2024-04-02 16:40:41 +05:30
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const urlQuery = useUrlQuery();
|
|
|
|
|
const location = useLocation();
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2023-11-15 15:33:45 +05:30
|
|
|
const fullViewRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
2023-11-29 00:02:51 +05:30
|
|
|
const { selectedDashboard, isDashboardLocked } = useDashboard();
|
2023-10-08 23:21:17 +05:30
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
const getSelectedTime = useCallback(
|
|
|
|
|
() =>
|
|
|
|
|
timeItems.find((e) => e.enum === (widget?.timePreferance || 'GLOBAL_TIME')),
|
|
|
|
|
[widget],
|
|
|
|
|
);
|
|
|
|
|
|
2023-11-15 15:33:45 +05:30
|
|
|
const fullViewChartRef = useRef<ToggleGraphProps>();
|
2023-08-02 20:41:09 +05:30
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
const [selectedTime, setSelectedTime] = useState<timePreferance>({
|
|
|
|
|
name: getSelectedTime()?.name || '',
|
|
|
|
|
enum: widget?.timePreferance || 'GLOBAL_TIME',
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-12 17:38:05 +05:30
|
|
|
const updatedQuery = widget?.query;
|
2023-07-18 08:55:01 +05:30
|
|
|
|
2024-04-02 16:40:41 +05:30
|
|
|
const [requestData, setRequestData] = useState<GetQueryResultsProps>(() => {
|
|
|
|
|
if (widget.panelTypes !== PANEL_TYPES.LIST) {
|
|
|
|
|
return {
|
|
|
|
|
selectedTime: selectedTime.enum,
|
|
|
|
|
graphType: getGraphType(widget.panelTypes),
|
|
|
|
|
query: updatedQuery,
|
|
|
|
|
globalSelectedInterval: globalSelectedTime,
|
|
|
|
|
variables: getDashboardVariables(selectedDashboard?.data.variables),
|
2024-06-27 22:04:14 +05:30
|
|
|
fillGaps: widget.fillSpans,
|
2024-06-28 12:10:57 +05:30
|
|
|
formatForWeb: widget.panelTypes === PANEL_TYPES.TABLE,
|
2024-04-02 16:40:41 +05:30
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
updatedQuery.builder.queryData[0].pageSize = 10;
|
|
|
|
|
return {
|
2023-07-18 08:55:01 +05:30
|
|
|
query: updatedQuery,
|
2024-04-02 16:40:41 +05:30
|
|
|
graphType: PANEL_TYPES.LIST,
|
2024-04-09 11:05:49 +05:30
|
|
|
selectedTime: widget?.timePreferance || 'GLOBAL_TIME',
|
2023-07-18 08:55:01 +05:30
|
|
|
globalSelectedInterval: globalSelectedTime,
|
2025-03-19 11:58:20 +05:30
|
|
|
variables: getDashboardVariables(selectedDashboard?.data.variables),
|
2024-04-02 16:40:41 +05:30
|
|
|
tableParams: {
|
|
|
|
|
pagination: {
|
|
|
|
|
offset: 0,
|
|
|
|
|
limit: updatedQuery.builder.queryData[0].limit || 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setRequestData((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
selectedTime: selectedTime.enum,
|
|
|
|
|
}));
|
|
|
|
|
}, [selectedTime]);
|
|
|
|
|
|
|
|
|
|
const response = useGetQueryRange(
|
|
|
|
|
requestData,
|
2024-03-04 10:15:43 +05:30
|
|
|
selectedDashboard?.data?.version || version || DEFAULT_ENTITY_VERSION,
|
2023-07-18 08:55:01 +05:30
|
|
|
{
|
2024-04-02 16:40:41 +05:30
|
|
|
queryKey: [widget?.query, widget?.panelTypes, requestData, version],
|
|
|
|
|
enabled: !isDependedDataLoaded,
|
|
|
|
|
keepPreviousData: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onDragSelect = useCallback(
|
|
|
|
|
(start: number, end: number): void => {
|
|
|
|
|
const startTimestamp = Math.trunc(start);
|
|
|
|
|
const endTimestamp = Math.trunc(end);
|
|
|
|
|
|
|
|
|
|
if (startTimestamp !== endTimestamp) {
|
|
|
|
|
dispatch(UpdateTimeInterval('custom', [startTimestamp, endTimestamp]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { maxTime, minTime } = GetMinMax('custom', [
|
|
|
|
|
startTimestamp,
|
|
|
|
|
endTimestamp,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
urlQuery.set(QueryParams.startTime, minTime.toString());
|
|
|
|
|
urlQuery.set(QueryParams.endTime, maxTime.toString());
|
|
|
|
|
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
|
2025-02-14 08:24:49 +04:30
|
|
|
safeNavigate(generatedUrl);
|
2023-07-18 08:55:01 +05:30
|
|
|
},
|
2025-02-14 08:24:49 +04:30
|
|
|
[dispatch, location.pathname, safeNavigate, urlQuery],
|
2022-05-19 23:08:27 +05:30
|
|
|
);
|
|
|
|
|
|
2024-03-08 14:11:38 +05:30
|
|
|
const [graphsVisibilityStates, setGraphsVisibilityStates] = useState<
|
|
|
|
|
boolean[]
|
2024-09-18 18:02:17 +05:30
|
|
|
>(Array(response.data?.payload?.data?.result?.length).fill(true));
|
2024-03-08 14:11:38 +05:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const {
|
|
|
|
|
graphVisibilityStates: localStoredVisibilityState,
|
|
|
|
|
} = getLocalStorageGraphVisibilityState({
|
|
|
|
|
apiResponse: response.data?.payload.data.result || [],
|
|
|
|
|
name: originalName,
|
|
|
|
|
});
|
|
|
|
|
setGraphsVisibilityStates(localStoredVisibilityState);
|
|
|
|
|
}, [originalName, response.data?.payload.data.result]);
|
|
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
const canModifyChart = useChartMutable({
|
|
|
|
|
panelType: widget.panelTypes,
|
|
|
|
|
panelTypeAndGraphManagerVisibility: PANEL_TYPES_VS_FULL_VIEW_TABLE,
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-28 14:56:50 +05:30
|
|
|
if (response.data && widget.panelTypes === PANEL_TYPES.BAR) {
|
|
|
|
|
const sortedSeriesData = getSortedSeriesData(
|
|
|
|
|
response.data?.payload.data.result,
|
|
|
|
|
);
|
|
|
|
|
response.data.payload.data.result = sortedSeriesData;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 15:33:45 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
graphsVisibilityStates?.forEach((e, i) => {
|
|
|
|
|
fullViewChartRef?.current?.toggleGraph(i, e);
|
|
|
|
|
});
|
2024-03-08 14:11:38 +05:30
|
|
|
}, [graphsVisibilityStates]);
|
2023-08-02 20:41:09 +05:30
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
const isListView = widget.panelTypes === PANEL_TYPES.LIST;
|
|
|
|
|
|
2024-09-20 16:36:35 +05:30
|
|
|
const isTablePanel = widget.panelTypes === PANEL_TYPES.TABLE;
|
|
|
|
|
|
|
|
|
|
const [searchTerm, setSearchTerm] = useState<string>('');
|
|
|
|
|
|
2024-04-02 16:40:41 +05:30
|
|
|
if (response.isLoading && widget.panelTypes !== PANEL_TYPES.LIST) {
|
2022-05-19 23:08:27 +05:30
|
|
|
return <Spinner height="100%" size="large" tip="Loading..." />;
|
2021-10-20 09:24:55 +05:30
|
|
|
}
|
|
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
return (
|
2023-11-15 15:33:45 +05:30
|
|
|
<div className="full-view-container">
|
|
|
|
|
<div className="full-view-header-container">
|
|
|
|
|
{fullViewOptions && (
|
|
|
|
|
<TimeContainer $panelType={widget.panelTypes}>
|
2024-04-02 16:40:41 +05:30
|
|
|
{response.isFetching && (
|
|
|
|
|
<Spin spinning indicator={<LoadingOutlined spin />} />
|
|
|
|
|
)}
|
2023-11-15 15:33:45 +05:30
|
|
|
<TimePreference
|
|
|
|
|
selectedTime={selectedTime}
|
|
|
|
|
setSelectedTime={setSelectedTime}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
style={{
|
|
|
|
|
marginLeft: '4px',
|
|
|
|
|
}}
|
|
|
|
|
onClick={(): void => {
|
|
|
|
|
response.refetch();
|
|
|
|
|
}}
|
|
|
|
|
type="primary"
|
|
|
|
|
icon={<SyncOutlined />}
|
|
|
|
|
/>
|
|
|
|
|
</TimeContainer>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2023-11-29 00:02:51 +05:30
|
|
|
<div
|
2024-02-20 16:21:07 +05:30
|
|
|
className={cx('graph-container', {
|
|
|
|
|
disabled: isDashboardLocked,
|
2024-06-10 17:15:30 +05:30
|
|
|
'height-widget': widget?.mergeAllActiveQueries || widget?.stackedBarChart,
|
2024-02-20 16:21:07 +05:30
|
|
|
'list-graph-container': isListView,
|
|
|
|
|
})}
|
2023-11-29 00:02:51 +05:30
|
|
|
ref={fullViewRef}
|
|
|
|
|
>
|
2024-04-02 16:40:41 +05:30
|
|
|
<GraphContainer
|
|
|
|
|
style={{
|
|
|
|
|
height: isListView ? '100%' : '90%',
|
|
|
|
|
}}
|
|
|
|
|
isGraphLegendToggleAvailable={canModifyChart}
|
|
|
|
|
>
|
2024-09-20 16:36:35 +05:30
|
|
|
{isTablePanel && (
|
|
|
|
|
<Input
|
|
|
|
|
addonBefore={<SearchOutlined size={14} />}
|
|
|
|
|
className="global-search"
|
|
|
|
|
placeholder="Search..."
|
|
|
|
|
allowClear
|
|
|
|
|
key={widget.id}
|
|
|
|
|
onChange={(e): void => {
|
|
|
|
|
setSearchTerm(e.target.value || '');
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-04-02 16:40:41 +05:30
|
|
|
<PanelWrapper
|
|
|
|
|
queryResponse={response}
|
|
|
|
|
widget={widget}
|
|
|
|
|
setRequestData={setRequestData}
|
|
|
|
|
isFullViewMode
|
|
|
|
|
onToggleModelHandler={onToggleModelHandler}
|
|
|
|
|
setGraphVisibility={setGraphsVisibilityStates}
|
|
|
|
|
graphVisibility={graphsVisibilityStates}
|
|
|
|
|
onDragSelect={onDragSelect}
|
2024-05-24 15:54:36 +05:30
|
|
|
tableProcessedDataRef={tableProcessedDataRef}
|
2024-09-20 16:36:35 +05:30
|
|
|
searchTerm={searchTerm}
|
2024-04-02 16:40:41 +05:30
|
|
|
/>
|
|
|
|
|
</GraphContainer>
|
2023-11-15 15:33:45 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-09-23 15:43:43 +05:30
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2022-03-24 12:06:57 +05:30
|
|
|
FullView.defaultProps = {
|
|
|
|
|
fullViewOptions: undefined,
|
|
|
|
|
onClickHandler: undefined,
|
|
|
|
|
yAxisUnit: undefined,
|
2023-01-17 13:30:34 +02:00
|
|
|
onDragSelect: undefined,
|
2023-07-18 08:55:01 +05:30
|
|
|
isDependedDataLoaded: undefined,
|
2022-03-24 12:06:57 +05:30
|
|
|
};
|
|
|
|
|
|
2023-08-02 20:41:09 +05:30
|
|
|
FullView.displayName = 'FullView';
|
|
|
|
|
|
2021-11-16 21:13:20 +05:30
|
|
|
export default FullView;
|