From 6e40f0c6b588c3b0cb12993a8b120b422b7daa41 Mon Sep 17 00:00:00 2001 From: Ian Jones <51156018+ianjon3s@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:47:15 +0100 Subject: [PATCH] refactor: Move editor console to tab (#3578) --- .../components/Sidebar/StyledTab.tsx | 39 ++++++++++ .../FlowEditor/components/Sidebar/index.tsx | 76 +++++-------------- 2 files changed, 58 insertions(+), 57 deletions(-) create mode 100644 editor.planx.uk/src/pages/FlowEditor/components/Sidebar/StyledTab.tsx diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/StyledTab.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/StyledTab.tsx new file mode 100644 index 0000000000..94bdc60043 --- /dev/null +++ b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/StyledTab.tsx @@ -0,0 +1,39 @@ +import { styled } from "@mui/material/styles"; +import Tab, { tabClasses, TabProps } from "@mui/material/Tab"; +import React from "react"; +import { FONT_WEIGHT_SEMI_BOLD } from "theme"; + +interface StyledTabProps extends TabProps { + tabTheme?: "light" | "dark"; +} + +const StyledTab = styled(({ tabTheme, ...props }: StyledTabProps) => ( + +))(({ theme, tabTheme }) => ({ + position: "relative", + zIndex: 1, + textTransform: "none", + background: "transparent", + border: `1px solid transparent`, + borderBottomColor: theme.palette.border.main, + color: theme.palette.primary.main, + fontWeight: FONT_WEIGHT_SEMI_BOLD, + minHeight: "36px", + margin: theme.spacing(0, 0.5), + marginBottom: "-1px", + padding: "0.5em", + [`&.${tabClasses.selected}`]: { + background: + tabTheme === "dark" + ? theme.palette.background.dark + : theme.palette.background.default, + borderColor: theme.palette.border.main, + borderBottomColor: theme.palette.common.white, + color: + tabTheme === "dark" + ? theme.palette.common.white + : theme.palette.text.primary, + }, +})); + +export default StyledTab; diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/index.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/index.tsx index 715fb86105..f7ac1b7416 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/index.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/index.tsx @@ -1,5 +1,4 @@ import LanguageIcon from "@mui/icons-material/Language"; -import MenuOpenIcon from "@mui/icons-material/MenuOpen"; import OpenInNewIcon from "@mui/icons-material/OpenInNew"; import OpenInNewOffIcon from "@mui/icons-material/OpenInNewOff"; import Badge from "@mui/material/Badge"; @@ -12,7 +11,6 @@ import DialogContent from "@mui/material/DialogContent"; import DialogTitle from "@mui/material/DialogTitle"; import Link from "@mui/material/Link"; import { styled } from "@mui/material/styles"; -import Tab, { tabClasses } from "@mui/material/Tab"; import Tabs from "@mui/material/Tabs"; import Tooltip from "@mui/material/Tooltip"; import Typography from "@mui/material/Typography"; @@ -35,13 +33,16 @@ import { ValidationChecks, } from "./PublishDialog"; import Search from "./Search"; +import StyledTab from "./StyledTab"; -type SidebarTabs = "PreviewBrowser" | "History" | "Search"; +type SidebarTabs = "PreviewBrowser" | "History" | "Search" | "Console"; -const Console = styled(Box)(() => ({ +const Console = styled(Box)(({ theme }) => ({ overflow: "auto", - padding: 20, - maxHeight: "50%", + padding: theme.spacing(2), + height: "100%", + backgroundColor: theme.palette.background.dark, + color: theme.palette.common.white, })); const Root = styled(Box)(({ theme }) => ({ @@ -114,27 +115,6 @@ const TabList = styled(Box)(({ theme }) => ({ }, })); -const StyledTab = styled(Tab)(({ theme }) => ({ - position: "relative", - zIndex: 1, - textTransform: "none", - background: "transparent", - border: `1px solid transparent`, - borderBottomColor: theme.palette.border.main, - color: theme.palette.primary.main, - fontWeight: "600", - minHeight: "36px", - margin: theme.spacing(0, 0.5), - marginBottom: "-1px", - padding: "0.5em", - [`&.${tabClasses.selected}`]: { - background: theme.palette.background.default, - borderColor: theme.palette.border.main, - borderBottomColor: theme.palette.common.white, - color: theme.palette.text.primary, - }, -})) as typeof Tab; - const DebugConsole = () => { const [passport, breadcrumbs, flowId, cachedBreadcrumbs] = useStore( (state) => [ @@ -145,7 +125,7 @@ const DebugConsole = () => { ], ); return ( - + { }/flows/${flowId}/download-schema`} target="_blank" rel="noopener noreferrer" + style={{ color: "inherit" }} > Download the flow schema - + {JSON.stringify({ passport, breadcrumbs, cachedBreadcrumbs }, null, 2)} @@ -270,12 +251,6 @@ const Sidebar: React.FC<{ value={props.url.replace("/published", "/preview")} /> - - setDebugConsoleVisibility(!showDebugConsole)} - /> - - - - + + {hasFeatureFlag("SEARCH") && ( - + )} + {activeTab === "PreviewBrowser" && ( @@ -466,7 +424,11 @@ const Sidebar: React.FC<{ )} - {showDebugConsole && } + {activeTab === "Console" && ( + + + + )} ); });
+ {JSON.stringify({ passport, breadcrumbs, cachedBreadcrumbs }, null, 2)}
{JSON.stringify({ passport, breadcrumbs, cachedBreadcrumbs }, null, 2)}