1 import { Outlet } from "react-router-dom"
2 import { JsonViewSection } from "../../../common/json-view-section"
3 import { MetadataSection } from "../../../common/metadata-section"
4 import { PageProps } from "../types"
5
6 export const SingleColumnPage = <TData,>({
7 children,
8 widgets,
9 /**
10 * Data of the page which is passed to Widgets, JSON view, and Metadata view.
11 */
12 data,
13 /**
14 * Whether the page should render an outlet for children routes. Defaults to true.
15 */
16 hasOutlet = true,
17 /**
18 * Whether to show JSON view of the data. Defaults to false.
19 */
20 showJSON,
21 /**
22 * Whether to show metadata view of the data. Defaults to false.
23 */
24 showMetadata,
25 }: PageProps<TData>) => {
26 const { before, after } = widgets
27 const widgetProps = { data }
28
29 if (showJSON && !data) {
30 if (process.env.NODE_ENV === "development") {
31 console.warn(
32 "`showJSON` is true but no data is provided. To display JSON, provide data prop."
33 )
34 }
35
36 showJSON = false
37 }
38
39 if (showMetadata && !data) {
40 if (process.env.NODE_ENV === "development") {
41 console.warn(
42 "`showMetadata` is true but no data is provided. To display metadata, provide data prop."
43 )
44 }
45
46 showMetadata = false
47 }
48
49 return (
50 <div className="flex flex-col gap-y-3">
51 {before.map((Component, i) => {
52 return <Component {...widgetProps} key={i} />
53 })}
54 {children}
55 {after.map((Component, i) => {
56 return <Component {...widgetProps} key={i} />
57 })}
58 {showMetadata && <MetadataSection data={data!} />}
59 {showJSON && <JsonViewSection data={data!} />}
60 {hasOutlet && <Outlet />}
61 </div>
62 )
63 }