Merge branch 'main' into avm99963-monorail
Merged commit 4137ed7879acadbf891e8c471108acb874dae886.
GitOrigin-RevId: b6100ffc5b1da355a35f37b13fcaaf746ee8b307
diff --git a/static_src/react/issue-wizard/CustomQuestions/CustomQuestionInput.tsx b/static_src/react/issue-wizard/CustomQuestions/CustomQuestionInput.tsx
new file mode 100644
index 0000000..aa7fdd0
--- /dev/null
+++ b/static_src/react/issue-wizard/CustomQuestions/CustomQuestionInput.tsx
@@ -0,0 +1,48 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import React from 'react'
+import OutlinedInput from "@material-ui/core/OutlinedInput";
+import {makeStyles} from '@material-ui/styles';
+
+const userStyles = makeStyles({
+ head: {
+ marginTop: '1.5rem',
+ fontSize: '1rem'
+ },
+ inputArea: {
+ width: '100%',
+ },
+});
+
+type Props = {
+ question: string,
+ updateAnswers: Function,
+}
+
+export default function CustomQuestionInput(props: Props): React.ReactElement {
+
+ const classes = userStyles();
+
+ const {question, updateAnswers} = props;
+ const [answer, setAnswer] = React.useState('');
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+ setAnswer(e.target.value);
+ updateAnswers(e.target.value);
+ };
+ const getInnerHtml = ()=> {
+ return {__html: question};
+ }
+ return (
+ <>
+ <h3 dangerouslySetInnerHTML={getInnerHtml()} className={classes.head}/>
+ <OutlinedInput
+ value={answer}
+ onChange={handleChange}
+ className={classes.inputArea}
+ inputProps={{ maxLength: 1000 }}
+ />
+ </>
+ );
+}
diff --git a/static_src/react/issue-wizard/CustomQuestions/CustomQuestionSelector.tsx b/static_src/react/issue-wizard/CustomQuestions/CustomQuestionSelector.tsx
new file mode 100644
index 0000000..bb855a3
--- /dev/null
+++ b/static_src/react/issue-wizard/CustomQuestions/CustomQuestionSelector.tsx
@@ -0,0 +1,105 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import React from 'react';
+import {makeStyles} from '@material-ui/styles';
+import SelectMenu from '../SelectMenu.tsx';
+import {CustomQuestion, CustomQuestionType} from '../IssueWizardTypes.tsx';
+import CustomQuestionInput from './CustomQuestionInput.tsx';
+import CustomQuestionTextarea from './CustomQuestionTextarea.tsx';
+import {GetSelectMenuOptions} from '../IssueWizardUtils.tsx';
+
+const userStyles = makeStyles({
+ head: {
+ marginTop: '1.5rem',
+ fontSize: '1rem'
+ },
+ inputArea: {
+ width: '100%',
+ },
+ tip: {
+ margin: '0.5rem 0',
+ },
+});
+
+type Props = {
+ question: string,
+ tip?: string,
+ options: string[],
+ subQuestions: CustomQuestion[] | null,
+ updateAnswers: Function,
+}
+
+export default function CustomQuestionSelector(props: Props): React.ReactElement {
+
+ const classes = userStyles();
+
+ const {question, updateAnswers, options, subQuestions, tip} = props;
+ const [selectedOption, setSelectedOption] = React.useState(options[0]);
+
+ const [subQuestion, setSubQuestion] = React.useState(subQuestions? subQuestions[0] : null);
+
+ React.useEffect(() => {
+ updateAnswers(options[0]);
+ },[]);
+
+ const handleOptionChange = (option: string) => {
+ setSelectedOption(option);
+ updateAnswers(option);
+ const index = options.indexOf(option);
+ if (subQuestions !== null) {
+ setSubQuestion(subQuestions[index]);
+ }
+ };
+
+ const updateSubQuestionAnswer = (answer:string) => {
+ const updatedAnswer = selectedOption + ' ' + answer;
+ updateAnswers(updatedAnswer);
+ }
+ const optionList = GetSelectMenuOptions(options);
+
+ let renderSubQuestion = null;
+
+ if (subQuestion != null) {
+ switch(subQuestion.type) {
+ case CustomQuestionType.Input:
+ renderSubQuestion =
+ <CustomQuestionInput
+ question={subQuestion.question}
+ updateAnswers={updateSubQuestionAnswer}
+ />
+ break;
+ case CustomQuestionType.Text:
+ renderSubQuestion =
+ <CustomQuestionTextarea
+ question={subQuestion.question}
+ tip={subQuestion.tip}
+ updateAnswers={updateSubQuestionAnswer}
+ />;
+ break;
+ default:
+ break;
+ }
+ }
+
+ const getQuestionInnerHtml = () => {
+ return {__html: question};
+ }
+
+ const getTipInnerHtml = () => {
+ return {__html: tip};
+ }
+ return (
+ <>
+ <h3 dangerouslySetInnerHTML={getQuestionInnerHtml()} className={classes.head}/>
+ {tip? <div dangerouslySetInnerHTML={getTipInnerHtml()} className={classes.tip}/> : null}
+ <SelectMenu
+ optionsList={optionList}
+ selectedOption={selectedOption}
+ setOption={handleOptionChange}
+ />
+ {renderSubQuestion}
+ </>
+ );
+}
diff --git a/static_src/react/issue-wizard/CustomQuestions/CustomQuestionTextarea.tsx b/static_src/react/issue-wizard/CustomQuestions/CustomQuestionTextarea.tsx
new file mode 100644
index 0000000..fdbdf1f
--- /dev/null
+++ b/static_src/react/issue-wizard/CustomQuestions/CustomQuestionTextarea.tsx
@@ -0,0 +1,59 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import React from 'react';
+import OutlinedInput from "@material-ui/core/OutlinedInput";
+import {makeStyles} from '@material-ui/styles';
+
+const userStyles = makeStyles({
+ head: {
+ marginTop: '1.5rem',
+ fontSize: '1rem'
+ },
+ inputArea: {
+ width: '100%',
+ },
+ tip: {
+ margin: '0.5rem 0'
+ },
+});
+
+type Props = {
+ question: string,
+ tip?: string,
+ updateAnswers: Function,
+}
+
+export default function CustomQuestionTextarea(props: Props): React.ReactElement {
+
+ const classes = userStyles();
+
+ const {question, updateAnswers, tip} = props;
+ const [answer, setAnswer] = React.useState('');
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+ setAnswer(e.target.value);
+ updateAnswers(e.target.value);
+ };
+
+ const getQuestionInnerHtml = ()=> {
+ return {__html: question};
+ }
+
+ const getTipInnerHtml = ()=> {
+ return {__html: tip};
+ }
+ return (
+ <>
+ <h3 dangerouslySetInnerHTML={getQuestionInnerHtml()} className={classes.head}/>
+ {tip? <div dangerouslySetInnerHTML={getTipInnerHtml()} className={classes.tip}/> : null}
+ <OutlinedInput
+ multiline={true}
+ rows={3}
+ value={answer}
+ onChange={handleChange}
+ className={classes.inputArea}
+ />
+ </>
+ );
+}