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 PropertyBreakdown extends React.Component { constructor(props) { super(props) let propKey = props.goal.prop_names[0] this.storageKey = 'goalPropTab__' + props.site.domain + props.goal.name const storedKey = window.localStorage[this.storageKey] if (props.goal.prop_names.includes(storedKey)) { propKey = storedKey } if (props.query.filters['props']) { propKey = Object.keys(props.query.filters['props'])[0] } this.state = { loading: true, propKey: propKey } } componentDidMount() { this.fetchPropBreakdown() } fetchPropBreakdown() { if (this.props.query.filters['goal']) { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/property/${encodeURIComponent(this.state.propKey)}`, this.props.query) .then((res) => this.setState({loading: false, breakdown: res})) } } renderUrl(value) { if (value.is_url) { return ( ) } return null } renderPropValue(value) { const query = new URLSearchParams(window.location.search) query.set('props', JSON.stringify({[this.state.propKey]: value.name})) return (