@contentbit/studio 1.0.0 → 2.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -9
- package/dist/client/assets/api-aCc2x-IO.js +1 -0
- package/dist/client/assets/arrow-right-tp4VknZo.js +1 -0
- package/dist/client/assets/document-DIh3ZPXr.js +56 -0
- package/dist/client/assets/documents-CjBZYbQ4.js +1 -0
- package/dist/client/assets/file-code-corner-Fzc5liO9.js +1 -0
- package/dist/client/assets/file-text-B8O46COn.js +1 -0
- package/dist/client/assets/index-Cd04OFZT.js +11 -0
- package/dist/client/assets/page-BMU8eIrR.js +1 -0
- package/dist/client/assets/routes-WndCJoku.js +1 -0
- package/dist/client/assets/search-BnUPH8AI.js +1 -0
- package/dist/client/assets/styles-hAsz_paS.css +2 -0
- package/dist/client/assets/target-BMSXP2fU.js +1 -0
- package/dist/client/assets/templates-IJid1Zwh.js +1 -0
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/assets/_tanstack-start-manifest_v-WfZ3uz_l.js +69 -0
- package/dist/server/assets/api-CHfynRIj.js +342 -0
- package/dist/server/assets/{document-DSV89Ser.js → document-BjPXZ9gS.js} +2529 -1317
- package/dist/server/assets/{routes-FGdym0e5.js → documents-jT4KnSkA.js} +63 -112
- package/dist/server/assets/empty-plugin-adapters-Ctp1ZmyT.js +4 -0
- package/dist/server/assets/page--xw7NmtK.js +388 -0
- package/dist/server/assets/router-xI8HUWRI.js +125 -0
- package/dist/server/assets/routes-CfwU-Ww2.js +372 -0
- package/dist/server/assets/start-Dk-BJfGT.js +3 -0
- package/dist/server/assets/templates--9wK-MK9.js +123 -0
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +6104 -110
- package/dist/server/scan.d.ts +1 -2
- package/dist/server/scan.d.ts.map +1 -1
- package/dist/server/server.js +3150 -1878
- package/dist/server/site.d.ts +38 -0
- package/dist/server/site.d.ts.map +1 -0
- package/dist/server/types.d.ts +33 -31
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +26 -15
- package/src/components/studio.test.ts +10 -0
- package/src/components/studio.tsx +209 -0
- package/src/lib/api.test.ts +80 -0
- package/src/lib/api.ts +68 -7
- package/src/routeTree.gen.ts +57 -3
- package/src/routes/document.tsx +34 -88
- package/src/routes/documents.tsx +433 -0
- package/src/routes/index.tsx +295 -414
- package/src/routes/page.tsx +401 -0
- package/src/routes/templates.tsx +104 -0
- package/src/server/api.ts +19 -3
- package/src/server/index.ts +31 -12
- package/src/server/scan.test.ts +31 -44
- package/src/server/scan.ts +56 -82
- package/src/server/site.test.ts +355 -0
- package/src/server/site.ts +164 -0
- package/src/server/types.ts +28 -30
- package/tsconfig.json +1 -1
- package/dist/client/assets/api-BX-WUPtV.js +0 -1
- package/dist/client/assets/document-BOMp4_F5.js +0 -65
- package/dist/client/assets/index-C0ybJ4zQ.js +0 -12
- package/dist/client/assets/routes-ACKdIhYm.js +0 -1
- package/dist/client/assets/styles-DogO4Wcf.css +0 -2
- package/dist/server/assets/_tanstack-start-manifest_v-BC1PNuB0.js +0 -25
- package/dist/server/assets/api-Bqt_atjc.js +0 -72
- package/dist/server/assets/document-BB_UYqNL.js +0 -9
- package/dist/server/assets/empty-plugin-adapters-De7E1vAI.js +0 -5
- package/dist/server/assets/router-BJiN6b7L.js +0 -63
- package/dist/server/assets/routes-p0tk6PAr.js +0 -20
- package/dist/server/assets/start-m8EQRpUf.js +0 -4
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
|
|
2
|
+
import {
|
|
3
|
+
AlertTriangle,
|
|
4
|
+
ArrowRight,
|
|
5
|
+
Blocks,
|
|
6
|
+
FileText,
|
|
7
|
+
Filter,
|
|
8
|
+
RefreshCw,
|
|
9
|
+
Search,
|
|
10
|
+
ChevronsUpDown,
|
|
11
|
+
Target,
|
|
12
|
+
} from 'lucide-react'
|
|
13
|
+
import type { ReactNode } from 'react'
|
|
14
|
+
import { useMemo } from 'react'
|
|
15
|
+
|
|
16
|
+
import { FileFindings, StudioNav } from '../components/studio'
|
|
17
|
+
import { Button } from '../components/ui/button'
|
|
18
|
+
import { useProject } from '../lib/api'
|
|
19
|
+
import type { StudioFileSummary, StudioStatus } from '../server/types'
|
|
20
|
+
|
|
21
|
+
type StatusFilter = 'all' | StudioStatus
|
|
22
|
+
type SortKey = 'document' | 'status' | 'blocks' | 'keywords' | 'findings'
|
|
23
|
+
type SortDir = 'asc' | 'desc'
|
|
24
|
+
|
|
25
|
+
interface DashboardSearch {
|
|
26
|
+
q: string
|
|
27
|
+
status: StatusFilter
|
|
28
|
+
sort: SortKey
|
|
29
|
+
dir: SortDir
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const Route = createFileRoute('/documents')({
|
|
33
|
+
validateSearch: (search: Record<string, unknown>): DashboardSearch => ({
|
|
34
|
+
q: typeof search.q === 'string' ? search.q : '',
|
|
35
|
+
status: isStatus(search.status) ? search.status : 'all',
|
|
36
|
+
sort: isSortKey(search.sort) ? search.sort : 'status',
|
|
37
|
+
dir: search.dir === 'asc' || search.dir === 'desc' ? search.dir : 'asc',
|
|
38
|
+
}),
|
|
39
|
+
component: Dashboard,
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
function Dashboard() {
|
|
43
|
+
const search = Route.useSearch()
|
|
44
|
+
const navigate = useNavigate({ from: '/documents' })
|
|
45
|
+
const { data: project, error, refreshing, refresh } = useProject()
|
|
46
|
+
|
|
47
|
+
const files = useMemo(() => {
|
|
48
|
+
if (!project) return []
|
|
49
|
+
const query = search.q.toLowerCase().trim()
|
|
50
|
+
return project.files
|
|
51
|
+
.filter((file) => {
|
|
52
|
+
const haystack = [
|
|
53
|
+
file.relativePath,
|
|
54
|
+
file.title,
|
|
55
|
+
file.slug,
|
|
56
|
+
file.key,
|
|
57
|
+
file.locale,
|
|
58
|
+
file.keywords?.primary,
|
|
59
|
+
...(file.keywords?.secondary ?? []),
|
|
60
|
+
...(file.keywords?.lsi ?? []),
|
|
61
|
+
]
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.join(' ')
|
|
64
|
+
.toLowerCase()
|
|
65
|
+
return (
|
|
66
|
+
(search.status === 'all' || file.status === search.status) && haystack.includes(query)
|
|
67
|
+
)
|
|
68
|
+
})
|
|
69
|
+
.toSorted((a, b) => compareFiles(a, b, search.sort, search.dir))
|
|
70
|
+
}, [project, search.dir, search.q, search.sort, search.status])
|
|
71
|
+
|
|
72
|
+
function setSearch(next: Partial<DashboardSearch>) {
|
|
73
|
+
void navigate({ to: '/documents', search: (prev) => ({ ...prev, ...next }) })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function setSort(sort: SortKey) {
|
|
77
|
+
setSearch({ sort, dir: search.sort === sort && search.dir === 'asc' ? 'desc' : 'asc' })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<main className="min-h-svh bg-background text-foreground">
|
|
82
|
+
<section className="border-b bg-muted/30">
|
|
83
|
+
<div className="mx-auto flex max-w-7xl flex-col gap-6 px-5 py-6">
|
|
84
|
+
<StudioNav />
|
|
85
|
+
<div className="flex flex-col gap-4 md:flex-row md:items-end md:justify-between">
|
|
86
|
+
<div>
|
|
87
|
+
<p className="font-mono text-xs uppercase text-muted-foreground">contentbit studio</p>
|
|
88
|
+
<h1 className="mt-1 text-3xl font-semibold tracking-tight">Documents</h1>
|
|
89
|
+
<p className="mt-2 max-w-2xl text-sm text-muted-foreground">
|
|
90
|
+
The Markdown files, with their findings, structure, links, keywords and previews.
|
|
91
|
+
</p>
|
|
92
|
+
</div>
|
|
93
|
+
<Button onClick={refresh} disabled={refreshing} className="w-fit gap-2">
|
|
94
|
+
<RefreshCw className={refreshing ? 'size-4 animate-spin' : 'size-4'} />
|
|
95
|
+
Refresh
|
|
96
|
+
</Button>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
{project && (
|
|
100
|
+
<div className="grid gap-px overflow-hidden rounded-sm border bg-border md:grid-cols-3">
|
|
101
|
+
<Metric
|
|
102
|
+
label="files"
|
|
103
|
+
value={project.summary.files}
|
|
104
|
+
icon={<FileText className="size-4" />}
|
|
105
|
+
/>
|
|
106
|
+
<Metric
|
|
107
|
+
label="findings"
|
|
108
|
+
value={
|
|
109
|
+
project.summary.errors + project.summary.warnings + project.summary.suggestions
|
|
110
|
+
}
|
|
111
|
+
icon={<AlertTriangle className="size-4" />}
|
|
112
|
+
tone={
|
|
113
|
+
project.summary.errors > 0 ? 'bad' : project.summary.warnings > 0 ? 'warn' : 'ok'
|
|
114
|
+
}
|
|
115
|
+
/>
|
|
116
|
+
<Metric
|
|
117
|
+
label="blocks"
|
|
118
|
+
value={project.summary.blocks}
|
|
119
|
+
icon={<Blocks className="size-4" />}
|
|
120
|
+
/>
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
</section>
|
|
125
|
+
|
|
126
|
+
<section className="mx-auto grid max-w-7xl gap-5 px-5 py-5 lg:grid-cols-[minmax(0,1fr)_320px]">
|
|
127
|
+
<div className="min-w-0">
|
|
128
|
+
<div className="mb-3 flex flex-col gap-2 md:flex-row">
|
|
129
|
+
<label className="relative flex min-w-0 flex-1 items-center">
|
|
130
|
+
<Search className="pointer-events-none absolute left-3 size-4 text-muted-foreground" />
|
|
131
|
+
<input
|
|
132
|
+
value={search.q}
|
|
133
|
+
onChange={(event) => setSearch({ q: event.target.value })}
|
|
134
|
+
placeholder="Search path, title, slug, keyword..."
|
|
135
|
+
className="h-10 w-full border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-foreground"
|
|
136
|
+
/>
|
|
137
|
+
</label>
|
|
138
|
+
<div className="flex items-center gap-1 border bg-background p-1">
|
|
139
|
+
<Filter className="mx-2 size-4 text-muted-foreground" />
|
|
140
|
+
{(['all', 'error', 'warning', 'suggestion', 'healthy'] as const).map((status) => (
|
|
141
|
+
<button
|
|
142
|
+
key={status}
|
|
143
|
+
onClick={() => setSearch({ status })}
|
|
144
|
+
className={
|
|
145
|
+
search.status === status
|
|
146
|
+
? 'bg-foreground px-2.5 py-1.5 text-xs font-medium text-background'
|
|
147
|
+
: 'px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground'
|
|
148
|
+
}
|
|
149
|
+
>
|
|
150
|
+
{status}
|
|
151
|
+
</button>
|
|
152
|
+
))}
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<div className="overflow-hidden border">
|
|
157
|
+
<div className="grid grid-cols-[1.4fr_0.6fr_0.6fr_0.6fr_2rem] gap-px border-b bg-border text-xs font-medium uppercase text-muted-foreground">
|
|
158
|
+
<SortHeader
|
|
159
|
+
label="Document"
|
|
160
|
+
active={search.sort === 'document'}
|
|
161
|
+
onClick={() => setSort('document')}
|
|
162
|
+
/>
|
|
163
|
+
<SortHeader
|
|
164
|
+
label="Status"
|
|
165
|
+
active={search.sort === 'status'}
|
|
166
|
+
onClick={() => setSort('status')}
|
|
167
|
+
/>
|
|
168
|
+
<SortHeader
|
|
169
|
+
label="Blocks"
|
|
170
|
+
active={search.sort === 'blocks'}
|
|
171
|
+
onClick={() => setSort('blocks')}
|
|
172
|
+
/>
|
|
173
|
+
<SortHeader
|
|
174
|
+
label="Keywords"
|
|
175
|
+
active={search.sort === 'keywords'}
|
|
176
|
+
onClick={() => setSort('keywords')}
|
|
177
|
+
/>
|
|
178
|
+
<div className="bg-muted/50 px-2 py-2" />
|
|
179
|
+
</div>
|
|
180
|
+
{error ? (
|
|
181
|
+
<div className="p-4 text-sm text-destructive">{error}</div>
|
|
182
|
+
) : project ? (
|
|
183
|
+
<div className="divide-y">
|
|
184
|
+
{files.map((file) => (
|
|
185
|
+
<FileRow key={file.path} file={file} />
|
|
186
|
+
))}
|
|
187
|
+
{files.length === 0 && (
|
|
188
|
+
<div className="p-4 text-sm text-muted-foreground">
|
|
189
|
+
{project.files.length === 0
|
|
190
|
+
? 'No Markdown files. The built pages are under Pages.'
|
|
191
|
+
: 'No documents match the current filters.'}
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
) : (
|
|
196
|
+
<div className="p-4 text-sm text-muted-foreground">Scanning content...</div>
|
|
197
|
+
)}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<aside className="flex flex-col gap-4">
|
|
202
|
+
{project && project.agentGuidanceFindings.length > 0 && (
|
|
203
|
+
<Panel title="Agent guidance">
|
|
204
|
+
<FileFindings root={project.root} findings={project.agentGuidanceFindings} />
|
|
205
|
+
</Panel>
|
|
206
|
+
)}
|
|
207
|
+
|
|
208
|
+
{project?.seo && (
|
|
209
|
+
<Panel title="SEO">
|
|
210
|
+
<div className="grid grid-cols-3 gap-px overflow-hidden border bg-border text-center">
|
|
211
|
+
<TinyMetric value={project.seo.pages} label="pages" />
|
|
212
|
+
<TinyMetric value={project.seo.planned} label="planned" />
|
|
213
|
+
<TinyMetric value={project.seo.findings} label="findings" />
|
|
214
|
+
</div>
|
|
215
|
+
<div className="mt-3 flex items-center gap-2 text-xs text-muted-foreground">
|
|
216
|
+
<Target className="size-4" />
|
|
217
|
+
<span>{project.seo.schemaVersion}</span>
|
|
218
|
+
</div>
|
|
219
|
+
</Panel>
|
|
220
|
+
)}
|
|
221
|
+
|
|
222
|
+
<Panel title="Block usage">
|
|
223
|
+
{project && Object.keys(project.blockUsage).length > 0 ? (
|
|
224
|
+
<div className="flex flex-wrap gap-1">
|
|
225
|
+
{Object.entries(project.blockUsage).map(([name, count]) => (
|
|
226
|
+
<span key={name} className="border bg-muted px-2 py-1 font-mono text-xs">
|
|
227
|
+
{name} x{count}
|
|
228
|
+
</span>
|
|
229
|
+
))}
|
|
230
|
+
</div>
|
|
231
|
+
) : (
|
|
232
|
+
<p className="text-sm text-muted-foreground">No blocks found yet.</p>
|
|
233
|
+
)}
|
|
234
|
+
</Panel>
|
|
235
|
+
|
|
236
|
+
<Panel title="Keyword coverage">
|
|
237
|
+
{project && (
|
|
238
|
+
<div className="space-y-2 text-sm">
|
|
239
|
+
<Coverage
|
|
240
|
+
label="primary"
|
|
241
|
+
value={project.keywordCoverage.withPrimary}
|
|
242
|
+
total={project.keywordCoverage.total}
|
|
243
|
+
/>
|
|
244
|
+
<Coverage
|
|
245
|
+
label="secondary"
|
|
246
|
+
value={project.keywordCoverage.withSecondary}
|
|
247
|
+
total={project.keywordCoverage.total}
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
250
|
+
)}
|
|
251
|
+
</Panel>
|
|
252
|
+
</aside>
|
|
253
|
+
</section>
|
|
254
|
+
</main>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function FileRow({ file }: { file: StudioFileSummary }) {
|
|
259
|
+
return (
|
|
260
|
+
<Link
|
|
261
|
+
to="/document"
|
|
262
|
+
search={{ path: file.path }}
|
|
263
|
+
className="grid grid-cols-[1.4fr_0.6fr_0.6fr_0.6fr_2rem] gap-px bg-border text-sm transition-colors hover:bg-foreground/20"
|
|
264
|
+
>
|
|
265
|
+
<div className="min-w-0 bg-background px-3 py-3">
|
|
266
|
+
<p className="truncate font-medium">{file.title}</p>
|
|
267
|
+
<p className="truncate font-mono text-xs text-muted-foreground">{file.relativePath}</p>
|
|
268
|
+
</div>
|
|
269
|
+
<div className="bg-background px-3 py-3">
|
|
270
|
+
<StatusBadge status={file.status} />
|
|
271
|
+
</div>
|
|
272
|
+
<div className="bg-background px-3 py-3 font-mono text-xs">{file.blocks}</div>
|
|
273
|
+
<div className="bg-background px-3 py-3 text-xs text-muted-foreground">
|
|
274
|
+
{file.keywords?.primary ? 'primary' : 'missing'}
|
|
275
|
+
</div>
|
|
276
|
+
<div className="flex items-center justify-center bg-background px-2 py-3">
|
|
277
|
+
<ArrowRight className="size-4 text-muted-foreground" />
|
|
278
|
+
</div>
|
|
279
|
+
</Link>
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function Metric({
|
|
284
|
+
label,
|
|
285
|
+
value,
|
|
286
|
+
icon,
|
|
287
|
+
tone,
|
|
288
|
+
}: {
|
|
289
|
+
label: string
|
|
290
|
+
value: number | string
|
|
291
|
+
icon: ReactNode
|
|
292
|
+
tone?: 'bad' | 'warn' | 'ok'
|
|
293
|
+
}) {
|
|
294
|
+
const color =
|
|
295
|
+
tone === 'bad'
|
|
296
|
+
? 'text-destructive'
|
|
297
|
+
: tone === 'warn'
|
|
298
|
+
? 'text-amber-600'
|
|
299
|
+
: tone === 'ok'
|
|
300
|
+
? 'text-emerald-600'
|
|
301
|
+
: 'text-foreground'
|
|
302
|
+
return (
|
|
303
|
+
<div className="bg-background p-4">
|
|
304
|
+
<div className="mb-3 flex items-center justify-between text-muted-foreground">
|
|
305
|
+
<span className="text-xs uppercase">{label}</span>
|
|
306
|
+
{icon}
|
|
307
|
+
</div>
|
|
308
|
+
<div className={`font-mono text-3xl font-semibold ${color}`}>{value}</div>
|
|
309
|
+
</div>
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function TinyMetric({ value, label }: { value: number | string; label: string }) {
|
|
314
|
+
return (
|
|
315
|
+
<div className="bg-background px-2 py-2">
|
|
316
|
+
<div className="font-mono text-lg font-semibold">{value}</div>
|
|
317
|
+
<div className="text-[0.65rem] uppercase text-muted-foreground">{label}</div>
|
|
318
|
+
</div>
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function Panel({ title, children }: { title: string; children: ReactNode }) {
|
|
323
|
+
return (
|
|
324
|
+
<section className="border bg-background p-4">
|
|
325
|
+
<h2 className="mb-3 text-sm font-semibold">{title}</h2>
|
|
326
|
+
{children}
|
|
327
|
+
</section>
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function Coverage({ label, value, total }: { label: string; value: number; total: number }) {
|
|
332
|
+
const pct = total === 0 ? 0 : Math.round((value / total) * 100)
|
|
333
|
+
return (
|
|
334
|
+
<div>
|
|
335
|
+
<div className="mb-1 flex justify-between text-xs">
|
|
336
|
+
<span className="text-muted-foreground">{label}</span>
|
|
337
|
+
<span className="font-mono">{pct}%</span>
|
|
338
|
+
</div>
|
|
339
|
+
<div className="h-2 bg-muted">
|
|
340
|
+
<div className="h-full bg-foreground" style={{ width: `${pct}%` }} />
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function StatusBadge({ status }: { status: StudioStatus }) {
|
|
347
|
+
const cls =
|
|
348
|
+
status === 'error'
|
|
349
|
+
? 'border-destructive/40 bg-destructive/10 text-destructive'
|
|
350
|
+
: status === 'warning'
|
|
351
|
+
? 'border-amber-500/40 bg-amber-500/10 text-amber-700'
|
|
352
|
+
: status === 'suggestion'
|
|
353
|
+
? 'border-blue-500/40 bg-blue-500/10 text-blue-700'
|
|
354
|
+
: 'border-emerald-500/40 bg-emerald-500/10 text-emerald-700'
|
|
355
|
+
return <span className={`inline-flex border px-2 py-0.5 text-xs ${cls}`}>{status}</span>
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function isStatus(value: unknown): value is StatusFilter {
|
|
359
|
+
return (
|
|
360
|
+
value === 'all' ||
|
|
361
|
+
value === 'error' ||
|
|
362
|
+
value === 'warning' ||
|
|
363
|
+
value === 'suggestion' ||
|
|
364
|
+
value === 'healthy'
|
|
365
|
+
)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function SortHeader({
|
|
369
|
+
label,
|
|
370
|
+
active,
|
|
371
|
+
onClick,
|
|
372
|
+
}: {
|
|
373
|
+
label: string
|
|
374
|
+
active: boolean
|
|
375
|
+
onClick: () => void
|
|
376
|
+
}) {
|
|
377
|
+
return (
|
|
378
|
+
<button
|
|
379
|
+
className={
|
|
380
|
+
active
|
|
381
|
+
? 'flex items-center gap-1 bg-muted px-3 py-2 text-foreground'
|
|
382
|
+
: 'flex items-center gap-1 bg-muted/50 px-3 py-2 hover:text-foreground'
|
|
383
|
+
}
|
|
384
|
+
onClick={onClick}
|
|
385
|
+
>
|
|
386
|
+
{label}
|
|
387
|
+
<ChevronsUpDown className="size-3" />
|
|
388
|
+
</button>
|
|
389
|
+
)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function compareFiles(a: StudioFileSummary, b: StudioFileSummary, sort: SortKey, dir: SortDir) {
|
|
393
|
+
const direction = dir === 'asc' ? 1 : -1
|
|
394
|
+
const statusOrder: Record<StudioStatus, number> = {
|
|
395
|
+
error: 0,
|
|
396
|
+
warning: 1,
|
|
397
|
+
suggestion: 2,
|
|
398
|
+
healthy: 3,
|
|
399
|
+
}
|
|
400
|
+
const result =
|
|
401
|
+
sort === 'status'
|
|
402
|
+
? statusOrder[a.status] - statusOrder[b.status]
|
|
403
|
+
: sort === 'blocks'
|
|
404
|
+
? a.blocks - b.blocks
|
|
405
|
+
: sort === 'keywords'
|
|
406
|
+
? keywordScore(a) - keywordScore(b)
|
|
407
|
+
: sort === 'findings'
|
|
408
|
+
? findingScore(a) - findingScore(b)
|
|
409
|
+
: a.relativePath.localeCompare(b.relativePath)
|
|
410
|
+
return (result || a.relativePath.localeCompare(b.relativePath)) * direction
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function keywordScore(file: StudioFileSummary): number {
|
|
414
|
+
return (
|
|
415
|
+
(file.keywords?.primary ? 1 : 0) +
|
|
416
|
+
(file.keywords?.secondary?.length ? 1 : 0) +
|
|
417
|
+
(file.keywords?.lsi?.length ? 1 : 0)
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function findingScore(file: StudioFileSummary): number {
|
|
422
|
+
return file.findings.errors * 100 + file.findings.warnings * 10 + file.findings.suggestions
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function isSortKey(value: unknown): value is SortKey {
|
|
426
|
+
return (
|
|
427
|
+
value === 'document' ||
|
|
428
|
+
value === 'status' ||
|
|
429
|
+
value === 'blocks' ||
|
|
430
|
+
value === 'keywords' ||
|
|
431
|
+
value === 'findings'
|
|
432
|
+
)
|
|
433
|
+
}
|