feat ui: add funnel bar focusing for issues (#2037)
This commit is contained in:
parent
7d82b4a04c
commit
e5929e9818
2 changed files with 63 additions and 23 deletions
|
|
@ -5,11 +5,15 @@ import { Icon } from 'UI';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
filter: any;
|
filter: any;
|
||||||
|
index?: number;
|
||||||
|
focusStage?: (index: number, isFocused: boolean) => void
|
||||||
|
focusedFilter?: number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
function FunnelBar(props: Props) {
|
function FunnelBar(props: Props) {
|
||||||
const { filter } = props;
|
const { filter, index, focusStage, focusedFilter } = props;
|
||||||
|
|
||||||
|
const isFocused = focusedFilter && index ? focusedFilter === index - 1 : false;
|
||||||
return (
|
return (
|
||||||
<div className="w-full mb-4">
|
<div className="w-full mb-4">
|
||||||
<FunnelStepText filter={filter} />
|
<FunnelStepText filter={filter} />
|
||||||
|
|
@ -38,6 +42,19 @@ function FunnelBar(props: Props) {
|
||||||
{filter.completedPercentageTotal}%
|
{filter.completedPercentageTotal}%
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: `${100.1 - filter.completedPercentageTotal}%`,
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
backgroundColor: isFocused ? 'rgba(204, 0, 0, 0.3)' : '#f5f5f5',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
onClick={() => focusStage?.(index! - 1, filter.isActive)}
|
||||||
|
className={'hover:border border-red-lightest'}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between py-2">
|
<div className="flex justify-between py-2">
|
||||||
{/* @ts-ignore */}
|
{/* @ts-ignore */}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import Widget from 'App/mstore/types/widget';
|
||||||
import Funnelbar, { UxTFunnelBar } from "./FunnelBar";
|
import Funnelbar, { UxTFunnelBar } from "./FunnelBar";
|
||||||
import cn from 'classnames';
|
import cn from 'classnames';
|
||||||
import stl from './FunnelWidget.module.css';
|
import stl from './FunnelWidget.module.css';
|
||||||
import { useObserver } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { NoContent, Icon } from 'UI';
|
import { NoContent, Icon } from 'UI';
|
||||||
import { useModal } from 'App/components/Modal';
|
import { useModal } from 'App/components/Modal';
|
||||||
|
|
||||||
|
|
@ -13,7 +13,8 @@ interface Props {
|
||||||
data: any;
|
data: any;
|
||||||
}
|
}
|
||||||
function FunnelWidget(props: Props) {
|
function FunnelWidget(props: Props) {
|
||||||
const { metric, isWidget = false, data } = props;
|
const [focusedFilter, setFocusedFilter] = React.useState<number | null>(null);
|
||||||
|
const { isWidget = false, data } = props;
|
||||||
const funnel = data.funnel || { stages: [] };
|
const funnel = data.funnel || { stages: [] };
|
||||||
const totalSteps = funnel.stages.length;
|
const totalSteps = funnel.stages.length;
|
||||||
const stages = isWidget ? [...funnel.stages.slice(0, 1), funnel.stages[funnel.stages.length - 1]] : funnel.stages;
|
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 (
|
||||||
<NoContent
|
<NoContent
|
||||||
style={{ minHeight: 220 }}
|
style={{ minHeight: 220 }}
|
||||||
title={
|
title={
|
||||||
|
|
@ -43,7 +61,14 @@ function FunnelWidget(props: Props) {
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
{ !isWidget && (
|
{ !isWidget && (
|
||||||
stages.map((filter: any, index: any) => (
|
stages.map((filter: any, index: any) => (
|
||||||
<Stage key={index} index={index + 1} isWidget={isWidget} stage={filter} />
|
<Stage
|
||||||
|
key={index}
|
||||||
|
index={index + 1}
|
||||||
|
isWidget={isWidget}
|
||||||
|
stage={filter}
|
||||||
|
focusStage={focusStage}
|
||||||
|
focusedFilter={focusedFilter}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -82,11 +107,11 @@ function FunnelWidget(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
{funnel.totalDropDueToIssues > 0 && <div className="flex items-center mb-2"><Icon name="magic" /> <span className="ml-2">{funnel.totalDropDueToIssues} sessions dropped due to issues.</span></div>}
|
{funnel.totalDropDueToIssues > 0 && <div className="flex items-center mb-2"><Icon name="magic" /> <span className="ml-2">{funnel.totalDropDueToIssues} sessions dropped due to issues.</span></div>}
|
||||||
</NoContent>
|
</NoContent>
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EmptyStage({ total }: any) {
|
export const EmptyStage = observer(({ total }: any) => {
|
||||||
return useObserver( () => (
|
return (
|
||||||
<div className={cn("flex items-center mb-4 pb-3", stl.step)}>
|
<div className={cn("flex items-center mb-4 pb-3", stl.step)}>
|
||||||
<IndexNumber index={0} />
|
<IndexNumber index={0} />
|
||||||
<div className="w-fit px-2 border border-teal py-1 text-center justify-center bg-teal-lightest flex items-center rounded-full color-teal" style={{ width: '100px'}}>
|
<div className="w-fit px-2 border border-teal py-1 text-center justify-center bg-teal-lightest flex items-center rounded-full color-teal" style={{ width: '100px'}}>
|
||||||
|
|
@ -94,42 +119,40 @@ export function EmptyStage({ total }: any) {
|
||||||
</div>
|
</div>
|
||||||
<div className="border-b w-full border-dashed"></div>
|
<div className="border-b w-full border-dashed"></div>
|
||||||
</div>
|
</div>
|
||||||
))
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
export function Stage({ stage, index, isWidget, uxt }: any) {
|
export const Stage = observer(({ stage, index, isWidget, uxt, focusStage, focusedFilter }: any) => {
|
||||||
return useObserver(() =>
|
return stage ? (
|
||||||
stage ? (
|
|
||||||
<div
|
<div
|
||||||
className={cn('flex items-start', stl.step, { [stl['step-disabled']]: !stage.isActive })}
|
className={cn('flex items-start', stl.step, { [stl['step-disabled']]: !stage.isActive })}
|
||||||
>
|
>
|
||||||
<IndexNumber index={index} />
|
<IndexNumber index={index} />
|
||||||
{!uxt ? <Funnelbar filter={stage} /> : <UxTFunnelBar filter={stage} />}
|
{!uxt ? <Funnelbar index={index} filter={stage} focusStage={focusStage} focusedFilter={focusedFilter} /> : <UxTFunnelBar filter={stage} />}
|
||||||
{!isWidget && !uxt && <BarActions bar={stage} />}
|
{!isWidget && !uxt && <BarActions bar={stage} />}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)
|
)
|
||||||
);
|
})
|
||||||
}
|
|
||||||
|
|
||||||
export function IndexNumber({ index }: any) {
|
export const IndexNumber = observer(({ index }: any) => {
|
||||||
return (
|
return (
|
||||||
<div className="z-10 w-6 h-6 border shrink-0 mr-4 text-sm rounded-full bg-gray-lightest flex items-center justify-center leading-3">
|
<div className="z-10 w-6 h-6 border shrink-0 mr-4 text-sm rounded-full bg-gray-lightest flex items-center justify-center leading-3">
|
||||||
{index === 0 ? <Icon size="14" color="gray-dark" name="list" /> : index}
|
{index === 0 ? <Icon size="14" color="gray-dark" name="list" /> : index}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
})
|
||||||
|
|
||||||
|
|
||||||
function BarActions({ bar }: any) {
|
const BarActions = observer(({ bar }: any) => {
|
||||||
return useObserver(() => (
|
return (
|
||||||
<div className="self-end flex items-center justify-center ml-4" style={{ marginBottom: '49px'}}>
|
<div className="self-end flex items-center justify-center ml-4" style={{ marginBottom: '49px'}}>
|
||||||
<button onClick={() => bar.updateKey('isActive', !bar.isActive)}>
|
<button onClick={() => bar.updateKey('isActive', !bar.isActive)}>
|
||||||
<Icon name="eye-slash-fill" color={bar.isActive ? "gray-light" : "gray-darkest"} size="22" />
|
<Icon name="eye-slash-fill" color={bar.isActive ? "gray-light" : "gray-darkest"} size="22" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
))
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
export default FunnelWidget;
|
export default observer(FunnelWidget);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue