From d453abdeedcac5b7593f72d63a5641f9a3e99da0 Mon Sep 17 00:00:00 2001 From: Sascha Date: Fri, 19 Mar 2021 11:21:18 +0100 Subject: Move toggle button out of history menu --- webui/src/pages/bug/EditHistoryMenu.tsx | 33 +++++--------------- webui/src/pages/bug/Message.tsx | 54 ++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 33 deletions(-) (limited to 'webui') diff --git a/webui/src/pages/bug/EditHistoryMenu.tsx b/webui/src/pages/bug/EditHistoryMenu.tsx index a916a1a8..da2ed0cd 100644 --- a/webui/src/pages/bug/EditHistoryMenu.tsx +++ b/webui/src/pages/bug/EditHistoryMenu.tsx @@ -1,10 +1,8 @@ import React from 'react'; import CircularProgress from '@material-ui/core/CircularProgress'; -import IconButton, { IconButtonProps } from '@material-ui/core/IconButton'; import Menu from '@material-ui/core/Menu'; import MenuItem from '@material-ui/core/MenuItem'; -import HistoryIcon from '@material-ui/icons/History'; import Date from 'src/components/Date'; @@ -15,13 +13,13 @@ import { useMessageEditHistoryQuery } from './MessageEditHistory.generated'; const ITEM_HEIGHT = 48; type Props = { + anchor: null | HTMLElement; bugId: string; commentId: string; - iconBtnProps?: IconButtonProps; + onClose: () => void; }; -function EditHistoryMenu({ iconBtnProps, bugId, commentId }: Props) { - const [anchorEl, setAnchorEl] = React.useState(null); - const open = Boolean(anchorEl); +function EditHistoryMenu({ anchor, bugId, commentId, onClose }: Props) { + const open = Boolean(anchor); const { loading, error, data } = useMessageEditHistoryQuery({ variables: { bugIdPrefix: bugId }, @@ -38,31 +36,14 @@ function EditHistoryMenu({ iconBtnProps, bugId, commentId }: Props) { const comment = comments.find((elem) => elem.id === commentId); const history = comment?.history; - const handleClick = (event: React.MouseEvent) => { - setAnchorEl(event.currentTarget); - }; - - const handleClose = () => { - setAnchorEl(null); - }; - return (
- - - {history?.map((edit, index) => ( - + ))} diff --git a/webui/src/pages/bug/Message.tsx b/webui/src/pages/bug/Message.tsx index b117c103..bf3fb6da 100644 --- a/webui/src/pages/bug/Message.tsx +++ b/webui/src/pages/bug/Message.tsx @@ -5,6 +5,7 @@ import Paper from '@material-ui/core/Paper'; import Tooltip from '@material-ui/core/Tooltip/Tooltip'; import { makeStyles } from '@material-ui/core/styles'; import EditIcon from '@material-ui/icons/Edit'; +import HistoryIcon from '@material-ui/icons/History'; import Author, { Avatar } from 'src/components/Author'; import Content from 'src/components/Content'; @@ -58,7 +59,6 @@ const useStyles = makeStyles((theme) => ({ ...theme.typography.body2, padding: '0.5rem', }, - headerActions2: {}, headerActions: { color: theme.palette.info.contrastText, padding: '0rem', @@ -70,11 +70,55 @@ const useStyles = makeStyles((theme) => ({ }, })); +//TODO move button out of this component and let only menu as component with +//query. Then the query won't execute unless button click renders menu with +//query. +//TODO Fix display of load button spinner. +//TODO Move this button and menu in separate component directory +//TODO fix failing pipeline due to eslint error +type HistBtnProps = { + bugId: string; + commentId: string; +}; +function HistoryMenuToggleButton({ bugId, commentId }: HistBtnProps) { + const classes = useStyles(); + const [anchorEl, setAnchorEl] = React.useState(null); + + const handleClick = (event: React.MouseEvent) => { + setAnchorEl(event.currentTarget); + }; + + const handleClose = () => { + setAnchorEl(null); + }; + + return ( +
+ + + + {anchorEl && ( + + )} +
+ ); +} + type Props = { bug: BugFragment; op: AddCommentFragment | CreateFragment; }; - function Message({ bug, op }: Props) { const classes = useStyles(); const [editMode, switchToEditMode] = useState(false); @@ -94,11 +138,7 @@ function Message({ bug, op }: Props) {
{comment.edited && ( - + )} {() => ( -- cgit