fix: avoid double API call on the adding new panel type (#3246)

This commit is contained in:
dnazarenkoo 2023-08-02 08:22:33 +03:00 committed by GitHub
parent 54738432af
commit fafa6f9960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -62,6 +62,10 @@ function GridCardGraph({
allowEdit,
isQueryEnabled,
}: GridCardGraphProps): JSX.Element {
const { isAddWidget } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards,
);
const { ref: graphRef, inView: isGraphVisible } = useInView({
threshold: 0,
triggerOnce: true,
@ -116,7 +120,7 @@ function GridCardGraph({
variables,
],
keepPreviousData: true,
enabled: isGraphVisible && !isEmptyWidget && isQueryEnabled,
enabled: isGraphVisible && !isEmptyWidget && isQueryEnabled && !isAddWidget,
refetchOnMount: false,
onError: (error) => {
setErrorMessage(error.message);

View File

@ -8,6 +8,7 @@ import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import { Widgets } from 'types/api/dashboard/getAll';
import AppReducer from 'types/reducer/app';
import DashboardReducer from 'types/reducer/dashboards';
import { LayoutProps, State } from '.';
import {
@ -28,6 +29,9 @@ function GraphLayout({
widgets,
setLayout,
}: GraphLayoutProps): JSX.Element {
const { isAddWidget } = useSelector<AppState, DashboardReducer>(
(state) => state.dashboards,
);
const { role } = useSelector<AppState, AppReducer>((state) => state.app);
const isDarkMode = useIsDarkMode();
@ -53,7 +57,7 @@ function GraphLayout({
{addPanelPermission && (
<Button
loading={addPanelLoading}
disabled={addPanelLoading}
disabled={addPanelLoading || isAddWidget}
onClick={onAddPanelHandler}
icon={<PlusOutlined />}
>