import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { FormGroup, TextInput, TextArea } from '@patternfly/react-core';
import PropTypes from 'prop-types';
import SearchBar from 'foremanReact/components/SearchBar';
import { helpLabel } from './FormHelpers';
import { SelectField } from './SelectField';
const TemplateSearchField = ({
name,
controller,
labelText,
required,
defaultValue,
setValue,
values,
}) => {
const searchQuery = useSelector(
state => state.autocomplete?.[name]?.searchQuery
);
useEffect(() => {
setValue({ ...values, [name]: searchQuery });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [searchQuery]);
const id = name.replace(/ /g, '-');
return (
null}
/>
);
};
export const formatter = (input, values, setValue) => {
const isSelectType = !!input?.options;
const inputType = input.value_type;
const isTextType = inputType === 'plain' || !inputType; // null defaults to plain
const { name, required, hidden_value: hidden } = input;
const labelText = input.description;
const value = values[name];
const id = name.replace(/ /g, '-');
if (isSelectType) {
const options = input.options.split(/\r?\n/).map(option => option.trim());
return (
setValue({ ...values, [name]: newValue })}
/>
);
}
if (isTextType) {
return (
);
}
if (inputType === 'date') {
return (
setValue({ ...values, [name]: newValue })}
/>
);
}
if (inputType === 'search') {
const controller = input.resource_type;
// TODO: get text from redux autocomplete
return (
);
}
return null;
};
TemplateSearchField.propTypes = {
name: PropTypes.string.isRequired,
controller: PropTypes.string.isRequired,
labelText: PropTypes.string,
required: PropTypes.bool.isRequired,
defaultValue: PropTypes.string,
setValue: PropTypes.func.isRequired,
values: PropTypes.object.isRequired,
};
TemplateSearchField.defaultProps = {
labelText: null,
defaultValue: '',
};