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.

fix(prompts): show what "Late or missing" leaves and put the furthest behind first (#1098)

Cihanddd051316757
diff --git a/web/messages/en.json b/web/messages/en.json
index a0fbb79b6..d9f9bd46e 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -2401,6 +2401,11 @@
"stopped": "{deleted} of {total} prompts deleted",
"stoppedDescription": "Deleting stopped at an error. {kept, plural, one {The other prompt is} other {The other # prompts are}} back in the list, so you can try again.",
"notDeleted": "{kept} of {total} {total, plural, one {prompt} other {prompts}} couldn't be deleted."
+ },
+ "lateFilter": {
+ "label": "Late or missing · {count}",
+ "title": "Prompts named late, or not at all, on at least one AI platform. On, the furthest behind come first.",
+ "order": "Furthest behind first: late or missing on the most AI platforms, then the worse average position."
}
},
"competitors": {
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
index 5ec46a6f6..88bdad4e6 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
@@ -30,6 +30,7 @@ import { Input } from '@/components/ui/input';
import {
Table,
TableBody,
+ TableCaption,
TableCell,
TableHead,
TableHeader,
@@ -92,10 +93,11 @@ import {
Lightbulb,
} from 'lucide-react';
import { cn } from '@/lib/utils';
-import type {
- PlatformDot,
- PlatformDotState,
- PromptPositionCell,
+import {
+ compareLateness,
+ type PlatformDot,
+ type PlatformDotState,
+ type PromptPositionCell,
} from '@/lib/prompt-position-summary';
import { mentionRateLabel } from '@/lib/prompt-improve';
import { useBrandStore } from '@/stores/use-brand-store';
@@ -2562,6 +2564,7 @@ function AllPromptsTab({
const tUsage = useTranslations('prompts.usage');
const format = useFormatter();
const tDelete = useTranslations('prompts.bulkDelete');
+ const tLate = useTranslations('prompts.lateFilter');
// Rows deleted from the row menu or the bulk bar, hidden at once and
// deleted for real after the Undo window (PROMPT-006). There is no soft
// delete for prompts — a delete drops their history — so the delay is the
@@ -3004,6 +3007,10 @@ function AllPromptsTab({
const rawSort = searchParams.get('sort');
const activeSort: AllPromptsSortKey = isAllPromptsSortKey(rawSort) ? rawSort : 'visibility';
const dir: SortDir = searchParams.get('dir') === 'asc' ? 'asc' : 'desc';
+ // With "Late or missing" on and no column picked, the furthest behind come
+ // first: nearly every tracked prompt is late or missing somewhere, so the
+ // filter alone left the first page as it was (see compareLateness).
+ const latenessOrder = lateOnly && !isAllPromptsSortKey(rawSort);
// Click a header to sort: a new column starts at desc ("show me the extremes");
// re-clicking the active column toggles desc⇄asc. Persisted to the URL so the
@@ -3013,9 +3020,10 @@ function AllPromptsTab({
const handleSort = useCallback(
(key: AllPromptsSortKey) => {
const params = new URLSearchParams(Array.from(searchParams.entries()));
- // Position is best when lowest, so it starts at asc (#1 first).
+ // Position is best when lowest, so it starts at asc (#1 first). Under the
+ // "Late or missing" order no column is active, so any header starts afresh.
const nextDir: SortDir =
- activeSort === key
+ activeSort === key && !latenessOrder
? dir === 'desc'
? 'asc'
: 'desc'
@@ -3027,10 +3035,37 @@ function AllPromptsTab({
params.set('dir', nextDir);
window.history.replaceState(null, '', `?${params.toString()}`);
},
- [searchParams, activeSort, dir],
+ [searchParams, activeSort, dir, latenessOrder],
);
- const filtered = useMemo(() => {
+ // Turning "Late or missing" on sets a picked column aside, so the furthest
+ // behind lead; turning it off brings that column back, unless a header was
+ // clicked in between, which then stays.
+ const setAsideSort = useRef<{ sort: string; dir: string | null } | null>(null);
+ // Read and flipped at click time, so a quick second click sees the first.
+ const lateOnlyNow = useRef(lateOnly);
+ const toggleLateOnly = useCallback(() => {
+ const turningOn = !lateOnlyNow.current;
+ lateOnlyNow.current = turningOn;
+ const params = new URLSearchParams(window.location.search);
+ const sort = params.get('sort');
+ if (turningOn && sort) {
+ setAsideSort.current = { sort, dir: params.get('dir') };
+ params.delete('sort');
+ params.delete('dir');
+ window.history.replaceState(null, '', `?${params.toString()}`);
+ } else if (!turningOn && !sort && setAsideSort.current) {
+ params.set('sort', setAsideSort.current.sort);
+ if (setAsideSort.current.dir) params.set('dir', setAsideSort.current.dir);
+ window.history.replaceState(null, '', `?${params.toString()}`);
+ }
+ if (!turningOn) setAsideSort.current = null;
+ setLateOnly(turningOn);
+ }, []);
+
+ // Search, prompt status and work status first: the "Late or missing" count
+ // is out of these.
+ const searched = useMemo(() => {
const q = search.trim().toLowerCase();
let list = [...prompts];
if (q) {
@@ -3044,7 +3079,25 @@ function AllPromptsTab({
workFilter === 'none' ? statusOf(p) === null : statusOf(p) === workFilter,
);
}
- if (lateOnly) list = list.filter((p) => positions[p.id]?.lateOrMissing);
+ return list;
+ }, [prompts, search, statusFilter, workFilter, statusOf]);
+
+ const lateCount = useMemo(
+ () => searched.filter((p) => positions[p.id]?.lateOrMissing).length,
+ [searched, positions],
+ );
+
+ const filtered = useMemo(() => {
+ const list = lateOnly ? searched.filter((p) => positions[p.id]?.lateOrMissing) : [...searched];
+ if (latenessOrder) {
+ // Equally far behind: the more visible prompt first, as the table opens.
+ const score = (p: Prompt) => visibility[p.id]?.score ?? 0;
+ return list.sort(
+ (a, b) =>
+ compareLateness(positions[a.id], positions[b.id]) ||
+ compareNullsLast(score(a), score(b), 'desc'),
+ );
+ }
const valueOf = (p: Prompt): number | null => {
const vis = visibility[p.id];
@@ -3068,19 +3121,7 @@ function AllPromptsTab({
};
return list.sort((a, b) => compareNullsLast(valueOf(a), valueOf(b), dir));
- }, [
- prompts,
- search,
- statusFilter,
- workFilter,
- lateOnly,
- statusOf,
- activeSort,
- dir,
- visibility,
- positions,
- volumeByPromptId,
- ]);
+ }, [searched, lateOnly, latenessOrder, activeSort, dir, visibility, positions, volumeByPromptId]);
// Pagination for the main prompt list. resetKey encodes every variable that
// changes the visible row set (search text, sort column, sort direction, work
@@ -3208,10 +3249,10 @@ function AllPromptsTab({
variant={lateOnly ? 'default' : 'outline'}
className="h-8 text-xs"
aria-pressed={lateOnly}
- title="Prompts named late, or not at all, on at least one AI platform"
- onClick={() => setLateOnly((v) => !v)}
+ title={tLate('title')}
+ onClick={toggleLateOnly}
>
- Late or missing
+ {tLate('label', { count: lateCount })}
</Button>
<div className="relative w-60">
<Search className="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground" />
@@ -3249,6 +3290,7 @@ function AllPromptsTab({
/>
)}
<Table stickyHeader stickyFirstColumn>
+ {latenessOrder && <TableCaption className="sr-only">{tLate('order')}</TableCaption>}
<TableHeader>
<TableRow>
<TableHead className="pl-6">
@@ -3277,7 +3319,7 @@ function AllPromptsTab({
className="text-right"
tooltip={`AI Visibility Score (0-100) for this prompt over the ${rangeLabel}: how often answers mention the brand (60%), cite its site (25%) and how early it's named (15%). Hover a value for the components.`}
sortKey="visibility"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
@@ -3287,7 +3329,7 @@ function AllPromptsTab({
className="text-right"
tooltip={`Total times the brand was mentioned across AI answers for this prompt over the ${rangeLabel}.`}
sortKey="mentions"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
@@ -3297,7 +3339,7 @@ function AllPromptsTab({
className="text-right"
tooltip={`Total times your pages were cited in AI answers for this prompt over the ${rangeLabel}.`}
sortKey="citations"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
@@ -3307,7 +3349,7 @@ function AllPromptsTab({
className="pl-8"
tooltip={`Average position the brand is named at in AI answers over the ${rangeLabel}, with the change against the previous period of the same length. Hover a value for each platform; the chart button opens the details.`}
sortKey="position"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
@@ -3317,7 +3359,7 @@ function AllPromptsTab({
className="text-right"
tooltip="Estimated monthly AI prompt volume, from keyword analysis. Empty until analysed."
sortKey="volume"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
@@ -3333,7 +3375,7 @@ function AllPromptsTab({
className="text-right"
tooltip={`Number of tracking runs for this prompt over the ${rangeLabel} (one per platform per day).`}
sortKey="runs"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
@@ -3343,7 +3385,7 @@ function AllPromptsTab({
className="text-right"
tooltip="Most recent tracking run for this prompt."
sortKey="lastRun"
- activeSort={activeSort}
+ activeSort={latenessOrder ? null : activeSort}
dir={dir}
onSort={handleSort}
>
diff --git a/web/src/lib/prompt-position-summary.test.ts b/web/src/lib/prompt-position-summary.test.ts
index fd0899357..7d66ece4f 100644
--- a/web/src/lib/prompt-position-summary.test.ts
+++ b/web/src/lib/prompt-position-summary.test.ts
@@ -8,7 +8,10 @@
import { describe, expect, test } from 'vitest';
import {
buildPositionCell,
+ compareLateness,
previousWindow,
+ type PlatformDotState,
+ type PromptPositionCell,
type PlatformPositionRow,
} from './prompt-position-summary';
@@ -144,6 +147,55 @@ describe('buildPositionCell', () => {
});
});
+describe('compareLateness', () => {
+ const cell = (avg: number | null, states: PlatformDotState[]): PromptPositionCell => ({
+ avg,
+ delta: null,
+ dots: states.map((state, i) => ({
+ id: `p${i}`,
+ label: `P${i}`,
+ state,
+ avg: null,
+ runs: 4,
+ mentionedRuns: 0,
+ })),
+ lateOrMissing: states.some((s) => s === 'late' || s === 'missing'),
+ });
+ const order = (cells: Record<string, PromptPositionCell | undefined>) =>
+ Object.keys(cells).sort((a, b) => compareLateness(cells[a], cells[b]));
+
+ test('puts the prompt late or missing on the most platforms first', () => {
+ expect(
+ order({
+ one: cell(1.5, ['early', 'missing', 'early']),
+ three: cell(2, ['late', 'missing', 'missing']),
+ two: cell(3, ['late', 'missing', 'early']),
+ }),
+ ).toEqual(['three', 'two', 'one']);
+ });
+
+ test('then the one missing on more of them, then the worse average', () => {
+ expect(
+ order({
+ lateTwice: cell(4, ['late', 'late']),
+ missingTwice: cell(2, ['missing', 'missing']),
+ missingOnceAt3: cell(3, ['missing', 'late']),
+ missingOnceAt5: cell(5, ['missing', 'late']),
+ }),
+ ).toEqual(['missingTwice', 'missingOnceAt5', 'missingOnceAt3', 'lateTwice']);
+ });
+
+ test('counts a prompt never ranked as the furthest back, and one without a cell last', () => {
+ expect(
+ order({
+ none: undefined,
+ ranked: cell(6, ['missing']),
+ neverRanked: cell(null, ['missing']),
+ }),
+ ).toEqual(['neverRanked', 'ranked', 'none']);
+ });
+});
+
describe('previousWindow', () => {
test('is the same length, ending where the window starts', () => {
expect(
diff --git a/web/src/lib/prompt-position-summary.ts b/web/src/lib/prompt-position-summary.ts
index 1c8f4f28a..fbb9bb15b 100644
--- a/web/src/lib/prompt-position-summary.ts
+++ b/web/src/lib/prompt-position-summary.ts
@@ -110,6 +110,28 @@ export function buildPositionCell(
};
}
+/**
+ * Orders prompts furthest behind first, for the "Late or missing" filter.
+ * Nearly every tracked prompt is late or missing somewhere, so the filter
+ * alone barely changes the table; this puts first the prompts late or missing
+ * on the most platforms, then those missing on more of them, then the worse
+ * average position, a prompt never ranked counting as the furthest back.
+ * Negative when `a` is further behind.
+ */
+export function compareLateness(
+ a: PromptPositionCell | undefined,
+ b: PromptPositionCell | undefined,
+): number {
+ const count = (cell: PromptPositionCell | undefined, states: PlatformDotState[]) =>
+ cell?.dots.filter((d) => states.includes(d.state)).length ?? 0;
+ const behind = (cell: PromptPositionCell | undefined) => cell?.avg ?? Number.POSITIVE_INFINITY;
+ return (
+ count(b, ['late', 'missing']) - count(a, ['late', 'missing']) ||
+ count(b, ['missing']) - count(a, ['missing']) ||
+ (behind(b) === behind(a) ? 0 : behind(b) > behind(a) ? 1 : -1)
+ );
+}
+
/** The previous period of the same length, ending where this one starts. */
export function previousWindow(window: { from: string; to?: string }, now = Date.now()) {
const from = Date.parse(window.from);