diff --git a/packages/ts/react-crud/src/data-provider.ts b/packages/ts/react-crud/src/data-provider.ts index 6410ee04d2..f1f7483132 100644 --- a/packages/ts/react-crud/src/data-provider.ts +++ b/packages/ts/react-crud/src/data-provider.ts @@ -5,6 +5,7 @@ import type { CountService, ListService } from './crud'; import type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion'; import type Sort from './types/com/vaadin/hilla/mappedtypes/Sort'; import Direction from './types/org/springframework/data/domain/Sort/Direction'; +import NullHandling from './types/org/springframework/data/domain/Sort/NullHandling'; type MaybeCountService = Partial>; type ListAndMaybeCountService = ListService & MaybeCountService; @@ -42,6 +43,7 @@ function createSort(params: GridDataProviderParams): Sort { property: order.path, direction: order.direction === 'asc' ? Direction.ASC : Direction.DESC, ignoreCase: false, + nullHandling: NullHandling.NATIVE, })), }; } diff --git a/packages/ts/react-crud/test/autogrid.spec.tsx b/packages/ts/react-crud/test/autogrid.spec.tsx index 01167a7d98..fc381aa3bc 100644 --- a/packages/ts/react-crud/test/autogrid.spec.tsx +++ b/packages/ts/react-crud/test/autogrid.spec.tsx @@ -17,6 +17,7 @@ import Matcher from '../src/types/com/vaadin/hilla/crud/filter/PropertyStringFil import type PropertyStringFilter from '../src/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.js'; import type Sort from '../src/types/com/vaadin/hilla/mappedtypes/Sort.js'; import Direction from '../src/types/org/springframework/data/domain/Sort/Direction.js'; +import NullHandling from '../src/types/org/springframework/data/domain/Sort/NullHandling.js'; import type FilterUnion from '../types/com/vaadin/hilla/crud/filter/FilterUnion'; import GridController from './GridController.js'; import SelectController from './SelectController.js'; @@ -138,7 +139,11 @@ describe('@vaadin/hilla-react-crud', () => { const service = personService(); const grid = await GridController.init(render(), user); - const expectedSort: Sort = { orders: [{ property: 'firstName', direction: Direction.ASC, ignoreCase: false }] }; + const expectedSort: Sort = { + orders: [ + { property: 'firstName', direction: Direction.ASC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, + ], + }; expect(service.lastSort).to.deep.equal(expectedSort); await expect(grid.getSortOrder()).to.eventually.deep.equal([ { property: 'firstName', direction: Direction.ASC }, @@ -166,7 +171,9 @@ describe('@vaadin/hilla-react-crud', () => { await grid.sort('firstName', 'desc'); const expectedSort: Sort = { - orders: [{ property: 'firstName', direction: Direction.DESC, ignoreCase: false }], + orders: [ + { property: 'firstName', direction: Direction.DESC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, + ], }; expect(service.lastSort).to.deep.equal(expectedSort); await expect(grid.getSortOrder()).to.eventually.deep.equal([ @@ -490,9 +497,12 @@ describe('@vaadin/hilla-react-crud', () => { }); it('sorts according to first column by default', async () => { - expect(service.lastSort).to.deep.equal({ - orders: [{ property: 'firstName', direction: Direction.ASC, ignoreCase: false }], - }); + const expectedSort = { + orders: [ + { property: 'firstName', direction: Direction.ASC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, + ], + }; + expect(service.lastSort).to.deep.equal(expectedSort); await expect(grid.getSortOrder()).to.eventually.deep.equal([ { property: 'firstName', direction: Direction.ASC }, @@ -503,8 +513,8 @@ describe('@vaadin/hilla-react-crud', () => { await grid.sort('lastName', 'asc'); expect(service.lastSort).to.deep.equal({ orders: [ - { property: 'firstName', direction: Direction.ASC, ignoreCase: false }, - { property: 'lastName', direction: Direction.ASC, ignoreCase: false }, + { property: 'firstName', direction: Direction.ASC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, + { property: 'lastName', direction: Direction.ASC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, ], }); @@ -516,8 +526,8 @@ describe('@vaadin/hilla-react-crud', () => { await grid.sort('lastName', 'desc'); expect(service.lastSort).to.deep.equal({ orders: [ - { property: 'firstName', direction: Direction.ASC, ignoreCase: false }, - { property: 'lastName', direction: Direction.DESC, ignoreCase: false }, + { property: 'firstName', direction: Direction.ASC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, + { property: 'lastName', direction: Direction.DESC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, ], }); @@ -528,7 +538,9 @@ describe('@vaadin/hilla-react-crud', () => { await grid.sort('lastName', null); expect(service.lastSort).to.deep.equal({ - orders: [{ property: 'firstName', direction: Direction.ASC, ignoreCase: false }], + orders: [ + { property: 'firstName', direction: Direction.ASC, ignoreCase: false, nullHandling: NullHandling.NATIVE }, + ], }); await expect(grid.getSortOrder()).to.eventually.deep.equal([ diff --git a/packages/ts/react-crud/test/dataprovider.spec.tsx b/packages/ts/react-crud/test/dataprovider.spec.tsx index 62ee272c5a..fc9d21f03e 100644 --- a/packages/ts/react-crud/test/dataprovider.spec.tsx +++ b/packages/ts/react-crud/test/dataprovider.spec.tsx @@ -4,14 +4,15 @@ import type { GridDataProvider, GridSorterDefinition } from '@vaadin/react-compo import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import type { CountService, ListService } from '../crud.js'; -import { DataProvider } from '../src/data-provider.js'; import { createDataProvider, + DataProvider, FixedSizeDataProvider, InfiniteDataProvider, useDataProvider, type ItemCounts, } from '../src/data-provider.js'; +import NullHandling from '../src/types/org/springframework/data/domain/Sort/NullHandling.js'; import type AndFilter from '../types/com/vaadin/hilla/crud/filter/AndFilter.js'; import type FilterUnion from '../types/com/vaadin/hilla/crud/filter/FilterUnion.js'; import Matcher from '../types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js'; @@ -203,11 +204,15 @@ describe('@hilla/react-crud', () => { await grid.requestPage(0, [{ path: 'foo', direction: 'asc' }]); pageable = listSpy.lastCall.args[0]; - expect(pageable.sort).to.eql({ orders: [{ property: 'foo', direction: 'ASC', ignoreCase: false }] }); + expect(pageable.sort).to.eql({ + orders: [{ property: 'foo', direction: 'ASC', ignoreCase: false, nullHandling: NullHandling.NATIVE }], + }); await grid.requestPage(0, [{ path: 'bar', direction: 'desc' }]); pageable = listSpy.lastCall.args[0]; - expect(pageable.sort).to.eql({ orders: [{ property: 'bar', direction: 'DESC', ignoreCase: false }] }); + expect(pageable.sort).to.eql({ + orders: [{ property: 'bar', direction: 'DESC', ignoreCase: false, nullHandling: NullHandling.NATIVE }], + }); }); it('utilizes count from listAndCountService and call it only once', async () => { @@ -308,11 +313,15 @@ describe('@hilla/react-crud', () => { await grid.requestPage(0, [{ path: 'foo', direction: 'asc' }]); pageable = listSpy.lastCall.args[0]; - expect(pageable.sort).to.eql({ orders: [{ property: 'foo', direction: 'ASC', ignoreCase: false }] }); + expect(pageable.sort).to.eql({ + orders: [{ property: 'foo', direction: 'ASC', ignoreCase: false, nullHandling: NullHandling.NATIVE }], + }); await grid.requestPage(0, [{ path: 'bar', direction: 'desc' }]); pageable = listSpy.lastCall.args[0]; - expect(pageable.sort).to.eql({ orders: [{ property: 'bar', direction: 'DESC', ignoreCase: false }] }); + expect(pageable.sort).to.eql({ + orders: [{ property: 'bar', direction: 'DESC', ignoreCase: false, nullHandling: NullHandling.NATIVE }], + }); }); it('passes filter to service', async () => { @@ -438,11 +447,15 @@ describe('@hilla/react-crud', () => { await grid.requestPage(0, [{ path: 'foo', direction: 'asc' }]); pageable = listSpy.lastCall.args[0]; - expect(pageable.sort).to.eql({ orders: [{ property: 'foo', direction: 'ASC', ignoreCase: false }] }); + expect(pageable.sort).to.eql({ + orders: [{ property: 'foo', direction: 'ASC', ignoreCase: false, nullHandling: NullHandling.NATIVE }], + }); await grid.requestPage(0, [{ path: 'bar', direction: 'desc' }]); pageable = listSpy.lastCall.args[0]; - expect(pageable.sort).to.eql({ orders: [{ property: 'bar', direction: 'DESC', ignoreCase: false }] }); + expect(pageable.sort).to.eql({ + orders: [{ property: 'bar', direction: 'DESC', ignoreCase: false, nullHandling: NullHandling.NATIVE }], + }); }); it('passes filter to service', async () => {