Skip to content

Commit

Permalink
Merge branch 'master' into fix-charts-tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdickerson authored Sep 3, 2020
2 parents 507decb + d755beb commit 6c6fb2d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
44 changes: 44 additions & 0 deletions src/utils/__tests__/cardUtilityFunctions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,50 @@ describe('cardUtilityFunctions', () => {
'unit',
]);
});
it('getCardVariables does not blow up on null or react symbols', () => {
const timeSeriesCardWithVariables = {
id: 'air_flow_mean',
size: 'LARGE',
title: 'Air flow {deviceId} mean vs max',
type: 'TIMESERIES',
content: {
series: [
{
dataSourceId: 'airflow_max',
label: '{airflow_max}',
},
],
xLabel: '{x_axis}',
yLabel: '{y_axis}',
unit: '{unit}',
timeDataSourceId: 'timestamp',
},
dataSource: {
attributes: [
{
aggregator: 'max',
attribute: 'air_flow_rate',
id: 'airflow_max',
},
],
range: {
type: 'periodToDate',
count: -7,
interval: 'day',
},
timeGrain: 'day',
},
someNullProperty: null,
someReactSymbolProperty: <p>Hi I am a React symbol</p>,
};
expect(getCardVariables(timeSeriesCardWithVariables)).toEqual([
'deviceId',
'airflow_max',
'x_axis',
'y_axis',
'unit',
]);
});
it('getCardVariables returns empty array when no variables are given', () => {
const imageCard = {
content: {
Expand Down
9 changes: 4 additions & 5 deletions src/utils/cardUtilityFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,12 @@ export const replaceVariables = (variables, cardVariables, target) => {
};

/**
* @param {Object} card
* @param {Object} cardProperty
* @returns {Array<String>} an array of unique variable values
*/
export const getCardVariables = card => {
// for each
const propertyVariables = Object.values(card).reduce((acc, property) => {
if (typeof property === 'object' && !React.isValidElement(property)) {
export const getCardVariables = cardProperty => {
const propertyVariables = Object.values(cardProperty).reduce((acc, property) => {
if (typeof property === 'object' && !React.isValidElement(property) && !isNil(property)) {
// recursively search any objects for additional string properties
acc.push(...getCardVariables(property));
} else if (typeof property === 'string') {
Expand Down

0 comments on commit 6c6fb2d

Please sign in to comment.