({
specifier: specifier_,
question,
enableBucketGroups
}: {
specifier?: SortSpecifier
question: QuestionApiObject
enableBucketGroups?: boolean
})
| 117 | } |
| 118 | |
| 119 | const getQuestionSort = ({ |
| 120 | specifier: specifier_, |
| 121 | question, |
| 122 | enableBucketGroups |
| 123 | }: { |
| 124 | specifier?: SortSpecifier |
| 125 | question: QuestionApiObject |
| 126 | enableBucketGroups?: boolean |
| 127 | }) => { |
| 128 | let defaultSort: SortProperty, |
| 129 | defaultOrder: SortOrder = 'desc' |
| 130 | if (enableBucketGroups && question.groups) { |
| 131 | // if we're grouping, use group order |
| 132 | // assume options are organized in ascending order, |
| 133 | // i.e. from low to high age, salary, etc. |
| 134 | defaultSort = 'options' |
| 135 | defaultOrder = 'asc' |
| 136 | } else if (question.defaultSort) { |
| 137 | // if question has a default sort, use it |
| 138 | defaultSort = question.defaultSort |
| 139 | } else if (question.optionsAreSequential) { |
| 140 | if (question.options) { |
| 141 | // assume options are organized in ascending order, |
| 142 | // i.e. from low to high age, salary, etc. |
| 143 | defaultSort = 'options' |
| 144 | defaultOrder = 'asc' |
| 145 | } else { |
| 146 | // values are numeric but no options are specified, in this case |
| 147 | // sort by id to get a nice curve of successive number |
| 148 | defaultSort = 'id' |
| 149 | defaultOrder = 'asc' |
| 150 | } |
| 151 | } else { |
| 152 | // default to sorting by bucket count |
| 153 | defaultSort = 'count' |
| 154 | } |
| 155 | const specifier = { |
| 156 | sort: defaultSort, |
| 157 | order: defaultOrder |
| 158 | } |
| 159 | // if sort/order have been explicitly passed, use that instead |
| 160 | if (specifier_?.property) { |
| 161 | specifier.sort = specifier_?.property |
| 162 | } |
| 163 | if (specifier_?.order) { |
| 164 | specifier.order = specifier_?.order |
| 165 | } |
| 166 | // console.log('=====') |
no test coverage detected