Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update rows with __updateVisibleRows() when receiving a page #5733

Merged
merged 3 commits into from
Apr 3, 2023

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Mar 31, 2023

Description

There is an __updateVisibleRows() method that updates grid rows' content and the related a11y attributes. The custom implementations based on this._getVisibleRows().forEach(...) can be replaced with it.

Type of change

  • Internal

@@ -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) {
if (item !== undefined) {
Copy link
Contributor Author

@vursen vursen Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Without this change, the grid falls into an infinite loop if one of the items is 0.

data.push({ index: 11 });
grid.size = newExpectedSize;
Copy link
Contributor Author

@vursen vursen Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: This size change triggered an immediate data provider request while the data array was only updated on the following line.

@vursen vursen marked this pull request as ready for review March 31, 2023 13:51
@vursen vursen requested a review from tomivirkki March 31, 2023 13:52
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -770,7 +770,7 @@ describe('wrapped grid', () => {

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

@vursen vursen Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The grid doesn't support using undefined as an item.

@@ -791,7 +791,7 @@ describe('wrapped grid', () => {
container.dataProvider = (params, callback) => {
cb = callback;
};
cb(Array(25));
cb(Array.from({ length: 25 }, (_, i) => i));
Copy link
Contributor Author

@vursen vursen Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The grid doesn't support using undefined as an item.

@@ -812,14 +812,14 @@ describe('wrapped grid', () => {

it('should clear loading attribute from rows when data received', () => {
container.dataProvider = (params, callback) => {
callback([{}]);
callback([{}], 1);
Copy link
Contributor Author

@vursen vursen Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The grid size should be updated when the data provider is going to return fewer items than specified by size. Otherwise, the virtualizer will always try to request more items than the data provider can provide => infinite loop.

};
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([{}]);
callback([{}], 1);
Copy link
Contributor Author

@vursen vursen Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The grid size should be updated when the data provider is going to return fewer items than specified by size. Otherwise, the virtualizer will always try to request more items than the data provider can provide => infinite loop.

@@ -294,7 +294,7 @@ describe('row details', () => {
beforeEach(async () => {
dataset = buildDataSet(10);
grid = fixtureSync(`
<vaadin-grid style="width: 50px; height: 400px" size="100">
<vaadin-grid style="width: 50px; height: 400px" size="10">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The grid size didn't match the number of items the data provider actually returned (10).

@vursen vursen merged commit b16f960 into main Apr 3, 2023
@vursen vursen deleted the refactor/use-update-visible-rows-method branch April 3, 2023 09:04
@vursen vursen changed the title refactor: use __updateVisibleRows() instead of a custom implementation refactor: update rows with __updateVisibleRows() when receiving a page Apr 3, 2023
DiegoCardoso added a commit that referenced this pull request Apr 14, 2023
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.1.0.alpha3 and is also targeting the upcoming stable 24.1.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants