Skip to content

Commit

Permalink
fix(funnels): fix infinite scroll caused by scrollbar (#18848)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Nov 23, 2023
1 parent 7540489 commit fc0107f
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 57 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-dashboards--edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-dashboards--show.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions frontend/src/scenes/funnels/FunnelBarChart/FunnelBarChart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
table {
--bar-width: 0.5rem; // This should be overriden from React
--bar-row-height: 18rem;
--bar-padding-top: 1rem;
--bar-padding-bottom: 1.5rem;

width: 100%;
height: 100%;
Expand All @@ -20,8 +22,8 @@
border-bottom: 1px solid var(--border);

> td {
padding: 1.5rem 0;
padding-top: 1rem;
padding-top: var(--bar-padding-top);
padding-bottom: var(--bar-padding-bottom);
}
}

Expand All @@ -40,7 +42,7 @@
}

.StepBarLabels {
height: calc(var(--bar-row-height) - 3rem);
height: calc(var(--bar-row-height) - var(--bar-padding-top) - var(--bar-padding-bottom));
display: flex;
flex-direction: column-reverse;
align-items: flex-end;
Expand Down Expand Up @@ -68,7 +70,7 @@
align-items: flex-end;
gap: 0.125rem;
border-bottom: 1px solid var(--border);
height: calc(var(--bar-row-height) - 3rem);
height: calc(var(--bar-row-height) - var(--bar-padding-top) - var(--bar-padding-bottom));
padding: 0 1rem;

&:not(.StepBars--first) {
Expand Down
115 changes: 62 additions & 53 deletions frontend/src/scenes/funnels/FunnelBarChart/FunnelBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clsx from 'clsx'
import { useValues } from 'kea'
import { useResizeObserver } from 'lib/hooks/useResizeObserver'
import { useScrollable } from 'lib/hooks/useScrollable'
import { useMemo } from 'react'
import { useLayoutEffect, useState } from 'react'
import { insightLogic } from 'scenes/insights/insightLogic'

import { ChartParams } from '~/types'
Expand All @@ -29,7 +29,8 @@ export function FunnelBarChart({ showPersonsModal: showPersonsModalProp = true }
const vizRef = useFunnelTooltip(showPersonsModal)

const [scrollRef, [isScrollableLeft, isScrollableRight]] = useScrollable()
const { height } = useResizeObserver({ ref: vizRef })
const { height: availableHeight } = useResizeObserver({ ref: vizRef })
const [scrollbarHeightPx, setScrollbarHeightPx] = useState(0)

const seriesCount = visibleStepsWithConversionMetrics[0]?.nested_breakdown?.length ?? 0
const barWidthPx =
Expand All @@ -55,57 +56,24 @@ export function FunnelBarChart({ showPersonsModal: showPersonsModalProp = true }
? 96
: 192

const table = useMemo(() => {
/** Average conversion time is only shown if it's known for at least one step. */
// != is intentional to catch undefined too
const showTime = visibleStepsWithConversionMetrics.some((step) => step.average_conversion_time != null)
const barRowHeight = `calc(${height}px - 17px - 3rem - (1.75rem * ${showTime ? 3 : 2}) - 1px)`
useLayoutEffect(() => {
if (scrollRef.current) {
setScrollbarHeightPx(scrollRef.current.offsetHeight - scrollRef.current.clientHeight)
}
}, [availableHeight])

return (
<table
/* eslint-disable-next-line react/forbid-dom-props */
style={
{
'--bar-width': `${barWidthPx}px`,
'--bar-row-height': barRowHeight,
} as FunnelBarChartCSSProperties
}
>
<colgroup>
{visibleStepsWithConversionMetrics.map((_, i) => (
<col key={i} width={0} />
))}
<col width="100%" />
{/* The last column is meant to fill up leftover space. */}
</colgroup>
<tbody>
<tr>
<td>
<StepBarLabels />
</td>
{visibleStepsWithConversionMetrics.map((step, stepIndex) => (
<td key={stepIndex}>
<StepBars step={step} stepIndex={stepIndex} showPersonsModal={showPersonsModal} />
</td>
))}
</tr>
<tr>
<td />
{visibleStepsWithConversionMetrics.map((step, stepIndex) => (
<td key={stepIndex}>
<StepLegend
step={step}
stepIndex={stepIndex}
showTime={showTime}
showPersonsModal={showPersonsModal}
/>
</td>
))}
</tr>
</tbody>
</table>
)
}, [visibleStepsWithConversionMetrics, height])
/** Average conversion time is only shown if it's known for at least one step. */
// != is intentional to catch undefined too
const showTime = visibleStepsWithConversionMetrics.some((step) => step.average_conversion_time != null)

const stepLegendRows = showTime ? 4 : 3

// rows * (row height + gap between rows) - no gap for first row + padding top and bottom
const stepLegendHeightRem = stepLegendRows * (1.5 + 0.25) - 0.25 + 2 * 0.75
const borderHeightPx = 1

// available height - border - legend - (maybe) scrollbar
const barRowHeight = `calc(${availableHeight}px - ${borderHeightPx}px - ${stepLegendHeightRem}rem - ${scrollbarHeightPx}px)`

return (
<div
Expand All @@ -118,7 +86,48 @@ export function FunnelBarChart({ showPersonsModal: showPersonsModalProp = true }
data-attr="funnel-bar-graph"
>
<div className="scrollable__inner" ref={scrollRef}>
{table}
<table
/* eslint-disable-next-line react/forbid-dom-props */
style={
{
'--bar-width': `${barWidthPx}px`,
'--bar-row-height': barRowHeight,
} as FunnelBarChartCSSProperties
}
>
<colgroup>
{visibleStepsWithConversionMetrics.map((_, i) => (
<col key={i} width={0} />
))}
<col width="100%" />
{/* The last column is meant to fill up leftover space. */}
</colgroup>
<tbody>
<tr>
<td>
<StepBarLabels />
</td>
{visibleStepsWithConversionMetrics.map((step, stepIndex) => (
<td key={stepIndex}>
<StepBars step={step} stepIndex={stepIndex} showPersonsModal={showPersonsModal} />
</td>
))}
</tr>
<tr>
<td />
{visibleStepsWithConversionMetrics.map((step, stepIndex) => (
<td key={stepIndex}>
<StepLegend
step={step}
stepIndex={stepIndex}
showTime={showTime}
showPersonsModal={showPersonsModal}
/>
</td>
))}
</tr>
</tbody>
</table>
</div>
</div>
)
Expand Down

0 comments on commit fc0107f

Please sign in to comment.