-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5c4137
commit edd20a0
Showing
9 changed files
with
469 additions
and
348 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
app/javascript/components/automate-method-form/automate-method-input-parameter/helper.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,31 @@ | ||
export const InputParameterActions = { | ||
EDIT: 'editInputParameter', | ||
DELETE: 'deleteInputParameter', | ||
} | ||
const editInputParameterButton = () => ({ | ||
is_button: true, | ||
title: __('Edit'), | ||
text: __('Edit'), | ||
alt: __('Edit'), | ||
kind: 'ghost', | ||
callback: InputParameterActions.EDIT, | ||
}); | ||
|
||
const deleteInputParameterButton = () => ({ | ||
is_button: true, | ||
title: __('Delete'), | ||
text: __('Delete'), | ||
alt: __('Delete'), | ||
kind: 'ghost', | ||
callback: InputParameterActions.DELETE, | ||
}); | ||
|
||
export const inputParametersList = (items) => { | ||
const rows = items.map((item, index) => ({ | ||
...item, | ||
id: index.toString(), | ||
edit: editInputParameterButton(item, index), | ||
delete: deleteInputParameterButton(item, index), | ||
})); | ||
return rows; | ||
} |
131 changes: 131 additions & 0 deletions
131
app/javascript/components/automate-method-form/automate-method-input-parameter/index.jsx
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,131 @@ | ||
import React, { useState } from 'react'; | ||
import { inputParameterSchema } from './schema'; | ||
import {Button, Modal} from 'carbon-components-react'; | ||
import MiqFormRenderer from '@@ddf'; | ||
import { inputParametersList, InputParameterActions } from './helper'; | ||
import MiqDataTable from '../../miq-data-table'; | ||
import NotificationMessage from '../../notification-message'; | ||
|
||
const AutomateMethodInputParameter = () => { | ||
|
||
const headers = [ | ||
{ key: 'inputName', header: __('Input Name') }, | ||
{ key: 'dataType', header: __('Data Type') }, | ||
{ key: 'defaultValue', header: __('Default Value') }, | ||
{ key: 'edit', header: __('Edit')}, | ||
{ key: 'delete', header: __('Delete')}, | ||
] | ||
|
||
const [data, setData] = useState({ | ||
isModalOpen: false, | ||
initialValues: [], | ||
rows: [], | ||
selectedItemId: undefined, | ||
}); | ||
|
||
const addInputParameter = (values) => { | ||
console.log('actionType=', values); | ||
const newList = [...data.initialValues, values]; | ||
console.log(newList); | ||
setData({ | ||
...data, | ||
initialValues: newList, | ||
rows: inputParametersList(newList), | ||
selectedItemId: undefined, | ||
isModalOpen: false, | ||
}) | ||
}; | ||
|
||
const updateInputParameter = (values) => { | ||
data.initialValues[data.selectedItemId] = values; | ||
setData({ | ||
...data, | ||
initialValues: data.initialValues, | ||
rows: inputParametersList(data.initialValues), | ||
selectedItemId: undefined, | ||
isModalOpen: false, | ||
}); | ||
} | ||
|
||
const addOrUpdateInputParameter = (values) => { | ||
data.selectedItemId | ||
? updateInputParameter(values) | ||
: addInputParameter(values); | ||
} | ||
|
||
const editInputParameter = (id) => { | ||
console.log('Edit', id); | ||
|
||
console.log(data.initialValues); | ||
setData({ | ||
...data, | ||
isModalOpen: true, | ||
selectedItemId: id, | ||
}); | ||
} | ||
|
||
const deleteInputParameter = (id) => { | ||
console.log('Delete', id); | ||
data.initialValues.splice(id, 1); | ||
setData({ | ||
...data, | ||
initialValues: data.initialValues, | ||
rows: inputParametersList(data.initialValues), | ||
}) | ||
} | ||
|
||
const onSelect = (item) => { | ||
console.log(item); | ||
if (item && item.callbackAction) { | ||
switch(item.callbackAction) { | ||
case InputParameterActions.EDIT: | ||
return editInputParameter(item.id); | ||
case InputParameterActions.DELETE: | ||
return deleteInputParameter(item.id); | ||
} | ||
} | ||
} | ||
|
||
console.log("data====", data); | ||
|
||
return ( | ||
<div> | ||
<Button | ||
onClick={() => setData({...data, isModalOpen: true})} | ||
kind="primary" | ||
> | ||
Add Input Parameters | ||
</Button> | ||
|
||
{ | ||
data.rows.length > 0 | ||
? <MiqDataTable | ||
headers={headers} | ||
rows={data.rows} | ||
onCellClick={(selectedRow) => onSelect(selectedRow)} | ||
mode="button-group-list" | ||
/> | ||
: <NotificationMessage type="info" message={__('Input parameters are not available.')} /> | ||
} | ||
|
||
{ | ||
data.isModalOpen && | ||
<Modal | ||
open={data.isModalOpen} | ||
modalHeading={__('Add Input Parameters')} | ||
secondaryButtonText={__('Cancel')} | ||
onRequestClose={() => setData({...data, isModalOpen: false})} | ||
passiveModal | ||
> | ||
<MiqFormRenderer | ||
schema={inputParameterSchema} | ||
initialValues={data.selectedItemId && data.initialValues[data.selectedItemId]} | ||
onSubmit={(values) => addOrUpdateInputParameter(values)} /> | ||
</Modal> | ||
} | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default AutomateMethodInputParameter |
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
25 changes: 0 additions & 25 deletions
25
app/javascript/components/automate-method-form/automateModal.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.