-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: react-table --> tanstack #72
Merged
+2,988
−29,532
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f18d4c2
wip: to tanstack
eldu 39e1b7a
wip: to tanstack
eldu 84cf201
refactor: js --> tsx
eldu b3004d9
refactor: Use some basic React Bootstrap components
eldu b2c54a7
Merge branch 'build-update' into refactor-tanstack
eldu ae57867
fix: some dependencies that were trouble
eldu b36e2f0
style: Table Controls
eldu ed1186b
fix: missing package lock
eldu df9a796
refactor: remove _table.scss
eldu 2ab4f6f
style: fix theme colors
eldu f9e2b30
style: closer to original table
eldu 9474cbd
refactor: font awesome icon
eldu 8af8f41
refactor: tanstack columns
eldu ac59cf5
refactor: sorting icon
eldu 2ad9a31
style: refactor out _addPub.scss
eldu 0934920
build: remove reactstrap
eldu fb02993
style: clean up some more style
eldu 024da4a
style: clean up some more style
eldu d486873
style: fix table controls
eldu 8515c6a
style: refactor to same same
eldu dc7cc26
style: fix div
eldu 00816cf
wip: why is this table resizing so hard
eldu bac55c1
fix: most of my table resizing sadness
eldu 3c8b9e7
fix: pagination
eldu 8bf6240
refactor: move out components
eldu c19aa86
refactor: more clean up
eldu c1c147f
refactor: more clean up
eldu 9c6229a
refactor: more clean up
eldu 8e10aec
refactor: remove unneeded flex
eldu 11cd4e7
Merge branch 'build-update' into refactor-tanstack
eldu 5af92a5
fix: package-lock.json
eldu 8dff126
refactor: clean up
eldu 53fdaae
refactor: sorting icons
eldu f696930
fix: clicking header
eldu 0cedba2
fix: quick fix for footer. trying to not touch the rest ! :scream:
eldu d16c5e1
refactor: pagination clean up
eldu 00f03be
refactor: some more style clean up
eldu bfea3cb
refactor: some more style clean up
eldu 2b9d6d3
docs: add issue number for word cloud
eldu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import { DebouncedInput } from './DebouncedInput.tsx'; | ||
|
||
export function ColumnFilter({ column, table }) { | ||
const firstValue = table.getPreFilteredRowModel().flatRows[0]?.getValue(column.id); | ||
|
||
const columnFilterValue = column.getFilterValue(); | ||
|
||
const sortedUniqueValues = React.useMemo( | ||
() => | ||
typeof firstValue === 'number' | ||
? [] | ||
: Array.from(column.getFacetedUniqueValues().keys()).sort(), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[column.getFacetedUniqueValues()] | ||
); | ||
|
||
return typeof firstValue === 'number' ? ( | ||
<div className="d-flex"> | ||
<DebouncedInput | ||
type="number" | ||
min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')} | ||
max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')} | ||
value={(columnFilterValue as [number, number])?.[0] ?? ''} | ||
onChange={(value) => column.setFilterValue((old: [number, number]) => [value, old?.[1]])} | ||
placeholder="min" | ||
/> | ||
<DebouncedInput | ||
type="number" | ||
min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')} | ||
max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')} | ||
value={(columnFilterValue as [number, number])?.[1] ?? ''} | ||
onChange={(value) => column.setFilterValue((old: [number, number]) => [old?.[0], value])} | ||
placeholder="max" | ||
/> | ||
</div> | ||
) : ( | ||
<> | ||
<datalist id={column.id + 'list'}> | ||
{sortedUniqueValues.slice(0, 5000).map((value) => ( | ||
<option value={value} key={value} /> | ||
))} | ||
</datalist> | ||
<DebouncedInput | ||
type="text" | ||
value={(columnFilterValue ?? '') as string} | ||
onChange={(value) => column.setFilterValue(value)} | ||
list={column.id + 'list'} | ||
/> | ||
<div className="h-1" /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// A debounced input react component | ||
import React from 'react'; | ||
import Form from 'react-bootstrap/Form'; | ||
|
||
export function DebouncedInput({ | ||
value: initialValue, | ||
onChange, | ||
debounce = 500, | ||
...props | ||
}: { | ||
value: string | number; | ||
onChange: (value: string | number) => void; | ||
debounce?: number; | ||
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'>) { | ||
const [value, setValue] = React.useState(initialValue); | ||
|
||
React.useEffect(() => { | ||
setValue(initialValue); | ||
}, [initialValue]); | ||
|
||
React.useEffect( | ||
() => { | ||
const timeout = setTimeout(() => { | ||
onChange(value); | ||
}, debounce); | ||
|
||
return () => clearTimeout(timeout); | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[value] | ||
); | ||
|
||
return <Form.Control {...props} value={value} onChange={(e) => setValue(e.target.value)} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { | ||
ColumnFiltersState, | ||
createColumnHelper, | ||
flexRender, | ||
getCoreRowModel, | ||
getFacetedMinMaxValues, | ||
getFacetedRowModel, | ||
getFacetedUniqueValues, | ||
getFilteredRowModel, | ||
getPaginationRowModel, | ||
getSortedRowModel, | ||
PaginationState, | ||
useReactTable, | ||
} from '@tanstack/react-table'; | ||
|
||
import Table from 'react-bootstrap/Table'; | ||
import Container from 'react-bootstrap/Container'; | ||
import Row from 'react-bootstrap/Row'; | ||
import Col from 'react-bootstrap/Col'; | ||
import Button from 'react-bootstrap/Button'; | ||
import Form from 'react-bootstrap/Form'; | ||
|
||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faArrowDownWideShort, faArrowUpShortWide } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
import { selectPublications } from '../store/slice/appState'; | ||
import { Publication } from '../../types'; | ||
import { ColumnFilter } from './ColumnFilter.tsx'; | ||
|
||
export function PublicationsTable() { | ||
const publications = useSelector(selectPublications); | ||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([]); | ||
const [pagination, setPagination] = React.useState<PaginationState>({ | ||
pageIndex: 0, | ||
pageSize: 5, | ||
}); | ||
|
||
const columnHelper = createColumnHelper<Publication>(); | ||
|
||
const columns = [ | ||
columnHelper.accessor('title', { | ||
header: 'Title', | ||
cell: (info) => ( | ||
<a href={info.row.original.url} target="_blank" rel="noopener noreferrer"> | ||
{info.getValue()} | ||
</a> | ||
), | ||
}), | ||
columnHelper.accessor('author', { | ||
header: 'Author(s)', | ||
cell: (info) => info.getValue(), | ||
}), | ||
columnHelper.accessor('year', { | ||
header: 'Year', | ||
cell: (info) => info.getValue(), | ||
size: 100, | ||
}), | ||
]; | ||
|
||
const table = useReactTable({ | ||
data: publications, | ||
columns, | ||
state: { | ||
columnFilters, | ||
pagination, | ||
}, | ||
columnResizeMode: 'onChange', | ||
onColumnFiltersChange: setColumnFilters, | ||
onPaginationChange: setPagination, | ||
getCoreRowModel: getCoreRowModel(), | ||
getFilteredRowModel: getFilteredRowModel(), | ||
getSortedRowModel: getSortedRowModel(), | ||
getPaginationRowModel: getPaginationRowModel(), | ||
getFacetedRowModel: getFacetedRowModel(), | ||
getFacetedUniqueValues: getFacetedUniqueValues(), | ||
getFacetedMinMaxValues: getFacetedMinMaxValues(), | ||
}); | ||
|
||
return ( | ||
<Container fluid> | ||
<Row> | ||
<Table className="align-middle text-break text-center" bordered> | ||
<thead> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<tr key={headerGroup.id}> | ||
{headerGroup.headers.map((header) => { | ||
return ( | ||
<th | ||
key={header.id} | ||
colSpan={header.colSpan} | ||
className="h3 bg-secondary" | ||
style={{ | ||
position: 'relative', | ||
width: header.getSize(), | ||
}} | ||
> | ||
{header.isPlaceholder ? null : ( | ||
<> | ||
<div | ||
className={ | ||
header.column.getCanSort() ? 'cursor-pointer select-none' : '' | ||
} | ||
onClick={header.column.getToggleSortingHandler()} | ||
> | ||
{/* Header */} | ||
{flexRender(header.column.columnDef.header, header.getContext())} | ||
{/* Sorting Icons */} | ||
{{ | ||
asc: <FontAwesomeIcon icon={faArrowUpShortWide} />, | ||
desc: <FontAwesomeIcon icon={faArrowDownWideShort} />, | ||
}[header.column.getIsSorted() as string] ?? null} | ||
</div> | ||
{/* Column Filter */} | ||
{header.column.getCanFilter() ? ( | ||
<ColumnFilter column={header.column} table={table} /> | ||
) : null} | ||
<div | ||
onDoubleClick={() => header.column.resetSize()} | ||
onMouseDown={header.getResizeHandler()} | ||
onTouchStart={header.getResizeHandler()} | ||
className={`resizer ${header.column.getIsResizing() ? 'is-resizing' : ''}`} | ||
/> | ||
</> | ||
)} | ||
</th> | ||
); | ||
})} | ||
</tr> | ||
))} | ||
</thead> | ||
<tbody> | ||
{table.getRowModel().rows.map((row) => { | ||
return ( | ||
<tr key={row.id}> | ||
{row.getVisibleCells().map((cell) => { | ||
return ( | ||
<td key={cell.id}> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</td> | ||
); | ||
})} | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</Table> | ||
</Row> | ||
<Row> | ||
<Col sm={12} md={4} lg={4} className="d-grid"> | ||
<Button | ||
variant="warning" | ||
size="lg" | ||
onClick={() => table.previousPage()} | ||
disabled={!table.getCanPreviousPage()} | ||
> | ||
Previous | ||
</Button> | ||
</Col> | ||
<Col sm={12} md={4} lg={4} className="d-flex justify-content-around"> | ||
<div className="d-flex align-items-center"> | ||
<span className="mx-2">Page</span> | ||
<Form.Control | ||
type="number" | ||
value={table.getState().pagination.pageIndex + 1} | ||
onChange={(e) => { | ||
const page = e.target.value ? Number(e.target.value) - 1 : 0; | ||
table.setPageIndex(page); | ||
}} | ||
min={1} | ||
max={table.getPageCount()} | ||
/> | ||
<span className="mx-2 text-nowrap">of {table.getPageCount()}</span> | ||
</div> | ||
<div className="d-flex align-items-center"> | ||
<Form.Select | ||
value={table.getState().pagination.pageSize} | ||
onChange={(e) => { | ||
table.setPageSize(Number(e.target.value)); | ||
}} | ||
> | ||
{[5, 10, 20, 25, 50, 100].map((pageSize) => ( | ||
<option key={pageSize} value={pageSize}> | ||
{pageSize} rows | ||
</option> | ||
))} | ||
</Form.Select> | ||
</div> | ||
</Col> | ||
<Col sm={12} md={4} lg={4} className="d-grid"> | ||
<Button | ||
variant="secondary" | ||
size="lg" | ||
onClick={() => table.nextPage()} | ||
disabled={!table.getCanNextPage()} | ||
> | ||
Next | ||
</Button> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
// Import Bootstrap | ||
@import '~bootstrap/scss/bootstrap.scss'; | ||
|
||
// Override Bootstrap Variables | ||
@import 'variables'; | ||
|
||
@import '~bootstrap/scss/bootstrap.scss'; | ||
$theme-colors: map-merge($theme-colors, $custom-colors); | ||
|
||
// Import Custom Components | ||
@import './src/styles/components/_brown_fonts.scss'; | ||
@import './src/styles/components/_brown_icons.scss'; | ||
@import './src/styles/components/_brown_footer.scss'; | ||
@import './src/styles/components/_app.scss'; | ||
@import './src/styles/components/_table.scss'; | ||
@import './src/styles/components/_addPub.scss'; | ||
|
||
.main { | ||
min-height: 90vh; | ||
padding: 2vw 3vw; | ||
} | ||
|
||
.form-group.required > .form-label:after { | ||
content: '*'; | ||
content: ' *'; | ||
color: red; | ||
} | ||
|
||
.resizer { | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
height: 100%; | ||
width: 5px; | ||
background: $brown; | ||
cursor: col-resize; | ||
user-select: none; | ||
touch-action: none; | ||
opacity: 0; | ||
} | ||
|
||
@media (hover: hover) { | ||
.resizer:hover { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
.resizer.is-resizing { | ||
background: $green; | ||
opacity: 1; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my own understanding, what does adding a space do here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if you open up the form modal, all the required fields have " *" next to it if it's a required field. The space in this case is just a space. So instead of
DOI*
we getDOI *