-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Handle editor sidebar visibility toggle on sidebar #3747
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import LanguageIcon from "@mui/icons-material/Language"; | ||
import OpenInNewIcon from "@mui/icons-material/OpenInNew"; | ||
import OpenInNewOffIcon from "@mui/icons-material/OpenInNewOff"; | ||
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; | ||
import ChevronRightIcon from "@mui/icons-material/ChevronRight"; | ||
import ToggleButton from "@mui/material/ToggleButton"; | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import Container from "@mui/material/Container"; | ||
import Link from "@mui/material/Link"; | ||
import { styled } from "@mui/material/styles"; | ||
import Tabs from "@mui/material/Tabs"; | ||
import Tooltip from "@mui/material/Tooltip"; | ||
import React, { useState } from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import { rootFlowPath } from "routes/utils"; | ||
import Permission from "ui/editor/Permission"; | ||
import Reset from "ui/icons/Reset"; | ||
|
@@ -23,19 +26,24 @@ import StyledTab from "./StyledTab"; | |
|
||
type SidebarTabs = "PreviewBrowser" | "History" | "Search" | "Console"; | ||
|
||
const Root = styled(Box)(({ theme }) => ({ | ||
const SIDEBAR_WIDTH = 500; | ||
const SIDEBAR_WIDTH_MINIMISED = 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should these be set directly as strings to avoid the extra templating step below? |
||
|
||
const Root = styled(Box)<{ isMinimised: boolean }>(({ theme, isMinimised }) => ({ | ||
position: "relative", | ||
top: "0", | ||
right: "0", | ||
bottom: "0", | ||
width: "500px", | ||
width: isMinimised ? `${SIDEBAR_WIDTH_MINIMISED}px` : `${SIDEBAR_WIDTH}px`, | ||
display: "flex", | ||
flexShrink: 0, | ||
flexDirection: "column", | ||
borderLeft: `1px solid ${theme.palette.border.main}`, | ||
background: theme.palette.background.paper, | ||
zIndex: 1, | ||
transition: "width 200ms ease-in-out", | ||
"& iframe": { | ||
flex: "1", | ||
flex: 1, | ||
}, | ||
})); | ||
|
||
|
@@ -46,8 +54,37 @@ const SidebarContainer = styled(Box)(() => ({ | |
position: "relative", | ||
})); | ||
|
||
const SidebarWrapper = styled(Box)(() => ({ | ||
width: SIDEBAR_WIDTH, | ||
display: "flex", | ||
flexDirection: "column", | ||
flexShrink: 0, | ||
flexGrow: 1, | ||
maxHeight: "100%", | ||
})); | ||
|
||
const StyledToggleButton = styled(ToggleButton)(({ theme }) => ({ | ||
background: theme.palette.background.paper, | ||
border: `1px solid ${theme.palette.border.main}`, | ||
borderImage: `linear-gradient(to right, ${theme.palette.border.main} 50%, transparent 50%) 30% 1`, | ||
position: "absolute", | ||
width: "40px", | ||
height: "40px", | ||
left: "-20px", | ||
top: theme.spacing(0.5), | ||
boxShadow: "none", | ||
color: theme.palette.text.primary, | ||
"& > svg": { | ||
fontSize: "1.875rem", | ||
}, | ||
"&:hover": { | ||
background: theme.palette.background.paper, | ||
boxShadow: "none", | ||
}, | ||
})); | ||
|
||
const Header = styled("header")(({ theme }) => ({ | ||
padding: theme.spacing(1, 1.5), | ||
padding: theme.spacing(1, 2), | ||
"& input": { | ||
flex: "1", | ||
padding: "5px", | ||
|
@@ -74,7 +111,6 @@ const ResetToggle = styled(Button)(({ theme }) => ({ | |
|
||
const TabList = styled(Box)(({ theme }) => ({ | ||
position: "relative", | ||
// Use a pseudo element as border to allow for tab border overlap without excessive MUI overrides | ||
"&::after": { | ||
content: "''", | ||
position: "absolute", | ||
|
@@ -86,9 +122,8 @@ const TabList = styled(Box)(({ theme }) => ({ | |
}, | ||
"& .MuiTabs-root": { | ||
minHeight: "0", | ||
padding: theme.spacing(0, 1.5), | ||
padding: theme.spacing(0, 1.75), | ||
}, | ||
// Hide default MUI indicator as we're using custom styling | ||
"& .MuiTabs-indicator": { | ||
display: "none", | ||
}, | ||
|
@@ -101,6 +136,12 @@ const Sidebar: React.FC = React.memo(() => { | |
]); | ||
|
||
const [activeTab, setActiveTab] = useState<SidebarTabs>("PreviewBrowser"); | ||
const [isSidebarMinimised, setIsSidebarMinimised] = useState<boolean>( | ||
() => { | ||
const savedState = localStorage.getItem("isSidebarMinimised"); | ||
return savedState === 'true'; | ||
} | ||
); | ||
|
||
const handleChange = ( | ||
_event: React.SyntheticEvent, | ||
|
@@ -109,6 +150,14 @@ const Sidebar: React.FC = React.memo(() => { | |
setActiveTab(newValue); | ||
}; | ||
|
||
const togglePreview = () => { | ||
setIsSidebarMinimised((prev) => { | ||
const newState = !prev; | ||
localStorage.setItem("isSidebarMinimised", JSON.stringify(newState)); | ||
return newState; | ||
}); | ||
}; | ||
|
||
const baseUrl = `${window.location.origin}${rootFlowPath(false)}`; | ||
|
||
const urls = { | ||
|
@@ -118,97 +167,106 @@ const Sidebar: React.FC = React.memo(() => { | |
}; | ||
|
||
return ( | ||
<Root> | ||
<Header> | ||
<Box width="100%" display="flex"> | ||
<input type="text" disabled value={urls.preview} /> | ||
<Root isMinimised={isSidebarMinimised}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 nice & clear ! |
||
<SidebarWrapper> | ||
<StyledToggleButton onClick={togglePreview} value="toggleSidebar"> | ||
{isSidebarMinimised ? ( | ||
<ChevronLeftIcon /> | ||
) : ( | ||
<ChevronRightIcon /> | ||
)} | ||
</StyledToggleButton> | ||
<Header> | ||
<Box width="100%" display="flex"> | ||
<input type="text" disabled value={urls.preview} /> | ||
|
||
<Permission.IsPlatformAdmin> | ||
<Tooltip arrow title="Open draft service"> | ||
<Link | ||
href={urls.draft} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
color="inherit" | ||
> | ||
<OpenInNewOffIcon /> | ||
</Link> | ||
</Tooltip> | ||
</Permission.IsPlatformAdmin> | ||
|
||
<Tooltip arrow title="Open preview of changes to publish"> | ||
<Link | ||
href={urls.preview} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
color="inherit" | ||
> | ||
<OpenInNewIcon /> | ||
</Link> | ||
</Tooltip> | ||
<Permission.IsPlatformAdmin> | ||
<Tooltip arrow title="Open draft service"> | ||
<Link | ||
href={urls.draft} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
color="inherit" | ||
> | ||
<OpenInNewOffIcon /> | ||
</Link> | ||
</Tooltip> | ||
</Permission.IsPlatformAdmin> | ||
|
||
{isFlowPublished ? ( | ||
<Tooltip arrow title="Open published service"> | ||
<Tooltip arrow title="Open preview of changes to publish"> | ||
<Link | ||
href={urls.analytics} | ||
href={urls.preview} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
color="inherit" | ||
> | ||
<LanguageIcon /> | ||
<OpenInNewIcon /> | ||
</Link> | ||
</Tooltip> | ||
) : ( | ||
<Tooltip arrow title="Flow not yet published"> | ||
<Box> | ||
<Link component={"button"} disabled aria-disabled={true}> | ||
|
||
{isFlowPublished ? ( | ||
<Tooltip arrow title="Open published service"> | ||
<Link | ||
href={urls.analytics} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
color="inherit" | ||
> | ||
<LanguageIcon /> | ||
</Link> | ||
</Box> | ||
</Tooltip> | ||
)} | ||
</Box> | ||
<PublishFlowButton previewURL={urls.preview} /> | ||
</Header> | ||
<TabList> | ||
<Tabs onChange={handleChange} value={activeTab} aria-label=""> | ||
<StyledTab value="PreviewBrowser" label="Preview" /> | ||
<StyledTab value="History" label="History" /> | ||
<StyledTab value="Search" label="Search" /> | ||
<StyledTab value="Console" label="Console" /> | ||
</Tabs> | ||
</TabList> | ||
{activeTab === "PreviewBrowser" && ( | ||
<SidebarContainer> | ||
<ResetToggle | ||
variant="link" | ||
onClick={() => { | ||
resetPreview(); | ||
}} | ||
> | ||
<Reset fontSize="small" /> | ||
Restart | ||
</ResetToggle> | ||
<Questions previewEnvironment="editor" /> | ||
</SidebarContainer> | ||
)} | ||
{activeTab === "History" && ( | ||
<SidebarContainer py={3}> | ||
<Container> | ||
<EditHistory /> | ||
</Container> | ||
</SidebarContainer> | ||
)} | ||
{activeTab === "Search" && ( | ||
<SidebarContainer> | ||
<Search /> | ||
</SidebarContainer> | ||
)} | ||
{activeTab === "Console" && ( | ||
<SidebarContainer> | ||
<DebugConsole /> | ||
</SidebarContainer> | ||
)} | ||
</Tooltip> | ||
) : ( | ||
<Tooltip arrow title="Flow not yet published"> | ||
<Box> | ||
<Link component={"button"} disabled aria-disabled={true}> | ||
<LanguageIcon /> | ||
</Link> | ||
</Box> | ||
</Tooltip> | ||
)} | ||
</Box> | ||
<PublishFlowButton previewURL={urls.preview} /> | ||
</Header> | ||
<TabList> | ||
<Tabs onChange={handleChange} value={activeTab} aria-label=""> | ||
<StyledTab value="PreviewBrowser" label="Preview" /> | ||
<StyledTab value="History" label="History" /> | ||
<StyledTab value="Search" label="Search" /> | ||
<StyledTab value="Console" label="Console" /> | ||
</Tabs> | ||
</TabList> | ||
{activeTab === "PreviewBrowser" && ( | ||
<SidebarContainer> | ||
<ResetToggle | ||
variant="link" | ||
onClick={() => { | ||
resetPreview(); | ||
}} | ||
> | ||
<Reset fontSize="small" /> | ||
Restart | ||
</ResetToggle> | ||
<Questions previewEnvironment="editor" /> | ||
</SidebarContainer> | ||
)} | ||
{activeTab === "History" && ( | ||
<SidebarContainer py={3}> | ||
<Container> | ||
<EditHistory /> | ||
</Container> | ||
</SidebarContainer> | ||
)} | ||
{activeTab === "Search" && ( | ||
<SidebarContainer> | ||
<Search /> | ||
</SidebarContainer> | ||
)} | ||
{activeTab === "Console" && ( | ||
<SidebarContainer> | ||
<DebugConsole /> | ||
</SidebarContainer> | ||
)} | ||
</SidebarWrapper> | ||
</Root> | ||
); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should these simply be set directly as strings to avoid the extra templating below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great spot, updated 👍