-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathExplorerPage.tsx
149 lines (144 loc) · 4.62 KB
/
ExplorerPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import {
GRAPHER_PAGE_BODY_CLASS,
LoadingIndicator,
} from "@ourworldindata/grapher"
import {
serializeJSONForHTML,
SiteFooterContext,
GrapherInterface,
} from "@ourworldindata/utils"
import {
EMBEDDED_EXPLORER_DELIMITER,
EMBEDDED_EXPLORER_GRAPHER_CONFIGS,
EMBEDDED_EXPLORER_PARTIAL_GRAPHER_CONFIGS,
ExplorerContainerId,
EXPLORERS_ROUTE_FOLDER,
ExplorerProgram,
ExplorerPageUrlMigrationSpec,
EXPLORER_CONSTANTS_DELIMITER,
} from "@ourworldindata/explorer"
import { Head } from "../site/Head.js"
import { IFrameDetector } from "../site/IframeDetector.js"
import { SiteFooter } from "../site/SiteFooter.js"
import { SiteHeader } from "../site/SiteHeader.js"
import { SiteSubnavigation } from "../site/SiteSubnavigation.js"
import { Html } from "./Html.js"
import {
ADMIN_BASE_URL,
BAKED_BASE_URL,
BAKED_GRAPHER_URL,
DATA_API_URL,
} from "../settings/clientSettings.js"
interface ExplorerPageSettings {
program: ExplorerProgram
wpContent?: string
grapherConfigs: GrapherInterface[]
partialGrapherConfigs: GrapherInterface[]
baseUrl: string
urlMigrationSpec?: ExplorerPageUrlMigrationSpec
isPreviewing?: boolean
}
const ExplorerContent = ({ content }: { content: string }) => {
return (
<div className="explorerContentContainer">
<div className="sidebar"></div>
<div className="article-content">
<section>
<div className="wp-block-columns is-style-sticky-right">
<div
className="wp-block-column"
dangerouslySetInnerHTML={{
__html: content,
}}
></div>
<div className="wp-block-column"></div>
</div>
</section>
</div>
</div>
)
}
export const ExplorerPage = (props: ExplorerPageSettings) => {
const {
wpContent,
program,
grapherConfigs,
partialGrapherConfigs,
baseUrl,
urlMigrationSpec,
} = props
const {
subNavId,
subNavCurrentId,
explorerTitle,
explorerSubtitle,
slug,
thumbnail,
hideAlertBanner,
} = program
const subNav = subNavId ? (
<SiteSubnavigation
subnavId={subNavId}
subnavCurrentId={subNavCurrentId}
/>
) : undefined
const inlineJs = `const explorerProgram = ${serializeJSONForHTML(
program.toJson(),
EMBEDDED_EXPLORER_DELIMITER
)};
const grapherConfigs = ${serializeJSONForHTML(
grapherConfigs,
EMBEDDED_EXPLORER_GRAPHER_CONFIGS
)};
const partialGrapherConfigs = ${serializeJSONForHTML(
partialGrapherConfigs,
EMBEDDED_EXPLORER_PARTIAL_GRAPHER_CONFIGS
)};
const urlMigrationSpec = ${
urlMigrationSpec ? JSON.stringify(urlMigrationSpec) : "undefined"
};
const explorerConstants = ${serializeJSONForHTML(
{
adminBaseUrl: ADMIN_BASE_URL,
bakedBaseUrl: BAKED_BASE_URL,
bakedGrapherUrl: BAKED_GRAPHER_URL,
dataApiUrl: DATA_API_URL,
},
EXPLORER_CONSTANTS_DELIMITER
)}
window.Explorer.renderSingleExplorerOnExplorerPage(explorerProgram, grapherConfigs, partialGrapherConfigs, explorerConstants, urlMigrationSpec);`
return (
<Html>
<Head
canonicalUrl={`${baseUrl}/${EXPLORERS_ROUTE_FOLDER}/${slug}`}
hideCanonicalUrl // explorers set their canonical url dynamically
pageTitle={`${explorerTitle} Data Explorer`}
pageDesc={explorerSubtitle}
imageUrl={thumbnail}
baseUrl={baseUrl}
>
<IFrameDetector />
</Head>
<body className={GRAPHER_PAGE_BODY_CLASS}>
<SiteHeader
baseUrl={baseUrl}
hideAlertBanner={hideAlertBanner || false}
/>
{subNav}
<main id={ExplorerContainerId}>
<div className="js--show-warning-block-if-js-disabled" />
<LoadingIndicator />
</main>
{wpContent && <ExplorerContent content={wpContent} />}
<SiteFooter
baseUrl={baseUrl}
context={SiteFooterContext.explorerPage}
/>
<script
type="module"
dangerouslySetInnerHTML={{ __html: inlineJs }}
/>
</body>
</Html>
)
}