Antonio-RiveroMartnez commented on code in PR #34858: URL: https://github.com/apache/superset/pull/34858#discussion_r2306864201
########## superset-frontend/src/explore/components/controls/SelectControl.jsx: ########## @@ -87,6 +87,56 @@ const defaultProps = { valueKey: 'value', }; +const numberComparator = (a, b) => { + const aVal = typeof a.value === 'number' ? a.value : parseFloat(a.value); + const bVal = typeof b.value === 'number' ? b.value : parseFloat(b.value); + return aVal - bVal; +}; + +export const areAllChoiceValuesNumbers = (choices, valueKey = 'value') => { + if (!choices || choices.length === 0) { + return false; + } + return choices.every(c => { + if (Array.isArray(c)) { + const [value] = c; + return typeof value === 'number'; + } + if (typeof c === 'object' && c !== null) { + return typeof c[valueKey] === 'number'; + } + return typeof c === 'number'; + }); +}; + +export const areAllOptionValuesNumbers = (options, valueKey = 'value') => { + if (!options || options.length === 0) { + return false; + } + return options.every(o => typeof o[valueKey] === 'number'); +}; + +export const getSortComparator = ( + choices, Review Comment: nit: Could have add some types here? ########## superset-frontend/src/explore/components/controls/SelectControl.jsx: ########## @@ -87,6 +87,56 @@ const defaultProps = { valueKey: 'value', }; +const numberComparator = (a, b) => { + const aVal = typeof a.value === 'number' ? a.value : parseFloat(a.value); Review Comment: Isn't the type already checked in `areAllChoiceValuesNumbers` and `areAllOptionValuesNumbers`? ########## superset-frontend/src/explore/components/controls/SelectControl.jsx: ########## @@ -87,6 +87,56 @@ const defaultProps = { valueKey: 'value', }; +const numberComparator = (a, b) => { + const aVal = typeof a.value === 'number' ? a.value : parseFloat(a.value); + const bVal = typeof b.value === 'number' ? b.value : parseFloat(b.value); + return aVal - bVal; +}; + +export const areAllChoiceValuesNumbers = (choices, valueKey = 'value') => { Review Comment: this method and `areAllOptionValuesNumbers` seems very similar, and seems like this could work for both cases? so might be good to just have one `areAllValuesNumbers(...)`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org