2020-02-10 16:17:00 +03:00
|
|
|
import React from 'react';
|
|
|
|
|
2021-12-03 14:59:32 +03:00
|
|
|
import * as storage from '../../util/storage'
|
2021-11-25 13:00:17 +03:00
|
|
|
import ListReport from '../reports/list'
|
2020-11-10 16:18:59 +03:00
|
|
|
import * as api from '../../api'
|
2021-12-03 14:59:32 +03:00
|
|
|
import * as url from '../../util/url'
|
2020-02-10 16:17:00 +03:00
|
|
|
|
2021-11-25 13:00:17 +03:00
|
|
|
function Browsers({query, site}) {
|
|
|
|
function fetchData() {
|
|
|
|
return api.get(url.apiPath(site, '/browsers'), query)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListReport
|
|
|
|
fetchData={fetchData}
|
|
|
|
filter={{browser: 'name'}}
|
|
|
|
keyLabel="Browser"
|
|
|
|
query={query}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function BrowserVersions({query, site}) {
|
|
|
|
function fetchData() {
|
|
|
|
return api.get(url.apiPath(site, '/browser-versions'), query)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListReport
|
|
|
|
fetchData={fetchData}
|
|
|
|
filter={{browser_version: 'name'}}
|
|
|
|
keyLabel={query.filters.browser + ' version'}
|
|
|
|
query={query}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function OperatingSystems({query, site}) {
|
|
|
|
function fetchData() {
|
|
|
|
return api.get(url.apiPath(site, '/operating-systems'), query)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListReport
|
|
|
|
fetchData={fetchData}
|
|
|
|
filter={{os: 'name'}}
|
|
|
|
keyLabel="Operating system"
|
|
|
|
query={query}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function OperatingSystemVersions({query, site}) {
|
|
|
|
function fetchData() {
|
|
|
|
return api.get(url.apiPath(site, '/operating-system-versions'), query)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListReport
|
|
|
|
fetchData={fetchData}
|
|
|
|
filter={{os_version: 'name'}}
|
|
|
|
keyLabel={query.filters.os + ' version'}
|
|
|
|
query={query}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function ScreenSizes({query, site}) {
|
|
|
|
function fetchData() {
|
|
|
|
return api.get(url.apiPath(site, '/screen-sizes'), query)
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderIcon(screenSize) {
|
|
|
|
return iconFor(screenSize.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderTooltipText(screenSize) {
|
|
|
|
return EXPLANATION[screenSize.name]
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListReport
|
|
|
|
fetchData={fetchData}
|
|
|
|
filter={{screen: 'name'}}
|
|
|
|
keyLabel="Screen size"
|
|
|
|
query={query}
|
|
|
|
renderIcon={renderIcon}
|
|
|
|
tooltipText={renderTooltipText}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2020-02-10 16:17:00 +03:00
|
|
|
|
|
|
|
const EXPLANATION = {
|
|
|
|
'Mobile': 'up to 576px',
|
|
|
|
'Tablet': '576px to 992px',
|
|
|
|
'Laptop': '992px to 1440px',
|
|
|
|
'Desktop': 'above 1440px',
|
|
|
|
}
|
|
|
|
|
|
|
|
function iconFor(screenSize) {
|
|
|
|
if (screenSize === 'Mobile') {
|
|
|
|
return (
|
2021-10-11 15:48:19 +03:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="-mt-px feather"><rect x="5" y="2" width="14" height="20" rx="2" ry="2"/><line x1="12" y1="18" x2="12" y2="18"/></svg>
|
2020-02-10 16:17:00 +03:00
|
|
|
)
|
|
|
|
} else if (screenSize === 'Tablet') {
|
|
|
|
return (
|
2021-10-11 15:48:19 +03:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="-mt-px feather"><rect x="4" y="2" width="16" height="20" rx="2" ry="2" transform="rotate(180 12 12)"/><line x1="12" y1="18" x2="12" y2="18"/></svg>
|
2020-02-10 16:17:00 +03:00
|
|
|
)
|
|
|
|
} else if (screenSize === 'Laptop') {
|
|
|
|
return (
|
2021-10-11 15:48:19 +03:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="-mt-px feather"><rect x="2" y="3" width="20" height="14" rx="2" ry="2"/><line x1="2" y1="20" x2="22" y2="20"/></svg>
|
2020-02-10 16:17:00 +03:00
|
|
|
)
|
|
|
|
} else if (screenSize === 'Desktop') {
|
|
|
|
return (
|
2021-10-11 15:48:19 +03:00
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className="-mt-px feather"><rect x="2" y="3" width="20" height="14" rx="2" ry="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>
|
2020-02-10 16:17:00 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Devices extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2021-06-15 10:34:43 +03:00
|
|
|
this.tabKey = `deviceTab__${ props.site.domain}`
|
2021-04-28 11:31:10 +03:00
|
|
|
const storedTab = storage.getItem(this.tabKey)
|
2020-09-28 11:29:24 +03:00
|
|
|
this.state = {
|
|
|
|
mode: storedTab || 'size'
|
|
|
|
}
|
2020-02-10 16:17:00 +03:00
|
|
|
}
|
|
|
|
|
2021-09-20 17:17:11 +03:00
|
|
|
|
2020-02-10 16:17:00 +03:00
|
|
|
setMode(mode) {
|
|
|
|
return () => {
|
2021-04-28 11:31:10 +03:00
|
|
|
storage.setItem(this.tabKey, mode)
|
2020-02-10 16:17:00 +03:00
|
|
|
this.setState({mode})
|
|
|
|
}
|
|
|
|
}
|
2021-09-20 17:17:11 +03:00
|
|
|
|
2021-06-15 10:34:43 +03:00
|
|
|
renderContent() {
|
|
|
|
switch (this.state.mode) {
|
|
|
|
case 'browser':
|
2021-11-25 13:00:17 +03:00
|
|
|
if (this.props.query.filters.browser) {
|
|
|
|
return <BrowserVersions site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
|
|
|
}
|
2021-06-15 10:34:43 +03:00
|
|
|
return <Browsers site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
|
|
|
case 'os':
|
2021-11-25 13:00:17 +03:00
|
|
|
if (this.props.query.filters.os) {
|
|
|
|
return <OperatingSystemVersions site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
|
|
|
}
|
|
|
|
return <OperatingSystems site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
2021-06-15 10:34:43 +03:00
|
|
|
case 'size':
|
|
|
|
default:
|
|
|
|
return (
|
2021-11-25 13:00:17 +03:00
|
|
|
<ScreenSizes site={this.props.site} query={this.props.query} timer={this.props.timer} />
|
2021-06-15 10:34:43 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 16:17:00 +03:00
|
|
|
|
|
|
|
renderPill(name, mode) {
|
|
|
|
const isActive = this.state.mode === mode
|
|
|
|
|
|
|
|
if (isActive) {
|
2021-06-15 10:34:43 +03:00
|
|
|
return (
|
|
|
|
<li
|
2021-11-29 17:21:09 +03:00
|
|
|
className="inline-block h-5 font-bold text-indigo-700 active-prop-heading dark:text-indigo-500"
|
2021-06-15 10:34:43 +03:00
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</li>
|
|
|
|
)
|
2020-02-10 16:17:00 +03:00
|
|
|
}
|
2021-09-20 17:17:11 +03:00
|
|
|
|
2021-06-15 10:34:43 +03:00
|
|
|
return (
|
|
|
|
<li
|
|
|
|
className="cursor-pointer hover:text-indigo-600"
|
|
|
|
onClick={this.setMode(mode)}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</li>
|
|
|
|
)
|
2020-02-10 16:17:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2021-06-15 10:34:43 +03:00
|
|
|
<div
|
|
|
|
className="stats-item flex flex-col mt-6 stats-item--has-header w-full"
|
|
|
|
>
|
|
|
|
<div
|
2021-12-02 12:53:29 +03:00
|
|
|
className="stats-item-header flex flex-col flex-grow relative p-4 bg-white rounded shadow-xl dark:bg-gray-825"
|
2021-06-15 10:34:43 +03:00
|
|
|
>
|
2021-03-25 12:55:15 +03:00
|
|
|
<div className="flex justify-between w-full">
|
2020-12-16 12:57:28 +03:00
|
|
|
<h3 className="font-bold dark:text-gray-100">Devices</h3>
|
2021-03-25 12:55:15 +03:00
|
|
|
<ul className="flex text-xs font-medium text-gray-500 dark:text-gray-400 space-x-2">
|
2020-09-28 11:29:24 +03:00
|
|
|
{ this.renderPill('Size', 'size') }
|
|
|
|
{ this.renderPill('Browser', 'browser') }
|
|
|
|
{ this.renderPill('OS', 'os') }
|
|
|
|
</ul>
|
2020-02-10 16:17:00 +03:00
|
|
|
</div>
|
|
|
|
{ this.renderContent() }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|