Skip to content

Commit

Permalink
separate funnel correlation into sub-components
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Apr 3, 2023
1 parent aff29f2 commit 90df0a0
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 125 deletions.
8 changes: 3 additions & 5 deletions frontend/src/queries/nodes/InsightViz/InsightContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import {
import { PathCanvasLabel } from 'scenes/paths/PathsLabel'
import { InsightLegend } from 'lib/components/InsightLegend/InsightLegend'
import { InsightLegendButtonDataExploration } from 'lib/components/InsightLegend/InsightLegendButton'
// import { FunnelCorrelation } from './views/Funnels/FunnelCorrelation'
// import { AlertMessage } from 'lib/lemon-ui/AlertMessage'
import { ComputationTimeWithRefresh } from './ComputationTimeWithRefresh'
import { FunnelInsightDataExploration } from 'scenes/insights/views/Funnels/FunnelInsight'
import { FunnelStepsTableDataExploration } from 'scenes/insights/views/Funnels/FunnelStepsTable'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { FunnelCorrelation } from 'scenes/insights/views/Funnels/FunnelCorrelation'

const VIEW_MAP = {
[`${InsightType.TRENDS}`]: <TrendInsight view={InsightType.TRENDS} />,
Expand All @@ -49,7 +49,7 @@ const VIEW_MAP = {
export function InsightContainer({
disableHeader,
disableTable,
// disableCorrelationTable,
disableCorrelationTable,
disableLastComputation,
insightMode,
context,
Expand Down Expand Up @@ -240,9 +240,7 @@ export function InsightContainer({
</div>
</Card>
{renderTable()}
{/* {!disableCorrelationTable && activeView === InsightType.FUNNELS && (
<FunnelCorrelation />
)} */}
{!disableCorrelationTable && activeView === InsightType.FUNNELS && <FunnelCorrelation />}
</>
)
}
132 changes: 12 additions & 120 deletions frontend/src/scenes/insights/views/Funnels/FunnelCorrelation.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
import { Card } from 'antd'
import { CommentOutlined } from '@ant-design/icons'
import { useActions, useValues } from 'kea'
import { useRef } from 'react'
import { useValues } from 'kea'
import { funnelLogic } from 'scenes/funnels/funnelLogic'
import './FunnelCorrelation.scss'
import { IconClose, IconFeedbackWarning } from 'lib/lemon-ui/icons'
import { CloseOutlined } from '@ant-design/icons'
import { AvailableFeature } from '~/types'
import { insightLogic } from 'scenes/insights/insightLogic'
import { FunnelCorrelationTable } from './FunnelCorrelationTable'
import { FunnelPropertyCorrelationTable } from './FunnelPropertyCorrelationTable'
import { LemonButton, LemonTextArea } from '@posthog/lemon-ui'
import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'
import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'
import { FunnelCorrelationSkewWarning } from './FunnelCorrelationSkewWarning'
import { FunnelCorrelationFeedbackForm } from './FunnelCorrelationFeedbackForm'

export const FunnelCorrelation = (): JSX.Element | null => {
const { insightProps } = useValues(insightLogic)
const {
isSkewed,
steps,
correlationFeedbackHidden,
correlationDetailedFeedbackVisible,
correlationFeedbackRating,
} = useValues(funnelLogic(insightProps))
const {
sendCorrelationAnalysisFeedback,
hideSkewWarning,
hideCorrelationAnalysisFeedback,
setCorrelationFeedbackRating,
setCorrelationDetailedFeedback,
} = useActions(funnelLogic(insightProps))
const { insightProps, isUsingDataExploration } = useValues(insightLogic)
const { steps: legacySteps } = useValues(funnelLogic(insightProps))
const { steps } = useValues(funnelDataLogic(insightProps))

const detailedFeedbackRef = useRef<HTMLTextAreaElement>(null)

if (steps.length <= 1) {
if (isUsingDataExploration ? steps.length <= 1 : legacySteps.length <= 1) {
return null
}

Expand All @@ -41,101 +24,10 @@ export const FunnelCorrelation = (): JSX.Element | null => {
<h2 className="my-4">Correlation analysis</h2>
<PayGateMini feature={AvailableFeature.CORRELATION_ANALYSIS}>
<div className="funnel-correlation">
{isSkewed && (
<Card className="skew-warning">
<h4>
<IconFeedbackWarning
style={{ fontSize: 24, marginRight: 4, color: 'var(--warning)' }}
/>{' '}
Adjust your funnel definition to improve correlation analysis
<CloseOutlined className="close-button" onClick={hideSkewWarning} />
</h4>
<div>
<b>Tips for adjusting your funnel:</b>
<ol>
<li>
Adjust your first funnel step to be more specific. For example, choose a page or
an event that occurs less frequently.
</li>
<li>Choose an event that happens more frequently for subsequent funnels steps.</li>
</ol>
</div>
</Card>
)}

<FunnelCorrelationTable />

{/* Feedback Form */}
{!correlationFeedbackHidden && (
<div className="border rounded p-4 space-y-2 mt-4">
<div className="flex items-center justify-between">
<h4 className="text-muted-alt">
<CommentOutlined style={{ marginRight: 4 }} />
Was this correlation analysis report useful?
</h4>
<div className="flex items-center gap-2">
{!!correlationFeedbackRating && (
<i className="text-success mr-2">Thanks for your feedback!</i>
)}
{(
[
[5, '😍'],
[4, '😀'],
[3, '😴'],
[2, '😔'],
[1, '👎'],
] as const
).map((content, index) => (
<LemonButton
key={index}
active={correlationFeedbackRating === content[0]}
onClick={() => {
if (correlationFeedbackRating === content[0]) {
setCorrelationFeedbackRating(0)
} else {
setCorrelationFeedbackRating(content[0])
setTimeout(() => detailedFeedbackRef.current?.focus(), 100)
}
}}
>
{content[1]}
</LemonButton>
))}
<LemonButton
icon={<IconClose />}
onClick={hideCorrelationAnalysisFeedback}
status="stealth"
/>
</div>
</div>
{correlationDetailedFeedbackVisible ? (
<>
<form onSubmit={sendCorrelationAnalysisFeedback} className="space-y-2">
<LemonTextArea
onBlur={(e) => setCorrelationDetailedFeedback(e.target.value)}
placeholder="Optional. Help us by sharing details around your experience..."
ref={detailedFeedbackRef}
onPressCmdEnter={() => {
detailedFeedbackRef.current?.blur()
sendCorrelationAnalysisFeedback()
}}
/>
<div className="flex justify-end">
<LemonButton
data-attr="correlation-analysis-share-feedback"
type="primary"
htmlType="submit"
>
Share feedback
</LemonButton>
</div>
</form>
</>
) : null}
</div>
)}

<FunnelPropertyCorrelationTable />
{!isUsingDataExploration && <FunnelCorrelationSkewWarning />}
{!isUsingDataExploration && <FunnelCorrelationTable />}
{!isUsingDataExploration && <FunnelCorrelationFeedbackForm />}
{!isUsingDataExploration && <FunnelPropertyCorrelationTable />}
</div>
</PayGateMini>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { useRef } from 'react'
import { useActions, useValues } from 'kea'

import { insightLogic } from 'scenes/insights/insightLogic'
import { funnelLogic } from 'scenes/funnels/funnelLogic'

import { LemonButton, LemonTextArea } from '@posthog/lemon-ui'
import { IconClose } from 'lib/lemon-ui/icons'
import { CommentOutlined } from '@ant-design/icons'

export const FunnelCorrelationFeedbackForm = (): JSX.Element | null => {
const { insightProps } = useValues(insightLogic)
const { correlationFeedbackHidden, correlationDetailedFeedbackVisible, correlationFeedbackRating } = useValues(
funnelLogic(insightProps)
)
const {
sendCorrelationAnalysisFeedback,
hideCorrelationAnalysisFeedback,
setCorrelationFeedbackRating,
setCorrelationDetailedFeedback,
} = useActions(funnelLogic(insightProps))

const detailedFeedbackRef = useRef<HTMLTextAreaElement>(null)

if (correlationFeedbackHidden) {
return null
}

return (
<div className="border rounded p-4 space-y-2 mt-4">
<div className="flex items-center justify-between">
<h4 className="text-muted-alt">
<CommentOutlined style={{ marginRight: 4 }} />
Was this correlation analysis report useful?
</h4>
<div className="flex items-center gap-2">
{!!correlationFeedbackRating && <i className="text-success mr-2">Thanks for your feedback!</i>}
{(
[
[5, '😍'],
[4, '😀'],
[3, '😴'],
[2, '😔'],
[1, '👎'],
] as const
).map((content, index) => (
<LemonButton
key={index}
active={correlationFeedbackRating === content[0]}
onClick={() => {
if (correlationFeedbackRating === content[0]) {
setCorrelationFeedbackRating(0)
} else {
setCorrelationFeedbackRating(content[0])
setTimeout(() => detailedFeedbackRef.current?.focus(), 100)
}
}}
>
{content[1]}
</LemonButton>
))}
<LemonButton icon={<IconClose />} onClick={hideCorrelationAnalysisFeedback} status="stealth" />
</div>
</div>
{correlationDetailedFeedbackVisible ? (
<>
<form onSubmit={sendCorrelationAnalysisFeedback} className="space-y-2">
<LemonTextArea
onBlur={(e) => setCorrelationDetailedFeedback(e.target.value)}
placeholder="Optional. Help us by sharing details around your experience..."
ref={detailedFeedbackRef}
onPressCmdEnter={() => {
detailedFeedbackRef.current?.blur()
sendCorrelationAnalysisFeedback()
}}
/>
<div className="flex justify-end">
<LemonButton
data-attr="correlation-analysis-share-feedback"
type="primary"
htmlType="submit"
>
Share feedback
</LemonButton>
</div>
</form>
</>
) : null}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useActions, useValues } from 'kea'
import { Card } from 'antd'

import { insightLogic } from 'scenes/insights/insightLogic'
import { funnelLogic } from 'scenes/funnels/funnelLogic'

import { IconFeedbackWarning } from 'lib/lemon-ui/icons'
import { CloseOutlined } from '@ant-design/icons'

export const FunnelCorrelationSkewWarning = (): JSX.Element | null => {
const { insightProps } = useValues(insightLogic)
const { isSkewed } = useValues(funnelLogic(insightProps))
const { hideSkewWarning } = useActions(funnelLogic(insightProps))

if (!isSkewed) {
return null
}

return (
<Card className="skew-warning">
<h4>
<IconFeedbackWarning style={{ fontSize: 24, marginRight: 4, color: 'var(--warning)' }} /> Adjust your
funnel definition to improve correlation analysis
<CloseOutlined className="close-button" onClick={hideSkewWarning} />
</h4>
<div>
<b>Tips for adjusting your funnel:</b>
<ol>
<li>
Adjust your first funnel step to be more specific. For example, choose a page or an event that
occurs less frequently.
</li>
<li>Choose an event that happens more frequently for subsequent funnels steps.</li>
</ol>
</div>
</Card>
)
}

0 comments on commit 90df0a0

Please sign in to comment.