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(action-center): show the opportunity behind an action sent from Content (#944)

Gökhan Geyikbbb47d6dde86
diff --git a/server/src/lib/action-center/from-opportunity.js b/server/src/lib/action-center/from-opportunity.js
index 0ad21716f..80143d855 100644
--- a/server/src/lib/action-center/from-opportunity.js
+++ b/server/src/lib/action-center/from-opportunity.js
@@ -82,6 +82,16 @@ export function opportunityAssets(opportunity) {
const ACTIVE = ['new', 'in_progress', 'on_hold'];
+/**
+ * A task's status when the action opens. The brief task starts completed when
+ * the opportunity already has a brief: the work is done, and the brief is
+ * shown on the action. Every row states its status: a bulk insert sends the
+ * union of the rows' keys, so a row without one would send null.
+ */
+export function initialTaskStatus(taskKey, opportunity) {
+ return taskKey === 'create_content_brief' && opportunity.brief ? 'completed' : 'todo';
+}
+
/**
* Creates the action, or returns the open one if this opportunity or asset
* was already sent. Records the action on the opportunity and marks it sent.
@@ -164,6 +174,7 @@ export async function sendToActionCenter(opportunity, { assetKey = null, userId
permission: item.permission,
depends_on: item.dependsOn,
title_params: item.titleParams,
+ status: initialTaskStatus(item.taskKey, opportunity),
})),
);
if (tasksErr) throw new Error(tasksErr.message);
diff --git a/server/src/lib/action-center/from-opportunity.test.js b/server/src/lib/action-center/from-opportunity.test.js
index f05f70cc6..c8efff4cc 100644
--- a/server/src/lib/action-center/from-opportunity.test.js
+++ b/server/src/lib/action-center/from-opportunity.test.js
@@ -2,7 +2,8 @@ import { describe, expect, it, vi } from 'vitest';
vi.mock('../../config/supabase.js', () => ({ default: {} }));
-const { assetTasks, combinedTasks, opportunityAssets } = await import('./from-opportunity.js');
+const { assetTasks, combinedTasks, initialTaskStatus, opportunityAssets } =
+ await import('./from-opportunity.js');
const { getTask } = await import('./tasks/registry.js');
const owned = (decision) => ({ type: 'blog_post', channel: 'owned', decision });
@@ -66,6 +67,14 @@ describe('combinedTasks', () => {
});
});
+describe('initialTaskStatus', () => {
+ it('starts the brief task completed when the opportunity has a brief', () => {
+ expect(initialTaskStatus('create_content_brief', { brief: { outline: [] } })).toBe('completed');
+ expect(initialTaskStatus('create_content_brief', { brief: null })).toBe('todo');
+ expect(initialTaskStatus('create_content_draft', { brief: { outline: [] } })).toBe('todo');
+ });
+});
+
describe('opportunityAssets', () => {
it('gives an opportunity from before assets one, from its own fields', () => {
expect(
diff --git a/web/messages/en.json b/web/messages/en.json
index 69b3e3c35..f6976f81e 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -713,7 +713,20 @@
"skipReason": "Why was this skipped?",
"skipReasonPlaceholder": "e.g. handled elsewhere, no longer relevant",
"skipConfirm": "Skip task",
- "skipCancel": "Cancel"
+ "skipCancel": "Cancel",
+ "noSignalsOpportunity": "This action was sent from Content Optimization. Its evidence is the opportunity on the Overview tab, not detection signals.",
+ "opportunity": {
+ "title": "Content opportunity",
+ "open": "Open opportunity",
+ "brief": "Brief & outline",
+ "words": "~{count} words",
+ "noBrief": "No brief yet. <link>Generate one on the opportunity.</link>",
+ "prompts": "{count, plural, one {# prompt to answer} other {# prompts to answer}}",
+ "queries": "{count, plural, one {# search AI engines ran} other {# searches AI engines ran}}",
+ "allQueries": "Show all {count}",
+ "fewerQueries": "Show fewer",
+ "unavailable": "The opportunity this action was sent from is no longer available."
+ }
}
},
"actionTexts": {
diff --git a/web/src/components/action-center/action-drawer.tsx b/web/src/components/action-center/action-drawer.tsx
index 89e82bc6b..d5e8e0b57 100644
--- a/web/src/components/action-center/action-drawer.tsx
+++ b/web/src/components/action-center/action-drawer.tsx
@@ -58,6 +58,7 @@ import { signalTexts } from '@/lib/signals/display';
import { isKpiKey } from '@/lib/kpis/registry';
import { ImpactDots, isSuperseded, SignalStatusBadge } from './signal-table';
import { ActionIcon } from './action-table';
+import { OpportunityContext } from './opportunity-context';
import { cn } from '@/lib/utils';
type DrawerTab = 'overview' | 'tasks' | 'signals' | 'history';
@@ -126,6 +127,15 @@ export function ActionDrawer({
const texts = actionTexts(action, tTexts);
const tags = actionContextTags(action, t);
const relatedKpis: string[] = action.kpiKeys.filter(isKpiKey);
+ // Sent by a person from Content Optimization (#857): its evidence is the
+ // opportunity, not detection signals.
+ const opportunityId =
+ action.kind === 'content_opportunity' && typeof action.payload?.opportunityId === 'string'
+ ? action.payload.opportunityId
+ : null;
+ const opportunityPages = Array.isArray(action.payload?.pages)
+ ? (action.payload.pages as unknown[]).filter((u): u is string => typeof u === 'string')
+ : [];
const mutate = async (fn: () => Promise<void>) => {
setIsBusy(true);
@@ -237,30 +247,37 @@ export function ActionDrawer({
)}
</section>
<Separator />
- <section>
- <p className="text-xs font-medium text-muted-foreground">
- {t('drawer.primarySignals')}
- </p>
- <div className="mt-2 space-y-2">
- {detail.signals.slice(0, 3).map((signal) => {
- const st = signalTexts(signal, tSignalTexts);
- return (
- <button
- key={signal.id}
- type="button"
- onClick={() => openSignal(signal.id)}
- className="block w-full rounded-md border px-3 py-2 text-left transition-colors hover:bg-muted/40"
- >
- <div className="flex items-center justify-between gap-2">
- <p className="truncate text-xs font-medium">{st.title}</p>
- <ImpactDots impact={signal.impact} />
- </div>
- <p className="truncate text-xs text-muted-foreground">{st.description}</p>
- </button>
- );
- })}
- </div>
- </section>
+ {opportunityId ? (
+ <OpportunityContext
+ opportunityId={opportunityId}
+ pageUrls={action.payload?.assetKey ? opportunityPages : undefined}
+ />
+ ) : (
+ <section>
+ <p className="text-xs font-medium text-muted-foreground">
+ {t('drawer.primarySignals')}
+ </p>
+ <div className="mt-2 space-y-2">
+ {detail.signals.slice(0, 3).map((signal) => {
+ const st = signalTexts(signal, tSignalTexts);
+ return (
+ <button
+ key={signal.id}
+ type="button"
+ onClick={() => openSignal(signal.id)}
+ className="block w-full rounded-md border px-3 py-2 text-left transition-colors hover:bg-muted/40"
+ >
+ <div className="flex items-center justify-between gap-2">
+ <p className="truncate text-xs font-medium">{st.title}</p>
+ <ImpactDots impact={signal.impact} />
+ </div>
+ <p className="truncate text-xs text-muted-foreground">{st.description}</p>
+ </button>
+ );
+ })}
+ </div>
+ </section>
+ )}
</>
) : tab === 'tasks' ? (
<section>
@@ -304,7 +321,9 @@ export function ActionDrawer({
) : tab === 'signals' ? (
<section className="space-y-2">
{detail.signals.length === 0 && (
- <p className="text-xs text-muted-foreground">{t('drawer.noSignals')}</p>
+ <p className="text-xs text-muted-foreground">
+ {opportunityId ? t('drawer.noSignalsOpportunity') : t('drawer.noSignals')}
+ </p>
)}
{detail.signals.map((signal) => {
const st = signalTexts(signal, tSignalTexts);
diff --git a/web/src/components/action-center/opportunity-context.tsx b/web/src/components/action-center/opportunity-context.tsx
new file mode 100644
index 000000000..f2f82f322
--- /dev/null
+++ b/web/src/components/action-center/opportunity-context.tsx
@@ -0,0 +1,208 @@
+'use client';
+
+import { useEffect, useState } from 'react';
+import { useTranslations } from 'next-intl';
+import { ExternalLink, Search } from 'lucide-react';
+import { Badge } from '@/components/ui/badge';
+import { Separator } from '@/components/ui/separator';
+import { Skeleton } from '@/components/ui/skeleton';
+import { Link } from '@/i18n/navigation';
+import { getOpportunity, getOpportunityBasket } from '@/lib/actions/content';
+import type { ContentOpportunity, OpportunityBasket } from '@/types';
+
+/** Fan-out queries listed before the rest fold away. */
+const QUERIES_SHOWN = 15;
+
+/**
+ * What an action sent from Content Optimization is about (#857): the
+ * opportunity's decision and pages, its prompts and fan-out queries, and its
+ * brief. Read live from the opportunity rather than copied onto the action,
+ * so a brief generated after sending still shows here.
+ */
+export function OpportunityContext({
+ opportunityId,
+ pageUrls,
+}: {
+ opportunityId: string;
+ /** The pages of the asset that was sent; all of the opportunity's when it was sent whole. */
+ pageUrls?: string[];
+}) {
+ const t = useTranslations('actionCenter.actionsPage.drawer.opportunity');
+ const tContent = useTranslations('content');
+ const [opportunity, setOpportunity] = useState<ContentOpportunity | null>(null);
+ const [basket, setBasket] = useState<OpportunityBasket | null>(null);
+ const [failed, setFailed] = useState(false);
+ const [showAllQueries, setShowAllQueries] = useState(false);
+
+ useEffect(() => {
+ let cancelled = false;
+ Promise.all([getOpportunity(opportunityId), getOpportunityBasket(opportunityId)])
+ .then(([opp, b]) => {
+ if (cancelled) return;
+ setOpportunity(opp);
+ setBasket(b);
+ })
+ .catch(() => !cancelled && setFailed(true));
+ return () => {
+ cancelled = true;
+ };
+ }, [opportunityId]);
+
+ if (failed) {
+ return <p className="text-xs text-muted-foreground">{t('unavailable')}</p>;
+ }
+ if (!opportunity || !basket) {
+ return (
+ <div className="space-y-2">
+ <Skeleton className="h-4 w-1/2" />
+ <Skeleton className="h-16 w-full" />
+ </div>
+ );
+ }
+
+ const sd = opportunity.sourceData;
+ const allPages = [...(sd.targetPages ?? []), ...(sd.assets ?? []).flatMap((a) => a.pages)].filter(
+ (p, i, list) => list.findIndex((q) => q.url === p.url) === i,
+ );
+ const pages = pageUrls?.length ? allPages.filter((p) => pageUrls.includes(p.url)) : allPages;
+ const prompts = basket.clusters.flatMap((c) => c.prompts);
+ const queries = basket.queries.filter((q) => q.included);
+ const brief = opportunity.brief;
+
+ return (
+ <div className="space-y-5">
+ <section>
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-xs font-medium text-muted-foreground">{t('title')}</p>
+ <Link
+ href={`/dashboard/content/${opportunity.id}`}
+ className="text-xs text-primary hover:underline"
+ >
+ {t('open')}
+ </Link>
+ </div>
+ <p className="mt-1 font-medium">{opportunity.title}</p>
+ {opportunity.decision && (
+ <p className="mt-1 text-xs text-muted-foreground">
+ <Badge variant="secondary" className="mr-1.5 text-[10px]">
+ {tContent(`decision.${opportunity.decision}`)}
+ </Badge>
+ {tContent(`decisionHint.${opportunity.decision}`)}
+ </p>
+ )}
+ {pages.length > 0 && (
+ <div className="mt-2 space-y-1">
+ {pages.map((p) => (
+ <a
+ key={p.url}
+ href={p.url}
+ target="_blank"
+ rel="noreferrer"
+ className="flex items-center gap-1.5 text-xs text-muted-foreground hover:underline"
+ >
+ <ExternalLink className="h-3 w-3 shrink-0" />
+ <span className="truncate">{p.title || p.url}</span>
+ </a>
+ ))}
+ </div>
+ )}
+ </section>
+
+ <Separator />
+ <section>
+ <p className="text-xs font-medium text-muted-foreground">{t('brief')}</p>
+ {brief ? (
+ <div className="mt-2 space-y-2">
+ <p className="font-medium">{brief.suggestedTitle}</p>
+ <div className="flex flex-wrap gap-1">
+ <Badge variant="outline" className="text-[10px]">
+ {brief.contentType.replace(/-/g, ' ')}
+ </Badge>
+ <Badge variant="outline" className="text-[10px] tabular-nums">
+ {t('words', { count: brief.targetWordCount })}
+ </Badge>
+ </div>
+ <ol className="space-y-1.5 text-xs">
+ {brief.outline.map((section, i) => (
+ <li key={i}>
+ <p className="font-medium">
+ {i + 1}. {section.heading}
+ </p>
+ {section.keyPoints.length > 0 && (
+ <ul className="ml-4 list-disc text-muted-foreground">
+ {section.keyPoints.map((point, j) => (
+ <li key={j}>{point}</li>
+ ))}
+ </ul>
+ )}
+ </li>
+ ))}
+ </ol>
+ </div>
+ ) : (
+ <p className="mt-1 text-xs text-muted-foreground">
+ {t.rich('noBrief', {
+ link: (chunks) => (
+ <Link
+ href={`/dashboard/content/${opportunity.id}`}
+ className="text-primary hover:underline"
+ >
+ {chunks}
+ </Link>
+ ),
+ })}
+ </p>
+ )}
+ </section>
+
+ <Separator />
+ <section>
+ <p className="text-xs font-medium text-muted-foreground">
+ {t('prompts', { count: prompts.length })}
+ </p>
+ <ul className="mt-2 space-y-1 text-xs">
+ {prompts.map((p) => (
+ <li key={p.id} className="flex gap-2">
+ <span className="text-muted-foreground">•</span>
+ <span>{p.text}</span>
+ </li>
+ ))}
+ </ul>
+ </section>
+
+ {queries.length > 0 && (
+ <>
+ <Separator />
+ <section>
+ <p className="text-xs font-medium text-muted-foreground">
+ {t('queries', { count: queries.length })}
+ </p>
+ <div className="mt-2 flex flex-wrap gap-1">
+ {(showAllQueries ? queries : queries.slice(0, QUERIES_SHOWN)).map((q) => (
+ <Badge
+ key={q.query}
+ variant="outline"
+ className="gap-1 text-[10px]"
+ title={q.reason}
+ >
+ <Search className="h-2.5 w-2.5 shrink-0" />
+ {q.query}
+ <span className="tabular-nums opacity-60">×{q.timesSearched}</span>
+ </Badge>
+ ))}
+ </div>
+ {queries.length > QUERIES_SHOWN && (
+ <button
+ type="button"
+ onClick={() => setShowAllQueries((v) => !v)}
+ className="mt-1.5 text-xs text-primary hover:underline"
+ >
+ {showAllQueries ? t('fewerQueries') : t('allQueries', { count: queries.length })}
+ </button>
+ )}
+ </section>
+ </>
+ )}
+ </div>
+ );
+}
diff --git a/web/src/lib/action-center/display.ts b/web/src/lib/action-center/display.ts
index 9ba4136ab..249b53c2c 100644
--- a/web/src/lib/action-center/display.ts
+++ b/web/src/lib/action-center/display.ts
@@ -108,7 +108,10 @@ export function actionGoal(kind: string, t: Translator): string {
/** Compact evidence chips under the title: signal count plus the kind's own
* count (pages, prompts, competitors). */
export function actionContextTags(action: ActionItem, t: Translator): string[] {
- const tags = [t('tags.signals', { count: action.signalCount })];
+ // An action sent from a content opportunity has no detection signals by
+ // design; "0 signals" would read as missing evidence.
+ const tags =
+ action.kind === 'content_opportunity' ? [] : [t('tags.signals', { count: action.signalCount })];
const count = num(action.payload ?? {}, 'targetCount');
const entity = str(action.payload ?? {}, 'targetEntity');
if (count > 0 && entity) tags.push(t(`tags.${entity}`, { count }));