Skip to content

Commit 6ca9f69

Browse files
committed
release version patch and improve isNodeReadOnly
1 parent fbe023b commit 6ca9f69

File tree

6 files changed

+154
-5
lines changed

6 files changed

+154
-5
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import * as React from 'react';
2+
3+
import {
4+
InfiniteTableColumn,
5+
TreeDataSource,
6+
TreeGrid,
7+
} from '@infinite-table/infinite-react';
8+
import { useState } from 'react';
9+
10+
export type FileSystemNode = {
11+
name: string;
12+
type: 'file' | 'folder';
13+
children?: FileSystemNode[] | null;
14+
sizeKB?: number;
15+
id: string;
16+
collapsed?: boolean;
17+
};
18+
19+
export const nodes: FileSystemNode[] = [
20+
{
21+
name: 'Documents',
22+
type: 'folder',
23+
id: '1',
24+
children: [
25+
{
26+
name: 'report.doc',
27+
type: 'file',
28+
sizeKB: 100,
29+
id: '2',
30+
},
31+
{
32+
type: 'folder',
33+
name: 'pictures - empty',
34+
id: '3',
35+
children: [],
36+
},
37+
{
38+
type: 'folder',
39+
name: 'diverse',
40+
id: '4',
41+
children: [
42+
{
43+
name: 'beach.jpg',
44+
type: 'file',
45+
sizeKB: 2024,
46+
id: '6',
47+
},
48+
],
49+
},
50+
{
51+
type: 'file',
52+
name: 'last.txt',
53+
id: '7',
54+
},
55+
],
56+
},
57+
];
58+
59+
const columns: Record<string, InfiniteTableColumn<FileSystemNode>> = {
60+
name: {
61+
field: 'name',
62+
renderTreeIcon: true,
63+
64+
renderValue: ({ value, data }) => {
65+
return (
66+
<>
67+
{value} - {data!.id}
68+
</>
69+
);
70+
},
71+
},
72+
type: { field: 'type' },
73+
sizeKB: { field: 'sizeKB' },
74+
};
75+
76+
const returnFalse = () => false;
77+
export default function DataTestPage() {
78+
const [allowExpandEmptyNodes, setAllowExpandEmptyNodes] = useState(false);
79+
80+
const isNodeReadOnly = allowExpandEmptyNodes ? returnFalse : undefined;
81+
return (
82+
<React.StrictMode>
83+
<button
84+
onClick={() => {
85+
setAllowExpandEmptyNodes((v) => !v);
86+
}}
87+
>
88+
toggle
89+
</button>
90+
<TreeDataSource<FileSystemNode>
91+
data={nodes}
92+
primaryKey="id"
93+
nodesKey="children"
94+
isNodeReadOnly={isNodeReadOnly}
95+
>
96+
<TreeGrid<FileSystemNode>
97+
wrapRowsHorizontally
98+
domProps={{
99+
style: {
100+
margin: '5px',
101+
height: 900,
102+
border: '1px solid gray',
103+
position: 'relative',
104+
},
105+
}}
106+
columns={columns}
107+
/>
108+
</TreeDataSource>
109+
</React.StrictMode>
110+
);
111+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test, expect } from '@testing';
2+
3+
export default test.describe('isNodeReadOnly', () => {
4+
test('works as expected', async ({ page, tableModel }) => {
5+
await page.waitForInfinite();
6+
7+
const cell = tableModel.withCell({
8+
rowIndex: 2,
9+
colIndex: 0,
10+
});
11+
12+
expect(await cell.isTreeIconExpanded()).toBe(true);
13+
expect(await cell.isTreeIconDisabled()).toBe(true);
14+
15+
await page.click('button:text("toggle")');
16+
17+
expect(await cell.isTreeIconExpanded()).toBe(true);
18+
expect(await cell.isTreeIconDisabled()).toBe(false);
19+
});
20+
});

examples/src/pages/tests/testUtils/TableTestingModel.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ export class TableTestingModel {
130130
}
131131

132132
withCell(cellLocation: CellLocation) {
133+
const getTreeIcon = () => {
134+
return this.rowModel
135+
.getCellLocator(cellLocation)
136+
.locator('[data-name="expand-collapse-icon"]');
137+
};
138+
133139
return {
134140
getComputedStyleProperty: async (styleName: string) => {
135141
return await this.columnModel.getCellComputedStyleProperty(
@@ -138,13 +144,20 @@ export class TableTestingModel {
138144
);
139145
},
140146

141-
isTreeIconExpanded: async () => {
142-
const cellLocator = this.rowModel.getCellLocator(cellLocation);
147+
getTreeIcon: () => {
148+
return getTreeIcon();
149+
},
143150

144-
const icon = cellLocator.locator('[data-name="expand-collapse-icon"]');
151+
isTreeIconExpanded: async () => {
152+
const icon = getTreeIcon();
145153
return (await icon.getAttribute('data-state')) === 'expanded';
146154
},
147155

156+
isTreeIconDisabled: async () => {
157+
const icon = getTreeIcon();
158+
return (await icon.getAttribute('data-disabled')) === 'true';
159+
},
160+
148161
getLocator: () => {
149162
return this.rowModel.getCellLocator(cellLocation);
150163
},

source/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ function InfiniteTableColumnCellFn<T>(props: InfiniteTableColumnCellProps<T>) {
335335
[rowIndex, rowDisabled, column.computedVisibleIndex, keyboardNavigation],
336336
);
337337

338-
const { selectionMode, cellSelection } = dataSourceState;
338+
const { selectionMode, cellSelection, isNodeReadOnly } = dataSourceState;
339339

340340
const cellSelected = renderParam.cellSelected;
341341

@@ -585,6 +585,9 @@ function InfiniteTableColumnCellFn<T>(props: InfiniteTableColumnCellProps<T>) {
585585
hidden,
586586
inEdit,
587587
rowDetailState,
588+
column.renderTreeIcon || column.renderTreeIconForParentNode
589+
? isNodeReadOnly
590+
: false,
588591
...objectValuesExcept(renderParam, {
589592
renderBag: true,
590593
selectCell: true,

source/src/components/InfiniteTable/components/icons/ExpandCollapseIcon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function ExpandCollapseIcon(props: ExpandCollapseIconProps) {
4747
<svg
4848
data-name="expand-collapse-icon"
4949
data-state={currentState}
50+
data-disabled={disabled}
5051
xmlns="http://www.w3.org/2000/svg"
5152
height={`${size}px`}
5253
viewBox="0 0 24 24"

source/src/components/InfiniteTable/hooks/useCellRendering.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function useCellRendering<T>(
6666
api: dataSourceApi,
6767
} = useDataSourceContextValue<T>();
6868

69-
const { dataArray } = dataSourceState;
69+
const { dataArray, isNodeReadOnly } = dataSourceState;
7070

7171
const getData = useLatest(dataArray);
7272
const {
@@ -286,6 +286,7 @@ export function useCellRendering<T>(
286286
showZebraRows,
287287
brain,
288288
repaintId,
289+
isNodeReadOnly,
289290
rowStyle,
290291
rowClassName,
291292
cellClassName,

0 commit comments

Comments
 (0)