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.

fix(integrations): show resolved slack channels before blur (#104109)

Daniel Marchuk7f935ec226e2
diff --git a/docs/internal/slack-local-setup-guide.md b/docs/internal/slack-local-setup-guide.md
index 75143b7da546..0d99afc13298 100644
--- a/docs/internal/slack-local-setup-guide.md
+++ b/docs/internal/slack-local-setup-guide.md
@@ -309,6 +309,12 @@ Tokens from the development app cannot be transferred to the production app.
## Troubleshooting
+### Channel selection
+
+Paste a Slack channel ID into the channel picker to select that channel.
+The picker shows the channel name when the lookup succeeds, without requiring you to click outside the input.
+Click the selected channel in the list to clear the search text.
+
The walls we actually hit and fixed:
| Symptom | Cause / fix |
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index fa13066d9cf2..7143c57eb367 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2252,6 +2252,10 @@ snapshots:
hash: v1.k794b7964.2706bc3f6a6a560eeb7c2a7b25b0feafb0438bb7f2b94aa6f584de1eed7338a2.WscXFEXWmTCQX3rgoirWxfA_iSvW47pO5ZaLo7TFx3U
components-slack-channel-picker--multiple-selection--light:
hash: v1.k794b7964.ab1f574ecf1b582f420f90a56175b32bb1f76c585a6aa79a37d3bb351d21f20c.iPJrGKVub6zHD-M3h6qSWNrHWiqyBOXaSVMB1w1d_-E
+ components-slack-channel-picker--pasted-channel-id--dark:
+ hash: v1.k794b7964.d60e6043c5b85c4f8b8ba603cf0f0c568099d99921459bce9293cbfbd74fbf65.oS3gE2jgEoNm-sghm05J20yNWJqDlORObayJlsTlVlA
+ components-slack-channel-picker--pasted-channel-id--light:
+ hash: v1.k794b7964.dabe969bb89f1aaecb8d641eaa1c91f777306e4776eb80740fd30056d4d12030.SR_9HPnp47-t-kBbVGrPdqV3GHRQE6vSOvUq-ZT2Vmw
components-slack-channel-picker--recently-subscribed-first--dark:
hash: v1.k794b7964.de1b275c97b6eac538ac35f64bf4cf3ec79f224cf500d0078f748c063eb83601.qqYmyCsR4ryfUqltT9sX9UikOHaAkMvWoWGDrQZ164s
components-slack-channel-picker--recently-subscribed-first--light:
diff --git a/frontend/src/lib/integrations/SlackChannelPicker.stories.tsx b/frontend/src/lib/integrations/SlackChannelPicker.stories.tsx
index bfbd4b65d95c..48fa9a9ab0cc 100644
--- a/frontend/src/lib/integrations/SlackChannelPicker.stories.tsx
+++ b/frontend/src/lib/integrations/SlackChannelPicker.stories.tsx
@@ -87,6 +87,27 @@ function MultipleSelectionScene(): JSX.Element {
)
}
+function PastedChannelIdScene(): JSX.Element {
+ const [selectedChannel, setSelectedChannel] = useState<string | null>(null)
+ const response = { channels: [channel('C1234567890', 'release-updates')] }
+ useStorybookMocks({
+ get: {
+ '/api/projects/:id/integrations/:intId/channels': response,
+ '/api/environments/:id/integrations/:intId/channels': response,
+ },
+ })
+
+ return (
+ <div className="p-4 max-w-2xl">
+ <SlackChannelPicker
+ integration={integration}
+ value={selectedChannel ?? undefined}
+ onChange={setSelectedChannel}
+ />
+ </div>
+ )
+}
+
type StoryArgs = { recentlySubscribedChannelIds: string[] }
const meta: Meta<StoryArgs> = {
@@ -126,6 +147,16 @@ export const MultipleSelection: Story = {
render: () => <MultipleSelectionScene />,
}
+export const PastedChannelId: Story = {
+ render: () => <PastedChannelIdScene />,
+ play: async ({ canvasElement }) => {
+ const input = await within(canvasElement).findByRole('textbox')
+ await userEvent.click(input)
+ await userEvent.paste('C1234567890')
+ await within(document.body).findByText('#release-updates')
+ },
+}
+
// Typing a channel name and clicking away drops the search, because the picker takes an option
// rather than free text. The state below is what tells the user their channel is still unset.
export const SearchDroppedOnBlur: Story = {
diff --git a/frontend/src/lib/integrations/SlackChannelPicker.test.tsx b/frontend/src/lib/integrations/SlackChannelPicker.test.tsx
index d2b853badd73..2f934f947480 100644
--- a/frontend/src/lib/integrations/SlackChannelPicker.test.tsx
+++ b/frontend/src/lib/integrations/SlackChannelPicker.test.tsx
@@ -2,7 +2,7 @@ import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
import '@testing-library/jest-dom'
-import { cleanup, render, screen, waitFor } from '@testing-library/react'
+import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Provider } from 'kea'
@@ -333,7 +333,7 @@ describe('SlackChannelPicker', () => {
// Pasting an id is already an unambiguous choice, and the option it matches is labelled by
// name, so leaving it unselected asks the user to recognize a channel they only have an id for.
const onChange = jest.fn()
- const { container } = render(
+ const { container, rerender } = render(
<Provider>
<SlackChannelPicker integration={INTEGRATION} onChange={onChange} />
</Provider>
@@ -347,6 +347,21 @@ describe('SlackChannelPicker', () => {
await waitFor(() => expect(onChange).toHaveBeenCalledWith(`${OFF_PAGE_CHANNEL.id}|#off-page-channel`), {
timeout: 3000,
})
+ rerender(
+ <Provider>
+ <SlackChannelPicker
+ integration={INTEGRATION}
+ value={`${OFF_PAGE_CHANNEL.id}|#off-page-channel`}
+ onChange={onChange}
+ />
+ </Provider>
+ )
+ expect(input).toHaveFocus()
+ expect(screen.getByText('#off-page-channel')).toBeVisible()
+ expect(screen.queryByText(/No channels found/)).not.toBeInTheDocument()
+ await userEvent.click(screen.getByText('#off-page-channel'))
+ expect(input).toHaveValue('')
+ expect(within(container).getByText('#off-page-channel')).toBeVisible()
expect(screen.queryByText('No channel selected. Pick one from the list.')).toBeNull()
})
diff --git a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx
index bac61a59c8c4..b366b89cc15e 100644
--- a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx
+++ b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.test.tsx
@@ -1,6 +1,6 @@
import '@testing-library/jest-dom'
-import { render, screen } from '@testing-library/react'
+import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { LemonInputSelect } from './LemonInputSelect'
@@ -193,7 +193,10 @@ describe('LemonInputSelect', () => {
expect(lastCall[0]).toBe(42)
})
- it('single-select mode: clicking already-selected value keeps it selected', async () => {
+ it.each([
+ ['with no search text', ''],
+ ['after editing the search down to a prefix of it', '{backspace}{backspace}'],
+ ])('single-select mode: clicking already-selected value keeps it selected %s', async (_, keystrokes) => {
const onChange = jest.fn()
const { container } = render(
@@ -213,12 +216,22 @@ describe('LemonInputSelect', () => {
// Verify the selected option is displayed
expect(screen.getAllByText('Option 1').length).toBeGreaterThan(0)
- await openDropdown(container)
- const selectedOptionButton = await findDropdownButtonByText('Option 1')
- expect(selectedOptionButton).toBeInTheDocument()
- await userEvent.click(selectedOptionButton!)
- // Verify onChange was NOT called with empty array (which would reset the selection)
- expect(onChange).not.toHaveBeenCalledWith([])
+ const input = await openDropdown(container)
+ if (keystrokes) {
+ await userEvent.type(input, keystrokes)
+ expect(input).toHaveValue('option')
+ }
+ const selectedOptionButton = await waitFor(async () => {
+ const button = await findDropdownButtonByText('Option 1')
+ expect(button).toBeInTheDocument()
+ return button
+ })
+ // A browser returns focus to the input after the option's mousedown, but jsdom does not. Clicking
+ // with the input still focused reproduces the blur that the selection itself causes.
+ expect(input).toHaveFocus()
+ fireEvent.click(selectedOptionButton!)
+ // Neither an empty selection nor the typed search text may replace the selected value
+ expect(onChange).not.toHaveBeenCalled()
})
it('single-select mode: custom values show with formatCreateLabel when re-opening dropdown', async () => {
diff --git a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
index 016cf449f17d..da8c11e16729 100644
--- a/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
+++ b/frontend/src/lib/lemon-ui/LemonInputSelect/LemonInputSelect.tsx
@@ -222,6 +222,9 @@ export function LemonInputSelect<T = string>({
const [inputValue, _setInputValue] = useState('')
const [itemBeingEditedIndex, setItemBeingEditedIndex] = useState<number | null>(null)
const popoverFocusRef = useRef<boolean>(false)
+ // Picking an option blurs the input synchronously, and the blur would otherwise commit the typed
+ // search text as a custom value before (or instead of) the option the user picked.
+ const blurringForSelectionRef = useRef<boolean>(false)
const inputRef = useRef<HTMLInputElement>(null)
const [selectedIndex, setSelectedIndex] = useState(0)
const [frozenOptions, setFrozenOptions] = useState<LemonInputSelectOption<T>[] | null>(null)
@@ -357,7 +360,7 @@ export function LemonInputSelect<T = string>({
// We don't want to show the input-based option again. The check for __isInput covers the case the user types something that is already an option, but we want to keep the original option
continue
}
- if (mode === 'single' && values.length > 0 && option.key === getStringKey(values[0])) {
+ if (mode === 'single' && ret[0]?.key === option.key) {
// In single-select mode, we've already added the selected value to the top earlier
continue
}
@@ -514,7 +517,9 @@ export function LemonInputSelect<T = string>({
// Prevent propagating to Popover's onClickInside, which would set popoverFocusRef.current back to true
popoverOptionClickEvent?.stopPropagation()
// Remove focus from input after selecting an option, since in single mode that feels better UX-wise
+ blurringForSelectionRef.current = true
inputRef.current?.blur()
+ blurringForSelectionRef.current = false
}
if (stringKeys.includes(item)) {
@@ -522,6 +527,8 @@ export function LemonInputSelect<T = string>({
// (clicking an already selected item to toggle it off makes sense for multiple-select, not for single-select)
if (mode !== 'single') {
_removeItem(item)
+ } else {
+ setInputValue('')
}
} else {
_addItem(item, itemBeingEditedIndex)
@@ -542,7 +549,7 @@ export function LemonInputSelect<T = string>({
// and then the click handler sees it already exists and removes it.
return
}
- if (hasCustomValue) {
+ if (hasCustomValue && !blurringForSelectionRef.current) {
_onActionItem(inputValue.trim(), null)
} else {
setInputValue('')