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(data-warehouse): stop an account filter reading as a broken connection (#95857)

Tom Owers82e528bd6802
diff --git a/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.test.tsx b/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.test.tsx
new file mode 100644
index 000000000000..e74bf78a035f
--- /dev/null
+++ b/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.test.tsx
@@ -0,0 +1,42 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { initKeaTests } from '~/test/init'
+
+import { InputWithSuggestionsDropdown } from './InputWithSuggestionsDropdown'
+
+describe('InputWithSuggestionsDropdown', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ afterEach(cleanup)
+
+ const openPicker = (suggestions: string[]): void => {
+ render(
+ <InputWithSuggestionsDropdown
+ value=""
+ onChange={() => {}}
+ suggestions={suggestions}
+ data-attr="account"
+ emptyMessage="Nothing is available."
+ noMatchMessage={() => 'Nothing matches your filter.'}
+ />
+ )
+ fireEvent.focus(document.querySelector('[data-attr="account"]')!)
+ }
+
+ // Callers that filter server-side hand back an empty `suggestions` list while a search term is
+ // active, and the "nothing is available" wording there reads as a broken connection rather than
+ // a filter that matched nothing.
+ it('reports a filter that matched nothing rather than an empty source list', () => {
+ openPicker([])
+ expect(screen.getByText('Nothing is available.')).toBeInTheDocument()
+
+ fireEvent.change(screen.getByPlaceholderText('Filter suggestions…'), { target: { value: 'abc' } })
+
+ expect(screen.getByText('Nothing matches your filter.')).toBeInTheDocument()
+ expect(screen.queryByText('Nothing is available.')).not.toBeInTheDocument()
+ })
+})
diff --git a/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx b/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx
index b4189ca2e13c..8b4918b95147 100644
--- a/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/InputWithSuggestionsDropdown.tsx
@@ -40,7 +40,7 @@ export interface InputWithSuggestionsDropdownProps {
/** Notified as the popover search term changes, for sources that load suggestions server-side
* (e.g. a large repository list). Client-side filtering of the current suggestions still applies. */
onSearchChange?: (term: string) => void
- /** Text shown when `suggestions` is empty after loading. */
+ /** Text shown when `suggestions` is empty after loading and no search term is filtering them. */
emptyMessage?: string
/** Text shown when the search term filters out every suggestion. Receives the current term. */
noMatchMessage?: (term: string) => string
@@ -117,7 +117,7 @@ export function InputWithSuggestionsDropdown({
<p className="m-0 px-2 py-1 text-xs text-secondary flex items-center gap-1">
<Spinner /> {loadingMessage}
</p>
- ) : suggestions.length === 0 ? (
+ ) : suggestions.length === 0 && !searchTerm.trim() ? (
<p className="m-0 px-2 py-1 text-xs text-secondary">{emptyMessage}</p>
) : filtered.length === 0 ? (
<p className="m-0 px-2 py-1 text-xs text-secondary">{noMatchMessage(searchTerm)}</p>
diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx
index 6d02892337c1..504fe2a1bf94 100644
--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx
+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx
@@ -436,7 +436,7 @@ function IntegrationAccountFieldWithDropdown({
placeholder,
caption,
}: IntegrationAccountSelectorProps & { integrationId: number }): JSX.Element {
- const { accounts, accountsLoading, accountsLoaded, accountsError } = useValues(
+ const { accounts, accountsLoading, accountsLoaded, accountsError, search } = useValues(
integrationAccountsLogic({ id: integrationId, sourceType })
)
const { loadAccounts, setSearch } = useActions(integrationAccountsLogic({ id: integrationId, sourceType }))
@@ -445,6 +445,11 @@ function IntegrationAccountFieldWithDropdown({
loadAccounts()
}, [loadAccounts])
+ // The list is filtered server-side, so while a search term is active `accounts` holds the
+ // matches rather than everything the connection can reach. Every "we found nothing" hint below
+ // is about the connection, so hold them back until the list is unfiltered.
+ const filtering = !!search.trim()
+
const suggestions = useMemo<InputSuggestion[]>(() => {
const sorted = [...accounts].sort((a, b) => Number(b.is_primary) - Number(a.is_primary))
return sorted.map((account) => {
@@ -475,7 +480,11 @@ function IntegrationAccountFieldWithDropdown({
{({ value, onChange }) => {
const accountValues = accounts.map((account) => account.value)
const savedValueMissing =
- !!value && !accountsLoading && accounts.length > 0 && !accountValues.includes(String(value))
+ !!value &&
+ !accountsLoading &&
+ !filtering &&
+ accounts.length > 0 &&
+ !accountValues.includes(String(value))
return (
<div className="flex flex-col gap-2">
<InputWithSuggestionsDropdown
@@ -488,6 +497,9 @@ function IntegrationAccountFieldWithDropdown({
onSearchChange={setSearch}
searchPlaceholder="Filter accounts…"
emptyMessage="No accounts accessible by this integration."
+ noMatchMessage={() =>
+ 'No accounts match your filter. Clear it to see every account this connection can reach.'
+ }
loadingMessage="Loading accounts…"
/>
{accountsError && (
@@ -495,12 +507,17 @@ function IntegrationAccountFieldWithDropdown({
{accountsError} <ReconnectLink integrationKind={integrationKind} />
</p>
)}
- {accountsLoaded && !accountsLoading && !accountsError && accounts.length === 0 && (
- <p className="m-0 text-xs text-warning">
- No accounts to show. If you know the {fieldLabel}, enter it above and save. You can also{' '}
- <ReconnectLink integrationKind={integrationKind} /> to grant access to more accounts.
- </p>
- )}
+ {accountsLoaded &&
+ !accountsLoading &&
+ !accountsError &&
+ !filtering &&
+ accounts.length === 0 && (
+ <p className="m-0 text-xs text-warning">
+ No accounts to show. If you know the {fieldLabel}, enter it above and save. You can
+ also <ReconnectLink integrationKind={integrationKind} /> to grant access to more
+ accounts.
+ </p>
+ )}
{savedValueMissing && (
<p className="m-0 text-xs text-warning">
The currently saved {fieldLabel} <code>{value}</code> isn't in the accessible list for