-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEL-189-Create-lap-table-component (#153)
* table for lap data and lap tab * moved code to RaceTab.tsx and deleted LapTab.tsx * overhaul to tanstack table --------- Co-authored-by: burtonjong <[email protected]>
- Loading branch information
1 parent
72781c9
commit 41f14d7
Showing
4 changed files
with
232 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
"amplify", | ||
".eslintrc.cjs" | ||
], | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,214 @@ | ||
import { useMemo } from "react"; | ||
|
||
import type { ILapData } from "@shared/helios-types"; | ||
import { | ||
createColumnHelper, | ||
flexRender, | ||
getCoreRowModel, | ||
useReactTable, | ||
} from "@tanstack/react-table"; | ||
|
||
const columnHelper = createColumnHelper<ILapData>(); | ||
|
||
const columns = [ | ||
columnHelper.accessor("ampHours", { | ||
cell: (info) => info.getValue(), | ||
header: "Amp Hours", | ||
}), | ||
columnHelper.accessor("averagePackCurrent", { | ||
cell: (info) => info.getValue(), | ||
header: "Average Pack Current", | ||
}), | ||
columnHelper.accessor("averageSpeed", { | ||
cell: (info) => info.getValue(), | ||
header: "Average Speed", | ||
}), | ||
columnHelper.accessor("batterySecondsRemaining", { | ||
cell: (info) => info.getValue(), | ||
header: "Battery Seconds Remaining", | ||
}), | ||
columnHelper.accessor("distance", { | ||
cell: (info) => info.getValue(), | ||
header: "Distance", | ||
}), | ||
columnHelper.accessor("lapTime", { | ||
cell: (info) => info.getValue(), | ||
header: "Lap Time", | ||
}), | ||
columnHelper.accessor("netPowerOut", { | ||
cell: (info) => info.getValue(), | ||
header: "Net Power Out", | ||
}), | ||
columnHelper.accessor("timeStamp", { | ||
cell: (info) => info.getValue(), | ||
header: "Time Stamp", | ||
}), | ||
columnHelper.accessor("totalPowerIn", { | ||
cell: (info) => info.getValue(), | ||
header: "Total Power In", | ||
}), | ||
columnHelper.accessor("totalPowerOut", { | ||
cell: (info) => info.getValue(), | ||
header: "Total Power Out", | ||
}), | ||
]; | ||
|
||
// sample data | ||
const exampleData: ILapData[] = [ | ||
{ | ||
ampHours: 10, | ||
averagePackCurrent: 11, | ||
averageSpeed: 23, | ||
batterySecondsRemaining: 23, | ||
distance: 23, | ||
lapTime: 23423, | ||
netPowerOut: 13434, | ||
timeStamp: 324234, | ||
totalPowerIn: 1234, | ||
totalPowerOut: 123, | ||
}, | ||
{ | ||
ampHours: 15, | ||
averagePackCurrent: 12, | ||
averageSpeed: 25, | ||
batterySecondsRemaining: 30, | ||
distance: 25, | ||
lapTime: 25000, | ||
netPowerOut: 15000, | ||
timeStamp: 324235, | ||
totalPowerIn: 1500, | ||
totalPowerOut: 150, | ||
}, | ||
{ | ||
ampHours: 15, | ||
averagePackCurrent: 12, | ||
averageSpeed: 25, | ||
batterySecondsRemaining: 30, | ||
distance: 25, | ||
lapTime: 25000, | ||
netPowerOut: 15000, | ||
timeStamp: 324235, | ||
totalPowerIn: 1500, | ||
totalPowerOut: 150, | ||
}, | ||
{ | ||
ampHours: 15, | ||
averagePackCurrent: 12, | ||
averageSpeed: 25, | ||
batterySecondsRemaining: 30, | ||
distance: 25, | ||
lapTime: 25000, | ||
netPowerOut: 15000, | ||
timeStamp: 324235, | ||
totalPowerIn: 1500, | ||
totalPowerOut: 150, | ||
}, | ||
{ | ||
ampHours: 15, | ||
averagePackCurrent: 12, | ||
averageSpeed: 25, | ||
batterySecondsRemaining: 30, | ||
distance: 25, | ||
lapTime: 25000, | ||
netPowerOut: 15000, | ||
timeStamp: 324235, | ||
totalPowerIn: 1500, | ||
totalPowerOut: 150, | ||
}, | ||
{ | ||
ampHours: 15, | ||
averagePackCurrent: 12, | ||
averageSpeed: 25, | ||
batterySecondsRemaining: 30, | ||
distance: 25, | ||
lapTime: 25000, | ||
netPowerOut: 15000, | ||
timeStamp: 324235, | ||
totalPowerIn: 1500, | ||
totalPowerOut: 150, | ||
}, | ||
{ | ||
ampHours: 15, | ||
averagePackCurrent: 12, | ||
averageSpeed: 25, | ||
batterySecondsRemaining: 30, | ||
distance: 25, | ||
lapTime: 25000, | ||
netPowerOut: 15000, | ||
timeStamp: 324235, | ||
totalPowerIn: 1500, | ||
totalPowerOut: 150, | ||
}, | ||
]; | ||
|
||
function RaceTab() { | ||
return <div className="size-full">Race Tab</div>; | ||
const data = useMemo(() => exampleData, []); | ||
|
||
const table = useReactTable({ | ||
columns, | ||
data, | ||
getCoreRowModel: getCoreRowModel(), | ||
}); | ||
|
||
return ( | ||
<div className="m-4 flex justify-center gap-2"> | ||
<div className="mb-4 flex flex-col flex-wrap justify-end gap-2"> | ||
{table.getAllLeafColumns().map((column) => ( | ||
<label | ||
className="flex items-center gap-1 text-sm text-helios" | ||
key={column.id} | ||
> | ||
<input | ||
checked={column.getIsVisible()} | ||
className="accent-slate-200 hover:accent-red-500" | ||
onChange={column.getToggleVisibilityHandler()} | ||
type="checkbox" | ||
/> | ||
{column.id} | ||
</label> | ||
))} | ||
</div> | ||
|
||
<div className="w-3/4 overflow-x-auto"> | ||
<table className="w-full table-fixed divide-gray-200 border-b-2 border-helios"> | ||
<thead className="border-b-2 border-helios"> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<tr key={headerGroup.id}> | ||
{headerGroup.headers.map((header) => ( | ||
<th | ||
className="text-gray-500 overflow-x-hidden px-4 py-2 text-center text-xs font-medium uppercase text-helios" | ||
key={header.id} | ||
> | ||
{header.isPlaceholder | ||
? null | ||
: flexRender( | ||
header.column.columnDef.header, | ||
header.getContext(), | ||
)} | ||
</th> | ||
))} | ||
</tr> | ||
))} | ||
</thead> | ||
|
||
<tbody className="divide-y divide-gray-200 bg-white"> | ||
{table.getRowModel().rows.map((row) => ( | ||
<tr key={row.id}> | ||
{row.getVisibleCells().map((cell) => ( | ||
<td | ||
className={`text-gray-900 border-x-2 border-helios px-4 py-2 text-center text-sm`} | ||
key={cell.id} | ||
> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default RaceTab; |
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