Skip to content

Commit 7995404

Browse files
committed
Conversion progress
1 parent ad347f5 commit 7995404

File tree

4 files changed

+60
-46
lines changed

4 files changed

+60
-46
lines changed

app/javascript/components/automate-method-form/automateModal.jsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { Modal } from 'carbon-components-react';
33
import MiqFormRenderer from '@@ddf';
44

5-
const AutomateModal = ({ isOpen, onClose, modalLabel, schema }) => {
5+
const AutomateModal = ({ isOpen, onClose, modalLabel, schema, callBack }) => {
6+
7+
const [data, setData] = useState();
8+
9+
const onSubmit = (values) => {
10+
const formData = {
11+
type:values.type,
12+
selectInput: values.selectInput,
13+
defaultValue: values.defaultValue,
14+
}
15+
console.log("data=",formData)
16+
callBack(formData);
17+
onClose();
18+
}
619

720
return (
821
<Modal open={isOpen} onRequestClose={onClose} modalLabel={modalLabel} passiveModal>
9-
<MiqFormRenderer schema={schema} />
22+
<MiqFormRenderer schema={schema}
23+
onSubmit={onSubmit} />
1024
</Modal>
1125
);
1226
};

app/javascript/components/automate-method-form/index.jsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import InputParams from './method-input-parameters';
66
import AutomateModal from './automateModal';
77
import { inputParameterSchema } from './method-input-parameters/helper';
88
import ReactCodeMirror from './codeMirror';
9+
import mapper from '../../forms/mappers/componentMapper';
10+
import enhancedSelect from '../../helpers/enhanced-select';
911

1012
const MainInfo = ({ options, selectedOption, handleSelect, ansibleSchema }) => (
1113
<div className="mainClass">
@@ -24,6 +26,7 @@ const MainInfo = ({ options, selectedOption, handleSelect, ansibleSchema }) => (
2426
const AutomateMethodForm = (props) => {
2527
const [selectedOption, setSelectedOption] = useState(null);
2628
const [isModalOpen, setIsModalOpen] = useState(undefined);
29+
const [inputParamsFormData, setInputParamsFormData] = useState(null);
2730

2831
const handleSelect = (selectedItem) => {
2932
setSelectedOption(selectedItem);
@@ -42,11 +45,19 @@ const AutomateMethodForm = (props) => {
4245
let modalSchema;
4346
modalSchema = isModalOpen === 'inputParameter' ? inputParameterSchema : undefined;
4447

48+
const componentMapper = {
49+
...mapper,
50+
'enhanced-select': enhancedSelect,
51+
};
52+
4553
return (
4654
<>
4755
<MainInfo options={options} selectedOption={selectedOption} handleSelect={handleSelect} ansibleSchema={ansibleSchema} />
4856
{selectedOption && shouldRenderForm(selectedOption) && (
49-
<MiqFormRenderer schema={{ fields: ansibleSchema.fields }} />
57+
<MiqFormRenderer
58+
schema={{ fields: ansibleSchema.fields }}
59+
componentMapper={componentMapper}
60+
/>
5061
)}
5162
{selectedOption && shouldRenderForm(selectedOption) && (
5263
<>
@@ -71,14 +82,19 @@ const AutomateMethodForm = (props) => {
7182
</>
7283
)}
7384
<br/>
74-
<InputParams />
85+
<InputParams formData={inputParamsFormData}/>
7586
</>
7687
)}
7788
<AutomateModal
7889
isOpen={ isModalOpen && modalSchema }
7990
onClose={closeModal}
8091
modalLabel="Input Parameters"
81-
schema={ modalSchema }/>
92+
schema={ modalSchema }
93+
callBack={(formData) => {
94+
console.log(formData);
95+
setInputParamsFormData(formData);
96+
}}
97+
/>
8298
</>
8399
);
84100
};

app/javascript/components/automate-method-form/method-input-parameters/helper.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { componentTypes } from '@@ddf';
22

3+
const options = [
4+
{ id: 'option1', name: 'Option 1', label: 'Option 1'},
5+
{ id: 'option2', name: 'Option 2', label: 'Option 2' },
6+
{ id: 'option3', name: 'Option 3', label: 'Option 3' },
7+
]
38
export const inputParameterSchema = {
49
fields: [
510
{
@@ -13,16 +18,12 @@ export const inputParameterSchema = {
1318
id: 'selectInput',
1419
name: 'selectInput',
1520
label: __('Choose'),
16-
options: [
17-
{ id: 'option1', text: 'Option 1' },
18-
{ id: 'option2', text: 'Option 2' },
19-
{ id: 'option3', text: 'Option 3' },
20-
],
21+
options: options,
2122
},
2223
{
2324
component: componentTypes.TEXT_FIELD,
24-
id: 'DefaultValue',
25-
name: 'DefaultValue',
25+
id: 'defaultValue',
26+
name: 'defaultValue',
2627
label: __('Default Value'),
2728
},
2829
],

app/javascript/components/automate-method-form/method-input-parameters/index.js

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,28 @@
11
import React from 'react';
2-
import { DataTable } from 'carbon-components-react';
2+
import MiqDataTable from '../../miq-data-table';
33

4-
const InputParams = () => {
5-
const data = [
6-
{ id: '1', inputName: 'username', dataType: 'string', defaultValue: 'guest', actions: 'Edit, Delete' },
7-
{ id: '2', inputName: 'password', dataType: 'password', defaultValue: '********', actions: 'Edit, Delete' },
8-
];
4+
const InputParams = (props) => {
5+
const { formData: { defaultValue, type } } = props;
96

10-
const headers = [
7+
const row = {
8+
inputName: 'Input Name',
9+
dataType: type,
10+
defaultValue: defaultValue,
11+
};
12+
13+
const headers = inputParams.length > 0 ? [
1114
{ key: 'inputName', header: 'Input Name' },
1215
{ key: 'dataType', header: 'Data Type' },
1316
{ key: 'defaultValue', header: 'Default Value' },
14-
{ key: 'actions', header: 'Actions' },
15-
];
17+
] : [];
1618

1719
return (
18-
<DataTable
19-
rows={data}
20+
<MiqDataTable
2021
headers={headers}
21-
render={({ rows, headers, getHeaderProps, getRowProps, getTableProps }) => (
22-
<table {...getTableProps()} className="bx--data-table">
23-
<thead>
24-
<tr>
25-
{headers.map((header) => (
26-
<th key={header.key} {...getHeaderProps({ header })}>
27-
{header.header}
28-
</th>
29-
))}
30-
</tr>
31-
</thead>
32-
<tbody>
33-
{rows.map((row) => (
34-
<tr key={row.id} {...getRowProps({ row })}>
35-
{headers.map((header) => (
36-
<td key={header.key}>{row[header.key]}</td>
37-
))}
38-
</tr>
39-
))}
40-
</tbody>
41-
</table>
42-
)}
22+
rows={[row]}
23+
onCellClick={(selectedRow) => onSelect(selectedRow)}
24+
mode="button-group-list"
25+
isSortable={false}
4326
/>
4427
);
4528
};

0 commit comments

Comments
 (0)