This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
18 changed files
with
458 additions
and
180 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
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,51 @@ | ||
import { | ||
Cell, | ||
ExpandedContent, | ||
flexRender, | ||
HeaderCell, | ||
HeaderRow, | ||
type LGRowData, | ||
Row, | ||
Table, | ||
TableBody, | ||
type TableProps, | ||
TableHead, | ||
} from "@leafygreen-ui/table/new"; | ||
|
||
type SpruceTableProps = { | ||
"data-cy-row"?: string; | ||
"data-cy-table"?: string; | ||
}; | ||
|
||
export const BaseTable = <T extends LGRowData>({ | ||
"data-cy-row": dataCyRow, | ||
"data-cy-table": dataCyTable, | ||
table, | ||
...args | ||
}: SpruceTableProps & TableProps<T>) => ( | ||
<Table data-cy={dataCyTable} table={table} {...args}> | ||
<TableHead> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<HeaderRow key={headerGroup.id}> | ||
{headerGroup.headers.map((header) => ( | ||
<HeaderCell key={header.id} header={header}> | ||
{flexRender(header.column.columnDef.header, header.getContext())} | ||
</HeaderCell> | ||
))} | ||
</HeaderRow> | ||
))} | ||
</TableHead> | ||
<TableBody> | ||
{table.getRowModel().rows.map((row) => ( | ||
<Row key={row.id} row={row} data-cy={dataCyRow}> | ||
{row.getVisibleCells().map((cell) => ( | ||
<Cell key={cell.id}> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</Cell> | ||
))} | ||
{row.original.renderExpandedContent && <ExpandedContent row={row} />} | ||
</Row> | ||
))} | ||
</TableBody> | ||
</Table> | ||
); |
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,46 @@ | ||
import { LeafyGreenTableRow } from "@leafygreen-ui/table/new"; | ||
import { TableFilterPopover } from "components/TablePopover"; | ||
import { TreeDataEntry } from "components/TreeSelect"; | ||
|
||
type TreeSelectFilterProps = { | ||
"data-cy"?: string; | ||
tData: TreeDataEntry[]; | ||
title: React.ReactNode; | ||
}; | ||
|
||
export const getColumnTreeSelectFilterProps = ({ | ||
"data-cy": dataCy, | ||
tData, | ||
title, | ||
}: TreeSelectFilterProps) => ({ | ||
header: ({ column }) => { | ||
// Only present options that appear in the table | ||
const options = tData.filter( | ||
({ value }) => !!column.getFacetedUniqueValues().get(value) | ||
); | ||
return ( | ||
<> | ||
{title} | ||
<TableFilterPopover | ||
value={column?.getFilterValue() ?? []} | ||
options={options} | ||
onConfirm={(value) => { | ||
column.setFilterValue(value); | ||
}} | ||
data-cy={dataCy} | ||
/> | ||
</> | ||
); | ||
}, | ||
filterFn: ( | ||
row: LeafyGreenTableRow<any>, | ||
columnId: string, | ||
filterValue: string[] | ||
) => { | ||
// If no filter is specified, show all rows | ||
if (!filterValue.length) { | ||
return true; | ||
} | ||
return filterValue.includes(row.getValue(columnId)); | ||
}, | ||
}); |
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
Oops, something went wrong.