Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nasa-gcn/gcn.nasa.gov into …
Browse files Browse the repository at this point in the history
…across-api-add-fov
  • Loading branch information
swyatt7 committed Feb 22, 2024
2 parents f4a9b3d + d02ba66 commit 8b66004
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
border-left: 1px solid darkslategray;
border-right: 1px solid darkslategray;
border-bottom: 1px solid darkslategray;

& :first-child {
padding-top: 0;
margin-top: 0;
}
}

textarea {
Expand Down
18 changes: 8 additions & 10 deletions app/routes/_gcn.circulars.edit.$circularId/RichEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import {
} from '../../_gcn.circulars.$circularId.($version)/Body'
import { GitLabIcon } from './GitLabIcon'
import { Tab, TabBar } from './Tabs'
import { onKeyDown } from './onKeyDown'

import styles from './index.module.css'
import iconBold from '@gitlab/svgs/dist/sprite_icons/bold.svg'
import iconCode from '@gitlab/svgs/dist/sprite_icons/code.svg'
import iconText from '@gitlab/svgs/dist/sprite_icons/doc-text.svg'
import iconEllipsis from '@gitlab/svgs/dist/sprite_icons/ellipsis_h.svg'
import iconHeading from '@gitlab/svgs/dist/sprite_icons/heading.svg'
import iconItalic from '@gitlab/svgs/dist/sprite_icons/italic.svg'
Expand Down Expand Up @@ -57,7 +59,8 @@ function PlainTextButton({
>) {
return (
<SlimButton outline={!checked} type="button" {...props}>
Plain Text
<GitLabIcon src={iconText} className="width-2 height-2" />
<span className="display-none tablet-lg:display-inline"> Plain Text</span>
</SlimButton>
)
}
Expand Down Expand Up @@ -105,12 +108,12 @@ function StyleButton({
)
}

function insertText(text: string) {
export function insertText(text: string) {
if (text.length > 0) document.execCommand('insertText', false, text)
else document.execCommand('delete', false)
}

const linesep = '\n'
export const linesep = '\n'

export function RichEditor({
className,
Expand Down Expand Up @@ -370,19 +373,13 @@ export function RichEditor({
name="format"
value={markdown ? 'text/markdown' : 'text/plain'}
/>
<ButtonGroup
type="segmented"
className="display-none desktop:display-flex"
>
<ButtonGroup type="segmented">
<PlainTextButton
{...toggleMarkdownButtonProps}
checked={!markdown}
/>
<MarkdownButton {...toggleMarkdownButtonProps} checked={markdown} />
</ButtonGroup>
<ButtonGroup className="display-inline-block desktop:display-none">
<MarkdownButton {...toggleMarkdownButtonProps} checked={markdown} />
</ButtonGroup>
</Grid>
{editing && (
<Grid
Expand Down Expand Up @@ -436,6 +433,7 @@ export function RichEditor({
setValue(e.target.value)
onChange?.(e)
}}
onKeyDown={onKeyDown}
{...props}
/>
</div>
Expand Down
56 changes: 56 additions & 0 deletions app/routes/_gcn.circulars.edit.$circularId/RichEditor/onKeyDown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*!
* Copyright © 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import { type KeyboardEvent } from 'react'

import { insertText, linesep } from '.'

function identity([fullMatch]: RegExpMatchArray) {
return fullMatch
}

const matchers: {
regexp: RegExp
next: (match: RegExpMatchArray) => string
}[] = [
{ regexp: /^\s*[-*>]?\s+/, next: identity },
{
regexp: /^(\s*)(\d+)(\.\s+)/,
next: ([, prefix, num, suffix]) => `${prefix}${parseInt(num) + 1}${suffix}`,
},
]

/**
* Automatically continue unordered lists (-, *), ordered lists (1., 2., ...),
* indented whitespace, and quotations (>) on pressing Enter.
*/
export function onKeyDown(e: KeyboardEvent<HTMLTextAreaElement>) {
if (e.key === 'Enter') {
const { value, selectionStart } = e.currentTarget
let startOfLine = value.lastIndexOf(
linesep,
selectionStart - linesep.length
)
if (startOfLine < 0) {
startOfLine = 0
} else {
startOfLine += linesep.length
if (startOfLine > selectionStart) {
startOfLine = selectionStart
}
}
const line = value.substring(startOfLine, selectionStart)
for (const { regexp, next } of matchers) {
const match = line.match(regexp)
if (match) {
insertText(`${linesep}${next(match)}`)
e.preventDefault()
break
}
}
}
}
42 changes: 42 additions & 0 deletions app/routes/_gcn.synonyms/synonyms.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*!
* Copyright © 2023 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
import { tables } from '@architect/functions'
import type { DynamoDBDocument } from '@aws-sdk/lib-dynamodb/dist-types/DynamoDBDocument'
import crypto from 'crypto'

/*
* If an eventId already has a synonym and is passed in, it will unlink the
* eventId from the old synonym and the only remaining link will be to the
* new synonym.
*
* BatchWriteItem has a limit of 25 items, so the user may not add more than
* 25 synonyms at a time.
*/
export async function createSynonyms(...synonymousEventIds: string[]) {
const uuid = crypto.randomUUID()
const db = await tables()
const client = db._doc as unknown as DynamoDBDocument

const writeRequests = synonymousEventIds
.filter((eventId) => Boolean(eventId))
.map((eventId) => ({
PutRequest: {
Item: { uuid, eventId },
},
}))

const params = {
RequestItems: {
synonyms: writeRequests,
},
}

await client.batchWrite(params)

return uuid
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@architect/functions": "^5.3.4",
"@nasa-gcn/architect-functions-search": "^1.0.0",
"@nasa-gcn/dynamodb-autoincrement": "^2.2.0",
"@nasa-gcn/remark-rehype-astro": "^1.1.0",
"@nasa-gcn/remark-rehype-astro": "^1.1.1",
"@nasa-gcn/remix-seo": "^2.0.0",
"@octokit/request-error": "^5.0.1",
"@octokit/rest": "^20.0.2",
Expand Down

0 comments on commit 8b66004

Please sign in to comment.