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

Experience domain field in task creation as select component #3233

Merged
merged 13 commits into from
Sep 19, 2018

Conversation

MichaelBuessemeyer
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer commented Sep 17, 2018

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • the "change user experience"-modal should work as before

  • includes a bug fix, that disables entering domains with less than 3 letters in the modal

  • open the task creation

  • without selecting a exp domain and submitting the form should show an typical FieldDecorator error

  • selecting on should work and remove the waring from the FieldDecorator

  • create a task

  • check in the tasks view whether the exp domain is correct

Issues:


Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Nice 👍 Looks good and greatly increase the usability in my opinion. Please see my few comments for how to trim the code a bit :)

})(
<SelectExperienceDomain
disabled={isEditingMode}
mode="default"
Copy link
Member

Choose a reason for hiding this comment

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

Can you omit this line? If mode is undefined, antd should default automatically to "default", right?

<SelectExperienceDomain
disabled={isEditingMode}
mode="default"
placeholder="Select a Experience Domain"
Copy link
Member

Choose a reason for hiding this comment

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

an instead of a

placeholder="Select a Experience Domain"
notFoundContent={messages["task.domain_does_not_exist"]}
width={100}
alreadyUsedDomains={[]}
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be the default value so it doesn't need to be passed?

alreadyUsedDomains={[]}
onSelect={null}
onChange={null}
value={null}
Copy link
Member

Choose a reason for hiding this comment

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

These three lines shouldn't be necessary ideally. Can you omit them? If flow complains, you probably need to add a default value via static defaultProps = { ... } (see here: https://reactjs.org/docs/typechecking-with-proptypes.html#default-prop-values).

@@ -203,6 +204,10 @@ class ExperienceModalView extends React.PureComponent<Props, State> {
};

addEnteredExperience = (domain: string) => {
if (domain.length < 3) {
Toast.warning("A experience domain needs at least 3 letters.");
Copy link
Member

Choose a reason for hiding this comment

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

An experience...

value={[]}
width={50}
onSelect={this.addEnteredExperience}
onDeselect={() => {}}
onChange={null}
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this?

@@ -35,18 +41,28 @@ class SelectExperienceDomain extends React.PureComponent<Props, State> {
}

render() {
const options = this.getUnusedDomains().map(domain => <Option key={domain}>{domain}</Option>);
const notFoundContent = this.props.notFoundContent || "Not Found";
Copy link
Member

Choose a reason for hiding this comment

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

I think this variable is not necessary. If it's undefined, antd will default to "Not found" automatically.

@@ -35,18 +41,28 @@ class SelectExperienceDomain extends React.PureComponent<Props, State> {
}

render() {
const options = this.getUnusedDomains().map(domain => <Option key={domain}>{domain}</Option>);
const notFoundContent = this.props.notFoundContent || "Not Found";
const additionalProps = {};
Copy link
Member

@philippotto philippotto Sep 17, 2018

Choose a reason for hiding this comment

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

Since additionalProps is only used for one component (in contrast to an earlier state, where you used it for two different branches with JSX), it doesn't add much value. You can directly inline it into the JSX below like that:

<Select
  ...
  onChange: this.props.onChange

It doesn't matter whether this.props.onChange is undefined or not (so no need for the if-switches).

onSelect: () => {},
value: null,
notFoundContent: null,
disabled: false,
Copy link
Member

Choose a reason for hiding this comment

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

Sorry to bug you again about that, but I think that alreadyUsedDomains is the only prop which needs to get a default here. All other props should be defined as nullable in the props type (e.g., mode?: string) which is why they don't need a default value. Does that work?

@MichaelBuessemeyer
Copy link
Contributor Author

@philippotto Ok I applied your requested changes and they make sense to me :)

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Excellent! Looks and works well 👍

@philippotto
Copy link
Member

Don't forget to update the changelog, though ;)

@MichaelBuessemeyer MichaelBuessemeyer merged commit ab60bce into master Sep 19, 2018
@normanrz normanrz deleted the experience-field-as-select branch February 20, 2019 16:36
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.

Make experience field in task creation an antd select component
2 participants