From 098bcd0c1f26d0896e7ede3edb4040b01bc3126a Mon Sep 17 00:00:00 2001 From: Sascha Date: Tue, 25 May 2021 14:07:27 +0200 Subject: WebUI: Add comment-and-close of a bug in one step When a user has some text entered in the comment field, the close bug button will change to "Close bug with comment". This way the user does not have to comment and close a bug in two separate steps. --- .../CloseBugWithComment.graphql | 11 ++++ .../CloseBugWithCommentButton.tsx | 69 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 webui/src/components/CloseBugWithCommentButton/CloseBugWithComment.graphql create mode 100644 webui/src/components/CloseBugWithCommentButton/CloseBugWithCommentButton.tsx (limited to 'webui/src/components/CloseBugWithCommentButton') diff --git a/webui/src/components/CloseBugWithCommentButton/CloseBugWithComment.graphql b/webui/src/components/CloseBugWithCommentButton/CloseBugWithComment.graphql new file mode 100644 index 00000000..eb736f53 --- /dev/null +++ b/webui/src/components/CloseBugWithCommentButton/CloseBugWithComment.graphql @@ -0,0 +1,11 @@ +mutation AddCommentAndCloseBug($input: AddCommentAndCloseBugInput!) { + addCommentAndClose(input: $input) { + statusOperation { + status + } + commentOperation { + message + } + } +} + diff --git a/webui/src/components/CloseBugWithCommentButton/CloseBugWithCommentButton.tsx b/webui/src/components/CloseBugWithCommentButton/CloseBugWithCommentButton.tsx new file mode 100644 index 00000000..1d713f88 --- /dev/null +++ b/webui/src/components/CloseBugWithCommentButton/CloseBugWithCommentButton.tsx @@ -0,0 +1,69 @@ +import React from 'react'; + +import Button from '@material-ui/core/Button'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline'; + +import { BugFragment } from 'src/pages/bug/Bug.generated'; +import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated'; + +import { useAddCommentAndCloseBugMutation } from './CloseBugWithComment.generated'; + +const useStyles = makeStyles((theme: Theme) => ({ + closeIssueIcon: { + color: theme.palette.secondary.dark, + paddingTop: '0.1rem', + }, +})); + +interface Props { + bug: BugFragment; + comment: string; +} + +function CloseBugWithCommentButton({ bug, comment }: Props) { + const [ + addCommentAndCloseBug, + { loading, error }, + ] = useAddCommentAndCloseBugMutation(); + const classes = useStyles(); + + function addCommentAndCloseBugAction() { + addCommentAndCloseBug({ + variables: { + input: { + prefix: bug.id, + message: comment, + }, + }, + refetchQueries: [ + // TODO: update the cache instead of refetching + { + query: TimelineDocument, + variables: { + id: bug.id, + first: 100, + }, + }, + ], + awaitRefetchQueries: true, + }); + } + + if (loading) return
Loading...
; + if (error) return
Error
; + + return ( +
+ +
+ ); +} + +export default CloseBugWithCommentButton; -- cgit