Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(action-center): keep list filters, sort and search in the URL (#984)
Gökhan Geyik7cc2ab3cd68a
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsxindex cba256369..0bdcdf13c 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/action-center/actions/page.tsx@@ -18,6 +18,7 @@ import { useBrandStore } from '@/stores/use-brand-store';import type { Brand } from '@/types';import { getActions, type ActionItem } from '@/lib/actions/action-center';import { listMembers, type TeamMember } from '@/lib/actions/team';+import { readUrlChoice, readUrlParam, writeUrlParams } from '@/lib/url-state';import {ACTION_CATEGORIES,ACTION_IMPACTS,@@ -129,6 +130,35 @@ function ActionsContent({ brand }: { brand: Brand }) {const [search, setSearch] = useState('');const [focus, setFocus] = useState<CardFocus | null>(null);+ // Filters, sort and search live in the URL (#896) so a refresh keeps them+ // and a filtered view can be shared. Read after mount; defaults stay out.+ const [urlRead, setUrlRead] = useState(false);+ useEffect(() => {+ setCategory(+ readUrlChoice<ActionCategory | 'all'>('category', ['all', ...ACTION_CATEGORIES], 'all'),+ );+ setImpact(readUrlChoice<ActionImpact | 'all'>('impact', ['all', ...ACTION_IMPACTS], 'all'));+ setStatus(readUrlChoice<ActionStatus | 'all'>('status', ['all', ...ACTION_STATUSES], 'all'));+ setAssignee(readUrlParam('assignee') || 'all');+ setSort(readUrlChoice<ActionSort>('sort', ACTION_SORTS, 'priority'));+ setSearch(readUrlParam('q'));+ setUrlRead(true);+ }, []);++ useEffect(() => {+ if (!urlRead) return;+ // Debounced, so typing in search doesn't rewrite the URL on every key.+ const timer = setTimeout(+ () =>+ writeUrlParams(+ { category, impact, status, assignee, sort, q: search.trim() },+ { category: 'all', impact: 'all', status: 'all', assignee: 'all', sort: 'priority' },+ ),+ 300,+ );+ return () => clearTimeout(timer);+ }, [urlRead, category, impact, status, assignee, sort, search]);+const [selectedId, setSelectedId] = useState<string | null>(null);// The open drawer lives in the URL (?action=<id>) so that coming BACK from@@ -161,6 +191,12 @@ function ActionsContent({ brand }: { brand: Brand }) {.catch(() => setMembers([]));}, [load]);+ // An assignee from the URL who is no longer on the team falls back to all.+ useEffect(() => {+ if (members.length === 0 || assignee === 'all' || assignee === 'unassigned') return;+ if (!members.some((m) => m.userId === assignee)) setAssignee('all');+ }, [members, assignee]);+// Restore the drawer named by the URL once the list is in.useEffect(() => {if (!actions) return;diff --git a/web/src/app/[locale]/(dashboard)/dashboard/action-center/history/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/action-center/history/page.tsxindex 4f8368156..64cebdc99 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/action-center/history/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/action-center/history/page.tsx@@ -16,6 +16,7 @@ import {import { Skeleton } from '@/components/ui/skeleton';import { useBrandStore } from '@/stores/use-brand-store';import { getActionHistory } from '@/lib/actions/action-history';+import { readUrlChoice, readUrlParam, writeUrlParams } from '@/lib/url-state';import { actionTexts } from '@/lib/action-center/display';import {HISTORY_PAGE_SIZE,@@ -74,6 +75,41 @@ export default function ActionCenterHistoryPage() {const [page, setPage] = useState(1);const [selected, setSelected] = useState<ActionHistoryItem | null>(null);+ // Filters, sort and search live in the URL (#896) so a refresh keeps them+ // and a filtered view can be shared. Read after mount, before the first load.+ const [urlRead, setUrlRead] = useState(false);+ useEffect(() => {+ setRange(readUrlChoice('range', RANGE_PRESETS, '30d'));+ setStatus(readUrlChoice<ActionStatus | 'all'>('status', ['all', ...HISTORY_STATUSES], 'all'));+ setType(readUrlChoice<ActionCategory | 'all'>('type', ['all', ...ACTION_CATEGORIES], 'all'));+ setImpact(readUrlChoice<ActionImpact | 'all'>('impact', ['all', ...ACTION_IMPACTS], 'all'));+ setSource(readUrlChoice<SignalSource | 'all'>('source', ['all', ...SIGNAL_SOURCES], 'all'));+ setSort(readUrlChoice('sort', HISTORY_SORTS, 'newest'));+ setSearch(readUrlParam('q'));+ setUrlRead(true);+ }, []);++ useEffect(() => {+ if (!urlRead) return;+ // Debounced, so typing in search doesn't rewrite the URL on every key.+ const timer = setTimeout(+ () =>+ writeUrlParams(+ { range, status, type, impact, source, sort, q: search.trim() },+ {+ range: '30d',+ status: 'all',+ type: 'all',+ impact: 'all',+ source: 'all',+ sort: 'newest',+ },+ ),+ 300,+ );+ return () => clearTimeout(timer);+ }, [urlRead, range, status, type, impact, source, sort, search]);+const load = useCallback(async () => {if (!brandId) {setItems([]);@@ -94,8 +130,8 @@ export default function ActionCenterHistoryPage() {}, [brandId, range]);useEffect(() => {- void load();- }, [load]);+ if (urlRead) void load();+ }, [load, urlRead]);// Any narrowing puts the reader back on page 1; staying on page 4 of a list// that now has one page shows nothing and looks like a failure.diff --git a/web/src/app/[locale]/(dashboard)/dashboard/action-center/signals/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/action-center/signals/page.tsxindex 07aae5c70..82908892b 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/action-center/signals/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/action-center/signals/page.tsx@@ -41,6 +41,7 @@ import {import { Skeleton } from '@/components/ui/skeleton';import { cn } from '@/lib/utils';import { toCsv } from '@/lib/csv';+import { readUrlChoice, readUrlParam, writeUrlParams } from '@/lib/url-state';import type { KpiTrendPoint } from '@/lib/actions/kpis';const SIGNAL_EXPORT_HEADERS = [@@ -108,6 +109,35 @@ function SignalsContent({ brand }: { brand: Brand }) {const [source, setSource] = useState<SignalSource | 'all'>('all');const [search, setSearch] = useState('');+ // Filters and search live in the URL (#896) so a refresh keeps them and a+ // filtered view can be shared. Read after mount, before the first load.+ const [urlRead, setUrlRead] = useState(false);+ useEffect(() => {+ setDatePreset(readUrlChoice('range', DATE_PRESETS, '30d'));+ setCategory(+ readUrlChoice<SignalCategory | 'all'>('category', ['all', ...SIGNAL_CATEGORIES], 'all'),+ );+ setImpact(readUrlChoice<SignalImpact | 'all'>('impact', ['all', ...SIGNAL_IMPACTS], 'all'));+ setStatus(readUrlChoice<SignalStatus | 'all'>('status', ['all', ...SIGNAL_STATUSES], 'all'));+ setSource(readUrlChoice<SignalSource | 'all'>('source', ['all', ...SIGNAL_SOURCES], 'all'));+ setSearch(readUrlParam('q'));+ setUrlRead(true);+ }, []);++ useEffect(() => {+ if (!urlRead) return;+ // Debounced, so typing in search doesn't rewrite the URL on every key.+ const timer = setTimeout(+ () =>+ writeUrlParams(+ { range: datePreset, category, impact, status, source, q: search.trim() },+ { range: '30d', category: 'all', impact: 'all', status: 'all', source: 'all' },+ ),+ 300,+ );+ return () => clearTimeout(timer);+ }, [urlRead, datePreset, category, impact, status, source, search]);+const [selected, setSelected] = useState<Signal | null>(null);const [busyId, setBusyId] = useState<string | null>(null);@@ -145,8 +175,8 @@ function SignalsContent({ brand }: { brand: Brand }) {}, [brand.id, dayFrom, dayTo]);useEffect(() => {- void load();- }, [load]);+ if (urlRead) void load();+ }, [load, urlRead]);// Restore the drawer named by the URL once the list is in. Read via// window.location rather than useSearchParams to keep the page out of adiff --git a/web/src/lib/url-state.test.ts b/web/src/lib/url-state.test.tsnew file mode 100644index 000000000..8ebba6178--- /dev/null+++ b/web/src/lib/url-state.test.ts@@ -0,0 +1,46 @@+import { beforeEach, describe, expect, it } from 'vitest';+import { readUrlChoice, readUrlParam, writeUrlParams } from './url-state';++beforeEach(() => {+ window.history.replaceState({ router: 'state' }, '', '/dashboard/list');+});++describe('readUrlChoice', () => {+ it('returns an allowed value from the query string', () => {+ window.history.replaceState(null, '', '/dashboard/list?status=open');+ expect(readUrlChoice('status', ['all', 'open', 'done'] as const, 'all')).toBe('open');+ });++ it('falls back on a missing or unknown value', () => {+ expect(readUrlChoice('status', ['all', 'open'] as const, 'all')).toBe('all');+ window.history.replaceState(null, '', '/dashboard/list?status=bogus');+ expect(readUrlChoice('status', ['all', 'open'] as const, 'all')).toBe('all');+ });+});++describe('readUrlParam', () => {+ it('returns the value or an empty string', () => {+ window.history.replaceState(null, '', '/dashboard/list?q=shoes');+ expect(readUrlParam('q')).toBe('shoes');+ expect(readUrlParam('missing')).toBe('');+ });+});++describe('writeUrlParams', () => {+ it('writes non-default values and keeps unrelated params', () => {+ window.history.replaceState(null, '', '/dashboard/list?opportunity=abc');+ writeUrlParams({ status: 'open', impact: 'all' }, { status: 'all', impact: 'all' });+ expect(window.location.search).toBe('?opportunity=abc&status=open');+ });++ it('removes defaults, empty strings and nulls', () => {+ window.history.replaceState(null, '', '/dashboard/list?status=open&q=x&prompt=p1');+ writeUrlParams({ status: 'all', q: '', prompt: null }, { status: 'all' });+ expect(window.location.search).toBe('');+ });++ it("keeps the router's history state", () => {+ writeUrlParams({ status: 'open' });+ expect(window.history.state).toEqual({ router: 'state' });+ });+});diff --git a/web/src/lib/url-state.ts b/web/src/lib/url-state.tsnew file mode 100644index 000000000..51e19c3fb--- /dev/null+++ b/web/src/lib/url-state.ts@@ -0,0 +1,40 @@+/**+ * Page state kept in the query string, so a refresh or a shared link restores+ * a filtered view. Pages read it after mount — useSearchParams would need a+ * Suspense boundary around the page — and write it with replaceState, which+ * adds no history entry and keeps the router's own history state.+ */++/** A query param's value, or `fallback` when it is absent or not one of `allowed`. */+export function readUrlChoice<T extends string>(+ name: string,+ allowed: readonly T[],+ fallback: T,+): T {+ const value = new URLSearchParams(window.location.search).get(name);+ return value !== null && (allowed as readonly string[]).includes(value) ? (value as T) : fallback;+}++/** A free-form query param (an id, a search), or '' when absent. */+export function readUrlParam(name: string): string {+ return new URLSearchParams(window.location.search).get(name) ?? '';+}++/**+ * Merge `updates` into the current query string. A value equal to its entry+ * in `defaults`, an empty string or null removes the param, so a page in its+ * default state has a clean URL. Params not named in `updates` are kept.+ */+export function writeUrlParams(+ updates: Record<string, string | null | undefined>,+ defaults: Record<string, string> = {},+): void {+ const url = new URL(window.location.href);+ for (const [name, value] of Object.entries(updates)) {+ if (value == null || value === '' || value === defaults[name]) url.searchParams.delete(name);+ else url.searchParams.set(name, value);+ }+ if (url.href !== window.location.href) {+ window.history.replaceState(window.history.state, '', url);+ }+}