forked from uber/baseweb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-table): add onIncludedRowsChange callback (uber#3130)
* feat(data-table): add onIncludedRowsChange callback * test(vrt): update visual snapshots for 893c273 [skip ci] (uber#3131) Co-authored-by: UberOpenSourceBot <UberOpenSourceBot@users.noreply.github.com> * fix(data-table): lint Co-authored-by: UberOpenSourceBot <33560951+UberOpenSourceBot@users.noreply.github.com> Co-authored-by: UberOpenSourceBot <UberOpenSourceBot@users.noreply.github.com>
- Loading branch information
1 parent
0caa857
commit 2e48cb6
Showing
9 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/data-table/__tests__/data-table-included-rows-change.e2e.js
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,33 @@ | ||
/* | ||
Copyright (c) 2018-2020 Uber Technologies, Inc. | ||
This source code is licensed under the MIT license found in the | ||
LICENSE file in the root directory of this source tree. | ||
*/ | ||
/* eslint-env node */ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
|
||
const {mount} = require('../../../e2e/helpers'); | ||
|
||
const {sortColumnAtIndex, matchArrayElements} = require('./utilities.js'); | ||
|
||
describe('data table columns', () => { | ||
it('updates application state when rows change', async () => { | ||
const index = 0; | ||
await mount(page, 'data-table-included-rows-change'); | ||
await page.waitFor('div[data-baseweb="data-table"]'); | ||
|
||
const initialLi = await page.$$('li'); | ||
const initial = await Promise.all( | ||
initialLi.map(li => page.evaluate(e => e.textContent, li)), | ||
); | ||
expect(matchArrayElements(initial, ['1', '2', '3', '4'])).toBe(true); | ||
|
||
await sortColumnAtIndex(page, index); | ||
const afterLi = await page.$$('li'); | ||
const after = await Promise.all( | ||
afterLi.map(li => page.evaluate(e => e.textContent, li)), | ||
); | ||
expect(matchArrayElements(after, ['1', '3', '2', '4'])).toBe(true); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
src/data-table/__tests__/data-table-included-rows-change.scenario.js
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,54 @@ | ||
/* | ||
Copyright (c) 2018-2020 Uber Technologies, Inc. | ||
This source code is licensed under the MIT license found in the | ||
LICENSE file in the root directory of this source tree. | ||
*/ | ||
// @flow | ||
|
||
import * as React from 'react'; | ||
|
||
import {Unstable_StatefulDataTable, BooleanColumn} from '../index.js'; | ||
|
||
type RowDataT = [boolean, string, number, string, Date]; | ||
|
||
const columns = [ | ||
BooleanColumn({ | ||
title: 'boolean-column', | ||
mapDataToValue: (data: RowDataT) => data[0], | ||
}), | ||
]; | ||
|
||
const rows = [ | ||
{id: 1, data: [true]}, | ||
{id: 2, data: [false]}, | ||
{id: 3, data: [true]}, | ||
{id: 4, data: [false]}, | ||
]; | ||
|
||
export default function Scenario() { | ||
const [includedRows, setIncludedRows] = React.useState([]); | ||
const handleIncludedRowsChange = React.useCallback( | ||
included => { | ||
setIncludedRows(included); | ||
}, | ||
[setIncludedRows], | ||
); | ||
|
||
return ( | ||
<React.Fragment> | ||
<div style={{height: '400px', width: '600px', marginBottom: '10px'}}> | ||
<Unstable_StatefulDataTable | ||
columns={columns} | ||
rows={rows} | ||
onIncludedRowsChange={handleIncludedRowsChange} | ||
/> | ||
</div> | ||
<ul> | ||
{includedRows.map(row => ( | ||
<li key={row.id}>{row.id}</li> | ||
))} | ||
</ul> | ||
</React.Fragment> | ||
); | ||
} |
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
Binary file added
BIN
+9.6 KB
vrt/__image_snapshots__/data-table-included-rows-change__dark-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.7 KB
vrt/__image_snapshots__/data-table-included-rows-change__desktop-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.77 KB
vrt/__image_snapshots__/data-table-included-rows-change__mobile-snap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.