import React, { Fragment, useState } from 'react'; import * as storage from '../../util/storage' import * as url from '../../util/url' import * as api from '../../api' import ListReport from '../reports/list' import { VISITORS_METRIC, maybeWithCR } from '../reports/metrics'; import { Menu, Transition } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import { escapeFilterValue } from '../../util/filters' import classNames from 'classnames' const UTM_TAGS = { utm_medium: { label: 'UTM Medium', shortLabel: 'UTM Medium', endpoint: '/utm_mediums' }, utm_source: { label: 'UTM Source', shortLabel: 'UTM Source', endpoint: '/utm_sources' }, utm_campaign: { label: 'UTM Campaign', shortLabel: 'UTM Campai', endpoint: '/utm_campaigns' }, utm_content: { label: 'UTM Content', shortLabel: 'UTM Conten', endpoint: '/utm_contents' }, utm_term: { label: 'UTM Term', shortLabel: 'UTM Term', endpoint: '/utm_terms' }, } function AllSources(props) { const { site, query } = props function fetchData() { return api.get(url.apiPath(site, '/sources'), query, { limit: 9 }) } function getFilterFor(listItem) { return { source: escapeFilterValue(listItem['name']) } } function renderIcon(listItem) { return ( ) } return ( ) } function UTMSources(props) { const { site, query } = props const utmTag = UTM_TAGS[props.tab] function fetchData() { return api.get(url.apiPath(site, utmTag.endpoint), query, { limit: 9 }) } function getFilterFor(listItem) { return { [props.tab]: escapeFilterValue(listItem['name']) } } return ( ) } export default function SourceList(props) { const { site, query } = props const tabKey = 'sourceTab__' + props.site.domain const storedTab = storage.getItem(tabKey) const [currentTab, setCurrentTab] = useState(storedTab || 'all') function setTab(tab) { return () => { storage.setItem(tabKey, tab) setCurrentTab(tab) } } function renderTabs() { const activeClass = 'inline-block h-5 text-indigo-700 dark:text-indigo-500 font-bold active-prop-heading truncate text-left' const defaultClass = 'hover:text-indigo-600 cursor-pointer truncate text-left' const dropdownOptions = Object.keys(UTM_TAGS) let buttonText = UTM_TAGS[currentTab] ? UTM_TAGS[currentTab].label : 'Campaigns' return (
All
{buttonText}
{dropdownOptions.map((option) => { return ( {({ active }) => ( {UTM_TAGS[option].label} )} ) })}
) } function renderContent() { if (currentTab === 'all') { return } else { return } } return (
{/* Header Container */}

Top Sources

{renderTabs()}
{/* Main Contents */} {renderContent()}
) }