import React from 'react';
import * as storage from '../../util/storage'
import ListReport from '../reports/list'
import * as api from '../../api'
import * as url from '../../util/url'
import { VISITORS_METRIC, PERCENTAGE_METRIC, maybeWithCR } from '../reports/metrics';
function Browsers({ query, site }) {
function fetchData() {
return api.get(url.apiPath(site, '/browsers'), query)
}
function getFilterFor(listItem) {
return { browser: listItem['name']}
}
return (
)
}
function BrowserVersions({ query, site }) {
function fetchData() {
return api.get(url.apiPath(site, '/browser-versions'), query)
}
function getFilterFor(listItem) {
if (query.filters.browser === '(not set)') {
return {}
}
return { browser_version: listItem['name']}
}
return (
)
}
function OperatingSystems({ query, site }) {
function fetchData() {
return api.get(url.apiPath(site, '/operating-systems'), query)
}
function getFilterFor(listItem) {
return { os: listItem['name']}
}
return (
)
}
function OperatingSystemVersions({ query, site }) {
function fetchData() {
return api.get(url.apiPath(site, '/operating-system-versions'), query)
}
function getFilterFor(listItem) {
if (query.filters.os === '(not set)') {
return {}
}
return { os_version: listItem['name']}
}
return (
)
}
function ScreenSizes({ query, site }) {
function fetchData() {
return api.get(url.apiPath(site, '/screen-sizes'), query)
}
function renderIcon(screenSize) {
return iconFor(screenSize.name)
}
function getFilterFor(listItem) {
return { screen: listItem['name']}
}
return (
)
}
function iconFor(screenSize) {
if (screenSize === 'Mobile') {
return (
)
} else if (screenSize === 'Tablet') {
return (
)
} else if (screenSize === 'Laptop') {
return (
)
} else if (screenSize === 'Desktop') {
return (
)
} else if (screenSize === '(not set)') {
return null
}
}
export default class Devices extends React.Component {
constructor(props) {
super(props)
this.tabKey = `deviceTab__${props.site.domain}`
const storedTab = storage.getItem(this.tabKey)
this.state = {
mode: storedTab || 'browser'
}
}
setMode(mode) {
return () => {
storage.setItem(this.tabKey, mode)
this.setState({ mode })
}
}
renderContent() {
switch (this.state.mode) {
case 'browser':
if (this.props.query.filters.browser) {
return
}
return
case 'os':
if (this.props.query.filters.os) {
return
}
return
case 'size':
default:
return (
)
}
}
renderPill(name, mode) {
const isActive = this.state.mode === mode
if (isActive) {
return (
)
}
return (
)
}
render() {
return (
Devices
{this.renderPill('Browser', 'browser')}
{this.renderPill('OS', 'os')}
{this.renderPill('Size', 'size')}
{this.renderContent()}
)
}
}