Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

152 lines
7.6 KiB
TypeScript

import { Group } from 'kea-forms'
import { Banner, Input, SegmentedButton, Select } from '@hanzo/elements'
import { Field } from 'lib/elements/Field'
import { AlertConditionType, InsightThresholdType } from '~/queries/schema/schema-general'
import { AlertDefinitionRow } from 'products/alerts/frontend/components/AlertDefinition'
import { AlertFormType } from 'products/alerts/frontend/logic/alertFormLogic'
import {
fractionToPercentInput,
inputToStoredBound,
thresholdForConditionChange,
} from 'products/alerts/frontend/logic/thresholdPercent'
import { isAnyRowInsightsQLConfig, isFunnelsAlertConfig } from 'products/alerts/frontend/types'
export interface ThresholdRowRenderProps {
alertForm: AlertFormType
thresholdBoundsFormError?: string
isNonTimeSeriesDisplay: boolean
supportsRelativeConditions: boolean
onSetAlertFormValue: <K extends keyof AlertFormType>(key: K, value: AlertFormType[K]) => void
}
export function ThresholdDefinitionRow({
alertForm,
thresholdBoundsFormError,
isNonTimeSeriesDisplay,
supportsRelativeConditions,
onSetAlertFormValue,
}: ThresholdRowRenderProps): JSX.Element {
const isFunnelAlert = isFunnelsAlertConfig(alertForm.config)
const relativeConditionDisabledReason =
(isNonTimeSeriesDisplay && 'This condition is only supported for time series trends') ||
(isAnyRowInsightsQLConfig(alertForm.config) &&
"Rows in any-row mode aren't a time series. Switch to 'the latest value' for relative conditions")
return (
<div className="space-y-2">
{thresholdBoundsFormError ? <Banner type="error">{thresholdBoundsFormError}</Banner> : null}
<AlertDefinitionRow>
{supportsRelativeConditions && (
<Group name={['condition']}>
<Field name="type">
{({ value, onChange }) => (
<Select
fullWidth
className="w-40"
data-attr="alertForm-condition"
value={value}
onChange={(newType) => {
onChange(newType)
const configuration = alertForm.threshold.configuration
const nextConfiguration = thresholdForConditionChange(
configuration,
newType,
isFunnelAlert
)
if (nextConfiguration === configuration) {
return
}
onSetAlertFormValue('threshold', { configuration: nextConfiguration })
}}
options={[
{ label: 'has value', value: AlertConditionType.ABSOLUTE_VALUE },
{
label: 'increases by',
value: AlertConditionType.RELATIVE_INCREASE,
disabledReason: relativeConditionDisabledReason,
},
{
label: 'decreases by',
value: AlertConditionType.RELATIVE_DECREASE,
disabledReason: relativeConditionDisabledReason,
},
]}
/>
)}
</Field>
</Group>
)}
<div>less than</div>
<Field name="lower">
<Input
type="number"
min={alertForm.condition.type === AlertConditionType.ABSOLUTE_VALUE ? undefined : 0}
className="w-30"
data-attr="alertForm-lower-threshold"
suffix={isFunnelAlert ? <span aria-label="percent">%</span> : undefined}
value={
alertForm.threshold.configuration.type === InsightThresholdType.PERCENTAGE
? fractionToPercentInput(alertForm.threshold.configuration.bounds?.lower)
: alertForm.threshold.configuration.bounds?.lower
}
onChange={(value) =>
onSetAlertFormValue('threshold', {
configuration: {
type: alertForm.threshold.configuration.type,
bounds: {
...alertForm.threshold.configuration.bounds,
lower: inputToStoredBound(value, alertForm.threshold.configuration.type),
},
},
})
}
/>
</Field>
<div>or more than</div>
<Field name="upper">
<Input
type="number"
min={alertForm.condition.type === AlertConditionType.ABSOLUTE_VALUE ? undefined : 0}
className="w-30"
data-attr="alertForm-upper-threshold"
suffix={isFunnelAlert ? <span aria-label="percent">%</span> : undefined}
value={
alertForm.threshold.configuration.type === InsightThresholdType.PERCENTAGE
? fractionToPercentInput(alertForm.threshold.configuration.bounds?.upper)
: alertForm.threshold.configuration.bounds?.upper
}
onChange={(value) =>
onSetAlertFormValue('threshold', {
configuration: {
type: alertForm.threshold.configuration.type,
bounds: {
...alertForm.threshold.configuration.bounds,
upper: inputToStoredBound(value, alertForm.threshold.configuration.type),
},
},
})
}
/>
</Field>
{/* Funnels always compare as a percentage of the prior period, so their unit is fixed. */}
{!isFunnelAlert && alertForm.condition.type !== AlertConditionType.ABSOLUTE_VALUE && (
<Group name={['threshold', 'configuration']}>
<Field name="type">
<SegmentedButton
options={[
{ value: InsightThresholdType.PERCENTAGE, label: '%', tooltip: 'Percent' },
{ value: InsightThresholdType.ABSOLUTE, label: '#', tooltip: 'Absolute number' },
]}
/>
</Field>
</Group>
)}
</AlertDefinitionRow>
</div>
)
}