onSelect(selectedRow)}
mode="button-group-list"
/>
diff --git a/app/javascript/components/automate-method-form/index.jsx b/app/javascript/components/automate-method-form/index.jsx
index 53437496d5e..e874aa4ee3d 100644
--- a/app/javascript/components/automate-method-form/index.jsx
+++ b/app/javascript/components/automate-method-form/index.jsx
@@ -3,6 +3,7 @@ import { Dropdown } from 'carbon-components-react';
import PropTypes from 'prop-types';
import MiqFormRenderer from '@@ddf';
import { createSchema } from './schema';
+import { InputParameterRecordActions } from './automate-method-input-parameter/helper';
import componentMapper from '../../forms/mappers/componentMapper';
import AutomateMethodInputParameter from './automate-method-input-parameter';
import AutomateMethodCodeMirror from './automate-method-code-mirror';
@@ -10,7 +11,10 @@ import AutomateMethodInputParameterForm from './automate-method-input-parameter/
import AutomateMethodContext from './automate-method-context';
const AutomateMethodForm = ({ availableLocations }) => {
+ const options = availableLocations.map((item) => ({ id: item[1], label: item[0] }));
+
const [formData, setFormData] = useState({
+ selectedType: undefined,
inputParameter: {
modal: false,
selectedId: undefined,
@@ -18,33 +22,34 @@ const AutomateMethodForm = ({ availableLocations }) => {
},
});
- // add = modal,
- // edit = modal, id
- // delete = id
-
- console.log('formData=', formData);
-
const updateInputParameter = (actionType, data) => {
+ const { inputParameter } = formData;
switch (actionType) {
- case 'add':
- console.log('add');
+ case InputParameterRecordActions.OPEN:
+ inputParameter.modal = true;
+ if (data && data.selectedId) {
+ inputParameter.selectedId = data.selectedId;
+ }
+ break;
+ case InputParameterRecordActions.ADD:
+ inputParameter.items.push(data.values);
+ inputParameter.modal = false;
break;
- case 'edit':
- console.log('edit');
+ case InputParameterRecordActions.UPDATE:
+ inputParameter.items[inputParameter.selectedId] = data.values;
+ inputParameter.modal = false;
+ inputParameter.selectedId = undefined;
break;
- case 'delete':
- console.log('delete');
+
+ case InputParameterRecordActions.DELETE:
+ inputParameter.items.splice(data.selectedId, 1);
break;
default:
- console.log('unknown');
+ console.warn('unknown');
}
setFormData({
...formData,
- inputParameter: {
- ...formData.inputParameter,
- modal: data.status,
- selectedId: data.selectedId,
- },
+ inputParameter: { ...formData.inputParameter },
});
};
@@ -54,12 +59,6 @@ const AutomateMethodForm = ({ availableLocations }) => {
'automate-method-input-parameter': AutomateMethodInputParameter,
};
- console.log('Initial props', availableLocations);
- const [selectedOption, setSelectedOption] = useState(null);
-
- const options = availableLocations.map((item) => ({ id: item[1], label: item[0] }));
- console.log('options=', options);
-
const chooseAutomateType = () => (
{__('Main Info')}
@@ -68,15 +67,18 @@ const AutomateMethodForm = ({ availableLocations }) => {
label="Choose"
items={options}
itemToString={(item) => (item ? item.label : '')}
- onChange={({ selectedItem }) => setSelectedOption(selectedItem)}
- titleText={selectedOption ? selectedOption.label : ''}
+ onChange={({ selectedType }) => setFormData({
+ ...formData,
+ selectedType,
+ })}
+ titleText={formData.selectedType ? formData.selectedType.label : ''}
/>
);
const renderInputParameterModal = ({ inputParameter }) => (
);
@@ -84,18 +86,17 @@ const AutomateMethodForm = ({ availableLocations }) => {
return (
{chooseAutomateType()}
- {selectedOption && (
+ {formData.selectedType && (
+ {
+ formData.inputParameter.modal && renderInputParameterModal(formData)
+ }
)}
- {
- formData.inputParameter.modal && renderInputParameterModal(formData)
-
- }
);
};