Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circulars Archive Group View #2617

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions __tests__/synonyms.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*!
* 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 { AWSError, DynamoDB } from 'aws-sdk'
import * as awsSDKMock from 'aws-sdk-mock'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const AstroDataContext = createContext<AstroDataContextProps>({})
/**
* An Astro Flavored Markdown enriched link.
*/
// eslint-disable-next-line react/display-name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this addition necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I moved the component into the components directory, it is judged as a component definition and causes this warning:
Screenshot 2024-10-22 at 1 58 18 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to make the move have no changes to the code if possible

export const AstroDataLink = forwardRef(
(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { Grid } from '@trussworks/react-uswds'
import type { ReactNode } from 'react'

import { type Circular, formatDateISO } from '../circulars/circulars.lib'
import TimeAgo from '~/components/TimeAgo'
import { type Circular, formatDateISO } from '~/routes/circulars/circulars.lib'

Check warning on line 12 in app/components/circularDisplay/FrontMatter.tsx

View check run for this annotation

Codecov / codecov/patch

app/components/circularDisplay/FrontMatter.tsx#L12

Added line #L12 was not covered by tests

const submittedHowMap = {
web: 'Web form',
Expand Down
11 changes: 10 additions & 1 deletion app/components/pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ function getPageLink({
query,
startDate,
endDate,
view,
}: {
page: number
limit?: number
query?: string
startDate?: string
endDate?: string
view?: string
}) {
const searchParams = new URLSearchParams()
if (page > 1) searchParams.set('page', page.toString())
if (limit && limit != 100) searchParams.set('limit', limit.toString())
if (limit) searchParams.set('limit', limit.toString())
if (query) searchParams.set('query', query)
if (startDate) searchParams.set('startDate', startDate)
if (endDate) searchParams.set('endDate', endDate)
searchParams.set('view', view || 'index')

const searchString = searchParams.toString()
return searchString && `?${searchString}`
Expand All @@ -38,6 +41,7 @@ function getPageLink({
export default function Pagination({
page,
totalPages,
view,
...queryStringProps
}: {
page: number
Expand All @@ -46,8 +50,10 @@ export default function Pagination({
query?: string
startDate?: string
endDate?: string
view?: string
}) {
const pages = usePagination({ currentPage: page, totalPages })

return (
<nav aria-label="Pagination" className="usa-pagination">
<ul className="usa-pagination__list">
Expand All @@ -63,6 +69,7 @@ export default function Pagination({
<Link
to={getPageLink({
page: pageProps.number,
view,
...queryStringProps,
})}
className="usa-pagination__link usa-pagination__previous-page"
Expand Down Expand Up @@ -102,6 +109,7 @@ export default function Pagination({
<Link
to={getPageLink({
page: pageProps.number,
view,
...queryStringProps,
})}
className="usa-pagination__link usa-pagination__next-page"
Expand All @@ -124,6 +132,7 @@ export default function Pagination({
<Link
to={getPageLink({
page: pageProps.number,
view,
...queryStringProps,
})}
className={classNames('usa-pagination__button', {
Expand Down
7 changes: 6 additions & 1 deletion app/components/pagination/PaginationSelectionFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ export default function PaginationSelectionFooter({
limit,
query,
form,
view,
}: {
page: number
totalPages: number
limit?: number
query?: string
form: string
view?: string
}) {
const submit = useSubmit()

return (
<div className="display-flex flex-row flex-wrap">
<div className="display-flex flex-align-self-center margin-right-2 width-auto">
<div>
<input type="hidden" form={form} name="view" id="view" value={view} />
<Select
id="limit"
title="Number of results per page"
className="width-auto height-5 padding-y-0 margin-y-0"
name="limit"
defaultValue="100"
value={limit}
form={form}
onChange={({ target: { form } }) => {
submit(form)
Expand All @@ -53,6 +57,7 @@ export default function PaginationSelectionFooter({
page={page}
limit={limit}
totalPages={totalPages}
view={view}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the Pagination component need to know about the view?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because in getPageLink if the view is not set as a search param, then when it creates the link, it doesn't include view. If it doesn't include view, then the view defaults to index. If it's always index, then the pagination links will never work for groups. To show you what I mean, here is what happens when I remove the view from getPageLinks. When I hover over the 2 button, this is the link. You will see that it doesn't include the view so when that page is navigated to, it's the index view which is the default.
pagination_view

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see.

The last time that I looked at this component, I noticed that a lot of apparently separate concerns were leaking into it from pages that use it. At some point, I'd like to come back to this and try to refactor it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea. It did feel odd to have to add view specific code to it.

/>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/routes/circulars.$circularId.($version)/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import type { loader as parentLoader } from '../circulars.$circularId/route'
import { get } from '../circulars/circulars.server'
import { MarkdownBody, PlainTextBody } from './Body'
import { FrontMatter } from './FrontMatter'
import DetailsDropdownButton from '~/components/DetailsDropdownButton'
import DetailsDropdownContent from '~/components/DetailsDropdownContent'
import { ToolbarButtonGroup } from '~/components/ToolbarButtonGroup'
import { MarkdownBody, PlainTextBody } from '~/components/circularDisplay/Body'
import { FrontMatter } from '~/components/circularDisplay/FrontMatter'

Check warning on line 22 in app/routes/circulars.$circularId.($version)/route.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars.$circularId.($version)/route.tsx#L21-L22

Added lines #L21 - L22 were not covered by tests
import { origin } from '~/lib/env.server'
import { getCanonicalUrlHeaders, pickHeaders } from '~/lib/headers.server'
import { useSearchString } from '~/lib/utils'
Expand Down
53 changes: 53 additions & 0 deletions app/routes/circulars._archive._index/SynonymGroupIndex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*!
* 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 { Link } from '@remix-run/react'

Check warning on line 8 in app/routes/circulars._archive._index/SynonymGroupIndex.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars._archive._index/SynonymGroupIndex.tsx#L8

Added line #L8 was not covered by tests

import type { SynonymGroupWithMembers } from '../synonyms/synonyms.lib'

export default function ({

Check warning on line 12 in app/routes/circulars._archive._index/SynonymGroupIndex.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars._archive._index/SynonymGroupIndex.tsx#L12

Added line #L12 was not covered by tests
allItems,
totalItems,
searchString,
query,
}: {
allItems: SynonymGroupWithMembers[]
totalItems: number
searchString: string
query?: string
}) {
return (

Check warning on line 23 in app/routes/circulars._archive._index/SynonymGroupIndex.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars._archive._index/SynonymGroupIndex.tsx#L23

Added line #L23 was not covered by tests
<>
{query && (
<h3>
{totalItems} result{totalItems != 1 && 's'} found.
</h3>
)}

{allItems.map(({ group, members }) => (
<div key={group.synonymId}>

Check warning on line 32 in app/routes/circulars._archive._index/SynonymGroupIndex.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars._archive._index/SynonymGroupIndex.tsx#L31-L32

Added lines #L31 - L32 were not covered by tests
<details>
<summary>
<Link to={`/circulars/group/${group.synonymId}${searchString}`}>
{group.eventIds.join(', ')}
</Link>
</summary>
<ol className="margin-left-3">
{members.map(({ circularId, subject }) => {
return (

Check warning on line 41 in app/routes/circulars._archive._index/SynonymGroupIndex.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/circulars._archive._index/SynonymGroupIndex.tsx#L40-L41

Added lines #L40 - L41 were not covered by tests
<li key={circularId} value={circularId}>
<Link to={`/circulars/${circularId}`}>{subject}</Link>
</li>
)
})}
</ol>
</details>
</div>
))}
</>
)
}
Loading
Loading