City level location data (#1449)
* Merge branch 'plausible_master'
* Add City level details
* Add City level details
* Use ISO codes instead of geoname_id for subdivisions
* Add easier way to configure geolocation database
* Add workflow for dev branch
* Correct clickhouse migration
* Translate subdivision names
* Translate city names
* WIP
* Region and country filters
* Fix region filter
* Remove region_name when removing region filter
* Add modals for regions and cities
* Remove dead code
* WIP
* Revert "WIP"
This reverts commit 3202bf2fe9.
* Feature flag to hide cities when deployed
* Add changelog entry
* Remove unused code
* Remove unused variables
* Fix test
Co-authored-by: AymanTerra <aymanterra@yahoo.com>
pull/1485/head
parent
06d0d0eafa
commit
05bf43c1be
@ -0,0 +1,108 @@
|
||||
import React from "react";
|
||||
import { Link, withRouter } from 'react-router-dom'
|
||||
import Datamap from 'datamaps'
|
||||
|
||||
import Modal from './modal'
|
||||
import * as api from '../../api'
|
||||
import numberFormatter from '../../number-formatter'
|
||||
import {parseQuery} from '../../query'
|
||||
|
||||
class ModalTable extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
loading: true,
|
||||
query: parseQuery(props.location.search, props.site)
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.get(this.props.endpoint, this.state.query, {limit: 100})
|
||||
.then((res) => this.setState({loading: false, list: res}))
|
||||
}
|
||||
|
||||
label() {
|
||||
return this.state.query.period === 'realtime' ? 'Current visitors' : 'Visitors'
|
||||
}
|
||||
|
||||
renderTableItem(tableItem) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
|
||||
Object.entries(this.props.filter).forEach((([key, valueKey]) => {
|
||||
query.set(key, tableItem[valueKey])
|
||||
}))
|
||||
|
||||
const allCountries = Datamap.prototype.worldTopo.objects.world.geometries;
|
||||
const thisCountry = allCountries.find((c) => c.id === tableItem.name) || {properties: {name: tableItem.name}};
|
||||
const countryFullName = thisCountry.properties.name
|
||||
|
||||
return (
|
||||
<tr className="text-sm dark:text-gray-200" key={tableItem.name}>
|
||||
<td className="p-2">
|
||||
<Link className="hover:underline" to={{search: query.toString(), pathname: `/${encodeURIComponent(this.props.site.domain)}`}}>
|
||||
{countryFullName}
|
||||
</Link>
|
||||
</td>
|
||||
<td className="p-2 w-32 font-medium" align="right">
|
||||
{numberFormatter(tableItem.visitors)}
|
||||
{tableItem.percentage &&
|
||||
<span className="inline-block text-xs w-8 text-right">({tableItem.percentage}%)</span> }
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
renderBody() {
|
||||
if (this.state.loading) {
|
||||
return (
|
||||
<div className="loading mt-32 mx-auto"><div></div></div>
|
||||
)
|
||||
}
|
||||
|
||||
if (this.state.list) {
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-xl font-bold dark:text-gray-100">{this.props.title}</h1>
|
||||
|
||||
<div className="my-4 border-b border-gray-300 dark:border-gray-500"></div>
|
||||
<main className="modal__content">
|
||||
<table className="w-max overflow-x-auto md:w-full table-striped table-fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th
|
||||
className="p-2 w-48 lg:w-1/2 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400"
|
||||
align="left"
|
||||
>
|
||||
{this.props.keyLabel}
|
||||
</th>
|
||||
<th
|
||||
// eslint-disable-next-line max-len
|
||||
className="p-2 w-32 lg:w-1/2 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400"
|
||||
align="right"
|
||||
>
|
||||
{this.label()}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{ this.state.list.map(this.renderTableItem.bind(this)) }
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal site={this.props.site} show={!this.state.loading}>
|
||||
{ this.renderBody() }
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(ModalTable)
|
||||
@ -0,0 +1,97 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
import FadeIn from '../../fade-in'
|
||||
import MoreLink from '../more-link'
|
||||
import numberFormatter from '../../number-formatter'
|
||||
import Bar from '../bar'
|
||||
import LazyLoader from '../../lazy-loader'
|
||||
|
||||
export default class ListReport extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {loading: true}
|
||||
this.onVisible = this.onVisible.bind(this)
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.query !== prevProps.query) {
|
||||
this.fetchData()
|
||||
}
|
||||
}
|
||||
|
||||
onVisible() {
|
||||
this.fetchData()
|
||||
if (this.props.timer) this.props.timer.onTick(this.fetchData.bind(this))
|
||||
}
|
||||
|
||||
fetchData() {
|
||||
this.setState({loading: true, list: null})
|
||||
this.props.fetchData()
|
||||
.then((res) => this.setState({loading: false, list: res}))
|
||||
}
|
||||
|
||||
label() {
|
||||
return this.props.query.period === 'realtime' ? 'Current visitors' : 'Visitors'
|
||||
}
|
||||
|
||||
renderListItem(listItem) {
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
|
||||
Object.entries(this.props.filter).forEach((([key, valueKey]) => {
|
||||
query.set(key, listItem[valueKey])
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between my-1 text-sm" key={listItem.name}>
|
||||
<Bar
|
||||
count={listItem.visitors}
|
||||
all={this.state.list}
|
||||
bg="bg-green-50 dark:bg-gray-500 dark:bg-opacity-15"
|
||||
maxWidthDeduction="6rem"
|
||||
>
|
||||
<span className="flex px-2 py-1.5 dark:text-gray-300 relative z-9 break-all">
|
||||
<Link className="md:truncate block hover:underline" to={{search: query.toString()}}>
|
||||
{listItem.name}
|
||||
</Link>
|
||||
</span>
|
||||
</Bar>
|
||||
<span className="font-medium dark:text-gray-200">
|
||||
{numberFormatter(listItem.visitors)}
|
||||
{
|
||||
listItem.percentage &&
|
||||
<span className="inline-block w-8 text-xs text-right">({listItem.percentage}%)</span>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
renderList() {
|
||||
if (this.state.list && this.state.list.length > 0) {
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center justify-between mt-3 mb-2 text-xs font-bold tracking-wide text-gray-500 dark:text-gray-400">
|
||||
<span>{ this.props.keyLabel }</span>
|
||||
<span>{ this.label() }</span>
|
||||
</div>
|
||||
{ this.state.list && this.state.list.map(this.renderListItem.bind(this)) }
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return <div className="font-medium text-center text-gray-500 mt-44 dark:text-gray-400">No data yet</div>
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<LazyLoader onVisible={this.onVisible} className="flex flex-col flex-grow">
|
||||
{ this.state.loading && <div className="mx-auto loading mt-44"><div></div></div> }
|
||||
<FadeIn show={!this.state.loading} className="flex-grow">
|
||||
{ this.renderList() }
|
||||
</FadeIn>
|
||||
{this.props.detailsLink && !this.state.loading && <MoreLink url={this.props.detailsLink} list={this.state.list} />}
|
||||
</LazyLoader>
|
||||
)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,17 @@
|
||||
defmodule Plausible.ClickhouseRepo.Migrations.AddMoreLocationDetails do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:events) do
|
||||
add(:subdivision1_code, :"LowCardinality(String)")
|
||||
add(:subdivision2_code, :"LowCardinality(String)")
|
||||
add(:city_geoname_id, :UInt32)
|
||||
end
|
||||
|
||||
alter table(:sessions) do
|
||||
add(:subdivision1_code, :"LowCardinality(String)")
|
||||
add(:subdivision2_code, :"LowCardinality(String)")
|
||||
add(:city_geoname_id, :UInt32)
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue