Skip to content

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.

feat(prompts): pick the Positions panel's date range inside the panel (#1010)

Cihanfe2ca20a18f1
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
index 937067b4a..7d06981d0 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
@@ -114,10 +114,12 @@ import { formatRelative } from '@/lib/format-relative';
import { compareNullsLast, type SortDir } from './prompt-sort';
import { formatCompactNumber } from '@/lib/format';
import { usePagination, TablePager } from '@/components/table-pager';
+import { PromptPositionsSheet } from '@/components/prompts/prompt-positions-sheet';
import {
- PromptPositionsSheet,
- type PositionsPrompt,
-} from '@/components/prompts/prompt-positions-sheet';
+ parsePositionsRange,
+ positionsUrlParams,
+ type PositionsRange,
+} from '@/lib/positions-range';
// ─── Info Tooltip ─────────────────────────────────────────────────────────────
@@ -2210,12 +2212,59 @@ function AllPromptsTab({
new Map(),
);
const searchParams = useSearchParams();
- // The row whose Positions panel is open. It lives here, beside the table,
- // so closing the panel leaves search, sort, page and scroll as they were.
- const [positionsFor, setPositionsFor] = useState<PositionsPrompt | null>(null);
+ // The row whose Positions panel is open, and the panel's own range. They
+ // live here, beside the table, so closing the panel leaves search, sort,
+ // page and scroll as they were. Both are mirrored to the URL
+ // (?positions=<id>&positionsRange=7d) so an open panel can be shared.
+ const [positionsId, setPositionsId] = useState<string | null>(() =>
+ searchParams.get('positions'),
+ );
+ const [positionsRange, setPositionsRange] = useState<PositionsRange>(() =>
+ parsePositionsRange(searchParams, positionsPreset),
+ );
+ const panelWindow = useMemo(
+ () =>
+ resolvePromptRange(positionsRange.preset, {
+ from: positionsRange.from,
+ to: positionsRange.to,
+ }),
+ [positionsRange],
+ );
// A brand switch or reload that drops the prompt must not leave its panel up.
- const openPositions =
- positionsFor && prompts.some((p) => p.id === positionsFor.id) ? positionsFor : null;
+ const openPositions = useMemo(() => {
+ const p = positionsId ? prompts.find((row) => row.id === positionsId) : undefined;
+ return p ? { id: p.id, text: p.text } : null;
+ }, [positionsId, prompts]);
+ // Adjust-state-during-render (as in usePagination): clear the id once the
+ // list has loaded without it, so the URL drops it too.
+ if (!loading && positionsId && !openPositions) setPositionsId(null);
+
+ // The panel opens on the table's window; changing it there only moves the panel.
+ const openPositionsPanel = useCallback(
+ (promptId: string) => {
+ setPositionsRange({
+ preset: positionsPreset,
+ from: positionsPreset === 'custom' ? positionsWindow.from.slice(0, 10) : '',
+ to: positionsPreset === 'custom' ? (positionsWindow.to?.slice(0, 10) ?? '') : '',
+ });
+ setPositionsId(promptId);
+ },
+ [positionsPreset, positionsWindow],
+ );
+
+ // Shallow URL sync, same reasoning as the page's tab sync. Reads the live
+ // location rather than `searchParams`, which can lag a sibling effect's
+ // replaceState in the same commit and would drop its params.
+ useEffect(() => {
+ const params = new URLSearchParams(window.location.search);
+ const want = positionsUrlParams(positionsId, positionsRange);
+ if (Object.entries(want).every(([k, v]) => params.get(k) === v)) return;
+ for (const [k, v] of Object.entries(want)) {
+ if (v) params.set(k, v);
+ else params.delete(k);
+ }
+ window.history.replaceState(null, '', `?${params.toString()}${window.location.hash}`);
+ }, [positionsId, positionsRange]);
const statusOf = useCallback(
(p: Prompt) => (statusOverrides.has(p.id) ? statusOverrides.get(p.id)! : p.workStatus),
@@ -2581,7 +2630,7 @@ function AllPromptsTab({
size="xs"
variant="outline"
aria-label={`View positions for ${p.text}`}
- onClick={() => setPositionsFor({ id: p.id, text: p.text })}
+ onClick={() => openPositionsPanel(p.id)}
>
<BarChart3 />
See
@@ -2649,10 +2698,11 @@ function AllPromptsTab({
</CardContent>
<PromptPositionsSheet
prompt={openPositions}
- window={positionsWindow}
- preset={positionsPreset}
+ range={positionsRange}
+ window={panelWindow}
+ onRangeChange={setPositionsRange}
region={regionFilter}
- onClose={() => setPositionsFor(null)}
+ onClose={() => setPositionsId(null)}
/>
</Card>
);
diff --git a/web/src/components/prompts/prompt-positions-sheet.tsx b/web/src/components/prompts/prompt-positions-sheet.tsx
index 13640125d..1b796f8b1 100644
--- a/web/src/components/prompts/prompt-positions-sheet.tsx
+++ b/web/src/components/prompts/prompt-positions-sheet.tsx
@@ -2,7 +2,8 @@
/**
* Positions panel for one tracked prompt: per-platform mention and citation
- * results over the Prompts table's window and location.
+ * results over a window and the Prompts table's location. The window opens on
+ * the table's and can be changed inside the panel without touching the table.
*
* The 24h window shows each platform's latest answer; longer windows show
* days — how many were tracked, mentioned and cited, with a block per day and
@@ -39,7 +40,9 @@ import { cn } from '@/lib/utils';
import { formatRegionDisplay } from '@/lib/region';
import { positionTone } from '@/lib/position-tone';
import { CONTACT_SALES_URL, type PlanId } from '@/config/plans';
-import type { PromptRangePreset } from '@/config/prompt-options';
+import { PROMPT_RANGE_PRESETS, type PromptRangePreset } from '@/config/prompt-options';
+import type { PositionsRange } from '@/lib/positions-range';
+import { DateRangeFilter } from '@/components/filters/date-range-filter';
import { getPromptPositions, type PromptPositionsData } from '@/lib/actions/prompt-positions';
import type {
AnswerView,
@@ -49,6 +52,8 @@ import type {
} from '@/lib/prompt-positions';
import type { Sentiment } from '@/types';
+export type { PositionsRange } from '@/lib/positions-range';
+
export interface PositionsPrompt {
id: string;
text: string;
@@ -57,9 +62,12 @@ export interface PositionsPrompt {
interface Props {
/** The prompt to show; null keeps the panel closed. */
prompt: PositionsPrompt | null;
- /** The table's window: the same bounds its Mentions / Citations columns read. */
+ /** The panel's selected range; it opens on the table's. */
+ range: PositionsRange;
+ /** `range` resolved to the bounds the data is read over. */
window: { from: string; to?: string };
- preset: PromptRangePreset;
+ /** Changes the panel's range only; the table keeps its own. */
+ onRangeChange: (range: PositionsRange) => void;
/** The table's location; empty means every location. */
region: string;
onClose: () => void;
@@ -93,13 +101,20 @@ const formatDateTime = (iso: string) =>
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`;
const pct = (n: number, of: number) => (of > 0 ? `${Math.round((n / of) * 100)}%` : '—');
-function windowTitle(preset: PromptRangePreset, window: { from: string; to?: string }): string {
- if (preset !== 'custom') return `Last ${preset}`;
- const to = window.to ?? new Date().toISOString();
- return `Custom: ${SHORT_DATE_FMT.format(new Date(window.from))} – ${DATE_FMT.format(new Date(to))}`;
+// The resolved dates follow in the caption, so a custom range isn't spelled out twice.
+function windowTitle(preset: PromptRangePreset): string {
+ return preset === 'custom' ? 'Custom range' : `Last ${preset}`;
}
-export function PromptPositionsSheet({ prompt, window, preset, region, onClose }: Props) {
+export function PromptPositionsSheet({
+ prompt,
+ range,
+ window,
+ onRangeChange,
+ region,
+ onClose,
+}: Props) {
+ const preset = range.preset;
// Everything the data depends on. A response is shown only while its key
// still matches, so another prompt's (or window's) numbers never linger.
const key = prompt ? `${prompt.id}|${window.from}|${window.to ?? ''}|${region}` : '';
@@ -161,7 +176,7 @@ export function PromptPositionsSheet({ prompt, window, preset, region, onClose }
)}
<SheetDescription className="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs">
<CalendarDays className="h-3.5 w-3.5" />
- <span className="font-medium text-foreground">{windowTitle(preset, window)}</span>
+ <span className="font-medium text-foreground">{windowTitle(preset)}</span>
{data && latestMode && (
<span>
Last run:{' '}
@@ -181,6 +196,18 @@ export function PromptPositionsSheet({ prompt, window, preset, region, onClose }
</Badge>
)}
</SheetDescription>
+ <div className="flex flex-wrap items-end gap-3 pt-1">
+ <DateRangeFilter
+ label="Period"
+ value={preset}
+ presets={PROMPT_RANGE_PRESETS}
+ onChange={(next) => onRangeChange({ ...range, preset: next })}
+ from={range.from}
+ to={range.to}
+ onFromChange={(from) => onRangeChange({ ...range, from })}
+ onToChange={(to) => onRangeChange({ ...range, to })}
+ />
+ </div>
</SheetHeader>
<div className="flex-1 overflow-y-auto px-5 py-4">
diff --git a/web/src/lib/positions-range.test.ts b/web/src/lib/positions-range.test.ts
new file mode 100644
index 000000000..6046f602f
--- /dev/null
+++ b/web/src/lib/positions-range.test.ts
@@ -0,0 +1,57 @@
+/**
+ * positions-range.test.ts (PROMPT-002)
+ *
+ * Tests the URL round trip of the Positions panel's own range.
+ */
+
+import { describe, expect, test } from 'vitest';
+import { parsePositionsRange, positionsUrlParams } from './positions-range';
+
+describe('positionsUrlParams', () => {
+ test('a closed panel clears every param', () => {
+ expect(
+ positionsUrlParams(null, { preset: 'custom', from: '2026-10-01', to: '2026-10-05' }),
+ ).toEqual({
+ positions: null,
+ positionsRange: null,
+ positionsFrom: null,
+ positionsTo: null,
+ });
+ });
+
+ test('a preset range keeps only the prompt and the preset', () => {
+ expect(positionsUrlParams('p1', { preset: '7d', from: '2026-10-01', to: '' })).toEqual({
+ positions: 'p1',
+ positionsRange: '7d',
+ positionsFrom: null,
+ positionsTo: null,
+ });
+ });
+
+ test('a custom range carries its dates, and omits a missing one', () => {
+ expect(positionsUrlParams('p1', { preset: 'custom', from: '2026-10-01', to: '' })).toEqual({
+ positions: 'p1',
+ positionsRange: 'custom',
+ positionsFrom: '2026-10-01',
+ positionsTo: null,
+ });
+ });
+});
+
+describe('parsePositionsRange', () => {
+ test('reads back what positionsUrlParams wrote', () => {
+ const range = { preset: 'custom' as const, from: '2026-10-01', to: '2026-10-05' };
+ const params = new URLSearchParams();
+ for (const [k, v] of Object.entries(positionsUrlParams('p1', range))) if (v) params.set(k, v);
+ expect(parsePositionsRange(params, '30d')).toEqual(range);
+ });
+
+ test('falls back to the table preset when the link has none or an unknown one', () => {
+ expect(parsePositionsRange(new URLSearchParams(), '30d')).toEqual({
+ preset: '30d',
+ from: '',
+ to: '',
+ });
+ expect(parsePositionsRange(new URLSearchParams('positionsRange=1y'), '7d').preset).toBe('7d');
+ });
+});
diff --git a/web/src/lib/positions-range.ts b/web/src/lib/positions-range.ts
new file mode 100644
index 000000000..8a5b29a28
--- /dev/null
+++ b/web/src/lib/positions-range.ts
@@ -0,0 +1,41 @@
+/**
+ * The Positions panel's own range (PROMPT-002) and its URL mirror, so an open
+ * panel can be shared: ?positions=<promptId>&positionsRange=7d, plus
+ * positionsFrom / positionsTo for a custom range.
+ */
+
+import { isPromptRangePreset, type PromptRangePreset } from '@/config/prompt-options';
+
+/** The panel's own window choice; `from` / `to` are YYYY-MM-DD and only used by custom. */
+export interface PositionsRange {
+ preset: PromptRangePreset;
+ from: string;
+ to: string;
+}
+
+/** URL params that mirror an open panel; null removes the param. */
+export function positionsUrlParams(
+ promptId: string | null,
+ range: PositionsRange,
+): Record<'positions' | 'positionsRange' | 'positionsFrom' | 'positionsTo', string | null> {
+ const custom = promptId !== null && range.preset === 'custom';
+ return {
+ positions: promptId,
+ positionsRange: promptId ? range.preset : null,
+ positionsFrom: custom && range.from ? range.from : null,
+ positionsTo: custom && range.to ? range.to : null,
+ };
+}
+
+/** The panel range a shared link asks for, falling back to the table's preset. */
+export function parsePositionsRange(
+ params: { get(name: string): string | null },
+ fallback: PromptRangePreset,
+): PositionsRange {
+ const raw = params.get('positionsRange');
+ return {
+ preset: isPromptRangePreset(raw) ? raw : fallback,
+ from: params.get('positionsFrom') ?? '',
+ to: params.get('positionsTo') ?? '',
+ };
+}