:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(stamphog): make the trigger label a deliberate edit (#108186)
Julian Bezae59ab17266b
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex c66901d0971f..79974b1b330c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11881,9 +11881,13 @@ snapshots:scenes-app-stamphog-repositories--repositories-list--light:hash: v1.k794b7964.da354a1edb7c115d0c7f695ef58237970f3057d26e1aedb0db0dd3fda4511780.htoHBFn118PVvGOY4sN_3CzVB5jwVcvMTod2ttIKi1Qscenes-app-stamphog-repositories--repository-expanded--dark:- hash: v1.k794b7964.f9e813ba71635974004268f9b7ccf89fa23cf4bc192653f0ac49ae9bdb22a55c.UYt1dmvJpiE0V3pvXdB37EkNNxGwr5h7Kkp0Q7GktLY+ hash: v1.k794b7964.291c7fa6edaeaa26e41e24739bb17174a18be7cc054b7813757d9df81b349fac.Sj75WE_Ma_jnObQgZeNLOBWyph05vAV5OV0jhUEDzBYscenes-app-stamphog-repositories--repository-expanded--light:- hash: v1.k794b7964.07ea2b4e15d17ef6c449dfb3c93089c0bbb836033e6deb240cc66540cfebc2b8.Ex8TXB5UPcDZjQgwE4DljCUwwNwFnjY7eI2sSwByglE+ hash: v1.k794b7964.30a60b3f269b7ac976e0d0df7dad70601a6f5b6acd42e8d0f7fe5e0cd8de5410.yKw9J5J-kA8fsGDN3iVSrl4l7Uiy76fxtQHfTHnvFPE+ scenes-app-stamphog-repositories--trigger-label-editing--dark:+ hash: v1.k794b7964.a00cb5e70789e655f4d82259153db0bea91c68bf3c9fbb680149c25b81c0c1ef.cxhOiWhY6q7rMWiD-F2BPqv2hybkStb4iWl95lsL4lA+ scenes-app-stamphog-repositories--trigger-label-editing--light:+ hash: v1.k794b7964.7141884cac757c04cd0431e389daf2628efd0ca4a1abf750fca812d0f4ce8c5b.DhwYQYYTjt5IsFgKiJGZ5k_xkt6_tUhuNPAx3eVV8iIscenes-app-stamphog-runs--runs-list--dark:hash: v1.k794b7964.0f6fb2d21628b8c0f8781d21610ca6fd605216cb07cfeae30f9fc6189ca72d2b.GzyJek2YNFSPSBQoznkgE_FcldLmSLCiVa0gCaHUIxIscenes-app-stamphog-runs--runs-list--light:diff --git a/products/stamphog/frontend/scenes/StamphogScene/ExpandedRepoSettings.tsx b/products/stamphog/frontend/scenes/StamphogScene/ExpandedRepoSettings.tsxindex 345f4fabaf02..cb1eec3aa8ed 100644--- a/products/stamphog/frontend/scenes/StamphogScene/ExpandedRepoSettings.tsx+++ b/products/stamphog/frontend/scenes/StamphogScene/ExpandedRepoSettings.tsx@@ -1,7 +1,8 @@import { useActions, useValues } from 'kea'-import { LemonInput, LemonSelect, LemonSwitch } from '@posthog/lemon-ui'+import { LemonSelect, LemonSwitch, Tooltip } from '@posthog/lemon-ui'+import { EditableField } from 'lib/components/EditableField/EditableField'import { toAccessControlLevel } from 'lib/utils/accessControlUtils'import { ReviewModeEnumApi, type StamphogRepoConfigApi } from '../../generated/api.schemas'@@ -34,16 +35,23 @@ function TriggerSettings({repo: StamphogRepoConfigApiupdatingReason?: string}): JSX.Element {- const { updateRepoConfig } = useActions(stamphogSceneLogic)- const disabledReason = managerDisabledReason(toAccessControlLevel(repo.user_access_level)) ?? updatingReason+ const { triggerLabelFieldResets, savingTriggerLabelRepoIds } = useValues(stamphogSceneLogic)+ const { updateRepoConfig, triggerLabelEditStarted, resetTriggerLabelField } = useActions(stamphogSceneLogic)+ const accessReason = managerDisabledReason(toAccessControlLevel(repo.user_access_level))+ // Only the access level and the label's own save lock the label. An update elsewhere in the row+ // must not swap the editor out and drop its draft.+ const labelReadOnlyReason =+ accessReason ?? (savingTriggerLabelRepoIds.includes(repo.id) ? 'Saving the label' : null)+ const disabledReason = accessReason ?? updatingReasonconst saveTriggerLabel = (value: string): void => {const trimmed = value.trim()- // Save only real changes — blur after no edit (or after enter already saved) must not re-PATCH,- // and a blank label is rejected by the API anyway.+ // Save only real changes. A save with no edit must not re-PATCH, and the API rejects a blank label.if (trimmed && trimmed !== repo.trigger_label) {updateRepoConfig(repo.id, { trigger_label: trimmed })+ return}+ resetTriggerLabelField(repo.id)}return (@@ -59,21 +67,34 @@ function TriggerSettings({]}data-attr="stamphog-repo-review-mode"/>- {repo.review_mode === ReviewModeEnumApi.Label && (- <LemonInput- // Uncontrolled on purpose: the label saves on blur/enter, not per keystroke.- // Keying by the saved value resets the draft after a reload.- key={`${repo.id}-${repo.trigger_label}`}- size="small"- className="w-40"- defaultValue={repo.trigger_label}- placeholder="Trigger label"- disabledReason={disabledReason}- onBlur={(e) => saveTriggerLabel(e.currentTarget.value)}- onPressEnter={(e) => saveTriggerLabel(e.currentTarget.value)}- data-attr="stamphog-repo-trigger-label"- />- )}+ {repo.review_mode === ReviewModeEnumApi.Label &&+ // EditableField has no disabled state, so a locked label reads as text.+ (labelReadOnlyReason ? (+ <Tooltip title={labelReadOnlyReason}>+ <span className="font-mono text-xs" data-attr="stamphog-repo-trigger-label">+ {repo.trigger_label}+ </span>+ </Tooltip>+ ) : (+ // A changed label silently stops reviews on pull requests that carry the old one, so a+ // change takes the pencil and an explicit save, never a stray blur.+ <EditableField+ key={triggerLabelFieldResets[repo.id] ?? 0}+ name="trigger_label"+ value={repo.trigger_label ?? ''}+ placeholder="Trigger label"+ minLength={1}+ compactButtons+ onModeToggle={(mode) => {+ if (mode === 'edit') {+ triggerLabelEditStarted(repo.id)+ }+ }}+ onSave={saveTriggerLabel}+ className="font-mono text-xs"+ data-attr="stamphog-repo-trigger-label"+ />+ ))}</div>)}diff --git a/products/stamphog/frontend/scenes/StamphogScene/StamphogScene.stories.tsx b/products/stamphog/frontend/scenes/StamphogScene/StamphogScene.stories.tsxindex 0942e838282d..fd75970371eb 100644--- a/products/stamphog/frontend/scenes/StamphogScene/StamphogScene.stories.tsx+++ b/products/stamphog/frontend/scenes/StamphogScene/StamphogScene.stories.tsx@@ -97,12 +97,24 @@ export default metaexport const RepositoriesList: StoryObj = {}-// Expands the label-triggered row, the only one that shows the trigger label input.+async function expandLabelRow(canvasElement: HTMLElement): Promise<void> {+ const labelRow = (await within(canvasElement).findByText('posthog-js', {}, { timeout: 15000 })).closest('tr')+ await userEvent.click(within(labelRow!).getByTitle('Show more'))+ await within(canvasElement).findByText('Daily digest')+}++// Expands the label-triggered row, the only one that shows the trigger label.export const RepositoryExpanded: StoryObj = {play: async ({ canvasElement }) => {- const labelRow = (await within(canvasElement).findByText('posthog-js', {}, { timeout: 15000 })).closest('tr')- await userEvent.click(within(labelRow!).getByTitle('Show more'))- await within(canvasElement).findByText('Daily digest')+ await expandLabelRow(canvasElement)+ },+}++export const TriggerLabelEditing: StoryObj = {+ play: async ({ canvasElement }) => {+ await expandLabelRow(canvasElement)+ await userEvent.click(within(canvasElement).getByTitle('Edit'))+ await within(canvasElement).findByText('Save')},}diff --git a/products/stamphog/frontend/scenes/StamphogScene/stamphogSceneLogic.ts b/products/stamphog/frontend/scenes/StamphogScene/stamphogSceneLogic.tsindex 0dc5f43bd564..a90f8c10b1dd 100644--- a/products/stamphog/frontend/scenes/StamphogScene/stamphogSceneLogic.ts+++ b/products/stamphog/frontend/scenes/StamphogScene/stamphogSceneLogic.ts@@ -1,6 +1,7 @@import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'import { router, urlToAction } from 'kea-router'+import posthog from 'posthog-js'import { LemonInputSelectOption } from 'lib/lemon-ui/LemonInputSelect'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'@@ -88,10 +89,12 @@ export interface stamphogSceneLogicValues {repoConfigsLoading: booleanrepoSearch: stringrepositoryToAdd: string | null+ savingTriggerLabelRepoIds: string[]skippedRepos: readonly string[]stamphogAccessLevel: AccessControlLevel | undefinedsyncResult: StamphogSyncInstallationResponseApi | nullsyncResultLoading: boolean+ triggerLabelFieldResets: Record<string, number>updatingRepoIds: string[]}@@ -184,6 +187,9 @@ export interface stamphogSceneLogicActions {repoUpdateDone: (id: string) => {id: string}+ resetTriggerLabelField: (id: string) => {+ id: string+ }setAvailableSearch: (search: string) => {search: string}@@ -237,6 +243,12 @@ export interface stamphogSceneLogicActions {state: string}}+ triggerLabelEditStarted: (id: string) => {+ id: string+ }+ triggerLabelSaveDone: (id: string) => {+ id: string+ }updateRepoConfig: (id: string,patch: PatchedStamphogRepoConfigWriteApi@@ -289,6 +301,9 @@ export const stamphogSceneLogic = kea<stamphogSceneLogicType>([// payload from its first parameter, and every `loadRepoConfigs()` call would stop compiling.loadRepoConfigs: true,updateRepoConfig: (id: string, patch: PatchedStamphogRepoConfigWriteApi) => ({ id, patch }),+ triggerLabelEditStarted: (id: string) => ({ id }),+ resetTriggerLabelField: (id: string) => ({ id }),+ triggerLabelSaveDone: (id: string) => ({ id }),repoUpdateDone: (id: string) => ({ id }),repoConfigUpdated: (config: StamphogRepoConfigApi) => ({ config }),setRepoSearch: (search: string) => ({ search }),@@ -392,6 +407,23 @@ export const stamphogSceneLogic = kea<stamphogSceneLogicType>([repoUpdateDone: (state, { id }) => state.filter((x) => x !== id),},],+ // Repos with an in-flight label PATCH. A second label save before the first settles could land+ // out of order and leave the older label stored.+ savingTriggerLabelRepoIds: [+ [] as string[],+ {+ updateRepoConfig: (state, { id, patch }) =>+ 'trigger_label' in patch && !state.includes(id) ? [...state, id] : state,+ triggerLabelSaveDone: (state, { id }) => state.filter((x) => x !== id),+ },+ ],+ // The label editor keeps a draft it did not save on screen, so a bumped count remounts it from the stored label.+ triggerLabelFieldResets: [+ {} as Record<string, number>,+ {+ resetTriggerLabelField: (state, { id }) => ({ ...state, [id]: (state[id] ?? 0) + 1 }),+ },+ ],repoConfigs: {repoConfigUpdated: (state, { config }) => state.map((repo) => (repo.id === config.id ? config : repo)),// Adding a paused repository turns its existing row back on, so replace before inserting.@@ -559,12 +591,30 @@ export const stamphogSceneLogic = kea<stamphogSceneLogicType>([actions.repoConfigUpdated(await stamphogRepoConfigsPartialUpdate(String(values.currentProjectId), id, patch))+ // The event names are frozen: insights on settings usage break if one is renamed. The label+ // text is left out because it is free text a team typed.+ posthog.capture('stamphog repo settings updated', {+ repo_config_id: id,+ fields: Object.keys(patch),+ review_mode: patch.review_mode,+ enabled: patch.enabled,+ digest_enabled: patch.digest_enabled,+ })} catch {lemonToast.error('Failed to update repository')+ if ('trigger_label' in patch) {+ actions.resetTriggerLabelField(id)+ }} finally {actions.repoUpdateDone(id)+ if ('trigger_label' in patch) {+ actions.triggerLabelSaveDone(id)+ }}},+ triggerLabelEditStarted: ({ id }) => {+ posthog.capture('stamphog trigger label edit started', { repo_config_id: id })+ },setAvailableSearch: async ({ search }, breakpoint) => {await breakpoint(AVAILABLE_SEARCH_DEBOUNCE_MS)actions.loadAvailableRepositories({ search })