mirror of
https://github.com/plausible/analytics.git
synced 2024-12-22 09:01:40 +03:00
7da138e99e
* chore(docker): improve repeat contributions workflow * This change adds two new commands to gracefully stop and remove the Postgres and Clickhouse docker containers. To do so, it also gives them a recognizable name. * Additionally, the Postgres container is updated to use a named volume for its data. This lower friction for repeat contributions where one would otherwise sign up and activate their accounts again and again each time. * fix(ui): pill text to use text decoration instead of border Support is pretty good including Safari 12+ without a prefix. * docs(changelog): entry for pill text fix
149 lines
3.8 KiB
JavaScript
149 lines
3.8 KiB
JavaScript
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 (
|
|
<ListReport
|
|
fetchData={fetchData}
|
|
filter={{country: 'code', country_name: 'name'}}
|
|
keyLabel="Country"
|
|
detailsLink={sitePath(site, '/countries')}
|
|
query={query}
|
|
color="bg-orange-50"
|
|
/>
|
|
)
|
|
}
|
|
|
|
function Regions({query, site}) {
|
|
function fetchData() {
|
|
return api.get(apiPath(site, '/regions'), query, {country_name: query.filters.country, limit: 9})
|
|
}
|
|
|
|
return (
|
|
<ListReport
|
|
fetchData={fetchData}
|
|
filter={{region: 'code', region_name: 'name'}}
|
|
keyLabel="Region"
|
|
detailsLink={sitePath(site, '/regions')}
|
|
query={query}
|
|
color="bg-orange-50"
|
|
/>
|
|
)
|
|
}
|
|
|
|
function Cities({query, site}) {
|
|
function fetchData() {
|
|
return api.get(apiPath(site, '/cities'), query, {limit: 9})
|
|
}
|
|
|
|
return (
|
|
<ListReport
|
|
fetchData={fetchData}
|
|
filter={{city: 'code', city_name: 'name'}}
|
|
keyLabel="City"
|
|
detailsLink={sitePath(site, '/cities')}
|
|
query={query}
|
|
color="bg-orange-50"
|
|
/>
|
|
)
|
|
}
|
|
|
|
|
|
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 <Cities site={this.props.site} query={this.props.query} timer={this.props.timer}/>
|
|
case "regions":
|
|
return <Regions site={this.props.site} query={this.props.query} timer={this.props.timer}/>
|
|
case "countries":
|
|
return <Countries site={this.props.site} query={this.props.query} timer={this.props.timer}/>
|
|
case "map":
|
|
default:
|
|
return <CountriesMap site={this.props.site} query={this.props.query} timer={this.props.timer}/>
|
|
}
|
|
}
|
|
|
|
renderPill(name, mode) {
|
|
const isActive = this.state.mode === mode
|
|
|
|
if (isActive) {
|
|
return (
|
|
<li
|
|
className="inline-block h-5 text-indigo-700 dark:text-indigo-500 font-bold active-prop-heading"
|
|
>
|
|
{name}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<li
|
|
className="hover:text-indigo-600 cursor-pointer"
|
|
onClick={this.setMode(mode)}
|
|
>
|
|
{name}
|
|
</li>
|
|
)
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div
|
|
className="stats-item flex flex-col w-full mt-6 stats-item--has-header"
|
|
>
|
|
<div
|
|
className="stats-item__header flex flex-col flex-grow bg-white dark:bg-gray-825 shadow-xl rounded p-4 relative"
|
|
>
|
|
<div className="w-full flex justify-between">
|
|
<h3 className="font-bold dark:text-gray-100">
|
|
{labelFor[this.state.mode] || 'Locations'}
|
|
</h3>
|
|
<ul className="flex font-medium text-xs text-gray-500 dark:text-gray-400 space-x-2">
|
|
{ this.renderPill('Map', 'map') }
|
|
{ this.renderPill('Countries', 'countries') }
|
|
{ this.props.site.cities && this.renderPill('Regions', 'regions') }
|
|
{ this.props.site.cities && this.renderPill('Cities', 'cities') }
|
|
</ul>
|
|
</div>
|
|
{ this.renderContent() }
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|