(options, value, creatable, formatter)
| 890 | } |
| 891 | |
| 892 | function getRealValue(options, value, creatable, formatter) { |
| 893 | let realValue = null; |
| 894 | if(options?.length == 0 && !creatable) { |
| 895 | return realValue; |
| 896 | } |
| 897 | if (_.isArray(value)) { |
| 898 | realValue = [...value]; |
| 899 | /* If multi select options need to be in some format by UI, use formatter */ |
| 900 | if (formatter) { |
| 901 | realValue = formatter.fromRaw(realValue, options); |
| 902 | } else if (creatable) { |
| 903 | realValue = realValue.map((val) => ({ label: val, value: val })); |
| 904 | } else { |
| 905 | realValue = realValue.map((val) => (_.find(options, (option) => _.isEqual(option.value, val)))); |
| 906 | } |
| 907 | } else { |
| 908 | let flatOptions = flattenSelectOptions(options); |
| 909 | realValue = _.find(flatOptions, (option) => option.value == value) || |
| 910 | (creatable && !_.isUndefined(value) && !_.isNull(value) ? { label: value, value: value } : null); |
| 911 | } |
| 912 | return realValue; |
| 913 | } |
| 914 | export function InputSelectNonSearch({ options, ...props }) { |
| 915 | return <MuiSelect native {...props} variant="outlined"> |
| 916 | {(options || []).map((o) => <option key={o.value} value={o.value}>{o.label}</option>)} |
no test coverage detected