@@ -6,10 +6,11 @@ import { schemaHeaders, createEditableRows } from './helper';
6
6
import MiqDataTable from '../../miq-data-table' ;
7
7
import createClassFieldsSchema from './modal-form.schema' ;
8
8
import { CellAction } from '../../miq-data-table/helper' ;
9
+ // import miqRedirectBack from '../../helpers/miq-redirect-back';
9
10
10
11
export const ClassFieldsEditor = ( props ) => {
11
12
const {
12
- aeClassId , initialData, aeTypeOptions, dTypeOptions
13
+ initialData, aeTypeOptions, dTypeOptions,
13
14
} = props ;
14
15
15
16
const fieldData = createEditableRows ( initialData ) ;
@@ -92,7 +93,7 @@ export const ClassFieldsEditor = (props) => {
92
93
// setModalOpen(false);
93
94
setState ( ( state ) => ( { ...state , isModalOpen : false } ) ) ;
94
95
} ;
95
-
96
+
96
97
const renderAddFieldButton = ( ) => (
97
98
< div className = "custom-accordion-buttons" >
98
99
< Button
@@ -109,40 +110,93 @@ export const ClassFieldsEditor = (props) => {
109
110
</ div >
110
111
) ;
111
112
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
+ } ;
114
150
151
+ const onModalSubmit = ( values ) => {
115
152
http . post ( `/miq_ae_class/field_accept?button=accept` , values , {
116
153
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
+ } ) ;
126
168
} ) . catch ( ( error ) => {
127
- console . error ( 'Response:' , error . response ) ;
169
+ console . error ( 'Response:' , error ) ;
128
170
} ) ;
129
171
130
172
handleModalClose ( ) ;
131
173
} ;
132
174
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
+
133
188
return (
134
189
< >
135
190
{ renderAddFieldButton ( ) }
136
191
137
192
< Modal
138
193
open = { state . isModalOpen }
139
- modalHeading = "ABCDEF "
194
+ modalHeading = "Edit "
140
195
onRequestClose = { handleModalClose }
141
196
passiveModal
142
197
>
143
198
< MiqFormRenderer
144
199
schema = { createClassFieldsSchema (
145
- aeClassId ,
146
200
aeTypeOptions ,
147
201
dTypeOptions ,
148
202
state . selectedRowId ,
@@ -165,12 +219,12 @@ export const ClassFieldsEditor = (props) => {
165
219
{ key : 'on_entry' , header : __ ( 'On Entry' ) } ,
166
220
{ key : 'on_exit' , header : __ ( 'On Exit' ) } ,
167
221
{ key : 'on_error' , header : __ ( 'On Error' ) } ,
168
- { key : 'max_entries ' , header : __ ( 'Max Retries' ) } ,
222
+ { key : 'max_retries ' , header : __ ( 'Max Retries' ) } ,
169
223
{ key : 'max_time' , header : __ ( 'Max Time' ) } ,
170
224
{ key : 'edit' , header : __ ( 'Edit' ) } ,
171
225
{ key : 'delete' , header : __ ( 'Delete' ) } ,
172
226
] }
173
- rows = { transformedRows ( ) }
227
+ rows = { state . rows }
174
228
size = "md"
175
229
sortable = { false }
176
230
onCellClick = { ( selectedRow , cellType , event ) =>
@@ -179,7 +233,7 @@ export const ClassFieldsEditor = (props) => {
179
233
< >
180
234
< MiqFormRenderer
181
235
onSubmit = { ( ) => { } }
182
- onCancel = { ( ) => { } }
236
+ onCancel = { onCancel }
183
237
canReset
184
238
buttonsLabels = { { submitLabel : __ ( 'Save' ) } }
185
239
/>
@@ -189,7 +243,7 @@ export const ClassFieldsEditor = (props) => {
189
243
} ;
190
244
191
245
ClassFieldsEditor . propTypes = {
192
- aeClassId : PropTypes . number . isRequired ,
246
+ // aeClassId: PropTypes.number.isRequired,
193
247
initialData : PropTypes . arrayOf ( PropTypes . any ) . isRequired ,
194
248
aeTypeOptions : PropTypes . arrayOf ( PropTypes . any ) ,
195
249
dTypeOptions : PropTypes . arrayOf ( PropTypes . any ) ,
0 commit comments