Skip to content

Commit

Permalink
Merge pull request #939 from MetaPhase-Consulting/update/external-obc
Browse files Browse the repository at this point in the history
Use internal/external OBC URL
  • Loading branch information
mjoyce91 committed Jun 9, 2020
2 parents c5671e5 + ebd652e commit 6333c27
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ exports[`CompareListComponent matches snapshot 1`] = `
>
<DefinitionList
dangerPay={0}
obcUrl=""
obcUrl={Object {}}
postDifferential={30}
/>
</td>
Expand All @@ -473,7 +473,7 @@ exports[`CompareListComponent matches snapshot 1`] = `
>
<DefinitionList
dangerPay={15}
obcUrl=""
obcUrl={Object {}}
postDifferential={20}
/>
</td>
Expand Down Expand Up @@ -1033,7 +1033,7 @@ exports[`CompareListComponent matches snapshot when there is an obc id 1`] = `
>
<DefinitionList
dangerPay={0}
obcUrl=""
obcUrl={Object {}}
postDifferential={30}
/>
</td>
Expand All @@ -1042,7 +1042,7 @@ exports[`CompareListComponent matches snapshot when there is an obc id 1`] = `
>
<DefinitionList
dangerPay={15}
obcUrl=""
obcUrl={Object {}}
postDifferential={20}
/>
</td>
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Differentials/Differentials.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { isNumeric } from 'utilities';
import OBCUrl from 'Components/OBCUrl';
import { OBC_URLS } from 'Constants/PropTypes';
import { NO_DANGER_PAY, NO_POST_DIFFERENTIAL } from 'Constants/SystemMessages';

const DefinitionList = ({ dangerPay, postDifferential, obcUrl }) => (
Expand All @@ -18,13 +19,13 @@ const DefinitionList = ({ dangerPay, postDifferential, obcUrl }) => (
DefinitionList.propTypes = {
dangerPay: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
postDifferential: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
obcUrl: PropTypes.string,
obcUrl: OBC_URLS,
};

DefinitionList.defaultProps = {
dangerPay: NO_DANGER_PAY,
postDifferential: NO_POST_DIFFERENTIAL,
obcUrl: '',
obcUrl: {},
};

export default DefinitionList;
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@ exports[`DefinitionList matches snapshot 1`] = `
<span>
N/A
</span>
<span
style={
Object {
"paddingLeft": 5,
"position": "absolute",
}
}
>
<OBCUrl
altStyle={false}
isButton={false}
label="OBC Details"
type="post-data"
url={Object {}}
/>
</span>
</div>
`;
26 changes: 16 additions & 10 deletions src/Components/OBCUrl/OBCUrl.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import { get, includes } from 'lodash';
import LinkButton from '../LinkButton';

const OBCUrl = ({ type, label, isButton, altStyle, url }) => {
let text; // link text value
let url$ = get(url, 'internal');

// define the URL according to the type
switch (type) {
Expand All @@ -22,28 +24,32 @@ const OBCUrl = ({ type, label, isButton, altStyle, url }) => {

text = label || `${text} details`;

if (includes(get(window, 'location.host'), 'msappproxy')) {
url$ = get(url, 'external');
}

const el = isButton ?
<LinkButton isExternal className={`post-data-button ${altStyle ? 'usa-button-secondary' : ''}`} toLink={url$} >{text}</LinkButton>
:
// This always directs to an internal resource, so there is no security risk.
// eslint-disable-next-line react/jsx-no-target-blank
<a href={url$} rel="noopener" target="_blank">{text}</a>;

return (
// This is not an internal react route. It references a route that
// should be defined on the same server that is serving the react application.
// We open it in a new tab.
isButton ?
<LinkButton isExternal className={`post-data-button ${altStyle ? 'usa-button-secondary' : ''}`} toLink={url} >{text}</LinkButton>
:
// This always directs to an internal resource, so there is no security risk.
// eslint-disable-next-line react/jsx-no-target-blank
<a href={url} rel="noopener" target="_blank">{text}</a>
url$ ? el : null
);
};

OBCUrl.propTypes = {
url: PropTypes.string.isRequired,
url: PropTypes.shape({ internal: PropTypes.string, external: PropTypes.string }),
type: PropTypes.oneOf(['post', 'post-data', 'country']),
label: PropTypes.node,
isButton: PropTypes.bool,
altStyle: PropTypes.bool,
};

OBCUrl.defaultProps = {
url: {},
type: 'post',
label: null,
isButton: false,
Expand Down
4 changes: 2 additions & 2 deletions src/Components/OBCUrl/OBCUrl.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('OBCUrlComponent', () => {
process.env.PUBLIC_URL = '/talentmap/';
});

const url = 'https://google.com/1';
const url = { internal: 'https://google.com/1', external: 'https://google-proxy.com/1' };

it('is defined', () => {
const wrapper = shallow(<OBCUrl
Expand All @@ -21,7 +21,7 @@ describe('OBCUrlComponent', () => {
const wrapper = shallow(<OBCUrl
url={url}
/>);
expect(wrapper.find('a').props().href).toBe(url);
expect(wrapper.find('a').props().href).toBe(url.internal);
});

it('is defined when id is a string', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ exports[`PositionDetailsItem matches snapshot 1`] = `
content={
<DefinitionList
dangerPay={0}
obcUrl=""
obcUrl={Object {}}
postDifferential={30}
/>
}
Expand Down Expand Up @@ -501,7 +501,7 @@ exports[`PositionDetailsItem matches snapshot when there is an obc id 1`] = `
content={
<DefinitionList
dangerPay={0}
obcUrl=""
obcUrl={Object {}}
postDifferential={30}
/>
}
Expand Down Expand Up @@ -862,7 +862,7 @@ exports[`PositionDetailsItem matches snapshot when various data is missing from
content={
<DefinitionList
dangerPay={0}
obcUrl=""
obcUrl={Object {}}
postDifferential={30}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/PositionTitle/PositionTitle.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('PositionTitleComponent', () => {

it('displays the OBC link if post_overview_url exists', () => {
const newDetailsObject = { ...detailsObject };
newDetailsObject.post.post_overview_url = 'url';
newDetailsObject.post.post_overview_url = { internal: 'url', external: 'url2' };
const wrapper = shallow(
<PositionTitle
{...props}
Expand Down
4 changes: 3 additions & 1 deletion src/Components/ViewPostDataButton/ViewPostDataButton.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import FontAwesome from 'react-fontawesome';
import { OBC_URLS } from 'Constants/PropTypes';
import OBCUrl from '../OBCUrl';

const ViewPostDataButton = ({ url, type, altStyle }) => (
Expand All @@ -14,12 +15,13 @@ const ViewPostDataButton = ({ url, type, altStyle }) => (
);

ViewPostDataButton.propTypes = {
url: PropTypes.string.isRequired,
url: OBC_URLS,
type: PropTypes.oneOf(['post', 'country']),
altStyle: PropTypes.bool,
};

ViewPostDataButton.defaultProps = {
url: {},
type: 'post',
altStyle: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ViewPostDataButton from './ViewPostDataButton';

describe('ViewPostDataButtonComponent', () => {
const props = {
url: 'https://google.com/1',
url: { internal: 'https://google.com/1', external: 'https://google-proxy.com/1' },
type: 'post',
};
it('is defined', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ exports[`ViewPostDataButtonComponent matches snapshot 1`] = `
</span>
}
type="post"
url="https://google.com/1"
url={
Object {
"external": "https://google-proxy.com/1",
"internal": "https://google.com/1",
}
}
/>
`;
5 changes: 5 additions & 0 deletions src/Constants/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,8 @@ export const HISTORY_OBJECT = PropTypes.shape({
push: PropTypes.func,
listen: PropTypes.func,
});

export const OBC_URLS = PropTypes.shape({
internal: PropTypes.string,
external: PropTypes.string,
});

0 comments on commit 6333c27

Please sign in to comment.