-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract useQueryWidgetSidePanel
- Loading branch information
1 parent
648370a
commit fc77a27
Showing
2 changed files
with
47 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/ui/src/ui/pages/query-tracker/QueryWidget/side-panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import {useDispatch} from 'react-redux'; | ||
|
||
import withSplit from '../../../hocs/withSplit'; | ||
import withLazyLoading from '../../../hocs/withLazyLoading'; | ||
import type {QueryWidgetProps} from './index'; | ||
import {mergeScreen, splitScreen} from '../../../store/actions/global'; | ||
import {SPLIT_TYPE} from '../../../constants/components/nodes/nodes'; | ||
import Loader from '../../../components/Loader/Loader'; | ||
|
||
export const QueryWidgetLazy = React.lazy(() => import('./index')); | ||
|
||
export const QueryWidgetPortal = withSplit( | ||
withLazyLoading<QueryWidgetProps>(QueryWidgetLazy, <Loader />), | ||
); | ||
|
||
export function useQueryWidgetSidePanel() { | ||
const [widgetOpened, setWidgetOpened] = React.useState(false); | ||
const dispatch = useDispatch(); | ||
|
||
const openWidget = React.useCallback(() => { | ||
dispatch(splitScreen(SPLIT_TYPE)); | ||
setWidgetOpened(true); | ||
}, [setWidgetOpened, dispatch]); | ||
|
||
const onClose = React.useCallback(() => { | ||
setWidgetOpened(false); | ||
dispatch(mergeScreen()); | ||
}, [setWidgetOpened, dispatch]); | ||
|
||
return { | ||
closeWidget: onClose, | ||
openWidget, | ||
widgetOpened, | ||
widgetContent: widgetOpened ? <QueryWidgetPortal onClose={onClose} /> : null, | ||
}; | ||
} |