Skip to content

Commit 69d2c0b

Browse files
committed
Adds new field to the ui
1 parent cdb1bca commit 69d2c0b

File tree

4 files changed

+77
-24
lines changed

4 files changed

+77
-24
lines changed

app/javascript/components/data-tables/datastore/class-fields-editor.jsx

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { schemaHeaders, createEditableRows } from './helper';
66
import MiqDataTable from '../../miq-data-table';
77
import createClassFieldsSchema from './modal-form.schema';
88
import { CellAction } from '../../miq-data-table/helper';
9+
// import miqRedirectBack from '../../helpers/miq-redirect-back';
910

1011
export const ClassFieldsEditor = (props) => {
1112
const {
12-
aeClassId, initialData, aeTypeOptions, dTypeOptions
13+
initialData, aeTypeOptions, dTypeOptions,
1314
} = props;
1415

1516
const fieldData = createEditableRows(initialData);
@@ -92,7 +93,7 @@ export const ClassFieldsEditor = (props) => {
9293
// setModalOpen(false);
9394
setState((state) => ({ ...state, isModalOpen: false }));
9495
};
95-
96+
9697
const renderAddFieldButton = () => (
9798
<div className="custom-accordion-buttons">
9899
<Button
@@ -109,40 +110,93 @@ export const ClassFieldsEditor = (props) => {
109110
</div>
110111
);
111112

112-
const onModalSubmit = (values) => {
113-
debugger
113+
const formatFieldValues = (field) => {
114+
if (!field || typeof field !== 'object') return [];
115+
116+
const row = {
117+
id: field.id || state.rows.length,
118+
name: { text: field.name, icon: field.icons },
119+
aetype: { text: field.aetype },
120+
datatype: { text: field.datatype },
121+
default_value: { text: field.default_value },
122+
display_name: { text: field.display_name },
123+
description: { text: field.description },
124+
substitute: { text: field.substitute },
125+
collect: { text: field.collect },
126+
message: { text: field.message },
127+
on_entry: { text: field.on_entry },
128+
on_exit: { text: field.on_exit },
129+
on_error: { text: field.on_error },
130+
max_retries: { text: field.max_retries },
131+
max_time: { text: field.max_time },
132+
edit: {
133+
is_button: true,
134+
text: __('Update'),
135+
kind: 'tertiary',
136+
size: 'md',
137+
callback: 'editSubscription',
138+
},
139+
delete: {
140+
is_button: true,
141+
text: __('Delete'),
142+
kind: 'danger',
143+
size: 'md',
144+
callback: 'deleteSubscription',
145+
},
146+
};
147+
148+
return row;
149+
};
114150

151+
const onModalSubmit = (values) => {
115152
http.post(`/miq_ae_class/field_accept?button=accept`, values, {
116153
skipErrors: [400],
117-
}).then((response) => {
118-
debugger
119-
console.log(response);
120-
121-
setState((prevState) => ({
122-
...prevState,
123-
schemaRecords: [...prevState.schemaRecords, values],
124-
}));
125-
// }
154+
}).then(() => {
155+
const data = formatFieldValues(values);
156+
// const clonedData = JSON.parse(JSON.stringify(data));
157+
// setState((prevState) => ({
158+
// ...prevState,
159+
// rows: [...prevState.rows, data],
160+
// }));
161+
setState((prevState) => {
162+
debugger;
163+
return {
164+
...prevState,
165+
rows: [...prevState.rows, data],
166+
};
167+
});
126168
}).catch((error) => {
127-
console.error('Response:', error.response);
169+
console.error('Response:', error);
128170
});
129171

130172
handleModalClose();
131173
};
132174

175+
// const onCancel = () => {
176+
// debugger
177+
// miqSparkleOn();
178+
// const message = __('Edit of schema field was cancelled by the user');
179+
// miqRedirectBack(message, 'warning', '/miq_ae_class/explorer');
180+
// };
181+
182+
const onCancel = () => {
183+
miqSparkleOn();
184+
// miqAjaxButton(`/miq_ae_class/explorer`);
185+
window.location.reload();
186+
};
187+
133188
return (
134189
<>
135190
{renderAddFieldButton()}
136191

137192
<Modal
138193
open={state.isModalOpen}
139-
modalHeading="ABCDEF"
194+
modalHeading="Edit"
140195
onRequestClose={handleModalClose}
141196
passiveModal
142197
>
143198
<MiqFormRenderer
144199
schema={createClassFieldsSchema(
145-
aeClassId,
146200
aeTypeOptions,
147201
dTypeOptions,
148202
state.selectedRowId,
@@ -165,12 +219,12 @@ export const ClassFieldsEditor = (props) => {
165219
{ key: 'on_entry', header: __('On Entry') },
166220
{ key: 'on_exit', header: __('On Exit') },
167221
{ key: 'on_error', header: __('On Error') },
168-
{ key: 'max_entries', header: __('Max Retries') },
222+
{ key: 'max_retries', header: __('Max Retries') },
169223
{ key: 'max_time', header: __('Max Time') },
170224
{ key: 'edit', header: __('Edit') },
171225
{ key: 'delete', header: __('Delete') },
172226
]}
173-
rows={transformedRows()}
227+
rows={state.rows}
174228
size="md"
175229
sortable={false}
176230
onCellClick={(selectedRow, cellType, event) =>
@@ -179,7 +233,7 @@ export const ClassFieldsEditor = (props) => {
179233
<>
180234
<MiqFormRenderer
181235
onSubmit={() => {}}
182-
onCancel={() => {}}
236+
onCancel={onCancel}
183237
canReset
184238
buttonsLabels={{ submitLabel: __('Save') }}
185239
/>
@@ -189,7 +243,7 @@ export const ClassFieldsEditor = (props) => {
189243
};
190244

191245
ClassFieldsEditor.propTypes = {
192-
aeClassId: PropTypes.number.isRequired,
246+
// aeClassId: PropTypes.number.isRequired,
193247
initialData: PropTypes.arrayOf(PropTypes.any).isRequired,
194248
aeTypeOptions: PropTypes.arrayOf(PropTypes.any),
195249
dTypeOptions: PropTypes.arrayOf(PropTypes.any),

app/javascript/components/data-tables/datastore/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const schemaHeaders = (isEdit = false) => {
3838
{ name: 'on_entry', text: 'OnEntry', header_text: __('On Entry') },
3939
{ name: 'on_exit', text: 'OnExit', header_text: __('On Exit') },
4040
{ name: 'on_error', text: 'OnError', header_text: __('On Error') },
41-
{ name: 'max_entries', text: 'MaxRetries', header_text: __('Max Retries') },
41+
{ name: 'max_retries', text: 'MaxRetries', header_text: __('Max Retries') },
4242
{ name: 'max_time', text: 'MaxTime', header_text: __('Max Time') },
4343
];
4444

app/javascript/components/data-tables/datastore/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const Datastore = ({
104104
case 'class_fields':
105105
return (
106106
<ClassFieldsEditor
107-
aeClassId={aeClassId}
107+
// aeClassId={aeClassId}
108108
initialData={initialData}
109109
aeTypeOptions={aeTypeOptions}
110110
dTypeOptions={dTypeOptions}

app/javascript/components/data-tables/datastore/modal-form.schema.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { componentTypes, validatorTypes } from '@@ddf';
22
import { transformSelectOptions, handleSchemaFieldChange } from './helper';
33

4-
const createClassFieldsSchema = (aeClassId, aeTypeOptions, dTypeOptions, selectedRowId, schemaField = {}) => {
5-
debugger
4+
const createClassFieldsSchema = (aeTypeOptions, dTypeOptions, selectedRowId, schemaField = {}) => {
65
const classField = schemaField;
76

87
// const getFieldName = (fname, index) =>

0 commit comments

Comments
 (0)