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): remember scouts roster filters and sort between visits (#125501)

posthog[bot]eb65a302d563
diff --git a/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts b/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts
index bceec78fc947..67e968b2c976 100644
--- a/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts
+++ b/products/signals/frontend/inbox/logics/scoutFleetLogic.test.ts
@@ -157,6 +157,8 @@ describe('scoutFleetLogic', () => {
let logic: ReturnType<typeof scoutFleetLogic.build>
beforeEach(async () => {
+ // The roster filters persist to localStorage, which jsdom keeps between tests.
+ localStorage.clear()
initKeaTests()
mockSignalsScoutChatTasksCreate.mockReset()
mockSignalsScoutConfigList.mockReset().mockResolvedValue([])
@@ -870,6 +872,34 @@ describe('scoutFleetLogic', () => {
expect(router.values.searchParams.scoutEnabled).toEqual('enabled')
})
+ it('restores the persisted roster filters and sort on a fresh visit to the bare roster URL', async () => {
+ logic.actions.setScoutEnabledFilter('enabled')
+ logic.actions.setScoutTagFilter(['revenue'])
+ logic.actions.setScoutOwnerFilter(OWNER.uuid)
+ logic.actions.setScoutRosterSort('last_run')
+ logic.actions.setScoutSearch('rev')
+ logic.unmount()
+
+ // A new tab: a fresh store mounts the roster on the bare URL, which kea-router reports as a POP.
+ initKeaTests()
+ router.actions.push(urls.inbox('scouts'))
+ logic = scoutFleetLogic()
+ logic.mount()
+
+ expect(logic.values).toMatchObject({
+ scoutEnabledFilter: 'enabled',
+ selectedScoutTags: ['revenue'],
+ selectedScoutOwner: OWNER.uuid,
+ scoutRosterSort: 'last_run',
+ scoutSearch: '',
+ })
+ expect(router.values.searchParams).toEqual({
+ scoutEnabled: 'enabled',
+ scoutTags: 'revenue',
+ scoutOwner: OWNER.uuid,
+ })
+ })
+
it('drops a typed search that a URL hydration has already replaced', async () => {
jest.useFakeTimers()
try {
diff --git a/products/signals/frontend/inbox/logics/scoutFleetLogic.ts b/products/signals/frontend/inbox/logics/scoutFleetLogic.ts
index fc491feca2ed..45a39cb9aecf 100644
--- a/products/signals/frontend/inbox/logics/scoutFleetLogic.ts
+++ b/products/signals/frontend/inbox/logics/scoutFleetLogic.ts
@@ -1307,8 +1307,11 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
startScoutChatTaskFailure: () => null,
},
],
+ // The enabled, tag, owner, and sort choices persist like the report list's filters, so a new
+ // visit opens the roster as the user left it. Search does not persist, the same as the report list.
selectedScoutTags: [
[] as string[],
+ { persist: true },
{
setScoutTagFilter: (_, { tags }) => tags,
hydrateRosterFilters: (_, { tags }) => tags,
@@ -1323,6 +1326,7 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
],
scoutEnabledFilter: [
'all' as ScoutEnabledFilter,
+ { persist: true },
{
setScoutEnabledFilter: (_, { filter }) => filter,
hydrateRosterFilters: (_, { filter }) => filter,
@@ -1330,6 +1334,7 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
],
selectedScoutOwner: [
null as string | null,
+ { persist: true },
{
setScoutOwnerFilter: (_, { owner }) => owner,
hydrateRosterFilters: (_, { owner }) => owner,
@@ -1337,6 +1342,7 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
],
scoutRosterSort: [
'name' as ScoutRosterSort,
+ { persist: true },
{
setScoutRosterSort: (_, { sort }) => sort,
},
@@ -2143,7 +2149,7 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
_: unknown,
searchParams: Record<string, any>,
__: unknown,
- { method }: { method: 'PUSH' | 'REPLACE' | 'POP' }
+ { method, initial }: { method: 'PUSH' | 'REPLACE' | 'POP'; initial?: boolean }
): void => {
const hasRosterParams =
'scoutSearch' in searchParams ||
@@ -2154,7 +2160,9 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
// Back or Forward onto a bare roster URL asks for the default, unfiltered view: reset
// the filters and leave the URL bare so a second Back can still reach the entries
// beneath it. Reflecting the persisted filters back here would undo the navigation.
- if (method === 'POP') {
+ // kea-router also reports the location at mount as a POP, flagged `initial`. That is a
+ // fresh visit, not a Back, so it keeps the persisted filters.
+ if (method === 'POP' && !initial) {
if (
values.scoutSearch !== '' ||
values.scoutEnabledFilter !== 'all' ||
@@ -2170,7 +2178,7 @@ export const scoutFleetLogic = kea<scoutFleetLogicType>([
// replaces the bare URL to restore its own params while a Back is still being
// handled, and writing the roster filters there would leave the URL filtered after
// that Back resets the controls.
- if (method !== 'PUSH') {
+ if (method !== 'PUSH' && !initial) {
return
}
const desired = rosterFilterSearchParams({}, rosterFilterUrlState(values))