1
1
import React , {
2
- useState , useEffect , useMemo , useCallback ,
2
+ useState , useEffect , useCallback ,
3
3
} from 'react' ;
4
4
import PropTypes from 'prop-types' ;
5
5
import { Modal } from 'carbon-components-react' ;
6
6
import MiqFormRenderer from '@@ddf' ;
7
7
import debounce from 'lodash/debounce' ;
8
8
import { schemaHeaders , createEditableRows } from '../helper' ;
9
9
import createClassFieldsSchema from './modal-form.schema' ;
10
- // import miqRedirectBack from '../../helpers/miq-redirect-back';
11
10
import createSchemaEditSchema from './class-fields-schema' ;
12
11
import mapper from '../../../../forms/mappers/componentMapper' ;
13
12
import { SchemaTableComponent } from './schema-table' ;
@@ -33,11 +32,12 @@ export const ClassFieldsEditor = (props) => {
33
32
// eslint-disable-next-line camelcase
34
33
id, field_id, cells, clickable,
35
34
} ) => {
35
+ // eslint-disable-next-line camelcase
36
+ const fieldId = field_id ;
36
37
const reducedItems = cells . reduce ( ( result , item , index ) => {
37
38
result [ headers [ index ] . name ] = item ;
38
- result . id = id ;
39
- // eslint-disable-next-line camelcase
40
- result . field_id = field_id ;
39
+ result . id = fieldId . toString ( ) ;
40
+ result . field_id = fieldId ;
41
41
result . clickable = clickable ;
42
42
return result ;
43
43
} , { } ) ;
@@ -60,7 +60,7 @@ export const ClassFieldsEditor = (props) => {
60
60
} , [ state . rows ] ) ;
61
61
62
62
const handleModalClose = ( ) => {
63
- setState ( ( state ) => ( { ...state , isModalOpen : false } ) ) ;
63
+ setState ( ( state ) => ( { ...state , isModalOpen : false , selectedRowId : undefined } ) ) ;
64
64
} ;
65
65
66
66
const formatFieldValues = ( field , rowId ) => {
@@ -80,8 +80,6 @@ export const ClassFieldsEditor = (props) => {
80
80
return [ aeTypeIcon , dTypeIcon , subIcon ] ;
81
81
} ;
82
82
83
- debugger
84
-
85
83
const row = {
86
84
id : rowId . toString ( ) ,
87
85
field_id : field . id ,
@@ -150,10 +148,10 @@ export const ClassFieldsEditor = (props) => {
150
148
} ;
151
149
152
150
const updateFieldValueInState = ( fieldName , newValue ) => {
153
- // Update existing field in rows
151
+ // Update existing field in state attr - rows
154
152
setState ( ( prevState ) => {
155
- const updatedRow = prevState . rows . map ( ( row ) => {
156
- if ( row . id === prevState . selectedRowId ) {
153
+ const updatedRow = prevState . rows . map ( ( row , index ) => {
154
+ if ( index === prevState . selectedRowId ) {
157
155
return {
158
156
...row ,
159
157
[ fieldName ] : {
@@ -204,8 +202,6 @@ export const ClassFieldsEditor = (props) => {
204
202
[ aeClassId , state . selectedRowId ]
205
203
) ;
206
204
207
-
208
-
209
205
const onSchemaReset = ( ) => {
210
206
http . post ( `/miq_ae_class/update_fields/${ aeClassId } ?button=reset` , { skipErrors : [ 400 ] } )
211
207
. then ( ( response ) => {
@@ -232,6 +228,7 @@ export const ClassFieldsEditor = (props) => {
232
228
. catch ( miqSparkleOff ) ;
233
229
} ;
234
230
231
+ // On cancelling the edit schema action
235
232
const onCancel = ( ) => {
236
233
http . post ( `/miq_ae_class/update_fields/${ aeClassId } ?button=cancel` , { skipErrors : [ 400 ] } )
237
234
. then ( ( response ) => {
@@ -272,12 +269,14 @@ export const ClassFieldsEditor = (props) => {
272
269
aeTypeOptions ,
273
270
dTypeOptions ,
274
271
state . rows [ state . selectedRowId ] ,
272
+ // state.rows.find((row) => row.id === state.selectedRowId),
275
273
handleSchemaFieldChange ,
276
274
updateFieldValueInState ,
277
275
) }
278
276
onSubmit = { onModalSubmit }
279
277
onCancel = { handleModalClose }
280
- // canReset
278
+ canReset
279
+ disableSubmit = { [ 'invalid' ] }
281
280
buttonsLabels = { { submitLabel : __ ( 'Save' ) } }
282
281
/>
283
282
</ Modal >
0 commit comments