@@ -16,12 +16,14 @@ import {
16
16
useFireCMSContext ,
17
17
useLargeLayout
18
18
} from "../hooks" ;
19
- import { CircularProgress , cls , defaultBorderMixin , Tab , Tabs , Typography } from "@firecms/ui" ;
19
+ import { CircularProgress , cls , CodeIcon , defaultBorderMixin , Tab , Tabs , Typography } from "@firecms/ui" ;
20
20
import { getEntityFromCache } from "../util/entity_cache" ;
21
21
import { EntityForm , EntityFormProps } from "../form" ;
22
22
import { EntityEditViewFormActions } from "./EntityEditViewFormActions" ;
23
+ import { EntityJsonPreview } from "../components/EntityJsonPreview" ;
23
24
24
- const MAIN_TAB_VALUE = "main_##Q$SC^#S6" ;
25
+ export const MAIN_TAB_VALUE = "__main_##Q$SC^#S6" ;
26
+ export const JSON_TAB_VALUE = "__json" ;
25
27
26
28
export type OnUpdateParams = {
27
29
entity : Entity < any > ,
@@ -141,7 +143,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
141
143
barActions,
142
144
status,
143
145
setStatus,
144
- formProps,
146
+ formProps
145
147
} : EntityEditViewProps < M > & {
146
148
entity ?: Entity < M > ,
147
149
cachedDirtyValues ?: Partial < M > , // dirty cached entity in memory
@@ -186,7 +188,8 @@ export function EntityEditViewInner<M extends Record<string, any>>({
186
188
const subcollectionsCount = subcollections ?. length ?? 0 ;
187
189
const customViews = collection . entityViews ;
188
190
const customViewsCount = customViews ?. length ?? 0 ;
189
- const hasAdditionalViews = customViewsCount > 0 || subcollectionsCount > 0 ;
191
+ const includeJsonView = true ;
192
+ const hasAdditionalViews = customViewsCount > 0 || subcollectionsCount > 0 || includeJsonView ;
190
193
191
194
const {
192
195
resolvedEntityViews,
@@ -229,6 +232,17 @@ export function EntityEditViewInner<M extends Record<string, any>>({
229
232
230
233
const globalLoading = dataLoading && ! usedEntity ;
231
234
235
+ const jsonView = < div
236
+ className = { cls ( "relative flex-1 h-full overflow-auto w-full" ,
237
+ { "hidden" : selectedTab !== JSON_TAB_VALUE } ) }
238
+ key = { "json_view" }
239
+ role = "tabpanel" >
240
+ < ErrorBoundary >
241
+ < EntityJsonPreview
242
+ values = { formContext ?. values ?? { } } />
243
+ </ ErrorBoundary >
244
+ </ div > ;
245
+
232
246
const subCollectionsViews = subcollections && subcollections . map ( ( subcollection ) => {
233
247
const subcollectionId = subcollection . id ?? subcollection . path ;
234
248
const fullPath = usedEntity ? `${ path } /${ usedEntity ?. id } /${ removeInitialAndTrailingSlashes ( subcollectionId ) } ` : undefined ;
@@ -269,7 +283,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
269
283
path,
270
284
entityId,
271
285
selectedTab : value === MAIN_TAB_VALUE ? undefined : value ,
272
- collection,
286
+ collection
273
287
} ) ;
274
288
}
275
289
} ;
@@ -303,7 +317,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
303
317
onSaved = { ( params ) => {
304
318
const res = {
305
319
...params ,
306
- selectedTab : MAIN_TAB_VALUE === selectedTab ? undefined : selectedTab ,
320
+ selectedTab : MAIN_TAB_VALUE === selectedTab ? undefined : selectedTab
307
321
} ;
308
322
onSaved ?.( res ) ;
309
323
formProps ?. onSaved ?.( res ) ;
@@ -350,13 +364,22 @@ export function EntityEditViewInner<M extends Record<string, any>>({
350
364
onSideTabClick ( value ) ;
351
365
} } >
352
366
367
+ { includeJsonView && < Tab
368
+ disabled = { ! hasAdditionalViews }
369
+ value = { JSON_TAB_VALUE }
370
+ innerClassName = { "block" }
371
+ className = { "text-sm" } >
372
+ < CodeIcon size = { "small" } />
373
+ </ Tab > }
374
+
353
375
< Tab
354
376
disabled = { ! hasAdditionalViews }
355
377
value = { MAIN_TAB_VALUE }
356
378
className = { "text-sm min-w-[120px]" } >
357
379
{ collection . singularName ?? collection . name }
358
380
</ Tab >
359
381
382
+
360
383
{ customViewTabs }
361
384
362
385
{ subcollectionTabs }
@@ -369,7 +392,7 @@ export function EntityEditViewInner<M extends Record<string, any>>({
369
392
</ div >
370
393
: entityView }
371
394
372
- { /*{secondaryForms}*/ }
395
+ { jsonView }
373
396
374
397
{ customViewsView }
375
398
0 commit comments