Skip to content

: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.

feat(signals): add a Linear team picker to the inbox (#101792)

Alex Lebedev3006555f55b1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 28b228fdc158..6402f94b3e64 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9064,6 +9064,14 @@ snapshots:
hash: v1.k794b7964.f2b5351f205a0abb1531706c02950c727ede9d9f7cf220869b571442805a5a24.NvzH40X-7cVbDTiW0u9CRIwI3ENeZ37ePippBtcZg2M
scenes-app-inbox-implementbutton--default--light:
hash: v1.k794b7964.3ae4db003fb100b088592e891f4f1dad7cc88fa9107562a7475bb2cb13e40416.IuzBG5uabdrl1YowQw8jUlTVOtRwExLrffxwo8ok2_4
+ scenes-app-inbox-linearteamsmodal--enable-flow--dark:
+ hash: v1.k794b7964.8165b65fb6ebc23218e341ae6928d679f19f91bc291406822ea9507e82e00f0f.S6iLt3oXYtv-DjPCA778nKLnxkVe7TvxGPK_GH4AMbs
+ scenes-app-inbox-linearteamsmodal--enable-flow--light:
+ hash: v1.k794b7964.f91f4f632ae8b86cd3ce8b89e77792588781aa7f26cda73f46c86345f5cf2606.-bq0NAYsdjQOUSysVENmzeD7BfdgHOF_70PMU9K4HFs
+ scenes-app-inbox-linearteamsmodal--teams-picked--dark:
+ hash: v1.k794b7964.1203e57baa347acd4e5b275dfed5f3c22728009a7373477de73ddf0783e93bc3.ULU5wVI3B8RrV8cDyd5q42JvAQMCPYz3lDFDtzPidv8
+ scenes-app-inbox-linearteamsmodal--teams-picked--light:
+ hash: v1.k794b7964.fbafa81bc3423f3f6daa5a4adb7cf061fb9cc7cdce756414a696daa088d2ccc0.A7XLMQQj4uatJWJApnBbLc1WkTuhCnS49DAYAlpr_qo
scenes-app-inbox-pullrequestdiffview--default--dark:
hash: v1.k794b7964.564cd678d9da50089c918c63d37c816257091c6c9d7d2f957dc9c96f596d34dc.8ICzP4d5gRBF0h4CT87lZgk82tCHyXIOsszi6P3JQ-M
scenes-app-inbox-pullrequestdiffview--default--light:
diff --git a/frontend/src/lib/integrations/integrationsLogic.ts b/frontend/src/lib/integrations/integrationsLogic.ts
index ae77ac7042f0..25839d087965 100644
--- a/frontend/src/lib/integrations/integrationsLogic.ts
+++ b/frontend/src/lib/integrations/integrationsLogic.ts
@@ -133,6 +133,7 @@ export interface integrationsLogicValues {
githubRepositoriesTotal: Record<number, number>
integrations: IntegrationType[] | null
integrationsLoading: boolean
+ linearIntegrations: IntegrationType[]
linkedGithubInstallation: IntegrationType | null
linkedGithubInstallationLoading: boolean
newIntegrationModalId: string | null
@@ -613,6 +614,7 @@ export interface integrationsLogicMeta {
__keaTypeGenInternalSelectorTypes: {
slackIntegrations: (integrations: IntegrationType[] | null) => IntegrationType[] | undefined
githubIntegrations: (integrations: IntegrationType[] | null) => IntegrationType[]
+ linearIntegrations: (integrations: IntegrationType[] | null) => IntegrationType[]
githubAvailableInstallations: (
githubAvailableInstallationsResponse: GitHubAvailableInstallationsResponseApi | null
) => GitHubAvailableInstallationApi[] | null
@@ -1167,6 +1169,12 @@ export const integrationsLogic = kea<integrationsLogicType>([
return integrations?.filter((x) => x.kind === 'github') ?? []
},
],
+ linearIntegrations: [
+ (s) => [s.integrations],
+ (integrations: IntegrationType[] | null): IntegrationType[] => {
+ return integrations?.filter((x) => x.kind === 'linear') ?? []
+ },
+ ],
githubAvailableInstallations: [
(s) => [s.githubAvailableInstallationsResponse],
(response: GitHubAvailableInstallationsResponseApi | null): GitHubAvailableInstallationApi[] | null => {
diff --git a/products/signals/frontend/inbox/components/config/AgentsRoster.tsx b/products/signals/frontend/inbox/components/config/AgentsRoster.tsx
index ec549335f9a4..3b8dabf06634 100644
--- a/products/signals/frontend/inbox/components/config/AgentsRoster.tsx
+++ b/products/signals/frontend/inbox/components/config/AgentsRoster.tsx
@@ -23,9 +23,10 @@ import type { SyncStatusEnumApi } from 'products/engineering_analytics/frontend/
import { sourceSteeringIsSet } from '../../logics/sourceSteeringModalLogic'
import { signalSourcesLogic } from '../../signalSourcesLogic'
import type { SourceToolDataStatus, SourceToolStatus } from '../../signalSourcesLogic'
-import { SignalSourceConfig, SignalSourceConfigStatus, SignalSourceType } from '../../types'
+import { SignalSourceConfig, SignalSourceConfigStatus, SignalSourceType, linearTeamIdsFromConfig } from '../../types'
import { getSourceProductMeta } from '../badges/sourceProductIcons'
import { AGENT_ROSTER_GROUPS, AgentRosterDefinition, AgentRosterGroup, AgentRosterSource } from './agentRosterMeta'
+import { LinearTeamsModal } from './LinearTeamsModal'
import { SourceSteeringModal } from './SourceSteeringModal'
type AgentRosterStatus = 'standby' | 'watching' | 'syncing' | 'sync_failed'
@@ -61,6 +62,14 @@ function entityKindLabel(kind: string): string {
/** Above this many entities the list gets a filter box. */
const ENTITY_FILTER_THRESHOLD = 8
+function linearTeamsSummary(config: SignalSourceConfig): string {
+ const count = linearTeamIdsFromConfig(config.config).length
+ if (count === 0) {
+ return 'Reads issues from all Linear teams.'
+ }
+ return `Reads issues from ${count} Linear ${count === 1 ? 'team' : 'teams'}.`
+}
+
/** The entity rows are part of the source list, so an unbounded one would push every source below it off screen. */
const ENTITY_VISIBLE_LIMIT = 8
@@ -89,6 +98,13 @@ interface RosterEntity {
enabled: boolean
}
+interface SourceFilters {
+ summary: string
+ changeLabel: string
+ onChange: () => void
+ disabledReason?: string
+}
+
/** Per-source derived state assembled by `AgentsRoster` from `signalSourcesLogic`. */
interface AgentSourceState {
armed: boolean
@@ -224,7 +240,7 @@ interface ExpansionProps {
enablingTool: boolean
onEnableTool: (tool: SourceToolStatus) => void
onToggleEntity: (entityId: string) => void
- onConfigureFilters?: () => void
+ filters?: SourceFilters
/** Opens the steering form. Only set for steerable sources that are on with a persisted config row. */
onSteer?: () => void
onRetryData: () => void
@@ -293,7 +309,7 @@ function Expansion({
enablingTool,
onEnableTool,
onToggleEntity,
- onConfigureFilters,
+ filters,
onSteer,
onRetryData,
}: ExpansionProps): JSX.Element {
@@ -312,7 +328,7 @@ function Expansion({
const steeringIsSet = state.steeringConfigs.some(sourceSteeringIsSet)
// `ToolDataStatus` renders nothing for an unavailable status, so the meta line would be empty.
const hasToolLine = !!tool && (toolOff || tool.dataStatus !== 'unavailable')
- const hasMetaLine = hasToolLine || !!onSteer || !!onConfigureFilters
+ const hasMetaLine = hasToolLine || !!onSteer
const newEntityButton = agent.manageUrl ? (
<LemonButton size="xsmall" type="secondary" to={agent.manageUrl} icon={<IconPlus />} targetBlank>
New {agent.entityNounSingular}
@@ -372,14 +388,23 @@ function Expansion({
{steeringIsSet ? 'Edit guidance' : 'Add guidance'}
</LemonButton>
)}
- {onConfigureFilters && (
- <LemonButton type="secondary" size="xsmall" onClick={onConfigureFilters}>
- Configure filters
- </LemonButton>
- )}
</div>
</div>
)}
+ {filters && (
+ <div className="flex items-center gap-2">
+ <span className="text-xs text-secondary">{filters.summary}</span>
+ <LemonButton
+ type="secondary"
+ size="xsmall"
+ onClick={filters.onChange}
+ disabledReason={filters.disabledReason}
+ data-attr="signal-source-change-filters"
+ >
+ {filters.changeLabel}
+ </LemonButton>
+ </div>
+ )}
</div>
{state.entitiesLoading ? (
@@ -467,7 +492,7 @@ interface AgentRowProps {
onToggle: (source: AgentRosterSource) => void
onToggleEntity: (source: AgentRosterSource, entityId: string) => void
onEnableTool: (tool: SourceToolStatus) => void
- onConfigureFilters?: () => void
+ filters?: SourceFilters
onSteer?: () => void
onRetryData: () => void
}
@@ -482,7 +507,7 @@ const AgentRow = memo(function AgentRow({
onToggle,
onToggleEntity,
onEnableTool,
- onConfigureFilters,
+ filters,
onSteer,
onRetryData,
}: AgentRowProps): JSX.Element {
@@ -584,7 +609,7 @@ const AgentRow = memo(function AgentRow({
enablingTool={enablingTool}
onEnableTool={onEnableTool}
onToggleEntity={(entityId) => onToggleEntity(agent.source, entityId)}
- onConfigureFilters={onConfigureFilters}
+ filters={filters}
onSteer={onSteer}
onRetryData={onRetryData}
/>
@@ -647,8 +672,11 @@ export function AgentsRoster(): JSX.Element {
enablingTool,
sourceConfigsLoadFailed,
sourceConfigsLoading,
+ linearTeamsPicker,
} = useValues(signalSourcesLogic)
const {
+ openLinearTeamsPicker,
+ closeLinearTeamsPicker,
toggleConversations,
toggleErrorTracking,
toggleErrorTrackingType,
@@ -918,6 +946,23 @@ export function AgentsRoster(): JSX.Element {
state.steeringConfigs.every((config) => !config.id.startsWith('new_'))
? state.steeringConfigs
: null
+ const filters =
+ agent.source === 'linear' &&
+ linearIssuesConfig &&
+ !linearIssuesConfig.id.startsWith('new_')
+ ? {
+ summary: linearTeamsSummary(linearIssuesConfig),
+ changeLabel: 'Change teams',
+ onChange: () =>
+ openLinearTeamsPicker({ enableOnSave: false, viaSetupWizard: false }),
+ // A save or reload can replace the row, and the picker reads it on open.
+ disabledReason: isLinearIssuesToggling
+ ? 'Saving'
+ : sourceConfigsLoading
+ ? 'Refreshing'
+ : undefined,
+ }
+ : undefined
return (
<AgentRow
key={agent.source}
@@ -934,7 +979,7 @@ export function AgentsRoster(): JSX.Element {
onToggle={handleToggle}
onToggleEntity={handleToggleEntity}
onEnableTool={(tool) => tool.enablement && enableSourceTool(tool.enablement)}
- onConfigureFilters={undefined}
+ filters={filters}
onSteer={
steeringConfigs
? () => setSteeringTarget({ configs: steeringConfigs, label: agent.label })
@@ -948,6 +993,15 @@ export function AgentsRoster(): JSX.Element {
</div>
))}
+ {linearTeamsPicker && (
+ <LinearTeamsModal
+ config={linearIssuesConfig}
+ enableOnSave={linearTeamsPicker.enableOnSave}
+ viaSetupWizard={linearTeamsPicker.viaSetupWizard}
+ onClose={closeLinearTeamsPicker}
+ />
+ )}
+
{/* Remounts per target (the key), so the form defaults re-derive from that source's config. */}
{steeringTarget && (
<SourceSteeringModal
diff --git a/products/signals/frontend/inbox/components/config/LinearTeamsModal.stories.tsx b/products/signals/frontend/inbox/components/config/LinearTeamsModal.stories.tsx
new file mode 100644
index 000000000000..9d5104f43261
--- /dev/null
+++ b/products/signals/frontend/inbox/components/config/LinearTeamsModal.stories.tsx
@@ -0,0 +1,71 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { useStorybookMocks } from '~/mocks/browser'
+
+import { SignalSourceConfig, SignalSourceProduct, SignalSourceType } from '../../types'
+import { LinearTeamsModal } from './LinearTeamsModal'
+
+function sourceConfig(config: Record<string, any>, enabled = true): SignalSourceConfig {
+ return {
+ id: 'config-linear-issue',
+ source_product: SignalSourceProduct.Linear,
+ source_type: SignalSourceType.Issue,
+ enabled,
+ config,
+ created_at: '2024-03-20T00:00:00Z',
+ updated_at: '2024-03-20T00:00:00Z',
+ status: null,
+ }
+}
+
+const LINEAR_INTEGRATION = {
+ id: 7,
+ kind: 'linear',
+ display_name: 'Example workspace',
+ icon_url: '/static/services/linear.png',
+ config: {},
+ created_at: '2024-03-20T00:00:00Z',
+}
+
+const LINEAR_TEAMS = [
+ { id: 'team-eng', name: 'Engineering' },
+ { id: 'team-design', name: 'Design' },
+ { id: 'team-support', name: 'Support' },
+]
+
+interface HarnessProps {
+ config: SignalSourceConfig | null
+ enableOnSave: boolean
+}
+
+function ModalHarness({ config, enableOnSave }: HarnessProps): JSX.Element {
+ useStorybookMocks({
+ get: {
+ '/api/projects/:team_id/integrations/': { results: [LINEAR_INTEGRATION] },
+ '/api/environments/:team_id/integrations/:id/linear_teams/': { teams: LINEAR_TEAMS },
+ },
+ })
+ return <LinearTeamsModal config={config} enableOnSave={enableOnSave} viaSetupWizard={false} onClose={() => {}} />
+}
+
+const meta: Meta<typeof ModalHarness> = {
+ title: 'Scenes-App/Inbox/LinearTeamsModal',
+ component: ModalHarness,
+ parameters: {
+ layout: 'fullscreen',
+ viewMode: 'story',
+ mockDate: '2024-03-20',
+ testOptions: { waitForSelector: '[data-attr="signal-source-linear-teams-save"]' },
+ },
+}
+export default meta
+
+type Story = StoryObj<typeof ModalHarness>
+
+export const EnableFlow: Story = {
+ args: { config: null, enableOnSave: true },
+}
+
+export const TeamsPicked: Story = {
+ args: { config: sourceConfig({ linear_team_ids: ['team-eng', 'team-support'] }), enableOnSave: false },
+}
diff --git a/products/signals/frontend/inbox/components/config/LinearTeamsModal.tsx b/products/signals/frontend/inbox/components/config/LinearTeamsModal.tsx
new file mode 100644
index 000000000000..81b392d1e21c
--- /dev/null
+++ b/products/signals/frontend/inbox/components/config/LinearTeamsModal.tsx
@@ -0,0 +1,143 @@
+import { useValues } from 'kea'
+import { Form } from 'kea-forms'
+import { useId } from 'react'
+
+import { LemonBanner, LemonButton, LemonInputSelect, LemonModal, LemonSkeleton } from '@posthog/lemon-ui'
+
+import { useLinearTeams } from 'lib/integrations/LinearIntegrationHelpers'
+import { LemonField } from 'lib/lemon-ui/LemonField'
+import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio'
+
+import { LinearTeamsModalLogicProps, LinearTeamsScope, linearTeamsModalLogic } from '../../logics/linearTeamsModalLogic'
+import { SignalSourceConfig } from '../../types'
+
+const SCOPE_OPTIONS: LemonRadioOption<LinearTeamsScope>[] = [
+ { value: 'all', label: 'All teams', 'data-attr': 'signal-source-linear-teams-all' },
+ { value: 'selected', label: 'Only the teams I pick', 'data-attr': 'signal-source-linear-teams-selected' },
+]
+
+export interface LinearTeamsModalProps {
+ config: SignalSourceConfig | null
+ enableOnSave: boolean
+ viaSetupWizard: boolean
+ onClose: () => void
+}
+
+function LinearTeamsSelect({
+ integrationId,
+ disabled,
+ value,
+ onChange,
+}: {
+ integrationId: number
+ disabled?: boolean
+ value?: string[]
+ onChange?: (value: string[]) => void
+}): JSX.Element {
+ const { options, loading } = useLinearTeams(integrationId)
+ return (
+ <LemonInputSelect
+ mode="multiple"
+ value={value ?? []}
+ onChange={onChange}
+ options={options}
+ loading={loading}
+ disabled={disabled}
+ placeholder="Select teams"
+ data-attr="select-linear-teams"
+ />
+ )
+}
+
+export function LinearTeamsModal({
+ config,
+ enableOnSave,
+ viaSetupWizard,
+ onClose,
+}: LinearTeamsModalProps): JSX.Element {
+ const formId = useId()
+ const logicProps: LinearTeamsModalLogicProps = { config, enableOnSave, viaSetupWizard, onClose }
+ const logic = linearTeamsModalLogic(logicProps)
+ const { linearTeams, linearTeamsValidationErrors, isLinearIssuesToggling, linearIntegration, integrationsUnknown } =
+ useValues(logic)
+
+ const handleClose = (): void => {
+ if (isLinearIssuesToggling) {
+ return
+ }
+ onClose()
+ }
+
+ const scopeError =
+ typeof linearTeamsValidationErrors.scope === 'string' ? linearTeamsValidationErrors.scope : undefined
+
+ // A radio group disables per option, so the saving reason goes on each one.
+ const scopeOptions = isLinearIssuesToggling
+ ? SCOPE_OPTIONS.map((option) => ({ ...option, disabledReason: 'Saving' }))
+ : SCOPE_OPTIONS
+
+ return (
+ <LemonModal
+ isOpen
+ onClose={handleClose}
+ title="Linear teams"
+ description="Choose which Linear teams self-driving reads. It reads open issues only from those teams."
+ width={480}
+ footer={
+ <>
+ <LemonButton
+ type="secondary"
+ onClick={handleClose}
+ disabledReason={isLinearIssuesToggling ? 'Saving' : undefined}
+ >
+ Cancel
+ </LemonButton>
+ <LemonButton
+ type="primary"
+ form={formId}
+ htmlType="submit"
+ loading={isLinearIssuesToggling}
+ disabledReason={scopeError}
+ data-attr="signal-source-linear-teams-save"
+ >
+ {enableOnSave && !config?.enabled ? 'Turn on Linear' : 'Save'}
+ </LemonButton>
+ </>
+ }
+ >
+ <Form logic={linearTeamsModalLogic} props={logicProps} formKey="linearTeams" id={formId} enableFormOnSubmit>
+ <div className="flex flex-col gap-3">
+ <LemonField name="scope">
+ {({ value, onChange }) => (
+ <LemonRadio
+ value={value}
+ onChange={onChange}
+ options={scopeOptions}
+ aria-label="Which Linear teams to read"
+ />
+ )}
+ </LemonField>
+ {linearTeams.scope === 'selected' &&
+ (integrationsUnknown ? (
+ <LemonSkeleton className="h-10" />
+ ) : linearIntegration ? (
+ <LemonField
+ name="teamIds"
+ help="Applies from the next sync. Reports already in your inbox stay."
+ >
+ <LinearTeamsSelect
+ integrationId={linearIntegration.id}
+ disabled={isLinearIssuesToggling}
+ />
+ </LemonField>
+ ) : (
+ <LemonBanner type="warning">
+ Couldn't find your Linear connection, so the team list isn't available. Reconnect Linear
+ in integration settings, then try again.
+ </LemonBanner>
+ ))}
+ </div>
+ </Form>
+ </LemonModal>
+ )
+}
diff --git a/products/signals/frontend/inbox/inboxAnalytics.ts b/products/signals/frontend/inbox/inboxAnalytics.ts
index 5fe0dff2f513..3897f9640801 100644
--- a/products/signals/frontend/inbox/inboxAnalytics.ts
+++ b/products/signals/frontend/inbox/inboxAnalytics.ts
@@ -48,6 +48,7 @@ export const INBOX_EVENTS = {
SOURCE_DISABLED: 'Signal source disabled',
SOURCE_INTEREST: 'signals source interest',
SOURCE_STEERING_CHANGED: 'Signal source steering changed',
+ SOURCE_FILTERS_CHANGED: 'Signal source filters changed',
// Scout-troop management. Names and property shapes match the desktop app one-for-one so both
// clients union in one project; desktop sends no `inbox_client`, so its rows read as null.
SCOUT_FLEET_VIEWED: 'Scout fleet viewed',
@@ -592,6 +593,23 @@ export function captureSignalSourceSteeringChanged(params: {
})
}
+export function captureSignalSourceFiltersChanged(params: {
+ sourceProduct: string
+ sourceType: string
+ filter: string
+ selectedCount: number
+ success: boolean
+}): void {
+ captureInboxEvent(INBOX_EVENTS.SOURCE_FILTERS_CHANGED, {
+ source_product: params.sourceProduct,
+ source_type: params.sourceType,
+ filter: params.filter,
+ selected_count: params.selectedCount,
+ reads_everything: params.selectedCount === 0,
+ success: params.success,
+ })
+}
+
/**
* Outcome of a task-kickoff action, fired once the request settles. Pairs with the press event on
* `report_id` + `action_type`. `blocked` means we never issued the request (no AI consent), which is
diff --git a/products/signals/frontend/inbox/logics/linearTeamsModalLogic.test.ts b/products/signals/frontend/inbox/logics/linearTeamsModalLogic.test.ts
new file mode 100644
index 000000000000..3f9676e0a432
--- /dev/null
+++ b/products/signals/frontend/inbox/logics/linearTeamsModalLogic.test.ts
@@ -0,0 +1,213 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { sourcesDataLogic } from 'products/data_warehouse/frontend/shared/logics/sourcesDataLogic'
+
+import { signalSourcesLogic } from '../signalSourcesLogic'
+import { SignalSourceConfig, SignalSourceProduct, SignalSourceType } from '../types'
+import { linearTeamsModalLogic } from './linearTeamsModalLogic'
+
+const existingConfig: SignalSourceConfig = {
+ id: 'config-linear',
+ source_product: SignalSourceProduct.Linear,
+ source_type: SignalSourceType.Issue,
+ enabled: false,
+ // A key the picker does not own, to prove saves merge rather than clobber.
+ config: { steering: 'Skip chores', linear_team_ids: ['team-1'] },
+ created_at: '2026-08-01T00:00:00Z',
+ updated_at: '2026-08-01T00:00:00Z',
+ status: null,
+}
+
+describe('linearTeamsModalLogic', () => {
+ let requests: { method: string; body: Record<string, any> }[]
+ let onClose: jest.Mock
+
+ beforeEach(() => {
+ requests = []
+ useMocks({
+ get: {
+ '/api/projects/:team_id/signals/source_configs/': () => [
+ 200,
+ { results: [existingConfig], count: 1, next: null, previous: null },
+ ],
+ },
+ post: {
+ '/api/projects/:team_id/signals/source_configs/': async ({ request }) => {
+ const body = (await request.json()) as Record<string, any>
+ requests.push({ method: 'POST', body })
+ return [201, { ...existingConfig, id: 'config-new', ...body }]
+ },
+ },
+ patch: {
+ '/api/projects/:team_id/signals/source_configs/:id/': async ({ request }) => {
+ const body = (await request.json()) as Record<string, any>
+ requests.push({ method: 'PATCH', body })
+ return [200, { ...existingConfig, ...body }]
+ },
+ },
+ })
+ initKeaTests()
+ onClose = jest.fn()
+ })
+
+ afterEach(async () => {
+ // The modal logic mounts integrationsLogic, whose mount-time load must settle here, or its
+ // response lands in the next test's context.
+ await expectLogic(integrationsLogic).toFinishAllListeners()
+ })
+
+ it.each([
+ {
+ name: 'a pick from Filters keeps the other keys and leaves enabled alone',
+ props: { config: existingConfig, enableOnSave: false },
+ form: { scope: 'selected' as const, teamIds: ['team-1', 'team-2'] },
+ expected: {
+ method: 'PATCH',
+ body: { enabled: false, config: { steering: 'Skip chores', linear_team_ids: ['team-1', 'team-2'] } },
+ },
+ },
+ {
+ name: 'reading all teams writes an empty list',
+ props: { config: existingConfig, enableOnSave: false },
+ form: { scope: 'all' as const, teamIds: ['team-1'] },
+ expected: {
+ method: 'PATCH',
+ body: { enabled: false, config: { steering: 'Skip chores', linear_team_ids: [] } },
+ },
+ },
+ {
+ name: 'the enable flow turns the source on with the pick',
+ props: { config: existingConfig, enableOnSave: true },
+ form: { scope: 'selected' as const, teamIds: ['team-2'] },
+ expected: {
+ method: 'PATCH',
+ body: { enabled: true, config: { steering: 'Skip chores', linear_team_ids: ['team-2'] } },
+ },
+ },
+ ])('$name', async ({ props, form, expected }) => {
+ const sourcesLogic = signalSourcesLogic()
+ sourcesLogic.mount()
+ await expectLogic(sourcesLogic, () => sourcesLogic.actions.loadSourceConfigs()).toDispatchActions([
+ 'loadSourceConfigsSuccess',
+ ])
+ const logic = linearTeamsModalLogic({ ...props, viaSetupWizard: false, onClose })
+ logic.mount()
+
+ logic.actions.setLinearTeamsValues(form)
+ await expectLogic(logic, () => logic.actions.submitLinearTeams()).toDispatchActions([
+ 'submitLinearTeamsSuccess',
+ 'toggleSignalSourceSuccess',
+ ])
+
+ expect(requests).toEqual([expected])
+ expect(onClose).toHaveBeenCalledTimes(1)
+ })
+
+ it.each([
+ {
+ name: 'the workspace the warehouse source syncs',
+ sources: [
+ { id: 'src-linear', source_type: 'Linear', job_inputs: { linear_integration_id: 2 }, schemas: [] },
+ ],
+ expectedIntegrationId: 2,
+ },
+ { name: 'any connection before a source exists', sources: [], expectedIntegrationId: 1 },
+ ])('lists teams from $name', async ({ sources, expectedIntegrationId }) => {
+ useMocks({
+ get: {
+ '/api/projects/:team_id/integrations/': () => [
+ 200,
+ {
+ results: [
+ { id: 1, kind: 'linear', display_name: 'Workspace A', config: {}, errors: '' },
+ { id: 2, kind: 'linear', display_name: 'Workspace B', config: {}, errors: '' },
+ ],
+ },
+ ],
+ '/api/projects/:team_id/external_data_sources/': () => [
+ 200,
+ { results: sources, count: sources.length, next: null, previous: null },
+ ],
+ },
+ })
+ const logic = linearTeamsModalLogic({
+ config: existingConfig,
+ enableOnSave: false,
+ viaSetupWizard: false,
+ onClose,
+ })
+ logic.mount()
+ await expectLogic(integrationsLogic).toFinishAllListeners()
+ await expectLogic(sourcesDataLogic, () => sourcesDataLogic.actions.loadSources()).toDispatchActions([
+ 'loadSourcesSuccess',
+ ])
+
+ expect(logic.values.linearIntegration?.id).toBe(expectedIntegrationId)
+ })
+
+ it('ignores a Linear toggle it did not start', async () => {
+ const sourcesLogic = signalSourcesLogic()
+ sourcesLogic.mount()
+ const logic = linearTeamsModalLogic({
+ config: existingConfig,
+ enableOnSave: false,
+ viaSetupWizard: false,
+ onClose,
+ })
+ logic.mount()
+
+ sourcesLogic.actions.toggleSignalSourceSuccess({
+ sourceProduct: SignalSourceProduct.Linear,
+ sourceType: SignalSourceType.Issue,
+ enabled: false,
+ })
+
+ expect(onClose).not.toHaveBeenCalled()
+ })
+
+ it('creates the row when Linear was never turned on before', async () => {
+ const logic = linearTeamsModalLogic({ config: null, enableOnSave: true, viaSetupWizard: true, onClose })
+ logic.mount()
+ expect(logic.values.linearTeams).toEqual({ scope: 'all', teamIds: [] })
+
+ await expectLogic(logic, () => logic.actions.submitLinearTeams()).toDispatchActions([
+ 'toggleSignalSourceSuccess',
+ ])
+
+ expect(requests).toEqual([
+ {
+ method: 'POST',
+ body: {
+ source_product: 'linear',
+ source_type: 'issue',
+ enabled: true,
+ config: { linear_team_ids: [] },
+ },
+ },
+ ])
+ })
+
+ it('refuses to save a pick with no teams', async () => {
+ const logic = linearTeamsModalLogic({
+ config: existingConfig,
+ enableOnSave: false,
+ viaSetupWizard: false,
+ onClose,
+ })
+ logic.mount()
+
+ logic.actions.setLinearTeamsValues({ scope: 'selected', teamIds: [] })
+ await expectLogic(logic, () => logic.actions.submitLinearTeams()).toDispatchActions([
+ 'submitLinearTeamsFailure',
+ ])
+
+ expect(logic.values.linearTeamsValidationErrors.scope).toBe('Pick at least one team, or read all teams.')
+ expect(requests).toEqual([])
+ expect(onClose).not.toHaveBeenCalled()
+ })
+})
diff --git a/products/signals/frontend/inbox/logics/linearTeamsModalLogic.ts b/products/signals/frontend/inbox/logics/linearTeamsModalLogic.ts
new file mode 100644
index 000000000000..f7b1264364d8
--- /dev/null
+++ b/products/signals/frontend/inbox/logics/linearTeamsModalLogic.ts
@@ -0,0 +1,270 @@
+import { LogicWrapper, MakeLogicType, actions, connect, kea, listeners, path, props, reducers, selectors } from 'kea'
+import { forms } from 'kea-forms'
+import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'
+
+import { lemonToast } from '@posthog/lemon-ui'
+
+import type { PaginatedResponse } from 'lib/api'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+
+import { ExternalDataSource, IntegrationType } from '~/types'
+
+import { captureSignalSourceFiltersChanged } from '../inboxAnalytics'
+import { signalSourcesLogic } from '../signalSourcesLogic'
+import {
+ SOURCE_LINEAR_TEAM_IDS_KEY,
+ SignalSourceConfig,
+ SignalSourceProduct,
+ SignalSourceType,
+ ToggleSignalSourceParams,
+ linearTeamIdsFromConfig,
+} from '../types'
+
+export type LinearTeamsScope = 'all' | 'selected'
+
+export interface LinearTeamsFormValues {
+ scope: LinearTeamsScope
+ teamIds: string[]
+}
+
+export interface LinearTeamsModalLogicProps {
+ /** The Linear source row, or null before the source was ever turned on. */
+ config: SignalSourceConfig | null
+ /** Saving from the enable flow turns the source on; saving from Filters leaves `enabled` as it is. */
+ enableOnSave: boolean
+ viaSetupWizard: boolean
+ onClose: () => void
+}
+
+function formDefaults(config: SignalSourceConfig | null): LinearTeamsFormValues {
+ const teamIds = linearTeamIdsFromConfig(config?.config)
+ return teamIds.length > 0 ? { scope: 'selected', teamIds } : { scope: 'all', teamIds: [] }
+}
+
+function isLinearIssueToggle(params: ToggleSignalSourceParams): boolean {
+ return params.sourceProduct === SignalSourceProduct.Linear && params.sourceType === SignalSourceType.Issue
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface linearTeamsModalLogicValues {
+ integrations: IntegrationType[] | null // integrationsLogic
+ linearIntegrations: IntegrationType[] // integrationsLogic
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null // signalSourcesLogic
+ isLinearIssuesToggling: boolean // signalSourcesLogic
+ sourceConfigs: SignalSourceConfig[] | null // signalSourcesLogic
+ integrationsUnknown: boolean
+ isLinearTeamsSubmitting: boolean
+ isLinearTeamsValid: boolean
+ linearIntegration: IntegrationType | null
+ linearTeams: LinearTeamsFormValues
+ linearTeamsAllErrors: Record<string, any>
+ linearTeamsChanged: boolean
+ linearTeamsErrors: DeepPartialMap<LinearTeamsFormValues, ValidationErrorType>
+ linearTeamsHasErrors: boolean
+ linearTeamsManualErrors: Record<string, any>
+ linearTeamsTouched: boolean
+ linearTeamsTouches: Record<string, boolean>
+ linearTeamsValidationErrors: DeepPartialMap<LinearTeamsFormValues, ValidationErrorType>
+ saveInFlight: boolean
+ showLinearTeamsErrors: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface linearTeamsModalLogicActions {
+ toggleSignalSource: (params: ToggleSignalSourceParams) => {
+ params: ToggleSignalSourceParams
+ } // signalSourcesLogic
+ toggleSignalSourceFailure: (
+ params: ToggleSignalSourceParams,
+ error: string
+ ) => {
+ error: string
+ params: ToggleSignalSourceParams
+ } // signalSourcesLogic
+ toggleSignalSourceSuccess: (params: ToggleSignalSourceParams) => {
+ params: ToggleSignalSourceParams
+ } // signalSourcesLogic
+ resetLinearTeams: (values?: LinearTeamsFormValues) => {
+ values?: LinearTeamsFormValues
+ }
+ saveSettled: () => {
+ value: true
+ }
+ setLinearTeamsManualErrors: (errors: Record<string, any>) => {
+ errors: Record<string, any>
+ }
+ setLinearTeamsValue: (
+ key: FieldName,
+ value: any
+ ) => {
+ name: FieldName
+ value: any
+ }
+ setLinearTeamsValues: (values: DeepPartial<LinearTeamsFormValues>) => {
+ values: DeepPartial<LinearTeamsFormValues>
+ }
+ submitLinearTeams: () => {
+ value: boolean
+ }
+ submitLinearTeamsFailure: (
+ error: Error,
+ errors: Record<string, any>
+ ) => {
+ error: Error
+ errors: Record<string, any>
+ }
+ submitLinearTeamsRequest: (linearTeams: LinearTeamsFormValues) => {
+ linearTeams: LinearTeamsFormValues
+ }
+ submitLinearTeamsSuccess: (linearTeams: LinearTeamsFormValues) => {
+ linearTeams: LinearTeamsFormValues
+ }
+ touchLinearTeamsField: (key: string) => {
+ key: string
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface linearTeamsModalLogicMeta {
+ __keaTypeGenInternalSelectorTypes: {
+ linearIntegration: (
+ linearIntegrations: IntegrationType[],
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null
+ ) => IntegrationType | null
+ integrationsUnknown: (integrations: IntegrationType[] | null) => boolean
+ }
+}
+
+export type linearTeamsModalLogicType = MakeLogicType<
+ linearTeamsModalLogicValues,
+ linearTeamsModalLogicActions,
+ LinearTeamsModalLogicProps,
+ linearTeamsModalLogicMeta
+>
+
+/**
+ * The form behind the Linear teams modal. Saving goes through `signalSourcesLogic.toggleSignalSource`,
+ * which already decides between creating the row and updating it, reloads the list, and reports
+ * the connection, so the enable flow and the Filters button share one save path.
+ */
+export const linearTeamsModalLogic: LogicWrapper<linearTeamsModalLogicType> = kea<linearTeamsModalLogicType>([
+ path(['scenes', 'inbox', 'logics', 'linearTeamsModalLogic']),
+ props({} as LinearTeamsModalLogicProps),
+ // Not keyed on the row id: the enable flow creates the row mid-save, and a keyed instance would
+ // be swapped out before its own result arrives.
+ actions({
+ saveSettled: true,
+ }),
+ reducers({
+ // Set while this modal's own save is in flight, so a Linear toggle from elsewhere is ignored.
+ saveInFlight: [
+ false,
+ {
+ submitLinearTeamsRequest: () => true,
+ saveSettled: () => false,
+ },
+ ],
+ }),
+ connect(() => ({
+ values: [
+ signalSourcesLogic,
+ ['sourceConfigs', 'isLinearIssuesToggling', 'dataWarehouseSources'],
+ integrationsLogic,
+ ['linearIntegrations', 'integrations'],
+ ],
+ actions: [signalSourcesLogic, ['toggleSignalSource', 'toggleSignalSourceSuccess', 'toggleSignalSourceFailure']],
+ })),
+ forms(({ props: logicProps, actions, values }) => ({
+ linearTeams: {
+ defaults: formDefaults(logicProps.config),
+ // The message hangs off `scope` (a string field) because kea-forms types an array
+ // field's error as an array, one entry per item, and this is about the list as a whole.
+ errors: ({ scope, teamIds }: LinearTeamsFormValues) => ({
+ scope:
+ scope === 'selected' && teamIds.length === 0
+ ? 'Pick at least one team, or read all teams.'
+ : undefined,
+ }),
+ submit: ({ scope, teamIds }: LinearTeamsFormValues) => {
+ // The endpoint replaces the config object wholesale, so the whole blob goes back with
+ // the team list merged in; a partial object would clobber the steering text. The merge
+ // base is the freshest cached row rather than the open-time prop snapshot.
+ const baseConfig =
+ (logicProps.config &&
+ values.sourceConfigs?.find((c: SignalSourceConfig) => c.id === logicProps.config?.id)
+ ?.config) ??
+ logicProps.config?.config ??
+ {}
+ actions.toggleSignalSource({
+ sourceProduct: SignalSourceProduct.Linear,
+ sourceType: SignalSourceType.Issue,
+ enabled: logicProps.enableOnSave ? true : (logicProps.config?.enabled ?? true),
+ config: { ...baseConfig, [SOURCE_LINEAR_TEAM_IDS_KEY]: scope === 'all' ? [] : teamIds },
+ viaSetupWizard: logicProps.viaSetupWizard,
+ })
+ },
+ },
+ })),
+ selectors({
+ // The warehouse source records the workspace it syncs, so the teams come from that connection
+ // and match the synced issues. Before a source exists, any Linear connection will do.
+ linearIntegration: [
+ (s) => [s.linearIntegrations, s.dataWarehouseSources],
+ (
+ linearIntegrations: IntegrationType[],
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null
+ ): IntegrationType | null => {
+ const syncedIntegrationId = dataWarehouseSources?.results.find(
+ (source: ExternalDataSource) => source.source_type === 'Linear'
+ )?.job_inputs?.linear_integration_id
+ return (
+ linearIntegrations.find((integration) => String(integration.id) === String(syncedIntegrationId)) ??
+ linearIntegrations[0] ??
+ null
+ )
+ },
+ ],
+ // A null list means the first load has not landed, which is not the same as no connection.
+ // Reading the list rather than the loading flag keeps a later reload from blanking the picker.
+ integrationsUnknown: [
+ (s) => [s.integrations],
+ (integrations: IntegrationType[] | null): boolean => integrations === null,
+ ],
+ }),
+ listeners(({ props: logicProps, actions, values }) => ({
+ toggleSignalSourceSuccess: ({ params }) => {
+ if (!isLinearIssueToggle(params) || !values.saveInFlight) {
+ return
+ }
+ actions.saveSettled()
+ const teamCount = linearTeamIdsFromConfig(params.config).length
+ captureSignalSourceFiltersChanged({
+ sourceProduct: params.sourceProduct,
+ sourceType: params.sourceType,
+ filter: SOURCE_LINEAR_TEAM_IDS_KEY,
+ selectedCount: teamCount,
+ success: true,
+ })
+ lemonToast.success(
+ teamCount === 0
+ ? 'Linear reads all teams from the next sync.'
+ : `Linear reads ${teamCount} ${teamCount === 1 ? 'team' : 'teams'} from the next sync.`
+ )
+ logicProps.onClose()
+ },
+ // signalSourcesLogic already shows the error toast; the modal stays open for a retry.
+ toggleSignalSourceFailure: ({ params }) => {
+ if (!isLinearIssueToggle(params) || !values.saveInFlight) {
+ return
+ }
+ actions.saveSettled()
+ captureSignalSourceFiltersChanged({
+ sourceProduct: params.sourceProduct,
+ sourceType: params.sourceType,
+ filter: SOURCE_LINEAR_TEAM_IDS_KEY,
+ selectedCount: linearTeamIdsFromConfig(params.config).length,
+ success: false,
+ })
+ },
+ })),
+])
diff --git a/products/signals/frontend/inbox/signalSourcesLogic.ts b/products/signals/frontend/inbox/signalSourcesLogic.ts
index 572f064b04ab..14c1c016e65c 100644
--- a/products/signals/frontend/inbox/signalSourcesLogic.ts
+++ b/products/signals/frontend/inbox/signalSourcesLogic.ts
@@ -74,6 +74,12 @@ function inheritedErrorTrackingConfig(configs: SignalSourceConfig[]): Record<str
/** Warehouse-backed signal sources, keyed by roster source id. */
export type WarehouseBackedSource = 'github' | 'linear' | 'zendesk' | 'pganalyze' | 'engineering_analytics'
+/** Why the Linear teams picker is open: enabling the source (its save turns it on) or editing the filter. */
+export interface LinearTeamsPickerState {
+ enableOnSave: boolean
+ viaSetupWizard: boolean
+}
+
type WarehouseSourceCompletion =
| {
kind: 'source_config'
@@ -246,6 +252,7 @@ export interface signalSourcesLogicValues {
isPgAnalyzeIssuesToggling: boolean
isZendeskTicketsToggling: boolean
linearIssuesConfig: SignalSourceConfig | null
+ linearTeamsPicker: LinearTeamsPickerState | null
pgAnalyzeIssuesConfig: SignalSourceConfig | null
sourceConfigs: SignalSourceConfig[] | null
sourceConfigsLoadFailed: boolean
@@ -269,6 +276,9 @@ export interface signalSourcesLogicActions {
closeDataSourceSetup: () => {
value: true
}
+ closeLinearTeamsPicker: () => {
+ value: true
+ }
closeSourcesModal: () => {
value: true
}
@@ -350,6 +360,7 @@ export interface signalSourcesLogicActions {
openDataSourceSetup: (source: WarehouseBackedSource) => {
source: WarehouseBackedSource
}
+ openLinearTeamsPicker: (state: LinearTeamsPickerState) => LinearTeamsPickerState
openSourcesModal: () => {
value: true
}
@@ -516,6 +527,8 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
openDataSourceSetup: (source: WarehouseBackedSource) => ({ source }),
closeDataSourceSetup: true,
onDataSourceSetupComplete: true,
+ openLinearTeamsPicker: (state: LinearTeamsPickerState) => state,
+ closeLinearTeamsPicker: true,
toggleSignalSource: (params: ToggleSignalSourceParams) => ({ params }),
toggleSignalSourceSuccess: (params: ToggleSignalSourceParams) => ({ params }),
toggleSignalSourceFailure: (params: ToggleSignalSourceParams, error: string) => ({ params, error }),
@@ -640,6 +653,14 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
closeSourcesModal: () => null,
},
],
+ linearTeamsPicker: [
+ null as LinearTeamsPickerState | null,
+ {
+ openLinearTeamsPicker: (_, state) => state,
+ closeLinearTeamsPicker: () => null,
+ closeSourcesModal: () => null,
+ },
+ ],
enablingTool: [
null as SourceToolEnablement | null,
{
@@ -1074,6 +1095,11 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
if ((currentConfig?.enabled ?? false) === desiredEnabled) {
return
}
+ // Linear asks which teams to read before it turns on; the picker's save does the toggle.
+ if (source === 'linear' && desiredEnabled) {
+ actions.openLinearTeamsPicker({ enableOnSave: true, viaSetupWizard: false })
+ return
+ }
actions.setDataWarehouseSourceEnabled(source, desiredEnabled)
downstreamToggleStarted = true
} catch (error: any) {
@@ -1095,6 +1121,10 @@ export const signalSourcesLogic = kea<signalSourcesLogicType>([
actions.toggleCiSignals(true)
return
}
+ if (source === 'linear') {
+ actions.openLinearTeamsPicker({ enableOnSave: true, viaSetupWizard: true })
+ return
+ }
actions.toggleSignalSource({
sourceProduct: completion.sourceProduct,
sourceType: completion.sourceType,
diff --git a/products/signals/frontend/inbox/types.ts b/products/signals/frontend/inbox/types.ts
index a61d3d543ab7..25e372400c5e 100644
--- a/products/signals/frontend/inbox/types.ts
+++ b/products/signals/frontend/inbox/types.ts
@@ -203,6 +203,14 @@ export enum SignalSourceConfigStatus {
export const SOURCE_STEERING_KEY = 'steering'
export const SOURCE_DEFAULT_NOT_ACTIONABLE_KEY = 'default_not_actionable'
export const SOURCE_STEERING_MAX_LENGTH = 2000
+/** Linear source only: the Linear team ids it reads issues from. Absent or empty means every team. */
+export const SOURCE_LINEAR_TEAM_IDS_KEY = 'linear_team_ids'
+
+// Anything that is not a list of ids reads as "every team", matching the backend's fallback.
+export function linearTeamIdsFromConfig(config: Record<string, any> | null | undefined): string[] {
+ const raw = config?.[SOURCE_LINEAR_TEAM_IDS_KEY]
+ return Array.isArray(raw) ? raw.filter((id): id is string => typeof id === 'string' && id.length > 0) : []
+}
// ── Inbox IA: page tabs, report sections, scope ──────────────────────────────