-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from adhocteam/js-247-topic-resource-review-p…
…age-download Refactor activity report review pages
- Loading branch information
Showing
24 changed files
with
461 additions
and
200 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,9 @@ body { | |
} | ||
|
||
@media print { | ||
.smart-hub-header { | ||
position: relative; | ||
} | ||
|
||
* { | ||
color: #000 !important; | ||
|
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
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
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,46 @@ | ||
import join from 'url-join'; | ||
import fetchMock from 'fetch-mock'; | ||
|
||
import { | ||
submitReport, saveReport, reviewReport, resetToDraft, | ||
} from '../activityReports'; | ||
|
||
describe('activityReports fetcher', () => { | ||
afterEach(() => fetchMock.restore()); | ||
|
||
describe('submitReport', () => { | ||
it('returns the report', async () => { | ||
const report = { id: 1 }; | ||
fetchMock.post(join('api', 'activity-reports', '1', 'submit'), report); | ||
const savedReport = await submitReport(1, report); | ||
expect(savedReport).toEqual(report); | ||
}); | ||
}); | ||
|
||
describe('saveReport', () => { | ||
it('returns the report', async () => { | ||
const report = { id: 1 }; | ||
fetchMock.put(join('api', 'activity-reports', '1'), report); | ||
const savedReport = await saveReport(1, report); | ||
expect(savedReport).toEqual(report); | ||
}); | ||
}); | ||
|
||
describe('resetToDraft', () => { | ||
it('calls reset and returns the result', async () => { | ||
const report = { id: 1 }; | ||
fetchMock.put(join('api', 'activity-reports', '1', 'reset'), report); | ||
const savedReport = await resetToDraft(1); | ||
expect(savedReport).toEqual(report); | ||
}); | ||
}); | ||
|
||
describe('reviewReport', () => { | ||
it('returns the report', async () => { | ||
const report = { id: 1 }; | ||
fetchMock.put(join('api', 'activity-reports', '1', 'review'), report); | ||
const savedReport = await reviewReport(1, report); | ||
expect(savedReport).toEqual(report); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
frontend/src/pages/ActivityReport/Pages/Review/FileReviewItem.js
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,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Grid } from '@trussworks/react-uswds'; | ||
|
||
const APPROVED = 'APPROVED'; | ||
|
||
const FileReviewItem = ({ filename, url, status }) => { | ||
const approved = status === APPROVED; | ||
return ( | ||
<Grid row className="margin-top-1 "> | ||
<Grid col={6}> | ||
{filename} | ||
</Grid> | ||
<Grid col={6}> | ||
<div className="flex-align-end display-flex flex-column no-print"> | ||
{approved | ||
&& <a href={url}>Download</a>} | ||
{!approved | ||
&& <div>Not Approved</div>} | ||
</div> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; | ||
|
||
FileReviewItem.propTypes = { | ||
filename: PropTypes.string.isRequired, | ||
status: PropTypes.string.isRequired, | ||
url: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default FileReviewItem; |
48 changes: 48 additions & 0 deletions
48
frontend/src/pages/ActivityReport/Pages/Review/ReviewItem.js
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,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'lodash'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
const ReviewItem = ({ label, name, path }) => { | ||
const { watch } = useFormContext(); | ||
const value = watch(name); | ||
let values = value; | ||
|
||
if (!Array.isArray(value)) { | ||
values = [value]; | ||
} | ||
|
||
if (path) { | ||
values = values.map((v) => _.get(v, path)); | ||
} | ||
|
||
const emptySelector = value && value.length > 0 ? '' : 'smart-hub-review-item--empty'; | ||
const classes = ['margin-top-1', emptySelector].filter((x) => x !== '').join(' '); | ||
|
||
return ( | ||
<div className={`grid-row ${classes} margin-bottom-3 desktop:margin-bottom-0`}> | ||
<div className="grid-col-12 desktop:grid-col-6 font-sans-2xs desktop:font-sans-sm text-bold desktop:text-normal"> | ||
{label} | ||
</div> | ||
<div className="grid-col-12 desktop:grid-col-6"> | ||
{values.map((v, index) => ( | ||
<div aria-label={`${label} ${index + 1}`} key={`${label}${v}`} col={12} className="desktop:flex-align-end display-flex flex-column flex-justify-center"> | ||
{Number.isNaN(v) ? '' : v} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
ReviewItem.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
path: PropTypes.string, | ||
}; | ||
|
||
ReviewItem.defaultProps = { | ||
path: '', | ||
}; | ||
|
||
export default ReviewItem; |
53 changes: 53 additions & 0 deletions
53
frontend/src/pages/ActivityReport/Pages/Review/ReviewPage.js
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,53 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { some } from 'lodash'; | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
import Section from './ReviewSection'; | ||
import ReviewItem from './ReviewItem'; | ||
|
||
const ReviewPage = ({ sections, path }) => { | ||
const { getValues } = useFormContext(); | ||
return ( | ||
<> | ||
{sections.map((section) => { | ||
const names = section.items.map((item) => item.name); | ||
const values = getValues(names); | ||
const isEmpty = !some(values, (value) => value && value.length); | ||
return ( | ||
<Section | ||
hidePrint={isEmpty} | ||
key={section.title} | ||
basePath={path} | ||
anchor={section.anchor} | ||
title={section.title} | ||
> | ||
{section.items.map((item) => ( | ||
<ReviewItem | ||
key={item.label} | ||
label={item.label} | ||
path={item.path} | ||
name={item.name} | ||
/> | ||
))} | ||
</Section> | ||
); | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
ReviewPage.propTypes = { | ||
path: PropTypes.string.isRequired, | ||
sections: PropTypes.arrayOf(PropTypes.shape({ | ||
title: PropTypes.string, | ||
anchor: PropTypes.string, | ||
items: PropTypes.arrayOf(PropTypes.shape({ | ||
label: PropTypes.string, | ||
path: PropTypes.string, | ||
name: PropTypes.string, | ||
})), | ||
})).isRequired, | ||
}; | ||
|
||
export default ReviewPage; |
44 changes: 44 additions & 0 deletions
44
frontend/src/pages/ActivityReport/Pages/Review/ReviewSection.js
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,44 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { HashLink } from 'react-router-hash-link'; | ||
|
||
const Section = ({ | ||
title, children, basePath, anchor, hidePrint, | ||
}) => { | ||
const classes = [ | ||
'smart-hub-review-section', | ||
'margin-top-2 desktop:margin-top-0', | ||
hidePrint ? 'smart-hub-review-section--empty no-print' : '', | ||
'margin-bottom-3', | ||
].filter((x) => x).join(' '); | ||
|
||
return ( | ||
<div className={classes}> | ||
<div className="grid-row border-bottom padding-bottom-1 margin-bottom-105"> | ||
<div className="grid-col-12 desktop:grid-col-6"> | ||
<b className="margin-y-1">{title}</b> | ||
</div> | ||
<div className="grid-col-12 desktop:grid-col-6 display-flex flex-align-end flex-column flex-justify-center"> | ||
<HashLink | ||
aria-label={`Edit form section "${title}"`} | ||
to={`${basePath}#${anchor}`} | ||
className="smart-hub-edit-link pull-right no-print" | ||
> | ||
Edit | ||
</HashLink> | ||
</div> | ||
</div> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
Section.propTypes = { | ||
hidePrint: PropTypes.bool.isRequired, | ||
title: PropTypes.string.isRequired, | ||
anchor: PropTypes.string.isRequired, | ||
children: PropTypes.node.isRequired, | ||
basePath: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default Section; |
35 changes: 35 additions & 0 deletions
35
frontend/src/pages/ActivityReport/Pages/Review/__tests__/FileReviewItem.js
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,35 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import FileReviewItem from '../FileReviewItem'; | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const RenderFileReviewItem = ({ status = 'APPROVED' }) => ( | ||
<FileReviewItem | ||
filename="filename" | ||
url="http://localhost:3000" | ||
status={status} | ||
/> | ||
); | ||
|
||
describe('ReviewPage', () => { | ||
it('displays the filename', async () => { | ||
render(<RenderFileReviewItem />); | ||
const item = await screen.findByText('filename'); | ||
expect(item).toBeVisible(); | ||
}); | ||
|
||
it('displays the download link', async () => { | ||
render(<RenderFileReviewItem />); | ||
const link = await screen.findByRole('link'); | ||
expect(link).toHaveAttribute('href', 'http://localhost:3000'); | ||
}); | ||
|
||
it('displays "not approved" if the file has not been approved', async () => { | ||
render(<RenderFileReviewItem status="" />); | ||
const status = await screen.findByText('Not Approved'); | ||
expect(status).toBeVisible(); | ||
}); | ||
}); |
Oops, something went wrong.