Skip to content

Commit

Permalink
Revert "refactor: update rows with __updateVisibleRows() when receivi…
Browse files Browse the repository at this point in the history
…ng a page (#5733)" (#5755)
  • Loading branch information
DiegoCardoso authored Apr 14, 2023
1 parent 6711b6a commit e45dd5c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
11 changes: 9 additions & 2 deletions packages/grid/src/vaadin-grid-data-provider-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const DataProviderMixin = (superClass) =>
el.index = index;
const { cache, scaledIndex } = this._cache.getCacheAndIndex(index);
const item = cache.items[scaledIndex];
if (item !== undefined) {
if (item) {
this.__updateLoading(el, false);
this._updateItem(el, item);
if (this._isExpanded(item)) {
Expand Down Expand Up @@ -424,7 +424,14 @@ export const DataProviderMixin = (superClass) =>
// Schedule a debouncer to update the visible rows
this._debouncerApplyCachedData = Debouncer.debounce(this._debouncerApplyCachedData, timeOut.after(0), () => {
this._setLoading(false);
this.__updateVisibleRows();

this._getVisibleRows().forEach((row) => {
const cachedItem = this._cache.getItemForIndex(row.index);
if (cachedItem) {
this._getItem(row.index, row);
}
});

this.__scrollToPendingIndexes();
});

Expand Down
8 changes: 4 additions & 4 deletions packages/grid/test/data-provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ describe('wrapped grid', () => {

container.dataProvider = (params, callback) => {
expect(grid.loading).to.be.true;
callback(Array.from({ length: params.pageSize }, (_, i) => i));
callback(Array(params.pageSize));
expect(grid.loading).not.to.be.true;

cancelAnimationFrame(raf);
Expand All @@ -791,7 +791,7 @@ describe('wrapped grid', () => {
container.dataProvider = (params, callback) => {
cb = callback;
};
cb(Array.from({ length: 25 }, (_, i) => i));
cb(Array(25));
expect(grid.loading).not.to.be.true;
grid.clearCache();
expect(grid.loading).to.be.true;
Expand All @@ -812,14 +812,14 @@ describe('wrapped grid', () => {

it('should clear loading attribute from rows when data received', () => {
container.dataProvider = (params, callback) => {
callback([{}], 1);
callback([{}]);
};
expect(getRows(grid.$.items)[0].hasAttribute('loading')).to.be.false;
});

it('should remove loading from cells part attribute when data received', () => {
container.dataProvider = (params, callback) => {
callback([{}], 1);
callback([{}]);
};
const row = getRows(grid.$.items)[0];
getRowCells(row).forEach((cell) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/test/row-details.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('row details', () => {

describe('details opened attribute', () => {
let dataset = [];
const dataProvider = (params, callback) => callback(dataset, dataset.length);
const dataProvider = (params, callback) => callback(dataset);

const countRowsMarkedAsDetailsOpened = (grid) => {
return grid.$.items.querySelectorAll('tr[details-opened]').length;
Expand All @@ -294,7 +294,7 @@ describe('row details', () => {
beforeEach(async () => {
dataset = buildDataSet(10);
grid = fixtureSync(`
<vaadin-grid style="width: 50px; height: 400px" size="10">
<vaadin-grid style="width: 50px; height: 400px" size="100">
<vaadin-grid-column></vaadin-grid-column>
</vaadin-grid>
`);
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/test/scroll-to-index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ describe('scroll to index', () => {

it('should not reassign the first item on scrollToIndex', () => {
const newExpectedSize = grid.size + 1;
data.push({ index: 11 });
grid.size = newExpectedSize;
data.push({ index: 11 });
grid.scrollToIndex(grid.size - 1);

expect(grid.$.items.children[0]._item.index).to.equal(0);
Expand Down

0 comments on commit e45dd5c

Please sign in to comment.