-
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.
fix tree selection bug and release version patch fixes #255
- Loading branch information
1 parent
0c4b459
commit 39af92e
Showing
6 changed files
with
342 additions
and
3 deletions.
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
examples/src/pages/tests/table/treegrid/selection2.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,182 @@ | ||
import { | ||
DataSourceApi, | ||
InfiniteTableColumn, | ||
TreeDataSource, | ||
TreeGrid, | ||
TreeSelectionValue, | ||
} from '@infinite-table/infinite-react'; | ||
import { useState } from 'react'; | ||
|
||
type FileSystemNode = { | ||
id: string; | ||
name: string; | ||
type: 'folder' | 'file'; | ||
extension?: string; | ||
mimeType?: string; | ||
sizeInKB: number; | ||
children?: FileSystemNode[]; | ||
}; | ||
|
||
const columns: Record<string, InfiniteTableColumn<FileSystemNode>> = { | ||
name: { | ||
field: 'name', | ||
header: 'Name', | ||
defaultWidth: 500, | ||
renderValue: ({ value, rowInfo }) => { | ||
return ( | ||
<div style={{ color: 'red', display: 'inline-block' }}> | ||
{rowInfo.id} - {value} | ||
</div> | ||
); | ||
}, | ||
renderTreeIcon: true, | ||
renderSelectionCheckBox: true, | ||
}, | ||
type: { field: 'type', header: 'Type' }, | ||
extension: { field: 'extension', header: 'Extension' }, | ||
mimeType: { field: 'mimeType', header: 'Mime Type' }, | ||
size: { field: 'sizeInKB', type: 'number', header: 'Size (KB)' }, | ||
}; | ||
|
||
const defaultTreeSelection: TreeSelectionValue = { | ||
defaultSelection: true, | ||
deselectedPaths: [ | ||
['1', '10'], | ||
['3', '31'], | ||
], | ||
selectedPaths: [['3']], | ||
}; | ||
|
||
export default function App() { | ||
const [dataSourceApi, setDataSourceApi] = | ||
useState<DataSourceApi<FileSystemNode> | null>(); | ||
|
||
return ( | ||
<> | ||
<TreeDataSource | ||
onReady={setDataSourceApi} | ||
nodesKey="children" | ||
primaryKey="id" | ||
data={dataSource} | ||
defaultTreeSelection={defaultTreeSelection} | ||
> | ||
<div | ||
style={{ | ||
color: 'var(--infinite-cell-color)', | ||
padding: 10, | ||
display: 'flex', | ||
gap: 10, | ||
}} | ||
> | ||
<button | ||
onClick={() => { | ||
dataSourceApi!.treeApi.selectAll(); | ||
}} | ||
> | ||
Select all | ||
</button> | ||
<button | ||
onClick={() => { | ||
dataSourceApi!.treeApi.deselectAll(); | ||
}} | ||
> | ||
Deselect all | ||
</button> | ||
</div> | ||
|
||
<TreeGrid columns={columns} domProps={{ style: { height: '100%' } }} /> | ||
</TreeDataSource> | ||
</> | ||
); | ||
} | ||
|
||
const dataSource = () => { | ||
const nodes: FileSystemNode[] = [ | ||
{ | ||
id: '1', | ||
name: 'Documents', | ||
sizeInKB: 1200, | ||
type: 'folder', | ||
children: [ | ||
{ | ||
id: '10', | ||
name: 'Private', | ||
sizeInKB: 100, | ||
type: 'folder', | ||
children: [ | ||
{ | ||
id: '100', | ||
name: 'Report.docx', | ||
sizeInKB: 210, | ||
type: 'file', | ||
extension: 'docx', | ||
mimeType: 'application/msword', | ||
}, | ||
{ | ||
id: '101', | ||
name: 'Vacation.docx', | ||
sizeInKB: 120, | ||
type: 'file', | ||
extension: 'docx', | ||
mimeType: 'application/msword', | ||
}, | ||
{ | ||
id: '102', | ||
name: 'CV.pdf', | ||
sizeInKB: 108, | ||
type: 'file', | ||
extension: 'pdf', | ||
mimeType: 'application/pdf', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Desktop', | ||
sizeInKB: 1000, | ||
type: 'folder', | ||
children: [ | ||
{ | ||
id: '20', | ||
name: 'unknown.txt', | ||
sizeInKB: 100, | ||
type: 'file', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: '3', | ||
name: 'Media', | ||
sizeInKB: 1000, | ||
type: 'folder', | ||
children: [ | ||
{ | ||
id: '30', | ||
name: 'Music - empty', | ||
sizeInKB: 0, | ||
type: 'folder', | ||
children: [], | ||
}, | ||
{ | ||
id: '31', | ||
name: 'Videos', | ||
sizeInKB: 5400, | ||
type: 'folder', | ||
children: [ | ||
{ | ||
id: '310', | ||
name: 'Vacation.mp4', | ||
sizeInKB: 108, | ||
type: 'file', | ||
extension: 'mp4', | ||
mimeType: 'video/mp4', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
return Promise.resolve(nodes); | ||
}; |
21 changes: 21 additions & 0 deletions
21
examples/src/pages/tests/table/treegrid/selection2.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,21 @@ | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe('TreeSelectionProp', () => { | ||
test('when defined, makes selectionMode default to multi-row', async ({ | ||
page, | ||
}) => { | ||
await page.waitForInfinite(); | ||
|
||
const headerCheckbox = await page.locator( | ||
'.InfiniteHeader input[type="checkbox"]', | ||
); | ||
expect( | ||
await headerCheckbox?.evaluate((el) => { | ||
return { | ||
checked: (el as HTMLInputElement).checked, | ||
indeterminate: (el as HTMLInputElement).indeterminate, | ||
}; | ||
}), | ||
).toEqual({ checked: false, indeterminate: 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