Skip to content

Commit

Permalink
Merge pull request #69 from PagerDuty/release/0.7.2-beta.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gsreynolds authored Jun 8, 2023
2 parents 0f9996e + f7af056 commit 96c8682
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pd-live-react",
"homepage": "https://pagerduty.github.io/pd-live-react",
"version": "0.7.1-beta.0",
"version": "0.7.2-beta.0",
"private": true,
"dependencies": {
"@braintree/sanitize-url": "^6.0.2",
Expand Down
24 changes: 24 additions & 0 deletions src/components/IncidentTable/IncidentTableComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ describe('IncidentTableComponent', () => {
width: 100,
columnType: 'alert',
},
{
Header: 'object_details',
accessorPath: 'details.object_details',
aggregator: null,
width: 100,
columnType: 'alert',
},
],
},
incidentActions: {
Expand Down Expand Up @@ -108,4 +115,21 @@ describe('IncidentTableComponent', () => {

expect(validator.isURL(sanitizedUrl)).toBeTruthy();
});

it('should render cell with JSON stringified value for custom detail field', () => {
store = mockStore(baseStore);
const wrapper = componentWrapper(store, IncidentTableComponent);

const incidentNumber = 1;
const customDetailField = 'object_details';
const jsonValue = wrapper
.find('[role="row"]')
.get(incidentNumber)
.props.children.find((td) => td.key.includes(customDetailField)).props.children.props
.cell.value;

// jsonValue should include a key with value 'value1'
expect(typeof jsonValue).toBe('object');
expect(JSON.stringify(jsonValue)).toContain('value1');
});
});
43 changes: 30 additions & 13 deletions src/config/incident-table-columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,24 +675,41 @@ export const customReactTableColumnSchema = (
value,
}) => {
// Determine if content should be rendered as link or plaintext
let valueStr;
switch (typeof value) {
case 'string':
valueStr = value;
break;
case 'undefined':
valueStr = '';
break;
case 'object':
valueStr = value ? JSON.stringify(value) : '';
break;
default:
valueStr = `${value}`;
}

try {
const sanitizedValue = sanitizeUrl(value);
if (validator.isURL(sanitizedValue)) {
return (
<a
href={sanitizedValue}
target="_blank"
rel="noopener noreferrer"
className="td-wrapper"
>
{sanitizedValue}
</a>
);
if (typeof value === 'string') {
const sanitizedValue = sanitizeUrl(valueStr);
if (validator.isURL(sanitizedValue)) {
return (
<a
href={sanitizedValue}
target="_blank"
rel="noopener noreferrer"
className="td-wrapper"
>
{sanitizedValue}
</a>
);
}
}
} catch (e) {
console.log(e);
}
return <div className="td-wrapper">{value}</div>;
return <div className="td-wrapper">{valueStr}</div>;
},
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/config/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/mocks/incidents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const generateMockAlert = () => {
quote,
'some obsecure field': uuid,
link,
object_details: {
key1: 'value1',
},
},
event_class: jobType,
message,
Expand Down

0 comments on commit 96c8682

Please sign in to comment.