-
Notifications
You must be signed in to change notification settings - Fork 21
Lint fixes #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lint fixes #1289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,29 @@ | ||
| import { forwardRef, SelectHTMLAttributes } from 'react' | ||
| import classNames from 'classnames' | ||
|
|
||
| interface BasicSelectProps<T> extends SelectHTMLAttributes<T> { | ||
| options: { label: string; value: string|boolean|number }[]; | ||
| mapValue?: (value: any) => string; | ||
| interface BasicSelectProps extends SelectHTMLAttributes<HTMLSelectElement> { | ||
| options: { label: string; value: string | boolean | number }[]; | ||
| mapValue?: (value: string | number | boolean | '') => string; | ||
| placeholder?: string; | ||
| } | ||
|
|
||
| const BasicSelect = forwardRef<HTMLSelectElement, BasicSelectProps<any>>(( | ||
| props, | ||
| const BasicSelect = forwardRef<HTMLSelectElement, BasicSelectProps>(( | ||
| props: BasicSelectProps, | ||
| ref, | ||
| ) => { | ||
| const { className, options, placeholder, value, mapValue: _mapValue, ...rest } = props | ||
| const { | ||
| className, | ||
| options, | ||
| placeholder, | ||
| value, | ||
| mapValue, | ||
| ...rest | ||
| }: BasicSelectProps = props | ||
|
|
||
| const normalizedValue = value === null || value === undefined ? '' : value | ||
| const normalizedValue = value === null || value === undefined ? '' : String(value) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| const displayValue = typeof mapValue === 'function' | ||
| ? mapValue(normalizedValue) | ||
| : normalizedValue | ||
|
|
||
| return ( | ||
| <select | ||
|
|
@@ -25,7 +35,7 @@ const BasicSelect = forwardRef<HTMLSelectElement, BasicSelectProps<any>>(( | |
| !normalizedValue && `${normalizedValue}` !== 'false' && 'empty', | ||
| ) | ||
| } | ||
| value={normalizedValue as any} | ||
| value={displayValue} | ||
| > | ||
| <option | ||
| key='placeholder-option' | ||
|
|
@@ -34,10 +44,10 @@ const BasicSelect = forwardRef<HTMLSelectElement, BasicSelectProps<any>>(( | |
| > | ||
| {placeholder} | ||
| </option> | ||
| {options.map((option, index) => ( | ||
| {options.map(option => ( | ||
| <option | ||
| key={`${option.value ?? option.label ?? index}-${index}`} | ||
| value={`${option.value ?? ''}`} | ||
| key={String(option.value ?? option.label)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| value={String(option.value ?? '')} | ||
| > | ||
| {option.label} | ||
| </option> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,17 +172,20 @@ const ScorecardQuestionForm: FC<ScorecardQuestionFormProps> = (props: ScorecardQ | |
| <BasicSelect | ||
| options={scorecardScaleOptions} | ||
| {...{ | ||
| mapValue: (value: string) => ( | ||
| `${value?.toLowerCase()}${ | ||
| value === 'SCALE' | ||
| mapValue: (value: string | number | boolean | '') => { | ||
| const stringValue = typeof value === 'string' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| ? value | ||
| : String(value ?? '') | ||
| return `${stringValue.toLowerCase()}${ | ||
| stringValue === 'SCALE' | ||
| ? `(${ | ||
| get(values, `${name}.${index}.scaleMin`) | ||
| }-${ | ||
| get(values, `${name}.${index}.scaleMax`) | ||
| })` | ||
| : '' | ||
| }` | ||
| ), | ||
| }, | ||
| onChange: (( | ||
| ev: ChangeEvent<HTMLInputElement>, | ||
| field: any, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗
correctness]Switching from
_.pickByto_.omitBychanges the logic to exclude certain values. Ensure that excluding empty strings,null, andundefinedis intended and does not affect required fields or default values.