: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(signals): add base branch overrides to inbox settings (#73967)
Christiaan Hendriksen59c261a25563
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 5e1b41924e1e..e50a1c9dda7b 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6223,9 +6223,9 @@ snapshots:scenes-app-inbox-pullrequestdiffview--truncated--light:hash: v1.k794b7964.c8211a05cd4404a003460d2c4abe79fb078edd5c7801422dbb3a5c55cc50f6a1.R85Q2EEe3EteBgaslGBlB4Vp7AdPgMstb0whb50OXycscenes-app-inbox-scene--empty--dark:- hash: v1.k794b7964.8f143021c1c40d58ddae66405342d7ecf775a3b8c0a9ad996481325db55b5497.xdG0HoCq82l8pSWAsoRnBRUXf4fr_BtsJDkizyJsUOc+ hash: v1.k794b7964.9dbdb2d978eebc68aa9e3f77cb049626504aa730ec984a40eb06b786646dd7e7.wJCovsnKlvVmhUlWZGO9mN18KPZEngKGK1ADEVk_RUEscenes-app-inbox-scene--empty--light:- hash: v1.k794b7964.be3d92c919f54e31021dfec9f1c4d45ebe28e3bd62b4c34cb0c977e3416052d3.sBpfA6AgbG-fI0JQuWMKD0QL0hN_RMTfxWls1LRzoUg+ hash: v1.k794b7964.69b957bf8da898cf4ad1f2313a975163d8d5d7741706d2fa5cd39f3a976b8218.M2Xe7b3vKo_h9qcNCXkCZE0301ARqU8wqnnQ9-25mJwscenes-app-inbox-scene--inbox--dark:hash: v1.k794b7964.7ade0c95519de555691da00b03aaa9aeea1ba0c32762354222d23676099ea0da.OmzLebXW_1EJ-lRFDeh7flQ6cl3OqskJfVarjDu4FQcscenes-app-inbox-scene--inbox--light:@@ -6235,9 +6235,9 @@ snapshots:scenes-app-inbox-scene--self-driving-onboarding--light:hash: v1.k794b7964.35ccf8547b124cd9adeaae5edaf9943755f7788cfd4296e2f6c254490c5e6c17.pvQ5JFSpCQy5ZVl3jGG9wuCyEMqfmS1PIXl49SD8Yzgscenes-app-inbox-scene--self-driving-paused--dark:- hash: v1.k794b7964.0510b996167600e7acbceee1be6c6afc0bffd1e8fee0f553654234b85b3d72de.LmiU3KuU9y44MAKZ8DzizEXjHBTsDsZpvH_zysTInAU+ hash: v1.k794b7964.00929b96e59e35796acfc2f8d5f9f48e148c499b2932c227e1a4cf02c488bde0.0kZ4s9sfw8uPHzO2KT7GZ6vL6y-2qA4qzRoZW7n-bcUscenes-app-inbox-scene--self-driving-paused--light:- hash: v1.k794b7964.f9b5a6f1ecd482963d9850ced2d07c1ea729d2d63be8679db907709e5a6fde89.upcV4EokxFjnADvyUmiBiIp7UTjShqKZHDv2EKVV6HM+ hash: v1.k794b7964.e2ed5feaafcc219cbecaedafed11618a60e0b39911f54121ae02acbf68270238.v1MEVslQu-332g2PB_trr6JIb-knUHeoA42roLiGQRIscenes-app-inbox-tabs--pull-requests--dark:hash: v1.k794b7964.dad4d6e7b9f1f68f8eaf4b31187c798dfab1631bb6bf20432ce9746f7df1de73.cqSvLKv0E6PFhnMnbn4FS6yIypKYMUKzoKniwrRI4WMscenes-app-inbox-tabs--pull-requests--light:diff --git a/frontend/src/lib/integrations/ComboboxSearchChrome.tsx b/frontend/src/lib/integrations/ComboboxSearchChrome.tsxnew file mode 100644index 000000000000..af195e41aac9--- /dev/null+++ b/frontend/src/lib/integrations/ComboboxSearchChrome.tsx@@ -0,0 +1,108 @@+import { type MouseEvent } from 'react'++import { IconRefresh } from '@posthog/icons'+import {+ Button,+ ComboboxInput,+ ComboboxListFooter,+ InputGroupAddon,+ InputGroupButton,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill'++/** Keep the combobox from reading a control press as picking an item or as a dismiss. */+function swallowEvent(event: MouseEvent): void {+ event.preventDefault()+ event.stopPropagation()+}++export interface ComboboxSearchFieldProps {+ /** Plural noun for what's being searched, e.g. `branches`. Fills the placeholder and the refresh label. */+ itemsLabel: string+ loading: boolean+ disabled?: boolean+ onRefresh: () => void+}++/**+ * Search field for a combobox whose list is searched server-side. Refresh sits in the field's own addon+ * rather than beside it, which is what keeps the two the same height, and the field is inset to the+ * list's padding so it lines up with the items. The chevron is hidden because the popup is already open.+ */+export function ComboboxSearchField({+ itemsLabel,+ loading,+ disabled = false,+ onRefresh,+}: ComboboxSearchFieldProps): JSX.Element {+ return (+ <div className="p-1">+ <ComboboxInput placeholder={`Search ${itemsLabel}...`} showTrigger={false} className="w-full">+ <InputGroupAddon align="inline-end">+ <Tooltip>+ <TooltipTrigger+ render={+ <InputGroupButton+ size="icon-xs"+ disabled={disabled || loading}+ aria-label={`Refresh ${itemsLabel}`}+ onMouseDown={swallowEvent}+ onClick={(event: MouseEvent) => {+ swallowEvent(event)+ onRefresh()+ }}+ >+ <IconRefresh className={loading ? 'animate-spin' : undefined} />+ </InputGroupButton>+ }+ />+ <TooltipContent>Refresh {itemsLabel}</TooltipContent>+ </Tooltip>+ </InputGroupAddon>+ </ComboboxInput>+ </div>+ )+}++export interface ComboboxLoadMoreFooterProps {+ loadedCount: number+ /** Plural noun for the full list, e.g. `branches`. Reads as "matches" while a search is narrowing it. */+ itemsLabel: string+ searching: boolean+ loading: boolean+ onLoadMore: () => void+}++/** Paginated footer for a combobox list: how much of the list is loaded, and a way to get the next page. */+export function ComboboxLoadMoreFooter({+ loadedCount,+ itemsLabel,+ searching,+ loading,+ onLoadMore,+}: ComboboxLoadMoreFooterProps): JSX.Element {+ return (+ <ComboboxListFooter>+ <div className="px-2 pb-2">+ <div className="px-1 pb-2 text-center text-muted text-xs">+ {`Showing ${loadedCount}+ ${searching ? 'matches' : itemsLabel}`}+ </div>+ <Button+ variant="outline"+ size="sm"+ className="w-full justify-center"+ disabled={loading}+ onMouseDown={swallowEvent}+ onClick={(event: MouseEvent) => {+ swallowEvent(event)+ onLoadMore()+ }}+ >+ Load more+ </Button>+ </div>+ </ComboboxListFooter>+ )+}diff --git a/frontend/src/lib/integrations/GitHubBranchCombobox.tsx b/frontend/src/lib/integrations/GitHubBranchCombobox.tsxindex 544de7674ad6..5822457eafe2 100644--- a/frontend/src/lib/integrations/GitHubBranchCombobox.tsx+++ b/frontend/src/lib/integrations/GitHubBranchCombobox.tsx@@ -1,22 +1,18 @@import { useActions, useValues } from 'kea'-import { type MouseEvent, useEffect, useRef, useState } from 'react'+import { useEffect, useRef, useState } from 'react'-import { IconGitBranch, IconRefresh } from '@posthog/icons'+import { IconGitBranch } from '@posthog/icons'import {Button,Combobox,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,- ComboboxListFooter,ComboboxTrigger,- Tooltip,- TooltipContent,- TooltipTrigger,} from '@posthog/quill'+import { ComboboxLoadMoreFooter, ComboboxSearchField } from './ComboboxSearchChrome'import { githubBranchSearchLogic } from './githubBranchSearchLogic'export interface GitHubBranchComboboxProps {@@ -28,6 +24,7 @@ export interface GitHubBranchComboboxProps {onChange: (value: string | null) => voiddisabled?: booleanplaceholder?: string+ allowCustomValues?: boolean}/** Sentinel item value for the "type a new branch name" action. */@@ -47,28 +44,42 @@ export function GitHubBranchCombobox({onChange,disabled = false,placeholder = 'Select branch...',+ allowCustomValues = true,}: GitHubBranchComboboxProps): JSX.Element {const logic = githubBranchSearchLogic({ integrationId, repo })- const { branches, defaultBranch, loading, hasMore, searchQuery } = useValues(logic)+ const { branches, defaultBranch, loading, hasMore, searchQuery, error } = useValues(logic)const { setSearchQuery, loadMore, refresh } = useActions(logic)const triggerRef = useRef<HTMLButtonElement>(null)const [open, setOpen] = useState(false)+ const preselectRequestedFor = useRef<string | null>(null)const trimmedSearchQuery = searchQuery.trim()const showInlineLoadingState = open && loading// Pre-select the repo's default branch once it's known and nothing is chosen yet (matches PostHog Desktop).+ // Only a picker still missing a branch pays for the upfront fetch that surfaces it. One that already has+ // its branch stays lazy, so a list of them doesn't fire a request per row.useEffect(() => {- if (!value && defaultBranch) {+ if (value) {+ return+ }+ if (defaultBranch) {onChange(defaultBranch)+ return+ }+ const repoKey = `${integrationId}:${repo}`+ if (preselectRequestedFor.current !== repoKey) {+ preselectRequestedFor.current = repoKey+ refresh()}- }, [value, defaultBranch, onChange])+ }, [value, defaultBranch, onChange, refresh, integrationId, repo])// Offer "Use <typed> as branch name" when the search doesn't match an existing branch — lets the agent// work on a brand-new branch.const createSentinel = CREATE_BRANCH_PREFIX + trimmedSearchQuery- const showCreateItem = trimmedSearchQuery.length > 0 && !loading && !branches.includes(trimmedSearchQuery)+ const showCreateItem =+ allowCustomValues && trimmedSearchQuery.length > 0 && !loading && !branches.includes(trimmedSearchQuery)const items = showCreateItem ? [...branches, createSentinel] : branchesreturn (@@ -87,8 +98,16 @@ export function GitHubBranchCombobox({open={open}onOpenChange={(nextOpen: boolean) => {setOpen(nextOpen)- if (!nextOpen && trimmedSearchQuery.length > 0) {+ if (!nextOpen) {+ return+ }+ // Reset back to the full list on the next open rather than on close, matching+ // GitHubRepositoryCombobox: clearing the search while closing fetches an unfiltered page+ // for a list nobody is looking at.+ if (trimmedSearchQuery.length > 0) {setSearchQuery('')+ } else if (branches.length === 0 && !loading) {+ refresh()}}}inputValue={searchQuery}@@ -104,36 +123,10 @@ export function GitHubBranchCombobox({}/><ComboboxContent anchor={triggerRef} side="bottom" sideOffset={6} className="min-w-[280px]">- <div className="flex min-w-0 items-center gap-1 pe-2">- <div className="min-w-0 flex-1">- <ComboboxInput placeholder="Search branches..." />- </div>- <Tooltip>- <TooltipTrigger- render={- <Button- variant="outline"- size="sm"- disabled={disabled || loading}- aria-label="Refresh branches"- onMouseDown={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- }}- onClick={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- refresh()- }}- >- <IconRefresh className={loading ? 'animate-spin' : undefined} />- </Button>- }- />- <TooltipContent>Refresh branches</TooltipContent>- </Tooltip>- </div>- <ComboboxEmpty>{showInlineLoadingState ? 'Loading branches...' : 'No branches found.'}</ComboboxEmpty>+ <ComboboxSearchField itemsLabel="branches" loading={loading} disabled={disabled} onRefresh={refresh} />+ <ComboboxEmpty>+ {showInlineLoadingState ? 'Loading branches...' : (error ?? 'No branches found.')}+ </ComboboxEmpty><ComboboxList>{(item: string) =>item.startsWith(CREATE_BRANCH_PREFIX) ? (@@ -149,30 +142,13 @@ export function GitHubBranchCombobox({</ComboboxList>{hasMore && (- <ComboboxListFooter>- <div className="px-2 pb-2">- <div className="px-1 pb-2 text-center text-muted text-xs">- {`Showing ${branches.length}+ ${trimmedSearchQuery ? 'matches' : 'branches'}`}- </div>- <Button- variant="outline"- size="sm"- className="w-full justify-center"- disabled={loading}- onMouseDown={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- }}- onClick={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- loadMore()- }}- >- Load more- </Button>- </div>- </ComboboxListFooter>+ <ComboboxLoadMoreFooter+ loadedCount={branches.length}+ itemsLabel="branches"+ searching={!!trimmedSearchQuery}+ loading={loading}+ onLoadMore={loadMore}+ />)}</ComboboxContent></Combobox>diff --git a/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsx b/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsxindex 16e151b8c829..4a1a4b2fb18f 100644--- a/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsx+++ b/frontend/src/lib/integrations/GitHubRepositoryCombobox.tsx@@ -1,22 +1,18 @@import { useActions, useValues } from 'kea'-import { type MouseEvent, useRef, useState } from 'react'+import { useRef, useState } from 'react'-import { IconGithub, IconRefresh } from '@posthog/icons'+import { IconGithub } from '@posthog/icons'import {Button,Combobox,ComboboxContent,ComboboxEmpty,- ComboboxInput,ComboboxItem,ComboboxList,- ComboboxListFooter,ComboboxTrigger,- Tooltip,- TooltipContent,- TooltipTrigger,} from '@posthog/quill'+import { ComboboxLoadMoreFooter, ComboboxSearchField } from './ComboboxSearchChrome'import { githubRepositorySearchLogic } from './githubRepositorySearchLogic'export interface GitHubRepositoryComboboxProps {@@ -110,37 +106,14 @@ export function GitHubRepositoryCombobox({}/><ComboboxContent anchor={triggerRef} side="bottom" sideOffset={6} className="min-w-[280px]">- <div className="flex min-w-0 items-center gap-1 pe-2">- <div className="min-w-0 flex-1">- <ComboboxInput placeholder="Search repositories..." />- </div>- <Tooltip>- <TooltipTrigger- render={- <Button- variant="outline"- size="sm"- disabled={disabled || loading}- aria-label="Refresh repositories"- onMouseDown={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- }}- onClick={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- refresh()- }}- >- <IconRefresh className={loading ? 'animate-spin' : undefined} />- </Button>- }- />- <TooltipContent>Refresh repositories</TooltipContent>- </Tooltip>- </div>+ <ComboboxSearchField+ itemsLabel="repositories"+ loading={loading}+ disabled={disabled}+ onRefresh={refresh}+ /><ComboboxEmpty>- {showInlineLoadingState ? 'Loading repositories...' : error ? error : 'No repositories found.'}+ {showInlineLoadingState ? 'Loading repositories...' : (error ?? 'No repositories found.')}</ComboboxEmpty><ComboboxList>{(repo: string) =>@@ -157,30 +130,13 @@ export function GitHubRepositoryCombobox({</ComboboxList>{hasMore && (- <ComboboxListFooter>- <div className="px-2 pb-2">- <div className="px-1 pb-2 text-center text-muted text-xs">- {`Showing ${repositoryNames.length}+ ${trimmedSearchQuery ? 'matches' : 'repositories'}`}- </div>- <Button- variant="outline"- size="sm"- className="w-full justify-center"- disabled={loading}- onMouseDown={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- }}- onClick={(event: MouseEvent) => {- event.preventDefault()- event.stopPropagation()- loadMore()- }}- >- Load more- </Button>- </div>- </ComboboxListFooter>+ <ComboboxLoadMoreFooter+ loadedCount={repositoryNames.length}+ itemsLabel="repositories"+ searching={!!trimmedSearchQuery}+ loading={loading}+ onLoadMore={loadMore}+ />)}</ComboboxContent></Combobox>diff --git a/frontend/src/lib/integrations/githubBranchSearchLogic.test.ts b/frontend/src/lib/integrations/githubBranchSearchLogic.test.tsnew file mode 100644index 000000000000..499205a1f664--- /dev/null+++ b/frontend/src/lib/integrations/githubBranchSearchLogic.test.ts@@ -0,0 +1,29 @@+/* oxlint-disable react-hooks/rules-of-hooks -- useMocks is a test helper, not a React hook */+import { expectLogic } from 'kea-test-utils'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { githubBranchSearchLogic } from './githubBranchSearchLogic'++describe('githubBranchSearchLogic', () => {+ let logic: ReturnType<typeof githubBranchSearchLogic.build>++ afterEach(() => logic?.unmount())++ it('surfaces a branch loading failure', async () => {+ useMocks({+ get: {+ '/api/environments/:team_id/integrations/:id/github_branches/': () => [500, { detail: 'Unavailable' }],+ },+ })+ initKeaTests()+ logic = githubBranchSearchLogic({ integrationId: 1, repo: 'acme/web' })+ logic.mount()++ await expectLogic(logic, () => logic.actions.refresh()).toFinishAllListeners()++ expect(logic.values.loading).toBe(false)+ expect(logic.values.error).toBe("Couldn't load branches. Refresh and try again.")+ })+})diff --git a/frontend/src/lib/integrations/githubBranchSearchLogic.ts b/frontend/src/lib/integrations/githubBranchSearchLogic.tsindex 292f6154c92c..f3d389da28f0 100644--- a/frontend/src/lib/integrations/githubBranchSearchLogic.ts+++ b/frontend/src/lib/integrations/githubBranchSearchLogic.ts@@ -1,4 +1,4 @@-import { MakeLogicType, actions, afterMount, isBreakpoint, kea, key, listeners, path, props, reducers } from 'kea'+import { MakeLogicType, actions, isBreakpoint, kea, key, listeners, path, props, reducers } from 'kea'import api from 'lib/api'@@ -16,6 +16,7 @@ export interface githubBranchSearchLogicValues {branches: string[]currentOffset: numberdefaultBranch: string | null+ error: string | nullhasMore: booleanloading: booleansearchQuery: string@@ -29,8 +30,8 @@ export interface githubBranchSearchLogicActions {loadPage: (offset: number) => {offset: number}- loadPageFailure: () => {- value: true+ loadPageFailure: (error: string) => {+ error: string}loadPageSuccess: (branches: string[],@@ -83,7 +84,7 @@ export const githubBranchSearchLogic = kea<githubBranchSearchLogicType>([hasMore,offset,}),- loadPageFailure: true,+ loadPageFailure: (error: string) => ({ error }),loadMore: true,refresh: true,}),@@ -133,6 +134,16 @@ export const githubBranchSearchLogic = kea<githubBranchSearchLogicType>([loadPageFailure: () => false,},],+ error: [+ null as string | null,+ {+ setSearchQuery: () => null,+ refresh: () => null,+ loadPage: () => null,+ loadPageSuccess: () => null,+ loadPageFailure: (_, { error }) => error,+ },+ ],currentOffset: [0,{@@ -170,12 +181,8 @@ export const githubBranchSearchLogic = kea<githubBranchSearchLogicType>([if (isBreakpoint(e)) {throw e}- actions.loadPageFailure()+ actions.loadPageFailure("Couldn't load branches. Refresh and try again.")}},})),-- afterMount(({ actions }) => {- actions.loadPage(0)- }),])diff --git a/frontend/src/lib/integrations/integrationsLogic.ts b/frontend/src/lib/integrations/integrationsLogic.tsindex 2b09b1cfdf55..f8532040b010 100644--- a/frontend/src/lib/integrations/integrationsLogic.ts+++ b/frontend/src/lib/integrations/integrationsLogic.ts@@ -86,6 +86,7 @@ export interface integrationsLogicValues {| 'vercel')[]) => IntegrationType[]+ githubIntegrations: IntegrationType[]githubRepositories: Record<number, GitHubRepoApi[]>githubRepositoriesLoading: booleanintegrations: IntegrationType[] | null@@ -593,6 +594,7 @@ export interface integrationsLogicActions {export interface integrationsLogicMeta {__keaTypeGenInternalSelectorTypes: {slackIntegrations: (integrations: IntegrationType[] | null) => IntegrationType[] | undefined+ githubIntegrations: (integrations: IntegrationType[] | null) => IntegrationType[]getIntegrationsByKind: (integrations: IntegrationType[] | null) => (@@ -995,6 +997,12 @@ export const integrationsLogic = kea<integrationsLogicType>([return integrations?.filter((x) => x.kind == 'slack')},],+ githubIntegrations: [+ (s) => [s.integrations],+ (integrations: IntegrationType[] | null): IntegrationType[] => {+ return integrations?.filter((x) => x.kind === 'github') ?? []+ },+ ],getIntegrationsByKind: [(s) => [s.integrations],(integrations: IntegrationType[] | null) => {diff --git a/frontend/src/scenes/inbox/components/config/SelfDrivingSection.tsx b/frontend/src/scenes/inbox/components/config/SelfDrivingSection.tsxindex c64579cb856f..27cac8afa671 100644--- a/frontend/src/scenes/inbox/components/config/SelfDrivingSection.tsx+++ b/frontend/src/scenes/inbox/components/config/SelfDrivingSection.tsx@@ -1,7 +1,25 @@import { useActions, useValues } from 'kea'-import { IconRocket } from '@posthog/icons'+import { IconPlus, IconRocket, IconX } from '@posthog/icons'import { LemonSegmentedButton, LemonSkeleton, LemonSwitch } from '@posthog/lemon-ui'+import {+ Button,+ ButtonGroup,+ Collapsible,+ CollapsibleContent,+ CollapsibleTrigger,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill'++import { GitHubBranchCombobox } from 'lib/integrations/GitHubBranchCombobox'+import { GitHubRepositoryCombobox } from 'lib/integrations/GitHubRepositoryCombobox'+import { integrationsLogic } from 'lib/integrations/integrationsLogic'import { signalTeamConfigLogic } from '../../logics/signalTeamConfigLogic'import { PRIORITY_THRESHOLD_OPTIONS, SignalReportPriority } from '../../types'@@ -20,6 +38,188 @@ const THRESHOLD_SEGMENTS = PRIORITY_THRESHOLD_OPTIONS.map(({ value }) => ({label: THRESHOLD_SEGMENT_LABELS[value],}))+function BaseBranchOverrideRows(): JSX.Element | null {+ const { baseBranchOverrides, teamConfigUpdating } = useValues(signalTeamConfigLogic)+ const { updateBaseBranchOverride, removeBaseBranchOverride } = useActions(signalTeamConfigLogic)+ const { githubIntegrations } = useValues(integrationsLogic)++ if (baseBranchOverrides.length === 0) {+ return null+ }++ // A stored override is just `org/repo`, so the owning integration has to be recovered from the owner+ // half. A GitHub integration's display name is the installation's account login, which is that owner.+ const integrationsByOwner = new Map(+ githubIntegrations.map((integration) => [integration.display_name.toLowerCase(), integration])+ )++ return (+ <div className="flex flex-col gap-1">+ {baseBranchOverrides.map(({ repo, branch }) => {+ const integration = integrationsByOwner.get(repo.split('/')[0])+ return (+ <div key={repo} className="flex items-center gap-1">+ <span className="text-xs text-default min-w-0 flex-1 truncate" title={repo}>+ {repo}+ </span>+ {integration ? (+ <GitHubBranchCombobox+ integrationId={integration.id}+ repo={repo}+ value={branch}+ allowCustomValues={false}+ disabled={teamConfigUpdating}+ onChange={(next) => {+ if (next) {+ updateBaseBranchOverride(repo, next)+ }+ }}+ />+ ) : (+ <span className="text-xs text-muted shrink-0">{branch}</span>+ )}+ <Button+ variant="outline"+ size="sm"+ loading={teamConfigUpdating}+ aria-label={`Remove base branch override for ${repo}`}+ onClick={() => removeBaseBranchOverride(repo)}+ >+ <IconX />+ </Button>+ </div>+ )+ })}+ </div>+ )+}++function BaseBranchOverridePicker(): JSX.Element {+ const {+ draftBaseBranchIntegrationId,+ draftBaseBranchRepo,+ draftBaseBranchBranch,+ addBaseBranchOverrideDisabledReason,+ teamConfigUpdating,+ } = useValues(signalTeamConfigLogic)+ const { setDraftBaseBranchIntegrationId, setDraftBaseBranchRepo, setDraftBaseBranchBranch, addBaseBranchOverride } =+ useActions(signalTeamConfigLogic)+ const { githubIntegrations } = useValues(integrationsLogic)++ const integrationId = draftBaseBranchIntegrationId ?? githubIntegrations[0].id++ return (+ <div className="flex flex-wrap items-center gap-1">+ {githubIntegrations.length > 1 && (+ <DropdownMenu>+ <DropdownMenuTrigger+ render={+ <Button+ variant="outline"+ size="sm"+ aria-label="GitHub organization"+ disabled={teamConfigUpdating}+ >+ <span className="min-w-0 truncate">+ {githubIntegrations.find((integration) => integration.id === integrationId)+ ?.display_name ?? 'GitHub'}+ </span>+ </Button>+ }+ />+ <DropdownMenuContent>+ {githubIntegrations.map((integration) => (+ <DropdownMenuItem+ key={integration.id}+ onClick={() => setDraftBaseBranchIntegrationId(integration.id)}+ >+ {integration.display_name}+ </DropdownMenuItem>+ ))}+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ <ButtonGroup>+ <GitHubRepositoryCombobox+ integrationId={integrationId}+ value={draftBaseBranchRepo}+ disabled={teamConfigUpdating}+ onChange={(repo) => setDraftBaseBranchRepo(repo ?? '')}+ placeholder="Repository"+ />+ {draftBaseBranchRepo ? (+ <GitHubBranchCombobox+ integrationId={integrationId}+ repo={draftBaseBranchRepo}+ value={draftBaseBranchBranch}+ allowCustomValues={false}+ disabled={teamConfigUpdating}+ onChange={(branch) => setDraftBaseBranchBranch(branch ?? '')}+ />+ ) : null}+ </ButtonGroup>+ <Tooltip>+ <TooltipTrigger+ render={+ <Button+ variant="outline"+ size="sm"+ disabled={!!addBaseBranchOverrideDisabledReason}+ loading={teamConfigUpdating}+ aria-label="Add base branch override"+ onClick={() => addBaseBranchOverride()}+ >+ <IconPlus />+ Add+ </Button>+ }+ />+ <TooltipContent>{addBaseBranchOverrideDisabledReason ?? 'Add base branch override'}</TooltipContent>+ </Tooltip>+ </div>+ )+}++/**+ * Collapsed by default, because targeting anything but the repo's default branch is the exception.+ * Opens on its own when overrides exist, so a configured team isn't left to discover them behind a+ * chevron; the count keeps that state readable even once collapsed again.+ */+function BaseBranchOverrides(): JSX.Element {+ const { baseBranchOverrides } = useValues(signalTeamConfigLogic)+ const { githubIntegrations } = useValues(integrationsLogic)++ // The Collapsible root fills itself with --muted while open or hovered, which reads as an+ // off-color patch against the card. The trigger owns the hover instead.+ return (+ <Collapsible defaultOpen={baseBranchOverrides.length > 0} className="bg-transparent hover:bg-transparent">+ {/* px-2.5/py-1.5 matches the Threshold row above; the Button's own fill is dropped so the+ row reads as a label, not a band, leaving only the hover as the affordance. */}+ <CollapsibleTrigger className="w-full h-auto px-2.5 py-1.5 text-xs text-secondary font-normal bg-transparent hover:bg-[var(--fill-hover)]">+ <span className="flex-1 text-left">Base branch overrides</span>+ {baseBranchOverrides.length > 0 && (+ <span className="text-tertiary tabular-nums">{baseBranchOverrides.length}</span>+ )}+ </CollapsibleTrigger>+ {/* Padding goes on the panel itself rather than a nested wrapper, which would stack with+ the panel's own inset. Same 10px/6px as the trigger and the Threshold row. */}+ <CollapsibleContent className="flex flex-col gap-1.5 px-2.5 pb-1.5">+ <p className="text-[11px] text-tertiary leading-snug mb-0">+ Otherwise, PRs use GitHub's default branch.+ </p>+ <BaseBranchOverrideRows />+ {githubIntegrations.length > 0 ? (+ <BaseBranchOverridePicker />+ ) : (+ <p className="text-[11px] text-tertiary leading-snug mb-0">+ Connect GitHub above to add an override.+ </p>+ )}+ </CollapsibleContent>+ </Collapsible>+ )+}+/*** Team-wide PR-generation control, backed by `autostart_enabled` and `default_autostart_priority`* on `signalTeamConfigLogic`. The inline switch is the master opt-out for autonomous inbox PRs;@@ -30,7 +230,7 @@ const THRESHOLD_SEGMENTS = PRIORITY_THRESHOLD_OPTIONS.map(({ value }) => ({* threshold) that can't live inside that card's single button/link wrapper.*/export function SelfDrivingSection(): JSX.Element {- const { teamConfig, teamConfigLoading, autostartEnabled, defaultAutostartPriority } =+ const { teamConfig, teamConfigLoading, teamConfigUpdating, autostartEnabled, defaultAutostartPriority } =useValues(signalTeamConfigLogic)const { patchTeamConfig } = useActions(signalTeamConfigLogic)@@ -49,6 +249,7 @@ export function SelfDrivingSection(): JSX.Element {<span className="text-[13px] font-semibold text-default">PR generation</span><LemonSwitchchecked={autostartEnabled}+ loading={teamConfigUpdating}onChange={(enabled) => patchTeamConfig({ autostart_enabled: enabled })}aria-label="Generate PRs for actionable reports automatically"/>@@ -57,19 +258,27 @@ export function SelfDrivingSection(): JSX.Element {</div></div>- <div className="border-t border-primary bg-surface-secondary px-2.5 py-1.5">+ <div className="border-t border-primary bg-surface-secondary">{autostartEnabled ? (- <div className="flex items-center justify-between gap-2">- <span className="text-xs text-secondary shrink-0">Threshold</span>- <LemonSegmentedButton- size="xsmall"- value={defaultAutostartPriority}- options={THRESHOLD_SEGMENTS}- onChange={(next) => patchTeamConfig({ default_autostart_priority: next })}- />- </div>+ <>+ <div className="flex items-center justify-between gap-2 px-2.5 py-1.5">+ <span className="text-xs text-secondary shrink-0">Threshold</span>+ <LemonSegmentedButton+ size="xsmall"+ value={defaultAutostartPriority}+ options={THRESHOLD_SEGMENTS}+ disabledReason={teamConfigUpdating ? 'Saving changes' : undefined}+ onChange={(next) => patchTeamConfig({ default_autostart_priority: next })}+ />+ </div>+ <div className="border-t border-primary">+ <BaseBranchOverrides />+ </div>+ </>) : (- <p className="text-xs text-secondary mb-0">Reports still arrive and notify your team.</p>+ <p className="text-xs text-secondary mb-0 px-2.5 py-1.5">+ Reports still arrive and notify your team.+ </p>)}</div></div>diff --git a/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.test.ts b/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.test.tsnew file mode 100644index 000000000000..610277a1517b--- /dev/null+++ b/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.test.ts@@ -0,0 +1,179 @@+import { waitFor } from '@testing-library/react'+/* oxlint-disable react-hooks/rules-of-hooks -- useMocks is a test helper, not a React hook */+import { expectLogic } from 'kea-test-utils'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import type { SignalTeamConfig } from '../types'+import { signalTeamConfigLogic } from './signalTeamConfigLogic'++describe('signalTeamConfigLogic', () => {+ let logic: ReturnType<typeof signalTeamConfigLogic.build>+ let lastPostBody: Partial<SignalTeamConfig> | null++ const mountWith = async (baseBranches: Record<string, string>): Promise<void> => {+ let serverConfig: SignalTeamConfig = {+ id: 'cfg-1',+ autostart_enabled: true,+ default_autostart_priority: 'P4',+ autostart_base_branches: baseBranches,+ }+ lastPostBody = null+ useMocks({+ get: { '/api/projects/:team_id/signals/config/': () => [200, serverConfig] },+ post: {+ '/api/projects/:team_id/signals/config/': async ({ request }) => {+ lastPostBody = (await request.json()) as Partial<SignalTeamConfig>+ serverConfig = { ...serverConfig, ...lastPostBody }+ return [200, serverConfig]+ },+ },+ })+ initKeaTests()+ logic = signalTeamConfigLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ }++ afterEach(() => logic?.unmount())++ it('adds an override without clobbering existing repos, and clears the draft', async () => {+ await mountWith({ 'acme/web': 'staging' })+ logic.actions.setDraftBaseBranchRepo('Acme/API')+ logic.actions.setDraftBaseBranchBranch(' develop ')+ logic.actions.addBaseBranchOverride()+ await expectLogic(logic).toFinishAllListeners()++ expect(lastPostBody?.autostart_base_branches).toEqual({ 'acme/web': 'staging', 'acme/api': 'develop' })+ expect(logic.values.draftBaseBranchRepo).toBe('')+ expect(logic.values.draftBaseBranchBranch).toBe('')+ expect(logic.values.baseBranchOverrides).toEqual([+ { repo: 'acme/api', branch: 'develop' },+ { repo: 'acme/web', branch: 'staging' },+ ])+ })++ it('keeps the draft available when adding an override fails', async () => {+ const serverConfig: SignalTeamConfig = {+ id: 'cfg-1',+ autostart_enabled: true,+ default_autostart_priority: 'P4',+ autostart_base_branches: {},+ }+ useMocks({+ get: { '/api/projects/:team_id/signals/config/': () => [200, serverConfig] },+ post: { '/api/projects/:team_id/signals/config/': () => [500, { detail: 'Failed to save' }] },+ })+ initKeaTests()+ logic = signalTeamConfigLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ logic.actions.setDraftBaseBranchRepo('acme/api')+ logic.actions.setDraftBaseBranchBranch('develop')+ logic.actions.addBaseBranchOverride()+ await expectLogic(logic).toFinishAllListeners()++ expect(logic.values.draftBaseBranchRepo).toBe('acme/api')+ expect(logic.values.draftBaseBranchBranch).toBe('develop')+ expect(logic.values.teamConfigUpdating).toBe(false)+ expect(logic.values.baseBranchOverrides).toEqual([])+ })++ it.each([+ ['repo without a slash', 'acmeweb', 'develop'],+ ['repo with an empty half', 'acme/', 'develop'],+ ['blank branch', 'acme/api', ' '],+ ])('does not persist an incomplete draft (%s)', async (_label, repo, branch) => {+ await mountWith({ 'acme/web': 'staging' })+ logic.actions.setDraftBaseBranchRepo(repo)+ logic.actions.setDraftBaseBranchBranch(branch)+ logic.actions.addBaseBranchOverride()+ await expectLogic(logic).toFinishAllListeners()++ expect(lastPostBody).toBeNull()+ expect(logic.values.baseBranchOverrides).toEqual([{ repo: 'acme/web', branch: 'staging' }])+ })++ it('drops the drafted branch when the repository changes', async () => {+ await mountWith({})+ logic.actions.setDraftBaseBranchRepo('acme/web')+ logic.actions.setDraftBaseBranchBranch('release/web')+ logic.actions.setDraftBaseBranchRepo('acme/api')++ expect(logic.values.draftBaseBranchBranch).toBe('')+ expect(logic.values.addBaseBranchOverrideDisabledReason).toBe('Choose a branch first')+ })++ it('updates an existing override branch without touching others', async () => {+ await mountWith({ 'acme/web': 'staging', 'acme/api': 'develop' })+ logic.actions.updateBaseBranchOverride('acme/web', 'release')+ await expectLogic(logic).toFinishAllListeners()++ expect(lastPostBody?.autostart_base_branches).toEqual({ 'acme/web': 'release', 'acme/api': 'develop' })+ })++ it('serializes rapid override updates so the latest map is persisted last', async () => {+ const initialConfig: SignalTeamConfig = {+ id: 'cfg-1',+ autostart_enabled: true,+ default_autostart_priority: 'P4',+ autostart_base_branches: { 'acme/web': 'staging' },+ }+ const postBodies: Partial<SignalTeamConfig>[] = []+ let resolveFirstUpdate: (() => void) | undefined+ const firstUpdatePending = new Promise<void>((resolve) => {+ resolveFirstUpdate = resolve+ })++ useMocks({+ get: { '/api/projects/:team_id/signals/config/': () => [200, initialConfig] },+ post: {+ '/api/projects/:team_id/signals/config/': async ({ request }) => {+ const body = (await request.json()) as Partial<SignalTeamConfig>+ postBodies.push(body)+ if (postBodies.length === 1) {+ await firstUpdatePending+ }+ return [200, { ...initialConfig, ...body }]+ },+ },+ })+ initKeaTests()+ logic = signalTeamConfigLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ logic.actions.updateBaseBranchOverride('acme/web', 'release-one')+ logic.actions.updateBaseBranchOverride('acme/web', 'release-two')++ await waitFor(() => expect(postBodies).toHaveLength(1))+ expect(logic.values.teamConfigUpdating).toBe(true)+ resolveFirstUpdate?.()+ await expectLogic(logic).toFinishAllListeners()++ expect(postBodies).toEqual([+ { autostart_base_branches: { 'acme/web': 'release-one' } },+ { autostart_base_branches: { 'acme/web': 'release-two' } },+ ])+ expect(logic.values.teamConfigUpdating).toBe(false)+ })++ it('does not persist an update to the branch already stored', async () => {+ await mountWith({ 'acme/web': 'staging' })+ logic.actions.updateBaseBranchOverride('acme/web', 'staging')+ await expectLogic(logic).toFinishAllListeners()++ expect(lastPostBody).toBeNull()+ })++ it('removes only the targeted override', async () => {+ await mountWith({ 'acme/web': 'staging', 'acme/api': 'develop' })+ logic.actions.removeBaseBranchOverride('acme/web')+ await expectLogic(logic).toFinishAllListeners()++ expect(lastPostBody?.autostart_base_branches).toEqual({ 'acme/api': 'develop' })+ expect(logic.values.baseBranchOverrides).toEqual([{ repo: 'acme/api', branch: 'develop' }])+ })+})diff --git a/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts b/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.tsindex 113498b78de6..9c7ef94fa60d 100644--- a/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts+++ b/frontend/src/scenes/inbox/logics/signalTeamConfigLogic.ts@@ -1,4 +1,4 @@-import { MakeLogicType, actions, afterMount, isBreakpoint, kea, listeners, path, reducers, selectors } from 'kea'+import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'import { lemonToast } from '@posthog/lemon-ui'@@ -7,16 +7,38 @@ import api from 'lib/api'import type { SignalReportPriority, SignalTeamConfig } from '../types'+export interface BaseBranchOverride {+ repo: string+ branch: string+}++function isRepositoryKey(repo: string): boolean {+ const parts = repo.trim().split('/')+ return parts.length === 2 && parts.every((part) => !!part)+}+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface signalTeamConfigLogicValues {+ addBaseBranchOverrideDisabledReason: string | nullautostartEnabled: boolean+ baseBranchOverrides: BaseBranchOverride[]defaultAutostartPriority: SignalReportPriority+ draftBaseBranchBranch: string+ draftBaseBranchIntegrationId: number | null+ draftBaseBranchRepo: stringteamConfig: SignalTeamConfig | nullteamConfigLoading: boolean+ teamConfigUpdating: boolean}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface signalTeamConfigLogicActions {+ addBaseBranchOverride: () => {+ value: true+ }+ clearDraftBaseBranch: () => {+ value: true+ }loadTeamConfig: () => anyloadTeamConfigFailure: (error: string,@@ -32,9 +54,52 @@ export interface signalTeamConfigLogicActions {teamConfig: SignalTeamConfigpayload?: any}- patchTeamConfig: (patch: Partial<SignalTeamConfig>) => {+ patchTeamConfig: (+ patch: Partial<SignalTeamConfig>,+ clearDraftOnSuccess?: boolean+ ) => {+ clearDraftOnSuccess: booleanpatch: Partial<SignalTeamConfig>}+ patchTeamConfigFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ patchTeamConfigSuccess: (+ teamConfig: SignalTeamConfig,+ payload?: {+ clearDraftOnSuccess: boolean+ patch: Partial<SignalTeamConfig>+ }+ ) => {+ teamConfig: SignalTeamConfig+ payload?: {+ clearDraftOnSuccess: boolean+ patch: Partial<SignalTeamConfig>+ }+ }+ removeBaseBranchOverride: (repo: string) => {+ repo: string+ }+ setDraftBaseBranchBranch: (branch: string) => {+ branch: string+ }+ setDraftBaseBranchIntegrationId: (integrationId: number | null) => {+ integrationId: number | null+ }+ setDraftBaseBranchRepo: (repo: string) => {+ repo: string+ }+ updateBaseBranchOverride: (+ repo: string,+ branch: string+ ) => {+ branch: string+ repo: string+ }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -42,6 +107,12 @@ export interface signalTeamConfigLogicMeta {__keaTypeGenInternalSelectorTypes: {autostartEnabled: (teamConfig: SignalTeamConfig | null) => booleandefaultAutostartPriority: (teamConfig: SignalTeamConfig | null) => SignalReportPriority+ baseBranchOverrides: (teamConfig: SignalTeamConfig | null) => BaseBranchOverride[]+ teamConfigUpdating: (teamConfigLoading: boolean, teamConfig: SignalTeamConfig | null) => boolean+ addBaseBranchOverrideDisabledReason: (+ draftBaseBranchRepo: string,+ draftBaseBranchBranch: string+ ) => string | null}}@@ -65,19 +136,50 @@ export type signalTeamConfigLogicType = MakeLogicType<export const signalTeamConfigLogic = kea<signalTeamConfigLogicType>([path(['scenes', 'inbox', 'logics', 'signalTeamConfigLogic']),actions({- // Partial update of the singleton, e.g. `{ default_slack_notification_channel: null }`- // to clear the team channel. One action serves every patchable field.- patchTeamConfig: (patch: Partial<SignalTeamConfig>) => ({ patch }),+ // Declared up front so the loader below adopts this signature instead of generating a+ // single-payload one: callers say `patchTeamConfig({ autostart_enabled: false })`.+ patchTeamConfig: (patch: Partial<SignalTeamConfig>, clearDraftOnSuccess: boolean = false) => ({+ patch,+ clearDraftOnSuccess,+ }),+ setDraftBaseBranchIntegrationId: (integrationId: number | null) => ({ integrationId }),+ setDraftBaseBranchRepo: (repo: string) => ({ repo }),+ setDraftBaseBranchBranch: (branch: string) => ({ branch }),+ clearDraftBaseBranch: true,+ addBaseBranchOverride: true,+ updateBaseBranchOverride: (repo: string, branch: string) => ({ repo, branch }),+ removeBaseBranchOverride: (repo: string) => ({ repo }),}),- loaders({- teamConfig: [- null as SignalTeamConfig | null,- {- loadTeamConfig: async () => {- return await api.signalTeamConfig.get()+ loaders(() => {+ // Every patch of `autostart_base_branches` sends the whole map, so two in flight at once let the+ // server settle on whichever lands last rather than whichever was asked for last.+ let updateQueue: Promise<unknown> = Promise.resolve()++ return {+ teamConfig: [+ null as SignalTeamConfig | null,+ {+ loadTeamConfig: async () => {+ return await api.signalTeamConfig.get()+ },+ // Partial update of the singleton, e.g. `{ default_slack_notification_channel: null }`+ // to clear the team channel. One action serves every patchable field.+ patchTeamConfig: async ({+ patch,+ }: {+ patch: Partial<SignalTeamConfig>+ clearDraftOnSuccess: boolean+ }) => {+ const update = updateQueue.then(() => api.signalTeamConfig.update(patch))+ updateQueue = update.then(+ () => undefined,+ () => undefined+ )+ return await update+ },},- },- ],+ ],+ }}),reducers({// Optimistically reflect the patched values so the controls don't flicker@@ -85,6 +187,29 @@ export const signalTeamConfigLogic = kea<signalTeamConfigLogicType>([teamConfig: {patchTeamConfig: (state, { patch }) => (state ? { ...state, ...patch } : state),},+ draftBaseBranchIntegrationId: [+ null as number | null,+ {+ setDraftBaseBranchIntegrationId: (_, { integrationId }) => integrationId,+ },+ ],+ draftBaseBranchRepo: [+ '',+ {+ setDraftBaseBranchRepo: (_, { repo }) => repo,+ setDraftBaseBranchIntegrationId: () => '',+ clearDraftBaseBranch: () => '',+ },+ ],+ draftBaseBranchBranch: [+ '',+ {+ setDraftBaseBranchBranch: (_, { branch }) => branch,+ setDraftBaseBranchRepo: () => '',+ setDraftBaseBranchIntegrationId: () => '',+ clearDraftBaseBranch: () => '',+ },+ ],}),selectors({// Master switch for autonomous inbox PRs: only an explicit false disables@@ -98,25 +223,74 @@ export const signalTeamConfigLogic = kea<signalTeamConfigLogicType>([(teamConfig: SignalTeamConfig | null): SignalReportPriority =>teamConfig?.default_autostart_priority ?? 'P4',],+ baseBranchOverrides: [+ (s) => [s.teamConfig],+ (teamConfig: SignalTeamConfig | null): BaseBranchOverride[] =>+ Object.entries(teamConfig?.autostart_base_branches ?? {})+ .map(([repo, branch]) => ({ repo, branch }))+ .sort((a, b) => a.repo.localeCompare(b.repo)),+ ],+ // One loader serves both the initial fetch and every patch, so what separates them is whether+ // there's already a config on screen to be updating.+ teamConfigUpdating: [+ (s) => [s.teamConfigLoading, s.teamConfig],+ (teamConfigLoading: boolean, teamConfig: SignalTeamConfig | null): boolean =>+ teamConfigLoading && teamConfig !== null,+ ],+ // Doubles as the add button's tooltip, so what blocks the add is stated once rather than+ // derived separately for the guard and for the copy.+ addBaseBranchOverrideDisabledReason: [+ (s) => [s.draftBaseBranchRepo, s.draftBaseBranchBranch],+ (draftBaseBranchRepo: string, draftBaseBranchBranch: string): string | null => {+ if (!isRepositoryKey(draftBaseBranchRepo)) {+ return 'Choose a repository first'+ }+ return draftBaseBranchBranch.trim() ? null : 'Choose a branch first'+ },+ ],}),- listeners(({ actions }) => ({- patchTeamConfig: async ({ patch }, breakpoint) => {- try {- const config = await api.signalTeamConfig.update(patch)- // A newer patch was dispatched while this one was in flight — drop the- // stale response so out-of-order arrivals can't overwrite the latest value.- breakpoint()- actions.loadTeamConfigSuccess(config)- } catch (error: any) {- if (isBreakpoint(error)) {- throw error+ listeners(({ actions, values }) => {+ return {+ addBaseBranchOverride: () => {+ if (values.addBaseBranchOverrideDisabledReason) {+ return+ }+ actions.patchTeamConfig(+ {+ autostart_base_branches: {+ ...values.teamConfig?.autostart_base_branches,+ [values.draftBaseBranchRepo.trim().toLowerCase()]: values.draftBaseBranchBranch.trim(),+ },+ },+ true+ )+ },+ updateBaseBranchOverride: ({ repo, branch }) => {+ const trimmed = branch.trim()+ if (!trimmed || values.teamConfig?.autostart_base_branches?.[repo] === trimmed) {+ return+ }+ actions.patchTeamConfig({+ autostart_base_branches: { ...values.teamConfig?.autostart_base_branches, [repo]: trimmed },+ })+ },+ removeBaseBranchOverride: ({ repo }) => {+ const next = { ...values.teamConfig?.autostart_base_branches }+ delete next[repo]+ actions.patchTeamConfig({ autostart_base_branches: next })+ },+ patchTeamConfigSuccess: ({ payload }) => {+ if (payload?.clearDraftOnSuccess) {+ actions.clearDraftBaseBranch()}- lemonToast.error(error?.detail ?? error?.message ?? 'Failed to update team self-driving settings')- // Resync so the optimistic value doesn't linger after a failed update.+ },+ patchTeamConfigFailure: ({ error, errorObject }) => {+ lemonToast.error(errorObject?.detail ?? error ?? 'Failed to update team self-driving settings')+ // The optimistic value is now a lie, and the server holds the truth about what stuck.actions.loadTeamConfig()- }- },- })),+ },+ }+ }),afterMount(({ actions }) => {actions.loadTeamConfig()}),