diff --git a/package.json b/package.json index b9b8c80abf..33fe5048d4 100644 --- a/package.json +++ b/package.json @@ -186,6 +186,7 @@ "@storybook/addon-storyshots": "^5.3.17", "@storybook/addons": "^5.3.17", "@storybook/react": "^5.3.17", + "@svgr/rollup": "^5.4.0", "@testing-library/dom": "^7.22.2", "@testing-library/jest-dom": "^5.11.3", "@testing-library/react": "^10.4.8", diff --git a/src/components/BarChartCard/barChartUtils.js b/src/components/BarChartCard/barChartUtils.js index 85d862ba41..0138fb4757 100644 --- a/src/components/BarChartCard/barChartUtils.js +++ b/src/components/BarChartCard/barChartUtils.js @@ -242,7 +242,7 @@ export const formatColors = (series, datasetNames) => { const colors = { identifier: 'group', scale: {} }; // if color is an array, order doesn't matter so just map as many as possible - if (Array.isArray(series[0].color)) { + if (series[0] && Array.isArray(series[0].color)) { series[0].color.forEach((color, index) => { colors.scale[datasetNames[index]] = color; }); diff --git a/src/components/CardEditor/CardEditForm/CardEditForm.jsx b/src/components/CardEditor/CardEditForm/CardEditForm.jsx index ee38b3ca96..d21adbcbb1 100644 --- a/src/components/CardEditor/CardEditForm/CardEditForm.jsx +++ b/src/components/CardEditor/CardEditForm/CardEditForm.jsx @@ -2,19 +2,37 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Code16 } from '@carbon/icons-react'; -import { - CARD_SIZES, - CARD_DIMENSIONS, - ALLOWED_CARD_SIZES_PER_TYPE, -} from '../../../constants/LayoutConstants'; +import { CARD_DIMENSIONS } from '../../../constants/LayoutConstants'; import { settings } from '../../../constants/Settings'; -import { Tabs, Tab, Button, TextArea, TextInput, Dropdown } from '../../../index'; +import { Tabs, Tab, Button } from '../../../index'; import CardCodeEditor from '../../CardCodeEditor/CardCodeEditor'; import CardEditFormContent from './CardEditFormContent'; +import CardEditFormSettings from './CardEditFormSettings'; const { iotPrefix } = settings; +const propTypes = { + /** card data value */ + cardJson: PropTypes.object, // eslint-disable-line react/forbid-prop-types + /** card data errors */ + // errors: PropTypes.object, // eslint-disable-line react/forbid-prop-types + /** Callback function when form data changes */ + onChange: PropTypes.func.isRequired, + i18n: PropTypes.shape({ + openEditorButton: PropTypes.string, + }), + /** if provided, returns an array of strings which are the dataItems to be allowed + * on each card + * getValidDataItems(card, selectedTimeRange) + */ + getValidDataItems: PropTypes.func, + /** an array of dataItem string names to be included on each card + * this prop will be ignored if getValidDataItems is defined + */ + dataItems: PropTypes.arrayOf(PropTypes.string), +}; + const defaultProps = { cardJson: {}, i18n: { @@ -36,18 +54,8 @@ const defaultProps = { barChartLayout_VERTICAL: 'Vertical', // additional card type names can be provided using the convention of `cardType_TYPE` }, -}; - -const propTypes = { - /** card data value */ - cardJson: PropTypes.object, // eslint-disable-line react/forbid-prop-types - /** card data errors */ - // errors: PropTypes.object, // eslint-disable-line react/forbid-prop-types - /** Callback function when form data changes */ - onChange: PropTypes.func.isRequired, - i18n: PropTypes.shape({ - openEditorButton: PropTypes.string, - }), + getValidDataItems: null, + dataItems: [], }; /** @@ -96,59 +104,13 @@ export const handleSubmit = (val, setError, onChange, setShowEditor) => { return false; }; -const CardEditForm = ({ cardJson, /* errors, */ onChange, /* onAddImage, */ i18n }) => { +const CardEditForm = ({ cardJson, onChange, i18n, dataItems, getValidDataItems }) => { const mergedI18n = { ...defaultProps.i18n, ...i18n }; const [showEditor, setShowEditor] = useState(false); const [modalData, setModalData] = useState(); const baseClassName = `${iotPrefix}--card-edit-form`; - const cardContentsTab = ( - <> -