@@ -4,15 +4,7 @@ import { transformSelectOptions } from '../helper';
4
4
const createClassFieldsSchema = ( aeClassId , selectedRowId , aeTypeOptions ,
5
5
dTypeOptions , schemaField = { } , handleSchemaFieldChange , updateFieldValueInState ) => {
6
6
const classField = schemaField ;
7
-
8
- // const formatName = () => {
9
- // const fullName = classField.name.text;
10
- // const match = fullName.match(/^(.+?)\s*\(([^)]+)\)$/);
11
- // return {
12
- // display_name: match[1],
13
- // name: match[2],
14
- // };
15
- // };
7
+ console . log ( "Class field -- " , classField ) ;
16
8
17
9
const formatName = ( ) => {
18
10
const fullName = classField . name . text ;
@@ -30,6 +22,25 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
30
22
} ;
31
23
} ;
32
24
25
+ const getIcons = ( index ) => {
26
+ if (
27
+ classField
28
+ && typeof classField === 'object'
29
+ && Object . keys ( classField ) . length > 0
30
+ && classField . name
31
+ && 'icon' in classField . name
32
+ ) {
33
+ let icons = classField . name . icon ;
34
+ if ( icons . length === 2 ) {
35
+ // icons come in the order [aetype, dtype, substitute]
36
+ // aetype and substitute will be present always; so rearrange index 1 and 2
37
+ icons = [ icons [ 0 ] , '' , icons [ 1 ] ] ;
38
+ }
39
+ return icons [ index ] ;
40
+ }
41
+ return '' ;
42
+ } ;
43
+
33
44
const getInitialValue = ( field , defaultVal = '' ) => {
34
45
if (
35
46
classField
@@ -38,10 +49,19 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
38
49
) {
39
50
if ( selectedRowId ) {
40
51
if ( field === 'name' || field === 'display_name' ) {
41
- // debugger
42
52
const formatted = formatName ( ) ;
43
53
return formatted [ field ] || defaultVal ;
44
54
}
55
+ if ( field === 'substitute' ) {
56
+ if ( classField [ field ] && 'text' in classField [ field ] ) {
57
+ return classField [ field ] . text !== undefined && classField [ field ] . text !== null
58
+ ? classField [ field ] . text
59
+ : defaultVal ;
60
+ }
61
+ const icon = getIcons ( 2 ) ;
62
+ return icon === 'pficon pficon-ok' ;
63
+ }
64
+ return classField [ field ] . text || defaultVal ;
45
65
}
46
66
47
67
if ( classField [ field ] && 'text' in classField [ field ] ) {
@@ -52,20 +72,6 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
52
72
return defaultVal ;
53
73
} ;
54
74
55
-
56
- const getIcons = ( index ) => {
57
- if (
58
- classField
59
- && typeof classField === 'object'
60
- && Object . keys ( classField ) . length > 0
61
- && classField . name
62
- && 'icon' in classField . name
63
- ) {
64
- return classField . name . icon [ index ] ;
65
- }
66
- return '' ;
67
- } ;
68
-
69
75
const getType = ( options , icon ) => {
70
76
const match = options . find (
71
77
( item ) => item [ 2 ] && item [ 2 ] [ 'data-icon' ] === icon
@@ -175,8 +181,7 @@ const createClassFieldsSchema = (aeClassId, selectedRowId, aeTypeOptions,
175
181
label : __ ( 'Sub' ) ,
176
182
initialValue : getInitialValue ( 'substitute' , true ) ,
177
183
...( selectedRowId && {
178
- onChange : ( e ) => {
179
- const val = e . target . value ;
184
+ onChange : ( val ) => {
180
185
updateFieldValueInState ( 'substitute' , val ) ;
181
186
handleSchemaFieldChange ( aeClassId , val , 'substitute' ) ;
182
187
} ,
0 commit comments