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

fix(funnels): replace antd correlation modal with lemon ui #20801

Merged
merged 6 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('funnelCorrelationDetailsLogic', () => {
describe('correlationMatrixAndScore', () => {
it('returns calculated values based on selected details', async () => {
await expectLogic(logic, () =>
logic.actions.setFunnelCorrelationDetails({
logic.actions.openCorrelationDetailsModal({
event: { event: 'some event', elements: [], properties: {} },
success_people_url: '',
failure_people_url: '',
Expand Down
24 changes: 16 additions & 8 deletions frontend/src/scenes/funnels/funnelCorrelationDetailsLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,31 @@ export const funnelCorrelationDetailsLogic = kea<funnelCorrelationDetailsLogicTy
})),

actions({
setFunnelCorrelationDetails: (payload: FunnelCorrelation | null) => ({ payload }),
openCorrelationDetailsModal: (payload: FunnelCorrelation) => ({ payload }),
closeCorrelationDetailsModal: true,
}),

reducers({
funnelCorrelationDetails: [
correlationDetailsModalOpen: [
false,
{
openCorrelationDetailsModal: () => true,
closeCorrelationDetailsModal: () => false,
},
],
correlationDetails: [
null as null | FunnelCorrelation,
{
setFunnelCorrelationDetails: (_, { payload }) => payload,
openCorrelationDetailsModal: (_, { payload }) => payload,
},
],
}),

selectors({
correlationMatrixAndScore: [
(s) => [s.funnelCorrelationDetails, s.steps],
(s) => [s.correlationDetails, s.steps],
(
funnelCorrelationDetails,
correlationDetails,
steps
): {
truePositive: number
Expand All @@ -41,7 +49,7 @@ export const funnelCorrelationDetailsLogic = kea<funnelCorrelationDetailsLogicTy
correlationScore: number
correlationScoreStrength: 'weak' | 'moderate' | 'strong' | null
} => {
if (!funnelCorrelationDetails) {
if (!correlationDetails) {
return {
truePositive: 0,
falsePositive: 0,
Expand All @@ -54,8 +62,8 @@ export const funnelCorrelationDetailsLogic = kea<funnelCorrelationDetailsLogicTy

const successTotal = steps[steps.length - 1].count
const failureTotal = steps[0].count - successTotal
const success = funnelCorrelationDetails.success_count
const failure = funnelCorrelationDetails.failure_count
const success = correlationDetails.success_count
const failure = correlationDetails.failure_count

const truePositive = success // has property, converted
const falseNegative = failure // has property, but dropped off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export const EventCorrelationActionsCell = ({ record }: { record: FunnelCorrelat
const { excludeEventFromProject, excludeEventPropertyFromProject } = useActions(
funnelCorrelationLogic(insightProps)
)
const { setFunnelCorrelationDetails } = useActions(funnelCorrelationDetailsLogic(insightProps))
const { openCorrelationDetailsModal } = useActions(funnelCorrelationDetailsLogic(insightProps))
const components = record.event.event.split('::')

const buttons: CorrelationActionsCellComponentButtonProps[] = [
...(record.result_type === FunnelCorrelationResultsType.Events
? [
{
children: 'View correlation details',
onClick: () => setFunnelCorrelationDetails(record),
onClick: () => openCorrelationDetailsModal(record),
},
]
: []),
Expand All @@ -56,13 +56,13 @@ export const PropertyCorrelationActionsCell = ({ record }: { record: FunnelCorre
const { insightProps } = useValues(insightLogic)
const { isPropertyExcludedFromProject } = useValues(funnelPropertyCorrelationLogic(insightProps))
const { excludePropertyFromProject } = useActions(funnelPropertyCorrelationLogic(insightProps))
const { setFunnelCorrelationDetails } = useActions(funnelCorrelationDetailsLogic(insightProps))
const { openCorrelationDetailsModal } = useActions(funnelCorrelationDetailsLogic(insightProps))
const propertyName = (record.event.event || '').split('::')[0]

const buttons: CorrelationActionsCellComponentButtonProps[] = [
{
children: 'View correlation details',
onClick: () => setFunnelCorrelationDetails(record),
onClick: () => openCorrelationDetailsModal(record),
},
{
children: 'Exclude property from project',
Expand Down
79 changes: 36 additions & 43 deletions frontend/src/scenes/insights/views/Funnels/CorrelationMatrix.scss
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
.correlation-matrix {
.ant-modal-body {
display: flex;
justify-content: center;
}

.correlation-table-wrapper {
table {
margin: 0 auto;
border-spacing: 0;
border-collapse: separate;
border: 1px solid var(--border);
border-radius: var(--radius);

td {
padding: 0.5rem 1rem;
text-align: center;
border-top: 1px solid var(--border);
border-left: 1px solid var(--border);

.percentage {
padding-bottom: 0.25rem;
font-weight: bold;
}
.correlation-table-wrapper {
table {
margin: 0 auto;
border-spacing: 0;
border-collapse: separate;
border: 1px solid var(--border);
border-radius: var(--radius);

td {
padding: 0.5rem 1rem;
text-align: center;
border-top: 1px solid var(--border);
border-left: 1px solid var(--border);

.percentage {
padding-bottom: 0.25rem;
font-weight: bold;
}

&:first-child {
border-left: none;
}
&:first-child {
border-left: none;
}
}

.table-title {
color: var(--muted-alt);
.table-title {
color: var(--muted-alt);

td {
border-top: none;
}
td {
border-top: none;
}
}

thead,
.horizontal-header {
font-weight: bold;
color: var(--muted);
text-transform: uppercase;
background-color: var(--antd-table-background-dark);
}
thead,
.horizontal-header {
font-weight: bold;
color: var(--muted);
text-transform: uppercase;
background-color: var(--mid);
}

tbody {
td:not(.horizontal-header) {
text-align: right;
}
tbody {
td:not(.horizontal-header) {
text-align: right;
}
}
}
Expand Down
44 changes: 18 additions & 26 deletions frontend/src/scenes/insights/views/Funnels/CorrelationMatrix.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './CorrelationMatrix.scss'

import { IconCheckCircle } from '@posthog/icons'
import { Button, Modal } from 'antd'
import { LemonButton, LemonModal } from '@posthog/lemon-ui'
import clsx from 'clsx'
import { useActions, useValues } from 'kea'
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
Expand All @@ -22,22 +22,20 @@ import { FunnelCorrelationResultsType, FunnelCorrelationType } from '~/types'
export function CorrelationMatrix(): JSX.Element {
const { insightProps } = useValues(insightLogic)
const { correlationsLoading } = useValues(funnelCorrelationLogic(insightProps))
const { funnelCorrelationDetails, correlationMatrixAndScore } = useValues(
const { correlationDetailsModalOpen, correlationDetails, correlationMatrixAndScore } = useValues(
funnelCorrelationDetailsLogic(insightProps)
)
const { setFunnelCorrelationDetails } = useActions(funnelCorrelationDetailsLogic(insightProps))
const { closeCorrelationDetailsModal } = useActions(funnelCorrelationDetailsLogic(insightProps))
const { openCorrelationPersonsModal } = useActions(funnelPersonsModalLogic(insightProps))

const actor = funnelCorrelationDetails?.result_type === FunnelCorrelationResultsType.Events ? 'event' : 'property'
const actor = correlationDetails?.result_type === FunnelCorrelationResultsType.Events ? 'event' : 'property'
const action =
funnelCorrelationDetails?.result_type === FunnelCorrelationResultsType.Events
? 'performed event'
: 'have property'
correlationDetails?.result_type === FunnelCorrelationResultsType.Events ? 'performed event' : 'have property'

let displayName = <></>

if (funnelCorrelationDetails) {
const { first_value, second_value } = parseDisplayNameForCorrelation(funnelCorrelationDetails)
if (correlationDetails) {
const { first_value, second_value } = parseDisplayNameForCorrelation(correlationDetails)
displayName = (
<>
<PropertyKeyInfo value={first_value} />
Expand All @@ -63,24 +61,19 @@ export function CorrelationMatrix(): JSX.Element {
<IconErrorOutline className="text-danger" />
)

const dismiss = (): void => setFunnelCorrelationDetails(null)

return (
<Modal
className="correlation-matrix"
visible={!!funnelCorrelationDetails}
onCancel={dismiss}
destroyOnClose
footer={<Button onClick={dismiss}>Dismiss</Button>}
width={600}
<LemonModal
isOpen={correlationDetailsModalOpen}
onClose={closeCorrelationDetailsModal}
footer={<LemonButton onClick={closeCorrelationDetailsModal}>Dismiss</LemonButton>}
title="Correlation details"
>
<div className="correlation-table-wrapper">
{correlationsLoading ? (
<div className="mt-4 text-center">
<Spinner className="text-4xl" />
</div>
) : funnelCorrelationDetails ? (
) : correlationDetails ? (
<>
<p className="text-muted-alt mb-4">
The table below displays the correlation details for users who {action} <b>{displayName}</b>
Expand All @@ -93,7 +86,7 @@ export function CorrelationMatrix(): JSX.Element {
</tr>
<tr>
<td>
{funnelCorrelationDetails?.result_type === FunnelCorrelationResultsType.Events
{correlationDetails?.result_type === FunnelCorrelationResultsType.Events
? 'Performed event'
: 'Has property'}
</td>
Expand All @@ -119,7 +112,7 @@ export function CorrelationMatrix(): JSX.Element {
) : (
<Link
onClick={() => {
openCorrelationPersonsModal(funnelCorrelationDetails, true)
openCorrelationPersonsModal(correlationDetails, true)
}}
>
{pluralize(truePositive, 'user', undefined, true)}
Expand All @@ -141,7 +134,7 @@ export function CorrelationMatrix(): JSX.Element {
) : (
<Link
onClick={() => {
openCorrelationPersonsModal(funnelCorrelationDetails, false)
openCorrelationPersonsModal(correlationDetails, false)
}}
>
{pluralize(falseNegative, 'user', undefined, true)}
Expand Down Expand Up @@ -188,9 +181,8 @@ export function CorrelationMatrix(): JSX.Element {
</tbody>
</table>
<div className="mt-4 text-center">
{capitalizeFirstLetter(funnelCorrelationDetails?.result_type || '')} <b>{displayName}</b>{' '}
has a{' '}
{funnelCorrelationDetails?.correlation_type === FunnelCorrelationType.Success ? (
{capitalizeFirstLetter(correlationDetails?.result_type || '')} <b>{displayName}</b> has a{' '}
{correlationDetails?.correlation_type === FunnelCorrelationType.Success ? (
<Tooltip
title={`Positive correlation means this ${actor} is correlated with a successful conversion.`}
>
Expand Down Expand Up @@ -231,6 +223,6 @@ export function CorrelationMatrix(): JSX.Element {
</LemonBanner>
)}
</div>
</Modal>
</LemonModal>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export function FunnelCorrelationTable(): JSX.Element | null {
? 'have this event property'
: 'do this event'}
</div>
<CorrelationMatrix />
</>
)
}
Expand Down Expand Up @@ -233,6 +232,7 @@ export function FunnelCorrelationTable(): JSX.Element | null {
</div>
</span>
</span>
<CorrelationMatrix />
<ConfigProvider
renderEmpty={() =>
loadedEventCorrelationsTableOnce ? (
Expand Down
Loading