1
1
import React , { useEffect , useMemo , useState } from "react" ;
2
- import { Entity , EntityCollection , EntityCustomView , EntityStatus , FireCMSPlugin , FormContext , User } from "../types" ;
2
+ import { Entity , EntityCollection , EntityStatus , FireCMSPlugin , FormContext , User } from "../types" ;
3
3
4
4
import { CircularProgressCenter , EntityCollectionView , EntityView , ErrorBoundary } from "../components" ;
5
- import { canEditEntity , removeInitialAndTrailingSlashes , resolveDefaultSelectedView , resolveEntityView } from "../util" ;
5
+ import {
6
+ canEditEntity ,
7
+ removeInitialAndTrailingSlashes ,
8
+ resolveDefaultSelectedView ,
9
+ resolvedSelectedEntityView
10
+ } from "../util" ;
6
11
7
12
import {
8
13
useAuthController ,
@@ -13,7 +18,7 @@ import {
13
18
} from "../hooks" ;
14
19
import { CircularProgress , cls , defaultBorderMixin , Tab , Tabs , Typography } from "@firecms/ui" ;
15
20
import { getEntityFromCache } from "../util/entity_cache" ;
16
- import { EntityForm , EntityFormProps , FormLayoutInner } from "../form" ;
21
+ import { EntityForm , EntityFormProps } from "../form" ;
17
22
import { EntityEditViewFormActions } from "./EntityEditViewFormActions" ;
18
23
19
24
const MAIN_TAB_VALUE = "main_##Q$SC^#S6" ;
@@ -120,43 +125,6 @@ export function EntityEditView<M extends Record<string, any>, USER extends User>
120
125
/> ;
121
126
}
122
127
123
- function SecondaryForm < M extends object > ( {
124
- collection,
125
- className,
126
- customView,
127
- entity,
128
- formContext,
129
- forceActionsAtTheBottom,
130
- } : {
131
- className ?: string ,
132
- customView : EntityCustomView ,
133
- formContext : FormContext < M > ,
134
- collection : EntityCollection < M > ,
135
- forceActionsAtTheBottom ?: boolean ,
136
- entity : Entity < M > | undefined ,
137
- } ) {
138
-
139
- if ( ! customView . Builder ) {
140
- console . error ( "customView.Builder is not defined" ) ;
141
- return null ;
142
- }
143
-
144
- return < FormLayoutInner
145
- className = { className }
146
- forceActionsAtTheBottom = { forceActionsAtTheBottom }
147
- formContext = { formContext }
148
- EntityFormActionsComponent = { EntityEditViewFormActions } >
149
- < ErrorBoundary >
150
- { formContext && < customView . Builder
151
- collection = { collection }
152
- entity = { entity }
153
- modifiedValues = { formContext . formex . values ?? entity ?. values }
154
- formContext = { formContext }
155
- /> }
156
- </ ErrorBoundary >
157
- </ FormLayoutInner > ;
158
- }
159
-
160
128
export function EntityEditViewInner < M extends Record < string , any > > ( {
161
129
path,
162
130
entityId,
@@ -214,42 +182,21 @@ export function EntityEditViewInner<M extends Record<string, any>>({
214
182
}
215
183
} , [ selectedTabProp ] ) ;
216
184
217
- const mainViewVisible = selectedTab === MAIN_TAB_VALUE ;
218
-
219
185
const subcollections = ( collection . subcollections ?? [ ] ) . filter ( c => ! c . hideFromNavigation ) ;
220
186
const subcollectionsCount = subcollections ?. length ?? 0 ;
221
187
const customViews = collection . entityViews ;
222
188
const customViewsCount = customViews ?. length ?? 0 ;
223
189
const hasAdditionalViews = customViewsCount > 0 || subcollectionsCount > 0 ;
224
190
225
- const resolvedEntityViews = customViews ? customViews
226
- . map ( e => resolveEntityView ( e , customizationController . entityViews ) )
227
- . filter ( Boolean ) as EntityCustomView [ ]
228
- : [ ] ;
191
+ const {
192
+ resolvedEntityViews,
193
+ selectedEntityView,
194
+ selectedSecondaryForm
195
+ } = resolvedSelectedEntityView ( customViews , customizationController , selectedTab ) ;
229
196
230
- const selectedEntityView = resolvedEntityViews . find ( e => e . key === selectedTab ) ;
231
197
const actionsAtTheBottom = ! largeLayout || layout === "side_panel" || selectedEntityView ?. includeActions === "bottom" ;
232
198
233
- const secondaryForms : React . ReactNode [ ] | undefined = formContext && customViews && resolvedEntityViews
234
- . filter ( e => e . includeActions )
235
- . map ( ( customView ) => {
236
- if ( ! customView || ! formContext )
237
- return null ;
238
-
239
- if ( ! customView . Builder ) {
240
- console . error ( "customView.Builder is not defined" ) ;
241
- return null ;
242
- }
243
-
244
- return < SecondaryForm key = { `custom_view_${ customView . key } ` }
245
- className = { selectedTab !== customView . key ? "hidden" : "" }
246
- customView = { customView }
247
- formContext = { formContext }
248
- collection = { collection }
249
- forceActionsAtTheBottom = { ! largeLayout || layout === "side_panel" || customView . includeActions === "bottom" }
250
- entity = { usedEntity } /> ;
251
-
252
- } ) . filter ( Boolean ) ;
199
+ const mainViewVisible = selectedTab === MAIN_TAB_VALUE || Boolean ( selectedSecondaryForm ) ;
253
200
254
201
const customViewsView : React . ReactNode [ ] | undefined = customViews && resolvedEntityViews
255
202
. filter ( e => ! e . includeActions )
@@ -322,7 +269,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
322
269
path,
323
270
entityId,
324
271
selectedTab : value === MAIN_TAB_VALUE ? undefined : value ,
325
- collection
272
+ collection,
326
273
} ) ;
327
274
}
328
275
} ;
@@ -361,6 +308,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
361
308
onSaved ?.( res ) ;
362
309
formProps ?. onSaved ?.( res ) ;
363
310
} }
311
+ Builder = { selectedSecondaryForm ?. Builder }
364
312
/> ;
365
313
366
314
const subcollectionTabs = subcollections && subcollections . map ( ( subcollection ) =>
@@ -421,7 +369,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
421
369
</ div >
422
370
: entityView }
423
371
424
- { secondaryForms }
372
+ { /*{ secondaryForms}*/ }
425
373
426
374
{ customViewsView }
427
375
0 commit comments