UI tweaks to Properties and Conversions (#3226)

* fix conversions fetchData limit to the right number

* make Goal Conversions metric column width match Properties

* add more top-margin to Details links in ListReport

* add special handling for url prop in Conversions

* change 'Details' button to 'More' when no additional details

* fix CI

* breakdown by 'path' prop instead for 404 pages

* change the 'MORE' button back to 'DETAILS'

But keep the option of not showing the button when there are less
than 9 list entries.

* capture special props in an object instead (review suggestion)

* Add cloaked link to special goals list

---------

Co-authored-by: Vinicius Brasil <vini@hey.com>
pull/3230/head r2023.08.03-161
RobertJoonas 3 years ago committed by GitHub
parent 59a82288e1
commit 373b8e8201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,7 @@ export default function Conversions(props) {
const {site, query} = props
function fetchConversions() {
return api.get(url.apiPath(site, '/conversions'), query, {limit: 20})
return api.get(url.apiPath(site, '/conversions'), query, {limit: 9})
}
function getFilterFor(listItem) {
@ -30,8 +30,10 @@ export default function Conversions(props) {
{name: 'average_revenue', label: 'Average', hiddenOnMobile: true}
]}
detailsLink={url.sitePath(site, '/conversions')}
maybeHideDetails={true}
query={query}
color="bg-red-50"
colMinWidth={90}
/>
)
}

@ -0,0 +1,56 @@
import React from "react"
import Conversions from './conversions'
import ListReport from "../reports/list"
import { CR_METRIC } from "../reports/metrics"
import * as url from "../../util/url"
import * as api from "../../api"
const SPECIAL_GOALS = {
'404': {title: '404 Pages', prop: 'path'},
'Outbound Link: Click': {title: 'Outbound Links', prop: 'url'},
'Cloaked Link: Click': {title: 'Cloaked Links', prop: 'url'},
'File Download': {title: 'File Downloads', prop: 'url'}
}
export function specialTitleWhenGoalFilter(query, defaultTitle) {
return SPECIAL_GOALS[query.filters.goal]?.title || defaultTitle
}
function SpecialPropBreakdown(props) {
const { site, query } = props
const prop = SPECIAL_GOALS[query.filters.goal].prop
function fetchData() {
return api.get(url.apiPath(site, `/custom-prop-values/${prop}`), query)
}
const getFilterFor = (listItem) => { return {'props': JSON.stringify({[prop]: listItem['name']})} }
return (
<ListReport
fetchData={fetchData}
getFilterFor={getFilterFor}
keyLabel={prop}
metrics={[
{name: 'visitors', label: 'Visitors', plot: true},
{name: 'events', label: 'Events', hiddenOnMobile: true},
CR_METRIC
]}
detailsLink={url.sitePath(site, `/custom-prop-values/${prop}`)}
maybeHideDetails={true}
query={query}
color="bg-red-50"
colMinWidth={90}
/>
)
}
export default function GoalConversions(props) {
const {site, query} = props
if (SPECIAL_GOALS[query.filters.goal]) {
return <SpecialPropBreakdown site={site} query={props.query} />
} else {
return <Conversions site={site} query={props.query} />
}
}

@ -4,7 +4,7 @@ import { ChevronDownIcon } from '@heroicons/react/20/solid'
import classNames from 'classnames'
import * as storage from '../../util/storage'
import Conversions from './conversions'
import GoalConversions, { specialTitleWhenGoalFilter } from './goal-conversions'
import DeprecatedConversions from './deprecated-conversions'
import Properties from './props'
import Funnel from './funnel'
@ -24,8 +24,8 @@ export const sectionTitles = {
}
export default function Behaviours(props) {
const site = props.site
const adminAccess = ['owner', 'admin', 'super_admin'].includes(props.currentUserRole)
const {site, query, currentUserRole} = props
const adminAccess = ['owner', 'admin', 'super_admin'].includes(currentUserRole)
const tabKey = `behavioursTab__${site.domain}`
const funnelKey = `behavioursTabFunnel__${site.domain}`
const [enabledModes, setEnabledModes] = useState(getEnabledModes())
@ -126,9 +126,9 @@ export default function Behaviours(props) {
function renderConversions() {
if (site.hasGoals) {
if (site.flags.props) {
return <Conversions site={site} query={props.query} />
return <GoalConversions site={site} query={query} />
} else {
return <DeprecatedConversions site={site} query={props.query} />
return <DeprecatedConversions site={site} query={query} />
}
}
else if (adminAccess) {
@ -148,7 +148,7 @@ export default function Behaviours(props) {
}
function renderFunnels() {
if (selectedFunnel) { return <Funnel site={site} query={props.query} funnelName={selectedFunnel} /> }
if (selectedFunnel) { return <Funnel site={site} query={query} funnelName={selectedFunnel} /> }
else if (adminAccess) {
return (
<FeatureSetupNotice
@ -167,7 +167,7 @@ export default function Behaviours(props) {
function renderProps() {
if (site.allowedEventProps && site.allowedEventProps.length > 0) {
return <Properties site={site} query={props.query} allowedEventProps={site.allowedEventProps}/>
return <Properties site={site} query={query} allowedEventProps={site.allowedEventProps}/>
} else if (adminAccess) {
return (
<FeatureSetupNotice
@ -237,7 +237,15 @@ export default function Behaviours(props) {
}
function isRealtime() {
return props.query.period === 'realtime'
return query.period === 'realtime'
}
function sectionTitle() {
if (mode === CONVERSIONS) {
return specialTitleWhenGoalFilter(query, sectionTitles[mode])
} else {
return sectionTitles[mode]
}
}
if (mode) {
@ -246,7 +254,7 @@ export default function Behaviours(props) {
<div className="w-full p-4 bg-white rounded shadow-xl dark:bg-gray-825">
<div className="flex justify-between w-full">
<h3 className="font-bold dark:text-gray-100">
{sectionTitles[mode] + (isRealtime() ? ' (last 30min)' : '')}
{sectionTitle() + (isRealtime() ? ' (last 30min)' : '')}
</h3>
{tabs()}
</div>

@ -50,6 +50,7 @@ export default function Properties(props) {
{name: 'average_revenue', label: 'Average', hiddenOnMobile: true}
]}
detailsLink={url.sitePath(site, `/custom-prop-values/${propKey}`)}
maybeHideDetails={true}
query={query}
color="bg-red-50"
colMinWidth={90}

@ -8,6 +8,7 @@ import * as api from '../../api'
import * as url from "../../util/url";
import numberFormatter from '../../util/number-formatter'
import { parseQuery } from '../../query'
import { specialTitleWhenGoalFilter } from "../behaviours/goal-conversions";
function PropsModal(props) {
const site = props.site
@ -83,7 +84,7 @@ function PropsModal(props) {
return (
<>
<h1 className="text-xl font-bold dark:text-gray-100">Custom Property breakdown</h1>
<h1 className="text-xl font-bold dark:text-gray-100">{ specialTitleWhenGoalFilter(query, 'Custom Property Breakdown') }</h1>
<div className="my-4 border-b border-gray-300"></div>
<main className="modal__content">

@ -1,6 +1,25 @@
import React from 'react';
import { Link } from 'react-router-dom'
function detailsIcon() {
return (
<svg
className="feather mr-1"
style={{marginTop: '-2px'}}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
{/* eslint-disable-next-line max-len */}
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
</svg>
)
}
export default function MoreLink({url, site, list, endpoint, className}) {
if (list.length > 0) {
return (
@ -10,20 +29,7 @@ export default function MoreLink({url, site, list, endpoint, className}) {
// eslint-disable-next-line max-len
className="leading-snug font-bold text-sm text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400 transition tracking-wide"
>
<svg
className="feather mr-1"
style={{marginTop: '-2px'}}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
{/* eslint-disable-next-line max-len */}
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
</svg>
{ detailsIcon() }
DETAILS
</Link>
</div>

@ -91,7 +91,12 @@ function ExternalLink({ item, externalLinkDest }) {
// * `onClick` - function with additional action to be taken when a list entry is clicked.
// * `detailsLink` - the pathname to the detailed view of this report. E.g.:
// `/dummy.site/pages`
// `/dummy.site/pages`. If this is given as input to the ListReport, the Details button
// will always be rendered.
// * `maybeHideDetails` - set this to `true` if the details button should be hidden on
// the condition that there are less than MAX_ITEMS entries in the list. (i.e . nothing
// more to show)
// * `externalLinkDest` - a function that takes a list item and returns an external url
// to navigate to. If this prop is given, an additional icon is rendered upon hovering
@ -168,7 +173,7 @@ export default function ListReport(props) {
{renderReportBody()}
</div>
{maybeRenderMoreLink()}
{maybeRenderDetailsLink()}
</div>
)
}
@ -297,8 +302,12 @@ export default function ListReport(props) {
)
}
function maybeRenderMoreLink() {
return props.detailsLink && !state.loading && <MoreLink url={props.detailsLink} list={state.list} />
function maybeRenderDetailsLink() {
const moreResultsAvailable = state.list.length >= MAX_ITEMS
const hideDetails = props.maybeHideDetails && !moreResultsAvailable
const showDetails = props.detailsLink && !state.loading && !hideDetails
return showDetails && <MoreLink className={'mt-2'} url={props.detailsLink} list={state.list} />
}
return (

Loading…
Cancel
Save