Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions components/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useTranslation } from './hooks/useTranslation'

type Props = { children?: React.ReactNode }
export const DefaultLayout = (props: Props) => {
const { builtAssets, page, error, isHomepageVersion } = useMainContext()
const { page, error, isHomepageVersion } = useMainContext()
const { t } = useTranslation('errors')
return (
<div className="d-lg-flex">
Expand All @@ -22,8 +22,6 @@ export const DefaultLayout = (props: Props) => {
<title>{page.fullTitle}</title>
) : null}

<script src={builtAssets.main.js} />

{/* For Google and Bots */}
{page.introPlainText && <meta name="description" content={page.introPlainText} />}

Expand Down
16 changes: 16 additions & 0 deletions components/PrintAction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

type Props = {
children: React.ReactElement
}
export function PrintAction({ children }: Props) {
const onClick = () => {
try {
document.execCommand('print', false)
} catch (e) {
window.print()
}
}

return React.cloneElement(React.Children.only(children), { onClick })
}
19 changes: 7 additions & 12 deletions components/article/ArticleTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Tooltip } from '@primer/components'
import { PrinterIcon } from './PrinterIcon'

import { PrintAction } from 'components/PrintAction'

type Props = {
children: React.ReactNode
}
Expand All @@ -10,18 +12,11 @@ export const ArticleTitle = ({ children }: Props) => {
<h1 className="my-4 border-bottom-0">{children}</h1>
<div className="d-none d-lg-block ml-2">
<Tooltip aria-label="Print this article" noDelay direction="n">
<button
className="btn-link Link--muted"
onClick={() => {
try {
document.execCommand('print', false)
} catch (e) {
window.print()
}
}}
>
<PrinterIcon />
</button>
<PrintAction>
<button className="btn-link Link--muted">
<PrinterIcon />
</button>
</PrintAction>
</Tooltip>
</div>
</div>
Expand Down
2 changes: 0 additions & 2 deletions components/context/MainContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export type MainContextT = {
maptopic?: BreadcrumbT
article?: BreadcrumbT
}
builtAssets: { main: { js: string } }
activeProducts: Array<ProductT>
currentProduct?: ProductT
currentLayoutName: string
Expand Down Expand Up @@ -112,7 +111,6 @@ export type MainContextT = {

export const getMainContextFromRequest = (req: any): MainContextT => {
return {
builtAssets: { main: { js: req.context.builtAssets.main.js } },
breadcrumbs: req.context.breadcrumbs || {},
activeProducts: req.context.activeProducts,
currentProduct: req.context.productMap[req.context.currentProduct] || null,
Expand Down
5 changes: 4 additions & 1 deletion components/release-notes/GHESReleaseNotePatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PatchNotes } from './PatchNotes'
import { Link } from 'components/Link'
import { CurrentVersion, ReleaseNotePatch, GHESMessage } from './types'
import { useOnScreen } from 'components/hooks/useOnScreen'
import { PrintAction } from 'components/PrintAction'

type Props = {
patch: ReleaseNotePatch
Expand Down Expand Up @@ -65,7 +66,9 @@ export function GHESReleaseNotePatch({
</Link>
)}

<button className="js-print btn-link ml-3 text-small text-bold">Print</button>
<PrintAction>
<button className="btn-link ml-3 text-small text-bold">Print</button>
</PrintAction>
</div>

<p className="color-text-secondary mt-1">{dayjs(patch.date).format('MMMM, DD, YYYY')}</p>
Expand Down
48 changes: 25 additions & 23 deletions components/sublanding/LearningTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ type Props = {
track: FeaturedTrack
}

const MAX_VISIBLE_GUIDES = 4
const DEFAULT_VISIBLE_GUIDES = 4
export const LearningTrack = ({ track }: Props) => {
const [visibleGuides, setVisibleGuides] = useState(track?.guides?.slice(0, 4))
const [numVisible, setNumVisible] = useState(DEFAULT_VISIBLE_GUIDES)
const showAll = () => {
setVisibleGuides(track?.guides)
setNumVisible(track?.guides?.length || 0)
}
const { t } = useTranslation('product_sublanding')

return (
<div className="my-3 px-4 col-12 col-md-6 learning-track">
<div className="Box js-show-more-container d-flex flex-column">
<div className="Box d-flex flex-column">
<div className="Box-header bg-gradient--blue-pink p-4 d-flex flex-1 flex-items-start flex-wrap">
<div className="d-flex flex-auto flex-items-start col-8 col-md-12 col-xl-8">
<div className="my-xl-0 mr-xl-3">
Expand All @@ -38,10 +38,11 @@ export const LearningTrack = ({ track }: Props) => {
</span>
</a>
</div>
{visibleGuides?.map((guide) => (
<div>

{track?.guides?.slice(0, numVisible).map((guide) => (
<div key={guide.href + track?.trackName}>
<a
className="Box-row d-flex flex-items-center color-text-primary no-underline js-show-more-item"
className="Box-row d-flex flex-items-center color-text-primary no-underline"
href={`${guide.href}?learn=${track?.trackName}`}
>
<div className="circle color-bg-tertiary d-inline-flex mr-4">
Expand All @@ -56,24 +57,25 @@ export const LearningTrack = ({ track }: Props) => {
{t('guide_types')[guide.page?.type || '']}
</div>
</a>
{track?.guides && track?.guides?.indexOf(guide) + 1 === MAX_VISIBLE_GUIDES ? (
<button
className="Box-footer btn-link border-top-0 position-relative text-center text-bold color-text-link pt-1 pb-3 col-12 js-show-more-button"
onClick={showAll}
>
<div
className="position-absolute left-0 right-0 py-5 fade-background-bottom"
style={{ bottom: '50px' }}
></div>
<span>
Show {track?.guides?.length - MAX_VISIBLE_GUIDES} {t(`more_guides`)}
</span>
</button>
) : (
<div />
)}
</div>
))}

{(track?.guides?.length || 0) > numVisible ? (
<button
className="Box-footer btn-link border-top-0 position-relative text-center text-bold color-text-link pt-1 pb-3 col-12"
onClick={showAll}
>
<div
className="position-absolute left-0 right-0 py-5 fade-background-bottom"
style={{ bottom: '50px' }}
></div>
<span>
Show {(track?.guides?.length || 0) - numVisible} {t(`more_guides`)}
</span>
</button>
) : (
<div />
)}
</div>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion javascripts/copy-code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default () => {
export default function copyCode() {
const buttons = Array.from(document.querySelectorAll('button.js-btn-copy'))

if (!buttons) return
Expand Down
1 change: 0 additions & 1 deletion javascripts/experiment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import murmur from 'imurmurhash'
import { getUserEventsId, sendEvent, EventType } from './events'
// import h from './hyperscript'

const TREATMENT = 'TREATMENT'
const CONTROL = 'CONTROL'
Expand Down
19 changes: 19 additions & 0 deletions pages/[versionId]/[productId]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { GetServerSideProps } from 'next'

// "legacy" javascript needed to maintain existing functionality
// typically operating on elements **within** an article.
import copyCode from 'javascripts/copy-code'
import displayPlatformSpecificContent from 'javascripts/display-platform-specific-content'
import displayToolSpecificContent from 'javascripts/display-tool-specific-content'
import localization from 'javascripts/localization'
import toggleImages from 'javascripts/toggle-images'
import wrapCodeTerms from 'javascripts/wrap-code-terms'

import {
MainContextT,
MainContext,
Expand Down Expand Up @@ -32,6 +41,7 @@ import {
TocLandingContext,
TocLandingContextT,
} from 'components/context/TocLandingContext'
import { useEffect } from 'react'

type Props = {
mainContext: MainContextT
Expand All @@ -49,6 +59,15 @@ const GlobalPage = ({
}: Props) => {
const { currentLayoutName, relativePath } = mainContext

useEffect(() => {
copyCode()
displayPlatformSpecificContent()
displayToolSpecificContent()
localization()
toggleImages()
wrapCodeTerms()
}, [])

let content
if (currentLayoutName === 'product-landing') {
content = (
Expand Down
16 changes: 10 additions & 6 deletions pages/[versionId]/graphql/overview/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ import {
} from 'components/context/MainContext'
import { Breadcrumbs } from 'components/Breadcrumbs'
import { DefaultLayout } from 'components/DefaultLayout'
import { useEffect, useRef } from 'react'

type Props = {
mainContext: MainContextT
graphqlExplorerUrl: string
}
export default function GQLExplorer({ mainContext, graphqlExplorerUrl }: Props) {
const { page, airGap } = mainContext
const graphiqlRef = useRef<HTMLIFrameElement>(null)

useEffect(() => {
if (typeof window !== 'undefined' && window.location.search) {
graphiqlRef.current?.contentWindow?.postMessage(window.location.search, graphqlExplorerUrl)
}
}, [])

return (
<MainContext.Provider value={mainContext}>
<DefaultLayout>
Expand All @@ -33,12 +42,7 @@ export default function GQLExplorer({ mainContext, graphqlExplorerUrl }: Props)
<p>GraphQL explorer is not available on this environment.</p>
) : (
/* eslint-disable-next-line jsx-a11y/iframe-has-title */
<iframe
id="graphiql"
className="graphql-explorer"
scrolling="no"
src={graphqlExplorerUrl}
>
<iframe ref={graphiqlRef} id="graphiql" scrolling="no" src={graphqlExplorerUrl}>
<p>You must have iframes enabled to use this feature.</p>
</iframe>
)}
Expand Down
12 changes: 12 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ import { defaultThemeProps, getThemeProps } from 'components/lib/getThemeProps'

import '../stylesheets/index.scss'

import events from 'javascripts/events'
import experiment from 'javascripts/experiment'
import setNextEnv from 'javascripts/set-next-env'


type MyAppProps = AppProps & { csrfToken: string; themeProps: typeof defaultThemeProps }
const MyApp = ({ Component, pageProps, csrfToken, themeProps }: MyAppProps) => {

useEffect(() => {
events()
experiment()
setNextEnv()
}, [])

return (
<>
<Head>
Expand Down