forked from ManageIQ/manageiq-ui-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automate Method Form Conversion From HAML to REACT
- Loading branch information
1 parent
1c78100
commit 7366805
Showing
6 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
app/javascript/components/automate-method-form/ansibleTowerJobTemplateSchema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { componentTypes } from '@@ddf'; | ||
|
||
const baseSchema = (options, selectedOption) => { | ||
const commonFields = [ | ||
{ | ||
component: componentTypes.TEXTAREA, | ||
name: 'specify-details', | ||
label: __('Specify details'), | ||
condition: { | ||
and: [{ when: 'hostValue', is: 'specify' }], | ||
}, | ||
}, | ||
{ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'maxttl', | ||
name: 'maxttl', | ||
label: __('Max TTL(mins)'), | ||
}, | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'loggingOutput', | ||
name: 'loggingOutput', | ||
label: __('Logging Output'), | ||
}, | ||
]; | ||
|
||
return { | ||
fields: [ | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'provider', | ||
name: 'provider', | ||
label: __('Provider'), | ||
options: options, | ||
}, | ||
{ | ||
component: componentTypes.SELECT, | ||
id: 'workflowTemplate', | ||
name: 'workflowTemplate', | ||
label: __('Workflow Template'), | ||
options: options, | ||
}, | ||
...(selectedOption && selectedOption.id === 'Ansible Tower Workflow Template' | ||
? [] | ||
: [ | ||
{ | ||
component: componentTypes.RADIO, | ||
id: 'hostValue', | ||
name: 'hostValue', | ||
label: __('Hosts'), | ||
options: [ | ||
{ value: 'localhost', label: 'Localhost' }, | ||
{ value: 'specify', label: 'Specify host values' }, | ||
], | ||
}, | ||
]), | ||
...commonFields, | ||
], | ||
}; | ||
}; | ||
|
||
const ansibleTowerJobTemplateSchema = (options, selectedOption) => { | ||
let schema = baseSchema(options, selectedOption); | ||
|
||
return schema; | ||
}; | ||
|
||
export default ansibleTowerJobTemplateSchema; |
38 changes: 38 additions & 0 deletions
38
app/javascript/components/automate-method-form/commonSchema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { componentTypes } from '@@ddf'; | ||
|
||
const commonSchema = () => ({ | ||
fields: [ | ||
{ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'type', | ||
name: 'type', | ||
label: __('Type'), | ||
disabled: true, | ||
initialValue: 'Ansible Tower Job Template', | ||
}, | ||
{ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'fully-qualified-name', | ||
name: 'fully-qualified-name', | ||
label: __('Fully Qualified Name'), | ||
disabled: true, | ||
initialValue: '', | ||
}, | ||
{ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'name', | ||
name: 'name', | ||
label: __('Name'), | ||
initialValue: '', | ||
}, | ||
{ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'displayName', | ||
name: 'displayname', | ||
label: __('Display Name'), | ||
initialValue: '', | ||
}, | ||
], | ||
}); | ||
|
||
export default commonSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState } from 'react'; | ||
import { Dropdown } from 'carbon-components-react'; | ||
import MiqFormRenderer from '@@ddf'; | ||
import commonSchema from './commonSchema'; | ||
import ansibleTowerJobTemplateSchema from './ansibleTowerJobTemplateSchema'; | ||
|
||
const AutomateMethodForm = (props) => { | ||
const [selectedOption, setSelectedOption] = useState(null); | ||
|
||
const handleSelect = (selectedItem) => { | ||
setSelectedOption(selectedItem); | ||
}; | ||
|
||
const options = props.availableLocations.map(([id, label]) => ({ id, label })); | ||
|
||
const ansibleSchema = | ||
(selectedOption && selectedOption.id === 'Ansible Tower Job Template') || | ||
(selectedOption && selectedOption.id === 'Ansible Tower Workflow Template') || | ||
(selectedOption && selectedOption.id === 'Playbook') | ||
? [ | ||
...commonSchema(options).fields, | ||
...ansibleTowerJobTemplateSchema(options, selectedOption).fields, | ||
] | ||
: commonSchema().fields; | ||
console.log(selectedOption) | ||
return ( | ||
<> | ||
{selectedOption && | ||
(selectedOption.id === 'Ansible Tower Job Template' || | ||
selectedOption.id === 'Ansible Tower Workflow Template' || | ||
selectedOption.id === 'Ansible Tower Workflow Playbook' ) ? ( | ||
<MiqFormRenderer schema={{ fields: ansibleSchema }} /> | ||
) : ( | ||
<div className="mainClass"> | ||
<h3>Main Info</h3> | ||
<Dropdown | ||
id="choose" | ||
label="Choose" | ||
items={options} | ||
itemToString={(item) => (item ? item.label : '')} | ||
onChange={({ selectedItem }) => handleSelect(selectedItem)} | ||
titleText={selectedOption ? selectedOption.label : ''} | ||
/> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default AutomateMethodForm; |
72 changes: 72 additions & 0 deletions
72
app/javascript/components/automate-method-form/schemaHelper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { componentTypes } from '@@ddf'; | ||
|
||
const typeField = () => ({ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'type', | ||
name: 'type', | ||
label: __('Type'), | ||
disabled: true, | ||
initialValue: 'Ansible Tower Job Template', | ||
}); | ||
|
||
const qualifiedNameField = () => ({ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'fully-qualified-name', | ||
name: 'fully-qualified-name', | ||
label: __('Fully Qualified Name'), | ||
disabled: true, | ||
initialValue: '', | ||
}); | ||
|
||
const nameField = () => ({ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'name', | ||
name: 'name', | ||
label: __('Name'), | ||
initialValue: '', | ||
}); | ||
|
||
const displayNameField = () => ({ | ||
component: componentTypes.TEXT_FIELD, | ||
id: 'displayName', | ||
name: 'displayname', | ||
label: __('Display Name'), | ||
initialValue: '', | ||
}); | ||
|
||
const providerField = () => ({ | ||
component: componentTypes.SELECT, | ||
id: 'provider', | ||
name: 'provider', | ||
label: __('Provider'), | ||
options: options, | ||
}); | ||
|
||
const workflowProviderField = () => ({ | ||
component: componentTypes.SELECT, | ||
id: 'workflowProvider', | ||
name: 'workflowProvider', | ||
label: __('Workflow Provider'), | ||
options: options, | ||
}); | ||
|
||
const hostValueField = () => ({ | ||
component: componentTypes.RADIO, | ||
id: 'hostValue', | ||
name: 'hostValue', | ||
label: __('Hosts'), | ||
options: [ | ||
{ value: 'localhost', label: 'Localhost' }, | ||
{ value: 'specify', label: 'Specify host values' }, | ||
], | ||
}); | ||
|
||
export const schemaHelper = () => ([ | ||
typeField(), | ||
qualifiedNameField(), | ||
nameField(), | ||
displayNameField(), | ||
providerField(), | ||
workflowProviderField(), | ||
hostValueField(), | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters