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: make combo-box use DataProviderController #7044

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Dec 29, 2023

@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from 3fbad4a to b3e1d14 Compare December 29, 2023 08:28
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from e96006a to 223e39f Compare December 29, 2023 10:30
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from 5e2e3bf to ab03e1e Compare January 12, 2024 06:45
Copy link

sonarcloud bot commented Jan 12, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from ab03e1e to 34ecc64 Compare February 23, 2024 07:21
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch 6 times, most recently from 1418504 to f08d006 Compare March 23, 2024 09:49
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from 73cc8c8 to 9957d9c Compare April 19, 2024 08:03
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch 4 times, most recently from bd70e58 to 065f12b Compare April 19, 2024 18:50
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch 3 times, most recently from 630a74a to d8a450b Compare May 3, 2024 19:18
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from 33d13ba to 8963067 Compare May 17, 2024 11:45
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch 2 times, most recently from fcbea2c to 9e4b5e2 Compare May 17, 2024 12:56
@vursen vursen changed the title [WIP] refactor: make combo-box use DataProviderController refactor: make combo-box use DataProviderController May 17, 2024
@vursen vursen marked this pull request as ready for review May 17, 2024 16:12
Comment on lines +170 to +174
Object.keys(this.pendingRequests).forEach((page) => {
const startIndex = parseInt(page) * this.pageSize;
if (startIndex >= this.size || 0) {
delete this.pendingRequests[page];
}
});
Copy link
Contributor Author

@vursen vursen May 20, 2024

Choose a reason for hiding this comment

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

note: This change also affects grid, but it makes sense there as well.

Comment on lines 153 to 159
// The controller adds new items to the cache through mutation,
// so we need to create a new array to trigger filteredItems observers.
const { rootCache } = this._dataProviderController;
rootCache.items = [...rootCache.items];
Copy link
Contributor Author

@vursen vursen May 21, 2024

Choose a reason for hiding this comment

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

note: This would become unnecessary if we improved the combo-box's requestContentUpdate to properly handle mutations in filteredItems. The scroller's requestContentUpdate is already capable of handling dropdownItems mutations. However, we also have focused index restoration logic that happens in _setDropdownItems and currently relies on filteredItems being immutable. We could consider improving this separately.

Copy link
Contributor

@DiegoCardoso DiegoCardoso left a comment

Choose a reason for hiding this comment

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

Some new methods/properties that are meant to be private don't follow the naming convention. Added change suggestions to rename them to use double underscore prefixes.

Comment on lines 117 to 121
this.size = undefined;
this.clearCache();
Copy link
Contributor Author

@vursen vursen May 22, 2024

Choose a reason for hiding this comment

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

The requestContentUpdate method is called twice during these two lines. To optimize, we could set the undefined size in the controller instead of the component so that requestContentUpdate is only called in clearCache. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the tests pass now even with this.size = undefined; removed. Are we missing a test case for this?

@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from a564ed6 to e7f0ea6 Compare May 24, 2024 09:20
wip

wip

remove hasData API from DataProviderController

get rid of page-received

fix JSDoc

add isPlaceholder for backward compatibility

reduce diff

fix tests

remove unnecessary this binding

revert some changes, add more tests

wip

wip

update data provider controller tests

minimize diff

revert incorrect change after rebase

minimize diff

remove extra checks

improve JSDoc

fix corner case, add test

enhance JSDoc

fix tests

reassign cache items to trigger filteredItems observer

add code comments

fix

wip

revert check for size from setPage

fix failing tests

remove unnecessary check

revert unnecessary changes

use logical assignment operator

make data provider controller properties and listeners private
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from e7f0ea6 to b58e6d2 Compare May 24, 2024 09:22
size: this.size,
pageSize: this.pageSize,
placeholder: new ComboBoxPlaceholder(),
isPlaceholder: (item) => item instanceof ComboBoxPlaceholder,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this line is untested (all the tests still pass when I remove it).

* @private
*/
this.__dataProviderController = new DataProviderController(this, {
size: this.size,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this line is untested (all the tests still pass when I remove it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I removed this line.

*/
this.__dataProviderController = new DataProviderController(this, {
size: this.size,
pageSize: this.pageSize,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this line is untested (all the tests still pass when I remove it).
Maybe it's not needed as we set page size in the observer?

Copy link
Contributor Author

@vursen vursen May 24, 2024

Choose a reason for hiding this comment

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

Removed this line.

pageSize: this.pageSize,
placeholder: new ComboBoxPlaceholder(),
isPlaceholder: (item) => item instanceof ComboBoxPlaceholder,
dataProvider: this.dataProvider,
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this line is untested (all the tests still pass when I remove it).
Maybe it's not needed as we set dataProvider in the observer?

Copy link
Contributor Author

@vursen vursen May 24, 2024

Choose a reason for hiding this comment

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

Removed this line.

rootCache.size = size;
// The controller adds new placeholders to the cache through mutation,
// so we need to create a new array to trigger filteredItems observers.
rootCache.items = [...rootCache.items];
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this line is untested (all the tests still pass when I remove it).

@@ -244,6 +238,8 @@ export const ComboBoxDataProviderMixin = (superClass) =>
this.pageSize = oldPageSize;
throw new Error('`pageSize` value must be an integer > 0');
}

this.__dataProviderController.setPageSize(pageSize);
Copy link
Member

Choose a reason for hiding this comment

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

nit: looks like all the tests pass with clearCache() line below being removed.
But this also happens on main so not related to this PR, can be ignored.

@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch 3 times, most recently from c3695be to add3e15 Compare May 24, 2024 14:39
@vursen vursen force-pushed the refactor/combo-box/data-provider-controller branch from add3e15 to a022592 Compare May 24, 2024 14:42
Copy link

sonarcloud bot commented May 24, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

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

Successfully merging this pull request may close these issues.

None yet

4 participants