Skip to content

Conversation

@jmgasper
Copy link
Collaborator

@jmgasper jmgasper commented Nov 2, 2025

Feat/ Fix for page crashing when editing a scorecard

@jmgasper jmgasper requested a review from kkartunov as a code owner November 2, 2025 05:17
@jmgasper jmgasper merged commit 45f9452 into dev Nov 2, 2025
4 of 6 checks passed
)
{options.map((option, index) => (
<option
key={`${option.value ?? option.label ?? index}-${index}`}
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
Using option.value ?? '' for the value attribute may lead to unexpected behavior if option.value is null or undefined. Consider explicitly handling these cases to ensure the value attribute is always a valid string.

control: form.control,
defaultValue: [],
name: props.fieldName,
}) as { weight?: number | string | null }[] | undefined
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
Casting useWatch result to { weight?: number | string | null }[] | undefined could lead to runtime errors if the structure of the watched fields changes. Consider adding runtime validation to ensure the structure matches expectations.

const weightsSum = useMemo(
() => fields.reduce(
(sum: number, field: { weight?: string | number | null }) => (
Number(field?.weight ?? 0) + sum
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
Using Number(field?.weight ?? 0) is safe here, but be aware that Number will convert non-numeric strings to NaN, which might not be the intended behavior. Consider validating or sanitizing field.weight before conversion if there's a risk of unexpected input.

QA: 'QUALITY_ASSURANCE',
}

const normalizeTrackOptionValue = (track: useFetchChallengeTracksProps['challengeTracks'][number]): 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 normalizeTrackOptionValue function uses track.track and track.name without checking if these properties exist on the track object. Consider adding type checks or default values to prevent runtime errors if these properties are undefined.

const { challengeTypes }: useFetchChallengeTypesProps = useFetchChallengeTypes()
const { getValues, setValue } = form
const normalizeValue = useCallback((
value: string | number | boolean | null | undefined,
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The normalizeValue function converts any input to a string and trims it. This might lead to unexpected behavior if the input is a non-string type, such as a number or boolean. Consider handling different types explicitly or documenting the expected input types.

), [challengeTracks])

const fallbackChallengeTrack = useMemo(
() => challengeTrackOptions.find(option => option.value)?.value,
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The fallbackChallengeTrack logic assumes that the first active track option is always valid. This might lead to incorrect fallback behavior if the options are not properly filtered or sorted. Consider adding validation or sorting logic to ensure the correct fallback is selected.

), [challengeTypes])

const fallbackChallengeType = useMemo(
() => challengeTypeOptions.find(option => option.value)?.value,
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The fallbackChallengeType logic assumes that the first active type option is always valid. Similar to fallbackChallengeTrack, this might lead to incorrect fallback behavior if the options are not properly filtered or sorted. Consider adding validation or sorting logic to ensure the correct fallback is selected.

const shouldNormalizeType = useRef(true)

useEffect(() => {
if (!shouldNormalizeTrack.current) {
Copy link

Choose a reason for hiding this comment

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

[💡 maintainability]
The use of useRef for shouldNormalizeTrack and shouldNormalizeType flags is correct but could be improved by ensuring these flags are reset appropriately after normalization logic is executed. Consider adding more explicit control over these flags to prevent unintended behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants