From e5929e981884aa2e4a25e7eb14e4f07dfde05cf7 Mon Sep 17 00:00:00 2001 From: Delirium Date: Thu, 4 Apr 2024 17:53:49 +0200 Subject: [PATCH] feat ui: add funnel bar focusing for issues (#2037) --- .../Funnels/FunnelWidget/FunnelBar.tsx | 19 +++++- .../Funnels/FunnelWidget/FunnelWidget.tsx | 67 +++++++++++++------ 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/frontend/app/components/Funnels/FunnelWidget/FunnelBar.tsx b/frontend/app/components/Funnels/FunnelWidget/FunnelBar.tsx index cb2082d9c..b3aef756c 100644 --- a/frontend/app/components/Funnels/FunnelWidget/FunnelBar.tsx +++ b/frontend/app/components/Funnels/FunnelWidget/FunnelBar.tsx @@ -5,11 +5,15 @@ import { Icon } from 'UI'; interface Props { filter: any; + index?: number; + focusStage?: (index: number, isFocused: boolean) => void + focusedFilter?: number | null } function FunnelBar(props: Props) { - const { filter } = props; + const { filter, index, focusStage, focusedFilter } = props; + const isFocused = focusedFilter && index ? focusedFilter === index - 1 : false; return (
@@ -38,6 +42,19 @@ function FunnelBar(props: Props) { {filter.completedPercentageTotal}%
+
focusStage?.(index! - 1, filter.isActive)} + className={'hover:border border-red-lightest'} + />
{/* @ts-ignore */} diff --git a/frontend/app/components/Funnels/FunnelWidget/FunnelWidget.tsx b/frontend/app/components/Funnels/FunnelWidget/FunnelWidget.tsx index 814a3a734..5feefb888 100644 --- a/frontend/app/components/Funnels/FunnelWidget/FunnelWidget.tsx +++ b/frontend/app/components/Funnels/FunnelWidget/FunnelWidget.tsx @@ -3,7 +3,7 @@ import Widget from 'App/mstore/types/widget'; import Funnelbar, { UxTFunnelBar } from "./FunnelBar"; import cn from 'classnames'; import stl from './FunnelWidget.module.css'; -import { useObserver } from 'mobx-react-lite'; +import { observer } from 'mobx-react-lite'; import { NoContent, Icon } from 'UI'; import { useModal } from 'App/components/Modal'; @@ -13,7 +13,8 @@ interface Props { data: any; } function FunnelWidget(props: Props) { - const { metric, isWidget = false, data } = props; + const [focusedFilter, setFocusedFilter] = React.useState(null); + const { isWidget = false, data } = props; const funnel = data.funnel || { stages: [] }; const totalSteps = funnel.stages.length; const stages = isWidget ? [...funnel.stages.slice(0, 1), funnel.stages[funnel.stages.length - 1]] : funnel.stages; @@ -29,7 +30,24 @@ function FunnelWidget(props: Props) { } }, []); - return useObserver(() => ( + const focusStage = (index: number) => { + funnel.stages.forEach((s, i) => { + // turning on all filters if one was focused already + if (focusedFilter === index) { + s.updateKey('isActive', true) + setFocusedFilter(null) + } else { + setFocusedFilter(index) + if (i === index) { + s.updateKey('isActive', true) + } else { + s.updateKey('isActive', false) + } + } + }) + } + + return ( { !isWidget && ( stages.map((filter: any, index: any) => ( - + )) )} @@ -82,11 +107,11 @@ function FunnelWidget(props: Props) {
{funnel.totalDropDueToIssues > 0 &&
{funnel.totalDropDueToIssues} sessions dropped due to issues.
} - )); + ); } -export function EmptyStage({ total }: any) { - return useObserver( () => ( +export const EmptyStage = observer(({ total }: any) => { + return (
@@ -94,42 +119,40 @@ export function EmptyStage({ total }: any) {
- )) -} + ) +}) -export function Stage({ stage, index, isWidget, uxt }: any) { - return useObserver(() => - stage ? ( +export const Stage = observer(({ stage, index, isWidget, uxt, focusStage, focusedFilter }: any) => { + return stage ? (
- {!uxt ? : } + {!uxt ? : } {!isWidget && !uxt && }
) : ( <> ) - ); -} +}) -export function IndexNumber({ index }: any) { +export const IndexNumber = observer(({ index }: any) => { return (
{index === 0 ? : index}
); -} +}) -function BarActions({ bar }: any) { - return useObserver(() => ( +const BarActions = observer(({ bar }: any) => { + return (
- )) -} + ) +}) -export default FunnelWidget; +export default observer(FunnelWidget);