Skip to content

Commit

Permalink
Merge pull request #2454 from fedspendingtransparency/staging
Browse files Browse the repository at this point in the history
Dynamic Renderer Release + Minor Copy Updates to COVID DS&M [DEV-6973]
  • Loading branch information
MaxwellKendall authored Mar 18, 2021
2 parents 908f17b + 27de737 commit e28a256
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 26 deletions.
2 changes: 1 addition & 1 deletion scripts/sitemaps/buildSitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const createSitemapEntry = (xml, pageData, pageInfo) => {
const createRobots = () => {
fs.writeFile(
path.resolve(__dirname, `./sitemapFiles/robots.txt`),
`User-agent: * \nAllow: /\n\nSitemap: ${siteUrl}/sitemap.xml`,
`User-agent: * \nDisallow: /*.php*\nDisallow: /*?glossary=*\n\nSitemap: ${siteUrl}/sitemap.xml`,
(e) => {
if (e) {
console.log(' Error : ', e);
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/award/shared/overview/Recipient.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const Recipient = ({

const formatRecipientLink = (internalId, name) => {
if (internalId && name) {
return (<Link to={`/recipient/${internalId}`}>{name}</Link>);
return (<Link to={`/recipient/${internalId}/latest`}>{name}</Link>);
}
else if (internalId) {
return (<Link to={`/recipient/${internalId}`}>Unknown</Link>);
return (<Link to={`/recipient/${internalId}/latest`}>Unknown</Link>);
}
return name;
};
Expand Down
6 changes: 3 additions & 3 deletions src/js/components/recipient/RecipientMultiParentCollapse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class RecipientMultiParentCollapse extends React.Component {
<Link
className="recipient-overview__multiparents"
key={currentValue.parent_duns}
to={`/recipient/${currentValue.parent_id}`}>
to={`/recipient/${currentValue.parent_id}/latest`}>
{currentValue.parent_name}
{currentValue.parent_duns ? `(${currentValue.parent_duns})` : ''}
</Link>
Expand All @@ -62,7 +62,7 @@ export default class RecipientMultiParentCollapse extends React.Component {
This recipient is a child of &nbsp;
<Link
className="recipient-overview__parent-link"
to={`/recipient/${initialParent.parent_id}`}>
to={`/recipient/${initialParent.parent_id}/latest`}>
{initialParent.parent_name} {initialDuns}
</Link>
</div>
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class RecipientMultiParentCollapse extends React.Component {
<Link
key={initialDuns}
className="recipient-overview__multiparents"
to={`/recipient/${initialParent.parent_id}`}>
to={`/recipient/${initialParent.parent_id}/latest`}>
{initialParent.parent_name} {initialDuns}
</Link>
<div className={this.state.open ? '' : 'hide'}>
Expand Down
20 changes: 12 additions & 8 deletions src/js/components/sharedComponents/metaTags/MetaTags.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { useLocation } from 'react-router-dom';

import Analytics from 'helpers/analytics/Analytics';
import { Helmet } from 'react-helmet';
import {
isCustomPageTitleDefined,
getCanonicalUrl
} from 'helpers/metaTagHelper';

const propTypes = {
og_url: PropTypes.string,
Expand All @@ -19,19 +23,13 @@ const propTypes = {
};

const defaultProps = {
og_url: 'https://usaspending.gov/',
og_url: 'https://usaspending.gov',
og_title: 'USAspending.gov',
og_description: 'USAspending.gov is the new official source of accessible, searchable and reliable spending data for the U.S. Government.',
og_site_name: 'USAspending.gov',
og_image: 'https://usaspending.gov/img/FacebookOG.png'
};

const isCustomPageTitleDefined = (title = "USAspending.gov") => {
if (title === "USAspending.gov") return false;
if (title.split('|')[0] === ' ') return false;
return true;
};

const MetaTags = ({
og_url: url,
og_title: title,
Expand All @@ -40,6 +38,7 @@ const MetaTags = ({
og_image: image
}) => {
const { pathname } = useLocation();

const [tags, setTags] = useState([]);

const generateTags = () => {
Expand Down Expand Up @@ -78,7 +77,12 @@ const MetaTags = ({
key="og_image" />);
}

setTags(newTags);
setTags(
newTags
.concat([
<link rel="canonical" href={getCanonicalUrl(pathname)} />
])
);
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ export const parseRows = (rows, activeTab, query) => (
link = (
<>
{description}&nbsp;(
<Link onClick={handleClick} to={`/recipient/${rowData._childId}`}>
<Link onClick={handleClick} to={`/recipient/${rowData._childId}/latest`}>
as Child
</Link>,&nbsp;
<Link onClick={handleClick} to={`/recipient/${rowData._recipientId}`}>
<Link onClick={handleClick} to={`/recipient/${rowData._recipientId}/latest`}>
as Recipient
</Link>
)
Expand All @@ -141,7 +141,7 @@ export const parseRows = (rows, activeTab, query) => (
const handleClick = clickedRecipientProfile(`${description}`);
// there is a single profile page for this recipient
link = (
<Link onClick={handleClick} to={`/recipient/${rowData._childId || rowData._recipientId}`}>
<Link onClick={handleClick} to={`/recipient/${rowData._childId || rowData._recipientId}/latest`}>
{description}
</Link>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class RankVisualizationWrapperContainer extends React.Component {
dataSeries.push(result._amount);

if (this.state.scope === 'recipient_duns' && !this.props.subaward) {
const recipientLink = result.recipientId ? `recipient/${result.recipientId}` : '';
const recipientLink = result.recipientId ? `recipient/${result.recipientId}/latest` : '';
linkSeries.push(recipientLink);
}

Expand Down
13 changes: 13 additions & 0 deletions src/js/helpers/metaTagHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,16 @@ export const stateLandingPageMetaTags = {
};

/* eslint-enable max-len */

export const isCustomPageTitleDefined = (title = "USAspending.gov") => {
if (title === "USAspending.gov") return false;
if (title.split('|')[0] === ' ') return false;
if (!title) return false;
return true;
};

const canonicalUrl = 'https://www.usaspending.gov';

const trailingSlashRegExp = new RegExp(/\/$/);

export const getCanonicalUrl = (path) => `${canonicalUrl}${path.replace(trailingSlashRegExp, '')}`;
12 changes: 6 additions & 6 deletions tests/containers/covid19/SpendingByRecipientContainer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ describe('SpendingByRecipientContainer', () => {
(
<>
{mockResults[0].description}&nbsp;(
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-C">
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-C/latest">
as Child
</Link>,&nbsp;
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-R">
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-R/latest">
as Recipient
</Link>
)
Expand All @@ -50,7 +50,7 @@ describe('SpendingByRecipientContainer', () => {
],
[
(
<Link to="/recipient/3c92491a-f2cd-ec7d-294b-7daf91511866-R">
<Link to="/recipient/3c92491a-f2cd-ec7d-294b-7daf91511866-R/latest">
RECIPIENT 2
</Link>
),
Expand Down Expand Up @@ -92,10 +92,10 @@ describe('SpendingByRecipientContainer', () => {
(
<>
{mockLoanResults[0].description}&nbsp;(
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-C">
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-C/latest">
as Child
</Link>,&nbsp;
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-R">
<Link to="/recipient/d2894d22-67fc-f9cb-4005-33fa6a29ef86-R/latest">
as Recipient
</Link>
)
Expand All @@ -108,7 +108,7 @@ describe('SpendingByRecipientContainer', () => {
],
[
(
<Link to="/recipient/3c92491a-f2cd-ec7d-294b-7daf91511866-R">
<Link to="/recipient/3c92491a-f2cd-ec7d-294b-7daf91511866-R/latest">
RECIPIENT 2
</Link>
),
Expand Down
6 changes: 4 additions & 2 deletions tests/helpers/aboutTheDataHelper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const mockPeriods = {
}
};

const { timeZone } = Intl.DateTimeFormat().resolvedOptions();

describe('About The Data Helper', () => {
describe('formatPublicationDates', () => {
const mockData = [
Expand All @@ -54,7 +56,7 @@ describe('About The Data Helper', () => {
});
it('should format dates if they exist', () => {
// or, 5hr offset America/New_York UTC-05:000
expect(new Date().getTimezoneOffset()).toBe(300);
expect(timeZone).toBe('America/New_York');
expect(data[0][0]).toBe('04/30/2020');
expect(data[1][0]).toBe('07/31/2020');
expect(data[1][1]).toBe('08/30/2020');
Expand All @@ -70,7 +72,7 @@ describe('About The Data Helper', () => {
['publication_date', null, {}, '--'],
['certification_date', null, {}, '--']
])('renderDeadline: for title %s when deadline is %s returns %s', (title, timestamp, obj, rtrn) => {
expect(new Date().getTimezoneOffset()).toBe(300);
expect(timeZone).toBe('America/New_York');
if (title === 'publication_date') {
expect(renderDeadline(title, obj)).toEqual(rtrn);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/helpers/metaTagHelper-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isCustomPageTitleDefined, getCanonicalUrl } from 'helpers/metaTagHelper';

test.each([
['Test Page | USAspending.gov', true],
['', false],
['USAspending.gov', false],
[' | USAspending.gov', false],
['T | USAspending.gov', true]
])('isCustomPageTitleDefined: when input is %s, return is %s', (input, rtrn) => {
expect(isCustomPageTitleDefined(input)).toEqual(rtrn);
});

test.each([
['/', 'https://www.usaspending.gov'],
['/award/123/', 'https://www.usaspending.gov/award/123'],
['/test', 'https://www.usaspending.gov/test']
])('getCanonicalUrl: when input is %s, return is %s', (input, rtrn) => {
expect(getCanonicalUrl(input)).toEqual(rtrn);
});

0 comments on commit e28a256

Please sign in to comment.