From d39e6c4c4391c1a3cd96f791b47d66b043da7f51 Mon Sep 17 00:00:00 2001 From: Tim Becker Date: Wed, 24 Mar 2021 23:26:14 +0100 Subject: [PATCH] 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 + + +