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

[DataGrid] Send warning when the rowCount is provided with server #3902

Merged
merged 15 commits into from
Mar 1, 2022

Conversation

alexfauquette
Copy link
Member

Fix #3602

The first commit is made to send a warning if the paginationMode="server" and the rowCount is undefined. This should help developers to fix the bug.

About the default behavior of Appolo (having data undefined during loading), the only solution I found is to keep the previous rowCount when it moves from a number to undefined. I coded it for discussion, but I think it's better to ask for developers to provide clean props than desynchronize the state and the props of the DataGrid

@mui-bot
Copy link

mui-bot commented Feb 9, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 284.8 509.8 387.9 397 91.704
Sort 100k rows ms 536.6 943 805.4 780.14 134.211
Select 100k rows ms 188.5 314.9 220.9 231 46.244
Deselect 100k rows ms 124.1 283.9 168.3 183.3 53.457

Generated by 🚫 dangerJS against eadb890

@@ -0,0 +1,12 @@
export const buildWarning = (message: string | string[]) => {
Copy link
Member

Choose a reason for hiding this comment

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

In wrapWithDeprecationWarning I am doing the env check inside the method, which I think makes the product-code more readable.

And I propose we move the wrapWithDeprecationWarning in this file as well and rename it wrapWithWarning as there goal is very similar.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can do so because you don't have a if condition to verify before sending the warning.

Since it is a deprecated function, as soon as the function is called you log the message saying "hey it's deprecated"

Here it s not the case, I have a custome if between the env check and the warning. So the wrapper will need to get a function computing the condition in which warning must be logged a bit like that, but not sure it makes the code clearer

export const buildConsistencyWarning = (message: string | string[], warningCondition: () => boolean) => {
  if (process.env.NODE_ENV === 'production') {
    return () => null
  }
  let alreadyWarned = false;

  const cleanMessage = Array.isArray(message) ? message.join('\n') : message;

  return (...params) => {
    if (!alreadyWarned && warningCondition(...params)) {
      alreadyWarned = true;
      console.warn(cleanMessage);
    }
  };
};

Copy link
Member

@flaviendelangle flaviendelangle Feb 9, 2022

Choose a reason for hiding this comment

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

It has the benefits of hiding the env topic in a single file and be sure to never forget it.
But as you like, I agree that the gain is less clear that for the deprecation for the reason you explained.

@flaviendelangle
Copy link
Member

I don't know what the best behavior is here.
Could we consider that when loading={true} we don't reset some props when they switch to undefined ?

@alexfauquette
Copy link
Member Author

alexfauquette commented Feb 11, 2022

I'm not in favor of using loading prop to adapt the internal behavior.

For now, loading is only about displaying the loading overlay. Not adding custom logic. It allows developers to use it with no side effects.

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 14, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 17, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 17, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 21, 2022
@flaviendelangle
Copy link
Member

I think it's better to ask for developers to provide clean props than desynchronize the state and the props of the DataGrid

Agreed

}
}
}, [props.rowCount, props.paginationMode]);

React.useEffect(() => {
apiRef.current.setState((state) => {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to:

  • Remove this logic
  • Add a doc note on the pagination server saying that if the rowCount switch to undefined while loading, users must to the trick you implemented here
  • Implement the same trick but in our server pagination demo (and change the fake server behavior to return "undefined" while loading
  • Change the warning to link to the doc note

Copy link
Member Author

Choose a reason for hiding this comment

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

🤯 That's a mind-blowing suggestion:
creating a horrible demo to let users know how to do 😄

Copy link
Member

Choose a reason for hiding this comment

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

"Horrible", it's the Apollo Client behavior 😆
But alternatively, we can add a new "Apollo Client" section. It would make sense to start giving examples with various famous data management libraries.

@alexfauquette
Copy link
Member Author

I moved the message to the level of an 'error' because it is more important now that we do not correct it by magic.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 24, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 25, 2022
@github-actions
Copy link

github-actions bot commented Mar 1, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 1, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 1, 2022
@flaviendelangle flaviendelangle added component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation feature: Pagination Related to the data grid Pagination feature labels Mar 1, 2022
Co-authored-by: Flavien DELANGLE <flaviendelangle@gmail.com>
@alexfauquette alexfauquette merged commit 136c7f1 into mui:master Mar 1, 2022
@alexfauquette alexfauquette deleted the warn-serverPagination branch March 1, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation feature: Pagination Related to the data grid Pagination feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DatagridPro] Using GraphQl and Apollo Graphql using pagination does not work
4 participants