-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AB#914 create and display my attachments list
- Loading branch information
1 parent
9e4b575
commit 28b4d02
Showing
18 changed files
with
480 additions
and
32 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
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,199 @@ | ||
import { gql } from "@apollo/client" | ||
import API from "api" | ||
import Fieldset from "components/Fieldset" | ||
import LinkTo from "components/LinkTo" | ||
import { | ||
mapPageDispatchersToProps, | ||
PageDispatchersPropType, | ||
useBoilerplate, | ||
usePageTitle | ||
} from "components/Page" | ||
import UltimatePagination from "components/UltimatePagination" | ||
import PropTypes from "prop-types" | ||
import React, { useEffect, useState } from "react" | ||
import { Table } from "react-bootstrap" | ||
import { connect } from "react-redux" | ||
import utils from "utils" | ||
|
||
const GQL_GET_MY_ATTACHMENTS = gql` | ||
query ($attachmentsQuery: AttachmentSearchQueryInput) { | ||
myAttachments(query: $attachmentsQuery) { | ||
totalCount | ||
pageNum | ||
pageSize | ||
list { | ||
uuid | ||
fileName | ||
caption | ||
contentLength | ||
mimeType | ||
classification | ||
description | ||
author { | ||
uuid | ||
name | ||
rank | ||
avatarUuid | ||
} | ||
attachmentRelatedObjects { | ||
relatedObject { | ||
... on AuthorizationGroup { | ||
name | ||
} | ||
... on Location { | ||
name | ||
} | ||
... on Organization { | ||
shortName | ||
} | ||
... on Person { | ||
name | ||
rank | ||
avatarUuid | ||
} | ||
... on Position { | ||
type | ||
name | ||
} | ||
... on Report { | ||
intent | ||
} | ||
... on Task { | ||
shortName | ||
} | ||
} | ||
relatedObjectUuid | ||
relatedObjectType | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
const MyAttachments = ({ | ||
forceRefetch, | ||
setForceRefetch, | ||
refetchCallback, | ||
pageDispatchers | ||
}) => { | ||
const [pageNum, setPageNum] = useState(0) | ||
const attachmentsQuery = { | ||
pageNum, | ||
pageSize: 10 | ||
} | ||
const { loading, error, data, refetch } = API.useApiQuery( | ||
GQL_GET_MY_ATTACHMENTS, | ||
{ | ||
attachmentsQuery | ||
} | ||
) | ||
useEffect(() => { | ||
if (forceRefetch) { | ||
setForceRefetch(false) | ||
refetch() | ||
} | ||
}, [forceRefetch, setForceRefetch, refetch]) | ||
const { done, result } = useBoilerplate({ | ||
loading, | ||
error, | ||
pageDispatchers | ||
}) | ||
usePageTitle("My Attachments") | ||
if (done) { | ||
return result | ||
} | ||
|
||
const paginatedAttachments = data.myAttachments | ||
const attachments = paginatedAttachments ? paginatedAttachments.list : [] | ||
const { pageSize, totalCount } = paginatedAttachments | ||
const attachmentsExist = totalCount > 0 | ||
|
||
return ( | ||
<Fieldset id="my-attachments" title="My Attachments"> | ||
{attachmentsExist ? ( | ||
<div> | ||
<UltimatePagination | ||
Component="header" | ||
componentClassName="searchPagination" | ||
className="float-end" | ||
pageNum={pageNum} | ||
pageSize={pageSize} | ||
totalCount={totalCount} | ||
goToPage={setPageNum} | ||
/> | ||
|
||
<Table striped hover responsive className="attachments_table"> | ||
<thead> | ||
<tr> | ||
<th>Content</th> | ||
<th>Name</th> | ||
<th>Caption</th> | ||
<th>Used In</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{attachments.map(attachment => { | ||
const { backgroundImage } = utils.getAttachmentIconDetails( | ||
attachment, | ||
true | ||
) | ||
return ( | ||
<tr key={attachment.uuid}> | ||
<td> | ||
<div | ||
key={attachment.id} | ||
style={{ | ||
backgroundSize: "cover", | ||
height: "40px", | ||
width: "40px", | ||
backgroundPosition: "center", | ||
backgroundImage: `url(${backgroundImage})`, | ||
backgroundRepeat: "no-repeat" | ||
}} | ||
/> | ||
</td> | ||
<td> | ||
<LinkTo modelType="Attachment" model={attachment}> | ||
{attachment.fileName} | ||
</LinkTo> | ||
</td> | ||
<td>{attachment.caption}</td> | ||
<td> | ||
{attachment.attachmentRelatedObjects[0] ? ( | ||
<LinkTo | ||
modelType={ | ||
attachment.attachmentRelatedObjects[0] | ||
.relatedObjectType | ||
} | ||
model={{ | ||
uuid: attachment.attachmentRelatedObjects[0] | ||
.relatedObjectUuid, | ||
...attachment.attachmentRelatedObjects[0] | ||
.relatedObject | ||
}} | ||
/> | ||
) : ( | ||
<>No linked objects</> | ||
)} | ||
</td> | ||
</tr> | ||
) | ||
})} | ||
</tbody> | ||
</Table> | ||
</div> | ||
) : ( | ||
<em>No attachments found</em> | ||
)} | ||
</Fieldset> | ||
) | ||
} | ||
|
||
MyAttachments.propTypes = { | ||
forceRefetch: PropTypes.bool.isRequired, | ||
setForceRefetch: PropTypes.func.isRequired, | ||
refetchCallback: PropTypes.func.isRequired, | ||
pageDispatchers: PageDispatchersPropType | ||
} | ||
|
||
export default connect(null, mapPageDispatchersToProps)(MyAttachments) |
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,37 @@ | ||
import { expect } from "chai" | ||
import Home from "../pages/home.page" | ||
import MyAttachments from "../pages/myAttachments.page" | ||
|
||
describe("Home page", () => { | ||
describe("When checking the navigation items", () => { | ||
it("Should see a link to my attachments page", async() => { | ||
await Home.open() | ||
await (await Home.getLinksMenuButton()).click() | ||
await (await Home.getMyAttachmentsLink()).waitForDisplayed() | ||
// eslint-disable-next-line no-unused-expressions | ||
expect(await (await Home.getMyAttachmentsLink()).isExisting()).to.be.true | ||
await Home.logout() | ||
}) | ||
}) | ||
}) | ||
|
||
describe("My Attachments page", () => { | ||
beforeEach("Open the my attachments page", async() => { | ||
await MyAttachments.open("arthur") | ||
}) | ||
|
||
afterEach("On the my attachments page...", async() => { | ||
await MyAttachments.logout() | ||
}) | ||
|
||
describe("When checking the content of the page", () => { | ||
it("Should see a table of the user attachments", async() => { | ||
await (await MyAttachments.getMyAttachments()).waitForDisplayed() | ||
const myAttachments = await ( | ||
await MyAttachments.getMyAttachments() | ||
).$$("tr") | ||
// table has a header and 5 attachment rows | ||
expect(myAttachments).to.have.length(5) | ||
}) | ||
}) | ||
}) |
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,15 @@ | ||
import Page from "./page" | ||
|
||
const PAGE_URL = "/attachments/mine" | ||
|
||
class MyAttachments extends Page { | ||
async open(credentials) { | ||
await super.open(PAGE_URL, credentials) | ||
} | ||
|
||
async getMyAttachments() { | ||
return browser.$("#my-attachments") | ||
} | ||
} | ||
|
||
export default new MyAttachments() |
14 changes: 14 additions & 0 deletions
14
src/main/java/mil/dds/anet/beans/search/AttachmentSearchQuery.java
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,14 @@ | ||
package mil.dds.anet.beans.search; | ||
|
||
public class AttachmentSearchQuery extends AbstractSearchQuery<AttachmentSearchSortBy> { | ||
|
||
public AttachmentSearchQuery() { | ||
super(AttachmentSearchSortBy.CREATED_AT); | ||
this.setSortOrder(SortOrder.DESC); | ||
} | ||
|
||
@Override | ||
public AttachmentSearchQuery clone() throws CloneNotSupportedException { | ||
return (AttachmentSearchQuery) super.clone(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/mil/dds/anet/beans/search/AttachmentSearchSortBy.java
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,5 @@ | ||
package mil.dds.anet.beans.search; | ||
|
||
public enum AttachmentSearchSortBy implements ISortBy { | ||
CREATED_AT | ||
} |
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
Oops, something went wrong.