@@ -111,12 +40,12 @@ function VariablesField({ i18n, id, name, label, readOnly, promptId }) {
try {
const newVal =
newMode === YAML_MODE
- ? jsonToYaml(value)
- : yamlToJson(value);
- setFieldValue(name, newVal);
+ ? jsonToYaml(field.value)
+ : yamlToJson(field.value);
+ helpers.setValue(newVal);
setMode(newMode);
} catch (err) {
- setFieldError(name, err.message);
+ helpers.setError(err.message);
}
}}
/>
@@ -130,29 +59,20 @@ function VariablesField({ i18n, id, name, label, readOnly, promptId }) {
/>
)}
-
- {({ field, form }) => (
- <>
- {
- form.setFieldValue(name, newVal);
- }}
- hasErrors={!!form.errors[field.name]}
- />
- {form.errors[field.name] ? (
-
- {form.errors[field.name]}
-
- ) : null}
- >
- )}
-
+
{
+ helpers.setValue(newVal);
+ }}
+ hasErrors={!!meta.error}
+ />
+ {meta.error ? (
+
+ {meta.error}
+
+ ) : null}
);
}
@@ -161,10 +81,11 @@ VariablesField.propTypes = {
name: string.isRequired,
label: string.isRequired,
readOnly: bool,
+ promptId: string,
};
VariablesField.defaultProps = {
readOnly: false,
+ promptId: null,
};
export default withI18n()(VariablesField);
-*/
diff --git a/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx b/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx
index 12d660ffef..9a24316c74 100644
--- a/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx
+++ b/awx/ui_next/src/components/Lookup/MultiCredentialsLookup.jsx
@@ -3,210 +3,10 @@ import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
-import { FormGroup, ToolbarItem } from '@patternfly/react-core';
-import { CredentialsAPI, CredentialTypesAPI } from '@api';
-import AnsibleSelect from '@components/AnsibleSelect';
-import { FieldTooltip } from '@components/FormField';
-import CredentialChip from '@components/CredentialChip';
-import { getQSConfig, parseQueryString } from '@util/qs';
-import Lookup from './Lookup';
-import OptionsList from './shared/OptionsList';
-
-const QS_CONFIG = getQSConfig('credentials', {
- page: 1,
- page_size: 5,
- order_by: 'name',
-});
-
-async function loadCredentialTypes() {
- const { data } = await CredentialTypesAPI.read();
- const acceptableTypes = ['machine', 'cloud', 'net', 'ssh', 'vault'];
- return data.results.filter(type => acceptableTypes.includes(type.kind));
-}
-
-async function loadCredentials(params, selectedCredentialTypeId) {
- params.credential_type = selectedCredentialTypeId || 1;
- const { data } = await CredentialsAPI.read(params);
- return data;
-}
-
-function MultiCredentialsLookup(props) {
- const { tooltip, value, onChange, onError, history, i18n } = props;
- const [credentialTypes, setCredentialTypes] = useState([]);
- const [selectedType, setSelectedType] = useState(null);
- const [credentials, setCredentials] = useState([]);
- const [credentialsCount, setCredentialsCount] = useState(0);
-
- useEffect(() => {
- (async () => {
- try {
- const types = await loadCredentialTypes();
- setCredentialTypes(types);
- const match = types.find(type => type.kind === 'ssh') || types[0];
- setSelectedType(match);
- } catch (err) {
- onError(err);
- }
- })();
- }, [onError]);
-
- useEffect(() => {
- (async () => {
- if (!selectedType) {
- return;
- }
- try {
- const params = parseQueryString(QS_CONFIG, history.location.search);
- const { results, count } = await loadCredentials(
- params,
- selectedType.id
- );
- setCredentials(results);
- setCredentialsCount(count);
- } catch (err) {
- onError(err);
- }
- })();
- }, [selectedType, history.location.search, onError]);
-
- const renderChip = ({ item, removeItem, canDelete }) => (
-