From 91c52f599bdd0ba9ca2454fcf6d2d1452480c013 Mon Sep 17 00:00:00 2001 From: c-bata Date: Mon, 22 Feb 2021 22:55:16 +0900 Subject: [PATCH] Add a refactor change --- optuna_dashboard/static/components/DataGrid.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/optuna_dashboard/static/components/DataGrid.tsx b/optuna_dashboard/static/components/DataGrid.tsx index e0c44f63..18b32890 100644 --- a/optuna_dashboard/static/components/DataGrid.tsx +++ b/optuna_dashboard/static/components/DataGrid.tsx @@ -132,13 +132,7 @@ function DataGrid(props: { setOrder(isAsc ? "desc" : "asc") setOrderBy(columnId) } - const lessFunc = columns[orderBy].less - const sortedRows = stableSort( - filteredRows, - getComparator(order, columns, orderBy), - order, - lessFunc - ) + const sortedRows = stableSort(filteredRows, order, orderBy, columns) const currentPageRows = rowsPerPage > 0 ? sortedRows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) @@ -333,10 +327,13 @@ function descendingComparator( function stableSort( array: T[], - comparator: (a: T, b: T) => number, order: Order, - less?: (i: number, j: number) => number + orderBy: number, + columns: DataGridColumn[] ) { + // TODO(c-bata): Refactor here by implementing as the same comparator interface. + const less = columns[orderBy].less + const comparator = getComparator(order, columns, orderBy) const stabilizedThis = array.map((el, index) => [el, index] as [T, number]) stabilizedThis.sort((a, b) => { if (less) {