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(signals): hide the suggestions strip when there is nothing to suggest (#96076)

posthog[bot]67905adfd6f1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e07e7d2f44f5..5d11c795ec34 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -7537,9 +7537,13 @@ snapshots:
scenes-app-inbox-scoutsuggestionsstrip--never-generated--light:
hash: v1.k794b7964.42ff6f1076df4cda1912e9d4da32c776e98c58ec2526dd7f1b3dcc8a2de17cbc.4amW1-ua55bSo0F7aZPgnuOXpTAdbvkhym1WzOkKfFM
scenes-app-inbox-scoutsuggestionsstrip--nothing-left--dark:
- hash: v1.k794b7964.4bca4c8d2bf4fdc2ab4010ae1903be8a2244023972129e4190ca6e9c08ec6568.V2__hYR_JWIqKzFZePVc63NdnTF23nDtJLwiqFwgPlU
+ hash: v1.k794b7964.669e760714fe3acda90a90713fd40015a8eda10ee6aae7c7628d6820a18a520f.05GoZkCOgwfyr5N54RAer1SGyJIYQKB8D-7g_Cb5PD8
scenes-app-inbox-scoutsuggestionsstrip--nothing-left--light:
- hash: v1.k794b7964.3820117f26fba2e6ed35651118de53657944447a2d4580d6fac343d84128bb5b.87vV-RofQ_1ZA3X_ODe97BVmlKHVhq79Y2LbWuwiZxM
+ hash: v1.k794b7964.6132d08f6269e363d43e27e6908ce8c719099c00bcbf2dadd41516a2c474c85b.fzuFZjcwuJfMmZybduYCmSKdSu8nGl_udgCPRZcZobw
+ scenes-app-inbox-scoutsuggestionsstrip--scanning--dark:
+ hash: v1.k794b7964.e849770feab5d46a037863d74c2ce37deca6fcec3677db1c434cc3406b22f8bc.rSRNUba302jNZkVQo0xYybhP4xAil1vHsS4ohtEJLrE
+ scenes-app-inbox-scoutsuggestionsstrip--scanning--light:
+ hash: v1.k794b7964.d7c88ad16a6054b96d398ffd66af687768fed227ca65d1713474caa80db7d18e.rp4z_jMQ78IkiLAyyOp31jI3Rrh8AdwBVEOLH_2qaAc
scenes-app-inbox-scoutsuggestionsstrip--single-card--dark:
hash: v1.k794b7964.4d5c0231716b6cad6a9088686a42b0d1c327d741a184db9d9bf47360d936dbb9.KBYF0nvsalBWo1FkSKwcr56qgjlQM4HzIdidtJhf5to
scenes-app-inbox-scoutsuggestionsstrip--single-card--light:
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutCreateButton.test.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutCreateButton.test.tsx
index a967cb97d642..e41d88b4b668 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutCreateButton.test.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutCreateButton.test.tsx
@@ -33,9 +33,11 @@ const mockGetAccessControlDisabledReason = getAccessControlDisabledReason as jes
describe('scout creation buttons', () => {
let startedChatTypes: string[]
+ let refreshRequests: number
beforeEach(() => {
startedChatTypes = []
+ refreshRequests = 0
mockGetAccessControlDisabledReason.mockReturnValue(null)
useMocks({
get: {
@@ -98,7 +100,7 @@ describe('scout creation buttons', () => {
setSuggestionsFlag(true)
const logic = scoutSuggestionsLogic()
logic.mount()
- await waitFor(() => expect(logic.values.hasBatch).toBe(true))
+ await waitFor(() => expect(logic.values.hasPicks).toBe(true))
const { findByText, queryByText } = render(<ScoutsRosterActions />)
expect(queryByText('Suggest a scout')).toBeNull()
@@ -111,6 +113,33 @@ describe('scout creation buttons', () => {
logic.unmount()
})
+ // A project with no picks has no strip to reopen, so the header button is the only entry point
+ // there. It has to be present, and it has to pay for a scan rather than open a chat.
+ it('starts a scan from the header on a project with no picks', async () => {
+ setSuggestionsFlag(true)
+ useMocks({
+ get: { '/api/projects/:team/signals/scout/suggestions/': mockScoutSuggestionSet({ items: [] }) },
+ post: {
+ '/api/projects/:team/signals/scout/suggestions/refresh/': () => {
+ refreshRequests += 1
+ return [200, { workflow_id: 'workflow-1' }]
+ },
+ },
+ })
+ const logic = scoutSuggestionsLogic()
+ logic.mount()
+ const { findByText } = render(<ScoutsRosterActions />)
+ // The button is busy until the batch is known, so a press before then costs no scan.
+ await waitFor(() => expect(logic.values.suggestionSet).not.toBeNull())
+
+ fireEvent.click(await findByText('Suggest a scout'))
+
+ await waitFor(() => expect(refreshRequests).toBe(1))
+ expect(logic.values.stripVisible).toBe(true)
+ expect(startedChatTypes).toEqual([])
+ logic.unmount()
+ })
+
// "Suggest a scout" only moves into the Ask menu for people on the suggestions strip. Off the
// flag it stays a header button, which is the only way those people can ask for a pick.
it.each([
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.stories.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.stories.tsx
index 22477aa6e9ef..a9decdfce1e4 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.stories.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.stories.tsx
@@ -21,12 +21,23 @@ import { ScoutsRoster } from './ScoutsRoster'
const SUGGESTIONS_URL = '/api/projects/:id/signals/scout/suggestions/'
/** The strip opens collapsed, so the stories open it unless one asks for the collapsed line. */
-function StripState({ collapsed, children }: { collapsed: boolean; children: React.ReactNode }): JSX.Element {
+function StripState({
+ collapsed,
+ refreshing,
+ children,
+}: {
+ collapsed: boolean
+ refreshing: boolean
+ children: React.ReactNode
+}): JSX.Element {
const logic = useMountedLogic(scoutSuggestionsLogic)
useEffect(() => {
logic.actions.showStrip()
logic.actions.setCollapsed(collapsed)
- }, [logic, collapsed])
+ if (refreshing) {
+ logic.actions.requestRefresh()
+ }
+ }, [logic, collapsed, refreshing])
return <>{children}</>
}
@@ -46,7 +57,7 @@ const meta: Meta<typeof ScoutsRoster> = {
},
decorators: [
(Story, { parameters }) => (
- <StripState collapsed={parameters.stripCollapsed === true}>
+ <StripState collapsed={parameters.stripCollapsed === true} refreshing={parameters.stripRefreshing === true}>
<Story />
</StripState>
),
@@ -58,6 +69,9 @@ const meta: Meta<typeof ScoutsRoster> = {
'/api/projects/:id/signals/scout/metadata/current/': () => [200, null],
'/api/projects/:id/signals/scout/scratchpad/': () => [200, []],
},
+ post: {
+ '/api/projects/:id/signals/scout/suggestions/refresh/': () => [200, { workflow_id: 'workflow-1' }],
+ },
}),
],
}
@@ -103,7 +117,8 @@ export const LastScanFailed: Story = {
],
}
-// Every pick acted on or dismissed. The header line stays so Refresh is still reachable.
+// Every pick acted on or dismissed. No strip at all: an empty box helps nobody, and the scene
+// header's "Suggest a scout" button is what asks for a new batch.
export const NothingLeft: Story = {
decorators: [
mswDecorator({
@@ -112,6 +127,16 @@ export const NothingLeft: Story = {
],
}
+// What the header button opens on a project with nothing to suggest: skeletons until the scan lands.
+export const Scanning: Story = {
+ parameters: { stripRefreshing: true },
+ decorators: [
+ mswDecorator({
+ get: { [SUGGESTIONS_URL]: () => [200, mockScoutSuggestionSet({ items: [] })] },
+ }),
+ ],
+}
+
// No batch has ever been generated, so the roster looks exactly as it did before the strip existed.
export const NeverGenerated: Story = {
decorators: [
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.tsx
index d618811de0f3..e2677d61566a 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutSuggestionsStrip.tsx
@@ -20,20 +20,19 @@ const COLLAPSED_TITLE_PREVIEW = 2
* The "Suggested for this project" strip above the roster: a pre-computed batch of scouts worth
* running here, each ready to turn on or create without waiting for a scan.
*
- * Nothing renders until a batch exists, so a project that has never been scanned sees the roster
- * exactly as it was. `stale` is a footer note rather than an error: any fleet change flips it and
- * the picks stay valid.
+ * Nothing renders without picks to read, so a project with an empty batch sees the roster exactly
+ * as it was. `stale` is a footer note rather than an error: any fleet change flips it and the picks
+ * stay valid.
*
* The strip opens collapsed and can be closed outright. A closed strip comes back through the
* "Suggest a scout" header button, so the picks are never more than one click away.
*/
export function ScoutSuggestionsStrip(): JSX.Element | null {
- const { suggestions, hasBatch, collapsed, stripHidden, isRefreshing, suggestionSet } =
- useValues(scoutSuggestionsLogic)
+ const { suggestions, stripVisible, collapsed, isRefreshing, suggestionSet } = useValues(scoutSuggestionsLogic)
const { setCollapsed, hideStrip, requestRefresh } = useActions(scoutSuggestionsLogic)
useReportSuggestionsShown('strip')
- if (!hasBatch || stripHidden) {
+ if (!stripVisible) {
return null
}
@@ -91,7 +90,7 @@ export function ScoutSuggestionsStrip(): JSX.Element | null {
)
}
-/** Whichever of the strip's four states applies: collapsed, scanning, nothing left, or the cards. */
+/** Whichever of the strip's three states applies: collapsed, scanning, or the cards. */
function StripBody(): JSX.Element {
const { suggestions, collapsed, batchStatus, isRefreshing, suggestionSetLoading } = useValues(scoutSuggestionsLogic)
@@ -101,16 +100,6 @@ function StripBody(): JSX.Element {
if (isRefreshing || (suggestionSetLoading && suggestions.length === 0)) {
return <SuggestionsSkeleton />
}
- if (suggestions.length === 0) {
- return (
- <p className="m-0 text-xs text-secondary">
- {batchStatus === 'failed'
- ? "The last scan didn't finish, so there are no picks yet. Refresh to try again, or "
- : 'Nothing left to suggest right now. Refresh to scan the project again, or '}
- <SuggestWithAiLink />.
- </p>
- )
- }
return (
<>
<SuggestionGrid surface="strip" />
@@ -134,10 +123,10 @@ function StripBody(): JSX.Element {
/** The suggestion cards on their own, for the empty state's body. */
export function ScoutSuggestionsEmptyStateCards(): JSX.Element | null {
- const { suggestions, hasBatch } = useValues(scoutSuggestionsLogic)
+ const { hasPicks } = useValues(scoutSuggestionsLogic)
useReportSuggestionsShown('empty_state')
- if (!hasBatch || suggestions.length === 0) {
+ if (!hasPicks) {
return null
}
@@ -168,8 +157,9 @@ function SuggestionGrid({ surface, columns = 3 }: { surface: ScoutSuggestionSurf
}
function CollapsedLine({ titles }: { titles: string[] }): JSX.Element {
+ // The strip only stays up without titles while a scan runs, so that is what this line means.
if (titles.length === 0) {
- return <span className="text-xs text-muted">Nothing left to suggest right now.</span>
+ return <span className="text-xs text-muted">Scanning the project…</span>
}
const named = titles.slice(0, COLLAPSED_TITLE_PREVIEW).join(', ')
const rest = titles.length - COLLAPSED_TITLE_PREVIEW
@@ -219,13 +209,13 @@ function SuggestWithAiLink(): JSX.Element {
)
}
-/** Fires the impression once per mount, the first time a batch has actually resolved on screen. */
+/** Fires the impression once per mount, the first time picks have actually reached the screen. */
function useReportSuggestionsShown(surface: ScoutSuggestionSurface): void {
- const { hasBatch, stripHidden } = useValues(scoutSuggestionsLogic)
+ const { hasPicks, stripHidden } = useValues(scoutSuggestionsLogic)
const { reportSuggestionsShown } = useActions(scoutSuggestionsLogic)
const reportedRef = useRef(false)
// The empty state has no close control, so only the strip can be hidden.
- const onScreen = hasBatch && (surface !== 'strip' || !stripHidden)
+ const onScreen = hasPicks && (surface !== 'strip' || !stripHidden)
useEffect(() => {
if (!onScreen || reportedRef.current) {
return
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutsEmptyState.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutsEmptyState.tsx
index 857111804b6f..5d6348ffe05b 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutsEmptyState.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutsEmptyState.tsx
@@ -13,16 +13,15 @@ import { ScoutSuggestionsEmptyStateCards } from './ScoutSuggestionsStrip'
export function ScoutsEmptyState(): JSX.Element {
const { loadScoutConfigs } = useActions(scoutFleetLogic)
- const { suggestions, hasBatch } = useValues(scoutSuggestionsLogic)
- // A project with picks waiting gets them as the body of the empty state. Without a batch the
+ // A project with picks waiting gets them as the body of the empty state. Without picks the
// empty state stays exactly as it was.
- const hasSuggestions = hasBatch && suggestions.length > 0
+ const { hasPicks } = useValues(scoutSuggestionsLogic)
return (
<div
className={cn(
'mx-auto flex flex-col items-center gap-2 py-12 text-center',
- hasSuggestions ? 'w-full' : 'max-w-md'
+ hasPicks ? 'w-full' : 'max-w-md'
)}
>
<div className="mb-1 flex h-12 w-12 items-center justify-center rounded-full bg-fill-primary text-secondary">
@@ -30,11 +29,11 @@ export function ScoutsEmptyState(): JSX.Element {
</div>
<h3 className="m-0 text-base font-semibold">No scouts on this project yet</h3>
<p className="m-0 max-w-md text-sm text-tertiary">
- {hasSuggestions
+ {hasPicks
? 'Here is what PostHog would watch on this project. Turn one on, or write your own.'
: 'Create a scout to investigate a recurring signal or behavior on a schedule.'}
</p>
- {hasSuggestions && (
+ {hasPicks && (
<div className="mt-3 w-full text-left">
<ScoutSuggestionsEmptyStateCards />
</div>
diff --git a/products/signals/frontend/inbox/components/config/scouts/ScoutsRosterActions.tsx b/products/signals/frontend/inbox/components/config/scouts/ScoutsRosterActions.tsx
index 8a813db5b392..53c909b8ef26 100644
--- a/products/signals/frontend/inbox/components/config/scouts/ScoutsRosterActions.tsx
+++ b/products/signals/frontend/inbox/components/config/scouts/ScoutsRosterActions.tsx
@@ -29,19 +29,35 @@ export function ScoutsRosterActions(): JSX.Element {
)
}
-/** Takes the "Suggest a scout" spot while the strip is closed, and reopens it in place of a chat. */
+/**
+ * Takes the "Suggest a scout" spot whenever the strip has no picks to show: it reopens a closed
+ * strip, and on a project with none it starts a scan rather than opening a chat. It stays put while
+ * that scan runs, because the empty-fleet state renders no strip whose skeletons could report it.
+ */
function ShowSuggestionsButton(): JSX.Element | null {
- const { hasBatch, stripHidden } = useValues(scoutSuggestionsLogic)
- const { showStrip } = useActions(scoutSuggestionsLogic)
- if (!hasBatch || !stripHidden) {
+ const { suggestButtonVisible, hasPicks, isRefreshing, suggestionSetLoading, aiConsentDisabledReason } =
+ useValues(scoutSuggestionsLogic)
+ const { askForSuggestions } = useActions(scoutSuggestionsLogic)
+ if (!suggestButtonVisible) {
return null
}
+ // Reopening a closed strip needs no scan, so the AI gate only applies when a press would pay
+ // for one. The refresh endpoint refuses without consent, and a refusal reads as a failure.
+ const busyReason = isRefreshing
+ ? 'Scanning the project…'
+ : suggestionSetLoading
+ ? 'Reading the suggestions…'
+ : hasPicks
+ ? null
+ : aiConsentDisabledReason
return (
<LemonButton
type="secondary"
size="small"
icon={<IconSparkles />}
- onClick={() => showStrip()}
+ loading={!!busyReason}
+ disabledReason={busyReason ?? undefined}
+ onClick={() => askForSuggestions()}
data-attr="scout-suggestions-show"
>
Suggest a scout
diff --git a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts
index 63fb6accf1c0..231dee98d87b 100644
--- a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.test.ts
@@ -4,6 +4,9 @@ import { expectLogic } from 'kea-test-utils'
import { ApiError } from 'lib/api-error'
import { FEATURE_FLAGS } from 'lib/constants'
+// Imported from the source module rather than the `@posthog/lemon-ui` barrel, so the spies below
+// replace the methods on the same `lemonToast` singleton the logic calls at runtime.
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { initKeaTests } from '~/test/init'
@@ -134,6 +137,9 @@ describe('scoutSuggestionsLogic', () => {
}
beforeEach(() => {
+ // The strip's collapsed and closed state persists per user and project, so one test's
+ // chevron would otherwise decide how the next one opens.
+ localStorage.clear()
initKeaTests()
featureFlagLogic.mount()
setSuggestionsFlag(true)
@@ -169,34 +175,87 @@ describe('scoutSuggestionsLogic', () => {
await mountWithBatch()
expect(mockList).not.toHaveBeenCalled()
- expect(logic.values.hasBatch).toBe(false)
+ expect(logic.values.hasPicks).toBe(false)
// Flags usually resolve after the tab mounts, so the answer arriving is what starts the read.
setSuggestionsFlag(true)
await expectLogic(logic).toFinishAllListeners()
expect(mockList).toHaveBeenCalledTimes(1)
- expect(logic.values.hasBatch).toBe(true)
+ expect(logic.values.hasPicks).toBe(true)
})
- // A scan that found nothing has a `generated_at`; only an unscanned project has none. The first
- // still needs the strip, for its "nothing left" line and the Refresh that asks again.
+ // Whatever the batch row says, a batch with no picks has nothing to put on the roster.
it.each([
- ['never scanned', 'empty', null, false],
- ['scanned and found nothing', 'empty', '2026-09-01T00:00:00Z', true],
- ['first scan failed', 'failed', null, true],
- ])('shows the strip only once the project was scanned: %s', async (_name, status, generatedAt, expected) => {
+ ['never scanned', 'empty', null],
+ ['scanned and found nothing', 'empty', '2026-09-01T00:00:00Z'],
+ ['last scan failed', 'failed', null],
+ ])('keeps the strip off a batch with no picks: %s', async (_name, status, generatedAt) => {
await mountWithBatch(
suggestionSet({ status: status as ScoutSuggestionSetApi['status'], generated_at: generatedAt, items: [] })
)
- expect(logic.values.hasBatch).toBe(expected)
+ expect(logic.values.hasPicks).toBe(false)
+ expect(logic.values.stripVisible).toBe(false)
+ })
+
+ // The header button is the entry point whenever the strip is off screen, so it has to cover
+ // both reasons it can be: closed by the person, and empty because the project has no picks.
+ it.each([
+ ['pays for a scan when there is nothing to reopen', [] as ScoutSuggestionItemApi[], 1],
+ ['only reopens the strip when picks are waiting', [CANONICAL_ITEM, CUSTOM_ITEM], 0],
+ ])('the header button %s', async (_name, items, refreshCalls) => {
+ await mountWithBatch(suggestionSet({ items }))
+ logic.actions.hideStrip()
+ expect(logic.values.stripVisible).toBe(false)
+
+ logic.actions.askForSuggestions()
+ await expectLogic(logic).toFinishAllListeners()
+
+ // Either way the strip is back on screen: with the picks, or with the scan's skeletons.
+ expect(logic.values.stripVisible).toBe(true)
+ expect(mockRefresh).toHaveBeenCalledTimes(refreshCalls)
+ })
+
+ it('re-reads the batch instead of paying for a scan when the read never landed', async () => {
+ mockList.mockRejectedValue(new ApiError('nope', 500))
+ logic = scoutSuggestionsLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.suggestionSet).toBeNull()
+
+ logic.actions.askForSuggestions()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockRefresh).not.toHaveBeenCalled()
+ expect(mockList).toHaveBeenCalledTimes(2)
+ })
+
+ // The strip closes on an empty batch, so this toast is the whole report on the scan. A scan
+ // that never finished is worth another press; one that ran and found nothing is not.
+ it.each([
+ ['found nothing', { status: 'empty', generated_at: '2026-09-03T00:00:00Z' }, 'info'],
+ ['did not finish', { status: 'failed' }, 'error'],
+ ])('reports how a scan that left no picks ended: %s', async (_name, outcome, level) => {
+ const toast = jest.spyOn(lemonToast, level as 'info' | 'error').mockReturnValue('toast-1')
+ await mountWithBatch()
+
+ logic.actions.requestRefresh()
+ await expectLogic(logic).toFinishAllListeners()
+ mockList.mockResolvedValue(suggestionSet({ ...(outcome as Partial<ScoutSuggestionSetApi>), items: [] }))
+ logic.actions.loadSuggestions()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.isRefreshing).toBe(false)
+ expect(logic.values.stripVisible).toBe(false)
+ expect(toast).toHaveBeenCalledTimes(1)
+ toast.mockRestore()
})
it('keeps a stale batch visible, because its picks are still valid', async () => {
await mountWithBatch(suggestionSet({ status: 'stale' }))
- expect(logic.values.hasBatch).toBe(true)
+ expect(logic.values.hasPicks).toBe(true)
expect(logic.values.suggestions).toHaveLength(2)
})
diff --git a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts
index 14b4124e89da..890442525d22 100644
--- a/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts
+++ b/products/signals/frontend/inbox/logics/scoutSuggestionsLogic.ts
@@ -63,10 +63,12 @@ export interface scoutSuggestionsLogicValues {
item: ScoutSuggestionItemApi
} | null
expandedSuggestionId: string | null
- hasBatch: boolean
+ hasPicks: boolean
hiddenSuggestionIds: string[]
isRefreshing: boolean
stripHidden: boolean
+ stripVisible: boolean
+ suggestButtonVisible: boolean
suggestionSet: ScoutSuggestionSetApi | null
suggestionSetLoading: boolean
suggestions: ScoutSuggestionItemApi[]
@@ -105,6 +107,9 @@ export interface scoutSuggestionsLogicActions {
configId: string
updates: import('products/signals/frontend/generated/api.schemas').PatchedSignalScoutConfigUpdateApi
} // scoutFleetLogic
+ askForSuggestions: () => {
+ value: true
+ }
closeCreateFromSuggestion: () => {
value: true
}
@@ -208,7 +213,14 @@ export interface scoutSuggestionsLogicMeta {
batchStatus: (suggestionSet: ScoutSuggestionSetApi | null) => string
batchAgeHours: (suggestionSet: ScoutSuggestionSetApi | null) => number | null
suggestionsEnabled: (featureFlags: FeatureFlagsSet) => boolean
- hasBatch: (suggestionSet: ScoutSuggestionSetApi | null, suggestionsEnabled: boolean) => boolean
+ hasPicks: (suggestions: ScoutSuggestionItemApi[], suggestionsEnabled: boolean) => boolean
+ stripVisible: (
+ hasPicks: boolean,
+ suggestionsEnabled: boolean,
+ stripHidden: boolean,
+ isRefreshing: boolean
+ ) => boolean
+ suggestButtonVisible: (hasPicks: boolean, suggestionsEnabled: boolean, stripHidden: boolean) => boolean
collapsed: (collapsedOverride: boolean | null) => boolean
}
}
@@ -268,6 +280,7 @@ export const scoutSuggestionsLogic = kea<scoutSuggestionsLogicType>([
surface,
}),
closeCreateFromSuggestion: true,
+ askForSuggestions: true,
suggestionCreated: (item: ScoutSuggestionItemApi, surface: ScoutSuggestionSurface) => ({ item, surface }),
requestRefresh: true,
refreshRequestRefused: true,
@@ -414,19 +427,28 @@ export const scoutSuggestionsLogic = kea<scoutSuggestionsLogicType>([
(s) => [s.featureFlags],
(featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.SCOUTS_SUGGESTIONS_UI],
],
- // A project that has never been scanned has nothing to show and no refresh worth offering,
- // so the roster and the empty state stay exactly as they were.
- // A scan that found nothing still counts: it has a `generated_at`, and the person needs
- // the strip's "nothing left" line and its Refresh to ask again once data arrives. So does a
- // first scan that failed, which has no `generated_at` at all but still needs the Refresh.
- hasBatch: [
- (s) => [s.suggestionSet, s.suggestionsEnabled],
- (suggestionSet: ScoutSuggestionSetApi | null, suggestionsEnabled: boolean): boolean =>
- suggestionsEnabled &&
- suggestionSet !== null &&
- (suggestionSet.generated_at !== null ||
- suggestionSet.items.length > 0 ||
- suggestionSet.status === 'failed'),
+ // Every suggestions surface reads this instead of the batch row. A batch with no picks left
+ // — a scan that found nothing, picks all acted on, a scan that failed — has nothing to
+ // show, so it must not put an empty box on the roster.
+ hasPicks: [
+ (s) => [s.suggestions, s.suggestionsEnabled],
+ (suggestions: ScoutSuggestionItemApi[], suggestionsEnabled: boolean): boolean =>
+ suggestionsEnabled && suggestions.length > 0,
+ ],
+ // A running scan keeps the strip up with its skeletons, so the person who pressed for one
+ // watches it arrive rather than looking at a roster that ignored the press.
+ stripVisible: [
+ (s) => [s.hasPicks, s.suggestionsEnabled, s.stripHidden, s.isRefreshing],
+ (hasPicks: boolean, suggestionsEnabled: boolean, stripHidden: boolean, isRefreshing: boolean): boolean =>
+ suggestionsEnabled && !stripHidden && (hasPicks || isRefreshing),
+ ],
+ // The header's own entry point, which stays put while a scan runs: the empty-fleet state
+ // renders no strip at all, so a button that hid itself on press would be the only feedback
+ // the person got, and it would be feedback that the press did nothing.
+ suggestButtonVisible: [
+ (s) => [s.hasPicks, s.suggestionsEnabled, s.stripHidden],
+ (hasPicks: boolean, suggestionsEnabled: boolean, stripHidden: boolean): boolean =>
+ suggestionsEnabled && (!hasPicks || stripHidden),
],
collapsed: [
(s) => [s.collapsedOverride],
@@ -554,6 +576,19 @@ export const scoutSuggestionsLogic = kea<scoutSuggestionsLogicType>([
surface,
})
},
+ askForSuggestions: () => {
+ actions.showStrip()
+ // A read that never landed is not an empty batch, and a scan is paid for and daily
+ // capped, so an unknown batch is re-read rather than scanned.
+ if (values.suggestionSet === null) {
+ actions.loadSuggestions()
+ return
+ }
+ // With no picks on offer there is nothing to reopen, so the button pays for a scan.
+ if (values.suggestions.length === 0) {
+ actions.requestRefresh()
+ }
+ },
requestRefresh: async () => {
const teamId = values.currentTeamId
// The reducer already shows the button as busy; this non-reactive flag is what keeps a
@@ -614,8 +649,21 @@ export const scoutSuggestionsLogic = kea<scoutSuggestionsLogicType>([
const settled =
(suggestionSet?.generated_at ?? null) !== cache.refreshBaselineGeneratedAt ||
(suggestionSet?.status === 'failed' && cache.refreshBaselineStatus !== 'failed')
- if (settled) {
- actions.refreshFinished()
+ if (!settled) {
+ return
+ }
+ actions.refreshFinished()
+ // The strip closes on an empty batch, so a scan that produced nothing would otherwise
+ // just take the skeletons away and leave the person guessing what the press did. The
+ // two outcomes are not the same: `failed` means the scan never finished, so it is
+ // worth another press, while `empty` means it ran and found nothing.
+ if (values.suggestions.length > 0) {
+ return
+ }
+ if (suggestionSet?.status === 'failed') {
+ lemonToast.error("That scan didn't finish. Try again in a moment.")
+ } else {
+ lemonToast.info('That scan found nothing new to suggest.')
}
},
refreshFinished: () => {