Skip to content

Commit

Permalink
Conversion progress
Browse files Browse the repository at this point in the history
  • Loading branch information
amalvijayan03 committed Jan 29, 2024
1 parent 81e357e commit 2e46f47
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 46 deletions.
20 changes: 17 additions & 3 deletions app/javascript/components/automate-method-form/automateModal.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import React from 'react';
import React, { useState } from 'react';
import { Modal } from 'carbon-components-react';
import MiqFormRenderer from '@@ddf';

const AutomateModal = ({ isOpen, onClose, modalLabel, schema }) => {
const AutomateModal = ({ isOpen, onClose, modalLabel, schema, callBack }) => {

const [data, setData] = useState();

const onSubmit = (values) => {
const formData = {
type:values.type,
selectInput: values.selectInput,
defaultValue: values.defaultValue,
}
console.log("data=",formData)
callBack(formData);
onClose();
}

return (
<Modal open={isOpen} onRequestClose={onClose} modalLabel={modalLabel} passiveModal>
<MiqFormRenderer schema={schema} />
<MiqFormRenderer schema={schema}
onSubmit={onSubmit} />
</Modal>
);
};
Expand Down
22 changes: 19 additions & 3 deletions app/javascript/components/automate-method-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import InputParams from './method-input-parameters';
import AutomateModal from './automateModal';
import { inputParameterSchema } from './method-input-parameters/helper';
import ReactCodeMirror from './codeMirror';
import mapper from '../../forms/mappers/componentMapper';
import enhancedSelect from '../../helpers/enhanced-select';

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

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

const componentMapper = {
...mapper,
'enhanced-select': enhancedSelect,
};

return (
<>
<MainInfo options={options} selectedOption={selectedOption} handleSelect={handleSelect} ansibleSchema={ansibleSchema} />
{selectedOption && shouldRenderForm(selectedOption) && (
<MiqFormRenderer schema={{ fields: ansibleSchema.fields }} />
<MiqFormRenderer
schema={{ fields: ansibleSchema.fields }}
componentMapper={componentMapper}
/>
)}
{selectedOption && shouldRenderForm(selectedOption) && (
<>
Expand All @@ -71,14 +82,19 @@ const AutomateMethodForm = (props) => {
</>
)}
<br/>
<InputParams />
<InputParams formData={inputParamsFormData}/>
</>
)}
<AutomateModal
isOpen={ isModalOpen && modalSchema }
onClose={closeModal}
modalLabel="Input Parameters"
schema={ modalSchema }/>
schema={ modalSchema }
callBack={(formData) => {
console.log(formData);
setInputParamsFormData(formData);
}}
/>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { componentTypes } from '@@ddf';

const options = [
{ id: 'option1', name: 'Option 1', label: 'Option 1'},
{ id: 'option2', name: 'Option 2', label: 'Option 2' },
{ id: 'option3', name: 'Option 3', label: 'Option 3' },
]
export const inputParameterSchema = {
fields: [
{
Expand All @@ -13,16 +18,12 @@ export const inputParameterSchema = {
id: 'selectInput',
name: 'selectInput',
label: __('Choose'),
options: [
{ id: 'option1', text: 'Option 1' },
{ id: 'option2', text: 'Option 2' },
{ id: 'option3', text: 'Option 3' },
],
options: options,
},
{
component: componentTypes.TEXT_FIELD,
id: 'DefaultValue',
name: 'DefaultValue',
id: 'defaultValue',
name: 'defaultValue',
label: __('Default Value'),
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,28 @@
import React from 'react';
import { DataTable } from 'carbon-components-react';
import MiqDataTable from '../../miq-data-table';

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

const headers = [
const row = {
inputName: 'Input Name',
dataType: type,
defaultValue: defaultValue,
};

const headers = inputParams.length > 0 ? [
{ key: 'inputName', header: 'Input Name' },
{ key: 'dataType', header: 'Data Type' },
{ key: 'defaultValue', header: 'Default Value' },
{ key: 'actions', header: 'Actions' },
];
] : [];

return (
<DataTable
rows={data}
<MiqDataTable
headers={headers}
render={({ rows, headers, getHeaderProps, getRowProps, getTableProps }) => (
<table {...getTableProps()} className="bx--data-table">
<thead>
<tr>
{headers.map((header) => (
<th key={header.key} {...getHeaderProps({ header })}>
{header.header}
</th>
))}
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.id} {...getRowProps({ row })}>
{headers.map((header) => (
<td key={header.key}>{row[header.key]}</td>
))}
</tr>
))}
</tbody>
</table>
)}
rows={[row]}
onCellClick={(selectedRow) => onSelect(selectedRow)}
mode="button-group-list"
isSortable={false}
/>
);
};
Expand Down

0 comments on commit 2e46f47

Please sign in to comment.