-
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: Setup additional node tags #3775
Changes from all commits
b112dcc
11f4322
70e2770
aad2b5b
3a41393
658cd3d
9100ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,60 @@ | ||
import Box from "@mui/material/Box"; | ||
import { visuallyHidden } from "@mui/utils"; | ||
import { Palette, useTheme } from "@mui/material/styles"; | ||
import { NodeTag } from "@opensystemslab/planx-core/types"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
import { getContrastTextColor } from "styleUtils"; | ||
import { FONT_WEIGHT_SEMI_BOLD } from "theme"; | ||
|
||
export const TAG_DISPLAY_VALUES: Record< | ||
NodeTag, | ||
{ color: string; displayName: string } | ||
{ color: keyof Palette["nodeTag"]; displayName: string } | ||
> = { | ||
placeholder: { | ||
color: "#FAE1B7", | ||
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. Very much approve of the removal of colour hex codes 😁 |
||
color: "blocking", | ||
displayName: "Placeholder", | ||
}, | ||
toReview: { | ||
color: "nonBlocking", | ||
displayName: "To review", | ||
}, | ||
sensitiveData: { | ||
color: "information", | ||
displayName: "Sensitive data", | ||
}, | ||
analytics: { | ||
color: "information", | ||
displayName: "Analytics", | ||
}, | ||
automation: { | ||
color: "information", | ||
displayName: "Automation", | ||
}, | ||
} as const; | ||
|
||
export const Tag: React.FC<{ tag: NodeTag }> = ({ tag }) => ( | ||
<Box | ||
// Temporarily hidden until we decide how this should appear in the graph | ||
// Please see https://github.com/theopensystemslab/planx-new/pull/3762 | ||
style={visuallyHidden} | ||
sx={(theme) => ({ | ||
bgcolor: TAG_DISPLAY_VALUES[tag].color, | ||
borderColor: theme.palette.common.black, | ||
borderWidth: "0 1px 1px 1px", | ||
borderStyle: "solid", | ||
width: "100%", | ||
p: 0.5, | ||
textAlign: "center", | ||
fontWeight: FONT_WEIGHT_SEMI_BOLD, | ||
})} | ||
> | ||
{TAG_DISPLAY_VALUES[tag].displayName} | ||
</Box> | ||
); | ||
export const Tag: React.FC<{ tag: NodeTag }> = ({ tag }) => { | ||
const theme = useTheme(); | ||
|
||
const showTags = useStore((state) => state.showTags); | ||
if (!showTags) return null; | ||
|
||
const tagBgColor = theme.palette.nodeTag[TAG_DISPLAY_VALUES[tag].color]; | ||
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. Glad you've extracted this out but it's still quite horrible how nested it is 😂 |
||
|
||
return ( | ||
<Box | ||
sx={(theme) => ({ | ||
bgcolor: tagBgColor, | ||
borderColor: theme.palette.common.black, | ||
borderWidth: "0 1px 1px 1px", | ||
borderStyle: "solid", | ||
width: "100%", | ||
p: 0.5, | ||
textAlign: "center", | ||
fontWeight: FONT_WEIGHT_SEMI_BOLD, | ||
color: getContrastTextColor(tagBgColor, "#FFF"), | ||
})} | ||
> | ||
{TAG_DISPLAY_VALUES[tag].displayName} | ||
</Box> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import LabelIcon from "@mui/icons-material/Label"; | ||
import LabelOffIcon from "@mui/icons-material/LabelOff"; | ||
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 { useStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
import { FONT_WEIGHT_SEMI_BOLD } from "theme"; | ||
|
||
const TooltipWrap = styled(({ className, ...props }: TooltipProps) => ( | ||
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. This is repeated a few places now, I'll open up a follow up PR to make a variant or standardise this via the theme. |
||
<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, | ||
}, | ||
})); | ||
|
||
export const ToggleTagsButton: React.FC = () => { | ||
const [showTags, toggleShowTags] = useStore((state) => [ | ||
state.showTags, | ||
state.toggleShowTags, | ||
]); | ||
|
||
return ( | ||
<Box | ||
sx={(theme) => ({ | ||
position: "fixed", | ||
bottom: theme.spacing(2), | ||
left: theme.spacing(7), | ||
zIndex: theme.zIndex.appBar, | ||
border: `1px solid ${theme.palette.border.main}`, | ||
borderRadius: "3px", | ||
background: theme.palette.background.paper, | ||
})} | ||
> | ||
<TooltipWrap title="Toggle tags"> | ||
<IconButton | ||
aria-label="Toggle tags" | ||
onClick={toggleShowTags} | ||
size="large" | ||
sx={(theme) => ({ | ||
padding: theme.spacing(1), | ||
color: showTags | ||
? theme.palette.text.primary | ||
: theme.palette.text.disabled, | ||
})} | ||
> | ||
{showTags ? <LabelIcon /> : <LabelOffIcon />} | ||
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. This pattern may be restricting us more than we need to by limiting us to using "off" MUI icons if we want to expand this to toggle images or data fields? |
||
</IconButton> | ||
</TooltipWrap> | ||
</Box> | ||
); | ||
}; |
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.
Not sure if I have the right colour scheme or setup here @ianjon3s , should be be a quick and easy fix though!