🧩 react-table 8.1.1 breaking changes fixes

This commit is contained in:
2022-07-03 21:59:59 -07:00
parent a4beae5d95
commit 2ab27926f6
2 changed files with 58 additions and 188 deletions

View File

@@ -66,28 +66,28 @@ export const Library = (data: IComicBookLibraryProps): ReactElement => {
return !value ? <span className="tag is-info is-light">Wanted</span> : null; return !value ? <span className="tag is-info is-light">Wanted</span> : null;
}; };
const columns = useMemo( const columns = [
() => [
{ {
Header: "Comic Metadata", header: "Comic Metadata",
footer: 1,
columns: [ columns: [
{ {
Header: "File Details", header: "File Details",
id: "fileDetails", id: "fileDetails",
minWidth: 400, minWidth: 400,
accessor: "_source", accessorKey: "_source",
Cell: ({ value }) => { cell: info => {
return <MetadataPanel data={value} />; return <MetadataPanel data={info.getValue()} />;
}, },
}, },
{ {
Header: "ComicInfo.xml", header: "ComicInfo.xml",
accessor: "_source.sourcedMetadata.comicInfo", accessorKey: "_source.sourcedMetadata.comicInfo",
align: "center", align: "center",
minWidth: 250, minWidth: 250,
Cell: ({ value }) => cell: info =>
!isEmpty(value) ? ( !isEmpty(info.getValue()) ? (
<ComicInfoXML data={value} /> <ComicInfoXML data={info.getValue()} />
) : ( ) : (
<span className="tag">No ComicInfo.xml</span> <span className="tag">No ComicInfo.xml</span>
), ),
@@ -95,34 +95,33 @@ export const Library = (data: IComicBookLibraryProps): ReactElement => {
], ],
}, },
{ {
Header: "Additional Metadata", header: "Additional Metadata",
columns: [ columns: [
{ {
Header: "Publisher", header: "Publisher",
accessor: accessorKey:
"_source.sourcedMetadata.comicvine.volumeInformation.publisher", "_source.sourcedMetadata.comicvine.volumeInformation.publisher",
Cell(props) { cell: info => {
return ( return (
!isNil(props.cell.value) && ( !isNil(info.getValue()) && (
<h6 className="is-size-7 has-text-weight-bold"> <h6 className="is-size-7 has-text-weight-bold">
{props.cell.value.name} {info.getValue().rawFileDetails.name}
</h6> </h6>
) )
); );
}, },
}, },
{ {
Header: "Something", header: "Something",
accessor: "_source.acquisition.source.wanted", accessorKey: "_source.acquisition.source.wanted",
Cell: (props) => { cell: info => {
return <WantedStatus value={props.cell.value.toString()} />; !isUndefined(info.getValue()) ?
<WantedStatus value={info.getValue().toString()} /> : "Nothing";
}, },
}, },
], ],
}, }
], ]
[],
);
// ImportStatus.propTypes = { // ImportStatus.propTypes = {
// value: PropTypes.bool.isRequired, // value: PropTypes.bool.isRequired,

View File

@@ -1,6 +1,11 @@
import React, { ReactElement, useState } from "react"; import React, { ReactElement, useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useTable, usePagination, useFlexLayout } from "react-table"; import {
ColumnDef,
flexRender,
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
export const T2Table = (tableOptions): ReactElement => { export const T2Table = (tableOptions): ReactElement => {
const { rowData, columns, paginationHandlers, totalPages, rowClickHandler } = const { rowData, columns, paginationHandlers, totalPages, rowClickHandler } =
@@ -9,80 +14,48 @@ export const T2Table = (tableOptions): ReactElement => {
useState(false); useState(false);
const togglePageSizeDropdown = () => const togglePageSizeDropdown = () =>
collapsePageSizeDropdown(!isPageSizeDropdownCollapsed); collapsePageSizeDropdown(!isPageSizeDropdownCollapsed);
const { console.log(rowData);
getTableProps, const table = useReactTable({
getTableBodyProps,
headerGroups,
prepareRow,
page,
canPreviousPage,
canNextPage,
pageOptions,
pageCount,
gotoPage,
nextPage,
previousPage,
setPageSize,
state: { pageIndex, pageSize },
} = useTable(
{
columns,
data: rowData, data: rowData,
manualPagination: true, columns,
initialState: { getCoreRowModel: getCoreRowModel(),
pageIndex: 1, })
pageSize: 25,
},
pageCount: totalPages,
},
usePagination,
// useFlexLayout,
);
return ( return (
<> <>
<table {...getTableProps()} className="table is-hoverable"> <table className="table is-hoverable">
<thead> <thead>
{headerGroups.map((headerGroup, idx) => ( {table.getHeaderGroups().map((headerGroup, idx) => (
<tr key={idx} {...headerGroup.getHeaderGroupProps()}> <tr key={headerGroup.id}>
{headerGroup.headers.map((column, idx) => ( {headerGroup.headers.map((header, idx) => (
<th <th
key={idx} key={header.id}
{...column.getHeaderProps({ colSpan={header.colSpan}
style: { minWidth: column.minWidth, width: column.width },
})}
> >
{column.render("Header")} {header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</th> </th>
))} ))}
</tr> </tr>
))} ))}
</thead> </thead>
<tbody {...getTableBodyProps()}> <tbody>
{page.map((row, idx) => { {table.getRowModel().rows.map((row, idx) => {
prepareRow(row);
return ( return (
<tr <tr
key={idx} key={row.id}
{...row.getRowProps()}
onClick={() => rowClickHandler(row)} onClick={() => rowClickHandler(row)}
> >
{row.cells.map((cell, idx) => { {row.getVisibleCells().map(cell => (
return ( <td key={cell.id}>
<td {flexRender(cell.column.columnDef.cell, cell.getContext())}
key={idx} </td>
{...cell.getCellProps({ ))}
style: {
minWidth: cell.column.minWidth,
width: cell.column.width,
},
})}
className="is-vcentered"
>
{cell.render("Cell")}
</td>
);
})}
</tr> </tr>
); );
})} })}
@@ -90,109 +63,7 @@ export const T2Table = (tableOptions): ReactElement => {
</table> </table>
{/* pagination control */} {/* pagination control */}
<nav className="pagination" role="navigation" aria-label="pagination">
{/* x of total indicator */}
<div>
Page {pageIndex} of {Math.ceil(pageCount / pageSize)}
(Total resources: {pageCount})
</div>
{/* previous page and next page controls */}
<div className="field has-addons">
<p className="control">
<button
className="button"
onClick={() => {
previousPage();
return paginationHandlers.previousPage(pageIndex, pageSize);
}}
disabled={!canPreviousPage}
>
Previous Page
</button>
</p>
<p className="control">
<button
className="button"
onClick={() => {
nextPage();
return paginationHandlers.nextPage(pageIndex, pageSize);
}}
disabled={!canNextPage}
>
<span>Next Page</span>
</button>
</p>
</div>
{/* first and last page controls */}
<div className="field has-addons">
<p className="control">
<button
className="button"
onClick={() => gotoPage(1)}
disabled={!canPreviousPage}
>
<i className="fas fa-angle-double-left"></i>
</button>
</p>
<p className="control">
<button
className="button"
onClick={() => gotoPage(Math.ceil(pageCount / pageSize))}
disabled={!canNextPage}
>
<i className="fas fa-angle-double-right"></i>
</button>
</p>
</div>
{/* page selector */}
<span>
Go to page:
<input
type="number"
className="input"
defaultValue={pageIndex}
onChange={(e) => {
const page = e.target.value ? Number(e.target.value) : 0;
gotoPage(page);
}}
style={{ width: "100px" }}
/>
</span>
{/* page size selector */}
{/* <div
className={
"dropdown " + (isPageSizeDropdownCollapsed ? "is-active" : "")
}
onBlur={() => togglePageSizeDropdown()}
>
<div className="dropdown-trigger">
<button
className="button"
aria-haspopup="true"
aria-controls="dropdown-menu"
onClick={() => togglePageSizeDropdown()}
>
<span>Select Page Size</span>
<span className="icon is-small">
<i className="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div className="dropdown-menu" id="dropdown-menu" role="menu">
<div className="dropdown-content">
{[10, 20, 30, 40, 50].map((pageSize) => (
<a href="#" className="dropdown-item" key={pageSize}>
Show {pageSize}
</a>
))}
</div>
</div>
</div> */}
</nav>
</> </>
); );
}; };