-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathArticlePage.tsx
More file actions
173 lines (160 loc) · 5.82 KB
/
ArticlePage.tsx
File metadata and controls
173 lines (160 loc) · 5.82 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { useRouter } from 'next/router'
import dynamic from 'next/dynamic'
import cx from 'classnames'
import { LinkExternalIcon } from '@primer/octicons-react'
import { DefaultLayout } from '@/frame/components/DefaultLayout'
import { ArticleTitle } from '@/frame/components/article/ArticleTitle'
import { useArticleContext } from '@/frame/components/context/ArticleContext'
import { LearningTrackNav } from '@/learning-track/components/article/LearningTrackNav'
import { JourneyTrackNav } from '@/journeys/components/JourneyTrackNav'
import { JourneyTrackCard } from '@/journeys/components/JourneyTrackCard'
import { MarkdownContent } from '@/frame/components/ui/MarkdownContent'
import { Lead } from '@/frame/components/ui/Lead'
import { PermissionsStatement } from '@/frame/components/ui/PermissionsStatement'
import { ArticleGridLayout } from './ArticleGridLayout'
import { ArticleInlineLayout } from './ArticleInlineLayout'
import { PlatformPicker } from '@/tools/components/PlatformPicker'
import { ToolPicker } from '@/tools/components/ToolPicker'
import { MiniTocs } from '@/frame/components/ui/MiniTocs'
import { LearningTrackCard } from '@/learning-track/components/article/LearningTrackCard'
import { RestRedirect } from '@/rest/components/RestRedirect'
import { Breadcrumbs } from '@/frame/components/page-header/Breadcrumbs'
import { Link } from '@/frame/components/Link'
import { useTranslation } from '@/languages/components/useTranslation'
import { LinkPreviewPopover } from '@/links/components/LinkPreviewPopover'
import { UtmPreserver } from '@/frame/components/UtmPreserver'
const ClientSideRefresh = dynamic(() => import('@/frame/components/ClientSideRefresh'), {
ssr: false,
})
const isDev = process.env.NODE_ENV === 'development'
export const ArticlePage = () => {
const router = useRouter()
const {
title,
intro,
effectiveDate,
renderedPage,
permissions,
includesPlatformSpecificContent,
includesToolSpecificContent,
product,
productVideoUrl,
miniTocItems,
currentLearningTrack,
currentJourneyTrack,
supportPortalVaIframeProps,
currentLayout,
} = useArticleContext()
const isLearningPath = !!currentLearningTrack?.trackName
const isJourneyPath = !!currentJourneyTrack?.trackId
// Only show journey track components when feature flag is enabled
const showJourneyTracks = isJourneyPath && router.query?.feature === 'journey-navigation'
const { t } = useTranslation(['pages'])
const introProp = (
<>
{intro && (
// Note the `_page-intro` is used by the popover preview cards
// when it needs this text for in-page links.
<Lead data-testid="lead" data-search="lead" className="_page-intro">
{intro}
</Lead>
)}
</>
)
const introCalloutsProp = (
<>
<PermissionsStatement permissions={permissions} product={product} />
{includesPlatformSpecificContent && <PlatformPicker />}
{includesToolSpecificContent && <ToolPicker />}
</>
)
const toc = (
<>
{isLearningPath && <LearningTrackCard track={currentLearningTrack} />}
{showJourneyTracks && <JourneyTrackCard journey={currentJourneyTrack} />}
{miniTocItems.length > 1 && <MiniTocs miniTocItems={miniTocItems} />}
</>
)
const articleContents = (
<div id="article-contents">
{productVideoUrl && (
<div className="my-2">
<Link id="product-video" href={productVideoUrl} target="_blank">
<LinkExternalIcon aria-label="(external site)" className="octicon-link mr-2" />
{t('video_from_transcript')}
</Link>
</div>
)}
<MarkdownContent>{renderedPage}</MarkdownContent>
{effectiveDate && (
<div className="mt-4" id="effectiveDate">
Effective as of:{' '}
<time dateTime={new Date(effectiveDate).toISOString()}>
{new Date(effectiveDate).toDateString()}
</time>
</div>
)}
</div>
)
return (
<DefaultLayout>
<LinkPreviewPopover />
<UtmPreserver />
{isDev && <ClientSideRefresh />}
{router.pathname.includes('/rest/') && <RestRedirect />}
{currentLayout === 'inline' ? (
<>
<ArticleInlineLayout
supportPortalVaIframeProps={supportPortalVaIframeProps}
topper={<ArticleTitle>{title}</ArticleTitle>}
intro={introProp}
introCallOuts={introCalloutsProp}
toc={toc}
breadcrumbs={<Breadcrumbs />}
>
{articleContents}
</ArticleInlineLayout>
{isLearningPath ? (
<div className="container-lg mt-4 px-3">
<LearningTrackNav track={currentLearningTrack} />
</div>
) : null}
{showJourneyTracks ? (
<div className="container-lg mt-4 px-3">
<JourneyTrackNav context={currentJourneyTrack} />
</div>
) : null}
</>
) : (
<div className="container-xl px-3 px-md-6 my-4">
<div className={cx('d-none d-xxl-block mt-3 mr-auto width-full')}>
<Breadcrumbs />
</div>
<ArticleGridLayout
supportPortalVaIframeProps={supportPortalVaIframeProps}
topper={<ArticleTitle>{title}</ArticleTitle>}
intro={
<>
{introProp}
{introCalloutsProp}
</>
}
toc={toc}
>
{articleContents}
</ArticleGridLayout>
{isLearningPath ? (
<div className="mt-4">
<LearningTrackNav track={currentLearningTrack} />
</div>
) : null}
{showJourneyTracks ? (
<div className="mt-4">
<JourneyTrackNav context={currentJourneyTrack} />
</div>
) : null}
</div>
)}
</DefaultLayout>
)
}