Skip to content

Commit 44c345c

Browse files
committed
DataViews: filterSortAndPaginate should ignore sorting on non-sortable field
1 parent 96f35c0 commit 44c345c

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

packages/dataviews/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- DataViews: Apply primary style to first column if there is no title field. [#73729](https://github.com/WordPress/gutenberg/pull/73729)
1313
- DataViews: Combined field alignment in table layout. [#73908](https://github.com/WordPress/gutenberg/pull/73908)
1414
- DataViews: Fix table row multiselection in Firefox [#73945](https://github.com/WordPress/gutenberg/pull/73945)
15+
- DataViews: `filterSortAndPaginate()` will ignore sorting on non-sortable fields [#73950](https://github.com/WordPress/gutenberg/pull/73950)
1516

1617
### Enhancements
1718

packages/dataviews/src/test/filter-sort-and-paginate.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,30 @@ describe( 'sorting', () => {
11361136

11371137
expect( groupCount ).toBe( 5 );
11381138
} );
1139+
1140+
it( 'should NOT sort the data if the field is not sortable', () => {
1141+
const { data: result } = filterSortAndPaginate(
1142+
data,
1143+
{
1144+
sort: { field: 'description', direction: 'asc' },
1145+
filters: [
1146+
{
1147+
field: 'type',
1148+
operator: 'is',
1149+
value: 'Terrestrial',
1150+
},
1151+
],
1152+
},
1153+
fields
1154+
);
1155+
1156+
expect( result.map( ( r ) => r.name.description ) ).toEqual( [
1157+
'Terrestrial planet in the Solar system',
1158+
'La planète Vénus',
1159+
'Terrestrial planet in the Solar system',
1160+
'Terrestrial planet in the Solar system',
1161+
] );
1162+
} );
11391163
} );
11401164

11411165
describe( 'pagination', () => {

packages/dataviews/src/utils/filter-sort-and-paginate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,10 @@ export default function filterSortAndPaginate< Item >(
389389
// Handle sorting.
390390
const sortByField = view.sort?.field
391391
? _fields.find( ( field ) => {
392-
return field.id === view.sort?.field;
392+
return (
393+
field.enableSorting !== false &&
394+
field.id === view.sort?.field
395+
);
393396
} )
394397
: null;
395398
const groupByField = view.groupBy?.field

0 commit comments

Comments
 (0)