-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c267f59
commit e6fce90
Showing
14 changed files
with
557 additions
and
18 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
examples/src/pages/tests/table/treegrid/remove-children-of-collapsed-node.page.tsx
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,107 @@ | ||
import * as React from 'react'; | ||
|
||
import { TreeDataSource, TreeGrid } from '@infinite-table/infinite-react'; | ||
import { | ||
DataSourceApi, | ||
type InfiniteTableColumn, | ||
} from '@infinite-table/infinite-react'; | ||
|
||
export type FileSystemNode = { | ||
name: string; | ||
type: 'file' | 'folder'; | ||
children?: FileSystemNode[] | null; | ||
sizeKB?: number; | ||
id: string; | ||
collapsed?: boolean; | ||
}; | ||
|
||
const nodes: FileSystemNode[] = [ | ||
{ | ||
name: 'Documents', | ||
type: 'folder', | ||
id: '1', | ||
children: [ | ||
{ | ||
name: 'report.doc', | ||
type: 'file', | ||
sizeKB: 100, | ||
id: '2', | ||
}, | ||
{ | ||
type: 'folder', | ||
name: 'pictures', | ||
id: '3', | ||
collapsed: true, | ||
children: [ | ||
{ | ||
name: 'mountain.jpg', | ||
type: 'file', | ||
sizeKB: 302, | ||
id: '5', | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
type: 'file', | ||
name: 'last.txt', | ||
id: '7', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const columns: Record<string, InfiniteTableColumn<FileSystemNode>> = { | ||
name: { | ||
field: 'name', | ||
renderTreeIcon: true, | ||
|
||
renderValue: ({ value, data }) => { | ||
return ( | ||
<> | ||
{value} - {data!.id} | ||
</> | ||
); | ||
}, | ||
}, | ||
type: { field: 'type' }, | ||
sizeKB: { field: 'sizeKB' }, | ||
}; | ||
export default function App() { | ||
const [dataSourceApi, setDataSourceApi] = | ||
React.useState<DataSourceApi<FileSystemNode> | null>(null); | ||
|
||
const removeRowsByPrimaryKey = async () => { | ||
if (!dataSourceApi) { | ||
return; | ||
} | ||
|
||
dataSourceApi.removeDataArray([{ id: '3' }, { id: '7' }]); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button type="button" onClick={removeRowsByPrimaryKey}> | ||
Click to remove children | ||
</button> | ||
<TreeDataSource<FileSystemNode> | ||
onReady={setDataSourceApi} | ||
data={nodes} | ||
primaryKey="id" | ||
nodesKey="children" | ||
> | ||
<TreeGrid<FileSystemNode> | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: 900, | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columns={columns} | ||
/> | ||
</TreeDataSource> | ||
</> | ||
); | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/src/pages/tests/table/treegrid/remove-children-of-collapsed-node.spec.ts
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,28 @@ | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe.parallel('TreeDataSourceApi', () => { | ||
test('removeDataArray - with ids of collapsed children', async ({ | ||
page, | ||
rowModel, | ||
treeModel, | ||
}) => { | ||
await page.waitForInfinite(); | ||
|
||
let rowCount = await rowModel.getRenderedRowCount(); | ||
|
||
expect(rowCount).toBe(5); | ||
|
||
await treeModel.toggleParentNode(0); | ||
|
||
rowCount = await rowModel.getRenderedRowCount(); | ||
|
||
expect(rowCount).toBe(1); | ||
|
||
await page.click('button:text("Click to remove children")'); | ||
await treeModel.toggleParentNode(0); | ||
|
||
rowCount = await rowModel.getRenderedRowCount(); | ||
|
||
expect(rowCount).toBe(2); | ||
}); | ||
}); |
140 changes: 140 additions & 0 deletions
140
examples/src/pages/tests/table/treegrid/test-isNodeExpanded.page.tsx
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,140 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
DataSourcePropIsNodeExpanded, | ||
InfiniteTableColumn, | ||
TreeDataSource, | ||
TreeExpandState, | ||
TreeGrid, | ||
} from '@infinite-table/infinite-react'; | ||
import { useState } from 'react'; | ||
|
||
export type FileSystemNode = { | ||
name: string; | ||
type: 'file' | 'folder'; | ||
children?: FileSystemNode[] | null; | ||
sizeKB?: number; | ||
id: string; | ||
collapsed?: boolean; | ||
}; | ||
|
||
export const nodes: FileSystemNode[] = [ | ||
{ | ||
name: 'Documents', | ||
type: 'folder', | ||
id: '1', | ||
children: [ | ||
{ | ||
name: 'report.doc', | ||
type: 'file', | ||
sizeKB: 100, | ||
id: '2', | ||
}, | ||
{ | ||
type: 'folder', | ||
name: 'pictures', | ||
id: '3', | ||
children: [ | ||
{ | ||
name: 'mountain.jpg', | ||
type: 'file', | ||
sizeKB: 302, | ||
id: '5', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'folder', | ||
name: 'diverse', | ||
id: '4', | ||
children: [ | ||
{ | ||
name: 'beach.jpg', | ||
type: 'file', | ||
sizeKB: 2024, | ||
id: '6', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'file', | ||
name: 'last.txt', | ||
id: '7', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const columns: Record<string, InfiniteTableColumn<FileSystemNode>> = { | ||
name: { | ||
field: 'name', | ||
renderTreeIcon: true, | ||
|
||
renderValue: ({ value, data }) => { | ||
return ( | ||
<> | ||
{value} - {data!.id} | ||
</> | ||
); | ||
}, | ||
}, | ||
type: { field: 'type' }, | ||
sizeKB: { field: 'sizeKB' }, | ||
}; | ||
|
||
export default function DataTestPage() { | ||
const [treeExpandState] = useState<TreeExpandState>(() => { | ||
return new TreeExpandState({ | ||
defaultExpanded: false, | ||
expandedPaths: [['1', '4', '5'], ['1']], | ||
}); | ||
}); | ||
const [key, setKey] = useState(0); | ||
const isNodeExpanded = React.useCallback< | ||
DataSourcePropIsNodeExpanded<FileSystemNode> | ||
>( | ||
(rowInfo) => { | ||
return rowInfo.data.id === '3' | ||
? false | ||
: treeExpandState.isNodeExpanded(rowInfo.nodePath); | ||
}, | ||
[key], | ||
); | ||
|
||
return ( | ||
<React.StrictMode> | ||
<button | ||
onClick={() => { | ||
treeExpandState.expandAll(); | ||
setKey((k) => k + 1); | ||
}} | ||
> | ||
expand all | ||
</button> | ||
<TreeDataSource<FileSystemNode> | ||
data={nodes} | ||
primaryKey="id" | ||
nodesKey="children" | ||
treeExpandState={treeExpandState} | ||
onTreeExpandStateChange={(treeExpandStateValue) => { | ||
treeExpandState.update(treeExpandStateValue); | ||
setKey((k) => k + 1); | ||
}} | ||
isNodeExpanded={isNodeExpanded} | ||
> | ||
<TreeGrid<FileSystemNode> | ||
wrapRowsHorizontally | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: 900, | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columns={columns} | ||
/> | ||
</TreeDataSource> | ||
</React.StrictMode> | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/src/pages/tests/table/treegrid/test-isNodeExpanded.spec.ts
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,27 @@ | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe('isNodeExpanded', () => { | ||
test('works as expected', async ({ page, rowModel, tableModel }) => { | ||
await page.waitForInfinite(); | ||
|
||
const cell = tableModel.withCell({ | ||
rowIndex: 2, | ||
colIndex: 0, | ||
}); | ||
|
||
const collapsedNode = tableModel.withCell({ | ||
rowIndex: 3, | ||
colIndex: 0, | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(5); | ||
expect(await cell.isTreeIconExpanded()).toBe(false); | ||
expect(await collapsedNode.isTreeIconExpanded()).toBe(false); | ||
|
||
await page.click('button:text("expand all")'); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(6); | ||
expect(await cell.isTreeIconExpanded()).toBe(false); | ||
expect(await collapsedNode.isTreeIconExpanded()).toBe(true); | ||
}); | ||
}); |
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
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.