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

feat: add useDataProvider hook #1934

Merged
merged 22 commits into from
Jan 29, 2024
Merged

Conversation

sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Dec 22, 2023

As an alternative to #1910, this implements a hook that returns a data provider function that can be passed to the grid:

const { dataProvider } = useDataProvider(MyListService);

<Grid dataProvider={dataProvider} />

It supports the same filter + refresh functionality as the implementation in #1910. In order to make this work, the hook returns a new data provider function reference when the filter changes or refresh is called, which in turn causes grid to reload.

This also requires making some changes to the data provider implementation itself, as it currently requires the grid element for a number of features. In order to remove the grid reference the following changes were necessary:

  • The infinite data provider now uses its cached filtered count instead of the grid's cache size for detecting whether to shrink the size or not. Those values should be equivalent, as long as reset is called on the data provider whenever the grid should be reloaded or the filter changes.
  • Removed the refresh functionality from the data provider itself. Instead, whatever uses the data provider needs to both reset the data provider and trigger a reload of the grid.
  • Removed the automatic reload of the grid when the filter changes in the data provider. Instead, whatever uses the data provider needs to both update the filter in the data provider and then trigger a reload of the grid.

The last two points don't concern developers really, as these automatisms are provided by AutoGrid and useDataProvider.

Copy link

codecov bot commented Dec 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (01a8b17) 95.31% compared to head (3e2e4b2) 95.33%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1934      +/-   ##
==========================================
+ Coverage   95.31%   95.33%   +0.01%     
==========================================
  Files          52       52              
  Lines        3482     3492      +10     
  Branches      524      524              
==========================================
+ Hits         3319     3329      +10     
  Misses        129      129              
  Partials       34       34              
Flag Coverage Δ
unittests 95.33% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@taefi
Copy link
Contributor

taefi commented Jan 3, 2024

Thanks @sissbruecker for this alternative implementation. IMO, both the usage and the implementation are more conventional this way. The refactoring done for removing the dependency of the DataProvider on the Grid makes it more clear and less coupled. I'm in favor of this implementation over the one suggested in #1910.

@taefi taefi mentioned this pull request Jan 4, 2024
@taefi taefi changed the title feat: useDataProvider hook (alternative) feat: add useDataProvider hook Jan 4, 2024
@taefi taefi marked this pull request as ready for review January 4, 2024 20:51
@taefi taefi requested a review from cromoteca January 9, 2024 08:07
@cromoteca cromoteca self-requested a review January 9, 2024 10:28
Copy link
Contributor

@cromoteca cromoteca left a comment

Choose a reason for hiding this comment

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

It's weird not to see useDataProvider in a TS test

@taefi taefi requested review from cromoteca and Lodin January 15, 2024 12:01
Copy link
Contributor

@Lodin Lodin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

sonarcloud bot commented Jan 29, 2024

Quality Gate Failed Quality Gate failed

Failed conditions

4.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@taefi taefi merged commit 53365a5 into main Jan 29, 2024
14 of 15 checks passed
@taefi taefi deleted the feat/use-data-provider-hook-alternative branch January 29, 2024 19:37
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Hilla 24.4.0.alpha3 and is also targeting the upcoming stable 24.4.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.

None yet

5 participants