mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 14:41:02 +00:00
un-prettify for less lines of code changed :)
This commit is contained in:
parent
705efc1b8a
commit
510dd4dfb7
1 changed files with 26 additions and 24 deletions
|
|
@ -1,18 +1,18 @@
|
|||
import React, { FC, Fragment, useEffect, useRef, useState } from "react";
|
||||
import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown";
|
||||
import classNames from "classnames";
|
||||
import OrderBy from "lodash/orderBy";
|
||||
import Table from "@material-ui/core/Table";
|
||||
import TableBody from "@material-ui/core/TableBody";
|
||||
import TableCell from "@material-ui/core/TableCell";
|
||||
import TableHead from "@material-ui/core/TableHead";
|
||||
import React, { FC, Fragment, useEffect, useRef, useState } from 'react';
|
||||
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown';
|
||||
import classNames from 'classnames';
|
||||
import OrderBy from 'lodash/orderBy';
|
||||
import Table from '@material-ui/core/Table';
|
||||
import TableBody from '@material-ui/core/TableBody';
|
||||
import TableCell from '@material-ui/core/TableCell';
|
||||
import TableHead from '@material-ui/core/TableHead';
|
||||
// import TablePagination from '@material-ui/core/TablePagination';
|
||||
import TableRow from "@material-ui/core/TableRow";
|
||||
import Typography from "@material-ui/core/Typography";
|
||||
import { ColumnInfo } from "proto/pilosa_pb";
|
||||
import { Pager } from "shared/Pager";
|
||||
import { formatTableCell } from "shared/utils/formatTableCell";
|
||||
import css from "./DataTable.module.scss";
|
||||
import TableRow from '@material-ui/core/TableRow';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import { ColumnInfo } from 'proto/pilosa_pb';
|
||||
import { Pager } from 'shared/Pager';
|
||||
import { formatTableCell } from 'shared/utils/formatTableCell';
|
||||
import css from './DataTable.module.scss';
|
||||
|
||||
type TableProps = {
|
||||
headers: ColumnInfo.AsObject[];
|
||||
|
|
@ -25,11 +25,11 @@ export const DataTable: FC<TableProps> = ({
|
|||
headers,
|
||||
data,
|
||||
loading = false,
|
||||
autoWidth = false,
|
||||
autoWidth = false
|
||||
}) => {
|
||||
const [sortedData, setSortedData] = useState<any[]>(data);
|
||||
const [sort, setSort] = useState<string>(headers[0]?.name);
|
||||
const [sortDir, setSortDir] = useState<"asc" | "desc">("asc");
|
||||
const [sortDir, setSortDir] = useState<'asc' | 'desc'>('asc');
|
||||
const [page, setPage] = useState<number>(1);
|
||||
const [rowsPerPage, setRowsPerPage] = useState<number>(10);
|
||||
const resultsRef = useRef<HTMLDivElement>(null);
|
||||
|
|
@ -54,8 +54,8 @@ export const DataTable: FC<TableProps> = ({
|
|||
setTimeout(() => {
|
||||
if (resultsRef.current) {
|
||||
resultsRef.current.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "start",
|
||||
behavior: 'smooth',
|
||||
block: 'start'
|
||||
});
|
||||
}
|
||||
}, 0);
|
||||
|
|
@ -63,13 +63,15 @@ export const DataTable: FC<TableProps> = ({
|
|||
|
||||
const onSortClick = (name: string) => {
|
||||
if (sort === name) {
|
||||
setSortDir(sortDir === "desc" ? "asc" : "desc");
|
||||
setSortDir(sortDir === 'desc' ? 'asc' : 'desc');
|
||||
} else {
|
||||
setSort(name);
|
||||
setSortDir("asc");
|
||||
setSortDir('asc');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<div ref={resultsRef} />
|
||||
|
|
@ -84,14 +86,14 @@ export const DataTable: FC<TableProps> = ({
|
|||
>
|
||||
<span
|
||||
className={classNames(css.sortable, {
|
||||
[css.currentSort]: sort === col.name,
|
||||
[css.currentSort]: sort === col.name
|
||||
})}
|
||||
onClick={() => onSortClick(col.name)}
|
||||
>
|
||||
{col.name}
|
||||
<ArrowDropDownIcon
|
||||
className={classNames(css.sortArrow, {
|
||||
[css.asc]: sortDir === "asc",
|
||||
[css.asc]: sortDir === 'asc'
|
||||
})}
|
||||
/>
|
||||
</span>
|
||||
|
|
@ -110,7 +112,7 @@ export const DataTable: FC<TableProps> = ({
|
|||
.map((row, rowIdx) => (
|
||||
<TableRow
|
||||
key={`table-row-${rowIdx}`}
|
||||
className={rowIdx % 2 === 0 ? "" : css.altBg}
|
||||
className={rowIdx % 2 === 0 ? '' : css.altBg}
|
||||
>
|
||||
{headers.map((col, colIdx) => (
|
||||
<TableCell
|
||||
|
|
@ -118,7 +120,7 @@ export const DataTable: FC<TableProps> = ({
|
|||
className={css.tableCell}
|
||||
>
|
||||
{formatTableCell(row, col)}
|
||||
</TableCell>
|
||||
</TableCell>
|
||||
))}
|
||||
{autoWidth ? <TableCell className={css.fillWidth} /> : null}
|
||||
</TableRow>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue