Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ export const DefaultReviewersAddForm: FC<Props> = (props: Props) => {

const onSubmit = useCallback(
(data: FormAddDefaultReviewer) => {
const requestBody = _.pickBy(data, _.identity)
const requestBody = _.omitBy(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Switching from _.pickBy to _.omitBy changes the logic to exclude certain values. Ensure that excluding empty strings, null, and undefined is intended and does not affect required fields or default values.

data,
value => value === undefined || value === null || value === '',
)
if (isEdit) {
doUpdateDefaultReviewer(requestBody, () => {
navigate('./../..')
Expand Down
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Converting value to a string using String(value) may lead to unexpected results if value is an object or a symbol. Consider ensuring value is always a primitive type before this conversion.

const displayValue = typeof mapValue === 'function'
? mapValue(normalizedValue)
: normalizedValue

return (
<select
Expand All @@ -25,7 +35,7 @@ const BasicSelect = forwardRef<HTMLSelectElement, BasicSelectProps<any>>((
!normalizedValue && `${normalizedValue}` !== 'false' && 'empty',
)
}
value={normalizedValue as any}
value={displayValue}
>
<option
key='placeholder-option'
Expand All @@ -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)}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Using String(option.value ?? option.label) as a key may lead to duplicate keys if option.value or option.label are not unique. Ensure that each option has a unique key to prevent rendering issues.

value={String(option.value ?? '')}
>
{option.label}
</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ const toChallengeTrackLabel = (value: string): string => (
)

const legacyChallengeTrackMap: Record<string, string> = {
DEVELOPMENT: 'DEVELOPMENT',
DEVELOP: 'DEVELOPMENT',
QUALITY_ASSURANCE: 'QUALITY_ASSURANCE',
DEVELOPMENT: 'DEVELOPMENT',
QA: 'QUALITY_ASSURANCE',
QUALITY_ASSURANCE: 'QUALITY_ASSURANCE',
}

const normalizeTrackOptionValue = (track: useFetchChallengeTracksProps['challengeTracks'][number]): string => {
Expand Down Expand Up @@ -140,15 +140,16 @@ const ScorecardInfoForm: FC = () => {
const form = useFormContext()
const { challengeTracks }: useFetchChallengeTracksProps = useFetchChallengeTracks()
const { challengeTypes }: useFetchChallengeTypesProps = useFetchChallengeTypes()
const { getValues, setValue } = form
const { getValues, setValue }: Pick<typeof form, 'getValues' | 'setValue'> = form
const normalizeValue = useCallback((
value: string | number | boolean | null | undefined,
): string | undefined => {
if (value === null || value === undefined) {
return undefined
}

const normalized = String(value).trim()
const normalized = String(value)
.trim()

return normalized.length ? normalized : undefined
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The mapValue function now handles value as string | number | boolean | ''. Ensure that String(value ?? '') correctly handles all expected cases, especially for boolean values, as this could lead to unexpected string representations like 'true' or 'false'.

? value
: String(value ?? '')
return `${stringValue.toLowerCase()}${
stringValue === 'SCALE'
? `(${
get(values, `${name}.${index}.scaleMin`)
}-${
get(values, `${name}.${index}.scaleMax`)
})`
: ''
}`
),
},
onChange: ((
ev: ChangeEvent<HTMLInputElement>,
field: any,
Expand Down