mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
Fixed displaying/resetting of selected value
This commit is contained in:
@@ -21,29 +21,33 @@ type Props = {
|
|||||||
value?: AutocompleteObject
|
value?: AutocompleteObject
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {};
|
||||||
value: AutocompleteObject
|
|
||||||
};
|
|
||||||
|
|
||||||
class Autocomplete extends React.Component<Props, State> {
|
class Autocomplete extends React.Component<Props, State> {
|
||||||
handleInputChange = (newValue: SelectValue) => {
|
handleInputChange = (newValue: SelectValue) => {
|
||||||
this.setState({ value: newValue.value });
|
|
||||||
this.props.valueSelected(newValue.value);
|
this.props.valueSelected(newValue.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { label, helpText, value } = this.props;
|
const { label, helpText, value } = this.props;
|
||||||
const stringValue = value ? value.id : "";
|
let selectValue = null;
|
||||||
|
if (value) {
|
||||||
|
selectValue = {
|
||||||
|
value,
|
||||||
|
label: value.displayName
|
||||||
|
};
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<LabelWithHelpIcon label={label} helpText={helpText} />
|
<LabelWithHelpIcon label={label} helpText={helpText} />
|
||||||
<div className="control">
|
<div className="control">
|
||||||
<AsyncSelect
|
<AsyncSelect
|
||||||
cacheOptions
|
cacheOptions
|
||||||
defaultOptions
|
|
||||||
loadOptions={this.props.loadSuggestions}
|
loadOptions={this.props.loadSuggestions}
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
value={stringValue}
|
value={selectValue}
|
||||||
|
placeholder="Start typing..." // TODO: i18n
|
||||||
|
noOptionsMessage={() => <>No suggestion available</>} // TODO: i18n
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,15 +15,18 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
entryToAdd: AutocompleteObject
|
entryToAdd?: AutocompleteObject
|
||||||
};
|
};
|
||||||
|
|
||||||
class AutocompleteAddEntryToTableField extends React.Component<Props, State> {
|
class AutocompleteAddEntryToTableField extends React.Component<Props, State> {
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { entryToAdd: undefined };
|
||||||
|
}
|
||||||
render() {
|
render() {
|
||||||
const { disabled, buttonLabel, fieldLabel, helpText } = this.props;
|
const { disabled, buttonLabel, fieldLabel, helpText } = this.props;
|
||||||
|
|
||||||
const { entryToAdd } = this.state;
|
const { entryToAdd } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
@@ -50,11 +53,15 @@ class AutocompleteAddEntryToTableField extends React.Component<Props, State> {
|
|||||||
|
|
||||||
appendEntry = () => {
|
appendEntry = () => {
|
||||||
const { entryToAdd } = this.state;
|
const { entryToAdd } = this.state;
|
||||||
this.props.addEntry(entryToAdd.id);
|
if (!entryToAdd) {
|
||||||
this.setState({ ...this.state, entryToAdd: undefined });
|
return;
|
||||||
|
}
|
||||||
|
this.setState({ ...this.state, entryToAdd: undefined }, () =>
|
||||||
|
this.props.addEntry(entryToAdd.id)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleAddEntryChange = (selection: any) => {
|
handleAddEntryChange = (selection: AutocompleteObject) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
entryToAdd: selection
|
entryToAdd: selection
|
||||||
|
|||||||
Reference in New Issue
Block a user