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): mark prompts added in the last day as New, and open them from Track (#1109)

Cihana5edd99fbcf8
diff --git a/docs/guides/prompts.mdx b/docs/guides/prompts.mdx
index dfc76dac3..27af1650d 100644
--- a/docs/guides/prompts.mdx
+++ b/docs/guides/prompts.mdx
@@ -18,6 +18,16 @@ Three ways:
2. **Suggestions card** (Insights tab) — Ansvisor analyzes your tracked prompts, competitor citations, and topic gaps, then generates 6–12 new prompt ideas with a topic label, reason, and estimated monthly AI volume. Click `+` to add directly to your tracked set.
3. **Bulk import** — paste a list of prompts, one per line, into the bulk-add dialog
+## Prompt status
+
+Each row in **Tracked Prompts** has a status:
+
+- **New** (amber) — added in the last 24 hours. New prompts lead the table until you sort by a column; after a day they read as Active.
+- **Active** — tracked on its schedule.
+- **Paused** — kept, but not tracked.
+
+The table opens on Active + New. The **Status** filter, or the cards above the table, show one status or all of them. **Track** on a suggestion in the Visibility page's Opportunities opens Tracked Prompts in a new tab, with the new prompts on top.
+
## Prompt Suggestions logic
The suggestion engine considers four signals:
diff --git a/web/messages/en.json b/web/messages/en.json
index 67267ce23..e467e1e86 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -2405,6 +2405,7 @@
"trackedPartly": "Tracked {tracked} of {total}: your plan's prompt locations are full.",
"trackFailed": "Couldn't track the suggestions.",
"openPrompts": "Open",
+ "addingPrompts": "Adding prompts to Tracked Prompts…",
"empty": "No prompt suggestions yet. Generate ideas to see what to track next.",
"unrated": "These suggestions aren't rated for fit yet. New suggestions are rated when they refresh, within a monthly allowance on your plan.",
"noneRelevant": "No suggestion fits your brand closely enough right now. Refresh for new ideas.",
@@ -2889,6 +2890,7 @@
"promptLocations": "Prompt locations",
"slotsLeft": "Slots left",
"paused": "{count} paused",
+ "new": "{count} new",
"beingTracked": "being tracked now",
"activePlusPaused": "active + paused",
"acrossBrands": "across {count, plural, one {# brand} other {# brands}}",
@@ -2908,16 +2910,32 @@
"loadFailed": "Couldn't load the counts",
"retry": "Retry",
"showPaused": "Show paused prompts",
+ "showNew": "Show prompts added in the last 24 hours",
"table": {
+ "tracked": "Tracked prompts ({count})",
"active": "Active prompts ({count})",
+ "new": "New prompts ({count})",
"paused": "Paused prompts ({count})",
"all": "All prompts ({count})",
- "filtered": "Filtered by the card above",
+ "filtered": "Filtered by status",
"showAll": "Show all {count}",
- "noneActive": "No active prompts match.",
- "nonePaused": "No paused prompts match."
+ "none": {
+ "tracked": "No tracked prompts match.",
+ "active": "No active prompts match.",
+ "new": "No new prompts match.",
+ "paused": "No paused prompts match."
+ }
}
},
+ "status": {
+ "label": "Status",
+ "tracked": "Active + New",
+ "all": "All statuses",
+ "active": "Active",
+ "new": "New",
+ "paused": "Paused",
+ "newHint": "Added in the last 24 hours"
+ },
"fanout": {
"engines": "Engines",
"allEngines": "All engines",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/_opportunities.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/_opportunities.tsx
index 4e61c2492..037df7bfb 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/_opportunities.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/_opportunities.tsx
@@ -12,6 +12,7 @@ import { trackSuggestions } from '@/lib/actions/prompt-suggestions';
import { sendTopicOpportunityToActionCenter } from '@/lib/actions/topic';
import { generateOpportunitiesOnDemand, getGenerationJobStatus } from '@/lib/actions/content';
import { waitForContentJob } from '@/lib/content-job';
+import { openPendingTab } from '@/lib/pending-tab';
import type { ContentUsage } from '@/lib/content-usage';
import {
contentLeft,
@@ -27,6 +28,8 @@ import type { TopicCompetitors } from '@/lib/insights-topics';
const VISIBLE_ITEMS = 4;
const SUGGESTIONS_HREF = '/dashboard/prompts/suggestions';
+/** Where Track takes the user: the table, with what they added on top as New. */
+const TRACKED_HREF = '/dashboard/prompts/tracked';
/**
* Opportunities (VIS-011), as in the v2 mockup: what to track next, from the
@@ -198,6 +201,9 @@ export function Opportunities({
left === null ? t('suggestHint') : `${t('suggestHint')} ${t('suggestHintQuota')}`;
const track = async (item: Opportunity) => {
+ // Tracked Prompts opens in a new tab, opened here in the click so it isn't
+ // blocked as a pop-up; it moves to the table once the prompts are added.
+ const tab = openPendingTab(t('addingPrompts'));
setBusy(item.key);
try {
const {
@@ -210,8 +216,16 @@ export function Opportunities({
if (done.length + skippedIds.length > 0) {
setTrackedIds((prev) => new Set([...prev, ...done, ...skippedIds]));
}
- if (done.length > 0) onTracked(done.length);
- const open = { label: t('openPrompts'), onClick: () => router.push('/dashboard/prompts') };
+ if (done.length > 0) {
+ onTracked(done.length);
+ tab.go(TRACKED_HREF);
+ } else {
+ tab.close();
+ }
+ // With the tab blocked, the toast's Open is the way there.
+ const open = tab.opened
+ ? undefined
+ : { label: t('openPrompts'), onClick: () => router.push(TRACKED_HREF) };
if (!error && done.length === 0) {
toast.info(t('alreadyHandled'));
} else if (!error && item.kind === 'topic' && item.topicId) {
@@ -236,6 +250,7 @@ export function Opportunities({
toast.error(t('trackFailed'), { description: error });
}
} catch {
+ tab.close();
toast.error(t('trackFailed'));
} finally {
setBusy(null);
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.test.tsx
index 3b5d191c6..435748d75 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.test.tsx
@@ -9,6 +9,8 @@ import {
countByStatus,
locationQuotaFromUsage,
matchesStatusFilter,
+ newFirst,
+ promptStatus,
type PromptUsageState,
} from './_usage-cards';
@@ -35,7 +37,12 @@ let root: Root;
const onFilter = vi.fn();
const onRetry = vi.fn();
-function render(state: PromptUsageState) {
+function render(state: PromptUsageState, newCount = 0) {
+ // Added an hour before the provider's clock, so they read as New.
+ const prompts = Array.from({ length: newCount }, () => ({
+ isActive: true,
+ createdAt: '2026-10-15T08:00:00.000Z',
+ }));
act(() => {
root.render(
<NextIntlClientProvider
@@ -48,7 +55,8 @@ function render(state: PromptUsageState) {
state={state}
brandName="Acme Coffee"
readOnly={false}
- filter="active"
+ prompts={prompts}
+ filter="tracked"
onFilter={onFilter}
onRetry={onRetry}
/>
@@ -138,8 +146,20 @@ describe('PromptUsageCards', () => {
expect(onFilter).toHaveBeenLastCalledWith('all');
act(() => button('2 paused').click());
expect(onFilter).toHaveBeenLastCalledWith('paused');
+ // Active prompts counts the new ones too, so it shows them all.
act(() => button('Active prompts').click());
- expect(onFilter).toHaveBeenLastCalledWith('active');
+ expect(onFilter).toHaveBeenLastCalledWith('tracked');
+ });
+
+ it('notes the new prompts the Active card counts, and filters to them', () => {
+ render({ status: 'ready', usage: summary() });
+ expect(container.textContent).not.toContain('new');
+
+ render({ status: 'ready', usage: summary() }, 3);
+ expect(values()[0]).toBe('44');
+ expect(container.textContent).toContain('3 new · 2 paused · being tracked now');
+ act(() => button('3 new').click());
+ expect(onFilter).toHaveBeenLastCalledWith('new');
});
it('shows dashes and a retry when the counts fail to load', () => {
@@ -189,12 +209,49 @@ describe('locationQuotaFromUsage', () => {
});
describe('the table status filter', () => {
- const rows = [{ isActive: true }, { isActive: true }, { isActive: false }];
+ const now = Date.parse('2026-10-17T12:00:00.000Z');
+ const old = '2026-10-01T09:00:00.000Z';
+ const rows = [
+ { isActive: true, createdAt: old },
+ { isActive: true, createdAt: old },
+ { isActive: true, createdAt: '2026-10-17T08:00:00.000Z' },
+ { isActive: false, createdAt: old },
+ ];
+
+ it('opens on tracked rows, new ones included, and counts each filter for the title', () => {
+ expect(rows.filter((r) => matchesStatusFilter(r, 'tracked', now))).toHaveLength(3);
+ expect(rows.filter((r) => matchesStatusFilter(r, 'active', now))).toHaveLength(2);
+ expect(rows.filter((r) => matchesStatusFilter(r, 'new', now))).toHaveLength(1);
+ expect(rows.filter((r) => matchesStatusFilter(r, 'paused', now))).toHaveLength(1);
+ expect(rows.filter((r) => matchesStatusFilter(r, 'all', now))).toHaveLength(4);
+ expect(countByStatus(rows, now)).toEqual({ tracked: 3, active: 2, new: 1, paused: 1, all: 4 });
+ });
+
+ it('reads a tracked prompt as New for its first 24 hours', () => {
+ const at = (createdAt: string, isActive = true) => promptStatus({ isActive, createdAt }, now);
+ expect(at('2026-10-17T11:59:00.000Z')).toBe('new');
+ expect(at('2026-10-16T12:00:01.000Z')).toBe('new');
+ expect(at('2026-10-16T12:00:00.000Z')).toBe('active');
+ expect(at(old)).toBe('active');
+ // Paused wins: a prompt paused on its first day isn't tracked, so it isn't New.
+ expect(at('2026-10-17T11:00:00.000Z', false)).toBe('paused');
+ });
- it('opens on active rows and counts each filter for the title', () => {
- expect(rows.filter((r) => matchesStatusFilter(r, 'active'))).toHaveLength(2);
- expect(rows.filter((r) => matchesStatusFilter(r, 'paused'))).toHaveLength(1);
- expect(rows.filter((r) => matchesStatusFilter(r, 'all'))).toHaveLength(3);
- expect(countByStatus(rows)).toEqual({ active: 2, paused: 1, all: 3 });
+ it('leads the default order with the new prompts, newest first', () => {
+ const row = (id: string, createdAt: string, isActive = true) => ({ id, isActive, createdAt });
+ const sorted = [
+ row('best', old),
+ row('earlier-today', '2026-10-17T08:00:00.000Z'),
+ row('paused-today', '2026-10-17T10:00:00.000Z', false),
+ row('good', old),
+ row('just-now', '2026-10-17T11:30:00.000Z'),
+ ];
+ expect(newFirst(sorted, now).map((r) => r.id)).toEqual([
+ 'just-now',
+ 'earlier-today',
+ 'best',
+ 'paused-today',
+ 'good',
+ ]);
});
});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.tsx
index 196a3cc40..c0d16a5fd 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_usage-cards.tsx
@@ -20,22 +20,68 @@ import { cn } from '@/lib/utils';
* table never waits for them.
*/
-/** Which rows the table shows; set by the This brand cards. */
-export type PromptStatusFilter = 'active' | 'paused' | 'all';
+/** How long a tracked prompt reads as New after it is added. */
+export const NEW_PROMPT_MS = 24 * 60 * 60 * 1000;
+
+/** A row's Status: paused, new (tracked and added within the last day) or active. */
+export type PromptStatus = 'active' | 'new' | 'paused';
+
+/**
+ * Which rows the table shows; set by the This brand cards or the Status
+ * filter. It opens on Tracked: every prompt being tracked, Active and New.
+ */
+export type PromptStatusFilter = 'tracked' | PromptStatus | 'all';
+
+export function promptStatus(
+ prompt: { isActive: boolean; createdAt: string },
+ now: number,
+): PromptStatus {
+ if (!prompt.isActive) return 'paused';
+ return now - Date.parse(prompt.createdAt) < NEW_PROMPT_MS ? 'new' : 'active';
+}
export function matchesStatusFilter(
- prompt: { isActive: boolean },
+ prompt: { isActive: boolean; createdAt: string },
filter: PromptStatusFilter,
+ now: number,
): boolean {
- return filter === 'all' || prompt.isActive === (filter === 'active');
+ if (filter === 'all') return true;
+ const status = promptStatus(prompt, now);
+ return filter === 'tracked' ? status !== 'paused' : status === filter;
+}
+
+/**
+ * The table's default order: prompts added within the last day lead, newest
+ * first, then the rest as sorted. New prompts have no answers yet, so a
+ * performance sort alone would sink them to the bottom.
+ */
+export function newFirst<T extends { isActive: boolean; createdAt: string }>(
+ sorted: T[],
+ now: number,
+): T[] {
+ const isNew = (p: T) => promptStatus(p, now) === 'new';
+ const added = (p: T) => Date.parse(p.createdAt);
+ return [
+ ...sorted.filter(isNew).sort((a, b) => added(b) - added(a)),
+ ...sorted.filter((p) => !isNew(p)),
+ ];
}
/** How many rows each filter shows, for the table's title. */
export function countByStatus(
- prompts: { isActive: boolean }[],
+ prompts: { isActive: boolean; createdAt: string }[],
+ now: number,
): Record<PromptStatusFilter, number> {
- const active = prompts.filter((p) => p.isActive).length;
- return { active, paused: prompts.length - active, all: prompts.length };
+ const counts: Record<PromptStatusFilter, number> = {
+ tracked: 0,
+ active: 0,
+ new: 0,
+ paused: 0,
+ all: prompts.length,
+ };
+ for (const p of prompts) counts[promptStatus(p, now)] += 1;
+ counts.tracked = counts.active + counts.new;
+ return counts;
}
/** Plan keys this bundle has labels for; any other shows the server's name. */
@@ -126,6 +172,7 @@ export function PromptUsageCards({
state,
brandName,
readOnly,
+ prompts,
filter,
onFilter,
onRetry,
@@ -134,6 +181,8 @@ export function PromptUsageCards({
brandName: string | undefined;
/** Member role: the subtitle says the table is read-only. */
readOnly: boolean;
+ /** The brand's prompts, for the New ones the Active card also counts. */
+ prompts: { isActive: boolean; createdAt: string }[];
filter: PromptStatusFilter;
onFilter: (filter: PromptStatusFilter) => void;
onRetry: () => void;
@@ -142,6 +191,7 @@ export function PromptUsageCards({
const format = useFormatter();
const now = useNow({ updateInterval: 60_000 });
const n = (value: number) => format.number(value);
+ const newCount = countByStatus(prompts, now.getTime()).new;
const usage = state.status === 'ready' ? state.usage : null;
const plan = usage?.plan;
@@ -237,13 +287,30 @@ export function PromptUsageCards({
<div className="grid auto-cols-fr grid-flow-col">
<UsageCard
label={t('activePrompts')}
- selected={filter === 'active'}
- onSelect={() => onFilter('active')}
+ selected={filter === 'tracked'}
+ onSelect={() => onFilter('tracked')}
>
{value(usage && n(usage.brand.active))}
{sub(
usage && (
<>
+ {newCount > 0 && (
+ <>
+ <button
+ type="button"
+ onClick={() => onFilter('new')}
+ title={t('showNew')}
+ aria-pressed={filter === 'new'}
+ className={cn(
+ 'relative z-10 underline-offset-2 hover:underline',
+ filter === 'new' && 'font-medium text-foreground underline',
+ )}
+ >
+ {t('new', { count: n(newCount) })}
+ </button>{' '}
+ ·{' '}
+ </>
+ )}
<button
type="button"
onClick={() => onFilter('paused')}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
index 70e114376..0e3670641 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
@@ -2,7 +2,7 @@
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
import { createPortal } from 'react-dom';
-import { useFormatter, useTranslations } from 'next-intl';
+import { useFormatter, useNow, useTranslations } from 'next-intl';
import { useSearchParams } from 'next/navigation';
import { Link, usePathname, useRouter } from '@/i18n/navigation';
import { PROMPTS_BASE, sectionFor, sectionFromPath } from '@/lib/prompts-routes';
@@ -25,7 +25,10 @@ import {
countByStatus,
locationQuotaFromUsage,
matchesStatusFilter,
+ newFirst,
+ promptStatus,
usePromptUsage,
+ type PromptStatus,
type PromptStatusFilter,
} from './_usage-cards';
import { INTENT_LABELS, INTENT_COLORS } from '@/config/intent-labels';
@@ -1303,7 +1306,7 @@ export default function PromptsPage() {
const { state: usageState, retry: retryUsage } = usePromptUsage(activeBrandId, usageVersion);
const usage = usageState.status === 'ready' ? usageState.usage : null;
const locationQuota = useMemo(() => (usage ? locationQuotaFromUsage(usage) : null), [usage]);
- const [statusFilter, setStatusFilter] = useState<PromptStatusFilter>('active');
+ const [statusFilter, setStatusFilter] = useState<PromptStatusFilter>('tracked');
const searchParams = useSearchParams();
// On /dashboard/prompts/{tracked,suggestions,topics,fan-outs,insights} the route
// names the view (PROMPT-001); ?tab= / ?view= are the older links' shape.
@@ -1997,6 +2000,7 @@ export default function PromptsPage() {
state={usageState}
brandName={activeBrand?.name}
readOnly={!canManage}
+ prompts={allPrompts}
filter={statusFilter}
onFilter={setStatusFilter}
onRetry={retryUsage}
@@ -2630,6 +2634,15 @@ function RowActionsMenu({
// ─── All Prompts Tab ──────────────────────────────────────────────────────────
+/** The Status badge: New is amber, so a prompt added today stands out. */
+const STATUS_BADGE: Record<PromptStatus, string> = {
+ active: 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400',
+ new: 'border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-400',
+ paused: 'border-muted-foreground/20 text-muted-foreground',
+};
+
+const STATUS_FILTERS: PromptStatusFilter[] = ['tracked', 'active', 'new', 'paused', 'all'];
+
const WORK_FILTER_LABELS: Record<string, string> = {
all: 'All work',
todo: 'To do',
@@ -2669,7 +2682,7 @@ function AllPromptsTab({
positionsPreset: PromptRangePreset;
/** Selected location; empty means every location. */
regionFilter: string;
- /** Which rows show, set by the usage cards above (PROMPT-012). */
+ /** Which rows show, set by the usage cards above (PROMPT-012) or the Status filter. */
statusFilter: PromptStatusFilter;
onStatusFilterChange: (filter: PromptStatusFilter) => void;
/** Opens the Add Prompt dialog; undefined when the user can't write (member role). */
@@ -2686,6 +2699,8 @@ function AllPromptsTab({
const format = useFormatter();
const tDelete = useTranslations('prompts.bulkDelete');
const tLate = useTranslations('prompts.lateFilter');
+ const tStatus = useTranslations('prompts.status');
+ const now = useNow({ updateInterval: 60_000 }).getTime();
// 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
@@ -3194,14 +3209,14 @@ function AllPromptsTab({
(p) => p.text.toLowerCase().includes(q) || (p.category ?? '').toLowerCase().includes(q),
);
}
- list = list.filter((p) => matchesStatusFilter(p, statusFilter));
+ list = list.filter((p) => matchesStatusFilter(p, statusFilter, now));
if (workFilter !== 'all') {
list = list.filter((p) =>
workFilter === 'none' ? statusOf(p) === null : statusOf(p) === workFilter,
);
}
return list;
- }, [prompts, search, statusFilter, workFilter, statusOf]);
+ }, [prompts, search, statusFilter, workFilter, statusOf, now]);
const lateCount = useMemo(
() => searched.filter((p) => positions[p.id]?.lateOrMissing).length,
@@ -3241,8 +3256,22 @@ function AllPromptsTab({
}
};
- return list.sort((a, b) => compareNullsLast(valueOf(a), valueOf(b), dir));
- }, [searched, lateOnly, latenessOrder, activeSort, dir, visibility, positions, volumeByPromptId]);
+ const sorted = list.sort((a, b) => compareNullsLast(valueOf(a), valueOf(b), dir));
+ // Until a column is picked, prompts added within the last day lead: Track
+ // on Insights opens this table to show them.
+ return isAllPromptsSortKey(rawSort) ? sorted : newFirst(sorted, now);
+ }, [
+ searched,
+ lateOnly,
+ latenessOrder,
+ rawSort,
+ activeSort,
+ dir,
+ visibility,
+ positions,
+ volumeByPromptId,
+ now,
+ ]);
// Pagination for the main prompt list. resetKey encodes every variable that
// changes the visible row set (search text, sort column, sort direction, work
@@ -3251,7 +3280,7 @@ function AllPromptsTab({
const promptsResetKey = `${search}::${statusFilter}::${workFilter}::${lateOnly}::${activeSort}::${dir}`;
// From every row, pending deletes included, so the title agrees with the
// usage cards until a delete actually lands after its Undo window.
- const statusCounts = useMemo(() => countByStatus(allRows), [allRows]);
+ const statusCounts = useMemo(() => countByStatus(allRows, now), [allRows, now]);
const promptsPager = usePagination(filtered.length, promptsResetKey);
// Rows ticked for the bulk action bar. Only rows on screen can be ticked,
@@ -3347,6 +3376,22 @@ function AllPromptsTab({
)}
</div>
<div className="flex items-center gap-2">
+ <Select
+ value={statusFilter}
+ onValueChange={(v) => onStatusFilterChange((v as PromptStatusFilter | null) ?? 'all')}
+ items={STATUS_FILTERS.map((value) => ({ value, label: tStatus(value) }))}
+ >
+ <SelectTrigger className="h-8 w-32 text-xs" aria-label={tStatus('label')}>
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {STATUS_FILTERS.map((value) => (
+ <SelectItem key={value} value={value}>
+ {tStatus(value)}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
<Select
value={workFilter}
onValueChange={(v) => setWorkFilter((v as typeof workFilter) ?? 'all')}
@@ -3523,6 +3568,7 @@ function AllPromptsTab({
{pageRows.map((p) => {
const vol = volumeByPromptId.get(p.id);
const vis = visibility[p.id];
+ const status = promptStatus(p, now);
return (
<TableRow key={p.id} className="hover:bg-muted/50">
<TableCell className="pl-6 font-medium text-sm max-w-[320px]">
@@ -3565,14 +3611,10 @@ function AllPromptsTab({
<TableCell className="text-center">
<Badge
variant="outline"
- className={cn(
- 'text-xs',
- p.isActive
- ? 'border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
- : 'border-muted-foreground/20 text-muted-foreground',
- )}
+ className={cn('text-xs', STATUS_BADGE[status])}
+ title={status === 'new' ? tStatus('newHint') : undefined}
>
- {p.isActive ? 'Active' : 'Paused'}
+ {tStatus(status)}
</Badge>
</TableCell>
<TableCell className="text-center">
@@ -3730,10 +3772,10 @@ function AllPromptsTab({
No prompts match your search.
</div>
) : (
- // The table opens on Active: a brand whose prompts are all paused
+ // The table opens on Tracked: a brand whose prompts are all paused
// must not look empty with no way back.
<div className="py-10 text-center text-sm text-muted-foreground">
- {tUsage(statusFilter === 'active' ? 'table.noneActive' : 'table.nonePaused')}{' '}
+ {tUsage(`table.none.${statusFilter}`)}{' '}
<button
type="button"
onClick={() => onStatusFilterChange('all')}
diff --git a/web/src/lib/pending-tab.test.ts b/web/src/lib/pending-tab.test.ts
new file mode 100644
index 000000000..d35a9aee5
--- /dev/null
+++ b/web/src/lib/pending-tab.test.ts
@@ -0,0 +1,59 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { openPendingTab } from './pending-tab';
+
+function fakeTab() {
+ const body = document.implementation.createHTMLDocument('').body;
+ return {
+ closed: false,
+ document: { title: '', body },
+ location: { replace: vi.fn() },
+ close: vi.fn(function (this: { closed: boolean }) {
+ this.closed = true;
+ }),
+ };
+}
+
+afterEach(() => vi.restoreAllMocks());
+
+describe('openPendingTab', () => {
+ it('opens a tab at once, says what is happening, then moves it to the page', () => {
+ const tab = fakeTab();
+ const open = vi.spyOn(window, 'open').mockReturnValue(tab as unknown as Window);
+
+ const pending = openPendingTab('Adding prompts…');
+ expect(open).toHaveBeenCalledWith('', '_blank');
+ expect(pending.opened).toBe(true);
+ expect(tab.document.title).toBe('Adding prompts…');
+ expect(tab.document.body.textContent).toBe('Adding prompts…');
+
+ pending.go('/dashboard/prompts/tracked');
+ expect(tab.location.replace).toHaveBeenCalledWith(
+ `${window.location.origin}/dashboard/prompts/tracked`,
+ );
+ });
+
+ it('closes the tab when there is nothing to show', () => {
+ const tab = fakeTab();
+ vi.spyOn(window, 'open').mockReturnValue(tab as unknown as Window);
+
+ const pending = openPendingTab('Adding prompts…');
+ pending.close();
+ expect(tab.close).toHaveBeenCalledTimes(1);
+ // A tab the user already closed is left alone.
+ pending.go('/dashboard/prompts/tracked');
+ pending.close();
+ expect(tab.location.replace).not.toHaveBeenCalled();
+ expect(tab.close).toHaveBeenCalledTimes(1);
+ });
+
+ it('says so when the browser blocks the tab', () => {
+ vi.spyOn(window, 'open').mockReturnValue(null);
+
+ const pending = openPendingTab('Adding prompts…');
+ expect(pending.opened).toBe(false);
+ expect(() => {
+ pending.go('/dashboard/prompts/tracked');
+ pending.close();
+ }).not.toThrow();
+ });
+});
diff --git a/web/src/lib/pending-tab.ts b/web/src/lib/pending-tab.ts
new file mode 100644
index 000000000..292e5796c
--- /dev/null
+++ b/web/src/lib/pending-tab.ts
@@ -0,0 +1,37 @@
+/**
+ * A browser tab opened by a click, for a page that is ready only once the
+ * click's work is done. A tab opened after an `await` is blocked as a
+ * pop-up, so it opens at once with a line saying what is happening, then
+ * moves to the page, or closes when there is nothing to show.
+ */
+export interface PendingTab {
+ /** False when the browser blocked the tab. */
+ readonly opened: boolean;
+ go(href: string): void;
+ close(): void;
+}
+
+export function openPendingTab(message: string): PendingTab {
+ const tab = window.open('', '_blank');
+ if (tab) {
+ try {
+ tab.document.title = message;
+ tab.document.body.style.font = '14px system-ui, sans-serif';
+ tab.document.body.style.margin = '24px';
+ tab.document.body.textContent = message;
+ } catch {
+ // A tab we can't write to still moves on to the page.
+ }
+ }
+ const live = () => tab !== null && !tab.closed;
+ return {
+ opened: tab !== null,
+ // Absolute, as the blank tab has no address of its own to resolve against.
+ go: (href) => {
+ if (live()) tab!.location.replace(new URL(href, window.location.origin).toString());
+ },
+ close: () => {
+ if (live()) tab!.close();
+ },
+ };
+}