diff --git a/app/components/Form/ProjectAttachmentsFormSummary.tsx b/app/components/Form/ProjectAttachmentsFormSummary.tsx index 35c0b9cec7..9956695261 100644 --- a/app/components/Form/ProjectAttachmentsFormSummary.tsx +++ b/app/components/Form/ProjectAttachmentsFormSummary.tsx @@ -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"), @@ -39,7 +39,6 @@ const ProjectAttachmentsFormSummary: React.FC = ({ formDataTableName: "project_attachment" ) @connection(key: "connection_summaryProjectAttachmentFormChanges") { __id - totalCount edges { node { id @@ -66,7 +65,7 @@ const ProjectAttachmentsFormSummary: React.FC = ({ // 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" @@ -91,6 +90,10 @@ const ProjectAttachmentsFormSummary: React.FC = ({ if (isOnAmendmentsAndOtherRevisionsPage && projectAttachmentsFormNotUpdated) return null; + const tableFilters = isOnAmendmentsAndOtherRevisionsPage + ? [operationTableFilter, ...mainTableFilters] + : mainTableFilters; + return ( <> {!isOnAmendmentsAndOtherRevisionsPage &&

Project Attachments

} @@ -106,24 +109,22 @@ const ProjectAttachmentsFormSummary: React.FC = ({ ) : ( - {revision.summaryProjectAttachmentFormChanges.edges.map( - ({ node }) => ( - - ) - )} + {attachmentFormChanges.map(({ node }) => ( + + ))}
)} diff --git a/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx index 61e515451e..210c4f7787 100644 --- a/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx @@ -106,14 +106,16 @@ const TestWrapper: React.FC = (props: any) => { ); }; +const getPropsFromTestQuery = (data) => ({ + query: data.query, + projectRevision: data.query.projectRevision, +}); + const componentTestingHelper = new ComponentTestingHelper({ component: TestWrapper, testQuery: testQuery, compiledQuery: compiledFormIndexPageQuery, - getPropsFromTestQuery: (data) => ({ - query: data.query, - projectRevision: data.query.projectRevision, - }), + getPropsFromTestQuery: getPropsFromTestQuery, defaultQueryResolver: defaultQueryResolver, defaultQueryVariables: { projectRevision: "mock-id" }, }); @@ -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(); + }); }); diff --git a/app/yarn.lock b/app/yarn.lock index e44803ecee..1d857357cc 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -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" @@ -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" @@ -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"