Skip to content

Fix basePicker createGenericItem handling.#3519

Merged
joschect merged 15 commits into
microsoft:masterfrom
ohritz:fixPickerCreateGenericItem
Jan 22, 2018
Merged

Fix basePicker createGenericItem handling.#3519
joschect merged 15 commits into
microsoft:masterfrom
ohritz:fixPickerCreateGenericItem

Conversation

@ohritz

@ohritz ohritz commented Dec 5, 2017

Copy link
Copy Markdown
Contributor

Pull request checklist

Description of changes

Added logic in the SuggestionsController.convertSuggestionsToSuggestionItems() to handle being called with either ISuggestionModel<T> or T

It addresses an issue where when using a pickers createGenericItem, items are not resolved correctly.

@ohritz

ohritz commented Dec 5, 2017

Copy link
Copy Markdown
Contributor Author

Please wait with merging..
had forgot to run the tests..
Will be pushing again once I've resolved some errors,
and fixed formatting errors, that obfuscate the actual changes.

@ohritz

ohritz commented Dec 5, 2017

Copy link
Copy Markdown
Contributor Author

the tests are passing now.
and I've tried to minimize the changes in formatting, let me know if I should do more..
Seems like It formats differently on save compared to format document in vs.code.

@ohritz ohritz changed the title Fix picker create generic item Fix basePicker createGenericItem handling. Dec 7, 2017

@joschect joschect left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've got just a few suggestions but other

this.suggestions = [];
this.currentIndex = -1;
this._ensureSuggestionModel = this._ensureSuggestionModel.bind(this);
this._isSuggestionModel = this._isSuggestionModel.bind(this);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use @autoBind instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

and done! :)

private _onValidateInput() {
if (this.props.onValidateInput && (this.props.onValidateInput as any)(this.input.value) !== ValidationState.invalid && this.props.createGenericItem) {
let itemToConvert = (this.props.createGenericItem as any)(this.input.value, (this.props.onValidateInput as any)(this.input.value));
let itemToConvert = (this.props.createGenericItem as (input: string, ValidationState: ValidationState) => ISuggestionModel<T>)(this.input.value, (this.props.onValidateInput as any)(this.input.value));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You don't need the as here anymore since it's not any.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done !

@joschect joschect left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last suggestion, otherwise looks good.

private _onValidateInput() {
if (this.props.onValidateInput && (this.props.onValidateInput as any)(this.input.value) !== ValidationState.invalid && this.props.createGenericItem) {
let itemToConvert = (this.props.createGenericItem as any)(this.input.value, (this.props.onValidateInput as any)(this.input.value));
let itemToConvert = this.props.createGenericItem(this.input.value, (this.props.onValidateInput)(this.input.value));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't need these extra parens around this.props.onValidateInput

@joschect joschect merged commit e49507c into microsoft:master Jan 22, 2018
@ohritz ohritz deleted the fixPickerCreateGenericItem branch January 23, 2018 07:35
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BasePicker createGenericItem creates nested structure

3 participants