import React from 'react'; import * as storage from '../../storage' import CountriesMap from './map' import * as api from '../../api' import {apiPath, sitePath} from '../../url' import ListReport from '../reports/list' function Countries({query, site}) { function fetchData() { return api.get(apiPath(site, '/countries'), query, {limit: 9}).then((res) => { return res.map(row => Object.assign({}, row, {percentage: undefined})) }) } return ( ) } function Regions({query, site}) { function fetchData() { return api.get(apiPath(site, '/regions'), query, {country_name: query.filters.country, limit: 9}) } return ( ) } function Cities({query, site}) { function fetchData() { return api.get(apiPath(site, '/cities'), query, {limit: 9}) } return ( ) } const labelFor = { 'countries': 'Countries', 'regions': 'Regions', 'cities': 'Cities', } export default class Locations extends React.Component { constructor(props) { super(props) this.tabKey = `geoTab__${ props.site.domain}` const storedTab = storage.getItem(this.tabKey) this.state = { mode: storedTab || 'map' } } setMode(mode) { return () => { storage.setItem(this.tabKey, mode) this.setState({mode}) } } renderContent() { switch(this.state.mode) { case "cities": return case "regions": return case "countries": return case "map": default: return } } renderPill(name, mode) { const isActive = this.state.mode === mode if (isActive) { return (
  • {name}
  • ) } return (
  • {name}
  • ) } render() { return (

    {labelFor[this.state.mode] || 'Locations'}

      { this.renderPill('Map', 'map') } { this.renderPill('Countries', 'countries') } { this.props.site.cities && this.renderPill('Regions', 'regions') } { this.props.site.cities && this.renderPill('Cities', 'cities') }
    { this.renderContent() }
    ) } }