diff --git a/site/gatsby-site/cypress/e2e/integration/apps/incidents.cy.js b/site/gatsby-site/cypress/e2e/integration/apps/incidents.cy.js index c77afd1ecc..3c1311b798 100644 --- a/site/gatsby-site/cypress/e2e/integration/apps/incidents.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/apps/incidents.cy.js @@ -409,4 +409,34 @@ describe('Incidents App', () => { cy.get('[data-cy="current-page"]').should('have.text', '1'); } ); + + conditionalIt(!Cypress.env('isEmptyEnvironment'), 'Should switch between views', () => { + cy.visit(url); + + cy.waitForStableDOM(); + + cy.get('[data-cy="table-view"] button').contains('Issue Reports').click(); + + cy.waitForStableDOM(); + + cy.get('[data-cy="row"]').should('have.length.at.least', 10); + + cy.get('[data-cy="row"] td a') + .first() + .should('have.attr', 'href') + .and('match', /^\/reports\/\d+$/); + + cy.get('[data-cy="table-view"] button') + .contains(/^Reports$/) + .click(); + + cy.waitForStableDOM(); + + cy.get('[data-cy="row"]').should('have.length.at.least', 10); + + cy.get('[data-cy="row"] td a') + .first() + .should('have.attr', 'href') + .and('match', /^\/cite\/\d+#r\d+$/); + }); }); diff --git a/site/gatsby-site/src/components/reports/ReportsTable.js b/site/gatsby-site/src/components/reports/ReportsTable.js index b460ffd8c7..ce1f4eabbe 100644 --- a/site/gatsby-site/src/components/reports/ReportsTable.js +++ b/site/gatsby-site/src/components/reports/ReportsTable.js @@ -32,8 +32,15 @@ export default function ReportsTable({ data, isLiveData, setIsLiveData }) { { title: t('Report Number'), accessor: 'report_number', - Cell: ({ row: { values } }) => ( - + Cell: ({ row: { values, original } }) => ( + Report {values.report_number} ), diff --git a/site/gatsby-site/src/graphql/reports.js b/site/gatsby-site/src/graphql/reports.js index 3a197086d3..4b686a5a3f 100644 --- a/site/gatsby-site/src/graphql/reports.js +++ b/site/gatsby-site/src/graphql/reports.js @@ -209,7 +209,7 @@ export const FIND_REPORTS = gql` export const FIND_REPORTS_TABLE = gql` query FindReports($query: ReportQueryInput!) { - reports(query: $query, sort: { report_number: DESC }, limit: 999) { + reports(query: $query, sortBy: REPORT_NUMBER_DESC, limit: 9999) { _id submitters date_published diff --git a/site/gatsby-site/src/pages/apps/incidents.js b/site/gatsby-site/src/pages/apps/incidents.js index 8a48f2ee6b..ab718a49f9 100644 --- a/site/gatsby-site/src/pages/apps/incidents.js +++ b/site/gatsby-site/src/pages/apps/incidents.js @@ -83,18 +83,65 @@ const IncidentsPage = ({ data, ...props }) => { break; case 'reports': - if (isLiveData && reports) { + if (isLiveData && reports && !reportsLoading) { setReportsData(transformReports(reports.reports)); - } else if (data?.reports?.nodes) { + } else if (!isLiveData && data?.reports?.nodes) { setReportsData(transformReports(data.reports.nodes)); } break; default: } - }, [isLiveData, incidents, data, selectedView]); + }, [isLiveData, incidents, data, selectedView, reportsLoading]); function transformReports(reports) { - return reports.map((report) => ({ + let reportsData = reports; + + // Since we don't currently have report pages for reports, we need to add the incident_id to the reports to create the correct link /cite/:incident_id#r:report_number + if (selectedView === 'reports') { + const incidents = data.reports.nodes; + + if (isLiveData) { + if (incidents) { + const reportToIncidentMap = []; + + incidents.forEach((incident) => { + incident.reports.forEach((report) => { + reportToIncidentMap[report.report_number] = incident.incident_id; + }); + }); + const updatedReports = reports.map((report) => ({ + ...report, + incident_id: reportToIncidentMap[report.report_number], + })); + + reportsData = updatedReports; + } else { + reportsData = reports; + } + } else { + // Adds the incident_id to reports in order to create the correct link /cite/:incident_id#r:report_number + const reportsMap = new Map(); + + reports.forEach((incident) => { + incident.reports.forEach((report) => { + if (!reportsMap.has(report.report_number) && report.is_incident_report) { + reportsMap.set(report.report_number, { + ...report, + incident_id: incident.incident_id, + }); + } + }); + }); + + const flattenReports = Array.from(reportsMap.values()).sort( + (a, b) => b.report_number - a.report_number + ); + + reportsData = flattenReports; + } + } + + return reportsData.map((report) => ({ ...report, flag: report.flag ? 'Yes' : 'No', is_incident_report: report.is_incident_report ? 'No' : 'Yes', @@ -104,7 +151,7 @@ const IncidentsPage = ({ data, ...props }) => { return (
- + ); } - }, []); + }, [loading]); return ( <>
-

{locale == 'en' ? metaTitle : defaultTitle}

+
+

{locale == 'en' ? metaTitle : defaultTitle}

+ {incidentId && ( + + + + )} +