diff --git a/tslib/src/components/DataGrid.tsx b/tslib/src/components/DataGrid.tsx index 3aa7ffc3..72918b9d 100644 --- a/tslib/src/components/DataGrid.tsx +++ b/tslib/src/components/DataGrid.tsx @@ -15,8 +15,7 @@ import { useTheme, } from "@mui/material"; import { styled } from "@mui/system"; -import { Fragment, useState } from "react"; -import { DataGridColumn } from "./DataGridColumn"; +import React from "react"; type Order = "asc" | "desc"; @@ -25,6 +24,16 @@ type Value = any; const defaultRowsPerPageOption = [10, 50, 100, { label: "All", value: -1 }]; +interface DataGridColumn { + field: keyof T; + label: string; + sortable?: boolean; + less?: (a: T, b: T, ascending: boolean) => number; + filterable?: boolean; + toCellValue?: (rowIndex: number) => string | React.ReactNode; + padding?: "normal" | "checkbox" | "none"; +} + interface RowFilter { columnIdx: number; value: Value; @@ -42,10 +51,10 @@ function DataGrid(props: { }): React.ReactElement { const { columns, rows, keyField, dense, collapseBody, defaultFilter } = props; let { initialRowsPerPage, rowsPerPageOption } = props; - const [order, setOrder] = useState("asc"); - const [orderBy, setOrderBy] = useState(0); // index of columns - const [page, setPage] = useState(0); - const [filters, setFilters] = useState([]); + const [order, setOrder] = React.useState("asc"); + const [orderBy, setOrderBy] = React.useState(0); // index of columns + const [page, setPage] = React.useState(0); + const [filters, setFilters] = React.useState([]); const getRowIndex = (row: T): number => { return rows.findIndex((row2) => row[keyField] === row2[keyField]); @@ -58,7 +67,7 @@ function DataGrid(props: { : isNumber(rowsPerPageOption[0]) ? rowsPerPageOption[0] : rowsPerPageOption[0].value; - const [rowsPerPage, setRowsPerPage] = useState(initialRowsPerPage); + const [rowsPerPage, setRowsPerPage] = React.useState(initialRowsPerPage); const handleChangePage = (_event: unknown, newPage: number) => { setPage(newPage); @@ -247,7 +256,7 @@ function DataGridRow(props: { collapseBody, handleClickFilterCell, } = props; - const [open, setOpen] = useState(false); + const [open, setOpen] = React.useState(false); const theme = useTheme(); const FilterableDiv = styled("div")({ @@ -256,7 +265,7 @@ function DataGridRow(props: { cursor: "pointer", }); return ( - + {collapseBody ? ( @@ -308,7 +317,7 @@ function DataGridRow(props: { ) : null} - + ); } @@ -371,3 +380,4 @@ const isNumber = ( }; export { DataGrid }; +export type { DataGridColumn }; diff --git a/tslib/src/components/DataGridColumn.ts b/tslib/src/components/DataGridColumn.ts deleted file mode 100644 index 19aa381d..00000000 --- a/tslib/src/components/DataGridColumn.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface DataGridColumn { - field: keyof T; - label: string; - sortable?: boolean; - less?: (a: T, b: T, ascending: boolean) => number; - filterable?: boolean; - toCellValue?: (rowIndex: number) => string | React.ReactNode; - padding?: "normal" | "checkbox" | "none"; -} diff --git a/tslib/src/components/TrialTable.tsx b/tslib/src/components/TrialTable.tsx index db125c80..02efed2c 100644 --- a/tslib/src/components/TrialTable.tsx +++ b/tslib/src/components/TrialTable.tsx @@ -1,7 +1,6 @@ import { FC } from "react"; -import { DataGrid } from "./DataGrid"; -import { DataGridColumn } from "./DataGridColumn"; +import { DataGrid, DataGridColumn } from "./DataGrid"; export const TrialTable: FC<{ study: Study; @@ -35,13 +34,9 @@ export const TrialTable: FC<{ } if (firstVal === undefined) { return ascending ? -1 : 1; - } else if (secondVal === undefined) { - return ascending ? 1 : -1; } - if (firstVal === "-inf" || secondVal === "inf") { - return 1; - } else if (secondVal === "-inf" || firstVal === "inf") { - return -1; + if (secondVal === undefined) { + return ascending ? 1 : -1; } return firstVal < secondVal ? 1 : -1; }, @@ -67,13 +62,9 @@ export const TrialTable: FC<{ } if (firstVal === undefined) { return ascending ? -1 : 1; - } else if (secondVal === undefined) { - return ascending ? 1 : -1; } - if (firstVal === "-inf" || secondVal === "inf") { - return 1; - } else if (secondVal === "-inf" || firstVal === "inf") { - return -1; + if (secondVal === undefined) { + return ascending ? 1 : -1; } return firstVal < secondVal ? 1 : -1; }, @@ -97,8 +88,7 @@ export const TrialTable: FC<{ null, sortable: true, filterable: false, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - less: (firstEl, secondEl, _): number => { + less: (firstEl, secondEl): number => { const firstVal = firstEl.params.find( (p) => p.name === s.name, )?.param_internal_value; @@ -108,13 +98,14 @@ export const TrialTable: FC<{ if (firstVal === secondVal) { return 0; - } else if (firstVal && secondVal) { - return firstVal < secondVal ? 1 : -1; - } else if (firstVal) { - return -1; - } else { - return 1; } + if (firstVal && secondVal) { + return firstVal < secondVal ? 1 : -1; + } + if (firstVal) { + return -1; + } + return 1; }, }); }); @@ -128,8 +119,7 @@ export const TrialTable: FC<{ ?.value || null, sortable: attr_spec.sortable, filterable: false, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - less: (firstEl, secondEl, _): number => { + less: (firstEl, secondEl): number => { const firstVal = firstEl.user_attrs.find( (attr) => attr.key === attr_spec.key, )?.value; @@ -139,13 +129,14 @@ export const TrialTable: FC<{ if (firstVal === secondVal) { return 0; - } else if (firstVal && secondVal) { - return firstVal < secondVal ? 1 : -1; - } else if (firstVal) { - return -1; - } else { - return 1; } + if (firstVal && secondVal) { + return firstVal < secondVal ? 1 : -1; + } + if (firstVal) { + return -1; + } + return 1; }, }); });