Run prettier

This commit is contained in:
c-bata
2021-02-22 22:35:17 +09:00
parent aeef6ca5c5
commit 207ae862e7
2 changed files with 21 additions and 12 deletions
+15 -10
View File
@@ -72,7 +72,7 @@ function DataGrid<T>(props: {
const { columns, rows, keyField, dense, collapseBody } = props
let { initialRowsPerPage, rowsPerPageOption } = props
const [order, setOrder] = React.useState<Order>("asc")
const [orderBy, setOrderBy] = React.useState<number>(0) // index of columns
const [orderBy, setOrderBy] = React.useState<number>(0) // index of columns
const [page, setPage] = React.useState(0)
const [filters, setFilters] = React.useState<RowFilter<T>[]>([])
@@ -133,7 +133,12 @@ function DataGrid<T>(props: {
setOrderBy(columnId)
}
const lessFunc = columns[orderBy].less
const sortedRows = stableSort<T>(filteredRows, getComparator(order, columns, orderBy), order, lessFunc)
const sortedRows = stableSort<T>(
filteredRows,
getComparator(order, columns, orderBy),
order,
lessFunc
)
const currentPageRows =
rowsPerPage > 0
? sortedRows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
@@ -311,10 +316,10 @@ function getComparator<T>(
}
function descendingComparator<T>(
a: T,
b: T,
columns: DataGridColumn<T>[],
orderBy: number
a: T,
b: T,
columns: DataGridColumn<T>[],
orderBy: number
): number {
const field = columns[orderBy].field
if (b[field] < a[field]) {
@@ -327,10 +332,10 @@ function descendingComparator<T>(
}
function stableSort<T>(
array: T[],
comparator: (a: T, b: T) => number,
order: Order,
less?: (i: number, j: number) => number
array: T[],
comparator: (a: T, b: T) => number,
order: Order,
less?: (i: number, j: number) => number
) {
const stabilizedThis = array.map((el, index) => [el, index] as [T, number])
stabilizedThis.sort((a, b) => {
@@ -245,14 +245,18 @@ const TrialTable: FC<{ studyDetail: StudyDetail | null }> = ({
label: `Objective ${objectiveId}`,
sortable: true,
less: (i, j): number => {
if (trials[i].values?.[objectiveId] === trials[j].values?.[objectiveId]) {
if (
trials[i].values?.[objectiveId] === trials[j].values?.[objectiveId]
) {
return 0
} else if (trials[i].values === undefined) {
return -1
} else if (trials[j].values === undefined) {
return 1
}
return trials[i].values![objectiveId] < trials[j].values![objectiveId] ? 1 : -1
return trials[i].values![objectiveId] < trials[j].values![objectiveId]
? 1
: -1
},
toCellValue: (i) => trials[i].values?.[objectiveId] || null,
}))