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

[AutoComplete] Add key(text) support for dataSource and more general item componenta support #3662

Merged
merged 1 commit into from
Mar 16, 2016

Conversation

yongxu
Copy link
Contributor

@yongxu yongxu commented Mar 11, 2016

Rewrite some code to replace my initial PR, improved readability.
Broader item value support.
Clearer code.
Support for case #3137

@mbrookes
Copy link
Member

Hi @yongxu - thanks for doing this.

Before we review the rewrite of the other PR - what is the purpose of the sort prop? If the data is sorted are the results not also? The example doesn't work as an autocomplete - it shows all results no matter what is typed, and in any case I think this functionality should be in a separate PR.I would have also suggested an issue to discuss the use case before you did the work. 😄

@nathanmarks
Copy link
Member

@mbrookes I think we should move away from baking in application logic into the core autocomplete component. As a user I want access to a controlled component that isn't held back in any way by a maze of internal logic. Any helpers for searching/sorting data should be plugged in exactly the same way that you would plug in your own logic, imo.

@@ -178,6 +178,10 @@ const AutoComplete = React.createClass({
searchText: React.PropTypes.string,

/**
* Compare callback used to sort the items.
*/
sort: React.PropTypes.func,
Copy link
Member

Choose a reason for hiding this comment

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

Please add the signature for this too 😅

Copy link
Member

Choose a reason for hiding this comment

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

Lets figure out if this is a useful feature first. 😄

Copy link
Member

Choose a reason for hiding this comment

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

Yeah was thinking the same actually. 😅

@mbrookes mbrookes assigned mbrookes and unassigned mbrookes Mar 11, 2016
@oliviertassinari
Copy link
Member

I think we should move away from baking in complex logic into the core autocomplete component.

I completly agree.

@yongxu
Copy link
Contributor Author

yongxu commented Mar 11, 2016

@mbrookes @nathanmarks @alitaheri @oliviertassinari ,
Thanks for the feedback, here are the reason why I introduced sort:
It was not possible to sort the results after the filtered result. Doing sorting after applying filter can be much faster than sorting first, which is quite a waste.
I also remembered there were people asking for this feature, can't remember the details exactly, but this can be quite useful.
@mbrookes,

The example doesn't work as an autocomplete - it shows all results no matter what is typed

The result was sorted, but not filtered. I made a mistake for not noticing the fruit list was already sorted.

@oliviertassinari
Copy link
Member

Doing sorting after applying filter can be much faster than sorting first, which is quite a waste.

We can't disagree here. But that's not what is at stake.
Our concern is that the data handling logic can't scale to all the needs people might have. We feel like it's only adding more complexity without real benefit. I still strongly believe that we should aim to remove the data handling logic from the core of the AutoComplete.

Wouldn't it be better if we had a controlled AutoComplete component and a helper to apply some simple data logic? (sort, filter, map)
Then, if people have custom needs, they can still use the core component without the overhead.

@nathanmarks
Copy link
Member

@oliviertassinari

I agree:

I think we should move away from baking in application logic into the core autocomplete component. As a user I want access to a controlled component that isn't held back in any way by a maze of internal logic. Any helpers for searching/sorting data should be plugged in exactly the same way that you would plug in your own logic, imo.

@mbrookes mbrookes added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI Enhancement labels Mar 12, 2016
@oliviertassinari oliviertassinari self-assigned this Mar 12, 2016
@yongxu
Copy link
Contributor Author

yongxu commented Mar 12, 2016

Wouldn't it be better if we had a controlled AutoComplete component and a helper to apply some simple data logic? (sort, filter, map)

This enhancement is exactly intended for this kind of logic. As far as I know, there isn't anyway to manipulate the data or change the order(sorting) after the filter process.

Currently, we have to presort all the data before send it to dataSource if we want sorted result. Although I am not sure if this solution is the best, but there should be at least one way to do it.
@oliviertassinari @nathanmarks @mbrookes

@oliviertassinari
Copy link
Member

As far as I know, there isn't anyway to manipulate the data or change the order(sorting) after the filter process.

Yes you can, this is how I'm using the component, I can't rely on the internal logic.
You just need to update the dataSource when a onUpdateInput or a onNewRequest event trigger.

@nathanmarks
Copy link
Member

@yongxu As Olivier said, the direction we're moving towards would mean helpers such as this belong in optional utilities to plug into a less opinionated autocomplete. Right now, adding more built-in state logic does not help us move towards that goal.

I'd recommend filtering the data yourself and pass it to the component as @oliviertassinari outlined in the last post.

@nathanmarks nathanmarks added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 13, 2016
@nathanmarks
Copy link
Member

@oliviertassinari FYI, I think @yongxu is feeling rather confused as he had the same changes accepted 9 days ago by @mbrookes in #3182

I'm sorry for any misunderstanding @yongxu -- this likely would have been raised in the 2nd review before the PR was merged.

@yongxu
Copy link
Contributor Author

yongxu commented Mar 13, 2016

@oliviertassinari @mbrookes
I removed sort, which isn't the main purpose of this PR. Let's get this merged so we can move forward.

@nathanmarks I wasn't confused, but uuuumm...

Thanks for all the thought BTW 👍

<AutoComplete
floatingLabelText="Same text, different values"
filter={AutoComplete.noFilter}
triggerUpdateOnFocus={true}
Copy link
Member

Choose a reason for hiding this comment

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

I have deprecated this property. Can you use openOnFocus instead?

text: item.text,
value: (
<MenuItem
innerDivStyle={{overflow: 'hidden'}}
Copy link
Member

Choose a reason for hiding this comment

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

innerDivStyle={styles.innerDiv}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated :)

@oliviertassinari oliviertassinari added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Mar 13, 2016
@nathanmarks
Copy link
Member

@yongxu Can you edit the title and the description to reflect what the PR does now? 👍

And the commit message can match the title

@nathanmarks nathanmarks added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Mar 13, 2016
@oliviertassinari
Copy link
Member

@yongxu Thanks 👍.

@yongxu
Copy link
Contributor Author

yongxu commented Mar 16, 2016

Thanks @oliviertassinari , I will make sure to get it right next time 👍

@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete 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.

6 participants