diff --git a/assets/js/dashboard/historical.js b/assets/js/dashboard/historical.js index 38a663739..882c0521d 100644 --- a/assets/js/dashboard/historical.js +++ b/assets/js/dashboard/historical.js @@ -16,11 +16,11 @@ import { withPinnedHeader } from './pinned-header-hoc'; function Historical(props) { const tooltipBoundary = React.useRef(null) - function renderConversions() { + function renderBehaviours() { if (props.site.hasGoals) { return (
- +
) } @@ -51,7 +51,7 @@ function Historical(props) { - { renderConversions() } + {renderBehaviours()} ) } diff --git a/assets/js/dashboard/stats/behaviours/index.js b/assets/js/dashboard/stats/behaviours/index.js index 5f3263a70..2a767e98c 100644 --- a/assets/js/dashboard/stats/behaviours/index.js +++ b/assets/js/dashboard/stats/behaviours/index.js @@ -1,87 +1,139 @@ -import React, { Fragment, useState } from 'react' +import React, { Fragment } from 'react' import { Menu, Transition } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import classNames from 'classnames' +import * as storage from '../../util/storage' import Funnel from './funnel' import Conversions from './conversions' const ACTIVE_CLASS = 'inline-block h-5 text-indigo-700 dark:text-indigo-500 font-bold active-prop-heading truncate text-left' const DEFAULT_CLASS = 'hover:text-indigo-600 cursor-pointer truncate text-left' +const CONVERSIONS = 'conversions' -function Tabs({ tab, setTab, site }) { - return ( -
-
setTab('conversions')}>Conversions
- {site.flags.funnels && FunnelTab({ tab, setTab, site })} -
- ) -} -function FunnelTab({ tab, setTab, site }) { - const funnelNames = site.funnels.map(({ name }) => name) - - return -
- - Funnels - -
- - - -
- {funnelNames.map((option) => { - return ( - - {({ active }) => ( - setTab(option)} - className={classNames( - active ? 'bg-gray-100 dark:bg-gray-900 text-gray-900 dark:text-gray-200 cursor-pointer' : 'text-gray-700 dark:text-gray-200', - 'block px-4 py-2 text-sm', - tab === option ? 'font-bold' : '' - )} - > - {option} - - )} - - ) - })} -
-
-
-
-} +// export default function Behaviours({ query, site }) +// const [tab, setMode] = useState('conversions') +// const tabs = +// +// if (site.flags.funnels) { +// const selectedFunnel = site.funnels.find(funnel => funnel.name === tab) +// const funnelNames = site.funnels.map(({ name }) => name) +// +// return ( +//
+// {tab == 'conversions' && } +// {funnelNames.includes(tab) && } +//
+// ) +// } else { +// return
+// {tab == 'conversions' && } +//
+// } +// } + +export default class Behaviours extends React.Component { + constructor(props) { + super(props) + this.tabKey = `behavioursTab__${props.site.domain}` + const storedTab = storage.getItem(this.tabKey) + this.state = { + mode: storedTab || CONVERSIONS + } + } + + setMode(mode) { + console.info('setMode', mode) + return () => { + storage.setItem(this.tabKey, mode) + this.setState({ mode }) + } + } -export default function Behaviours({ query, site }) { - const [tab, setTab] = useState('conversions') - const tabs = + tabFunnelPicker() { + const funnelNames = this.props.site.funnels.map(({ name }) => name) - if (site.flags.funnels) { - const selectedFunnel = site.funnels.find(funnel => funnel.name === tab) - const funnelNames = site.funnels.map(({ name }) => name) + return +
+ + Funnels + +
+ + +
+ {funnelNames.map((option) => { + return ( + + {({ active }) => ( + + {option} + + )} + + ) + })} +
+
+
+
+ } + + tabConversions() { return ( -
- {tab == 'conversions' && } - {funnelNames.includes(tab) && } +
Conversions
+ ) + } + + tabs() { + console.info('tabs', this) + return ( +
+ {this.tabConversions()} + {this.tabFunnelPicker()}
) - } else { - return
- {tab == 'conversions' && } -
+ } + + renderContent() { + const funnelNames = this.props.site.funnels.map(({ name }) => name) + const selectedFunnel = this.props.site.funnels.find(funnel => funnel.name === this.state.mode) + + switch (this.state.mode) { + case CONVERSIONS: + return + default: + if (funnelNames.includes(this.state.mode)) { + console.info('yess', this.state.mode) + + return + } + } + } + + render() { + console.info('renderxxx') + return (
+ {this.renderContent()} +
) } }