Skip to content

Commit

Permalink
Redux: add active top panel state
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Nov 4, 2023
1 parent b4e9b40 commit 46cc4d5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
13 changes: 9 additions & 4 deletions packages/web-console/src/scenes/Console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { useLocalStorage } from "../../providers/LocalStorageProvider"
import { StoreKey } from "../../utils/localStorage/types"
import { useSelector } from "react-redux"
import { actions, selectors } from "../../store"
import { Tooltip } from "../../components/Tooltip"
import { Tooltip } from "../../components"
import { Sidebar } from "../../components/Sidebar"
import { Navigation } from "../../components/Sidebar/navigation"
import { Database2, Grid, PieChart, Upload2 } from "@styled-icons/remix-line"
import { ResultViewMode } from "./types"
import { BUTTON_ICON_SIZE } from "../../consts/index"
import { BUTTON_ICON_SIZE } from "../../consts"
import { PrimaryToggleButton } from "../../components"
import { Import } from "./import"
import { BottomPanel } from "../../store/Console/types"
Expand Down Expand Up @@ -130,12 +130,17 @@ const Console = () => {
trigger={
<Navigation
direction="left"
onClick={() =>
onClick={() => {
dispatch(
actions.console.setActiveTopPanel(
resultsSplitterBasis === 0 ? "tables" : undefined,
),
)
updateSettings(
StoreKey.RESULTS_SPLITTER_BASIS,
resultsSplitterBasis === 0 ? 300 : 0,
)
}
}}
selected={resultsSplitterBasis !== 0}
>
<Database2 size={BUTTON_ICON_SIZE} />
Expand Down
6 changes: 6 additions & 0 deletions packages/web-console/src/store/Console/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ConsoleConfigShape,
ConsoleAction,
ConsoleAT,
TopPanel,
Sidebar,
BottomPanel,
} from "./types"
Expand All @@ -43,6 +44,10 @@ const setConfig = (payload: ConsoleConfigShape): ConsoleAction => ({
type: ConsoleAT.SET_CONFIG,
})

const setActiveTopPanel = (panel: TopPanel): ConsoleAction => ({
payload: panel,
type: ConsoleAT.SET_ACTIVE_TOP_PANEL,
})
const setActiveSidebar = (panel: Sidebar): ConsoleAction => ({
payload: panel,
type: ConsoleAT.SET_ACTIVE_SIDEBAR,
Expand All @@ -62,6 +67,7 @@ export default {
refreshAuthToken,
setConfig,
toggleSideMenu,
setActiveTopPanel,
setActiveSidebar,
setActiveBottomPanel,
}
8 changes: 8 additions & 0 deletions packages/web-console/src/store/Console/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {

export const initialState: ConsoleStateShape = {
sideMenuOpened: false,
activeTopPanel: "tables",
activeSidebar: undefined,
activeBottomPanel: "zeroState",
}
Expand Down Expand Up @@ -63,6 +64,13 @@ const _console = (
}
}

case ConsoleAT.SET_ACTIVE_TOP_PANEL: {
return {
...state,
activeTopPanel: action.payload,
}
}

case ConsoleAT.SET_ACTIVE_SIDEBAR: {
return {
...state,
Expand Down
12 changes: 11 additions & 1 deletion packages/web-console/src/store/Console/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
* limitations under the License.
*
******************************************************************************/
import { ConsoleConfigShape, StoreShape, Sidebar, BottomPanel } from "types"
import {
ConsoleConfigShape,
StoreShape,
Sidebar,
BottomPanel,
TopPanel,
} from "types"

import { defaultConfig } from "./reducers"

Expand All @@ -31,6 +37,9 @@ const getConfig: (store: StoreShape) => ConsoleConfigShape = (store) =>
const getSideMenuOpened: (store: StoreShape) => boolean = (store) =>
store.console.sideMenuOpened

const getActiveTopPanel: (store: StoreShape) => TopPanel = (store) =>
store.console.activeTopPanel

const getActiveSidebar: (store: StoreShape) => Sidebar = (store) =>
store.console.activeSidebar

Expand All @@ -40,6 +49,7 @@ const getActiveBottomPanel: (store: StoreShape) => BottomPanel = (store) =>
export default {
getConfig,
getSideMenuOpened,
getActiveTopPanel,
getActiveSidebar,
getActiveBottomPanel,
}
10 changes: 10 additions & 0 deletions packages/web-console/src/store/Console/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type QueryGroup = {
queries: Query[]
}

export type TopPanel = "tables" | undefined

export type Sidebar = "news" | "create" | undefined

export type BottomPanel = "result" | "zeroState" | "import"
Expand All @@ -46,6 +48,7 @@ export type ConsoleConfigShape = Readonly<{
export type ConsoleStateShape = Readonly<{
config?: ConsoleConfigShape
sideMenuOpened: boolean
activeTopPanel: TopPanel
activeSidebar: Sidebar
activeBottomPanel: BottomPanel
}>
Expand All @@ -55,6 +58,7 @@ export enum ConsoleAT {
REFRESH_AUTH_TOKEN = "CONSOLE/REFRESH_AUTH_TOKEN",
SET_CONFIG = "CONSOLE/SET_CONFIG",
TOGGLE_SIDE_MENU = "CONSOLE/TOGGLE_SIDE_MENU",
SET_ACTIVE_TOP_PANEL = "CONSOLE/SET_ACTIVE_TOP_PANEL",
SET_ACTIVE_SIDEBAR = "CONSOLE/SET_ACTIVE_SIDEBAR",
SET_ACTIVE_BOTTOM_PANEL = "CONSOLE/SET_ACTIVE_BOTTOM_PANEL",
}
Expand All @@ -77,6 +81,11 @@ type ToggleSideMenuAction = Readonly<{
type: ConsoleAT.TOGGLE_SIDE_MENU
}>

type setActiveTopPanelAction = Readonly<{
payload: TopPanel
type: ConsoleAT.SET_ACTIVE_TOP_PANEL
}>

type setActiveSidebarAction = Readonly<{
payload: Sidebar
type: ConsoleAT.SET_ACTIVE_SIDEBAR
Expand All @@ -92,5 +101,6 @@ export type ConsoleAction =
| RefreshAuthTokenAction
| SetConfigAction
| ToggleSideMenuAction
| setActiveTopPanelAction
| setActiveSidebarAction
| setActiveBottomPanelAction

0 comments on commit 46cc4d5

Please sign in to comment.