-
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: Editor Menu #3028
Merged
Merged
feat: Editor Menu #3028
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
23443cd
feat: Editor sidebar menu
ianjon3s e8805bf
feat: Refine styling for sidebar menu
ianjon3s ec5ee50
fix: Analytics typo
ianjon3s fa1ed1d
chore: Move testing banner to header
DafyddLlyr 9b32bcb
chore: Move EditorMenu, use config array
DafyddLlyr 1221d6a
feat: Setup routes and views
DafyddLlyr 9f66536
chore: Add feature flag
DafyddLlyr bf2a305
chore: Better structure for icons
DafyddLlyr 1147979
feat: Link back to correct settings components
DafyddLlyr 9cd5d47
feat: Set up settings container view for standard layout
DafyddLlyr 5d310b1
fix: Stop test banner from re-appearing
DafyddLlyr fd63efe
chore: Tidy ups
DafyddLlyr 71b56c7
feat: Increase padding of setting pages
ianjon3s 29b329f
feat: Update icons and options
ianjon3s 5d76658
feat: Custom editor icon
ianjon3s 023554e
fix: Icon in correct folder
ianjon3s 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
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
113 changes: 113 additions & 0 deletions
113
editor.planx.uk/src/pages/FlowEditor/components/EditorMenu.tsx
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import FactCheckIcon from "@mui/icons-material/FactCheck"; | ||
import TuneIcon from "@mui/icons-material/Tune"; | ||
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"; | ||
import EditorIcon from "ui/icons/Editor"; | ||
|
||
const MENU_WIDTH = "46px"; | ||
|
||
const Root = styled(Box)(({ theme }) => ({ | ||
width: MENU_WIDTH, | ||
flexShrink: 0, | ||
background: theme.palette.background.paper, | ||
borderRight: `1px solid ${theme.palette.border.main}`, | ||
})); | ||
|
||
const MenuWrap = styled("ul")(({ theme }) => ({ | ||
listStyle: "none", | ||
margin: 0, | ||
padding: theme.spacing(4, 0, 0, 0), | ||
})); | ||
|
||
const MenuItem = styled("li")(({ theme }) => ({ | ||
margin: theme.spacing(0.75, 0), | ||
padding: 0, | ||
})); | ||
|
||
const TooltipWrap = styled(({ className, ...props }: TooltipProps) => ( | ||
<Tooltip {...props} arrow placement="right" classes={{ popper: className }} /> | ||
))(() => ({ | ||
[`& .${tooltipClasses.arrow}`]: { | ||
color: "#2c2c2c", | ||
}, | ||
[`& .${tooltipClasses.tooltip}`]: { | ||
backgroundColor: "#2c2c2c", | ||
left: "-5px", | ||
fontSize: "0.8em", | ||
borderRadius: 0, | ||
fontWeight: FONT_WEIGHT_SEMI_BOLD, | ||
}, | ||
})); | ||
|
||
const MenuButton = styled(IconButton, { | ||
shouldForwardProp: (prop) => prop !== "isActive", | ||
})<{ isActive: boolean }>(({ theme, isActive }) => ({ | ||
color: theme.palette.primary.main, | ||
width: MENU_WIDTH, | ||
height: MENU_WIDTH, | ||
border: "1px solid transparent", | ||
borderRightColor: theme.palette.border.main, | ||
"&:hover": { | ||
background: "white", | ||
borderTopColor: theme.palette.border.light, | ||
borderBottomColor: theme.palette.border.light, | ||
}, | ||
...(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 handleClick = (route: string) => | ||
!isActive(route) && navigate(rootPath + route); | ||
|
||
const routes = [ | ||
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. @ianjon3s This pattern of splitting up "content" and "code" is a good one to be aware of. We now have a list of items we're iterating over with the It's now a bit simpler to add or remove a menu item, or control the visual appearance of all of them consistently 👍 |
||
{ | ||
title: "Editor", | ||
Icon: EditorIcon, | ||
route: "/", | ||
}, | ||
{ | ||
title: "Service settings", | ||
Icon: TuneIcon, | ||
route: "/service", | ||
}, | ||
{ | ||
title: "Submissions log", | ||
Icon: FactCheckIcon, | ||
route: "/submissions-log", | ||
}, | ||
]; | ||
|
||
return ( | ||
<Root> | ||
<MenuWrap> | ||
{routes.map(({ title, Icon, route }) => ( | ||
<MenuItem onClick={() => handleClick(route)} key={title}> | ||
<TooltipWrap title={title}> | ||
<MenuButton isActive={isActive(route)} disableRipple> | ||
<Icon /> | ||
</MenuButton> | ||
</TooltipWrap> | ||
</MenuItem> | ||
))} | ||
</MenuWrap> | ||
</Root> | ||
); | ||
} | ||
|
||
export default EditorMenu; |
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
import EditorMenu from "pages/FlowEditor/components/EditorMenu"; | ||
import Box from "@mui/material/Box"; | ||
import { styled } from "@mui/material/styles"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import ErrorFallback from "components/ErrorFallback"; | ||
import { hasFeatureFlag } from "lib/featureFlags"; | ||
|
||
const Root = styled(Box)(() => ({ | ||
display: "flex", | ||
alignItems: "stretch", | ||
overflow: "hidden", | ||
flexGrow: 1, | ||
})) | ||
|
||
const FlowEditorLayout: React.FC<PropsWithChildren> = ({ children }) => ( | ||
<Root> | ||
{ hasFeatureFlag("EDITOR_NAVIGATION") && <EditorMenu /> } | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
{children} | ||
</ErrorBoundary> | ||
</Root> | ||
); | ||
|
||
export default FlowEditorLayout; | ||
|
||
|
Oops, something went wrong.
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.
This is now controlled at a store level as it was being re-rendered (and therefore going back to visible) on each route change.
I think this is the same issue we're seeing with everything re-rendering when we got to
/nodes
routes. See comment below on this 👍