mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 12:21:02 +01:00
fix(trends): Show appropriate nested math value immediately (#12679)
This commit is contained in:
parent
634976f304
commit
df11cf6c68
@ -414,18 +414,29 @@ interface MathSelectorProps {
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
function useMathSelectorOptions(
|
||||
index: number,
|
||||
mathAvailability: MathAvailability,
|
||||
onMathSelect: (index: number, value: any) => any
|
||||
): LemonSelectOptions<string> {
|
||||
function isPropertyValueMath(math: string | undefined): math is PropertyMathType {
|
||||
return !!math && math in PROPERTY_MATH_DEFINITIONS
|
||||
}
|
||||
|
||||
function isCountPerActorMath(math: string | undefined): math is CountPerActorMathType {
|
||||
return !!math && math in COUNT_PER_ACTOR_MATH_DEFINITIONS
|
||||
}
|
||||
|
||||
function useMathSelectorOptions({
|
||||
math,
|
||||
index,
|
||||
mathAvailability,
|
||||
onMathSelect,
|
||||
}: MathSelectorProps): LemonSelectOptions<string> {
|
||||
const { needsUpgradeForGroups, canStartUsingGroups, staticMathDefinitions, staticActorsOnlyMathDefinitions } =
|
||||
useValues(mathsLogic)
|
||||
const { featureFlags } = useValues(featureFlagLogic)
|
||||
|
||||
const [propertyMathTypeShown, setPropertyMathTypeShown] = useState<PropertyMathType>(PropertyMathType.Average)
|
||||
const [propertyMathTypeShown, setPropertyMathTypeShown] = useState<PropertyMathType>(
|
||||
isPropertyValueMath(math) ? math : PropertyMathType.Average
|
||||
)
|
||||
const [countPerActorMathTypeShown, setCountPerActorMathTypeShown] = useState<CountPerActorMathType>(
|
||||
CountPerActorMathType.Average
|
||||
isCountPerActorMath(math) ? math : CountPerActorMathType.Average
|
||||
)
|
||||
|
||||
const options: LemonSelectOption<string>[] = Object.entries(
|
||||
@ -508,14 +519,9 @@ function useMathSelectorOptions(
|
||||
]
|
||||
}
|
||||
|
||||
function MathSelector({
|
||||
math,
|
||||
mathGroupTypeIndex,
|
||||
mathAvailability,
|
||||
index,
|
||||
onMathSelect,
|
||||
}: MathSelectorProps): JSX.Element {
|
||||
const options = useMathSelectorOptions(index, mathAvailability, onMathSelect)
|
||||
function MathSelector(props: MathSelectorProps): JSX.Element {
|
||||
const options = useMathSelectorOptions(props)
|
||||
const { math, mathGroupTypeIndex, index, onMathSelect } = props
|
||||
|
||||
const mathType = apiValueToMathType(math, mathGroupTypeIndex)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user