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

Implement Circular Archive date range search frontend with new DateSelectorButton #1482

Merged
merged 58 commits into from
Oct 17, 2023
Merged
Changes from 10 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d322008
added date range selector dropdown content from nasa-gcn:#1265 . This…
tylerbarna Oct 5, 2023
5ed8033
Update app/routes/circulars._archive._index.tsx
tylerbarna Oct 6, 2023
8a26a4e
radios use self-closing syntax
tylerbarna Oct 6, 2023
2a33362
Merge branch 'circulars-date-search-frontend' of https://github.com/t…
tylerbarna Oct 6, 2023
498830e
fixed z-index
tylerbarna Oct 9, 2023
aa2cff1
Update app/routes/circulars._archive._index.tsx
tylerbarna Oct 9, 2023
8eb1668
fix undefined label
tylerbarna Oct 9, 2023
347d9d8
addressed various comments
tylerbarna Oct 10, 2023
75e4340
fixed radio button selection on submission
tylerbarna Oct 10, 2023
1c31122
fixed check condition to handle custom range
tylerbarna Oct 10, 2023
6e9e986
Add API for third parties to post GCN Circulars on behalf of users
lpsinger Sep 28, 2023
8050221
Refactor root meta function as meta tags
lpsinger Oct 6, 2023
94dcd42
Clean up URL routing for schema browser
lpsinger Oct 5, 2023
0e85a61
Rewrite schema browser docs in Markdown, make some minor edits
lpsinger Oct 6, 2023
90daebb
Fix visual artifact due to doubled breadcrumb
lpsinger Oct 6, 2023
9663783
Remove unnecessary spread syntax
lpsinger Oct 6, 2023
fa6e3b5
Make breadcrumb bar appearance more consistent across screen sizes
lpsinger Oct 6, 2023
ebdbca1
Remove schema feature flag
lpsinger Oct 6, 2023
6b5bf2c
Add page titles to schema browser
lpsinger Oct 6, 2023
93519b1
fixed schema browser link
jracusin Oct 6, 2023
19d92e6
Add FIXME comment
lpsinger Oct 8, 2023
b134fa5
Bump @trussworks/react-uswds from 5.1.1 to 5.4.0
dependabot[bot] Oct 6, 2023
502e51e
Bump @opensearch-project/opensearch from 2.2.1 to 2.4.0
dependabot[bot] Oct 9, 2023
f5104db
ignoring .DS_Store
Courey Oct 9, 2023
481c696
Bump openid-client from 5.4.3 to 5.6.0
dependabot[bot] Oct 9, 2023
3222dfe
Bump eslint from 8.50.0 to 8.51.0
dependabot[bot] Oct 9, 2023
e180d51
Colocate NoticeTypeCheckboxes with its data
lpsinger Oct 6, 2023
d43032f
Fix version selector toggle
lpsinger Oct 10, 2023
2cecc52
Adjust handling of DetailsDropdownContent props
lpsinger Oct 10, 2023
0a9e1e0
Bump @nasa-gcn/remark-rehype-astro from 1.0.0 to 1.1.0
dependabot[bot] Oct 11, 2023
6e42b03
Bump openid-client from 5.6.0 to 5.6.1
dependabot[bot] Oct 11, 2023
06f2d66
Remove unnecessary fragment
lpsinger Oct 10, 2023
275071a
Remove unnecessary reexport
lpsinger Oct 10, 2023
60c7902
Create hyperlinks for TNS transients in Circulars
lpsinger Oct 11, 2023
2e1e70c
enclosed content in CardBody
tylerbarna Oct 11, 2023
53a30ab
use cardfooter
tylerbarna Oct 11, 2023
8c3016d
switch to Grid usage
tylerbarna Oct 11, 2023
4a98c1c
reduce code redundancy for radio buttons
tylerbarna Oct 11, 2023
b479e2d
Merge pull request #6 from nasa-gcn/main
tylerbarna Oct 11, 2023
d91d10b
remove final merge issue
tylerbarna Oct 11, 2023
60733c6
reduced radioOptions overhead
tylerbarna Oct 11, 2023
88b8669
removed radioOptions constant
tylerbarna Oct 11, 2023
3d2faec
set defaultChecked
tylerbarna Oct 11, 2023
3c05f3c
combined map calls into one
tylerbarna Oct 12, 2023
f159a4e
remove alltime from dateSelectorLabels
tylerbarna Oct 12, 2023
a00c562
removed custom date from dateSelectorLabels
tylerbarna Oct 13, 2023
b3c2fa6
fix fuzzy date to custom date switch
tylerbarna Oct 13, 2023
e097606
removed commented out code
tylerbarna Oct 13, 2023
547b93e
switch method of setting date range
tylerbarna Oct 13, 2023
135c403
revert set date range method
tylerbarna Oct 16, 2023
6e4e0e2
resolve merge issues
tylerbarna Oct 16, 2023
b9459fd
remove vestigial file
tylerbarna Oct 16, 2023
5ebdd15
restored button group z-order
tylerbarna Oct 16, 2023
b7161e7
Update app/routes/circulars._archive._index/route.tsx
tylerbarna Oct 17, 2023
9530b10
Update app/routes/circulars._archive._index/route.tsx
tylerbarna Oct 17, 2023
28551c7
Update app/routes/circulars._archive._index/route.tsx
tylerbarna Oct 17, 2023
c248cba
reuse searchParams
tylerbarna Oct 17, 2023
c9266c7
remove conditional from setFuzzyTime
tylerbarna Oct 17, 2023
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
202 changes: 198 additions & 4 deletions app/routes/circulars._archive._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import {
import {
Button,
ButtonGroup,
DateRangePicker,
Icon,
Label,
Radio,
Select,
TextInput,
} from '@trussworks/react-uswds'
import classNames from 'classnames'
import clamp from 'lodash/clamp'
import { useState } from 'react'
import { useEffect, useState } from 'react'

import { circularRedirect, search } from './circulars/circulars.server'
import type { action } from './circulars/route'
import DetailsDropdownContent from '~/components/DetailsDropdownContent'
import Hint from '~/components/Hint'
import { usePagination } from '~/lib/pagination'
import { useFeature } from '~/root'
Expand Down Expand Up @@ -184,6 +187,7 @@ const dateSelectorLabels: Record<string, string> = {
today: 'Today',
mtd: 'Month to date',
ytd: 'Year to date',
undefined: 'All time',
}

function DateSelectorButton({
Expand Down Expand Up @@ -239,10 +243,55 @@ export default function () {
if (searchString) searchString = `?${searchString}`

const [inputQuery, setInputQuery] = useState(query)
const clean = inputQuery === query
const [inputDateGte, setInputDateGte] = useState(startDate)
const [inputDateLte, setInputDateLte] = useState(endDate)
const [showContent, setShowContent] = useState(false)
const [showDateRange, setShowDateRange] = useState(false)
const clean =
inputQuery === query &&
inputDateGte === startDate &&
inputDateLte === endDate

const submit = useSubmit()

const setFuzzyTime = (startDate?: string) => {
if (startDate === 'custom') {
setShowDateRange(true)
} else {
setShowDateRange(false)
setInputDateGte(startDate)
}
setInputDateLte('now')
}

const setDateRange = () => {
setShowContent(false)
const params = new URLSearchParams(location.search)
if (inputDateGte) params.set('startDate', inputDateGte)
if (inputDateLte) params.set('endDate', inputDateLte)
submit(params, {
method: 'get',
action: '/circulars',
})
}

useEffect(() => {
const radiobuttons = document.querySelectorAll('input[name="radio-date"]')
let radioSelected = false
radiobuttons.forEach((button) => {
if ((button as HTMLInputElement).value === inputDateGte) {
;(button as HTMLInputElement).checked = true
radioSelected = true
}
})
if (!radioSelected) {
const customButton = document.getElementById('radio-custom')
if (customButton) {
;(customButton as HTMLInputElement).checked = true
} // does not address the need for the custom date range button to be expanded if this button is checked
}
})
tylerbarna marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<h1>GCN Circulars</h1>
Expand All @@ -260,7 +309,7 @@ export default function () {
</Link>{' '}
for help with subscribing to or submitting Circulars.
</p>
<ButtonGroup className="position-sticky top-0 bg-white margin-bottom-1 padding-top-1">
<ButtonGroup className="position-sticky top-0 bg-white margin-bottom-1 padding-top-1 z-top">
<Form
className="display-inline-block usa-search usa-search--small"
role="search"
Expand Down Expand Up @@ -291,7 +340,152 @@ export default function () {
</Button>
</Form>
{featureCircularsFilterByDate && (
<DateSelectorButton startDate={startDate} endDate={endDate} />
<>
<DateSelectorButton
startDate={startDate}
endDate={endDate}
onClick={() => {
setShowContent((shown) => !shown)
setShowDateRange(false)
}}
expanded={showContent}
/>
{showContent && (
<DetailsDropdownContent className="margin-top-1">
<div className="maxw-card-xlg">
tylerbarna marked this conversation as resolved.
Show resolved Hide resolved
<div className="display-flex flex-row">
<div className="display-flex flex-column flex-align-start margin-1">
<Radio
id="radio-alltime"
name="radio-date"
value="undefined"
defaultChecked={true}
label="All Time"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
<Radio
id="radio-hour"
name="radio-date"
value="hour"
label="Last hour"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
<Radio
id="radio-today"
name="radio-date"
value="today"
label="Today"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
tylerbarna marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div className="display-flex flex-column margin-1">
lpsinger marked this conversation as resolved.
Show resolved Hide resolved
<Radio
id="radio-day"
name="radio-date"
value="day"
label="Last 24 Hours"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
<Radio
id="radio-week"
name="radio-date"
value="week"
label="Last Week"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
<Radio
id="radio-month"
name="radio-date"
value="month"
label="Last Month"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
</div>

<div className="display-flex flex-column margin-1">
<Radio
id="radio-year"
name="radio-date"
value="year"
label="Last Year"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
<Radio
id="radio-ytd"
name="radio-date"
value="ytd"
label="Year to Date"
onChange={(e) => {
setFuzzyTime(e.target.value)
}}
/>
<Radio
id="radio-custom"
name="radio-date"
value="custom"
label="Custom Range..."
onChange={(e) => {
setShowDateRange(e.target.checked)
}}
/>
</div>
</div>

{showDateRange && (
<DateRangePicker
startDateHint="dd/mm/yyyy"
startDateLabel="Start Date"
className="margin-bottom-2"
startDatePickerProps={{
id: 'event-date-start',
name: 'event-date-start',
defaultValue: 'startDate',
onChange: (value) => {
setInputDateGte(value)
},
}}
endDateHint="dd/mm/yyyy"
endDateLabel="End Date"
endDatePickerProps={{
id: 'event-date-end',
name: 'event-date-end',
defaultValue: 'endDate',
onChange: (value) => {
setInputDateLte(value)
},
}}
/>
)}
<div className="display-flex flex-row">
<Button
type="button"
className=""
tylerbarna marked this conversation as resolved.
Show resolved Hide resolved
form="searchForm"
onClick={() => {
setDateRange()
}}
>
<Icon.CalendarToday /> Submit
</Button>
</div>
</div>
tylerbarna marked this conversation as resolved.
Show resolved Hide resolved
</DetailsDropdownContent>
)}
</>
)}
<Link to={`/circulars/new${searchString}`}>
<Button
Expand Down