From d39e6c4c4391c1a3cd96f791b47d66b043da7f51 Mon Sep 17 00:00:00 2001 From: Tim Becker Date: Wed, 24 Mar 2021 23:26:14 +0100 Subject: [PATCH 01/11] Add label menu to bug detail page Also support label color in label filter menu on bug list page --- webui/src/components/Label.tsx | 41 +-- webui/src/pages/bug/Bug.tsx | 15 +- webui/src/pages/bug/labels/LabelMenu.tsx | 356 ++++++++++++++++++++ webui/src/pages/bug/labels/SetLabel.graphql | 13 + webui/src/pages/list/BugRow.tsx | 3 - webui/src/pages/list/Filter.tsx | 31 +- webui/src/pages/list/FilterToolbar.tsx | 1 + webui/src/pages/list/ListLabels.graphql | 3 +- 8 files changed, 424 insertions(+), 39 deletions(-) create mode 100644 webui/src/pages/bug/labels/LabelMenu.tsx create mode 100644 webui/src/pages/bug/labels/SetLabel.graphql diff --git a/webui/src/components/Label.tsx b/webui/src/components/Label.tsx index 111f6d7ff2b46ab09a20c7430ec41bdc47452b0c..13c913c92fcd633f45505e3b0f35761e9de4c2db 100644 --- a/webui/src/components/Label.tsx +++ b/webui/src/components/Label.tsx @@ -1,56 +1,43 @@ import React from 'react'; +import { Chip } from '@material-ui/core'; import { common } from '@material-ui/core/colors'; -import { makeStyles } from '@material-ui/core/styles'; import { - getContrastRatio, darken, + getContrastRatio, } from '@material-ui/core/styles/colorManipulator'; -import { LabelFragment } from '../graphql/fragments.generated'; -import { Color } from 'src/gqlTypes'; +import { Color } from '../gqlTypes'; + +import { LabelFragment } from './fragments.generated'; + +const _rgb = (color: Color) => + 'rgb(' + color.R + ',' + color.G + ',' + color.B + ')'; // Minimum contrast between the background and the text color const contrastThreshold = 2.5; - // Guess the text color based on the background color const getTextColor = (background: string) => getContrastRatio(background, common.white) >= contrastThreshold ? common.white // White on dark backgrounds : common.black; // And black on light ones -const _rgb = (color: Color) => - 'rgb(' + color.R + ',' + color.G + ',' + color.B + ')'; - // Create a style object from the label RGB colors const createStyle = (color: Color) => ({ backgroundColor: _rgb(color), color: getTextColor(_rgb(color)), borderBottomColor: darken(_rgb(color), 0.2), + margin: '3px', }); -const useStyles = makeStyles((theme) => ({ - label: { - ...theme.typography.body1, - padding: '1px 6px 0.5px', - fontSize: '0.9em', - fontWeight: 500, - margin: '0.05em 1px calc(-1.5px + 0.05em)', - borderRadius: '3px', - display: 'inline-block', - borderBottom: 'solid 1.5px', - verticalAlign: 'bottom', - }, -})); - type Props = { label: LabelFragment }; function Label({ label }: Props) { - const classes = useStyles(); return ( - - {label.name} - + ); } - export default Label; diff --git a/webui/src/pages/bug/Bug.tsx b/webui/src/pages/bug/Bug.tsx index 25281f963082de500ba3610ec8793bc9bc56e2f6..3cb48ecde214cd24675ebb7d73bc9106e3a19e29 100644 --- a/webui/src/pages/bug/Bug.tsx +++ b/webui/src/pages/bug/Bug.tsx @@ -9,6 +9,7 @@ import Label from 'src/components/Label'; import { BugFragment } from './Bug.generated'; import CommentForm from './CommentForm'; import TimelineQuery from './TimelineQuery'; +import LabelMenu from './labels/LabelMenu'; /** * Css in JS Styles @@ -53,13 +54,13 @@ const useStyles = makeStyles((theme) => ({ listStyle: 'none', padding: 0, margin: 0, + display: 'flex', + flexDirection: 'row', + flexWrap: 'wrap', }, label: { - marginTop: theme.spacing(1), - marginBottom: theme.spacing(1), - '& > *': { - display: 'block', - }, + marginTop: theme.spacing(0.1), + marginBottom: theme.spacing(0.1), }, noLabel: { ...theme.typography.body2, @@ -94,7 +95,9 @@ function Bug({ bug }: Props) {
- Labels + + +
d[1].toLowerCase().includes(filter.toLowerCase())) .map(([key, value, color]) => ( { toggleLabel(key, itemActive(key)); }} From f5df854def95e35e6fc2b408ecf746dcc0a8d38a Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 30 Mar 2021 15:51:36 +0200 Subject: [PATCH 05/11] Some changes to the label menu - Increase width of label menu - Use default selection styling instead of bold text - Use rem unit for labelcolor - Remove some tenary operator usage --- webui/src/pages/bug/labels/LabelMenu.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/webui/src/pages/bug/labels/LabelMenu.tsx b/webui/src/pages/bug/labels/LabelMenu.tsx index 5a70bd8a22c5dc689d3fd0cf4a8523c1f9f5f9e1..01be11d8e317225113eb4fd67cb628ff87a359a4 100644 --- a/webui/src/pages/bug/labels/LabelMenu.tsx +++ b/webui/src/pages/bug/labels/LabelMenu.tsx @@ -50,7 +50,7 @@ const CustomTextField = withStyles((theme) => ({ const ITEM_HEIGHT = 48; const useStyles = makeStyles((theme) => ({ - element: { + gearBtn: { ...theme.typography.body2, color: theme.palette.text.secondary, padding: theme.spacing(0, 1), @@ -61,15 +61,14 @@ const useStyles = makeStyles((theme) => ({ border: 'none', }, menu: { - witdh: 'auto', - }, - itemActive: { - fontWeight: 600, - color: theme.palette.text.primary, + '& .MuiMenu-paper': { + //somehow using "width" won't override the default width... + minWidth: '35ch', + }, }, labelcolor: { - width: '15px', - height: '15px', + minWidth: '1rem', + minHeight: '1rem', display: 'flex', backgroundColor: 'blue', borderRadius: '0.25rem', @@ -82,7 +81,6 @@ const useStyles = makeStyles((theme) => ({ }, menuRow: { display: 'flex', - flexDirection: 'row', alignItems: 'center', flexWrap: 'wrap', }, @@ -123,7 +121,7 @@ function FilterDropdown({ setOpen(!open)} - className={classes.element} + className={classes.gearBtn} > @@ -193,10 +191,10 @@ function FilterDropdown({ toggleLabel(key, itemActive(key)); }} key={key} - className={itemActive(key) ? classes.itemActive : undefined} + selected={itemActive(key)} >
- {itemActive(key) ? : null} + {itemActive(key) && }
Date: Tue, 30 Mar 2021 16:25:44 +0200 Subject: [PATCH 06/11] Cut of very long labels with an ellipse --- webui/src/components/Label.tsx | 12 ++++++++---- webui/src/pages/bug/Bug.tsx | 2 +- webui/src/pages/bug/LabelChange.tsx | 4 ++-- webui/src/pages/list/BugRow.tsx | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/webui/src/components/Label.tsx b/webui/src/components/Label.tsx index 13c913c92fcd633f45505e3b0f35761e9de4c2db..bbe7c1588ac994dca046046c360960816ef966c2 100644 --- a/webui/src/components/Label.tsx +++ b/webui/src/components/Label.tsx @@ -23,20 +23,24 @@ const getTextColor = (background: string) => : common.black; // And black on light ones // Create a style object from the label RGB colors -const createStyle = (color: Color) => ({ +const createStyle = (color: Color, maxWidth?: string) => ({ backgroundColor: _rgb(color), color: getTextColor(_rgb(color)), borderBottomColor: darken(_rgb(color), 0.2), margin: '3px', + maxWidth: maxWidth, }); -type Props = { label: LabelFragment }; -function Label({ label }: Props) { +type Props = { + label: LabelFragment; + maxWidth?: string; +}; +function Label({ label, maxWidth }: Props) { return ( ); } diff --git a/webui/src/pages/bug/Bug.tsx b/webui/src/pages/bug/Bug.tsx index 3cb48ecde214cd24675ebb7d73bc9106e3a19e29..5f3dfd035fe03f152c472da0a9a81d62c0fd52e7 100644 --- a/webui/src/pages/bug/Bug.tsx +++ b/webui/src/pages/bug/Bug.tsx @@ -104,7 +104,7 @@ function Bug({ bug }: Props) { )} {bug.labels.map((l) => (
  • -
  • ))} diff --git a/webui/src/pages/bug/LabelChange.tsx b/webui/src/pages/bug/LabelChange.tsx index c40636c115c79068a99ea0ada4a68e56de057a05..fd466ab88fc34c4191a4bbf86c53f66fa4b6dbb0 100644 --- a/webui/src/pages/bug/LabelChange.tsx +++ b/webui/src/pages/bug/LabelChange.tsx @@ -30,12 +30,12 @@ function LabelChange({ op }: Props) { {added.length > 0 && added the } {added.map((label, index) => ( -