-
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.
Tree/improve node selection & updating collapsed nodes (#259)
- Loading branch information
1 parent
06c6cb6
commit e7aaab5
Showing
47 changed files
with
1,699 additions
and
129 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
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
145 changes: 145 additions & 0 deletions
145
examples/src/pages/tests/table/treegrid/empty-children.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,145 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
DataSourceApi, | ||
InfiniteTableColumn, | ||
TreeDataSource, | ||
TreeGrid, | ||
} from '@infinite-table/infinite-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: [], | ||
}, | ||
{ | ||
type: 'folder', | ||
name: 'diverse', | ||
id: '4', | ||
children: [ | ||
{ | ||
name: 'beach.jpg', | ||
type: 'file', | ||
sizeKB: 2024, | ||
id: '6', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const columns: Record<string, InfiniteTableColumn<FileSystemNode>> = { | ||
name: { | ||
field: 'name', | ||
renderTreeIcon: ({ rowInfo }) => { | ||
if (!rowInfo.isParentNode) { | ||
return null; | ||
} | ||
return ( | ||
<div | ||
style={{ | ||
display: 'inline-block', | ||
width: 24, | ||
}} | ||
> | ||
{rowInfo.nodeExpanded ? '👇' : '👉'} | ||
</div> | ||
); | ||
}, | ||
renderSelectionCheckBox: true, | ||
renderValue: ({ value, data }) => { | ||
return ( | ||
<> | ||
{value} - {data!.id} | ||
</> | ||
); | ||
}, | ||
}, | ||
type: { field: 'type' }, | ||
sizeKB: { field: 'sizeKB' }, | ||
}; | ||
|
||
export default function DataTestPage() { | ||
const [dataSourceApi, setDataSourceApi] = | ||
React.useState<DataSourceApi<FileSystemNode> | null>(null); | ||
return ( | ||
<React.StrictMode> | ||
<div className="flex flex-col gap-2 bg-black justify-start p-10"> | ||
<button | ||
className="bg-white text-black p-2" | ||
onClick={() => { | ||
dataSourceApi!.updateData({ | ||
id: '3', | ||
children: undefined, | ||
}); | ||
dataSourceApi!.insertDataArray( | ||
[ | ||
{ | ||
id: 'x', | ||
name: 'x', | ||
type: 'file', | ||
}, | ||
{ | ||
id: 'y', | ||
name: 'y', | ||
type: 'file', | ||
}, | ||
], | ||
{ | ||
position: 'before', | ||
primaryKey: '6', | ||
}, | ||
); | ||
}} | ||
> | ||
Update | ||
</button> | ||
<TreeDataSource<FileSystemNode> | ||
onReady={setDataSourceApi} | ||
data={nodes} | ||
debugMode | ||
primaryKey="id" | ||
nodesKey="children" | ||
selectionMode="multi-row" | ||
> | ||
<TreeGrid<FileSystemNode> | ||
wrapRowsHorizontally | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: '80vh', | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columns={columns} | ||
columnDefaultWidth={250} | ||
/> | ||
</TreeDataSource> | ||
</div> | ||
</React.StrictMode> | ||
); | ||
} |
95 changes: 95 additions & 0 deletions
95
examples/src/pages/tests/table/treegrid/is-node-read-only.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,95 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTableColumn, | ||
TreeDataSource, | ||
TreeGrid, | ||
} from '@infinite-table/infinite-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: '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() { | ||
return ( | ||
<React.StrictMode> | ||
<TreeDataSource<FileSystemNode> | ||
data={nodes} | ||
primaryKey="id" | ||
isNodeReadOnly={(rowInfo) => rowInfo.data.id === '1'} | ||
defaultTreeExpandState={{ | ||
defaultExpanded: true, | ||
collapsedPaths: [['1']], | ||
}} | ||
> | ||
<TreeGrid<FileSystemNode> | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: 900, | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columns={columns} | ||
/> | ||
</TreeDataSource> | ||
</React.StrictMode> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
examples/src/pages/tests/table/treegrid/is-node-read-only.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,26 @@ | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe('isNodeReadOnly', () => { | ||
test('should work ', async ({ page, rowModel, treeModel, apiModel }) => { | ||
await page.waitForInfinite(); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(1); | ||
|
||
await treeModel.toggleParentNode(0); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(1); | ||
|
||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.toggleNode(['1']); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(1); | ||
|
||
// force: true should be respected | ||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.toggleNode(['1'], { force: true }); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(5); | ||
}); | ||
}); |
Oops, something went wrong.