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
fix(prompts): put the Topics buttons where Tracked Prompts has its own (#1149)
Cihan8706726af742
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.test.tsxnew file mode 100644index 000000000..52b95bb8e--- /dev/null+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.test.tsx@@ -0,0 +1,83 @@+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { NextIntlClientProvider } from 'next-intl';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import messages from '../../../../../../messages/en.json';++/**+ * The Topics tab's buttons sit where the Prompts tab's do: beside the tabs,+ * in the same order and size — Add Topic, Export CSV, Manage topics.+ */++let canManage = true;+vi.mock('@/hooks/use-user-role', () => ({ useUserRole: () => ({ canManage }) }));+vi.mock('@/stores/use-brand-store', () => ({+ useBrandStore: (select: (state: unknown) => unknown) =>+ select({ activeBrandId: 'b1', brands: [{ id: 'b1', slug: 'acme' }] }),+}));+vi.mock('@/i18n/navigation', () => ({+ Link: ({ href, ...props }: { href: string }) => <a href={href} {...props} />,+}));+vi.mock('@/lib/actions/topic', () => ({+ getTopicsOverview: vi.fn(async () => ({ topics: [], unassignedPromptCount: 0 })),+ createTopic: vi.fn(),+}));+vi.mock('./_topic-suggestions-card', () => ({ TopicSuggestionsCard: () => null }));++const { TopicsTab } = await import('./_topics-tab');++(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =+ true;++let container: HTMLDivElement;+let slot: HTMLDivElement;+let root: Root;++beforeEach(() => {+ canManage = true;+ container = document.createElement('div');+ slot = document.createElement('div');+ document.body.append(slot, container);+ root = createRoot(container);+});++afterEach(() => {+ act(() => root.unmount());+ container.remove();+ slot.remove();+});++async function render() {+ await act(async () => {+ root.render(+ <NextIntlClientProvider locale="en" messages={messages} timeZone="UTC">+ <TopicsTab+ actionsSlot={slot}+ range={{ from: '2026-10-11T00:00:00.000Z', days: 7 }}+ rangePreset="7d"+ customFrom=""+ customTo=""+ />+ </NextIntlClientProvider>,+ );+ });+}++const labels = (el: Element) =>+ [...el.querySelectorAll('a, button')].map((b) => b.textContent?.trim());++describe('TopicsTab buttons', () => {+ it('go beside the tabs as Add Topic, Export CSV, Manage topics', async () => {+ await render();+ expect(labels(slot)).toEqual(['Add Topic', 'Export CSV', 'Manage topics']);+ expect(slot.querySelector('a')!.getAttribute('href')).toBe('/dashboard/brands/b1/topics');+ // Not a second copy in the tab's own content.+ expect(labels(container)).not.toContain('Manage topics');+ });++ it("leave Add Topic out for members who can't manage", async () => {+ canManage = false;+ await render();+ expect(labels(slot)).toEqual(['Export CSV', 'Manage topics']);+ });+});diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsxindex 0ce9cf894..29ca02da0 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_topics-tab.tsx@@ -1,6 +1,7 @@'use client';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';+import { createPortal } from 'react-dom';import { useTranslations } from 'next-intl';import { Link } from '@/i18n/navigation';import { useBrandStore } from '@/stores/use-brand-store';@@ -214,12 +215,19 @@ function SortableHead({* shown, as its own chunk, so it costs the other tabs nothing.*/export function TopicsTab({+ actionsSlot,range,rangePreset,customFrom,customTo,onLoaded,}: {+ /**+ * The Prompts page's place for a tab's buttons, beside the tabs: Add Topic,+ * Export CSV and Manage topics go there in the order and size the Prompts+ * tab's Add prompt, Export CSV and Manage prompts have. Null until mounted.+ */+ actionsSlot: HTMLElement | null;/** The page's range resolved; null for a custom range with no dates yet. */range: PromptRange | null;rangePreset: PromptRangePreset;@@ -413,82 +421,81 @@ export function TopicsTab({return (<div className="space-y-6">- {/* Actions: the tab sits under the Prompts header, which names the area. */}- <div className="flex items-center justify-end gap-4 flex-wrap">- <div className="flex items-center gap-2">- <span title={!canExport ? t('exportHint') : undefined}>- <Button- type="button"- variant="outline"- size="sm"- className="gap-2"- onClick={handleExportCsv}- disabled={!canExport}- >- <Download className="h-4 w-4" />- {common('exportCsv')}- </Button>- </span>- <Link- href={`/dashboard/brands/${activeBrandId}/topics`}- className={buttonVariants({ variant: 'outline', size: 'sm' })}- >- <Settings2 className="h-4 w-4" />- {t('manageTopics')}- </Link>- {canManage && (- <>- <Button size="sm" onClick={() => setOpen(true)}>- <Plus className="mr-2 h-4 w-4" />+ {actionsSlot &&+ createPortal(+ <>+ {canManage && (+ <Button type="button" size="sm" className="gap-2" onClick={() => setOpen(true)}>+ <Plus className="h-4 w-4" />{t('addTopic')}</Button>- <Dialog- open={open}- onOpenChange={(value) => {- setOpen(value);- if (!value) {- setNewName('');- }- }}+ )}+ <span title={!canExport ? t('exportHint') : undefined}>+ <Button+ type="button"+ variant="outline"+ size="sm"+ className="gap-2"+ onClick={handleExportCsv}+ disabled={!canExport}>- <DialogContent className="sm:max-w-sm">- <DialogHeader>- <DialogTitle>{t('addTopic')}</DialogTitle>- <DialogDescription>{t('addTopicDescription')}</DialogDescription>- </DialogHeader>- <div className="flex gap-2">- <Input- placeholder="e.g. Industry, Comparison..."- value={newName}- onChange={(e) => setNewName(e.target.value)}- onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAddTopic()}- className="flex-1"- />- </div>- <DialogFooter>- <DialogClose render={<Button variant="outline" />}>- {common('cancel')}- </DialogClose>- <Button- variant="default"- onClick={handleAddTopic}- disabled={isAdding || !newName.trim()}- className="gap-1.5 shrink-0"- >- {isAdding ? (- <Loader2 className="h-4 w-4 animate-spin" />- ) : (- <Plus className="h-4 w-4" />- )}- {t('addTopic')}- </Button>- </DialogFooter>- </DialogContent>- </Dialog>- </>- )}- </div>- </div>+ <Download className="h-4 w-4" />+ {common('exportCsv')}+ </Button>+ </span>+ <Link+ href={`/dashboard/brands/${activeBrandId}/topics`}+ className={buttonVariants({ variant: 'outline', size: 'sm' })}+ >+ <Settings2 className="h-4 w-4" />+ {t('manageTopics')}+ </Link>+ </>,+ actionsSlot,+ )}+ {canManage && (+ <Dialog+ open={open}+ onOpenChange={(value) => {+ setOpen(value);+ if (!value) {+ setNewName('');+ }+ }}+ >+ <DialogContent className="sm:max-w-sm">+ <DialogHeader>+ <DialogTitle>{t('addTopic')}</DialogTitle>+ <DialogDescription>{t('addTopicDescription')}</DialogDescription>+ </DialogHeader>+ <div className="flex gap-2">+ <Input+ placeholder="e.g. Industry, Comparison..."+ value={newName}+ onChange={(e) => setNewName(e.target.value)}+ onKeyDown={(e) => e.key === 'Enter' && newName.trim() && handleAddTopic()}+ className="flex-1"+ />+ </div>+ <DialogFooter>+ <DialogClose render={<Button variant="outline" />}>{common('cancel')}</DialogClose>+ <Button+ variant="default"+ onClick={handleAddTopic}+ disabled={isAdding || !newName.trim()}+ className="gap-1.5 shrink-0"+ >+ {isAdding ? (+ <Loader2 className="h-4 w-4 animate-spin" />+ ) : (+ <Plus className="h-4 w-4" />+ )}+ {t('addTopic')}+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )}{/* KPIs */}{loading ? (diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsxindex de9fac7fa..a8af412c0 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx@@ -1274,6 +1274,8 @@ export default function PromptsPage() {const [refreshing, setRefreshing] = useState(false);const [quota, setQuota] = useState<VolumeQuota | null>(null);const [addPromptOpen, setAddPromptOpen] = useState(false);+ // Where a tab's own buttons go: beside the tabs, as the Prompts tab's do.+ const [headerActions, setHeaderActions] = useState<HTMLDivElement | null>(null);const [editingPrompt, setEditingPrompt] = useState<Prompt | null>(null);const { canManage } = useUserRole();@@ -1844,6 +1846,9 @@ export default function PromptsPage() {<TabsTrigger value="insights">Insights</TabsTrigger></TabsList><div className="flex items-center gap-2">+ {/* A tab's own buttons, portalled in (Topics). `contents` keeps+ them in this row's flex and gap. */}+ <div ref={setHeaderActions} className="contents" />{tab === 'all' && canManage && (<Buttontype="button"@@ -1871,13 +1876,16 @@ export default function PromptsPage() {</span>)}- <Link- href={`/dashboard/brands/${activeBrandId}/prompts`}- className={buttonVariants({ variant: 'outline', size: 'sm' })}- >- <Settings2 className="h-4 w-4" />- Manage prompts- </Link>+ {/* Topics has Manage topics in its place. */}+ {tab !== 'topics' && (+ <Link+ href={`/dashboard/brands/${activeBrandId}/prompts`}+ className={buttonVariants({ variant: 'outline', size: 'sm' })}+ >+ <Settings2 className="h-4 w-4" />+ Manage prompts+ </Link>+ )}</div></div>@@ -2051,6 +2059,7 @@ export default function PromptsPage() {<TabsContent value="topics" className="mt-4">{tab === 'topics' && (<TopicsTab+ actionsSlot={headerActions}range={range}rangePreset={rangePreset}customFrom={customFrom}