diff --git a/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/sortAlphanumericCaseInsensitive.ts b/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/sortAlphanumericCaseInsensitive.ts index 789e0cef7f75e..c1adc99949a23 100644 --- a/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/sortAlphanumericCaseInsensitive.ts +++ b/superset-frontend/plugins/plugin-chart-table/src/DataTable/utils/sortAlphanumericCaseInsensitive.ts @@ -33,5 +33,5 @@ export const sortAlphanumericCaseInsensitive = ( if (!valueB || typeof valueB !== 'string') { return 1; } - return valueA.localeCompare(valueB) > 0 ? 1 : -1; + return valueA.localeCompare(valueB); }; diff --git a/superset-frontend/plugins/plugin-chart-table/test/sortAlphanumericCaseInsensitive.test.ts b/superset-frontend/plugins/plugin-chart-table/test/sortAlphanumericCaseInsensitive.test.ts index 4ba35ba602d51..356596ec21061 100644 --- a/superset-frontend/plugins/plugin-chart-table/test/sortAlphanumericCaseInsensitive.test.ts +++ b/superset-frontend/plugins/plugin-chart-table/test/sortAlphanumericCaseInsensitive.test.ts @@ -17,8 +17,13 @@ * under the License. */ +import { defaultOrderByFn, Row } from 'react-table'; import { sortAlphanumericCaseInsensitive } from '../src/DataTable/utils/sortAlphanumericCaseInsensitive'; +type RecursivePartial = { + [P in keyof T]?: T[P] | RecursivePartial; +}; + const testData = [ { values: { @@ -133,3 +138,106 @@ describe('sortAlphanumericCaseInsensitive', () => { ]); }); }); + +const testDataMulti: Array>> = [ + { + values: { + colA: 'group 1', + colB: '10', + }, + }, + { + values: { + colA: 'group 1', + colB: '15', + }, + }, + { + values: { + colA: 'group 1', + colB: '20', + }, + }, + { + values: { + colA: 'group 2', + colB: '10', + }, + }, + { + values: { + colA: 'group 3', + colB: '10', + }, + }, + { + values: { + colA: 'group 3', + colB: '15', + }, + }, + { + values: { + colA: 'group 3', + colB: '10', + }, + }, +]; + +describe('sortAlphanumericCaseInsensitiveMulti', () => { + it('Sort rows', () => { + const sorted = defaultOrderByFn( + [...testDataMulti] as Array>, + [ + (a, b) => sortAlphanumericCaseInsensitive(a, b, 'colA'), + (a, b) => sortAlphanumericCaseInsensitive(a, b, 'colB'), + ], + [true, false], + ); + + expect(sorted).toEqual([ + { + values: { + colA: 'group 1', + colB: '20', + }, + }, + { + values: { + colA: 'group 1', + colB: '15', + }, + }, + { + values: { + colA: 'group 1', + colB: '10', + }, + }, + { + values: { + colA: 'group 2', + colB: '10', + }, + }, + { + values: { + colA: 'group 3', + colB: '15', + }, + }, + { + values: { + colA: 'group 3', + colB: '10', + }, + }, + { + values: { + colA: 'group 3', + colB: '10', + }, + }, + ]); + }); +});