Skip to content

Commit

Permalink
Merge pull request #1883 from specify/issue-1880
Browse files Browse the repository at this point in the history
Fix query table sorting not accounting for hidden fields
  • Loading branch information
grantfitzsimmons authored Jul 23, 2022
2 parents e352836 + 9a59df3 commit d9776d6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions specifyweb/frontend/js_src/lib/components/queryresultstable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export function QueryResultsTable({
readonly sortConfig?: RA<QueryField['sortType']>;
readonly onSelected?: (resource: RA<number>) => void;
readonly onSortChange?: (
fieldIndex: number,
fieldSpec: QueryFieldSpec,
direction: 'ascending' | 'descending' | undefined
) => void;
readonly createRecordSet: JSX.Element | undefined;
Expand Down Expand Up @@ -469,7 +469,8 @@ export function QueryResultsTable({
sortConfig={sortConfig?.[index]}
onSortChange={
typeof handleSortChange === 'function'
? (sortType): void => handleSortChange?.(index, sortType)
? (sortType): void =>
handleSortChange?.(fieldSpec, sortType)
: undefined
}
/>
Expand Down Expand Up @@ -642,8 +643,22 @@ export function QueryResultsWrapper({
totalCount,
fieldSpecs,
initialData,
sortConfig: fields.map((field) => field.sortType),
onSortChange: handleSortChange,
sortConfig: fields
.filter(({ isDisplay }) => isDisplay)
.map(({ sortType }) => sortType),
onSortChange:
typeof handleSortChange === 'function'
? (fieldSpec, direction) => {
/*
* If some fields are not displayed, visual index and actual
* field index differ
*/
const index = fieldSpecs.indexOf(fieldSpec);
const field = displayedFields[index];
const originalIndex = allFields.indexOf(field);
handleSortChange(originalIndex, direction);
}
: undefined,
createRecordSet,
extraButtons,
})
Expand Down

0 comments on commit d9776d6

Please sign in to comment.