Skip to content

Commit

Permalink
fix: Panels size (#1017)
Browse files Browse the repository at this point in the history
* chore: Upgrade react-resizable-panels package

* fix: Min panel size

* fix: Min size for Assets Panel
  • Loading branch information
cyaiox authored Oct 10, 2024
1 parent be05f6f commit 0c4dc9b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
9 changes: 5 additions & 4 deletions packages/@dcl/inspector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@dcl/inspector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"react-icons": "^4.7.1",
"react-modal": "^3.16.1",
"react-redux": "^8.1.0",
"react-resizable-panels": "^0.0.48",
"react-resizable-panels": "^2.1.4",
"redux-saga": "^1.2.3",
"redux-saga-test-plan": "^4.0.6",
"ts-node": "^10.9.1",
Expand Down
42 changes: 29 additions & 13 deletions packages/@dcl/inspector/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import React from 'react'
import React, { useCallback, useState } from 'react'
import { PanelGroup, Panel, PanelResizeHandle } from 'react-resizable-panels'
import cx from 'classnames'

import { EntityInspector } from '../EntityInspector'
import { Hierarchy } from '../Hierarchy'
import { Renderer } from '../Renderer'
import { Box } from '../Box'
import { Toolbar } from '../Toolbar'

import './App.css'
import Assets from '../Assets'
import { useSelectedEntity } from '../../hooks/sdk/useSelectedEntity'
import { useWindowSize } from '../../hooks/useWindowSize'
import { useAppSelector } from '../../redux/hooks'
Expand All @@ -18,6 +10,15 @@ import { selectEngines } from '../../redux/sdk'
import { getHiddenPanels } from '../../redux/ui'
import { PanelName } from '../../redux/ui/types'

import { EntityInspector } from '../EntityInspector'
import { Hierarchy } from '../Hierarchy'
import { Renderer } from '../Renderer'
import { Box } from '../Box'
import { Toolbar } from '../Toolbar'
import Assets from '../Assets'

import './App.css'

const App = () => {
const selectedEntity = useSelectedEntity()
const { height } = useWindowSize()
Expand All @@ -26,16 +27,25 @@ const App = () => {

const hiddenPanels = useAppSelector(getHiddenPanels)

const [isAssetsPanelCollapsed, setIsAssetsPanelCollapsed] = useState(false)

const handleToggleAssetsPanel = useCallback((collapse: boolean) => {
setIsAssetsPanelCollapsed(collapse)
}, [])

// Collapse the panel at 75 pixels
const collapseAt = (75 / Math.max(1, height ?? 1)) * 100
// Footer's height is 48 pixels, so we need to calculate the percentage of the screen that it takes to pass as the minSize prop for the Panel
const footerMin = (48 / height!) * 100
const footerMin = (48 / Math.max(1, height ?? 1)) * 100

const disconnected = useAppSelector(selectDataLayerError)
return (
<div
className={cx('App', { 'is-ready': !!sdkInitialized })}
style={{ pointerEvents: disconnected ? 'none' : 'auto' }}
>
<PanelGroup direction="vertical" autoSaveId="vertical">
<Panel>
<Panel defaultSize={70}>
<PanelGroup direction="horizontal" autoSaveId="horizontal">
{!hiddenPanels[PanelName.ENTITIES] && (
<>
Expand Down Expand Up @@ -76,9 +86,15 @@ const App = () => {
{!hiddenPanels[PanelName.ASSETS] && (
<>
<PanelResizeHandle className="vertical-handle" />
<Panel minSize={footerMin} defaultSize={30}>
<Panel
id="assets"
defaultSize={30}
{...(height ? { collapsible: true, collapsedSize: footerMin, minSize: collapseAt } : {})}
onCollapse={() => handleToggleAssetsPanel(true)}
onExpand={() => handleToggleAssetsPanel(false)}
>
<Box className="composite-renderer">
<Assets />
<Assets isAssetsPanelCollapsed={isAssetsPanelCollapsed} />
</Box>
</Panel>
</>
Expand Down
20 changes: 12 additions & 8 deletions packages/@dcl/inspector/src/components/Assets/Assets.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
position: relative;
}

.Assets .Assets-buttons>div>div {
.Assets .Assets-buttons > div > div {
display: flex;
position: relative;
}

.Assets .Assets-buttons>div:hover>div::after,
.Assets .Assets-buttons>div>div.underlined::after {
.Assets .Assets-buttons > div:hover > div::after,
.Assets .Assets-buttons > div > div.underlined::after {
width: 100%;
}

.Assets .Assets-buttons>div>div::after {
.Assets .Assets-buttons > div > div::after {
content: '';
position: absolute;
bottom: -6px;
Expand All @@ -40,24 +40,24 @@
background: var(--white-gray);
}

.Assets .Assets-buttons>div span {
.Assets .Assets-buttons > div span {
margin-left: 4px;
}

.Assets .Assets-buttons>div {
.Assets .Assets-buttons > div {
display: flex;
align-items: center;
padding: 8px;
cursor: pointer;
user-select: none;
}

.Assets .Assets-buttons>div:last-child svg {
.Assets .Assets-buttons > div:last-child svg {
width: 16px;
height: 16px;
}

.Assets .Assets-buttons>div:last-child {
.Assets .Assets-buttons > div:last-child {
position: absolute;
right: 0px;
margin-right: 8px;
Expand All @@ -67,3 +67,7 @@
background: var(--tree-bg-color) !important;
height: calc(100% - 36px);
}

.Assets .Assets-content.Hide {
display: none;
}
12 changes: 6 additions & 6 deletions packages/@dcl/inspector/src/components/Assets/Assets.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useCallback } from 'react'
import cx from 'classnames'

import { FolderOpen } from '../Icons/Folder'
import { MdImageSearch } from 'react-icons/md'
import { HiOutlinePlus } from 'react-icons/hi'
import { AssetsCatalog } from '../AssetsCatalog'

import { AssetPack, catalog, isSmart } from '../../lib/logic/catalog'
import { getConfig } from '../../lib/logic/config'
import { getSelectedAssetsTab, selectAssetsTab } from '../../redux/ui'
import { useAppDispatch, useAppSelector } from '../../redux/hooks'
import { getSelectedAssetsTab, selectAssetsTab } from '../../redux/ui'
import { AssetsTab } from '../../redux/ui/types'
import { FolderOpen } from '../Icons/Folder'
import { AssetsCatalog } from '../AssetsCatalog'
import { ProjectAssetExplorer } from '../ProjectAssetExplorer'
import ImportAsset from '../ImportAsset'

Expand All @@ -22,7 +22,7 @@ function removeSmartItems(assetPack: AssetPack) {
}
}

function Assets() {
function Assets({ isAssetsPanelCollapsed }: { isAssetsPanelCollapsed: boolean }) {
const dispatch = useAppDispatch()
const tab = useAppSelector(getSelectedAssetsTab)

Expand Down Expand Up @@ -59,7 +59,7 @@ function Assets() {
</div>
</div>
</div>
<div className="Assets-content">
<div className={cx('Assets-content', { Hide: isAssetsPanelCollapsed })}>
{tab === AssetsTab.AssetsPack && <AssetsCatalog catalog={filteredCatalog} />}
{tab === AssetsTab.FileSystem && <ProjectAssetExplorer />}
{tab === AssetsTab.Import && <ImportAsset onSave={handleTabClick(AssetsTab.FileSystem)} />}
Expand Down

0 comments on commit 0c4dc9b

Please sign in to comment.