Skip to content
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

Fix resizing reordered panels #6011

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions editor/src/components/canvas/grid-panels-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,40 @@ import {
useResolvedGridPanels,
wrapAroundColIndex,
} from './grid-panels-state'
import type { LayoutUpdate, StoredPanel } from './stored-layout'
import type { LayoutUpdate, PanelVisibility, StoredPanel } from './stored-layout'
import {
GridHorizontalExtraPadding,
GridPanelHorizontalGapHalf,
GridPanelVerticalGapHalf,
GridVerticalExtraPadding,
NumberOfColumns,
} from './stored-layout'
import { Substores, useEditorState } from '../editor/store/store-hook'

export const GridPanelsContainer = React.memo(() => {
const [panelState, setPanelState] = useGridPanelState()

const orderedPanels = useResolvedGridPanels()

const panelVisibility = useEditorState(
Substores.restOfEditor,
(store): PanelVisibility => {
return {
navigator: store.editor.leftMenu.visible,
inspector: store.editor.rightMenu.visible,
'code-editor': store.editor.interfaceDesigner.codePaneVisible,
}
},
'GridPanelsContainer panelVisibility',
)

const isPanelVisible = React.useCallback(
(panel: StoredPanel): boolean => {
return panelVisibility[panel.name]
},
[panelVisibility],
)

const nonEmptyColumns = React.useMemo(() => {
return Array.from(
accumulate(new Set<number>(), (acc: Set<number>) => {
Expand All @@ -37,13 +57,13 @@ export const GridPanelsContainer = React.memo(() => {
acc.add(wrapAroundColIndex(NumberOfColumns - 1))

panelState.forEach((column, colIndex) => {
if (column.panels.length > 0) {
if (column.panels.length > 0 && column.panels.some(isPanelVisible)) {
acc.add(wrapAroundColIndex(colIndex))
}
})
}),
)
}, [panelState])
}, [panelState, isPanelVisible])

const onDrop = React.useCallback(
(itemToMove: StoredPanel, newPosition: LayoutUpdate) => {
Expand Down
2 changes: 2 additions & 0 deletions editor/src/components/canvas/stored-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface GridPanelData {

export type PanelName = Menu | Pane

export type PanelVisibility = Record<PanelName, boolean>

export interface StoredPanel {
name: PanelName
type: 'menu' | 'pane'
Expand Down
Loading