Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move editor console to tab #3578

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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) => (
<Tab {...props} disableFocusRipple disableTouchRipple disableRipple />
))<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;
76 changes: 19 additions & 57 deletions editor.planx.uk/src/pages/FlowEditor/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand All @@ -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 }) => ({
Expand Down Expand Up @@ -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) => [
Expand All @@ -145,19 +125,20 @@ const DebugConsole = () => {
],
);
return (
<Console borderTop={2} borderColor="border.main" bgcolor="background.paper">
<Console>
<Typography variant="body2">
<a
href={`${
import.meta.env.VITE_APP_API_URL
}/flows/${flowId}/download-schema`}
target="_blank"
rel="noopener noreferrer"
style={{ color: "inherit" }}
>
Download the flow schema
</a>
</Typography>
<pre>
<pre style={{ whiteSpace: "pre-wrap", fontSize: "medium" }}>
{JSON.stringify({ passport, breadcrumbs, cachedBreadcrumbs }, null, 2)}
</pre>
</Console>
Expand Down Expand Up @@ -270,12 +251,6 @@ const Sidebar: React.FC<{
value={props.url.replace("/published", "/preview")}
/>

<Tooltip arrow title="Toggle debug console">
<MenuOpenIcon
onClick={() => setDebugConsoleVisibility(!showDebugConsole)}
/>
</Tooltip>

<Permission.IsPlatformAdmin>
<Tooltip arrow title="Open draft service">
<Link
Expand Down Expand Up @@ -415,29 +390,12 @@ const Sidebar: React.FC<{
</Header>
<TabList>
<Tabs centered onChange={handleChange} value={activeTab} aria-label="">
<StyledTab
disableFocusRipple
disableTouchRipple
disableRipple
value="PreviewBrowser"
label="Preview"
/>
<StyledTab
disableFocusRipple
disableTouchRipple
disableRipple
value="History"
label="History"
/>
<StyledTab value="PreviewBrowser" label="Preview" tabTheme="light" />
<StyledTab value="History" label="History" tabTheme="light" />
{hasFeatureFlag("SEARCH") && (
<StyledTab
disableFocusRipple
disableTouchRipple
disableRipple
value="Search"
label="Search"
/>
<StyledTab value="Search" label="Search" tabTheme="light" />
)}
<StyledTab value="Console" label="Console" tabTheme="dark" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much tidier 🙌

</Tabs>
</TabList>
{activeTab === "PreviewBrowser" && (
Expand Down Expand Up @@ -466,7 +424,11 @@ const Sidebar: React.FC<{
<Search />
</SidebarContainer>
)}
{showDebugConsole && <DebugConsole />}
{activeTab === "Console" && (
<SidebarContainer>
<DebugConsole />
</SidebarContainer>
)}
</Root>
);
});
Expand Down
Loading