Skip to content

Commit

Permalink
feat: move isVirtualized internally
Browse files Browse the repository at this point in the history
  • Loading branch information
tewarig committed Jan 29, 2025
1 parent 795a213 commit 8335605
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 30 deletions.
6 changes: 0 additions & 6 deletions packages/blade/codemods/aicodemod/knowledge/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,6 @@ Out implementation of virtualized table is an wrapper on top of react-table-libr
most of props are same as Table component. we have added following table component.
```ts

isVirtualized = false, // default value is false , it is used to enable virtualization in table

ref = React.Ref<HTMLDivElement> | undefined, // ref to the table container , since in virtualized table we need to calculate the height and width of the table to render only the visible rows and columns
```
but their is a change in children prop of Table component. In virtualized table we need to pass a component named TableVirtulized that takes TableHeader, TableBody components.
VirtualizedTable is a wrapper on top of react-table-library's [Virtualized](https://github.com/table-library/react-table-library/blob/master/src/virtualized/Virtualized.tsx) component. It provides a simple API to create a virtualized table.
Expand Down
12 changes: 9 additions & 3 deletions packages/blade/src/components/Table/Table.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ const _Table = <Item,>({
isRefreshing = false,
showBorderedCells = false,
defaultSelectedIds = [],
isVirtualized = false,
...rest
}: TableProps<Item>): React.ReactElement => {
const { theme } = useTheme();
Expand All @@ -201,6 +200,15 @@ const _Table = <Item,>({
undefined,
);
const [hasHoverActions, setHasHoverActions] = React.useState(false);
const tableRootComponent = children([]);
const isVirtualized = (React.isValidElement<{
header?: () => React.ReactElement;
children?: React.ReactNode;
}>(tableRootComponent) &&
Array.isArray(tableRootComponent.props?.children) &&
tableRootComponent.props.children?.length &&
React.isValidElement<{ children?: React.ReactNode }>(tableRootComponent.props?.children[1]) &&
typeof tableRootComponent.props?.children[1]?.props.children === 'function') as boolean;
// Need to make header is sticky if first column is sticky otherwise the first header cell will not be sticky
const shouldHeaderBeSticky = isVirtualized ?? isHeaderSticky ?? isFirstColumnSticky;
const backgroundColor = tableBackgroundColor;
Expand All @@ -217,8 +225,6 @@ const _Table = <Item,>({
transitionDuration: theme.motion.duration.quick,
});

console.log('isVirtualized', isVirtualized);

// Table Theme
const columnCount = getTableHeaderCellCount(children, isVirtualized);
const firstColumnStickyHeaderCellCSS = isFirstColumnSticky
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import userEvent from '@testing-library/user-event';
import { useState, useRef } from 'react';
import { useState } from 'react';
import { fireEvent, waitFor } from '@testing-library/react';
import { Table } from '../Table';
import { TableBody, TableCell, TableRow, TableVirtualizedWrapper } from '../TableBody';
Expand Down Expand Up @@ -1203,7 +1203,6 @@ describe('<Table />', () => {
const ReactVirtualTable = (): React.ReactElement => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [apiData, _] = useState({ nodes: nodes.slice(0, 10) });
const boxRef = useRef<HTMLElement>(null);
return (
<Box ref={boxRef}>
<Table
Expand All @@ -1216,8 +1215,6 @@ describe('<Table />', () => {
PAYMENT_ID: (array) => array.sort((a, b) => a.paymentId.localeCompare(b.paymentId)),
STATUS: (array) => array.sort((a, b) => a.status.localeCompare(b.status)),
}}
ref={boxRef}
isVirtualized
defaultSelectedIds={['1', '3']}
rowDensity="normal"
isFirstColumnSticky
Expand Down
9 changes: 0 additions & 9 deletions packages/blade/src/components/Table/_decisions/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,6 @@ also their is high chance of bugs and performance issues in the implementation o
most of props are same as Table component. we have added following table component.
```ts

isVirtualized = false, // default value is false , it is used to enable virtualization in table

ref = React.Ref<HTMLDivElement> | undefined, // ref to the table container , since in virtualized table we need to calculate the height and width of the table to render only the visible rows and columns


```
but their is a change in children prop of Table component. In virtualized table we need to pass a component named TableVirtulized that takes TableHeader, TableBody components.
VirtualizedTable is a wrapper on top of react-table-library's [Virtualized](https://github.com/table-library/react-table-library/blob/master/src/virtualized/Virtualized.tsx) component. It provides a simple API to create a virtualized table.
Expand All @@ -729,7 +721,6 @@ type VirtualizedWrapperProps<Item> = {
/**
* <TableComponent
* data={data}
* isVirtualized
* rowDensity="compact"
* selectionType="multiple"
* height="700px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const TableTemplate: StoryFn<typeof TableComponent> = () => {
>
<TableComponent
data={data}
isVirtualized
height={'500px'}
rowDensity="comfortable"
selectionType="multiple"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const TableTemplate: StoryFn<typeof TableComponent> = () => {
>
<TableComponent
data={data}
isVirtualized
rowDensity="compact"
selectionType="multiple"
height="700px"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const TableTemplate: StoryFn<typeof TableComponent> = ({ ...args }) => {
rowDensity="normal"
height="600px"
isFirstColumnSticky
isVirtualized
>
{(tableData) => (
<TableVirtualizedWrapper tableData={tableData} rowHeight={() => 57}>
Expand Down
5 changes: 0 additions & 5 deletions packages/blade/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ type TableProps<Item> = {
* An array of default selected row ids. This will be used to set the initial selected rows.
*/
defaultSelectedIds?: Identifier[];
/**
* isVirtualized prop determines whether the table is virutalized or not.
*/
isVirtualized?: boolean;
} & DataAnalyticsAttribute &
StyledPropsBlade;

Expand Down Expand Up @@ -485,7 +481,6 @@ type VirtualizedWrapperProps<Item> = {
/**
* <TableComponent
* data={data}
* isVirtualized
* rowDensity="compact"
* selectionType="multiple"
* height="700px"
Expand Down

0 comments on commit 8335605

Please sign in to comment.