mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-20 18:40:17 -04:00
added sorting util function to Table.tsx to reduce repetition
This commit is contained in:
parent
4e79bae4b4
commit
cf68ae57ff
|
@ -43,19 +43,27 @@ const fuzzyFilter = (
|
||||||
return itemRank.passed;
|
return itemRank.passed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General componenet that holds shared functionality for any data table component
|
* General componenet that holds shared functionality for any data table component
|
||||||
* @param props.data Stateful list of data to be held in the table
|
* @param props.data Stateful list of data to be held in the table
|
||||||
* @param props.setData State setter for the list of data
|
* @param props.setData State setter for the list of data
|
||||||
* @param props.columns Column definitions made with Tanstack columnHelper
|
* @param props.columns Column definitions made with Tanstack columnHelper
|
||||||
*/
|
*/
|
||||||
export default function Table<T extends DataPoint>({ data, setData, columns }: TableProps<T>) {
|
export default function Table<T extends DataPoint>({ data, setData, columns }: TableProps<T>) {
|
||||||
const columnHelper = createColumnHelper<T>();
|
const columnHelper = createColumnHelper<T>();
|
||||||
|
|
||||||
|
// For sorting
|
||||||
|
const sortData = (prevData: T[]) => (
|
||||||
|
prevData.sort((a, b) =>
|
||||||
|
a.visible === b.visible
|
||||||
|
? 0
|
||||||
|
: a.visible ? -1 : 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setData(prevData => prevData.sort((a, b) =>
|
setData(prevData => sortData(prevData))
|
||||||
a.visible === b.visible ? 0 : a.visible ? -1 : 1
|
|
||||||
))
|
|
||||||
}, [setData]);
|
}, [setData]);
|
||||||
|
|
||||||
// Data manipulation
|
// Data manipulation
|
||||||
|
|
Loading…
Reference in New Issue
Block a user