Skip to content

Commit

Permalink
feat(PHC-4380): support row selection #331
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Zhu committed Mar 20, 2023
1 parent b832083 commit d5bde5e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/components/TableModule/ReactTableModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const ReactTableModule = React.memo(
columns = config.map(mapTableConfigToColumnDef);
}

console.log('columns', columns);

const table = useReactTable({
data,
columns,
Expand All @@ -62,7 +64,7 @@ export const ReactTableModule = React.memo(
state,
});

const headings = table.getHeaderGroups()[0].headers;
const headers = table.getHeaderGroups()[0].headers;

return (
<table
Expand All @@ -83,7 +85,7 @@ export const ReactTableModule = React.memo(
<TableHeaderCell
index={i}
key={header.id}
header={{ label: header.id }}
header={{ ...header, label: header.id }}
></TableHeaderCell>
))}
</tr>
Expand All @@ -101,7 +103,7 @@ export const ReactTableModule = React.memo(
rowRole={rowRole}
maxCellWidth={maxCellWidth}
row={row}
headingsLength={headings?.length}
headingsLength={headers?.length}
cells={row.getVisibleCells()}
rowClickLabel={rowClickLabel}
/>
Expand All @@ -113,7 +115,7 @@ export const ReactTableModule = React.memo(
>
<td
className={classes.tableLoadingCell}
colSpan={table.getHeaderGroups()[0].headers.length}
colSpan={headers?.length}
>
<DotLoader size={0} />
</td>
Expand Down
8 changes: 7 additions & 1 deletion src/components/TableModule/TableHeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import clsx from 'clsx';
import * as React from 'react';

import { flexRender } from '@tanstack/react-table';
import { ChevronDown } from '@lifeomic/chromicons';
import { makeStyles } from '../../styles/index';
import { GetClasses } from '../../typeUtils';
Expand Down Expand Up @@ -157,7 +159,11 @@ export const TableHeaderCell: React.FC<TableHeaderCellProps> = ({
style={{ left: left }}
{...rootProps}
>
{header.content ? header.content(header) : header.label}
{header.column
? flexRender(header.column.columnDef.header, header.getContext())
: header.content
? header.content(header)
: header.label}
{/* We aren't actively sorting this column, but we want to display a "peek" icon so they know they can sort it */}
{(!sortDirection || !isSorting) && canSort && (
<ChevronDown
Expand Down
4 changes: 2 additions & 2 deletions src/components/TableModule/TableModuleRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import clsx from 'clsx';
import * as React from 'react';
import { Cell, flexRender } from '@tanstack/react-table';
import { flexRender } from '@tanstack/react-table';
import { useStyles } from './TableModule';
import { getTestProps } from '../../testUtils/getTestProps';
import { TableCell } from './types';
Expand All @@ -22,7 +22,7 @@ export interface TableModuleRowProps
maxCellWidth?: 1 | 2;
row: any;
headingsLength: number;
cells: Array<TableCell> | Array<Cell>;
cells: Array<TableCell>;
rowActions?: TableModuleProps['rowActions'];
rowClickLabel?: TableModuleProps['rowClickLabel'];
stickyCols?: Array<number>;
Expand Down
7 changes: 5 additions & 2 deletions src/components/TableModule/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Cell, Header } from '@tanstack/react-table';
/**
* @description A default interface for capturing the different
* "sortDirection" options.
Expand Down Expand Up @@ -26,14 +27,16 @@ export interface TableSortClickProps extends TableSortDirection {
header: TableHeader;
}

export interface TableHeader extends TableAlignOptions {
export interface TableHeader extends TableAlignOptions, Header<any, any> {
label?: string;
content?(header: TableHeader): any;
onSort?(sort: TableSortClickProps): any;
className?: string;
}

export interface TableCell<Item = any> extends TableAlignOptions {
export interface TableCell<Item = any>
extends TableAlignOptions,
Cell<any, any> {
valuePath?: string;
content?(cell: Item): any;
className?: string;
Expand Down

0 comments on commit d5bde5e

Please sign in to comment.