import { connect } from 'react-redux'; import cn from 'classnames'; import withToggle from 'HOCs/withToggle'; import { IconButton, Popup } from 'UI'; import { updateAppearance } from 'Duck/user'; import stl from './addWidgets.css'; import OutsideClickDetectingDiv from 'Shared/OutsideClickDetectingDiv'; import { updateActiveState } from 'Duck/customMetrics'; const CUSTOM_METRICS = 'custom_metrics'; @connect(state => ({ appearance: state.getIn([ 'user', 'account', 'appearance' ]), customMetrics: state.getIn(['customMetrics', 'list']), }), { updateAppearance, updateActiveState, }) @withToggle() export default class AddWidgets extends React.PureComponent { makeAddHandler = widgetKey => () => { if (this.props.type === CUSTOM_METRICS) { this.props.updateActiveState(widgetKey, true); } else { const { appearance } = this.props; const newAppearance = appearance.setIn([ 'dashboard', widgetKey ], true); this.props.updateAppearance(newAppearance) } this.props.switchOpen(false); } getCustomMetricWidgets = () => { return this.props.customMetrics.filter(i => !i.active).map(item => ({ type: CUSTOM_METRICS, key: item.metricId, name: item.name, })).toJS(); } render() { const { disabled, widgets, type } = this.props; const filteredWidgets = type === CUSTOM_METRICS ? this.getCustomMetricWidgets() : widgets; return (