forked from nasa-gcn/gcn.nasa.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/nasa-gcn/gcn.nasa.gov into …
…across-api-add-fov
- Loading branch information
Showing
6 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/routes/_gcn.circulars.edit.$circularId/RichEditor/onKeyDown.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters