From 950e61a422cf71d11e17fab2c5f88e6307a92139 Mon Sep 17 00:00:00 2001 From: Glen Wider Date: Tue, 27 Apr 2021 16:13:35 +0200 Subject: [PATCH] add showResult prop to CodeReview --- src/components/CodeReview.tsx | 20 +++++++----- src/components/CodeReviewCard.tsx | 30 +++++++++++------ src/stories/CodeReviewCard.stories.tsx | 45 ++++++++++++-------------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/components/CodeReview.tsx b/src/components/CodeReview.tsx index e821529..f33ac40 100644 --- a/src/components/CodeReview.tsx +++ b/src/components/CodeReview.tsx @@ -12,6 +12,7 @@ export interface CodeReviewProps { commentContainer?: CustomComment[]; onCommentCreated: (comment: CustomComment) => void; author: string; + showResult: boolean; } export const CodeReview: React.FC = ({ @@ -19,7 +20,8 @@ export const CodeReview: React.FC = ({ language, commentContainer, onCommentCreated, - author + author, + showResult }) => { const [linesWithComment, setLinesWithComment] = useState(new Array()); const [linesWithMildInfo, setLinesWithMildInfo] = useState(new Array()) @@ -116,13 +118,15 @@ export const CodeReview: React.FC = ({ )} -
- onCommentCreated(createComment(value, author))} - toggle={true} - /> -
+ {showResult && ( +
+ onCommentCreated(createComment(value, author))} + toggle={true} + /> +
+ )} ) diff --git a/src/components/CodeReviewCard.tsx b/src/components/CodeReviewCard.tsx index 914e276..1b5de15 100644 --- a/src/components/CodeReviewCard.tsx +++ b/src/components/CodeReviewCard.tsx @@ -3,6 +3,8 @@ import {Card} from "antd"; import "antd/dist/antd.css"; import "./CodeReview.css"; import CodeReview, {CodeReviewProps} from "./CodeReview"; +import {Language} from "prism-react-renderer"; +import {CustomComment} from "./CommentViewer"; const cardBodyStyle = { paddingTop: "0.5em", @@ -12,13 +14,22 @@ const cardBodyStyle = { export interface CodeReviewCardProps { width: number, title: string, - getCodeReviewProps: CodeReviewProps + code: string; + language: Language; + commentContainer?: CustomComment[]; + onCommentCreated: (comment: CustomComment) => void; + author: string; + showResult: boolean; } export const CodeReviewCard: React.FC = ({ - getCodeReviewProps, - width , - title, + width , + title, + code, + language, + commentContainer, + onCommentCreated, author, + showResult }) => { return ( = ({ bordered={true} size={"small"} > - ) diff --git a/src/stories/CodeReviewCard.stories.tsx b/src/stories/CodeReviewCard.stories.tsx index bfcf3ce..2cafc6e 100644 --- a/src/stories/CodeReviewCard.stories.tsx +++ b/src/stories/CodeReviewCard.stories.tsx @@ -122,29 +122,28 @@ const customComment4: CustomComment = { let customCommentContainer = [customComment1, customComment2, customComment3, customComment4]; const handleCommentCreatedJsx = (comment: CustomComment) => { - jsx.args!.getCodeReviewProps!.commentContainer = [...jsx.args!.getCodeReviewProps!.commentContainer!, comment] + jsx.args!.commentContainer = [...jsx.args!.commentContainer!, comment] forceReRender(); } const handleCommentCreatedCss = (comment: CustomComment) => { - css.args!.getCodeReviewProps!.commentContainer = [...css.args!.getCodeReviewProps!.commentContainer!, comment] + css.args!.commentContainer = [...css.args!.commentContainer!, comment] forceReRender(); } const handleCommentCreatedCpp = (comment: CustomComment) => { - cpp.args!.getCodeReviewProps!.commentContainer = [...cpp.args!.getCodeReviewProps!.commentContainer!, comment] + cpp.args!.commentContainer = [...cpp.args!.commentContainer!, comment] forceReRender(); } export let jsx = Template.bind({}); jsx.args = { - getCodeReviewProps: { - author: "Storybook Tester", - code: jsxCode, - language: "jsx", - commentContainer: customCommentContainer, - onCommentCreated: handleCommentCreatedJsx - }, + author: "Storybook Tester", + code: jsxCode, + language: "jsx", + showResult: true, + commentContainer: customCommentContainer, + onCommentCreated: handleCommentCreatedJsx, width: 500, title: "testReview.jsx", @@ -152,26 +151,24 @@ jsx.args = { export const css = Template.bind({}); css.args = { - getCodeReviewProps: { - author: "Storybook Tester", - code: cssCode, - language: "css", - commentContainer: customCommentContainer, - onCommentCreated: handleCommentCreatedCss - }, + author: "Storybook Tester", + code: cssCode, + language: "css", + showResult: true, + commentContainer: customCommentContainer, + onCommentCreated: handleCommentCreatedCss, width: 600, title: "layout.css", } export const cpp = Template.bind({}); cpp.args = { - getCodeReviewProps: { - author: "Storybook Tester", - code: cppCode, - language: "cpp", - commentContainer: customCommentContainer, - onCommentCreated: handleCommentCreatedCpp - }, + author: "Storybook Tester", + code: cppCode, + language: "cpp", + showResult: false, + commentContainer: customCommentContainer, + onCommentCreated: handleCommentCreatedCpp, width: 500, title: "matrix.cpp", } \ No newline at end of file