Skip to content

Commit 3b25f08

Browse files
authored
Merge pull request #1211 from topcoder-platform/PM-1504_edit-create-scorecard
PM-1504 - scorecard: Make category options dependent on project type
2 parents 31d9989 + 29a3deb commit 3b25f08

File tree

1 file changed

+73
-57
lines changed

1 file changed

+73
-57
lines changed
Lines changed: 73 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as yup from 'yup'
2-
import { FC } from 'react'
2+
import { FC, useMemo } from 'react'
3+
import { useFormContext } from 'react-hook-form'
34
import classNames from 'classnames'
45

56
import {
7+
categoryByProjectType,
8+
ProjectType,
69
ProjectTypeLabels,
710
scorecardCategories,
811
ScorecardStatusLabels,
@@ -19,7 +22,14 @@ const statusOptions = Object.entries(ScorecardStatusLabels)
1922
.map(([value, label]) => ({ label, value }))
2023
const typeOptions = Object.entries(ScorecardTypeLabels)
2124
.map(([value, label]) => ({ label, value }))
22-
const categoryOptions = scorecardCategories.map(key => ({ label: key, value: key }))
25+
const categoryOptions = (projectType?: ProjectType): { label: string; value: string }[] => {
26+
let categories = scorecardCategories
27+
if (projectType) {
28+
categories = categoryByProjectType[projectType]
29+
}
30+
31+
return categories.map(key => ({ label: key, value: key }))
32+
}
2333

2434
export const scorecardInfoSchema = {
2535
challengeTrack: yup.string()
@@ -47,67 +57,73 @@ export const scorecardInfoSchema = {
4757
.required('Version is required'),
4858
}
4959

50-
const ScorecardInfoForm: FC = () => (
51-
<div className={classNames(styles.grayWrapper, styles.scorecardInfo)}>
52-
<InputWrapper
53-
label='Scorecard Name'
54-
name='name'
55-
className={styles.mdWidthInput}
56-
>
57-
<input type='text' />
58-
</InputWrapper>
59-
<InputWrapper
60-
label='Category'
61-
name='challengeType'
62-
className={styles.mdWidthInput}
63-
>
64-
<BasicSelect options={categoryOptions} />
65-
</InputWrapper>
66-
<InputWrapper
67-
label='Version'
68-
name='version'
69-
className={styles.mdWidthInput}
70-
>
71-
<input type='text' />
72-
</InputWrapper>
73-
<InputWrapper
74-
label='Status'
75-
name='status'
76-
className={styles.mdWidthInput}
77-
>
78-
<BasicSelect options={statusOptions} />
79-
</InputWrapper>
80-
<InputWrapper
81-
label='Type'
82-
name='type'
83-
className={styles.mdWidthInput}
84-
>
85-
<BasicSelect options={typeOptions} />
86-
</InputWrapper>
87-
<div className={classNames(styles.mdWidthInput, styles.doubleInputWrap)}>
60+
const ScorecardInfoForm: FC = () => {
61+
const form = useFormContext()
62+
const challengeTrack = form.watch('challengeTrack')
63+
const categories = useMemo(() => categoryOptions(challengeTrack), [challengeTrack])
64+
65+
return (
66+
<div className={classNames(styles.grayWrapper, styles.scorecardInfo)}>
67+
<InputWrapper
68+
label='Scorecard Name'
69+
name='name'
70+
className={styles.mdWidthInput}
71+
>
72+
<input type='text' />
73+
</InputWrapper>
74+
<InputWrapper
75+
label='Category'
76+
name='challengeType'
77+
className={styles.mdWidthInput}
78+
>
79+
<BasicSelect options={categories} />
80+
</InputWrapper>
81+
<InputWrapper
82+
label='Version'
83+
name='version'
84+
className={styles.mdWidthInput}
85+
>
86+
<input type='text' />
87+
</InputWrapper>
8888
<InputWrapper
89-
label='Min. Score'
90-
name='minScore'
91-
className={styles.qWidthInput}
89+
label='Status'
90+
name='status'
91+
className={styles.mdWidthInput}
9292
>
93-
<input type='number' />
93+
<BasicSelect options={statusOptions} />
9494
</InputWrapper>
9595
<InputWrapper
96-
label='Max. Score'
97-
name='maxScore'
98-
className={styles.qWidthInput}
96+
label='Type'
97+
name='type'
98+
className={styles.mdWidthInput}
9999
>
100-
<input type='number' />
100+
<BasicSelect options={typeOptions} />
101+
</InputWrapper>
102+
<div className={classNames(styles.mdWidthInput, styles.doubleInputWrap)}>
103+
<InputWrapper
104+
label='Min. Score'
105+
name='minScore'
106+
className={styles.qWidthInput}
107+
>
108+
<input type='number' />
109+
</InputWrapper>
110+
<InputWrapper
111+
label='Max. Score'
112+
name='maxScore'
113+
className={styles.qWidthInput}
114+
>
115+
<input type='number' />
116+
</InputWrapper>
117+
</div>
118+
<InputWrapper
119+
label='Project Type'
120+
name='challengeTrack'
121+
className={styles.mdWidthInput}
122+
>
123+
<BasicSelect options={projectTypeOptions} />
101124
</InputWrapper>
102125
</div>
103-
<InputWrapper
104-
label='Project Type'
105-
name='challengeTrack'
106-
className={styles.mdWidthInput}
107-
>
108-
<BasicSelect options={projectTypeOptions} />
109-
</InputWrapper>
110-
</div>
111-
)
126+
)
127+
}
112128

113129
export default ScorecardInfoForm

0 commit comments

Comments
 (0)