-
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.
implement repeatGroupRows in tree horizontal layout
- Loading branch information
1 parent
1f1deb9
commit 298e034
Showing
20 changed files
with
865 additions
and
105 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
117 changes: 117 additions & 0 deletions
117
examples/src/pages/tests/table/treegrid/custom-collapsed.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,117 @@ | ||
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', | ||
collapsed: true, | ||
children: [ | ||
{ | ||
name: 'mountain.jpg', | ||
type: 'file', | ||
sizeKB: 302, | ||
id: '5', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'folder', | ||
name: 'misc', | ||
id: '4', | ||
collapsed: true, | ||
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() { | ||
return ( | ||
<React.StrictMode> | ||
<TreeDataSource<FileSystemNode> | ||
data={nodes} | ||
primaryKey="id" | ||
nodesKey="children" | ||
isNodeExpanded={({ data }) => data.collapsed !== true} | ||
onTreeExpandStateChange={( | ||
_treeExpandState, | ||
{ dataSourceApi, nodePath, nodeState }, | ||
) => { | ||
if (nodePath) { | ||
const data = dataSourceApi.treeApi.getNodeDataByPath(nodePath)!; | ||
|
||
data.collapsed = nodeState === 'collapsed' ? true : false; | ||
} | ||
}} | ||
> | ||
<TreeGrid<FileSystemNode> | ||
wrapRowsHorizontally | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: 900, | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columns={columns} | ||
/> | ||
</TreeDataSource> | ||
</React.StrictMode> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/src/pages/tests/table/treegrid/custom-collapsed.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,18 @@ | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe('Custom collapse', () => { | ||
test('should work when passing an isNodeCollapsed fn', async ({ | ||
page, | ||
rowModel, | ||
}) => { | ||
await page.waitForInfinite(); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(5); | ||
|
||
await rowModel.toggleGroupRow(2); | ||
expect(await rowModel.getRenderedRowCount()).toBe(6); | ||
|
||
await rowModel.toggleGroupRow(2); | ||
expect(await rowModel.getRenderedRowCount()).toBe(5); | ||
}); | ||
}); |
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
129 changes: 129 additions & 0 deletions
129
examples/src/pages/tests/table/treegrid/expand-collapse.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,129 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTableColumn, | ||
TreeDataSource, | ||
TreeGrid, | ||
TreeSelectionValue, | ||
} from '@infinite-table/infinite-react'; | ||
import { useState } from 'react'; | ||
import { TreeExpandStateValue } 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: '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, | ||
renderSelectionCheckBox: true, | ||
renderValue: ({ value, data }) => { | ||
return ( | ||
<> | ||
{value} - {data!.id} | ||
</> | ||
); | ||
}, | ||
}, | ||
type: { field: 'type' }, | ||
sizeKB: { field: 'sizeKB' }, | ||
}; | ||
|
||
export default function DataTestPage() { | ||
const [treeSelectionState, setTreeSelectionState] = | ||
useState<TreeSelectionValue>({ | ||
defaultSelection: false, | ||
selectedPaths: [ | ||
['1', '4', '5'], | ||
['1', '3'], | ||
], | ||
}); | ||
const [treeExpandState, setTreeExpandState] = useState<TreeExpandStateValue>({ | ||
defaultExpanded: true, | ||
collapsedPaths: [], | ||
}); | ||
return ( | ||
<React.StrictMode> | ||
<TreeDataSource<FileSystemNode> | ||
data={nodes} | ||
primaryKey="id" | ||
nodesKey="children" | ||
selectionMode="multi-row" | ||
treeSelection={treeSelectionState} | ||
onTreeSelectionChange={setTreeSelectionState} | ||
treeExpandState={treeExpandState} | ||
onTreeExpandStateChange={(expandState) => { | ||
console.log('expandState', expandState); | ||
debugger; | ||
setTreeExpandState(expandState); | ||
}} | ||
> | ||
<TreeGrid<FileSystemNode> | ||
wrapRowsHorizontally | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: 900, | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columns={columns} | ||
/> | ||
</TreeDataSource> | ||
</React.StrictMode> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
examples/src/pages/tests/table/treegrid/expand-collapse.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,39 @@ | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe('Controlled collapse and expand', () => { | ||
test('should work via the api', async ({ page, apiModel, rowModel }) => { | ||
await page.waitForInfinite(); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(7); | ||
|
||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.collapseAll(); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(1); | ||
|
||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.expandAll(); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(7); | ||
|
||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.collapseNode(['1', '3']); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(6); | ||
|
||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.collapseNode(['1']); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(1); | ||
|
||
await apiModel.evaluateDataSource((api) => { | ||
api.treeApi.expandNode(['1']); | ||
}); | ||
|
||
expect(await rowModel.getRenderedRowCount()).toBe(6); | ||
}); | ||
}); |
Oops, something went wrong.