-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Send warning when the rowCount
is provided with server
#3902
Conversation
These are the results for the performance tests:
|
packages/grid/_modules_/grid/hooks/features/pagination/useGridPage.ts
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,12 @@ | |||
export const buildWarning = (message: string | string[]) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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);
}
};
};
There was a problem hiding this comment.
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.
packages/grid/_modules_/grid/hooks/features/pagination/useGridPage.ts
Outdated
Show resolved
Hide resolved
I don't know what the best behavior is here. |
I'm not in favor of using For now, |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
packages/grid/_modules_/grid/hooks/features/pagination/useGridPage.ts
Outdated
Show resolved
Hide resolved
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Agreed |
packages/grid/x-data-grid/src/internals/hooks/features/pagination/useGridPage.ts
Outdated
Show resolved
Hide resolved
} | ||
} | ||
}, [props.rowCount, props.paginationMode]); | ||
|
||
React.useEffect(() => { | ||
apiRef.current.setState((state) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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.
I moved the message to the level of an |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Co-authored-by: Flavien DELANGLE <flaviendelangle@gmail.com>
Fix #3602
The first commit is made to send a warning if the
paginationMode="server"
and therowCount
isundefined
. 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 toundefined
. 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