Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable persons modal on funnel trends #5133

Merged
merged 19 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions frontend/src/lib/components/ChartFilter/ChartFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import {
PieChartOutlined,
TableOutlined,
} from '@ant-design/icons'
import { ChartDisplayType, FilterType, ViewType } from '~/types'
import { ChartDisplayType, FilterType, FunnelVizType, ViewType } from '~/types'
import { preflightLogic } from 'scenes/PreflightCheck/logic'

interface ChartFilterProps {
filters: FilterType
onChange: (chartFilter: ChartDisplayType) => void
onChange: (chartFilter: ChartDisplayType | FunnelVizType) => void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the addition of this type just confuses things, especially if they're going to be used interchangeably. My preferred approach would be to put everything in ChartDisplayType and do away with FunnelVizType, OR have e.g. ChartDisplayType.FUNNELS cover everything and have FunnelVizType make it more specific.

What do you think @mariusandra @alexkim205 ? I don't have a strong opinion here but feel like we should agree on a convention

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, I really think FunnelVizType should be removed. We already have ViewType.FUNNELS to describe funnels overall.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's where the typing will come from for funnel_viz_type, see this comment: #5133 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, FunnelVizType is the type of funnel visualization (since that's separate from overarching visualizations (like Trends or Funnels) )

Although, valid question whether ChartFilterProps, the top level interface should expect top level visualisation type or specific-to-funnels visualization type as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, @neilkakkar , ViewType includes Trends, Stickiness, Funnels, Retention, etc. and corresponds to overall type of query.

Then ChartDisplayType describes, for instance, linear line graph, cumulative line graph, bar chart, pie, etc. and seems like the logical place to distinguish between time to convert, steps, and historical trends as those are "types of visualization".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's also a little confusing to reuse ChartDisplayType for something like time conversion because that technically uses the ActionsLineGraphLinear display type and would also probably cause confusion on the frontend if we checked for insights === FUNNELS && display === ChartDisplayType.ActionsLineGraphLinear vs just funnel_viz_type === FunnelVizType.Trends/TimeConversion/whatever

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but also agree we should make our chart/display type system easier to navigate in general :o

disabled: boolean
}

export function ChartFilter({ filters, onChange, disabled }: ChartFilterProps): JSX.Element {
const { chartFilter } = useValues(chartFilterLogic)
const { setChartFilter } = useActions(chartFilterLogic)
const { preflight } = useValues(preflightLogic)

const linearDisabled = !!filters.session && filters.session === 'dist'
const cumulativeDisabled =
Expand Down Expand Up @@ -55,21 +57,28 @@ export function ChartFilter({ filters, onChange, disabled }: ChartFilterProps):

const options =
filters.insight === ViewType.FUNNELS
? [
{
value: ChartDisplayType.FunnelViz,
label: <Label icon={<OrderedListOutlined />}>Steps</Label>,
},
{
value: ChartDisplayType.ActionsLineGraphLinear,
label: (
<Label icon={<LineChartOutlined />}>
Trends
<WarningTag>BETA</WarningTag>
</Label>
),
},
]
? preflight?.is_clickhouse_enabled
? [
{
value: FunnelVizType.Steps,
label: <Label icon={<OrderedListOutlined />}>Steps</Label>,
},
{
value: FunnelVizType.Trends,
label: (
<Label icon={<LineChartOutlined />}>
Trends
<WarningTag>BETA</WarningTag>
</Label>
),
},
]
: [
{
value: FunnelVizType.Steps,
label: <Label icon={<OrderedListOutlined />}>Steps</Label>,
},
]
: [
{
label: 'Line Chart',
Expand Down Expand Up @@ -117,7 +126,7 @@ export function ChartFilter({ filters, onChange, disabled }: ChartFilterProps):
key="2"
defaultValue={filters.display || defaultDisplay}
value={chartFilter || defaultDisplay}
onChange={(value: ChartDisplayType) => {
onChange={(value: ChartDisplayType | FunnelVizType) => {
setChartFilter(value)
onChange(value)
}}
Expand Down
34 changes: 19 additions & 15 deletions frontend/src/lib/components/ChartFilter/chartFilterLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,47 @@ import { kea } from 'kea'
import { router } from 'kea-router'
import { objectsEqual } from 'lib/utils'
import { chartFilterLogicType } from './chartFilterLogicType'
import { ChartDisplayType, ViewType } from '~/types'
import { ChartDisplayType, FunnelVizType, ViewType } from '~/types'

export const chartFilterLogic = kea<chartFilterLogicType>({
actions: () => ({
setChartFilter: (filter: ChartDisplayType) => ({ filter }),
setChartFilter: (filter: ChartDisplayType | FunnelVizType) => ({ filter }),
}),
reducers: {
chartFilter: [
null as null | ChartDisplayType,
null as null | ChartDisplayType | FunnelVizType,
{
setChartFilter: (_, { filter }) => filter,
},
],
},
listeners: ({ values }) => ({
setChartFilter: () => {
const { display, ...searchParams } = router.values.searchParams // eslint-disable-line
setChartFilter: ({ filter }) => {
const { display, funnel_viz_type, ...searchParams } = router.values.searchParams // eslint-disable-line
const { pathname } = router.values.location
searchParams.display = values.chartFilter

if (!objectsEqual(display, values.chartFilter)) {
const isFunnelVizType = filter === 'steps' || filter === 'time_to_convert' || filter === 'trends'
if (isFunnelVizType) {
searchParams.funnel_viz_type = filter
searchParams.display = ChartDisplayType.FunnelViz
} else {
searchParams.display = values.chartFilter
}
liyiy marked this conversation as resolved.
Show resolved Hide resolved
if (
(!isFunnelVizType && !objectsEqual(display, values.chartFilter)) ||
(isFunnelVizType && !objectsEqual(funnel_viz_type, values.chartFilter))
) {
router.actions.replace(pathname, searchParams)
}
},
}),
urlToAction: ({ actions }) => ({
'/insights': (_, { display, insight }) => {
if (display) {
'/insights': (_, { display, insight, funnel_viz_type }) => {
if (display && !funnel_viz_type) {
actions.setChartFilter(display)
} else if (insight === ViewType.RETENTION) {
actions.setChartFilter(ChartDisplayType.ActionsTable)
} else if (insight === ViewType.FUNNELS) {
if (display === ChartDisplayType.FunnelsTimeToConvert) {
actions.setChartFilter(ChartDisplayType.FunnelsTimeToConvert)
} else {
actions.setChartFilter(ChartDisplayType.FunnelViz)
}
actions.setChartFilter(funnel_viz_type)
}
},
}),
Expand Down
1 change: 0 additions & 1 deletion frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const ACTIONS_BAR_CHART = 'ActionsBar'
export const ACTIONS_BAR_CHART_VALUE = 'ActionsBarValue'
export const PATHS_VIZ = 'PathsViz'
export const FUNNEL_VIZ = 'FunnelViz'
export const FUNNELS_TIME_TO_CONVERT = 'FunnelsTimeToConvert'

export enum OrganizationMembershipLevel {
Member = 1,
Expand Down
14 changes: 0 additions & 14 deletions frontend/src/scenes/dashboard/DashboardItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { ActionsBarValueGraph } from 'scenes/trends/viz'

import relativeTime from 'dayjs/plugin/relativeTime'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { FunnelHistogram } from 'scenes/funnels/FunnelHistogram'

dayjs.extend(relativeTime)

Expand Down Expand Up @@ -135,19 +134,6 @@ export const displayMap: Record<DisplayedType, DisplayProps> = {
).url
},
},
FunnelsTimeToConvert: {
className: 'funnel-time-to-convert',
element: FunnelHistogram,
icon: BarChartOutlined,
viewText: 'View time conversion',
link: ({ id, dashboard, name, filters }: DashboardItemType): string => {
return combineUrl(
`/insights`,
{ insight: ViewType.FUNNELS, ...filters },
{ fromItem: id, fromItemName: name, fromDashboard: dashboard }
).url
},
},
RetentionContainer: {
className: 'retention',
element: RetentionContainer,
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/scenes/funnels/FunnelCanvasLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// This file contains funnel-related components that are used in the general insights scope
import { useActions, useValues } from 'kea'
import { FUNNELS_TIME_TO_CONVERT, FUNNEL_VIZ } from 'lib/constants'
import { humanFriendlyDuration } from 'lib/utils'
import React from 'react'
import { Button } from 'antd'
import { insightLogic } from 'scenes/insights/insightLogic'
import { funnelLogic } from './funnelLogic'
import './FunnelCanvasLabel.scss'
import { chartFilterLogic } from 'lib/components/ChartFilter/chartFilterLogic'
import { ChartDisplayType } from '~/types'
import { FunnelVizType } from '~/types'

export function FunnelCanvasLabel(): JSX.Element | null {
const { stepsWithCount, histogramStep, totalConversionRate } = useValues(funnelLogic)
Expand All @@ -21,7 +20,7 @@ export function FunnelCanvasLabel(): JSX.Element | null {

return (
<div className="funnel-canvas-label">
{allFilters.display === FUNNEL_VIZ && (
{allFilters.funnel_viz_type === FunnelVizType.Steps && (
<>
<span className="text-muted-alt">Total conversion rate: </span>
<span>{totalConversionRate}%</span>
Expand All @@ -33,8 +32,8 @@ export function FunnelCanvasLabel(): JSX.Element | null {
<span className="text-muted-alt">Average time to convert: </span>
<Button
type="link"
disabled={allFilters.display === FUNNELS_TIME_TO_CONVERT}
onClick={() => setChartFilter(ChartDisplayType.FunnelsTimeToConvert)}
disabled={allFilters.funnel_viz_type === FunnelVizType.TimeToConvert}
onClick={() => setChartFilter(FunnelVizType.TimeToConvert)}
>
{humanFriendlyDuration(stepsWithCount[histogramStep]?.average_conversion_time)}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/funnels/FunnelHistogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { funnelLogic } from './funnelLogic'
import { Histogram } from 'scenes/insights/Histogram'
import { insightLogic } from 'scenes/insights/insightLogic'
import './FunnelHistogram.scss'
import { FUNNELS_TIME_TO_CONVERT } from 'lib/constants'
import { FunnelVizType } from '~/types'

export function FunnelHistogramHeader(): JSX.Element | null {
const { stepsWithCount, stepReference, histogramStepsDropdown } = useValues(funnelLogic)
const { changeHistogramStep } = useActions(funnelLogic)
const { allFilters } = useValues(insightLogic)

if (allFilters.display !== FUNNELS_TIME_TO_CONVERT) {
if (allFilters.funnel_viz_type !== FunnelVizType.TimeToConvert) {
return null
}

Expand Down
32 changes: 24 additions & 8 deletions frontend/src/scenes/funnels/FunnelViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import FunnelGraph from 'funnel-graph-js'
import { Loading, humanFriendlyDuration } from 'lib/utils'
import { useActions, useValues, BindLogic } from 'kea'
import { funnelLogic } from './funnelLogic'
import { ACTIONS_LINE_GRAPH_LINEAR, FEATURE_FLAGS } from 'lib/constants'
import { FEATURE_FLAGS } from 'lib/constants'
import { LineGraph } from 'scenes/insights/LineGraph'
import { FunnelBarGraph } from './FunnelBarGraph'
import { router } from 'kea-router'
import { InputNumber } from 'antd'
import { InputNumber, Row } from 'antd'
import { preflightLogic } from 'scenes/PreflightCheck/logic'
import { ChartDisplayType, ChartParams } from '~/types'
import { ChartParams, FunnelVizType } from '~/types'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FunnelHistogram } from './FunnelHistogram'
import { personsModalLogic } from 'scenes/trends/personsModalLogic'
import { FunnelEmptyState } from 'scenes/insights/EmptyStates'

import './FunnelViz.scss'
Expand All @@ -36,6 +37,7 @@ export function FunnelViz({
areFiltersValid,
} = useValues(logic)
const { loadResults: loadFunnel, loadConversionWindow } = useActions(logic)
const { loadPeople } = useActions(personsModalLogic)
const {
hashParams: { fromItem },
} = useValues(router)
Expand All @@ -49,7 +51,7 @@ export function FunnelViz({
!steps ||
steps.length === 0 ||
featureFlags[FEATURE_FLAGS.FUNNEL_BAR_VIZ] ||
filters.display === ACTIONS_LINE_GRAPH_LINEAR
filters.funnel_viz_type === FunnelVizType.Trends
) {
return
}
Expand Down Expand Up @@ -113,10 +115,10 @@ export function FunnelViz({
)
}

if (filters.display === ACTIONS_LINE_GRAPH_LINEAR) {
if (filters.funnel_viz_type === FunnelVizType.Trends) {
return steps && steps.length > 0 && steps[0].labels ? (
<>
<div style={{ position: 'absolute', marginTop: -20, textAlign: 'center', width: '90%' }}>
<Row style={{ marginTop: -16, justifyContent: 'center' }}>
{preflight?.is_clickhouse_enabled && (
<>
converted within&nbsp;
Expand All @@ -131,7 +133,7 @@ export function FunnelViz({
</>
)}
% converted from first to last step
</div>
</Row>
<LineGraph
data-attr="trend-line-graph-funnel"
type="line"
Expand All @@ -142,11 +144,25 @@ export function FunnelViz({
dashboardItemId={dashboardItemId || fromItem}
inSharedMode={inSharedMode}
percentage={true}
onClick={
dashboardItemId
? null
mariusandra marked this conversation as resolved.
Show resolved Hide resolved
: (point) => {
loadPeople({
action: { id: point.index, name: point.label, properties: [], type: 'actions' },
label: `Persons converted on ${point.label}`,
date_from: point.day,
date_to: point.day,
filters: filters,
saveOriginal: true,
})
}
}
/>
</>
) : null
}
if (featureFlags[FEATURE_FLAGS.FUNNEL_BAR_VIZ] && filters.display == ChartDisplayType.FunnelsTimeToConvert) {
if (featureFlags[FEATURE_FLAGS.FUNNEL_BAR_VIZ] && filters.funnel_viz_type == FunnelVizType.TimeToConvert) {
return timeConversionBins && timeConversionBins.length > 0 ? <FunnelHistogram /> : null
}

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/scenes/funnels/funnelLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EntityTypes,
FilterType,
FunnelStep,
ChartDisplayType,
FunnelVizType,
FunnelResult,
PathType,
PersonType,
Expand Down Expand Up @@ -100,6 +100,8 @@ export const cleanFunnelParams = (filters: Partial<FilterType>): FilterType => {
...(filters.funnel_step ? { funnel_step: filters.funnel_step } : {}),
...(filters.funnel_viz_type ? { funnel_viz_type: filters.funnel_viz_type } : {}),
...(filters.funnel_step ? { funnel_to_step: filters.funnel_step } : {}),
...(filters.entrance_period_start ? { entrance_period_start: filters.entrance_period_start } : {}),
liyiy marked this conversation as resolved.
Show resolved Hide resolved
...(filters.drop_off ? { drop_off: filters.drop_off } : {}),
interval: autocorrectInterval(filters),
breakdown: filters.breakdown || undefined,
breakdown_type: filters.breakdown_type || undefined,
Expand Down Expand Up @@ -179,12 +181,11 @@ export const funnelLogic = kea<funnelLogicType<LoadedRawFunnelResults, TimeStepO
}

async function loadBinsResults(): Promise<[number, number][]> {
if (filters.display === ChartDisplayType.FunnelsTimeToConvert) {
if (filters.funnel_viz_type === FunnelVizType.TimeToConvert) {
try {
const binsResult = await pollFunnel<[number, number][]>({
...apiParams,
...(refresh ? { refresh } : {}),
funnel_viz_type: 'time_to_convert',
funnel_to_step: histogramStep,
})
return binsResult.result
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/funnels/funnelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ export function getSeriesPositionName(
}

export function humanizeStepCount(count: number): string {
return count > 9999 ? humanizeNumber(count, 2) : count.toLocaleString()
return count > 9999 ? humanizeNumber(count, 2) : count?.toLocaleString()
}
Loading