Skip to content

Commit

Permalink
Merge pull request nasa-gcn#2260 from lpsinger/remove-circulars-markd…
Browse files Browse the repository at this point in the history
…own-feature-flag

Remove CIRCULARS_MARKDOWN feature flag
  • Loading branch information
dakota002 authored May 13, 2024
2 parents 4253077 + c74ea4f commit 54496af
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 97 deletions.
7 changes: 2 additions & 5 deletions app/routes/circulars.$circularId.($version)/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import DetailsDropdownContent from '~/components/DetailsDropdownContent'
import { origin } from '~/lib/env.server'
import { getCanonicalUrlHeaders, pickHeaders } from '~/lib/headers.server'
import { useSearchString } from '~/lib/utils'
import { useFeature, useModStatus, useSubmitterStatus } from '~/root'
import { useModStatus, useSubmitterStatus } from '~/root'
import type { BreadcrumbHandle } from '~/root/Title'

export const handle: BreadcrumbHandle<typeof loader> = {
Expand Down Expand Up @@ -60,10 +60,7 @@ export default function () {
const { circularId, body, bibcode, version, format, ...frontMatter } =
useLoaderData<typeof loader>()
const searchString = useSearchString()
const Body =
useFeature('CIRCULARS_MARKDOWN') && format === 'text/markdown'
? MarkdownBody
: PlainTextBody
const Body = format === 'text/markdown' ? MarkdownBody : PlainTextBody

const result = useRouteLoaderData<typeof parentLoader>(
'routes/circulars.$circularId'
Expand Down
13 changes: 4 additions & 9 deletions app/routes/circulars._archive._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import CircularsIndex from './CircularsIndex'
import { DateSelector } from './DateSelectorMenu'
import { SortSelector } from './SortSelectorButton'
import Hint from '~/components/Hint'
import { feature, origin } from '~/lib/env.server'
import { origin } from '~/lib/env.server'
import { getFormDataString } from '~/lib/utils'
import { postZendeskRequest } from '~/lib/zendesk.server'
import { useModStatus } from '~/root'
Expand Down Expand Up @@ -81,14 +81,9 @@ export async function action({ request }: ActionFunctionArgs) {
const body = getFormDataString(data, 'body')
const subject = getFormDataString(data, 'subject')
const intent = getFormDataString(data, 'intent')
let format
if (feature('CIRCULARS_MARKDOWN')) {
format = getFormDataString(data, 'format') as CircularFormat | undefined
if (format && !circularFormats.includes(format)) {
throw new Response('Invalid format', { status: 400 })
}
} else {
format = undefined
const format = getFormDataString(data, 'format') as CircularFormat | undefined
if (format && !circularFormats.includes(format)) {
throw new Response('Invalid format', { status: 400 })
}
if (!body || !subject)
throw new Response('Body and subject are required', { status: 400 })
Expand Down
72 changes: 13 additions & 59 deletions app/routes/circulars.edit.$circularId/CircularEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,22 @@ import {
InputPrefix,
Table,
TextInput,
Textarea,
} from '@trussworks/react-uswds'
import classnames from 'classnames'
import { type ReactNode, useContext, useState } from 'react'
import { dedent } from 'ts-dedent'

import { AstroDataContext } from '../circulars.$circularId.($version)/AstroDataContext'
import {
MarkdownBody,
PlainTextBody,
} from '../circulars.$circularId.($version)/Body'
import { MarkdownBody } from '../circulars.$circularId.($version)/Body'
import {
type CircularFormat,
bodyIsValid,
subjectIsValid,
} from '../circulars/circulars.lib'
import { RichEditor } from './RichEditor'
import {
SegmentedRadioButton,
SegmentedRadioButtonGroup,
} from './SegmentedRadioButton'
import { CircularsKeywords } from '~/components/CircularsKeywords'
import CollapsableInfo from '~/components/CollapsableInfo'
import Spinner from '~/components/Spinner'
import { useFeature } from '~/root'

function SyntaxExample({
label,
Expand Down Expand Up @@ -140,7 +131,6 @@ export function CircularEditForm({
const [subject, setSubject] = useState(defaultSubject)
const [format, setFormat] = useState(defaultFormat)
const bodyValid = bodyIsValid(body)
const [showPreview, setShowPreview] = useState(false)
const sending = Boolean(useNavigation().formData)
const valid = subjectValid && bodyValid
let headerText, saveButtonText
Expand Down Expand Up @@ -226,54 +216,18 @@ export function CircularEditForm({
<label hidden htmlFor="body">
Body
</label>
{useFeature('CIRCULARS_MARKDOWN') ? (
<RichEditor
aria-describedby="bodyDescription"
placeholder={bodyPlaceholder}
defaultValue={defaultBody}
defaultMarkdown={defaultFormat === 'text/markdown'}
required
className={bodyValid ? 'usa-input--success' : undefined}
onChange={({ target: { value } }) => {
setBody(value)
}}
markdownStateSetter={setFormat}
/>
) : (
<>
<SegmentedRadioButtonGroup>
<SegmentedRadioButton
defaultChecked
onClick={() => setShowPreview(false)}
>
Edit
</SegmentedRadioButton>
<SegmentedRadioButton onClick={() => setShowPreview(true)}>
Preview
</SegmentedRadioButton>
</SegmentedRadioButtonGroup>
<Textarea
hidden={showPreview}
name="body"
id="body"
aria-describedby="bodyDescription"
placeholder={bodyPlaceholder}
defaultValue={defaultBody}
required
className={classnames('maxw-full', {
'usa-input--success': bodyValid,
})}
onChange={({ target: { value } }) => {
setBody(value)
}}
/>
{showPreview && (
<PlainTextBody className="border padding-1 margin-top-1">
{body}
</PlainTextBody>
)}
</>
)}
<RichEditor
aria-describedby="bodyDescription"
placeholder={bodyPlaceholder}
defaultValue={defaultBody}
defaultMarkdown={defaultFormat === 'text/markdown'}
required
className={bodyValid ? 'usa-input--success' : undefined}
onChange={({ target: { value } }) => {
setBody(value)
}}
markdownStateSetter={setFormat}
/>
<CollapsableInfo
id="bodyDescription"
preambleText={
Expand Down
15 changes: 5 additions & 10 deletions app/routes/circulars.moderation.$circularId.$requestor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
moderatorGroup,
} from './circulars/circulars.server'
import { getFormDataString } from '~/lib/utils'
import { useFeature } from '~/root'
import type { BreadcrumbHandle } from '~/root/Title'

export const handle: BreadcrumbHandle<typeof loader> & SEOHandle = {
Expand Down Expand Up @@ -84,15 +83,11 @@ export default function () {
oldString={circular.subject}
newString={correction.subject}
/>
{useFeature('CIRCULARS_MARKDOWN') && (
<>
<h3>Format</h3>
<DiffedContent
oldString={circular.format ?? 'text/plain'}
newString={correction.format ?? 'text/plain'}
/>
</>
)}
<h3>Format</h3>
<DiffedContent
oldString={circular.format ?? 'text/plain'}
newString={correction.format ?? 'text/plain'}
/>
<h3>Body</h3>
<DiffedContent oldString={circular.body} newString={correction.body} />
<Form method="POST">
Expand Down
6 changes: 0 additions & 6 deletions app/routes/docs.circulars.markdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ handle:

import { Table } from '@trussworks/react-uswds'

import { feature } from '~/lib/env.server'
import { SyntaxReference } from '~/routes/circulars.edit.$circularId/CircularEditForm.tsx'

export async function loader() {
if (!feature('CIRCULARS_MARKDOWN')) throw new Response(null, { status: 404 })
return null
}

# Astro Flavored Markdown

Markdown is a lightweight markup language that is used to format text with HTML while still maintaining plaintext readability. It is commonly used in web development and has been implemented by many platforms, including GitHub and Slack. More information on Markdown can be found in the documentation written by the creators of Markdown, John Gruber and Aaron Swartz, at [daringfireball.net](https://daringfireball.net/projects/markdown/).
Expand Down
11 changes: 3 additions & 8 deletions app/routes/docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { Link, NavLink, Outlet } from '@remix-run/react'
import { GridContainer } from '@trussworks/react-uswds'

import { useFeature } from '../root'
import { SideNav, SideNavSub } from '~/components/SideNav'
import type { BreadcrumbHandle } from '~/root/Title'

Expand Down Expand Up @@ -51,13 +50,9 @@ export default function () {
<NavLink key="styleguide" to="circulars/styleguide">
Style Guide
</NavLink>,
<>
{useFeature('CIRCULARS_MARKDOWN') && (
<NavLink key="markdown" to="circulars/markdown">
Markdown
</NavLink>
)}
</>,
<NavLink key="markdown" to="circulars/markdown">
Markdown
</NavLink>,
]}
/>
</>,
Expand Down

0 comments on commit 54496af

Please sign in to comment.