Skip to content

Commit

Permalink
Add Manage Panels to Toolbar (#6004)
Browse files Browse the repository at this point in the history
**Problem:**
We'd like to have a more prominent, easily-accessible way to manage
panel visibility located in the toolbar

**Fix:**
As a v1, leveraging a lot of similarity to the insert mode's dropdown in
the toolbar. Will iterate to use leverage a newly created button +
dropdown menu component in the future.

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Preview mode

Fixes #5892

---------

Co-authored-by: Balazs Bajorics <[email protected]>
  • Loading branch information
benwolfram and balazsbajorics authored Jul 3, 2024
1 parent 4eba85d commit 21effe2
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 214 deletions.
9 changes: 4 additions & 5 deletions editor/src/components/canvas/canvas-floating-toolbars.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import { FlexColumn, FlexRow } from '../../uuiui'
import { CanvasToolbar } from '../editor/canvas-toolbar'
import { ClosedPanels } from '../editor/closed-panels'
import { Substores, useEditorState } from '../editor/store/store-hook'
import { ErrorOverlayComponent } from './canvas-error-overlay'
import { SafeModeErrorOverlay } from './canvas-wrapper-component'
import { CanvasStrategyPicker } from './controls/select-mode/canvas-strategy-picker'
import { TestMenu } from '../titlebar/test-menu'

export const CanvasFloatingToolbars = React.memo((props: { style: React.CSSProperties }) => {
const safeMode = useEditorState(
Expand All @@ -32,21 +32,20 @@ export const CanvasFloatingToolbars = React.memo((props: { style: React.CSSPrope
position: 'absolute',
top: 0,
alignItems: 'flex-start',
justifyContent: 'space-between',
justifyContent: 'center',
padding: 6,
width: '100%',
height: '100%',
}}
>
<ClosedPanels side='left' />
<FlexRow style={{ width: 250, alignItems: 'flex-start', gap: 10 }}>
<CanvasToolbar />
<CanvasStrategyPicker />
</FlexRow>
<ClosedPanels side='right' />
</FlexRow>
{/* The error overlays are deliberately the last here so they hide other canvas UI */}
{/* The error overlays are deliberately the last here so they hide other canvas UI, except the test menu */}
{safeMode ? <SafeModeErrorOverlay /> : <ErrorOverlayComponent />}
<TestMenu />
</FlexColumn>
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ function getInteractionTargetFromEditorState(editor: EditorState): InteractionTa
case 'textEdit':
case 'comment':
case 'follow':
case 'panels':
return targetPaths(editor.selectedViews)
default:
assertNever(editor.mode)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { MouseCallbacks } from '../select-mode/select-mode-hooks'
import { NO_OP } from '../../../../core/shared/utils'

const noop: MouseCallbacks = {
onMouseMove: NO_OP,
onMouseDown: NO_OP,
onMouseUp: NO_OP,
}

export function usePanelsModeSelectAndHover(): MouseCallbacks {
return noop
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { getAllLockedElementPaths } from '../../../../core/shared/element-lockin
import { treatElementAsGroupLike } from '../../canvas-strategies/strategies/group-helpers'
import { useCommentModeSelectAndHover } from '../comment-mode/comment-mode-hooks'
import { useFollowModeSelectAndHover } from '../follow-mode/follow-mode-hooks'
import { usePanelsModeSelectAndHover } from '../panels-mode/panels-mode-hooks'

const DRAG_START_THRESHOLD = 2

Expand Down Expand Up @@ -805,6 +806,7 @@ export function useSelectAndHover(
mode?.type === 'comment' ? mode.comment : null,
)
const followModeCallbacks = useFollowModeSelectAndHover()
const panelsModeCallbacks = usePanelsModeSelectAndHover()

if (hasInteractionSession) {
return {
Expand All @@ -826,6 +828,8 @@ export function useSelectAndHover(
return commentModeCallbacks
case 'follow':
return followModeCallbacks
case 'panels':
return panelsModeCallbacks
default:
const _exhaustiveCheck: never = modeType
throw new Error(`Unhandled editor mode ${JSON.stringify(modeType)}`)
Expand Down
5 changes: 5 additions & 0 deletions editor/src/components/editor/canvas-toolbar-states.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ToolbarMode =
| { primary: 'play' }
| { primary: 'comment' }
| { primary: 'zoom' }
| { primary: 'panels' }

export function useToolbarMode(): ToolbarMode {
const editorMode = useEditorState(
Expand Down Expand Up @@ -124,6 +125,10 @@ export function useToolbarMode(): ToolbarMode {
}
}

if (editorMode.type === 'panels') {
return { primary: 'panels' }
}

// Edit Mode
if (nothingSelected) {
return { primary: 'edit', secondary: 'nothing-selected' }
Expand Down
31 changes: 31 additions & 0 deletions editor/src/components/editor/canvas-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { insertComponentPickerItem } from '../navigator/navigator-item/component
import { useAtom } from 'jotai'
import { ActiveRemixSceneAtom } from '../canvas/remix/utopia-remix-root-component'
import * as EP from '../../core/shared/element-path'
import { PanelsPicker } from '../navigator/navigator-item/panels-picker'

export const InsertMenuButtonTestId = 'insert-menu-button'
export const PlayModeButtonTestId = 'canvas-toolbar-play-mode'
Expand Down Expand Up @@ -267,6 +268,14 @@ export const CanvasToolbar = React.memo(() => {
}
}, [canvasToolbarMode.primary, dispatch, dispatchSwitchToSelectModeCloseMenus])

const togglePanelsButtonClicked = React.useCallback(() => {
if (canvasToolbarMode.primary === 'panels') {
dispatchSwitchToSelectModeCloseMenus()
} else {
dispatch([switchEditorMode(EditorModes.panelsMode())])
}
}, [canvasToolbarMode.primary, dispatch, dispatchSwitchToSelectModeCloseMenus])

const currentStrategyState = useEditorState(
Substores.restOfStore,
(store) => store.strategyState,
Expand Down Expand Up @@ -423,6 +432,16 @@ export const CanvasToolbar = React.memo(() => {
</div>,
)}
<Separator />
<Tooltip title='Manage panels' placement='bottom'>
<InsertModeButton
testid={commentButtonTestId}
iconType={'panels'}
iconCategory='tools'
primary={canvasToolbarMode.primary === 'panels'}
onClick={togglePanelsButtonClicked}
keepActiveInLiveMode
/>
</Tooltip>
<Tooltip title='Zoom to 100%' placement='bottom'>
<SquareButton
style={{
Expand Down Expand Up @@ -510,6 +529,18 @@ export const CanvasToolbar = React.memo(() => {
: null}
{/* Live Mode */}
{showRemixNavBar ? wrapInSubmenu(<RemixNavigationBar />) : null}
{/* Panels Mode */}
{canvasToolbarMode.primary === 'panels'
? wrapInSubmenu(
<FlexColumn style={{ padding: '3px 8px 0 8px', flexGrow: 1 }}>
<FlexRow>
<Tile style={{ flexGrow: 1 }}>
<PanelsPicker />
</Tile>
</FlexRow>
</FlexColumn>,
)
: null}
</FlexColumn>
)
})
Expand Down
204 changes: 0 additions & 204 deletions editor/src/components/editor/closed-panels.tsx

This file was deleted.

Loading

0 comments on commit 21effe2

Please sign in to comment.