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

feat(experiments): Limit trends experiments to 'avg' and 'sum' #26819

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { actionsAndEventsToSeries } from '~/queries/nodes/InsightQuery/utils/fil
import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { Query } from '~/queries/Query/Query'
import { ExperimentTrendsQuery, NodeKind } from '~/queries/schema'
import { FilterType } from '~/types'
import { FilterType, PropertyMathType } from '~/types'

import { experimentLogic } from '../experimentLogic'
import { commonActionFilterProps } from './Selectors'
Expand Down Expand Up @@ -63,6 +63,7 @@ export function PrimaryGoalTrends(): JSX.Element {
showSeriesIndicator={true}
entitiesLimit={1}
showNumericalPropsOnly={true}
onlyPropertyMathDefinitions={[PropertyMathType.Average]}
{...commonActionFilterProps}
/>
<div className="mt-4 space-y-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export interface ActionFilterProps {
deleteButton,
orLabel,
}: Record<string, JSX.Element | string | undefined>) => JSX.Element
/** Only show these property math definitions */
onlyPropertyMathDefinitions?: Array<string> | null
}

export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(function ActionFilter(
Expand Down Expand Up @@ -116,6 +118,7 @@ export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(
buttonType = 'tertiary',
readOnly = false,
bordered = false,
onlyPropertyMathDefinitions = null,
},
ref
): JSX.Element {
Expand Down Expand Up @@ -174,6 +177,7 @@ export const ActionFilter = React.forwardRef<HTMLDivElement, ActionFilterProps>(
onRenameClick: showModal,
sortable,
showNumericalPropsOnly,
onlyPropertyMathDefinitions,
}

const reachedLimit: boolean = Boolean(entitiesLimit && localFilters.length >= entitiesLimit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export interface ActionFilterRowProps {
trendsDisplayCategory: ChartDisplayCategory | null
/** Whether properties shown should be limited to just numerical types */
showNumericalPropsOnly?: boolean
/** Only show these property math definitions */
onlyPropertyMathDefinitions?: Array<string> | null
}

export function ActionFilterRow({
Expand Down Expand Up @@ -155,6 +157,7 @@ export function ActionFilterRow({
renderRow,
trendsDisplayCategory,
showNumericalPropsOnly,
onlyPropertyMathDefinitions = null,
}: ActionFilterRowProps): JSX.Element {
const { entityFilterVisible } = useValues(logic)
const {
Expand Down Expand Up @@ -425,6 +428,7 @@ export function ActionFilterRow({
style={{ maxWidth: '100%', width: 'initial' }}
mathAvailability={mathAvailability}
trendsDisplayCategory={trendsDisplayCategory}
onlyPropertyMathDefinitions={onlyPropertyMathDefinitions}
/>
{mathDefinitions[math || BaseMathType.TotalCount]?.category ===
MathCategory.PropertyValue && (
Expand Down Expand Up @@ -642,6 +646,7 @@ interface MathSelectorProps {
onMathSelect: (index: number, value: any) => any
trendsDisplayCategory: ChartDisplayCategory | null
style?: React.CSSProperties
onlyPropertyMathDefinitions?: Array<string> | null
}

function isPropertyValueMath(math: string | undefined): math is PropertyMathType {
Expand All @@ -660,6 +665,7 @@ function useMathSelectorOptions({
mathAvailability,
onMathSelect,
trendsDisplayCategory,
onlyPropertyMathDefinitions = null,
}: MathSelectorProps): LemonSelectOptions<string> {
const mountedInsightDataLogic = insightDataLogic.findMounted()
const query = mountedInsightDataLogic?.values?.query
Expand Down Expand Up @@ -758,12 +764,19 @@ function useMathSelectorOptions({
setPropertyMathTypeShown(value as PropertyMathType)
onMathSelect(index, value)
}}
options={Object.entries(PROPERTY_MATH_DEFINITIONS).map(([key, definition]) => ({
value: key,
label: definition.shortName,
tooltip: definition.description,
'data-attr': `math-${key}-${index}`,
}))}
options={Object.entries(PROPERTY_MATH_DEFINITIONS)
.filter(([key]) => {
if (null === onlyPropertyMathDefinitions) {
return true
}
return onlyPropertyMathDefinitions.includes(key)
})
.map(([key, definition]) => ({
value: key,
label: definition.shortName,
tooltip: definition.description,
'data-attr': `math-${key}-${index}`,
}))}
onClick={(e) => e.stopPropagation()}
size="small"
dropdownMatchSelectWidth={false}
Expand Down
Loading