1 import { ReactNode } from "react"
2 import { JsonViewSection } from "../common/json-view-section"
3 import { MetadataSection } from "../common/metadata-section"
4 import { RequiredPermissionsSection } from "../common/required-permissions-section"
5 import { LayoutComposer } from "./layout-composer"
6
7 export type DetailPageDefaultsOptions = {
8 /** Render the metadata section. @default true */
9 metadata?: boolean
10 /** Render the JSON view section. @default true */
11 jsonView?: boolean
12 /** Render the required-permissions section. @default true */
13 permissions?: boolean
14 }
15
16 /**
17 * Returns the sections common to detail pages (metadata, JSON view, and
18 * required permissions), each wrapped in a `LayoutComposer.Entry` with a
19 * stable id so saved user preferences survive component renames.
20 *
21 * All three render by default. Pass an options object to opt out of any a
22 * given page doesn't use, so the page renders exactly the set it always had:
23 *
24 * ```tsx
25 * sections={{ main: <>{...coreContent}{detailPageDefaultEntries(entity)}</> }}
26 * // metadata + json only:
27 * {detailPageDefaultEntries(entity, { permissions: false })}
28 * ```
29 */
30 export function detailPageDefaultEntries(
31 data: object,
32 {
33 metadata = true,
34 jsonView = true,
35 permissions = true,
36 }: DetailPageDefaultsOptions = {}
37 ): ReactNode {
38 return (
39 <>
40 {metadata && (
41 <LayoutComposer.Entry id="MetadataSection">
42 <MetadataSection data={data} />
43 </LayoutComposer.Entry>
44 )}
45 {jsonView && (
46 <LayoutComposer.Entry id="JsonViewSection">
47 <JsonViewSection data={data} />
48 </LayoutComposer.Entry>
49 )}
50 {permissions && (
51 <LayoutComposer.Entry id="RequiredPermissionsSection">
52 <RequiredPermissionsSection />
53 </LayoutComposer.Entry>
54 )}
55 </>
56 )
57 }