import React from 'react'; import { Link } from 'react-router-dom' import Bar from '../bar' import numberFormatter from '../../number-formatter' import * as api from '../../api' export default class MetaBreakdown extends React.Component { constructor(props) { super(props) let metaKey = props.goal.meta_keys[0] this.storageKey = 'goalMetaTab__' + props.site.domain + props.goal.name const storedKey = window.localStorage[this.storageKey] if (props.goal.meta_keys.includes(storedKey)) { metaKey = storedKey } if (props.query.filters['meta']) { metaKey = Object.keys(props.query.filters['meta'])[0] } this.state = { loading: true, metaKey: metaKey } } componentDidMount() { this.fetchMetaBreakdown() } fetchMetaBreakdown() { if (this.props.query.filters['goal']) { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/meta-breakdown/${encodeURIComponent(this.state.metaKey)}`, this.props.query) .then((res) => this.setState({loading: false, breakdown: res})) } } renderMetadataValue(value) { const query = new URLSearchParams(window.location.search) query.set('meta', JSON.stringify({[this.state.metaKey]: value.name})) return (