diff options
-rw-r--r-- | webui/src/components/ReopenBugButton/OpenBug.graphql | 7 | ||||
-rw-r--r-- | webui/src/components/ReopenBugButton/ReopenBugButton.tsx | 55 | ||||
-rw-r--r-- | webui/src/pages/bug/CommentForm.tsx | 11 |
3 files changed, 72 insertions, 1 deletions
diff --git a/webui/src/components/ReopenBugButton/OpenBug.graphql b/webui/src/components/ReopenBugButton/OpenBug.graphql new file mode 100644 index 00000000..cf9e49e5 --- /dev/null +++ b/webui/src/components/ReopenBugButton/OpenBug.graphql @@ -0,0 +1,7 @@ +mutation openBug($input: OpenBugInput!) { + openBug(input: $input) { + bug { + id + } + } +}
\ No newline at end of file diff --git a/webui/src/components/ReopenBugButton/ReopenBugButton.tsx b/webui/src/components/ReopenBugButton/ReopenBugButton.tsx new file mode 100644 index 00000000..195ca512 --- /dev/null +++ b/webui/src/components/ReopenBugButton/ReopenBugButton.tsx @@ -0,0 +1,55 @@ +import React from 'react'; + +import Button from '@material-ui/core/Button'; + +import { BugFragment } from 'src/pages/bug/Bug.generated'; +import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated'; + +import { useOpenBugMutation } from './OpenBug.generated'; + +interface Props { + bug: BugFragment; + disabled: boolean; +} + +function ReopenBugButton({ bug, disabled }: Props) { + const [openBug, { loading, error }] = useOpenBugMutation(); + + function openBugAction() { + openBug({ + variables: { + input: { + prefix: bug.id, + }, + }, + refetchQueries: [ + // TODO: update the cache instead of refetching + { + query: TimelineDocument, + variables: { + id: bug.id, + first: 100, + }, + }, + ], + awaitRefetchQueries: true, + }); + } + + if (loading) return <div>Loading...</div>; + if (error) return <div>Error</div>; + + return ( + <div> + <Button + variant="contained" + onClick={() => openBugAction()} + disabled={bug.status === 'OPEN' || disabled} + > + Reopen issue + </Button> + </div> + ); +} + +export default ReopenBugButton; diff --git a/webui/src/pages/bug/CommentForm.tsx b/webui/src/pages/bug/CommentForm.tsx index 128e4d32..c623dabb 100644 --- a/webui/src/pages/bug/CommentForm.tsx +++ b/webui/src/pages/bug/CommentForm.tsx @@ -6,6 +6,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles'; import CommentInput from '../../layout/CommentInput/CommentInput'; import CloseBugButton from 'src/components/CloseBugButton/CloseBugButton'; +import ReopenBugButton from 'src/components/ReopenBugButton/ReopenBugButton'; import { BugFragment } from './Bug.generated'; import { useAddCommentMutation } from './CommentForm.generated'; @@ -83,6 +84,14 @@ function CommentForm({ bug }: Props) { if (issueComment.length > 0) submit(); }; + function getCloseButton() { + return <CloseBugButton bug={bug} disabled={issueComment.length > 0} />; + } + + function getReopenButton() { + return <ReopenBugButton bug={bug} disabled={issueComment.length > 0} />; + } + return ( <Paper className={classes.container}> <form onSubmit={handleSubmit} ref={form}> @@ -92,7 +101,7 @@ function CommentForm({ bug }: Props) { onChange={(comment: string) => setIssueComment(comment)} /> <div className={classes.actions}> - <CloseBugButton bug={bug} disabled={issueComment.length > 0} /> + {bug.status === 'OPEN' ? getCloseButton() : getReopenButton()} <Button className={classes.greenButton} variant="contained" |