diff --git a/public/app/features/explore/ExplorePage.tsx b/public/app/features/explore/ExplorePage.tsx index bf0b0920c31..d55a300b348 100644 --- a/public/app/features/explore/ExplorePage.tsx +++ b/public/app/features/explore/ExplorePage.tsx @@ -1,24 +1,24 @@ import { css } from '@emotion/css'; -import { inRange } from 'lodash'; -import React, { useEffect, useState } from 'react'; -import { useWindowSize } from 'react-use'; +import React, { useEffect } from 'react'; import { ErrorBoundaryAlert } from '@grafana/ui'; import { SplitPaneWrapper } from 'app/core/components/SplitPaneWrapper/SplitPaneWrapper'; import { useGrafana } from 'app/core/context/GrafanaContext'; import { useNavModel } from 'app/core/hooks/useNavModel'; import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; -import { useDispatch, useSelector } from 'app/types'; +import { useSelector } from 'app/types'; import { ExploreQueryParams } from 'app/types/explore'; import { ExploreActions } from './ExploreActions'; import { ExplorePaneContainer } from './ExplorePaneContainer'; import { useExplorePageTitle } from './hooks/useExplorePageTitle'; +import { useSplitSizeUpdater } from './hooks/useSplitSizeUpdater'; import { useStateSync } from './hooks/useStateSync'; import { useTimeSrvFix } from './hooks/useTimeSrvFix'; -import { splitSizeUpdateAction } from './state/main'; import { isSplit, selectPanesEntries } from './state/selectors'; +const MIN_PANE_WIDTH = 200; + const styles = { pageScrollbarWrapper: css` width: 100%; @@ -38,13 +38,9 @@ export default function ExplorePage(props: GrafanaRouteComponentProps<{}, Explor // if we were to update the URL on state change, the title would not match the URL. // Ultimately the URL is the single source of truth from which state is derived, the page title is not different useExplorePageTitle(props.queryParams); - const dispatch = useDispatch(); const { keybindings, chrome } = useGrafana(); const navModel = useNavModel('explore'); - const [rightPaneWidthRatio, setRightPaneWidthRatio] = useState(0.5); - const { width: windowWidth } = useWindowSize(); - const minWidth = 200; - const exploreState = useSelector((state) => state.explore); + const { updateSplitSize, widthCalc } = useSplitSizeUpdater(MIN_PANE_WIDTH); const panes = useSelector(selectPanesEntries); const hasSplit = useSelector(isSplit); @@ -59,33 +55,6 @@ export default function ExplorePage(props: GrafanaRouteComponentProps<{}, Explor keybindings.setupTimeRangeBindings(false); }, [keybindings]); - const updateSplitSize = (size: number) => { - const evenSplitWidth = windowWidth / 2; - const areBothSimilar = inRange(size, evenSplitWidth - 100, evenSplitWidth + 100); - if (areBothSimilar) { - dispatch(splitSizeUpdateAction({ largerExploreId: undefined })); - } else { - dispatch( - splitSizeUpdateAction({ - largerExploreId: size > evenSplitWidth ? panes[1][0] : panes[0][0], - }) - ); - } - - setRightPaneWidthRatio(size / windowWidth); - }; - - let widthCalc = 0; - if (hasSplit) { - if (!exploreState.evenSplitPanes && exploreState.maxedExploreId) { - widthCalc = exploreState.maxedExploreId === panes[1][0] ? windowWidth - minWidth : minWidth; - } else if (exploreState.evenSplitPanes) { - widthCalc = Math.floor(windowWidth / 2); - } else if (rightPaneWidthRatio !== undefined) { - widthCalc = windowWidth * rightPaneWidthRatio; - } - } - return (