diff --git a/package.json b/package.json index 86802490..52b85b20 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/IncidentTable/IncidentTableComponent.test.js b/src/components/IncidentTable/IncidentTableComponent.test.js index 21531817..0ef66f8e 100644 --- a/src/components/IncidentTable/IncidentTableComponent.test.js +++ b/src/components/IncidentTable/IncidentTableComponent.test.js @@ -57,6 +57,13 @@ describe('IncidentTableComponent', () => { width: 100, columnType: 'alert', }, + { + Header: 'object_details', + accessorPath: 'details.object_details', + aggregator: null, + width: 100, + columnType: 'alert', + }, ], }, incidentActions: { @@ -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'); + }); }); diff --git a/src/config/incident-table-columns.js b/src/config/incident-table-columns.js index 6fd34a1a..27b73f94 100644 --- a/src/config/incident-table-columns.js +++ b/src/config/incident-table-columns.js @@ -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 ( - - {sanitizedValue} - - ); + if (typeof value === 'string') { + const sanitizedValue = sanitizeUrl(valueStr); + if (validator.isURL(sanitizedValue)) { + return ( + + {sanitizedValue} + + ); + } } } catch (e) { console.log(e); } - return
{value}
; + return
{valueStr}
; }, }; }; diff --git a/src/config/version.js b/src/config/version.js index a87de2bf..e44fdb85 100644 --- a/src/config/version.js +++ b/src/config/version.js @@ -1,2 +1,2 @@ // Generated by genversion. -module.exports = '0.7.1-beta.0'; +module.exports = '0.7.2-beta.0'; diff --git a/src/mocks/incidents.test.js b/src/mocks/incidents.test.js index 25b18b6e..dcfd18c4 100644 --- a/src/mocks/incidents.test.js +++ b/src/mocks/incidents.test.js @@ -38,6 +38,9 @@ const generateMockAlert = () => { quote, 'some obsecure field': uuid, link, + object_details: { + key1: 'value1', + }, }, event_class: jobType, message,