diff --git a/web/pages/DeploymentPage.tsx b/web/pages/DeploymentPage.tsx index dccc66e..819e7e8 100644 --- a/web/pages/DeploymentPage.tsx +++ b/web/pages/DeploymentPage.tsx @@ -46,6 +46,8 @@ import { QueryHistory } from '../components/QueryHistory.tsx' import { DeploymentHeader } from '../components/DeploymentHeader.tsx' import type { ComponentChildren } from 'preact' import { querier, queriesHistory, runQuery } from '../lib/shared.tsx' +import { apiDocs, TypeDefinition } from './project/ApiDocPage.tsx' +import type { EndpointDoc } from './project/ApiDocPage.tsx' type AnyRecord = Record // API signals for schema and table data @@ -1501,6 +1503,14 @@ effect(() => { } }) +// Fetch API docs when the routes tab is active so expanded rows can show route documentation +effect(() => { + const { dep, tab } = url.params + if (dep && tab === 'routes') { + apiDocs.fetch({ deployment: dep }) + } +}) + // ─── Metrics types ─────────────────────────────────────────────────────────── type Metric = ApiOutput['GET/api/deployment/metrics-sql'][number] @@ -1852,6 +1862,107 @@ function MetricDetail() { ) } +function RouteMetricDetail() { + const expanded = url.params.expanded + const sorted = sortedRouterMetrics.value + const metric = expanded && sorted.find((m) => m.key === expanded) + if (!metric) { + expanded && navigate({ params: { expanded: null }, replace: true }) + return null + } + + const colonIdx = metric.key.indexOf(':') + const method = colonIdx > -1 ? metric.key.slice(0, colonIdx) : 'GET' + const path = colonIdx > -1 ? metric.key.slice(colonIdx + 1) : metric.key + + const endpoint = apiDocs.data?.find((d) => + d.method === method && d.path === path + ) as EndpointDoc | undefined + + const inputType = endpoint && ( + + ) + const outputType = endpoint && ( + + ) + + return ( +
+
+
+ Route Documentation +
+ {endpoint + ? ( +
+
+ + {method} + + + {path} + + {endpoint.requiresAuth && ( + + Requires Auth + + )} +
+ {endpoint.description && ( +

+ {endpoint.description} +

+ )} + {endpoint.requiresAuth && endpoint.authFunction && ( +

+ Auth Function:{' '} + + {endpoint.authFunction} + +

+ )} +
+
+
+ Input +
+
+                    {inputType || (
+                      
+                        No input documented
+                      
+                    )}
+                  
+
+
+
+ Output +
+
+                    {outputType || (
+                      
+                        No output documented
+                      
+                    )}
+                  
+
+
+
+ ) + : ( +
+ No API documentation found for this route. +
+ )} +
+
+ ) +} + const methodColors: Record = { GET: 'badge-info', POST: 'badge-success', @@ -1980,7 +2091,7 @@ const MetricRow = ({ type, metric }: MetricRowProps) => { - {isExpanded && isSql && } + {isExpanded && (isSql ? : )} ) } diff --git a/web/pages/project/ApiDocPage.tsx b/web/pages/project/ApiDocPage.tsx index 5fcbccd..4e25ced 100644 --- a/web/pages/project/ApiDocPage.tsx +++ b/web/pages/project/ApiDocPage.tsx @@ -141,7 +141,7 @@ const ObjectDefinition = ({ ) } -const TypeDefinition = ({ +export const TypeDefinition = ({ typeName, doc, }: {