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] Pagination refactoring #100

Merged
merged 18 commits into from
Jul 27, 2020
Merged

[DataGrid] Pagination refactoring #100

merged 18 commits into from
Jul 27, 2020

Conversation

dtassone
Copy link
Member

@dtassone dtassone commented Jul 23, 2020

Escape

Comment on lines 1 to 4
export enum FeatureMode {
Client = 'client',
Server = 'server',
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we even need a public enum for this? Do we even need a private enum for this?

Suggested change
export enum FeatureMode {
Client = 'client',
Server = 'server',
}
export enum FeatureMode {
client = 'client',
server = 'server',
}

Copy link
Member Author

Choose a reason for hiding this comment

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

it's cleaner and it avoids using magic strings. I need it in several places

Copy link
Member Author

Choose a reason for hiding this comment

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

same can't commit this change. Needs to be done across the repo

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

Ok, so you advocate for using a variable for internal usage. I used to do that often when using JavaScript only. I assumed that with TypeScript, it would duplicate with the types, making it unnecessary.

Regarding the public API? should we expose FeatureMode as, say GridPaginationFeatureMode? I'm not sure it will be really helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well we can expose it and let users decide if they want to use it or not.
I don't see why we should add a prefix like Grid or GridPagination.
I'm planning to use this enum in sorting too and probably filtering.

Users won't have name clashing, as they should use the lib in isolation of other components. It's not like they are going to use all their components in one file. Libraries don't prefix all their types with the library name.

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

What about we keep it private? We should be cautious with providing two ways to do the same things, it creates confusion around what's the correct way. It wouldn't be consistent with how we handle the API with the other components. We don't expose variables for each enum the components supports. Does it solve a problem for users?

Regarding prefixing, I think that it's important to consider that each exposed variable is in a global namespace, containing all the components. So far, we have enforced no collison on the exposed modules. I think that we should continue to do so. It's important for 1. people that grep in their codebase for refactoring 2. re-exporting the modules from @material-ui/x.

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

It's also important for the documentation, to make it more searchable. It's basically something we started discussing in https://github.com/mui-org/material-ui-pickers/issues/1778

Copy link
Member Author

@dtassone dtassone Jul 24, 2020

Choose a reason for hiding this comment

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

Well see it a bit like passing a constant instead of a string directly. In the end, it's a string.

Ok for prefixing with 'Grid' if you want. I don't mind.

I thought they would do something a bit like this, so it works with tree shaking

import { FeatureMode } from '@material-ui/x/grid'

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

Yeah, I think that Grid would be enough :), mind that we had prefixes for ExpensionPanel too, much longer.

Would you do?

import { Button, ButtonVariant } from '@material-ui/core';

<Button variant={ButtonVariant.outlined}>

Copy link
Member Author

Choose a reason for hiding this comment

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

nope I would do something like
<Button variant={theme.variant} />

In the button code, I wouldn't use "variant" as my code would be full of if(something === "variant")
As if "variant" changes then I have to rename it everywhere. Hence constants or enum.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

One item missing, otherwise, all good

const onPageChanged = (params) => {
setLoading(true);
loadServerRows(params).then((newRows) => {
setRows(newRows);
Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

Need to prevent setState if the component unmounts.

So how do you want to do that? Are you sure you want to add this complexity in the demo?

Yes, we especially want to do it if it adds complexity. It's great to feel the pain around it: "here is what it's required to do it right: ok, it's hard, ok maybe we can improve the API to make it easier".

In any case, it's important to showcase best practices. We need the feedback loop.

Copy link
Member

Choose a reason for hiding this comment

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

We have a couple of options, linking them:

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

Actually, outside of the unmounting issue, there is another one that is even more important that I forgot about: concurrent resolution.

If users switch from page 1 to page 2 then quickly to page 3 but the request for page 2 resolve after page 3, we still need to make sure we only consider the data of page 3, not the latest 2. It's not guaranteed by the current logic (if we replace setTimeout with a network request).

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

A thought for the coming months, not directly linked to the pull request.

Actually, I'm confused, for server-side pagination, won't we need a different API? I don't see how this once can scale to grouping, filtering, sorting. Maybe we don't need the server-side pagination, but only a server-side data fetcher (that would solve the unmounting and concurrency issues directly + a load more like windowing).

Copy link
Member Author

@dtassone dtassone Jul 24, 2020

Choose a reason for hiding this comment

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

Well RxJs is massively popular in react as well. Angular is built on it to manage events...
In react, events are managed by react, and server requests are out of the react scope.

That being said, in a react app it's up to you, how you build your communication layer with the server. You can use axios, fetch or rxjs if you want.
This is what makes react great and this is also why ppl go with angular as they want a full layer architecture and not just the component or rendering layer that react provides

Copy link
Member

@oliviertassinari oliviertassinari Jul 24, 2020

Choose a reason for hiding this comment

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

The proposed approach would fix two bugs with the current demo that people will face as soon as they copy the demo in their app and replace the fetch with a real network request.

Will it make the demo more complex? Not sure. It could be simpler to control the active page.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I do it

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want to manage server errors in this demo as well? Maybe add a catch with a server boundary, or we can add an error overlay in the grid which I think would be great

@dtassone dtassone merged commit 8cf1bd1 into master Jul 27, 2020
@dtassone dtassone deleted the paginationRefactoring branch July 27, 2020 09:04
dtassone added a commit that referenced this pull request Jul 27, 2020
* Release v0.1.62 (#95)

* v0.1.51

* fix demo app build

* v0.1.52

* v0.1.53

* v0.1.54

* v0.1.55

* v0.1.56

* v0.1.57

* v0.1.58

* v0.1.59

* add missing export

* v0.1.60

* v0.1.61

* hot fix for tsconfig conf

* fix mistypes on the package.json

* fix empty space with prettier

* v0.1.62

* fix lerna.json whitespace

* fix resize issue (#96)

* Bump eslint-config-airbnb-typescript from 8.0.2 to 9.0.0 (#112)

* Pagination refactoring (#100)

* implemented server pagination

* rename pagination options, doc, prettier

* fix lint

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* change casing value in featureMode and remove apiref check

* added missing dep in useEffect

* fix broken suggestion code

* fix doc comments

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* Fix FeatureMode enum and remove useCallback in demo

* fix import order

* added namespace to function call to remove import

* remove useCallback and add react. to mdx code

* add concurrency in server pagination demo

* fix feature mode export

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* [core] Use the classnames helper (#105)

* [core] Batch small changes (#104)

* [docs] Improve the JSDoc (#106)

* rename events and add onHover event (#103)

* rename events and added onHover event

* rename events and added onHover event

* fix onPageChange rename and merge

* Js doc improvements

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* added hover stories

* small fix and cleanup

* revert rename, back to onRowSelected

* refactor hover and click handlers

* refactor cellParams

* prettier

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* v0.1.63

* v0.1.64

* prettier lerna.json due to lerna

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
@oliviertassinari oliviertassinari changed the title Pagination refactoring [DataGrid] Pagination refactoring Jul 27, 2020
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Jul 27, 2020
dtassone added a commit that referenced this pull request Jul 28, 2020
* Release v0.1.62 (#95)

* v0.1.51

* fix demo app build

* v0.1.52

* v0.1.53

* v0.1.54

* v0.1.55

* v0.1.56

* v0.1.57

* v0.1.58

* v0.1.59

* add missing export

* v0.1.60

* v0.1.61

* hot fix for tsconfig conf

* fix mistypes on the package.json

* fix empty space with prettier

* v0.1.62

* fix lerna.json whitespace

* fix resize issue (#96)

* Bump eslint-config-airbnb-typescript from 8.0.2 to 9.0.0 (#112)

* Pagination refactoring (#100)

* implemented server pagination

* rename pagination options, doc, prettier

* fix lint

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* change casing value in featureMode and remove apiref check

* added missing dep in useEffect

* fix broken suggestion code

* fix doc comments

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* Fix FeatureMode enum and remove useCallback in demo

* fix import order

* added namespace to function call to remove import

* remove useCallback and add react. to mdx code

* add concurrency in server pagination demo

* fix feature mode export

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* [core] Use the classnames helper (#105)

* [core] Batch small changes (#104)

* [docs] Improve the JSDoc (#106)

* rename events and add onHover event (#103)

* rename events and added onHover event

* rename events and added onHover event

* fix onPageChange rename and merge

* Js doc improvements

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* added hover stories

* small fix and cleanup

* revert rename, back to onRowSelected

* refactor hover and click handlers

* refactor cellParams

* prettier

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* v0.1.63

* v0.1.64

* prettier lerna.json due to lerna

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
dtassone added a commit that referenced this pull request Jul 28, 2020
* Release v0.1.62 (#95)

* v0.1.51

* fix demo app build

* v0.1.52

* v0.1.53

* v0.1.54

* v0.1.55

* v0.1.56

* v0.1.57

* v0.1.58

* v0.1.59

* add missing export

* v0.1.60

* v0.1.61

* hot fix for tsconfig conf

* fix mistypes on the package.json

* fix empty space with prettier

* v0.1.62

* fix lerna.json whitespace

* fix resize issue (#96)

* Bump eslint-config-airbnb-typescript from 8.0.2 to 9.0.0 (#112)

* Pagination refactoring (#100)

* implemented server pagination

* rename pagination options, doc, prettier

* fix lint

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* change casing value in featureMode and remove apiref check

* added missing dep in useEffect

* fix broken suggestion code

* fix doc comments

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* Fix FeatureMode enum and remove useCallback in demo

* fix import order

* added namespace to function call to remove import

* remove useCallback and add react. to mdx code

* add concurrency in server pagination demo

* fix feature mode export

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* [core] Use the classnames helper (#105)

* [core] Batch small changes (#104)

* [docs] Improve the JSDoc (#106)

* rename events and add onHover event (#103)

* rename events and added onHover event

* rename events and added onHover event

* fix onPageChange rename and merge

* Js doc improvements

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* added hover stories

* small fix and cleanup

* revert rename, back to onRowSelected

* refactor hover and click handlers

* refactor cellParams

* prettier

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* [test] Add yarn deduplicate step (#107)

* [DataGrid] Set default logLevel to warn (#117)

* override default logLevel to warn

* rerun CI

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* [test] Lint JSON (#108)

* Merging release back to master (#120)

* v0.1.51

* fix demo app build

* v0.1.52

* v0.1.53

* v0.1.54

* v0.1.55

* v0.1.56

* v0.1.57

* v0.1.58

* v0.1.59

* add missing export

* v0.1.60

* v0.1.61

* hot fix for tsconfig conf

* fix mistypes on the package.json

* fix empty space with prettier

* v0.1.62

* fix lerna.json whitespace

* v0.1.63

* v0.1.64

* prettier lerna.json due to lerna

* fix cellClassRule type, fix keyboard timeout, small refactoring (#123)

* fix cellClassRule type, fix keyboard timeout, small refactoring

* prettier fix

* add cancel RAF for focus if new event coming

* added keyboard doc (#125)

* added keyboard doc

* Apply suggestions from code review

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>

* [DataGrid] Fix selection issue (#126)

* fix selection issue

* fix selection issue test

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
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!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants