-
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.
release version patch with cellSelectionApi.getAllCellSelectionPositions
- Loading branch information
1 parent
a1f93ea
commit eec311f
Showing
3 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
examples/src/pages/tests/table/props/cell-selection/get-selected-cells.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,88 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTable, | ||
DataSource, | ||
DataSourcePropCellSelection_MultiCell, | ||
InfiniteTableApi, | ||
} from '@infinite-table/infinite-react'; | ||
|
||
import type { InfiniteTablePropColumns } from '@infinite-table/infinite-react'; | ||
|
||
import { useState } from 'react'; | ||
|
||
type Developer = { | ||
id: number; | ||
|
||
firstName: string; | ||
lastName: string; | ||
country: string; | ||
city: string; | ||
currency: string; | ||
preferredLanguage: string; | ||
stack: string; | ||
canDesign: 'yes' | 'no'; | ||
hobby: string; | ||
salary: number; | ||
age: number; | ||
}; | ||
|
||
const dataSource = () => { | ||
return fetch(process.env.NEXT_PUBLIC_BASE_URL + '/developers10') | ||
.then((r) => r.json()) | ||
.then((data: Developer[]) => data); | ||
}; | ||
|
||
const columns: InfiniteTablePropColumns<Developer> = { | ||
id: { field: 'id' }, | ||
|
||
firstName: { | ||
field: 'firstName', | ||
}, | ||
|
||
preferredLanguage: { field: 'preferredLanguage' }, | ||
stack: { field: 'stack' }, | ||
}; | ||
|
||
const domProps = { | ||
style: { | ||
height: '80vh', | ||
margin: 10, | ||
}, | ||
}; | ||
|
||
export default function App() { | ||
const [_api, setApi] = useState<InfiniteTableApi<Developer> | null>(null); | ||
const [cellSelection, _setCellSelection] = | ||
useState<DataSourcePropCellSelection_MultiCell>({ | ||
selectedCells: [ | ||
[2, 'id'], | ||
[8, 'preferredLanguage'], | ||
[5, 'stack'], | ||
], | ||
deselectedCells: [[3, 'stack']], | ||
defaultSelection: false, | ||
}); | ||
|
||
return ( | ||
<> | ||
<DataSource<Developer> | ||
primaryKey="id" | ||
data={dataSource} | ||
selectionMode="multi-cell" | ||
defaultCellSelection={cellSelection} | ||
> | ||
<InfiniteTable<Developer> | ||
onReady={({ api }) => { | ||
setApi(api); | ||
}} | ||
domProps={domProps} | ||
columns={columns} | ||
keyboardSelection={true} | ||
keyboardNavigation={'cell'} | ||
columnDefaultWidth={200} | ||
/> | ||
</DataSource> | ||
</> | ||
); | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/src/pages/tests/table/props/cell-selection/get-selected-cells.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 { expect, test } from '@testing'; | ||
|
||
export default test.describe | ||
.parallel('Cell Selection - getAllCellSelectionPositions', () => { | ||
test('should work', async ({ page, apiModel }) => { | ||
await page.waitForInfinite(); | ||
|
||
const pos = await apiModel.evaluate((api) => { | ||
return api.cellSelectionApi.getAllCellSelectionPositions(); | ||
}); | ||
|
||
expect(pos).toEqual({ | ||
columnIds: ['id', 'preferredLanguage', 'stack'], | ||
positions: [ | ||
[[2, 'id'], null, null], | ||
[null, null, [5, 'stack']], | ||
[null, [8, 'preferredLanguage'], null], | ||
], | ||
}); | ||
}); | ||
}); |
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