Add search and RAG workspace flows
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import Link from 'next/link';
|
||||
import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { format } from 'date-fns';
|
||||
import {
|
||||
CartesianGrid,
|
||||
@@ -169,10 +169,12 @@ function AnalysisPageContent() {
|
||||
const [journalLoading, setJournalLoading] = useState(true);
|
||||
const [journalForm, setJournalForm] = useState<JournalFormState>(EMPTY_JOURNAL_FORM);
|
||||
const [editingJournalId, setEditingJournalId] = useState<number | null>(null);
|
||||
const [highlightedJournalId, setHighlightedJournalId] = useState<number | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [financialPeriodFilter, setFinancialPeriodFilter] = useState<FinancialPeriodFilter>('quarterlyAndFiscalYearEnd');
|
||||
const [financialValueScale, setFinancialValueScale] = useState<NumberScaleUnit>('millions');
|
||||
const journalEntryRefs = useRef(new Map<number, HTMLElement | null>());
|
||||
|
||||
useEffect(() => {
|
||||
const normalized = normalizeTickerInput(searchParams.get('ticker'));
|
||||
@@ -182,6 +184,8 @@ function AnalysisPageContent() {
|
||||
|
||||
setTickerInput(normalized);
|
||||
setTicker(normalized);
|
||||
const journalId = Number(searchParams.get('journalId'));
|
||||
setHighlightedJournalId(Number.isInteger(journalId) && journalId > 0 ? journalId : null);
|
||||
}, [searchParams]);
|
||||
|
||||
const loadAnalysis = useCallback(async (symbol: string) => {
|
||||
@@ -231,6 +235,26 @@ function AnalysisPageContent() {
|
||||
}
|
||||
}, [isPending, isAuthenticated, loadAnalysis, loadJournal, ticker]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!highlightedJournalId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const node = journalEntryRefs.current.get(highlightedJournalId);
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
setHighlightedJournalId((current) => (current === highlightedJournalId ? null : current));
|
||||
}, 2200);
|
||||
|
||||
return () => {
|
||||
window.clearTimeout(timeoutId);
|
||||
};
|
||||
}, [highlightedJournalId, journalEntries]);
|
||||
|
||||
const priceSeries = useMemo(() => {
|
||||
return (analysis?.priceHistory ?? []).map((point) => ({
|
||||
...point,
|
||||
@@ -349,26 +373,35 @@ function AnalysisPageContent() {
|
||||
subtitle="Research a single ticker across pricing, 10-K/10-Q financials, qualitative filings, and generated AI reports."
|
||||
activeTicker={analysis?.company.ticker ?? ticker}
|
||||
actions={(
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
const normalizedTicker = activeTicker.trim().toUpperCase();
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.companyAnalysis(normalizedTicker) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.researchJournal(normalizedTicker) });
|
||||
void Promise.all([
|
||||
loadAnalysis(normalizedTicker),
|
||||
loadJournal(normalizedTicker)
|
||||
]);
|
||||
}}
|
||||
>
|
||||
<RefreshCcw className="size-4" />
|
||||
Refresh
|
||||
</Button>
|
||||
<>
|
||||
<Link
|
||||
href={`/search?ticker=${encodeURIComponent(activeTicker.trim().toUpperCase())}`}
|
||||
className="inline-flex items-center justify-center gap-2 rounded-lg border border-[color:var(--line-weak)] px-3 py-2 text-sm text-[color:var(--accent)] transition hover:border-[color:var(--line-strong)] hover:text-[color:var(--accent-strong)]"
|
||||
>
|
||||
<Search className="size-4" />
|
||||
Ask with RAG
|
||||
</Link>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
const normalizedTicker = activeTicker.trim().toUpperCase();
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.companyAnalysis(normalizedTicker) });
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.researchJournal(normalizedTicker) });
|
||||
void Promise.all([
|
||||
loadAnalysis(normalizedTicker),
|
||||
loadJournal(normalizedTicker)
|
||||
]);
|
||||
}}
|
||||
>
|
||||
<RefreshCcw className="size-4" />
|
||||
Refresh
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
>
|
||||
<Panel title="Search Company" subtitle="Enter a ticker symbol to load the latest analysis view.">
|
||||
<form
|
||||
className="flex flex-wrap items-center gap-3"
|
||||
className="flex flex-col items-stretch gap-3 sm:flex-row sm:flex-wrap sm:items-center"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
const normalized = tickerInput.trim().toUpperCase();
|
||||
@@ -383,9 +416,9 @@ function AnalysisPageContent() {
|
||||
aria-label="Analysis ticker"
|
||||
onChange={(event) => setTickerInput(event.target.value.toUpperCase())}
|
||||
placeholder="Ticker (AAPL)"
|
||||
className="max-w-xs"
|
||||
className="w-full sm:max-w-xs"
|
||||
/>
|
||||
<Button type="submit">
|
||||
<Button type="submit" className="w-full sm:w-auto">
|
||||
<Search className="size-4" />
|
||||
Analyze
|
||||
</Button>
|
||||
@@ -462,7 +495,7 @@ function AnalysisPageContent() {
|
||||
<Panel title="Coverage Workflow" subtitle="Coverage metadata shared with the Coverage page.">
|
||||
{analysis?.coverage ? (
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] px-3 py-2">
|
||||
<p className="text-xs uppercase tracking-[0.12em] text-[color:var(--terminal-muted)]">Status</p>
|
||||
<p className="mt-1 text-[color:var(--terminal-bright)]">{analysis.coverage.status}</p>
|
||||
@@ -560,7 +593,7 @@ function AnalysisPageContent() {
|
||||
) : priceSeries.length === 0 ? (
|
||||
<p className="text-sm text-[color:var(--terminal-muted)]">No price history available.</p>
|
||||
) : (
|
||||
<div className="h-[320px]">
|
||||
<div className="h-[260px] sm:h-[320px]">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={priceSeries}>
|
||||
<CartesianGrid strokeDasharray="2 2" stroke={CHART_GRID} />
|
||||
@@ -638,35 +671,67 @@ function AnalysisPageContent() {
|
||||
) : filteredFinancialSeries.length === 0 ? (
|
||||
<p className="text-sm text-[color:var(--terminal-muted)]">No financial rows match the selected period filter.</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="data-table min-w-[820px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filed</th>
|
||||
<th>Period</th>
|
||||
<th>Form</th>
|
||||
<th>Revenue</th>
|
||||
<th>Net Income</th>
|
||||
<th>Assets</th>
|
||||
<th>Net Margin</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filteredFinancialSeries.map((point, index) => (
|
||||
<tr key={`${point.filingDate}-${point.filingType}-${index}`}>
|
||||
<td>{formatLongDate(point.filingDate)}</td>
|
||||
<td>{point.periodLabel}</td>
|
||||
<td>{point.filingType}</td>
|
||||
<td>{asScaledFinancialCurrency(point.revenue, financialValueScale)}</td>
|
||||
<td className={(point.netIncome ?? 0) >= 0 ? 'text-[#96f5bf]' : 'text-[#ff9f9f]'}>
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-3 lg:hidden">
|
||||
{filteredFinancialSeries.map((point, index) => (
|
||||
<article key={`${point.filingDate}-${point.filingType}-${index}`} className="rounded-xl border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] p-4">
|
||||
<div className="flex flex-wrap items-start justify-between gap-2">
|
||||
<div>
|
||||
<p className="text-sm font-semibold text-[color:var(--terminal-bright)]">{formatLongDate(point.filingDate)}</p>
|
||||
<p className="text-xs text-[color:var(--terminal-muted)]">{point.filingType} · {point.periodLabel}</p>
|
||||
</div>
|
||||
<p className={`text-sm font-medium ${(point.netIncome ?? 0) >= 0 ? 'text-[#96f5bf]' : 'text-[#ff9f9f]'}`}>
|
||||
{asScaledFinancialCurrency(point.netIncome, financialValueScale)}
|
||||
</td>
|
||||
<td>{asScaledFinancialCurrency(point.assets, financialValueScale)}</td>
|
||||
<td>{point.netMargin === null ? 'n/a' : formatPercent(point.netMargin)}</td>
|
||||
</p>
|
||||
</div>
|
||||
<dl className="mt-3 grid grid-cols-1 gap-2 text-xs sm:grid-cols-3">
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] px-2 py-1.5">
|
||||
<dt className="text-[color:var(--terminal-muted)]">Revenue</dt>
|
||||
<dd className="mt-1 text-sm text-[color:var(--terminal-bright)]">{asScaledFinancialCurrency(point.revenue, financialValueScale)}</dd>
|
||||
</div>
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] px-2 py-1.5">
|
||||
<dt className="text-[color:var(--terminal-muted)]">Assets</dt>
|
||||
<dd className="mt-1 text-sm text-[color:var(--terminal-bright)]">{asScaledFinancialCurrency(point.assets, financialValueScale)}</dd>
|
||||
</div>
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] px-2 py-1.5">
|
||||
<dt className="text-[color:var(--terminal-muted)]">Net Margin</dt>
|
||||
<dd className="mt-1 text-sm text-[color:var(--terminal-bright)]">{point.netMargin === null ? 'n/a' : formatPercent(point.netMargin)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="hidden overflow-x-auto lg:block">
|
||||
<table className="data-table min-w-[820px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filed</th>
|
||||
<th>Period</th>
|
||||
<th>Form</th>
|
||||
<th>Revenue</th>
|
||||
<th>Net Income</th>
|
||||
<th>Assets</th>
|
||||
<th>Net Margin</th>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filteredFinancialSeries.map((point, index) => (
|
||||
<tr key={`${point.filingDate}-${point.filingType}-${index}`}>
|
||||
<td>{formatLongDate(point.filingDate)}</td>
|
||||
<td>{point.periodLabel}</td>
|
||||
<td>{point.filingType}</td>
|
||||
<td>{asScaledFinancialCurrency(point.revenue, financialValueScale)}</td>
|
||||
<td className={(point.netIncome ?? 0) >= 0 ? 'text-[#96f5bf]' : 'text-[#ff9f9f]'}>
|
||||
{asScaledFinancialCurrency(point.netIncome, financialValueScale)}
|
||||
</td>
|
||||
<td>{asScaledFinancialCurrency(point.assets, financialValueScale)}</td>
|
||||
<td>{point.netMargin === null ? 'n/a' : formatPercent(point.netMargin)}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Panel>
|
||||
@@ -681,41 +746,75 @@ function AnalysisPageContent() {
|
||||
) : periodEndFilings.length === 0 ? (
|
||||
<p className="text-sm text-[color:var(--terminal-muted)]">No 10-K or 10-Q filings available for this ticker.</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="data-table min-w-[860px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filed</th>
|
||||
<th>Period</th>
|
||||
<th>Type</th>
|
||||
<th>Revenue</th>
|
||||
<th>Net Income</th>
|
||||
<th>Assets</th>
|
||||
<th>Document</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{periodEndFilings.map((filing) => (
|
||||
<tr key={filing.accession_number}>
|
||||
<td>{format(new Date(filing.filing_date), 'MMM dd, yyyy')}</td>
|
||||
<td>{filing.filing_type === '10-Q' ? 'Quarter End' : 'Fiscal Year End'}</td>
|
||||
<td>{filing.filing_type}</td>
|
||||
<td>{asScaledFinancialCurrency(filing.metrics?.revenue, financialValueScale)}</td>
|
||||
<td>{asScaledFinancialCurrency(filing.metrics?.netIncome, financialValueScale)}</td>
|
||||
<td>{asScaledFinancialCurrency(filing.metrics?.totalAssets, financialValueScale)}</td>
|
||||
<td>
|
||||
{filing.filing_url ? (
|
||||
<a href={filing.filing_url} target="_blank" rel="noreferrer" className="text-xs text-[color:var(--accent)] hover:text-[color:var(--accent-strong)]">
|
||||
SEC filing
|
||||
</a>
|
||||
) : (
|
||||
'n/a'
|
||||
)}
|
||||
</td>
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-3 lg:hidden">
|
||||
{periodEndFilings.map((filing) => (
|
||||
<article key={filing.accession_number} className="rounded-xl border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] p-4">
|
||||
<div className="flex flex-wrap items-start justify-between gap-2">
|
||||
<div>
|
||||
<p className="text-sm font-semibold text-[color:var(--terminal-bright)]">{format(new Date(filing.filing_date), 'MMM dd, yyyy')}</p>
|
||||
<p className="text-xs text-[color:var(--terminal-muted)]">{filing.filing_type} · {filing.filing_type === '10-Q' ? 'Quarter End' : 'Fiscal Year End'}</p>
|
||||
</div>
|
||||
{filing.filing_url ? (
|
||||
<a href={filing.filing_url} target="_blank" rel="noreferrer" className="text-xs text-[color:var(--accent)] hover:text-[color:var(--accent-strong)]">
|
||||
SEC filing
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
<dl className="mt-3 grid grid-cols-1 gap-2 text-xs sm:grid-cols-3">
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] px-2 py-1.5">
|
||||
<dt className="text-[color:var(--terminal-muted)]">Revenue</dt>
|
||||
<dd className="mt-1 text-sm text-[color:var(--terminal-bright)]">{asScaledFinancialCurrency(filing.metrics?.revenue, financialValueScale)}</dd>
|
||||
</div>
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] px-2 py-1.5">
|
||||
<dt className="text-[color:var(--terminal-muted)]">Net Income</dt>
|
||||
<dd className="mt-1 text-sm text-[color:var(--terminal-bright)]">{asScaledFinancialCurrency(filing.metrics?.netIncome, financialValueScale)}</dd>
|
||||
</div>
|
||||
<div className="rounded-md border border-[color:var(--line-weak)] px-2 py-1.5">
|
||||
<dt className="text-[color:var(--terminal-muted)]">Assets</dt>
|
||||
<dd className="mt-1 text-sm text-[color:var(--terminal-bright)]">{asScaledFinancialCurrency(filing.metrics?.totalAssets, financialValueScale)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="hidden overflow-x-auto lg:block">
|
||||
<table className="data-table min-w-[860px]">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filed</th>
|
||||
<th>Period</th>
|
||||
<th>Type</th>
|
||||
<th>Revenue</th>
|
||||
<th>Net Income</th>
|
||||
<th>Assets</th>
|
||||
<th>Document</th>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</thead>
|
||||
<tbody>
|
||||
{periodEndFilings.map((filing) => (
|
||||
<tr key={filing.accession_number}>
|
||||
<td>{format(new Date(filing.filing_date), 'MMM dd, yyyy')}</td>
|
||||
<td>{filing.filing_type === '10-Q' ? 'Quarter End' : 'Fiscal Year End'}</td>
|
||||
<td>{filing.filing_type}</td>
|
||||
<td>{asScaledFinancialCurrency(filing.metrics?.revenue, financialValueScale)}</td>
|
||||
<td>{asScaledFinancialCurrency(filing.metrics?.netIncome, financialValueScale)}</td>
|
||||
<td>{asScaledFinancialCurrency(filing.metrics?.totalAssets, financialValueScale)}</td>
|
||||
<td>
|
||||
{filing.filing_url ? (
|
||||
<a href={filing.filing_url} target="_blank" rel="noreferrer" className="text-xs text-[color:var(--accent)] hover:text-[color:var(--accent-strong)]">
|
||||
SEC filing
|
||||
</a>
|
||||
) : (
|
||||
'n/a'
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Panel>
|
||||
@@ -739,7 +838,7 @@ function AnalysisPageContent() {
|
||||
<BrainCircuit className="size-4 text-[color:var(--accent)]" />
|
||||
</div>
|
||||
<p className="mt-3 line-clamp-6 whitespace-pre-wrap text-sm leading-6 text-[color:var(--terminal-bright)]">{report.summary}</p>
|
||||
<div className="mt-4 flex items-center justify-between gap-2">
|
||||
<div className="mt-4 flex flex-col items-start justify-between gap-2 sm:flex-row sm:items-center">
|
||||
<p className="text-xs text-[color:var(--terminal-muted)]">{report.accessionNumber}</p>
|
||||
<Link
|
||||
href={`/analysis/reports/${analysis.company.ticker}/${encodeURIComponent(report.accessionNumber)}`}
|
||||
@@ -792,12 +891,12 @@ function AnalysisPageContent() {
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button type="submit">
|
||||
<Button type="submit" className="w-full sm:w-auto">
|
||||
<NotebookPen className="size-4" />
|
||||
{editingJournalId === null ? 'Save note' : 'Update note'}
|
||||
</Button>
|
||||
{editingJournalId !== null ? (
|
||||
<Button type="button" variant="ghost" onClick={resetJournalForm}>
|
||||
<Button type="button" variant="ghost" className="w-full sm:w-auto" onClick={resetJournalForm}>
|
||||
Cancel edit
|
||||
</Button>
|
||||
) : null}
|
||||
@@ -816,7 +915,17 @@ function AnalysisPageContent() {
|
||||
const canEdit = entry.entry_type !== 'status_change';
|
||||
|
||||
return (
|
||||
<article key={entry.id} className="rounded-xl border border-[color:var(--line-weak)] bg-[color:var(--panel-soft)] p-4">
|
||||
<article
|
||||
key={entry.id}
|
||||
ref={(node) => {
|
||||
journalEntryRefs.current.set(entry.id, node);
|
||||
}}
|
||||
className={`rounded-xl border bg-[color:var(--panel-soft)] p-4 transition ${
|
||||
highlightedJournalId === entry.id
|
||||
? 'border-[color:var(--line-strong)] shadow-[0_0_0_1px_rgba(0,255,180,0.14),0_0_28px_rgba(0,255,180,0.16)]'
|
||||
: 'border-[color:var(--line-weak)]'
|
||||
}`}
|
||||
>
|
||||
<div className="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<p className="text-xs uppercase tracking-[0.16em] text-[color:var(--terminal-muted)]">
|
||||
|
||||
Reference in New Issue
Block a user