Skip to content

Commit 041eeb2

Browse files
committed
[Suggested refactor] Move defaultComparator to data_grid_schema
- since comparators are schema related, and data_grid_schema contains several other similar utility exports/fns - goal is to continue making data_grid_body more encapsulated/focused on (e.g.) display logic and letting other components handle the detailed sort logic + unit tests will be written later for data_grid_schema
1 parent b89f80c commit 041eeb2

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/components/datagrid/body/data_grid_body.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
DataGridSortingContext,
3434
DataGridWrapperRowsContext,
3535
} from '../data_grid_context';
36+
import { defaultComparator } from '../data_grid_schema';
3637
import { EuiDataGridFooterRow } from './data_grid_footer_row';
3738
import { EuiDataGridHeaderRow } from './header';
3839
import {
@@ -47,14 +48,6 @@ import {
4748

4849
export const VIRTUALIZED_CONTAINER_CLASS = 'euiDataGrid__virtualized';
4950

50-
const defaultComparator: NonNullable<
51-
EuiDataGridSchemaDetector['comparator']
52-
> = (a, b, direction) => {
53-
if (a < b) return direction === 'asc' ? -1 : 1;
54-
if (a > b) return direction === 'asc' ? 1 : -1;
55-
return 0;
56-
};
57-
5851
const Cell: FunctionComponent<GridChildComponentProps> = ({
5952
columnIndex,
6053
rowIndex: visibleRowIndex,

src/components/datagrid/data_grid_schema.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ export const schemaDetectors: EuiDataGridSchemaDetector[] = [
210210
},
211211
];
212212

213+
export const defaultComparator: NonNullable<
214+
EuiDataGridSchemaDetector['comparator']
215+
> = (a, b, direction) => {
216+
if (a < b) return direction === 'asc' ? -1 : 1;
217+
if (a > b) return direction === 'asc' ? 1 : -1;
218+
return 0;
219+
};
220+
213221
function scoreValueBySchemaType(
214222
value: string,
215223
schemaDetectors: EuiDataGridSchemaDetector[] = []

0 commit comments

Comments
 (0)