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

Fix for list not updating when filter prop is changed #2926

Closed

Conversation

kara-todd
Copy link

fixes #2923

  • ListController: update to use componentDidUpdate instead of componentWillReceiveProps
  • ListController: Add filter and params to list of props comparison values for shouldComponentUpdate

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Looks good. I'd love some tests though

prevProps.query.perPage !== query.perPage ||
!isEqual(prevProps.query.filter, query.filter) ||
!isEqual(prevProps.query.filter, query.filter) ||
!isEqual(prevProps.params, params) ||
Copy link
Member

Choose a reason for hiding this comment

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

you've added the params key here, it has nothing to do with the bug you mentioned. Please remove.

? nextProps.query
: nextProps.params
);
this.updateData(Object.keys(query).length > 0 && query);
Copy link
Member

Choose a reason for hiding this comment

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

no, you've changed the logic here. Please revert.

Copy link
Author

Choose a reason for hiding this comment

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

@fzaninotto this was due to the second bug I mentioned. If you apply the dynamic filter with no query params for example /#/users the params with defaults of null are called on the update data queries. This throws the "Cannot read property 'toLowerCase' of null" error.

Since the params data is merged with the defaults in the this.getQuery() I thought that just not passing the params in this case would still work and properly merge the defaults, but perhaps I misunderstood the logic here?

Copy link
Member

Choose a reason for hiding this comment

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

with the previous logic, if there is no query string in the URL, we use the params from the Redux store, which are always defined.

I don't know about the Cannot read property 'toLowerCase' of null" error, I suggest we deal with it in another PR, and you provide a failing test case to demonstrate it.

@@ -222,6 +231,12 @@ export class UnconnectedListController extends Component<Props> {
nextProps.translate === this.props.translate &&
nextProps.isLoading === this.props.isLoading &&
nextProps.version === this.props.version &&
nextProps.filter === this.props.filter &&
nextProps.params.sort !== this.props.params.sort &&
Copy link
Member

Choose a reason for hiding this comment

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

Same remark as above, don't add the test for params key as it has nothing to do with the bug you're solving.

Copy link
Author

Choose a reason for hiding this comment

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

@fzaninotto in my testing when I removed the params comparison on shouldComponentUpdate the list failed to immediately update with no query string present. (/#/users)

This caused the sort filter to have to be clicked twice to be applied.

Copy link
Member

Choose a reason for hiding this comment

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

That means you have broken something in your PR that used to work before. Applications built with the current version have no problem displaying a resource list page without query string in the URL.

@kara-todd
Copy link
Author

@djhi @fzaninotto if the logic for the change is accepted I'm happy to add a test for it, but if it needs to be implemented differently I'd appreciate some direction on how you feel I should change it and still resolve the 'toLowerCase' of null error.

? nextProps.query
: nextProps.params
);
this.updateData(Object.keys(query).length > 0 && query);
Copy link
Member

Choose a reason for hiding this comment

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

with the previous logic, if there is no query string in the URL, we use the params from the Redux store, which are always defined.

I don't know about the Cannot read property 'toLowerCase' of null" error, I suggest we deal with it in another PR, and you provide a failing test case to demonstrate it.

@@ -222,6 +231,12 @@ export class UnconnectedListController extends Component<Props> {
nextProps.translate === this.props.translate &&
nextProps.isLoading === this.props.isLoading &&
nextProps.version === this.props.version &&
nextProps.filter === this.props.filter &&
nextProps.params.sort !== this.props.params.sort &&
Copy link
Member

Choose a reason for hiding this comment

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

That means you have broken something in your PR that used to work before. Applications built with the current version have no problem displaying a resource list page without query string in the URL.

@kara-todd
Copy link
Author

@djhi @fzaninotto I've reverted the code as requested. This does expose the Cannot read property 'toLowerCase' of null" error when changing filters, but that can be dealt with separately as requested.

@kopotp
Copy link

kopotp commented Mar 19, 2019

I saw a comment in code that directly points that it will not trigger an update, but this feature is used in almost every page of my current project, so i did the same thing, by ugly ejecting the whole component from ra-core. Please add this to master someday )

@djhi
Copy link
Contributor

djhi commented Oct 8, 2019

Superseded by #3308

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.

List component does not update when filter property is updated
4 participants