Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {ReactElement} from 'react'; |
| 6 | import * as React from 'react' |
| 7 | import ReactDOM from 'react-dom'; |
| 8 | import styles from './IssueWizard.css'; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 9 | import LandingStep from './issue-wizard/LandingStep.tsx'; |
| 10 | import DetailsStep from './issue-wizard/DetailsStep.tsx' |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 11 | import {IssueWizardPersona} from './issue-wizard/IssueWizardTypes.tsx'; |
| 12 | import CustomQuestionsStep from './issue-wizard/CustomQuestionsStep.tsx'; |
| 13 | import {getOs, getChromeVersion, buildIssueDescription} from './issue-wizard/IssueWizardUtils.tsx' |
| 14 | import Header from './issue-wizard/Header.tsx' |
| 15 | |
| 16 | import {GetQuestionsByCategory, buildIssueLabels, getCompValByCategory, getLabelsByCategory} from './issue-wizard/IssueWizardUtils.tsx'; |
| 17 | import {ISSUE_WIZARD_QUESTIONS, ISSUE_REPRODUCE_PLACEHOLDER, OS_CHANNEL_LIST} from './issue-wizard/IssueWizardConfig.ts'; |
| 18 | import {prpcClient} from 'prpc-client-instance.js'; |
| 19 | import {expandDescriptions} from './issue-wizard/IssueWizardDescriptionsUtils.tsx'; |
| 20 | import SubmitSuccessStep from './issue-wizard/SubmitSuccessStep.tsx'; |
| 21 | import {IssueWizardFeedback} from './issue-wizard/IssueWizardFeedback.tsx'; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Base component for the issue filing wizard, wrapper for other components. |
| 25 | * @return Issue wizard JSX. |
| 26 | */ |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 27 | type Props = { |
| 28 | loginUrl: string, |
| 29 | userDisplayName: string, |
| 30 | } |
| 31 | export function IssueWizard(props: Props): ReactElement { |
| 32 | const {loginUrl, userDisplayName} = props; |
| 33 | React.useEffect(() => { |
| 34 | if(!userDisplayName) { |
| 35 | window.location.href = loginUrl; |
| 36 | } |
| 37 | },[loginUrl, userDisplayName]); |
| 38 | |
| 39 | const [userPersona, setUserPersona] = React.useState(IssueWizardPersona.EndUser); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 40 | const [activeStep, setActiveStep] = React.useState(0); |
| 41 | const [category, setCategory] = React.useState(''); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 42 | const [newIssueID, setnewIssueID] = React.useState(''); |
| 43 | const [isRegression, setIsRegression] = React.useState(false); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 44 | const [textValues, setTextValues] = React.useState( |
| 45 | { |
| 46 | oneLineSummary: '', |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 47 | stepsToReproduce: ISSUE_REPRODUCE_PLACEHOLDER, |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 48 | describeProblem: '', |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 49 | chromeVersion: getChromeVersion(), |
| 50 | osName: getOs(), |
| 51 | channel: OS_CHANNEL_LIST[0].name, |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 52 | }); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 53 | const [enableFeedback, setEnableFeedback] = React.useState(false); |
| 54 | const questionByCategory = GetQuestionsByCategory(ISSUE_WIZARD_QUESTIONS); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 55 | |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 56 | const moveStep = (step: number) => { |
| 57 | window.scrollTo(0, 0); |
| 58 | setActiveStep(step); |
| 59 | } |
| 60 | |
| 61 | const reset = () => { |
| 62 | setTextValues({ |
| 63 | oneLineSummary: '', |
| 64 | stepsToReproduce: ISSUE_REPRODUCE_PLACEHOLDER, |
| 65 | describeProblem: '', |
| 66 | chromeVersion: getChromeVersion(), |
| 67 | osName: getOs(), |
| 68 | channel: OS_CHANNEL_LIST[0].name, |
| 69 | }); |
| 70 | setIsRegression(false); |
| 71 | } |
| 72 | |
| 73 | const updateCategory = (category: string) => { |
| 74 | setCategory(category); |
| 75 | reset(); |
| 76 | } |
| 77 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 78 | let page; |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 79 | if (activeStep === 0) { |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 80 | page = <LandingStep |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 81 | userPersona={userPersona} |
| 82 | setUserPersona={setUserPersona} |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 83 | category={category} |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 84 | setCategory={updateCategory} |
| 85 | setActiveStep={moveStep} |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 86 | />; |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 87 | } else if (activeStep === 1) { |
| 88 | page = <DetailsStep |
| 89 | textValues={textValues} |
| 90 | setTextValues={setTextValues} |
| 91 | category={category} |
| 92 | setActiveStep={moveStep} |
| 93 | setIsRegression={setIsRegression} |
| 94 | />; |
| 95 | } else if (activeStep === 2) { |
| 96 | const compValByCategory = getCompValByCategory(ISSUE_WIZARD_QUESTIONS); |
| 97 | const labelsByCategory = getLabelsByCategory(ISSUE_WIZARD_QUESTIONS); |
| 98 | |
| 99 | const onSubmitIssue = (comments: string, customQuestionsAnswers: Array<string>, attachments: Array<any>,onSuccess: Function, onFailure: Function) => { |
| 100 | const summary = textValues.oneLineSummary; |
| 101 | const component = compValByCategory.get(category); |
| 102 | const description = buildIssueDescription( |
| 103 | textValues.stepsToReproduce, |
| 104 | textValues.describeProblem, |
| 105 | comments, textValues.osName, |
| 106 | textValues.chromeVersion, |
| 107 | textValues.channel); |
| 108 | const labels = buildIssueLabels(category, textValues.osName, textValues.chromeVersion, labelsByCategory.get(category)); |
| 109 | |
| 110 | const {expandDescription, expandLabels, compVal} = |
| 111 | expandDescriptions(category, customQuestionsAnswers, isRegression, description, labels, component); |
| 112 | |
| 113 | const componentsArray = []; |
| 114 | if (compVal.length > 0) { |
| 115 | componentsArray.push({ |
| 116 | component: 'projects/chromium/componentDefs/' + compVal |
| 117 | }) |
| 118 | } |
| 119 | |
| 120 | const response = prpcClient.call('monorail.v3.Issues', 'MakeIssue', { |
| 121 | parent: 'projects/chromium', |
| 122 | issue: { |
| 123 | summary, |
| 124 | status: { |
| 125 | status: 'Untriaged', |
| 126 | }, |
| 127 | components: componentsArray, |
| 128 | labels: expandLabels, |
| 129 | }, |
| 130 | description: expandDescription, |
| 131 | uploads: attachments, |
| 132 | }); |
| 133 | response.then(onSuccess, onFailure); |
| 134 | } |
| 135 | page = |
| 136 | <CustomQuestionsStep |
| 137 | setActiveStep={moveStep} |
| 138 | questions={questionByCategory.get(category)} |
| 139 | onSubmit={onSubmitIssue} |
| 140 | setnewIssueID={setnewIssueID} |
| 141 | />; |
| 142 | } else if (activeStep === 3) { |
| 143 | page = <SubmitSuccessStep issueID={newIssueID}/>; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return ( |
| 147 | <> |
| 148 | <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins"></link> |
| 149 | <div className={styles.container}> |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 150 | <Header /> |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 151 | {page} |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 152 | <div className={styles.feedback} onClick={()=>{setEnableFeedback(true);}}>Report a problem with this wizard</div> |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 153 | </div> |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 154 | <IssueWizardFeedback enable={enableFeedback} setEnable={setEnableFeedback}/> |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 155 | </> |
| 156 | ); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Renders the issue filing wizard page. |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 161 | * @param mount HTMLElement that the React component should be added to. |
| 162 | * @param loginUrl redirect to login page |
| 163 | * @param userDisplayName login user |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 164 | */ |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 165 | export function renderWizard(mount: HTMLElement, loginUrl: string, userDisplayName: string): void { |
| 166 | ReactDOM.render(<IssueWizard loginUrl={loginUrl} userDisplayName={userDisplayName}/>, mount); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 167 | } |