@@ -3,7 +3,6 @@ import { PluginDocumentSettingPanel } from '@wordpress/editor';
3
3
import {
4
4
Button ,
5
5
Modal ,
6
- TextControl ,
7
6
__experimentalVStack as VStack ,
8
7
__experimentalItemGroup as ItemGroup ,
9
8
__experimentalItem as Item ,
@@ -19,31 +18,15 @@ import { seen, unseen, blockDefault } from '@wordpress/icons';
19
18
20
19
import EditFieldForm from './_edit-field' ;
21
20
22
- /**
23
- * Our base plugin component.
24
- * @returns CreateContentModelPageSettings
25
- */
26
21
const CreateContentModelPageSettings = function ( ) {
27
22
const [ isFieldsOpen , setFieldsOpen ] = useState ( false ) ;
28
23
29
- const [ meta , setMeta ] = useEntityProp (
24
+ const [ meta ] = useEntityProp (
30
25
'postType' ,
31
- contentModelFields . postType ,
26
+ window . contentModelFields . postType ,
32
27
'meta'
33
28
) ;
34
29
35
- const [ slug , setSlug ] = useEntityProp (
36
- 'postType' ,
37
- contentModelFields . postType ,
38
- 'slug'
39
- ) ;
40
-
41
- const [ title , setTitle ] = useEntityProp (
42
- 'postType' ,
43
- contentModelFields . postType ,
44
- 'title'
45
- ) ;
46
-
47
30
// Saving the fields as serialized JSON because I was tired of fighting the REST API.
48
31
const fields = meta ?. fields ? JSON . parse ( meta . fields ) : [ ] ;
49
32
@@ -54,94 +37,45 @@ const CreateContentModelPageSettings = function () {
54
37
}
55
38
} ) ;
56
39
57
- const textControlFields = [
58
- {
59
- key : 'slug' ,
60
- label : __ ( 'Slug' ) ,
61
- value : slug ,
62
- onChange : ( value ) => setSlug ( value ) ,
63
- help : __ (
64
- 'Warning: Changing the slug will break existing content.'
65
- ) ,
66
- } ,
67
- {
68
- key : 'singular_label' ,
69
- label : __ ( 'Singular Label' ) ,
70
- value : title ,
71
- onChange : ( value ) => setTitle ( value ) ,
72
- help : __ ( 'Synced with the title of the post type.' ) ,
73
- } ,
74
- {
75
- key : 'plural_label' ,
76
- label : __ ( 'Plural Label' ) ,
77
- value : meta . plural_label || `${ title } s` ,
78
- onChange : ( value ) => setMeta ( { ...meta , plural_label : value } ) ,
79
- help : __ (
80
- 'This is the label that will be used for the plural form of the post type.'
81
- ) ,
82
- } ,
83
- {
84
- key : 'description' ,
85
- label : __ ( 'Description' ) ,
86
- value : meta . description ,
87
- onChange : ( value ) => setMeta ( { ...meta , description : value } ) ,
88
- help : __ ( 'Description for the post type.' ) ,
89
- } ,
90
- ] ;
91
-
92
40
return (
93
41
< >
94
- < PluginDocumentSettingPanel
95
- name = "create-content-model-post-settings"
96
- title = { __ ( 'Post Type' ) }
97
- className = "create-content-model-post-settings"
98
- >
99
- { textControlFields . map ( ( field ) => (
100
- < TextControl
101
- key = { field . key }
102
- label = { field . label }
103
- value = { field . value }
104
- onChange = { field . onChange }
105
- disabled = { field . disabled }
106
- help = { field . help }
107
- />
108
- ) ) }
109
- </ PluginDocumentSettingPanel >
110
42
< PluginDocumentSettingPanel
111
43
name = "create-content-model-field-settings"
112
44
title = { __ ( 'Custom Fields' ) }
113
45
className = "create-content-model-field-settings"
114
46
>
115
- < ItemGroup isBordered isSeparated >
116
- { fields . map ( ( field ) => (
117
- < Item key = { field . uuid } >
118
- < Flex >
119
- < FlexBlock > { field . label } </ FlexBlock >
120
- < FlexItem >
121
- < code > { field . slug } </ code >
122
- </ FlexItem >
123
-
124
- { field . visible && (
47
+ { fields . length > 0 && (
48
+ < ItemGroup isBordered isSeparated >
49
+ { fields . map ( ( field ) => (
50
+ < Item key = { field . uuid } >
51
+ < Flex >
52
+ < FlexBlock > { field . label } </ FlexBlock >
125
53
< FlexItem >
126
- < Icon icon = { seen } / >
54
+ < code > { field . slug } </ code >
127
55
</ FlexItem >
128
- ) }
129
- { ! field . visible &&
130
- field . type . indexOf ( 'core' ) > - 1 && (
131
- < FlexItem >
132
- < Icon icon = { blockDefault } />
133
- </ FlexItem >
134
- ) }
135
- { ! field . visible &&
136
- field . type . indexOf ( 'core' ) < 0 && (
56
+
57
+ { field . visible && (
137
58
< FlexItem >
138
- < Icon icon = { unseen } />
59
+ < Icon icon = { seen } />
139
60
</ FlexItem >
140
61
) }
141
- </ Flex >
142
- </ Item >
143
- ) ) }
144
- </ ItemGroup >
62
+ { ! field . visible &&
63
+ field . type . indexOf ( 'core' ) > - 1 && (
64
+ < FlexItem >
65
+ < Icon icon = { blockDefault } />
66
+ </ FlexItem >
67
+ ) }
68
+ { ! field . visible &&
69
+ field . type . indexOf ( 'core' ) < 0 && (
70
+ < FlexItem >
71
+ < Icon icon = { unseen } />
72
+ </ FlexItem >
73
+ ) }
74
+ </ Flex >
75
+ </ Item >
76
+ ) ) }
77
+ </ ItemGroup >
78
+ ) }
145
79
146
80
< Button
147
81
variant = "secondary"
@@ -164,14 +98,10 @@ const CreateContentModelPageSettings = function () {
164
98
) ;
165
99
} ;
166
100
167
- /**
168
- * Display the list of fields inside the modal.
169
- * @returns FieldsList
170
- */
171
101
const FieldsList = ( ) => {
172
102
const [ meta , setMeta ] = useEntityProp (
173
103
'postType' ,
174
- contentModelFields . postType ,
104
+ window . contentModelFields . postType ,
175
105
'meta'
176
106
) ;
177
107
@@ -215,22 +145,22 @@ const FieldsList = () => {
215
145
index = { fields . findIndex (
216
146
( f ) => f . uuid === field . uuid
217
147
) }
218
- onMoveUp = { ( field ) => {
148
+ onMoveUp = { ( movedField ) => {
219
149
const index = fields . findIndex (
220
- ( f ) => f . uuid === field . uuid
150
+ ( f ) => f . uuid === movedField . uuid
221
151
) ;
222
152
const newFields = [ ...fields ] ;
223
153
newFields . splice ( index , 1 ) ;
224
- newFields . splice ( index - 1 , 0 , field ) ;
154
+ newFields . splice ( index - 1 , 0 , movedField ) ;
225
155
setFields ( newFields ) ;
226
156
} }
227
- onMoveDown = { ( field ) => {
157
+ onMoveDown = { ( movedField ) => {
228
158
const index = fields . findIndex (
229
- ( f ) => f . uuid === field . uuid
159
+ ( f ) => f . uuid === movedField . uuid
230
160
) ;
231
161
const newFields = [ ...fields ] ;
232
162
newFields . splice ( index , 1 ) ;
233
- newFields . splice ( index + 1 , 0 , field ) ;
163
+ newFields . splice ( index + 1 , 0 , movedField ) ;
234
164
setFields ( newFields ) ;
235
165
} }
236
166
/>
0 commit comments