From 34872a71f003246befce2c470870fdd2a361214e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 26 Apr 2024 13:32:19 +0100 Subject: [PATCH] chore: Move EditorMenu, use config array --- .../FlowEditor/components/EditorMenu.tsx | 108 +++++++++--------- .../src/pages/FlowEditor/index.tsx | 4 - 2 files changed, 52 insertions(+), 60 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/EditorMenu.tsx b/editor.planx.uk/src/pages/FlowEditor/components/EditorMenu.tsx index 34a8b314ad..a10e477771 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/EditorMenu.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/EditorMenu.tsx @@ -1,15 +1,15 @@ -import EqualizerIcon from '@mui/icons-material/Equalizer'; import FlagIcon from '@mui/icons-material/Flag'; import FormatListBulletedIcon from '@mui/icons-material/FormatListBulleted'; -import IosShareIcon from '@mui/icons-material/IosShare'; -import PeopleIcon from '@mui/icons-material/People'; +import DataObject from '@mui/icons-material/DataObject'; +import Article from '@mui/icons-material/Article'; import RuleFolderIcon from '@mui/icons-material/RuleFolder'; -import ShareIcon from '@mui/icons-material/Share'; import Box from "@mui/material/Box"; import IconButton from '@mui/material/IconButton'; import { styled } from "@mui/material/styles"; import Tooltip, { tooltipClasses,TooltipProps } from '@mui/material/Tooltip'; import React from "react"; +import { useCurrentRoute, useNavigation } from 'react-navi'; +import { rootFlowPath } from 'routes/utils'; import { FONT_WEIGHT_SEMI_BOLD } from 'theme'; const MENU_WIDTH = "46px"; @@ -47,7 +47,9 @@ const TooltipWrap = styled(({ className, ...props }: TooltipProps) => ( }, })); -const MenuButton = styled(IconButton)(({ theme }) => ({ +const MenuButton = styled(IconButton, { + shouldForwardProp: (prop) => prop !== "isActive", +})<{ isActive: boolean }>(({ theme, isActive }) => ({ color: theme.palette.primary.main, width: MENU_WIDTH, height: MENU_WIDTH, @@ -58,67 +60,61 @@ const MenuButton = styled(IconButton)(({ theme }) => ({ borderTopColor: theme.palette.border.light, borderBottomColor: theme.palette.border.light, }, - "&[data-state='active']": { + ...(isActive && { background: theme.palette.common.white, color: theme.palette.text.primary, border: `1px solid ${theme.palette.border.main}`, borderRightColor: "transparent", - }, + }), })); function EditorMenu() { + const { navigate } = useNavigation(); + const { lastChunk } = useCurrentRoute(); + const rootPath = rootFlowPath(); + + const isActive = (route: string) => lastChunk.url.pathname.endsWith(route); + + const routes = [ + { + title: "Editor", + icon: , + route: "/", + }, + { + title: "Service", + icon:
, + route: "/service", + }, + { + title: "Service Flags", + icon: , + route: "/service-flags", + }, + { + title: "Data", + icon: , + route: "/data", + }, + { + title: "Submissions log", + icon: , + route: "/submissions-log", + }, + ]; + return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {routes.map(({ title, icon, route }) => ( + navigate(rootPath + route)}> + + + {icon} + + + + ))} ); diff --git a/editor.planx.uk/src/pages/FlowEditor/index.tsx b/editor.planx.uk/src/pages/FlowEditor/index.tsx index de7aa83d94..b3fcaff524 100644 --- a/editor.planx.uk/src/pages/FlowEditor/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/index.tsx @@ -13,7 +13,6 @@ import { hasFeatureFlag } from "lib/featureFlags"; import React, { useRef } from "react"; import { rootFlowPath } from "../../routes/utils"; -import EditorMenu from "./components/EditorMenu"; import Flow from "./components/Flow"; import PreviewBrowser from "./components/PreviewBrowser"; import { useStore } from "./lib/store"; @@ -133,9 +132,6 @@ const FlowEditor: React.FC = ({ flow, breadcrumbs }) => { return ( - - -