-
Notifications
You must be signed in to change notification settings - Fork 24
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
Allow experience domains creation in task creation #4119
Changes from 1 commit
b4d5d1c
cc4e969
0abb4e0
3dc897b
f440378
fd0954c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import * as React from "react"; | |
import type { ExperienceDomainList } from "admin/api_flow_types"; | ||
import { getExistingExperienceDomains } from "admin/admin_rest_api"; | ||
|
||
const Option = Select.Option; | ||
const { Option } = Select; | ||
|
||
type Props = { | ||
value?: string | Array<string>, | ||
|
@@ -17,20 +17,24 @@ type Props = { | |
mode?: string, | ||
onSelect?: string => void, | ||
onChange?: () => void, | ||
allowCreation: boolean, | ||
alreadyUsedDomains: ExperienceDomainList, | ||
}; | ||
|
||
type State = { | ||
domains: ExperienceDomainList, | ||
currentlyEnteredDomain: string, | ||
}; | ||
|
||
class SelectExperienceDomain extends React.PureComponent<Props, State> { | ||
static defaultProps = { | ||
alreadyUsedDomains: [], | ||
allowCreation: false, | ||
}; | ||
|
||
state = { | ||
domains: [], | ||
currentlyEnteredDomain: "", | ||
}; | ||
|
||
componentDidMount() { | ||
|
@@ -45,21 +49,47 @@ class SelectExperienceDomain extends React.PureComponent<Props, State> { | |
return this.state.domains.filter(domain => !this.props.alreadyUsedDomains.includes(domain)); | ||
} | ||
|
||
onSearch = (domain: string) => { | ||
this.setState({ currentlyEnteredDomain: domain }); | ||
}; | ||
|
||
render() { | ||
const { | ||
mode, | ||
value, | ||
notFoundContent, | ||
width, | ||
disabled, | ||
placeholder, | ||
onSelect, | ||
onChange, | ||
allowCreation, | ||
} = this.props; | ||
const { currentlyEnteredDomain } = this.state; | ||
const options = this.getUnusedDomains(); | ||
if ( | ||
allowCreation && | ||
!options.includes(currentlyEnteredDomain) && | ||
currentlyEnteredDomain.trim() !== "" | ||
) { | ||
options.push(currentlyEnteredDomain); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit hesitant about the modification of options here. Currently it's not a problem as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for paying attention to this 👍 |
||
} | ||
|
||
return ( | ||
<Select | ||
showSearch | ||
mode={this.props.mode} | ||
value={this.props.value} | ||
mode={mode} | ||
value={value} | ||
optionFilterProp="children" | ||
notFoundContent={this.props.notFoundContent} | ||
style={{ width: `${this.props.width}%` }} | ||
disabled={this.props.disabled} | ||
placeholder={this.props.placeholder} | ||
onSelect={this.props.onSelect} | ||
onChange={this.props.onChange} | ||
notFoundContent={notFoundContent} | ||
style={{ width: `${width}%` }} | ||
disabled={disabled} | ||
placeholder={placeholder} | ||
onSelect={onSelect} | ||
onChange={onChange} | ||
onSearch={this.onSearch} | ||
> | ||
{this.getUnusedDomains().map(domain => ( | ||
{options.map(domain => ( | ||
<Option key={domain}>{domain}</Option> | ||
))} | ||
</Select> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mode property is no longer needed here. It served the purpose to be able to select the entered text/experience domain although it is not included in the suggestions. As I implemented this behaviour manually, this is no longer required. Please note that the approach "changing mode to 'tags' in
task_create_form_view
" does change the behaviour of the select and thus this is not an option for thetask creation view
.