From 7b1b77dc444518a07779e836ec0c4c6b9406bbf9 Mon Sep 17 00:00:00 2001 From: Cláudio Date: Tue, 2 Feb 2021 16:43:09 -0300 Subject: Commit for #546 --- .../components/CloseBugButton/CloseBugButton.tsx | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 webui/src/components/CloseBugButton/CloseBugButton.tsx (limited to 'webui/src/components/CloseBugButton/CloseBugButton.tsx') diff --git a/webui/src/components/CloseBugButton/CloseBugButton.tsx b/webui/src/components/CloseBugButton/CloseBugButton.tsx new file mode 100644 index 000000000..9aca6fdd8 --- /dev/null +++ b/webui/src/components/CloseBugButton/CloseBugButton.tsx @@ -0,0 +1,49 @@ +import React from 'react'; + +import Button from '@material-ui/core/Button'; + +import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated'; + +import { useCloseBugMutation } from './CloseBug.generated'; + +interface Props { + bugId: string; +} + +function CloseBugButton({ bugId }: Props) { + const [closeBug, { loading, error }] = useCloseBugMutation(); + + function closeBugAction() { + closeBug({ + variables: { + input: { + prefix: bugId, + }, + }, + refetchQueries: [ + // TODO: update the cache instead of refetching + { + query: TimelineDocument, + variables: { + id: bugId, + first: 100, + }, + }, + ], + awaitRefetchQueries: true, + }); + } + + if (loading) return
Loading...
; + if (error) return
Error
; + + return ( +
+ +
+ ); +} + +export default CloseBugButton; -- cgit v1.2.3 From b7ec2404b031257ea30f46d4d7f92a498ac906db Mon Sep 17 00:00:00 2001 From: Cláudio Date: Tue, 2 Feb 2021 20:27:48 -0300 Subject: Fix #546 - Fixing code review requests --- webui/src/components/CloseBugButton/CloseBugButton.tsx | 16 +++++++++++----- webui/src/pages/bug/Bug.tsx | 2 +- webui/src/pages/bug/CommentForm.tsx | 11 ++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'webui/src/components/CloseBugButton/CloseBugButton.tsx') diff --git a/webui/src/components/CloseBugButton/CloseBugButton.tsx b/webui/src/components/CloseBugButton/CloseBugButton.tsx index 9aca6fdd8..19f56cab6 100644 --- a/webui/src/components/CloseBugButton/CloseBugButton.tsx +++ b/webui/src/components/CloseBugButton/CloseBugButton.tsx @@ -2,22 +2,24 @@ 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 { useCloseBugMutation } from './CloseBug.generated'; interface Props { - bugId: string; + bug: BugFragment; + disabled: boolean; } -function CloseBugButton({ bugId }: Props) { +function CloseBugButton({ bug, disabled }: Props) { const [closeBug, { loading, error }] = useCloseBugMutation(); function closeBugAction() { closeBug({ variables: { input: { - prefix: bugId, + prefix: bug.id, }, }, refetchQueries: [ @@ -25,7 +27,7 @@ function CloseBugButton({ bugId }: Props) { { query: TimelineDocument, variables: { - id: bugId, + id: bug.id, first: 100, }, }, @@ -39,7 +41,11 @@ function CloseBugButton({ bugId }: Props) { return (
-
diff --git a/webui/src/pages/bug/Bug.tsx b/webui/src/pages/bug/Bug.tsx index f2a116f86..bd6e44c41 100644 --- a/webui/src/pages/bug/Bug.tsx +++ b/webui/src/pages/bug/Bug.tsx @@ -82,7 +82,7 @@ function Bug({ bug }: Props) { {() => (
- +
)}
diff --git a/webui/src/pages/bug/CommentForm.tsx b/webui/src/pages/bug/CommentForm.tsx index d0935e1e6..128e4d324 100644 --- a/webui/src/pages/bug/CommentForm.tsx +++ b/webui/src/pages/bug/CommentForm.tsx @@ -7,6 +7,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles'; import CommentInput from '../../layout/CommentInput/CommentInput'; import CloseBugButton from 'src/components/CloseBugButton/CloseBugButton'; +import { BugFragment } from './Bug.generated'; import { useAddCommentMutation } from './CommentForm.generated'; import { TimelineDocument } from './TimelineQuery.generated'; @@ -39,10 +40,10 @@ const useStyles = makeStyles((theme) => ({ })); type Props = { - bugId: string; + bug: BugFragment; }; -function CommentForm({ bugId }: Props) { +function CommentForm({ bug }: Props) { const [addComment, { loading }] = useAddCommentMutation(); const [issueComment, setIssueComment] = useState(''); const [inputProp, setInputProp] = useState(''); @@ -53,7 +54,7 @@ function CommentForm({ bugId }: Props) { addComment({ variables: { input: { - prefix: bugId, + prefix: bug.id, message: issueComment, }, }, @@ -62,7 +63,7 @@ function CommentForm({ bugId }: Props) { { query: TimelineDocument, variables: { - id: bugId, + id: bug.id, first: 100, }, }, @@ -91,7 +92,7 @@ function CommentForm({ bugId }: Props) { onChange={(comment: string) => setIssueComment(comment)} />
- + 0} />