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

Fix: don't display archived attachements on the project attachment view page #1925

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 21 additions & 20 deletions app/components/Form/ProjectAttachmentsFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ProjectAttachmentsFormSummary_projectRevision$key } from "__generated__
import { FormNotAddedOrUpdated } from "./SummaryFormCommonComponents";
import { useEffect, useMemo } from "react";

const tableFilters = [
new TextFilter("Operation", "operation"),
const operationTableFilter = new TextFilter("Operation", "operation");
const mainTableFilters = [
new TextFilter("File Name", "fileName"),
new TextFilter("Type", "type"),
new TextFilter("Size", "size"),
Expand Down Expand Up @@ -39,7 +39,6 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
formDataTableName: "project_attachment"
) @connection(key: "connection_summaryProjectAttachmentFormChanges") {
__id
totalCount
edges {
node {
id
Expand All @@ -66,7 +65,7 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
// If we are showing the diff then we want to see archived records, otherwise filter out the archived contacts
let attachmentFormChanges =
revision.summaryProjectAttachmentFormChanges.edges;
if (!renderDiff)
if (!renderDiff || isOnAmendmentsAndOtherRevisionsPage)
attachmentFormChanges =
revision.summaryProjectAttachmentFormChanges.edges.filter(
({ node }) => node.operation !== "ARCHIVE"
Expand All @@ -91,6 +90,10 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
if (isOnAmendmentsAndOtherRevisionsPage && projectAttachmentsFormNotUpdated)
return null;

const tableFilters = isOnAmendmentsAndOtherRevisionsPage
? [operationTableFilter, ...mainTableFilters]
: mainTableFilters;

return (
<>
{!isOnAmendmentsAndOtherRevisionsPage && <h3>Project Attachments</h3>}
Expand All @@ -106,24 +109,22 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
) : (
<Table
paginated
totalRowCount={
revision.summaryProjectAttachmentFormChanges.totalCount
}
totalRowCount={attachmentFormChanges.length}
filters={tableFilters}
>
{revision.summaryProjectAttachmentFormChanges.edges.map(
({ node }) => (
<AttachmentTableRow
key={node.id}
operation={node.operation}
attachment={node.asProjectAttachment.attachmentByAttachmentId}
formChangeRowId={node.rowId}
connectionId={revision.summaryProjectAttachmentFormChanges.__id}
hideDelete={true}
isFirstRevision={revision.isFirstRevision}
/>
)
)}
{attachmentFormChanges.map(({ node }) => (
<AttachmentTableRow
key={node.id}
operation={
isOnAmendmentsAndOtherRevisionsPage ? undefined : node.operation
}
attachment={node.asProjectAttachment.attachmentByAttachmentId}
formChangeRowId={node.rowId}
connectionId={revision.summaryProjectAttachmentFormChanges.__id}
hideDelete={true}
isFirstRevision={revision.isFirstRevision}
/>
))}
</Table>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ const TestWrapper: React.FC = (props: any) => {
);
};

const getPropsFromTestQuery = (data) => ({
query: data.query,
projectRevision: data.query.projectRevision,
});

const componentTestingHelper = new ComponentTestingHelper<FormIndexPageQuery>({
component: TestWrapper,
testQuery: testQuery,
compiledQuery: compiledFormIndexPageQuery,
getPropsFromTestQuery: (data) => ({
query: data.query,
projectRevision: data.query.projectRevision,
}),
getPropsFromTestQuery: getPropsFromTestQuery,
defaultQueryResolver: defaultQueryResolver,
defaultQueryVariables: { projectRevision: "mock-id" },
});
Expand All @@ -132,20 +134,47 @@ describe("The project's attachment page", () => {
).not.toBeInTheDocument();
});

it("Displays all attachments that were created in this revision", () => {
it("Displays all attachments that were created in this revision if the isOnAmendmentsAndOtherRevisionsPage flag is false, and displays their create operation", () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent();
componentTestingHelper.renderComponent(getPropsFromTestQuery, {
isOnAmendmentsAndOtherRevisionsPage: false,
});

expect(screen.getAllByText(/Create/i)).toHaveLength(2);
expect(screen.getByText(/test-attachment-1.jpg/i)).toBeInTheDocument();
expect(screen.getByText(/test-attachment-2.jpg/i)).toBeInTheDocument();
});

it("Displays all attachments that were archived in this revision", () => {
it("Displays all attachments that were archived in this revision if the isOnAmendmentsAndOtherRevisionsPage flag is false", () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent();
componentTestingHelper.renderComponent(getPropsFromTestQuery, {
isOnAmendmentsAndOtherRevisionsPage: false,
});

expect(screen.getAllByText(/Archive/i)).toHaveLength(1);
expect(screen.getByText(/test-attachment-3.jpg/i)).toBeInTheDocument();
});

it("Displays all attachments that were created in this revision if the isOnAmendmentsAndOtherRevisionsPage flag is false, without their create operation", () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent(getPropsFromTestQuery, {
isOnAmendmentsAndOtherRevisionsPage: true,
});

expect(screen.queryByText(/Create/i)).not.toBeInTheDocument();
expect(screen.getByText(/test-attachment-1.jpg/i)).toBeInTheDocument();
expect(screen.getByText(/test-attachment-2.jpg/i)).toBeInTheDocument();
});

it("Doesn't display archived items if the isOnAmendmentsAndOtherRevisionsPage flag is false", () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent(getPropsFromTestQuery, {
isOnAmendmentsAndOtherRevisionsPage: true,
});

expect(screen.queryByText(/Archive/i)).not.toBeInTheDocument();
expect(
screen.queryByText(/test-attachment-3.jpg/i)
).not.toBeInTheDocument();
});
});
22 changes: 11 additions & 11 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3573,11 +3573,11 @@ brace-expansion@^2.0.1:
balanced-match "^1.0.0"

braces@^3.0.1, braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.0.1"
fill-range "^7.1.1"

browser-process-hrtime@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -5488,10 +5488,10 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

Expand Down Expand Up @@ -10749,9 +10749,9 @@ write-file-atomic@^3.0.0:
typedarray-to-buffer "^3.1.5"

"ws@^5.2.0 || ^6.0.0 || ^7.0.0", ws@^7.4.2, ws@^7.4.6:
version "7.5.6"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.6.tgz#e59fc509fb15ddfb65487ee9765c5a51dec5fe7b"
integrity sha512-6GLgCqo2cy2A2rjCNFlxQS6ZljG/coZfZXclldI8FB/1G3CCI36Zd8xy2HrFVACi8tfk5XrgLQEk+P0Tnz9UcA==
version "7.5.10"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9"
integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==

xdg-basedir@^4.0.0:
version "4.0.0"
Expand Down
Loading