Skip to content

Commit

Permalink
Permissions statement rendering on automated pages (github#33718)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe authored Jan 3, 2023
1 parent b5d383b commit b240055
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
8 changes: 2 additions & 6 deletions components/article/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useTranslation } from 'components/hooks/useTranslation'
import { LearningTrackNav } from './LearningTrackNav'
import { MarkdownContent } from 'components/ui/MarkdownContent'
import { Lead } from 'components/ui/Lead'
import { PermissionsStatement } from 'components/ui/PermissionsStatement'
import { ArticleGridLayout } from './ArticleGridLayout'
import { PlatformPicker } from 'components/article/PlatformPicker'
import { ToolPicker } from 'components/article/ToolPicker'
Expand Down Expand Up @@ -89,12 +90,7 @@ export const ArticlePage = () => {
</Lead>
)}

{permissions && (
<div className="permissions-statement pl-3 my-4">
<div className="text-bold pr-2">{t('permissions_statement')}</div>
<div dangerouslySetInnerHTML={{ __html: permissions }} />
</div>
)}
{permissions && <PermissionsStatement permissions={permissions} />}

{includesPlatformSpecificContent && <PlatformPicker />}
{includesToolSpecificContent && <ToolPicker />}
Expand Down
6 changes: 5 additions & 1 deletion components/article/AutomatedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DefaultLayout } from 'components/DefaultLayout'
import { ArticleTitle } from 'components/article/ArticleTitle'
import { MarkdownContent } from 'components/ui/MarkdownContent'
import { Lead } from 'components/ui/Lead'
import { PermissionsStatement } from 'components/ui/PermissionsStatement'
import { ArticleGridLayout } from './ArticleGridLayout'
import { MiniTocs } from 'components/ui/MiniTocs'
import { useAutomatedPageContext } from 'components/context/AutomatedPageContext'
Expand All @@ -13,7 +14,8 @@ type Props = {
}

export const AutomatedPage = ({ children }: Props) => {
const { title, intro, renderedPage, miniTocItems, product } = useAutomatedPageContext()
const { title, intro, renderedPage, miniTocItems, product, permissions } =
useAutomatedPageContext()

return (
<DefaultLayout>
Expand All @@ -30,6 +32,8 @@ export const AutomatedPage = ({ children }: Props) => {
</Lead>
)}

{permissions && <PermissionsStatement permissions={permissions} />}

{product && (
<Callout
variant="success"
Expand Down
2 changes: 2 additions & 0 deletions components/context/AutomatedPageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type AutomatedPageContextT = {
renderedPage: string | JSX.Element[]
miniTocItems: Array<MiniTocItem>
product?: string
permissions?: string
}

export const AutomatedPageContext = createContext<AutomatedPageContextT | null>(null)
Expand All @@ -32,5 +33,6 @@ export const getAutomatedPageContextFromRequest = (req: any): AutomatedPageConte
renderedPage: req.context.renderedPage || '',
miniTocItems: req.context.miniTocItems || [],
product: page.product || '',
permissions: page.permissions || '',
}
}
9 changes: 7 additions & 2 deletions components/rest/RestReferencePage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect } from 'react'
import { useEffect } from 'react'
import cx from 'classnames'

import { DefaultLayout } from 'components/DefaultLayout'
import { MarkdownContent } from 'components/ui/MarkdownContent'
import { Lead } from 'components/ui/Lead'
import { PermissionsStatement } from 'components/ui/PermissionsStatement'
import { RestOperation } from './RestOperation'
import { useAutomatedPageContext } from 'components/context/AutomatedPageContext'
import { Operation } from './types'
Expand All @@ -18,7 +19,8 @@ export type StructuredContentT = {
}

export const RestReferencePage = ({ restOperations }: StructuredContentT) => {
const { title, intro, renderedPage } = useAutomatedPageContext()
const { title, intro, renderedPage, permissions } = useAutomatedPageContext()

// Scrollable code blocks in our REST API docs and elsewhere aren't accessible
// via keyboard navigation without setting tabindex="0". But we don't want to set
// this attribute on every `<pre>` code block, only the ones where there are scroll
Expand Down Expand Up @@ -53,6 +55,9 @@ export const RestReferencePage = ({ restOperations }: StructuredContentT) => {
{intro}
</Lead>
)}

{permissions && <PermissionsStatement permissions={permissions} />}

{renderedPage && <MarkdownContent className="pt-3 pb-4">{renderedPage}</MarkdownContent>}
{restOperations.length > 0 && (
<MarkdownContent className="pt-3 pb-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.permissions_statement {
border-left: 5px solid var(--color-border-muted);
}
22 changes: 22 additions & 0 deletions components/ui/PermissionsStatement/PermissionsStatement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import cx from 'classnames'

import styles from './PermissionsStatement.module.scss'
import { useTranslation } from 'components/hooks/useTranslation'

type Props = {
permissions: string
}

export function PermissionsStatement({ permissions }: Props) {
const { t } = useTranslation('pages')
return (
<div
className={cx(styles.permissions_statement, 'pl-3 my-4')}
data-search="hide"
data-testid="permissions-statement"
>
<div className="text-bold pr-2">{t('permissions_statement')}</div>
<div dangerouslySetInnerHTML={{ __html: permissions }} />
</div>
)
}
1 change: 1 addition & 0 deletions components/ui/PermissionsStatement/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PermissionsStatement } from './PermissionsStatement'
4 changes: 0 additions & 4 deletions stylesheets/extended-markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,3 @@
.warning {
font-weight: normal;
}

.permissions-statement {
border-left: 5px solid var(--color-border-muted);
}
2 changes: 1 addition & 1 deletion tests/rendering/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('server', () => {
const $ = await getDOM(
'/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site'
)
expect($('div.permissions-statement').text()).toContain('GitHub Pages site')
expect($('[data-testid="permissions-statement"]').text()).toContain('GitHub Pages site')
})

// see issue 9678
Expand Down

0 comments on commit b240055

Please sign in to comment.