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 table view report links #2756

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a2821b6
Report page for all reports
clari182 Apr 25, 2024
ef4ab0f
Merge branch 'staging' into feature/report-page
clari182 Apr 26, 2024
e83b8fb
Rollback change to test deploy
clari182 Apr 29, 2024
7853703
Split into two queries to test deploy
clari182 Apr 29, 2024
f7e1550
Update build to test creating report pages before build
clari182 Apr 30, 2024
8c61a38
Update deploy.yml
clari182 Apr 30, 2024
4b2be5c
Update preview.yml
clari182 Apr 30, 2024
f91f9b7
Update preview.yml
clari182 Apr 30, 2024
0c2fca4
Add correct link to reports in table view
clari182 May 2, 2024
3965388
Revert yml and creation changes
clari182 May 2, 2024
8cd118f
Merge branch 'staging' into feature/report-page
clari182 May 3, 2024
96e5a5a
Merge branch 'staging' into feature/report-page
clari182 May 6, 2024
24dec15
Merge branch 'staging' into feature/report-page
clari182 May 6, 2024
dcb4efc
Check if not live data before fallback
clari182 May 7, 2024
54906cd
Merge branch 'staging' into feature/report-page
clari182 May 7, 2024
cc1c923
Merge branch 'staging' into feature/report-page
clari182 May 8, 2024
50aa84f
Merge branch 'staging' into feature/report-page
clari182 May 21, 2024
4b004a4
Merge branch 'staging' into feature/report-page
clari182 May 21, 2024
df318d4
Add test for view switch and url check
clari182 May 21, 2024
8ba5997
Move new test to bottom
clari182 May 21, 2024
0fd7827
Merge branch 'staging' into feature/report-page
clari182 May 23, 2024
9b94928
Rollback reportCard link changes
clari182 May 23, 2024
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
30 changes: 30 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/apps/incidents.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+$/);
});
});
23 changes: 7 additions & 16 deletions site/gatsby-site/src/components/reports/ReportCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';
import { hasVariantData } from 'utils/variants';
import { format, fromUnixTime } from 'date-fns';
import { Link } from 'gatsby';

const ReportCard = ({
item,
Expand Down Expand Up @@ -46,12 +47,6 @@ const ReportCard = ({
}
};

const toggleReadMoreKeyDown = (e) => {
if (e.key === 'Enter') {
toggleReadMore();
}
};

const [isBottomReached, setIsBottomReached] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -143,23 +138,19 @@ const ReportCard = ({
</div>
<div className="mt-0 cursor-default select-text">
<div className="flex">
{reportTitle ? (
<>{reportTitle}</>
) : (
<button
className="w-3/4 text-left"
onClick={toggleReadMore}
onKeyDown={toggleReadMoreKeyDown}
>
<Link to={`/reports/${item.report_number}`} className="hover:no-underline">
clari182 marked this conversation as resolved.
Show resolved Hide resolved
{reportTitle ? (
<>{reportTitle}</>
) : (
<h5
className={`max-w-full text-xl font-bold tracking-tight text-gray-900 dark:text-white w-full ${
!alwaysExpanded ? 'cursor-pointer hover:text-primary-blue' : 'cursor-default'
}`}
>
<Trans ns="landing">{item.title}</Trans>
</h5>
</button>
)}
)}
</Link>
</div>
<div className="flex justify-between flex-wrap">
<WebArchiveLink url={item.url} className="text-dark-gray">
Expand Down
11 changes: 9 additions & 2 deletions site/gatsby-site/src/components/reports/ReportsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ export default function ReportsTable({ data, isLiveData, setIsLiveData }) {
{
title: t('Report Number'),
accessor: 'report_number',
Cell: ({ row: { values } }) => (
<a className="flex" href={`/reports/${values.report_number}`}>
Cell: ({ row: { values, original } }) => (
<a
className="flex"
href={
original.incident_id
? `/cite/${original.incident_id}#r${values.report_number}`
: `/reports/${values.report_number}`
}
>
Report {values.report_number}
</a>
),
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/src/graphql/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
97 changes: 74 additions & 23 deletions site/gatsby-site/src/pages/apps/incidents.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,65 @@
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 = [];

Check warning on line 105 in site/gatsby-site/src/pages/apps/incidents.js

View check run for this annotation

Codecov / codecov/patch

site/gatsby-site/src/pages/apps/incidents.js#L105

Added line #L105 was not covered by tests

incidents.forEach((incident) => {
incident.reports.forEach((report) => {
reportToIncidentMap[report.report_number] = incident.incident_id;

Check warning on line 109 in site/gatsby-site/src/pages/apps/incidents.js

View check run for this annotation

Codecov / codecov/patch

site/gatsby-site/src/pages/apps/incidents.js#L107-L109

Added lines #L107 - L109 were not covered by tests
});
});
const updatedReports = reports.map((report) => ({

Check warning on line 112 in site/gatsby-site/src/pages/apps/incidents.js

View check run for this annotation

Codecov / codecov/patch

site/gatsby-site/src/pages/apps/incidents.js#L112

Added line #L112 was not covered by tests
...report,
incident_id: reportToIncidentMap[report.report_number],
}));

reportsData = updatedReports;
} else {
reportsData = reports;

Check warning on line 119 in site/gatsby-site/src/pages/apps/incidents.js

View check run for this annotation

Codecov / codecov/patch

site/gatsby-site/src/pages/apps/incidents.js#L117-L119

Added lines #L117 - L119 were not covered by tests
}
} 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',
Expand All @@ -104,7 +151,7 @@
return (
<div className="w-full" {...props}>
<div>
<Button.Group className="mb-4">
<Button.Group className="mb-4" data-cy="table-view">
<Button
color={`${selectedView === 'incidents' ? 'dark' : 'gray'}`}
onClick={() => {
Expand Down Expand Up @@ -239,26 +286,30 @@
name
}
}
reports: allMongodbAiidprodReports(
filter: { is_incident_report: { eq: true } }
sort: { report_number: DESC }

reports: allMongodbAiidprodIncidents(
filter: { reports: { elemMatch: { is_incident_report: { eq: true } } } }
sort: { reports: { report_number: DESC } }
) {
nodes {
report_number
title
url
authors
date_downloaded
date_modified
date_published
date_submitted
description
flag
image_url
language
source_domain
submitters
is_incident_report
incident_id
reports {
report_number
title
url
authors
date_downloaded
date_modified
date_published
date_submitted
description
flag
image_url
language
source_domain
submitters
is_incident_report
}
}
}

Expand Down
31 changes: 26 additions & 5 deletions site/gatsby-site/src/templates/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Container from '../elements/Container';
import SocialShareButtons from '../components/ui/SocialShareButtons';
import { useLocalization } from 'plugins/gatsby-theme-i18n';
import { graphql } from 'gatsby';
import { Link, graphql } from 'gatsby';
import ReportCard from 'components/reports/ReportCard';
import { Button } from 'flowbite-react';
import { useUserContext } from 'contexts/userContext';
Expand All @@ -13,10 +13,12 @@

function ReportPage(props) {
const {
data: { report, allMongodbAiidprodTaxa, allMongodbAiidprodClassifications },
data: { report, allMongodbAiidprodTaxa, allMongodbAiidprodClassifications, incident },
data,
} = props;

const incidentId = incident?.incident_id;

const { t } = useTranslation();

const { locale } = useLocalization();
Expand All @@ -41,19 +43,33 @@
data-cy="edit-report"
size={'xs'}
color="light"
href={`/cite/edit?report_number=${report.report_number}`}
href={`/cite/edit?report_number=${report.report_number}${
incidentId ? `&incident_id=${incidentId}` : ''
}`}
className="hover:no-underline "
>
<Trans>Edit</Trans>
</Button>
);
}
}, []);
}, [loading]);

return (
<>
<div className={'titleWrapper'}>
<h1 className="tw-styled-heading">{locale == 'en' ? metaTitle : defaultTitle}</h1>
<div className="flex content-between w-full">
<h1 className="tw-styled-heading">{locale == 'en' ? metaTitle : defaultTitle}</h1>
{incidentId && (
<Link

Check warning on line 63 in site/gatsby-site/src/templates/report.js

View check run for this annotation

Codecov / codecov/patch

site/gatsby-site/src/templates/report.js#L63

Added line #L63 was not covered by tests
to={`/cite/${incident.incident_id}#r${report.report_number}`}
className="hover:no-underline mb-5"
>
<Button outline={true} color={'light'}>
<Trans>Back to Incident {{ incidentId }}</Trans>
</Button>
</Link>
)}
</div>
<SocialShareButtons
metaTitle={metaTitle}
path={props.location.pathname}
Expand Down Expand Up @@ -223,6 +239,11 @@
publish
}
}
incident: mongodbAiidprodIncidents(
reports: { elemMatch: { report_number: { in: [$report_number] } } }
) {
incident_id
}
}
`;

Expand Down