Skip to content

Commit c15ef18

Browse files
fix(reports): Inputs tab leads with the attached files, and they open
Report #3. The tab opened with Template and Objective - both already collected in the setup modal - so what the researcher came to check (which data is actually attached) sat underneath a duplicate of the setup form, and the files couldn't be opened at all. A "Files in this report" card now leads the tab, listing the attached data and reference documents as clickable rows that open the file in a new tab via a signed storage URL. The pickers and settings stay below for adding, removing and regenerating - they're still needed, so removing them outright would break regeneration. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 02beb48 commit c15ef18

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

components/reports/tabs/inputs-tab.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
55
import { Input } from "@/components/ui/input"
66
import { Label } from "@/components/ui/label"
77
import { Textarea } from "@/components/ui/textarea"
8+
import { getFileFromStorage } from "@/db/storage/files"
89
import { Tables } from "@/supabase/types"
910
import {
11+
IconFileText,
1012
IconLoader2,
1113
IconPlus,
1214
IconRefresh,
@@ -151,6 +153,50 @@ export const InputsTab: FC<InputsTabProps> = ({
151153
// three near-identical fields without forcing a separate component
152154
// file. The label / caption are passed in so each field stays
153155
// self-explanatory.
156+
/**
157+
* The files already attached, as an openable list. The tab used to lead with
158+
* Template + Objective - both already collected in the setup modal - so the
159+
* thing the researcher came here to check (what data is actually attached)
160+
* was buried under a duplicate of the setup form, and the files couldn't be
161+
* opened at all.
162+
*/
163+
const renderAttachedFiles = (label: string, items: Tables<"files">[]) => {
164+
if (items.length === 0) return null
165+
const open = async (f: Tables<"files">) => {
166+
try {
167+
const url = await getFileFromStorage(f.file_path)
168+
if (url) window.open(url, "_blank", "noopener,noreferrer")
169+
} catch {
170+
/* opening is best-effort - the row stays listed either way */
171+
}
172+
}
173+
return (
174+
<div className="space-y-1.5">
175+
<Label className="text-[12.5px]">{label}</Label>
176+
<ul className="space-y-1">
177+
{items.map(f => (
178+
<li key={f.id}>
179+
<button
180+
type="button"
181+
onClick={() => void open(f)}
182+
title="Open this file"
183+
className="border-line hover:border-line-strong hover:bg-paper-2 flex w-full items-center gap-2 rounded-lg border px-3 py-2 text-left transition-colors"
184+
>
185+
<IconFileText size={15} className="text-ink-3 shrink-0" />
186+
<span className="text-ink-800 min-w-0 flex-1 truncate text-[12.5px]">
187+
{f.name}
188+
</span>
189+
<span className="text-ink-400 shrink-0 text-[10.5px] uppercase">
190+
{(f.type || "").replace("application/", "") || "file"}
191+
</span>
192+
</button>
193+
</li>
194+
))}
195+
</ul>
196+
</div>
197+
)
198+
}
199+
154200
const renderFileField = (params: {
155201
label: string
156202
required?: boolean
@@ -217,6 +263,23 @@ export const InputsTab: FC<InputsTabProps> = ({
217263

218264
return (
219265
<div className="space-y-5">
266+
{(dataFiles.length > 0 || papers.length > 0) && (
267+
<Card className="rounded-2xl">
268+
<CardHeader className="pb-3">
269+
<CardTitle className="text-ink-900 text-lg">
270+
Files in this report
271+
</CardTitle>
272+
</CardHeader>
273+
<CardContent className="space-y-4">
274+
{renderAttachedFiles("Data", dataFiles)}
275+
{renderAttachedFiles("Reference documents", papers)}
276+
<p className="text-ink-400 text-xs">
277+
Click a file to open it. Add or remove files below.
278+
</p>
279+
</CardContent>
280+
</Card>
281+
)}
282+
220283
<Card className="rounded-2xl">
221284
<CardHeader className="pb-3">
222285
<CardTitle className="text-ink-900 text-lg">Template</CardTitle>

0 commit comments

Comments
 (0)