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

171 lines
7.0 KiB
TypeScript

import { useValues } from 'kea'
import { Select, Tooltip } from '@hanzo/elements'
import { TZLabel } from 'lib/components/TZLabel'
import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { Field } from 'lib/elements/Field'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
import { AlertCalculationInterval } from '~/queries/schema/schema-general'
import { AvailableFeature } from '~/types'
import { AlertDefinitionRow, AlertNextEvaluationStatus } from 'products/alerts/frontend/components/AlertDefinition'
import { AlertFormType } from 'products/alerts/frontend/logic/alertFormLogic'
import {
cadenceFinerThanInsightInterval,
selectAlertCalculationInterval,
} from 'products/alerts/frontend/logic/alertIntervalHelpers'
import { approximateNextAlertRun } from 'products/alerts/frontend/logic/alertSchedulingStale'
import {
AlertType,
isInsightsQLAlertConfig,
isTrendsAlertConfig,
supportsOngoingInterval,
supportsTimeWindow,
} from 'products/alerts/frontend/types'
import { getAlertIntervalOptions } from './editAlertModalUtils'
export interface AlertIntervalRowProps {
alertForm: AlertFormType
creatingNewAlert: boolean
alert: AlertType | null | undefined
trendInterval: string | null | undefined
nextPlannedEvaluationStale: boolean
canCheckOngoingInterval: boolean
onSetAlertFormValue: <K extends keyof AlertFormType>(key: K, value: AlertFormType[K]) => void
}
function getInsightsQLEvaluatedText(alertForm: AlertFormType): string {
if (!isInsightsQLAlertConfig(alertForm.config)) {
return ''
}
if (alertForm.config.evaluation === 'any_row') {
return 'and check every row of the result'
}
if (alertForm.config.evaluation === 'first_row') {
return "and evaluate the query's first (newest) row"
}
return "and evaluate the query's last (newest) row"
}
export function AlertIntervalRow({
alertForm,
creatingNewAlert,
alert,
trendInterval,
nextPlannedEvaluationStale,
canCheckOngoingInterval,
onSetAlertFormValue,
}: AlertIntervalRowProps): JSX.Element {
const { hasAvailableFeature } = useValues(userLogic)
const { guardAvailableFeature } = useValues(upgradeModalLogic)
const { currentTeam } = useValues(teamLogic)
const hasHighFrequencyAlertsEntitlement = hasAvailableFeature(AvailableFeature.HIGH_FREQUENCY_ALERTS)
const hasRealTimeAlertsEntitlement = hasAvailableFeature(AvailableFeature.REAL_TIME_ALERTS)
const realTimeAlertsEnabled = useFeatureFlag('ALERTS_REAL_TIME_INTERVAL')
let evaluatedWindow: JSX.Element
if (!supportsTimeWindow(alertForm.config)) {
evaluatedWindow = <div>{getInsightsQLEvaluatedText(alertForm)}</div>
} else {
const period =
isTrendsAlertConfig(alertForm.config) && alertForm.config.check_ongoing_interval ? 'current' : 'last'
evaluatedWindow = (
<div data-attr="alertForm-trend-interval">
and check {period}{' '}
<Tooltip
title={
<>
Set by the insight's <b>grouped by</b> interval. Edit the insight to change it.
</>
}
>
<span className="font-semibold underline decoration-dotted cursor-help">
{trendInterval ?? 'day'}
</span>
</Tooltip>
</div>
)
}
let nextEvaluation: JSX.Element | null
if (alertForm.calculation_interval === AlertCalculationInterval.REAL_TIME) {
nextEvaluation = null
} else if (creatingNewAlert || nextPlannedEvaluationStale) {
const approximateTime = approximateNextAlertRun(alertForm.calculation_interval, currentTeam?.timezone ?? 'UTC')
nextEvaluation = (
<AlertNextEvaluationStatus>
<span>
Approximately <TZLabel time={approximateTime} />
</span>
</AlertNextEvaluationStatus>
)
} else if (alert) {
let status: JSX.Element
if (alert.next_check_at) {
status = <TZLabel time={alert.next_check_at} />
} else {
status = <span>We're calculating this. This can take a few minutes.</span>
}
nextEvaluation = (
<AlertNextEvaluationStatus loading={!nextPlannedEvaluationStale && !alert.next_check_at}>
{status}
</AlertNextEvaluationStatus>
)
} else {
nextEvaluation = null
}
const scheduleLabel =
alertForm.calculation_interval === AlertCalculationInterval.REAL_TIME ? 'Run alert' : 'Run alert every'
return (
<div className="space-y-2">
<AlertDefinitionRow label={scheduleLabel}>
<Field name="calculation_interval">
{({ value, onChange }) => (
<Select
fullWidth
className="w-36 shrink-0 whitespace-nowrap"
data-attr="alertForm-calculation-interval"
value={value}
options={getAlertIntervalOptions(
hasHighFrequencyAlertsEntitlement,
hasRealTimeAlertsEntitlement,
realTimeAlertsEnabled || value === AlertCalculationInterval.REAL_TIME
)}
onChange={(interval) => {
selectAlertCalculationInterval(interval, {
guardAvailableFeature,
onSelect: (selected) => {
onChange(selected)
if (
cadenceFinerThanInsightInterval(selected, trendInterval) &&
canCheckOngoingInterval &&
supportsOngoingInterval(alertForm.config) &&
alertForm.config.check_ongoing_interval === undefined
) {
onSetAlertFormValue('config', {
...alertForm.config,
check_ongoing_interval: true,
})
}
},
hasHighFrequencyAlertsEntitlement,
hasRealTimeAlertsEntitlement,
})
}}
/>
)}
</Field>
{evaluatedWindow}
</AlertDefinitionRow>
{nextEvaluation}
</div>
)
}