//@flow import React from "react"; import { AddButton } from "@scm-manager/ui-components"; import Autocomplete from "../../containers/Autocomplete"; import type { AutocompleteObject } from "../../containers/Autocomplete"; type Props = { addEntry: string => void, disabled: boolean, buttonLabel: string, fieldLabel: string, helpText?: string, loadSuggestions: string => Promise }; type State = { entryToAdd?: AutocompleteObject }; class AutocompleteAddEntryToTableField extends React.Component { constructor(props: Props) { super(props); this.state = { entryToAdd: undefined }; } render() { const { disabled, buttonLabel, fieldLabel, helpText } = this.props; const { entryToAdd } = this.state; return (
); } addButtonClicked = (event: Event) => { event.preventDefault(); this.appendEntry(); }; appendEntry = () => { const { entryToAdd } = this.state; if (!entryToAdd) { return; } this.setState({ ...this.state, entryToAdd: undefined }, () => this.props.addEntry(entryToAdd.id) ); }; handleAddEntryChange = (selection: AutocompleteObject) => { this.setState({ ...this.state, entryToAdd: selection }); }; } export default AutocompleteAddEntryToTableField;