From 2f4f1dbe0200e18153ba5196abfb42c8c6a19859 Mon Sep 17 00:00:00 2001 From: Mohamed Karray Date: Wed, 27 Mar 2019 10:12:05 +0100 Subject: [PATCH 01/12] add prop to the autocomplete component to indicate if an automatic create action is required --- .../ui-components/src/Autocomplete.js | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/scm-ui-components/packages/ui-components/src/Autocomplete.js b/scm-ui-components/packages/ui-components/src/Autocomplete.js index f3023e268b..adf86e37b7 100644 --- a/scm-ui-components/packages/ui-components/src/Autocomplete.js +++ b/scm-ui-components/packages/ui-components/src/Autocomplete.js @@ -1,6 +1,6 @@ // @flow import React from "react"; -import { AsyncCreatable } from "react-select"; +import { AsyncCreatable, Async } from "react-select"; import type { AutocompleteObject, SelectValue } from "@scm-manager/ui-types"; import LabelWithHelpIcon from "./forms/LabelWithHelpIcon"; @@ -13,7 +13,8 @@ type Props = { value?: SelectValue, placeholder: string, loadingMessage: string, - noOptionsMessage: string + noOptionsMessage: string, + creatable?: boolean }; @@ -42,27 +43,40 @@ class Autocomplete extends React.Component { }; render() { - const { label, helpText, value, placeholder, loadingMessage, noOptionsMessage, loadSuggestions } = this.props; + const { label, helpText, value, placeholder, loadingMessage, noOptionsMessage, loadSuggestions, creatable } = this.props; return (
- loadingMessage} - noOptionsMessage={() => noOptionsMessage} - isValidNewOption={this.isValidNewOption} - onCreateOption={value => { - this.handleInputChange({ - label: value, - value: { id: value, displayName: value } - }); - }} - /> + {creatable? + loadingMessage} + noOptionsMessage={() => noOptionsMessage} + isValidNewOption={this.isValidNewOption} + onCreateOption={value => { + this.handleInputChange({ + label: value, + value: { id: value, displayName: value } + }); + }} + /> + : + loadingMessage} + noOptionsMessage={() => noOptionsMessage} + /> + + }
); From 98f98d123dc8427f87c1fb36da17f7bfef13a4f1 Mon Sep 17 00:00:00 2001 From: Mohamed Karray Date: Thu, 28 Mar 2019 10:13:56 +0100 Subject: [PATCH 02/12] add optionValues to the DropDow component --- .../packages/ui-components/src/forms/DropDown.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scm-ui-components/packages/ui-components/src/forms/DropDown.js b/scm-ui-components/packages/ui-components/src/forms/DropDown.js index 62a7f1ebe1..457039a0a8 100644 --- a/scm-ui-components/packages/ui-components/src/forms/DropDown.js +++ b/scm-ui-components/packages/ui-components/src/forms/DropDown.js @@ -5,6 +5,7 @@ import classNames from "classnames"; type Props = { options: string[], + optionValues?: string[], optionSelected: string => void, preselectedOption?: string, className: any, @@ -13,7 +14,7 @@ type Props = { class DropDown extends React.Component { render() { - const { options, preselectedOption, className, disabled } = this.props; + const { options, optionValues, preselectedOption, className, disabled } = this.props; return (