Skip to content

Commit

Permalink
fix(shared-data): fix broken RTP choice range formatter util (#16494)
Browse files Browse the repository at this point in the history
We developed a utility function `orderRuntimeParameterRangeOptions` to
order choice-type parameters in the `ParametersTable` and
`ProtocolDetails` components. However, the util incorrectly assumed that
the RTP choice array passed to the utility was of length 2 when it could
also be of length 1. This PR filters the array of any length rather than
explicitly indexing its second element to fix the bug.
  • Loading branch information
ncdiehl11 authored Oct 16, 2024
1 parent ee1aaca commit ce26f3e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions shared-data/js/helpers/orderRuntimeParameterRangeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const isNumeric = (str: string): boolean => {
export const orderRuntimeParameterRangeOptions = (
choices: Choice[]
): string => {
// when this function is called, the array length is always 2
// when this function is called, the array length is always in [1,2]
if (choices.length > 2) {
console.error(`expected to have length 2 but has length ${choices.length}`)
console.error(
`expected to have length [1,2] but has length ${choices.length}`
)
return ''
}
const displayNames = [choices[0].displayName, choices[1].displayName]
const displayNames = choices.map(({ displayName }) => displayName)
if (isNumeric(displayNames[0])) {
return displayNames
.sort((a, b) => {
Expand Down

0 comments on commit ce26f3e

Please sign in to comment.