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

Rebuild rows when predefined places change #539

Closed
wants to merge 2 commits into from

Conversation

freeatnet
Copy link

This PR adds componentDidUpdate handler that will update the data source when the list of predefinedPlaces changes.

@tmeiss
Copy link

tmeiss commented May 6, 2020

Fixes #495

@tmeiss
Copy link

tmeiss commented May 7, 2020

@guilhermepontes this seems like a pretty common issue. Any chance we can merge in the near term?

@bell-steven bell-steven self-assigned this May 8, 2020
@bell-steven bell-steven linked an issue May 17, 2020 that may be closed by this pull request
@bell-steven
Copy link
Collaborator

Curious to know the use case behind this. Would you mind giving me some background on this?

@@ -348,7 +354,7 @@ export default class GooglePlacesAutocomplete extends Component {
}

_getPredefinedPlace = (rowData) => {
if (rowData.isPredefinedPlace !== true) {
if (rowData.isPredefinedPlace !== true || rowData.description == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about this a bit. I think we might be better off filtering out the predefined places where the description is null or length === 0. If the description is blank, there is still a space (that was pressable) in the list.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add res = [ ...this.props.predefinedPlaces.filter( (place) => place.description && place.description.length, ), ];
in line 101, or something similar. It doesn't look like I can edit this PR, so let me know what you think about this and let's get this merged in.

@bell-steven
Copy link
Collaborator

@freeatnet can you address the comments above? Would like to get this merged.

@freeatnet
Copy link
Author

@bell-steven I'm not sure I understand the logic of the changes you suggested. The patch I provided is a solution to the specific issue I was facing; if I were to implement this from scratch, I'd probably try to get rid of the description-matching logic of _getPredefinedPlace altogether.

@bell-steven
Copy link
Collaborator

@freeatnet the logic behind my change was to solve the problem you were facing, while making the behavior of the library consistent.

However, this method may return the wrong predefined place if multiple predefined places have no description

You mentioned that this was the specific issue your were solving with that line of code. When I tested it, I found that there would still be a blank row rendered in the list if the description was not set (and if there are a few blank rows, because they have a separating line between them, things get a little wonky).
I suggested a change, because I thought that it would solve both of those problems in one swoop.

Even if I were to remove the matching logic in _getPredefinedPlace, I think the issue of the blank rows would still remain.

I will note, there are plenty of parts of this library which can be simplified or stripped out. But, because there are so many little features, changes can have some nasty side effects. The goal is, over time, to try and simplify things here, but it doesn't happen overnight. See #552 for more.

@bell-steven
Copy link
Collaborator

Thanks for the PR!

Closed with 31f98b4

@bell-steven bell-steven closed this Jul 9, 2020
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.

Update predefinedPlaces
3 participants