-
Notifications
You must be signed in to change notification settings - Fork 2
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 #680 from bcgov/feat/attachments-in-tasklist
Feat: attachments in tasklist
- Loading branch information
Showing
13 changed files
with
281 additions
and
330 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { IconDefinition } from "@fortawesome/fontawesome-svg-core"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
|
||
interface Props { | ||
icon: IconDefinition; | ||
title: string; | ||
linkUrl: { pathname: string; query: { projectRevision: string } }; | ||
} | ||
|
||
const AttachmentsTaskListSection: React.FC<Props> = ({ | ||
icon, | ||
title, | ||
linkUrl, | ||
}) => { | ||
const router = useRouter(); | ||
return ( | ||
<li | ||
aria-current={ | ||
router.pathname === | ||
"/cif/project-revision/[projectRevision]/attachments" | ||
? "step" | ||
: false | ||
} | ||
> | ||
<Link href={linkUrl} passHref> | ||
<h3> | ||
<span className="link"> | ||
{title} <FontAwesomeIcon icon={icon} /> | ||
</span> | ||
</h3> | ||
</Link> | ||
<style jsx>{` | ||
li { | ||
margin-bottom: 0; | ||
cursor: pointer; | ||
} | ||
li[aria-current="step"], | ||
li[aria-current="step"] div { | ||
background-color: #fafafc; | ||
} | ||
h3 { | ||
font-size: 1rem; | ||
line-height: 1; | ||
border-bottom: 1px solid #d1d1d1; | ||
padding: 10px 0 10px 0.5em; | ||
margin: 0; | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
h3, | ||
ul { | ||
list-style: none; | ||
margin: 0; | ||
} | ||
`}</style> | ||
</li> | ||
); | ||
}; | ||
|
||
export default AttachmentsTaskListSection; |
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 was deleted.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
app/pages/cif/project-revision/[projectRevision]/attachments.tsx
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,131 @@ | ||
import DefaultLayout from "components/Layout/DefaultLayout"; | ||
import { withRelay, RelayProps } from "relay-nextjs"; | ||
import { graphql, usePreloadedQuery } from "react-relay"; | ||
import { attachmentsQuery } from "__generated__/attachmentsQuery.graphql"; | ||
import withRelayOptions from "lib/relay/withRelayOptions"; | ||
import useRedirectTo404IfFalsy from "hooks/useRedirectTo404IfFalsy"; | ||
import Table from "components/Table"; | ||
import { NoHeaderFilter, TextFilter } from "components/Table/Filters"; | ||
import AttachmentTableRow from "components/Attachment/AttachmentTableRow"; | ||
import TaskList from "components/TaskList"; | ||
import { FilePicker } from "@button-inc/bcgov-theme"; | ||
import { useCreateAttachment } from "mutations/attachment/createAttachment"; | ||
import bytesToSize from "lib/helpers/bytesToText"; | ||
import LoadingSpinner from "components/LoadingSpinner"; | ||
|
||
const pageQuery = graphql` | ||
query attachmentsQuery($projectRevision: ID!) { | ||
session { | ||
...DefaultLayout_session | ||
} | ||
projectRevision(id: $projectRevision) { | ||
project: projectByProjectId { | ||
projectName | ||
rowId | ||
attachments: attachmentsByProjectId(first: 2147483647) | ||
@connection(key: "connection_attachments") { | ||
__id | ||
totalCount | ||
edges { | ||
node { | ||
file | ||
...AttachmentTableRow_attachment | ||
} | ||
} | ||
} | ||
} | ||
...TaskList_projectRevision | ||
} | ||
} | ||
`; | ||
|
||
const tableFilters = [ | ||
new TextFilter("File Name", "fileName"), | ||
new TextFilter("Type", "type"), | ||
new TextFilter("Size", "size"), | ||
new TextFilter("Uploaded by", "uploadedBy"), | ||
new TextFilter("Received", "received"), | ||
new NoHeaderFilter(), | ||
]; | ||
|
||
export function ProjectAttachments({ | ||
preloadedQuery, | ||
}: RelayProps<{}, attachmentsQuery>) { | ||
const { session, projectRevision } = usePreloadedQuery( | ||
pageQuery, | ||
preloadedQuery | ||
); | ||
|
||
const [createAttachment, isCreatingAttachment] = useCreateAttachment(); | ||
|
||
const isRedirecting = useRedirectTo404IfFalsy(projectRevision); | ||
if (isRedirecting) return null; | ||
|
||
const saveAttachment = async (e) => { | ||
var file = e.target.files[0]; | ||
const variables = { | ||
input: { | ||
attachment: { | ||
file: file, | ||
fileName: file.name, | ||
fileSize: bytesToSize(file.size), | ||
fileType: file.type, | ||
projectId: projectRevision.project.rowId, | ||
}, | ||
}, | ||
connections: [projectRevision.project.attachments.__id], | ||
}; | ||
createAttachment({ | ||
variables, | ||
onError: (err) => console.error(err), | ||
}); | ||
}; | ||
|
||
const taskList = <TaskList projectRevision={projectRevision} mode={"view"} />; | ||
|
||
return ( | ||
<DefaultLayout session={session} leftSideNav={taskList}> | ||
<h2>{projectRevision.project.projectName}</h2> | ||
<h3>Attachments List</h3> | ||
{isCreatingAttachment ? ( | ||
<div> | ||
<div className="loadingSpinnerContainer"> | ||
<LoadingSpinner></LoadingSpinner> | ||
<span>Uploading file...</span> | ||
</div> | ||
</div> | ||
) : ( | ||
<FilePicker onChange={saveAttachment} name={"upload-attachment"}> | ||
Upload New Attachment | ||
</FilePicker> | ||
)} | ||
<Table | ||
paginated | ||
totalRowCount={projectRevision.project.attachments.totalCount} | ||
filters={tableFilters} | ||
pageQuery={pageQuery} | ||
> | ||
{projectRevision.project.attachments.edges.map(({ node }) => ( | ||
<AttachmentTableRow key={node.file} attachment={node} /> | ||
))} | ||
</Table> | ||
<style jsx>{` | ||
header > section { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
.loadingSpinnerContainer { | ||
display: flex; | ||
} | ||
.loadingSpinnerContainer > span { | ||
margin: auto 0.5em; | ||
} | ||
div :global(div.spinner) { | ||
margin: 0; | ||
} | ||
`}</style> | ||
</DefaultLayout> | ||
); | ||
} | ||
|
||
export default withRelay(ProjectAttachments, pageQuery, withRelayOptions); |
Oops, something went wrong.