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

3407 - FRA Reports - submission history #3460

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
29ffa76
paginator HOCs
jtimpe Feb 3, 2025
1e7f529
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 7, 2025
a3752f3
implement submission history api
jtimpe Feb 7, 2025
82d0274
use paginator HOC over context
jtimpe Feb 7, 2025
a2c3994
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 7, 2025
6634d61
fix file input preview
jtimpe Feb 7, 2025
3a4682a
fix tests
jtimpe Feb 8, 2025
22d5655
add tests
jtimpe Feb 10, 2025
eb3427f
rm blank
jtimpe Feb 10, 2025
0385f37
dispatch get after upload
jtimpe Feb 10, 2025
2a65fa9
add file download
jtimpe Feb 10, 2025
1dee1fc
change var name
jtimpe Feb 10, 2025
6040750
datetimes not test-friendly
jtimpe Feb 10, 2025
9379258
unused vars
jtimpe Feb 10, 2025
34a955b
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 11, 2025
a566f99
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 11, 2025
4f1af46
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 11, 2025
0a316c1
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 12, 2025
6df195d
tests
jtimpe Feb 12, 2025
5fc50ef
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 12, 2025
4370b42
fix tests
jtimpe Feb 12, 2025
d616e3a
condense column
jtimpe Feb 12, 2025
d760ebf
fix download
jtimpe Feb 13, 2025
b9941da
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 13, 2025
7d488b8
fix label
jtimpe Feb 14, 2025
bc33448
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 14, 2025
897e981
add about/template links
jtimpe Feb 14, 2025
20c7f34
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 18, 2025
788e31a
add page subtitle
jtimpe Feb 18, 2025
fb71be0
update explainer table language
jtimpe Feb 18, 2025
3661c37
tests
jtimpe Feb 18, 2025
8f78d5e
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 18, 2025
bf4ec6b
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 18, 2025
9c80f0f
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 19, 2025
08ba02c
fix tests
jtimpe Feb 19, 2025
0f95b01
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 21, 2025
14a15a0
hide download button on upload input error
jtimpe Feb 25, 2025
a374b53
download should preserve original file name
jtimpe Feb 25, 2025
6674e7d
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 25, 2025
dc7012b
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 25, 2025
f990af4
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 26, 2025
f5a0662
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 28, 2025
33c4977
Merge branch '3398-fra-frontend' into 3407-fra-submission-history
jtimpe Feb 28, 2025
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
18 changes: 9 additions & 9 deletions tdrs-frontend/src/actions/fraReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ export const uploadFraReport =
}
)

// dispatch(
// getFraSubmissionHistory({
// stt,
// reportType,
// fiscalQuarter,
// fiscalYear,
// })
// )
// or, dispatch the state update if response from upload can contain updated submission history
dispatch(
getFraSubmissionHistory({
stt,
reportType,
fiscalQuarter,
fiscalYear,
})
)

onSuccess()
} catch (error) {
onError(error)
Expand Down
29 changes: 28 additions & 1 deletion tdrs-frontend/src/components/Paginator/Paginator.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
Expand Down Expand Up @@ -101,3 +101,30 @@ Paginator.propTypes = {
}

export default Paginator

const PaginatedComponent = ({ pageSize, data, children }) => {
const [pageNumber, setPageNumber] = useState(1)

const numPages =
data && data.length > pageSize ? Math.ceil(data.length / pageSize) : 1
const pageStart = (pageNumber - 1) * pageSize
const pageEnd =
data && data.length ? Math.min(data.length, pageStart + pageSize) : 1

const slicedData = data && data.length ? data.slice(pageStart, pageEnd) : null

return (
<>
{React.cloneElement(children, { data: slicedData })}
{numPages > 1 && (
<Paginator
onChange={(page) => setPageNumber(page)}
selected={pageNumber}
pages={numPages}
/>
)}
</>
)
}

export { PaginatedComponent }
96 changes: 87 additions & 9 deletions tdrs-frontend/src/components/Reports/FRAReports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ import { accountCanSelectStt } from '../../selectors/auth'
import { handlePreview, tryGetUTF8EncodedFile } from '../FileUpload/utils'
Copy link

Choose a reason for hiding this comment

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

I also noticed if I upload a file, and then select a new file to upload, the download button for the original file upload remains available.

Screenshot 2025-02-21 at 12 14 00 PM

Copy link

Choose a reason for hiding this comment

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

Another interesting visual bug. Upload and submit a file, click to change the file, cancel the file selector modal, see that the original file and download button are still there. This is different behavior than the data files page.

Copy link

Choose a reason for hiding this comment

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

I was also able to get the file input element to collapse like the datafiles one. The PR that fixed the issue for the datafiles page merged so you should be able to use the same logic. Note I had to actually expose functions to handle that, it wasn't the removal of our custom css classes completely causing the issue.

Screenshot 2025-02-21 at 12 19 40 PM

Copy link
Author

Choose a reason for hiding this comment

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

good callouts, thank you! i will take a look

Copy link
Author

Choose a reason for hiding this comment

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

I was only able to address your first comment here - hiding the download button when there's a previous upload and an error.

For the second and third comments, i did not experience the same behavior locally. The FRA and DF pages appear to work the same with respect to the original file/download button, and i actually have the input collapse every time i select a file when trying to implement the remove preview logic from the other PR. happy to pair and try to work through it if you're still having issues

Copy link

Choose a reason for hiding this comment

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

Everything looks good on this. I also could not reproduce the second bug I called out. As for the file collapse, Im going to write up a bug ticket for it. The preview logic is a little different than the datafiles page and can't use the exact same solution to prevent the input collapse.

import createFileInputErrorState from '../../utils/createFileInputErrorState'
import Modal from '../Modal'
import {
formatDate,
SubmissionSummaryStatusIcon,
getErrorReportStatus,
} from '../SubmissionHistory/helpers'

import {
getFraSubmissionHistory,
uploadFraReport,
} from '../../actions/fraReports'
import { fetchSttList } from '../../actions/sttList'
import { DropdownSelect, RadioSelect } from '../Form'
import { PaginatedComponent } from '../Paginator/Paginator'
import { download } from '../../actions/reports'

const INVALID_FILE_ERROR =
'We can’t process that file format. Please provide a plain text file.'
Expand Down Expand Up @@ -238,8 +245,8 @@ const UploadForm = ({

useEffect(() => {
const trySettingPreview = () => {
const targetClassName = 'usa-file-input__preview input #fra-file-upload'
const previewState = handlePreview(file?.name, targetClassName)
const targetClassName = '.usa-file-input__target input#fra-file-upload'
const previewState = handlePreview(file?.fileName, targetClassName)
if (!previewState) {
setTimeout(trySettingPreview, 100)
}
Expand Down Expand Up @@ -391,7 +398,55 @@ const UploadForm = ({
)
}

const SubmissionHistory = () => <></>
const SubmissionHistory = ({ data, sectionName, handleDownloadFile }) => (
<table className="usa-table usa-table--striped">
<caption>{sectionName}</caption>
{data && data.length > 0 ? (
<>
<thead>
<tr>
<th>Submitted On</th>
<th>Submitted By</th>
<th>File Name</th>
<th>Total Errors</th>
<th>Status</th>
<th>Error Report</th>
</tr>
</thead>
<tbody>
{data.map((file) => (
<tr>
<td>{formatDate(file.createdAt)}</td>
<td>{file.submittedBy}</td>
<td>
<button
className="section-download"
onClick={() => handleDownloadFile(file)}
>
{file.fileName}
</button>
</td>
<td>{file?.summary?.case_aggregates?.total_errors}</td>
<td>
<span>
<SubmissionSummaryStatusIcon
status={file.summary ? file.summary.status : 'Pending'}
/>
</span>
{file.summary && file.summary.status
? file.summary.status
: 'Pending'}
</td>
<td>{getErrorReportStatus(file)}</td>
</tr>
))}
</tbody>
</>
) : (
<span>No data available.</span>
)}
</table>
)

const FRAReports = () => {
const [isUploadReportToggled, setUploadReportToggled] = useState(false)
Expand Down Expand Up @@ -428,9 +483,16 @@ const FRAReports = () => {
},
})

const [selectedFile, setSelectedFile] = useState(null)
const fraSubmissionHistory = useSelector(
(state) => state.fraReports.submissionHistory
)

const latestSubmission =
fraSubmissionHistory && fraSubmissionHistory.length > 0
? fraSubmissionHistory[0]
: null

// const fraSubmissionHistory = useSelector((state) => state.fraReports)
const [selectedFile, setSelectedFile] = useState(latestSubmission)

const dispatch = useDispatch()

Expand Down Expand Up @@ -543,7 +605,7 @@ const FRAReports = () => {

const handleUpload = ({ file: selectedFile }) => {
const onFileUploadSuccess = () => {
setSelectedFile(null) // once we have the latest file in submission history, conditional setting of state in constructor should be sufficient
setSelectedFile(null)
setLocalAlertState({
active: true,
type: 'success',
Expand Down Expand Up @@ -573,6 +635,10 @@ const FRAReports = () => {
)
}

const handleDownloadFile = (file) => {
dispatch(download(file))
}

const getReportTypeLabel = () => {
if (isUploadReportToggled) {
const { reportType } = searchFormValues
Expand All @@ -595,7 +661,7 @@ const FRAReports = () => {
}

useEffect(() => {
if (sttList.length === 0) {
if (sttList && sttList.length === 0) {
dispatch(fetchSttList())
}
}, [dispatch, sttList])
Expand Down Expand Up @@ -648,13 +714,25 @@ const FRAReports = () => {
setUploadReportToggled(false)
}}
setLocalAlertState={setLocalAlertState}
file={selectedFile}
file={selectedFile ? selectedFile : latestSubmission}
setSelectedFile={setSelectedFile}
section={getReportTypeLabel()}
error={uploadError}
setError={setUploadError}
/>
<SubmissionHistory />

<div
className="submission-history-section usa-table-container--scrollable"
style={{ maxWidth: '100%' }}
tabIndex={0}
>
<PaginatedComponent pageSize={5} data={fraSubmissionHistory}>
<SubmissionHistory
sectionName={getReportTypeLabel()}
handleDownloadFile={handleDownloadFile}
/>
</PaginatedComponent>
</div>
</>
)}

Expand Down
Loading