-
Notifications
You must be signed in to change notification settings - Fork 8
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
Move report table to own component #610
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
frontend/src/components/ActivityReportsTable/ColumnHeader.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,47 @@ | ||
/* eslint-disable jsx-a11y/anchor-is-valid */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
function ColumnHeader({ | ||
displayName, name, sortBy, sortDirection, onUpdateSort, | ||
}) { | ||
const getClassNamesFor = (n) => (sortBy === n ? sortDirection : ''); | ||
const sortClassName = getClassNamesFor(name); | ||
let fullAriaSort; | ||
switch (sortClassName) { | ||
case 'asc': | ||
fullAriaSort = 'ascending'; | ||
break; | ||
case 'desc': | ||
fullAriaSort = 'descending'; | ||
break; | ||
default: | ||
fullAriaSort = 'none'; | ||
break; | ||
} | ||
|
||
return ( | ||
<th scope="col" aria-sort={fullAriaSort}> | ||
<a | ||
role="button" | ||
tabIndex={0} | ||
onClick={() => onUpdateSort(name)} | ||
onKeyPress={() => onUpdateSort(name)} | ||
className={`sortable ${sortClassName}`} | ||
aria-label={`${displayName}. Activate to sort ${sortClassName === 'asc' ? 'descending' : 'ascending'}`} | ||
> | ||
{displayName} | ||
</a> | ||
</th> | ||
); | ||
} | ||
|
||
ColumnHeader.propTypes = { | ||
displayName: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
sortBy: PropTypes.string.isRequired, | ||
sortDirection: PropTypes.string.isRequired, | ||
onUpdateSort: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ColumnHeader; |
144 changes: 144 additions & 0 deletions
144
frontend/src/components/ActivityReportsTable/ReportRow.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,144 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Tag, Checkbox, | ||
} from '@trussworks/react-uswds'; | ||
import { Link, useHistory } from 'react-router-dom'; | ||
|
||
import ContextMenu from '../ContextMenu'; | ||
import { getReportsDownloadURL } from '../../fetchers/helpers'; | ||
import TooltipWithCollection from '../TooltipWithCollection'; | ||
|
||
function ReportRow({ | ||
report, openMenuUp, handleReportSelect, isChecked, | ||
}) { | ||
const { | ||
id, | ||
displayId, | ||
activityRecipients, | ||
startDate, | ||
author, | ||
topics, | ||
collaborators, | ||
lastSaved, | ||
calculatedStatus, | ||
legacyId, | ||
} = report; | ||
|
||
const history = useHistory(); | ||
const authorName = author ? author.fullName : ''; | ||
const recipients = activityRecipients && activityRecipients.map((ar) => ( | ||
ar.grant ? ar.grant.grantee.name : ar.name | ||
)); | ||
|
||
const collaboratorNames = collaborators && collaborators.map((collaborator) => ( | ||
collaborator.fullName)); | ||
|
||
const viewOrEditLink = calculatedStatus === 'approved' ? `/activity-reports/view/${id}` : `/activity-reports/${id}`; | ||
const linkTarget = legacyId ? `/activity-reports/legacy/${legacyId}` : viewOrEditLink; | ||
|
||
const menuItems = [ | ||
{ | ||
label: 'View', | ||
onClick: () => { history.push(linkTarget); }, | ||
}, | ||
]; | ||
|
||
if (navigator.clipboard) { | ||
menuItems.push({ | ||
label: 'Copy URL', | ||
onClick: async () => { | ||
await navigator.clipboard.writeText(`${window.location.origin}${linkTarget}`); | ||
}, | ||
}); | ||
} | ||
|
||
if (!legacyId) { | ||
const downloadMenuItem = { | ||
label: 'Download', | ||
onClick: () => { | ||
const downloadURL = getReportsDownloadURL([id]); | ||
window.location.assign(downloadURL); | ||
}, | ||
}; | ||
menuItems.push(downloadMenuItem); | ||
} | ||
|
||
const contextMenuLabel = `Actions for activity report ${displayId}`; | ||
|
||
const selectId = `report-${id}`; | ||
|
||
return ( | ||
<tr key={`landing_${id}`}> | ||
<td className="width-8"> | ||
<Checkbox id={selectId} label="" value={id} checked={isChecked} onChange={handleReportSelect} aria-label={`Select ${displayId}`} /> | ||
</td> | ||
<th scope="row" className="smart-hub--blue"> | ||
<Link | ||
to={linkTarget} | ||
> | ||
{displayId} | ||
</Link> | ||
</th> | ||
<td> | ||
<TooltipWithCollection collection={recipients} collectionTitle={`recipients for ${displayId}`} /> | ||
</td> | ||
<td>{startDate}</td> | ||
<td> | ||
<span className="smart-hub--ellipsis" title={authorName}> | ||
{authorName} | ||
</span> | ||
</td> | ||
<td> | ||
<TooltipWithCollection collection={topics} collectionTitle={`topics for ${displayId}`} /> | ||
</td> | ||
<td> | ||
<TooltipWithCollection collection={collaboratorNames} collectionTitle={`collaborators for ${displayId}`} /> | ||
</td> | ||
<td>{lastSaved}</td> | ||
<td> | ||
<Tag | ||
className={`smart-hub--table-tag-status smart-hub--status-${calculatedStatus}`} | ||
> | ||
{calculatedStatus === 'needs_action' ? 'Needs action' : calculatedStatus} | ||
</Tag> | ||
</td> | ||
<td> | ||
<ContextMenu label={contextMenuLabel} menuItems={menuItems} up={openMenuUp} /> | ||
</td> | ||
</tr> | ||
); | ||
} | ||
|
||
export const reportPropTypes = { | ||
report: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
displayId: PropTypes.string.isRequired, | ||
activityRecipients: PropTypes.arrayOf(PropTypes.shape({ | ||
name: PropTypes.string, | ||
grant: PropTypes.shape({ | ||
grantee: PropTypes.shape({ | ||
name: PropTypes.string, | ||
}), | ||
}), | ||
})).isRequired, | ||
startDate: PropTypes.string.isRequired, | ||
author: PropTypes.shape({ | ||
fullName: PropTypes.string, | ||
homeRegionId: PropTypes.number, | ||
name: PropTypes.string, | ||
}).isRequired, | ||
topics: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
collaborators: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
lastSaved: PropTypes.string.isRequired, | ||
calculatedStatus: PropTypes.string.isRequired, | ||
legacyId: PropTypes.string, | ||
}).isRequired, | ||
openMenuUp: PropTypes.bool.isRequired, | ||
handleReportSelect: PropTypes.func.isRequired, | ||
isChecked: PropTypes.bool.isRequired, | ||
}; | ||
|
||
ReportRow.propTypes = reportPropTypes; | ||
|
||
export default ReportRow; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to make the API for generating the report more generic, and an instance of the API have the required specifics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it would be nice to have some way of defining which fields are required for the table be passed in as props. We will need something like that when we update the "My Alerts" table to use this component. However in this PR I'm trying to keep changes to a minimum, only want to move the table to a new component, not make any substantial changes.