-
Notifications
You must be signed in to change notification settings - Fork 17
chore: refrigerator as component #2225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e201a83
feat: side panel aka refrigerator for query text in top queries
astandrik 5bec8aa
chore: refrigerator as component
astandrik 2280533
fix: remove related to topQueries
astandrik 106cb33
chore: remove cat
astandrik 0d73536
fix: remove changes
astandrik 1d191a2
fix: some refactoring
astandrik d60f378
fix: review fix
astandrik e2fff80
fix: heights and scrolls
astandrik 3fbf72b
fix: import scss
astandrik 2621fd5
fix: margin-top variable
astandrik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,15 @@ | ||
| .ydb-drawer { | ||
| &__drawer-container { | ||
| position: relative; | ||
|
|
||
| overflow: hidden; | ||
|
|
||
| height: 100%; | ||
| } | ||
|
|
||
| &__item { | ||
| z-index: 4; | ||
|
|
||
| height: 100%; | ||
| } | ||
| } |
This file contains hidden or 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,165 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {DrawerItem, Drawer as GravityDrawer} from '@gravity-ui/navigation'; | ||
|
|
||
| import {cn} from '../../utils/cn'; | ||
| import {isNumeric} from '../../utils/utils'; | ||
|
|
||
| import {useDrawerContext} from './DrawerContext'; | ||
|
|
||
| const DEFAULT_DRAWER_WIDTH_PERCENTS = 60; | ||
| const DEFAULT_DRAWER_WIDTH = 600; | ||
| const DRAWER_WIDTH_KEY = 'drawer-width'; | ||
| const b = cn('ydb-drawer'); | ||
|
|
||
| import './Drawer.scss'; | ||
|
|
||
| interface DrawerPaneContentWrapperProps { | ||
| isVisible: boolean; | ||
| onClose: () => void; | ||
| children: React.ReactNode; | ||
| drawerId?: string; | ||
| storageKey?: string; | ||
| direction?: 'left' | 'right'; | ||
| className?: string; | ||
| detectClickOutside?: boolean; | ||
| defaultWidth?: number; | ||
| isPercentageWidth?: boolean; | ||
| } | ||
|
|
||
| const DrawerPaneContentWrapper = ({ | ||
| isVisible, | ||
| onClose, | ||
| children, | ||
| drawerId = 'drawer', | ||
| storageKey = DRAWER_WIDTH_KEY, | ||
| defaultWidth, | ||
| direction = 'right', | ||
| className, | ||
| detectClickOutside = false, | ||
| isPercentageWidth, | ||
| }: DrawerPaneContentWrapperProps) => { | ||
| const [drawerWidth, setDrawerWidth] = React.useState(() => { | ||
| const savedWidth = localStorage.getItem(storageKey); | ||
| return isNumeric(savedWidth) ? Number(savedWidth) : defaultWidth; | ||
| }); | ||
|
|
||
| const drawerRef = React.useRef<HTMLDivElement>(null); | ||
| const {containerWidth} = useDrawerContext(); | ||
| // Calculate drawer width based on container width percentage if specified | ||
| const calculatedWidth = React.useMemo(() => { | ||
| if (isPercentageWidth && containerWidth > 0) { | ||
| return Math.round( | ||
| (containerWidth * (drawerWidth || DEFAULT_DRAWER_WIDTH_PERCENTS)) / 100, | ||
| ); | ||
| } | ||
| return drawerWidth || DEFAULT_DRAWER_WIDTH; | ||
| }, [containerWidth, isPercentageWidth, drawerWidth]); | ||
|
|
||
| React.useEffect(() => { | ||
| if (!detectClickOutside) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const handleClickOutside = (event: MouseEvent) => { | ||
| if ( | ||
| isVisible && | ||
| drawerRef.current && | ||
| !drawerRef.current.contains(event.target as Node) | ||
| ) { | ||
| onClose(); | ||
| } | ||
| }; | ||
|
|
||
| document.addEventListener('click', handleClickOutside); | ||
| return () => { | ||
| document.removeEventListener('click', handleClickOutside); | ||
| }; | ||
| }, [isVisible, onClose, detectClickOutside]); | ||
|
|
||
| const handleResizeDrawer = (width: number) => { | ||
| if (isPercentageWidth && containerWidth > 0) { | ||
| const percentageWidth = Math.round((width / containerWidth) * 100); | ||
| setDrawerWidth(percentageWidth); | ||
| localStorage.setItem(storageKey, percentageWidth.toString()); | ||
| } else { | ||
| setDrawerWidth(width); | ||
| localStorage.setItem(storageKey, width.toString()); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <GravityDrawer | ||
| onEscape={onClose} | ||
| onVeilClick={onClose} | ||
| hideVeil | ||
| className={b('container', className)} | ||
| > | ||
| <DrawerItem | ||
| id={drawerId} | ||
| visible={isVisible} | ||
| resizable | ||
| maxResizeWidth={containerWidth} | ||
| width={isPercentageWidth ? calculatedWidth : drawerWidth} | ||
| onResize={handleResizeDrawer} | ||
| direction={direction} | ||
| className={b('item')} | ||
| ref={detectClickOutside ? drawerRef : undefined} | ||
| > | ||
| {children} | ||
| </DrawerItem> | ||
| </GravityDrawer> | ||
| ); | ||
| }; | ||
|
|
||
| interface DrawerPaneProps { | ||
| children: React.ReactNode; | ||
| renderDrawerContent: () => React.ReactNode; | ||
| isDrawerVisible: boolean; | ||
| onCloseDrawer: () => void; | ||
| drawerId?: string; | ||
| storageKey?: string; | ||
| defaultWidth?: number; | ||
| direction?: 'left' | 'right'; | ||
| className?: string; | ||
| detectClickOutside?: boolean; | ||
| isPercentageWidth?: boolean; | ||
| } | ||
|
|
||
| export const DrawerWrapper = ({ | ||
| children, | ||
| renderDrawerContent, | ||
| isDrawerVisible, | ||
| onCloseDrawer, | ||
| drawerId, | ||
| storageKey, | ||
| defaultWidth, | ||
| direction, | ||
| className, | ||
| detectClickOutside, | ||
| isPercentageWidth, | ||
| }: DrawerPaneProps) => { | ||
| React.useEffect(() => { | ||
| return () => { | ||
| onCloseDrawer(); | ||
| }; | ||
| }, [onCloseDrawer]); | ||
| return ( | ||
| <React.Fragment> | ||
| {children} | ||
| <DrawerPaneContentWrapper | ||
| isVisible={isDrawerVisible} | ||
| onClose={onCloseDrawer} | ||
| drawerId={drawerId} | ||
| storageKey={storageKey} | ||
| defaultWidth={defaultWidth} | ||
| direction={direction} | ||
| className={className} | ||
| detectClickOutside={detectClickOutside} | ||
| isPercentageWidth={isPercentageWidth} | ||
| > | ||
| {renderDrawerContent()} | ||
| </DrawerPaneContentWrapper> | ||
| </React.Fragment> | ||
| ); | ||
| }; |
This file contains hidden or 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,79 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {cn} from '../../utils/cn'; | ||
|
|
||
| import './Drawer.scss'; | ||
|
|
||
| const b = cn('ydb-drawer'); | ||
|
|
||
| export interface DrawerContextType { | ||
| containerWidth: number; | ||
| setContainerWidth: React.Dispatch<React.SetStateAction<number>>; | ||
| } | ||
|
|
||
| const DrawerContext = React.createContext<DrawerContextType>({ | ||
| containerWidth: 0, | ||
| setContainerWidth: () => {}, | ||
| }); | ||
|
|
||
| interface DrawerContextProviderProps { | ||
| children: React.ReactNode; | ||
| className?: string; | ||
| } | ||
|
|
||
| export const DrawerContextProvider = ({children, className}: DrawerContextProviderProps) => { | ||
| const [containerWidth, setContainerWidth] = React.useState(0); | ||
| const containerRef = React.useRef<HTMLDivElement>(null); | ||
|
|
||
| React.useEffect(() => { | ||
| if (!containerRef.current) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const updateWidth = () => { | ||
| if (containerRef.current) { | ||
| setContainerWidth(containerRef.current.clientWidth); | ||
| } | ||
| }; | ||
|
|
||
| // Set initial width | ||
| updateWidth(); | ||
|
|
||
| // Update width on resize | ||
| const resizeObserver = new ResizeObserver(updateWidth); | ||
| resizeObserver.observe(containerRef.current); | ||
|
|
||
| return () => { | ||
| if (containerRef.current) { | ||
|
Check warning on line 47 in src/components/Drawer/DrawerContext.tsx
|
||
| resizeObserver.disconnect(); | ||
| } | ||
| }; | ||
| }, []); | ||
|
|
||
| // Memoize the context value to prevent unnecessary re-renders | ||
| const value = React.useMemo( | ||
| () => ({ | ||
| containerWidth, | ||
| setContainerWidth, | ||
| }), | ||
| [containerWidth], | ||
| ); | ||
|
|
||
| return ( | ||
| <DrawerContext.Provider value={value}> | ||
| <div ref={containerRef} className={b('drawer-container', className)}> | ||
| {children} | ||
| </div> | ||
| </DrawerContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const useDrawerContext = (): DrawerContextType => { | ||
| const context = React.useContext(DrawerContext); | ||
|
|
||
| if (context === undefined) { | ||
| throw Error('useDrawerContext must be used within a DrawerContextProvider'); | ||
| } | ||
|
|
||
| return context; | ||
| }; | ||
This file contains hidden or 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,3 @@ | ||
| export {DrawerWrapper} from './Drawer'; | ||
| export {useDrawerContext} from './DrawerContext'; | ||
| export type {DrawerContextType} from './DrawerContext'; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let move it to variable like
--diagnostics-margin-top: var(--g-spacing-4)