Skip to content

Commit

Permalink
Move result actions into sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Sep 18, 2023
1 parent 0bf04f5 commit 352c89b
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 184 deletions.
2 changes: 1 addition & 1 deletion packages/web-console/src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled from "styled-components"
import { Box } from "../Box"

export const Sidebar = styled(Box).attrs({ flexDirection: "column" })`
width: 4rem;
width: 4.5rem;
height: 100%;
background: ${({ theme }) => theme.color.backgroundDarker};
`
38 changes: 38 additions & 0 deletions packages/web-console/src/components/Sidebar/navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import styled from "styled-components"
import { PrimaryToggleButton } from ".."

type NavigationProps = Readonly<{
selected: boolean
}>

export const Navigation = styled(PrimaryToggleButton)<NavigationProps>`
display: flex;
flex-direction: column;
flex: 0 0 4rem;
align-items: center;
justify-content: center;
cursor: pointer;
& > span {
margin-left: 0 !important;
}
& > :not(:first-child) {
margin-top: 0.3rem;
}
`

export const DisabledNavigation = styled.div`
display: flex;
position: relative;
height: 100%;
width: 100%;
flex: 0 0 4rem;
align-items: center;
justify-content: center;
&:disabled {
pointer-events: none;
cursor: default;
}
`
52 changes: 47 additions & 5 deletions packages/web-console/src/scenes/Console/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"
import React, { useState } from "react"
import styled from "styled-components"
import { Splitter, useScreenSize } from "../../components"
import { Splitter, useScreenSize, PopperHover } from "../../components"
import Editor from "../Editor"
import Result from "../Result"
import Schema from "../Schema"
Expand All @@ -12,8 +12,12 @@ import { useLocalStorage } from "../../providers/LocalStorageProvider"
import { StoreKey } from "../../utils/localStorage/types"
import { useSelector, useDispatch } from "react-redux"
import { selectors, actions } from "../../store"
import { Tooltip } from "../../components/Tooltip"
import { Sidebar } from "../../components/Sidebar"
import { color } from "../../utils"
import { Navigation } from "../../components/Sidebar/navigation"
import { Grid, PieChart } from "styled-icons/remix-line"
import { ViewMode } from "./types"

const Root = styled.div`
display: flex;
Expand All @@ -35,7 +39,7 @@ const Bottom = styled.div`
const Logo = styled.div`
position: relative;
display: flex;
width: 4rem;
width: 4.5rem;
height: 4rem;
background: ${color("black")};
z-index: 1;
Expand All @@ -44,12 +48,30 @@ const Logo = styled.div`
cursor: pointer;
`

const viewModes: {
icon: React.ReactNode
mode: ViewMode
tooltipText: string
}[] = [
{
icon: <Grid size="18px" />,
mode: "grid",
tooltipText: "Grid",
},
{
icon: <PieChart size="18px" />,
mode: "chart",
tooltipText: "Chart",
},
]

const Console = () => {
const { sm } = useScreenSize()
const { editorSplitterBasis, resultsSplitterBasis, updateSettings } =
useLocalStorage()
const result = useSelector(selectors.query.getResult)
const dispatch = useDispatch()
const [resultViewMode, setResultViewMode] = useState<ViewMode>("grid")

const handleEditorSplitterChange = useCallback((value) => {
updateSettings(StoreKey.EDITOR_SPLITTER_BASIS, value)
Expand Down Expand Up @@ -96,8 +118,28 @@ const Console = () => {
</Splitter>
</Top>
<Bottom>
<Sidebar>bottom</Sidebar>
{result ? <Result /> : <ZeroState />}
<Sidebar>
{result &&
viewModes.map(({ icon, mode, tooltipText }) => (
<PopperHover
key={mode}
delay={350}
placement="right"
trigger={
<Navigation
direction="left"
onClick={() => setResultViewMode(mode)}
selected={resultViewMode === mode}
>
{icon}
</Navigation>
}
>
<Tooltip>{tooltipText}</Tooltip>
</PopperHover>
))}
</Sidebar>
{result ? <Result viewMode={resultViewMode} /> : <ZeroState />}
</Bottom>
</Splitter>
</EditorProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/web-console/src/scenes/Console/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ViewMode = "chart" | "grid"
Loading

0 comments on commit 352c89b

Please sign in to comment.