Fix file display on record rows

This commit is contained in:
2025-12-12 23:16:25 +03:00
parent 77de7c447c
commit 33bf97d7f9
7 changed files with 61 additions and 46 deletions

View File

@@ -62,8 +62,15 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
const showError = React.useCallback(
(error: string, type: "error" | "warning" = "error") => {
try {
// Prevent error loops by checking if error is already being shown
if (error.includes("Unauthorized") || error.includes("auth")) {
// Prevent error toasts for auth errors (401/403) - these are handled by the auth dialog
const errorLower = error.toLowerCase()
if (
errorLower.includes("unauthorized") ||
errorLower.includes("forbidden") ||
errorLower.includes("auth") ||
errorLower.includes("403") ||
errorLower.includes("401")
) {
return // Don't show toast for auth errors, handle with dialog
}
@@ -84,7 +91,7 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
try {
setAuthErrorReason(reason || "") // Set the auth error string
setAuthErrorDialog(true) // Set the auth dialog to open
handleLogout()
// Don't call handleLogout() here - let the dialog handle navigation
} catch (error) {
console.warn("Failed to handle unauthorized:", error)
}
@@ -172,12 +179,20 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
const handleAuthErrorLogin = () => {
try {
setAuthErrorDialog(false)
// Always navigate to login and discard token, regardless of button clicked
handleLogout()
} catch (error) {
console.warn("Failed to handle auth error login:", error)
}
}
const handleAuthErrorDialogClose = (open: boolean) => {
// If dialog is being closed (either by Cancel or X button), navigate to login
if (!open) {
handleAuthErrorLogin()
}
}
const handleModeChange = (newMode: AppMode, baseUrl?: string) => {
// Update API client when mode changes (mode is handled via app state)
const newApiClient = new ApiClient(token || "", handleUnauthorized, showError)
@@ -233,7 +248,7 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
<div className="flex min-h-screen w-full items-center justify-center">
<div className="text-center">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent mx-auto mb-4"></div>
<p className="text-muted-foreground">Loading dashboard...</p>
<p className="text-muted-foreground">Loading MantisBase Admin Dashboard...</p>
</div>
</div>
)
@@ -374,7 +389,7 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
</div>
{/* Auth Error Dialog */}
<Dialog open={authErrorDialog} onOpenChange={setAuthErrorDialog}>
<Dialog open={authErrorDialog} onOpenChange={handleAuthErrorDialogClose}>
<DialogContent>
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
@@ -394,7 +409,7 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
}
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={() => setAuthErrorDialog(false)}>
<Button variant="outline" onClick={handleAuthErrorLogin}>
Cancel
</Button>
<Button onClick={handleAuthErrorLogin}>Login Again</Button>

View File

@@ -41,7 +41,7 @@ export function AddItemDrawer({ table, apiClient, open, onClose, onItemAdded }:
setFormData({})
setHasUnsavedChanges(false)
setTableFields(table.schema?.fields.filter(f => !isSystemGeneratedField(f)))
setIsViewIsViewType(table?.type === "view")
setIsViewIsViewType(table?.schema.type === "view")
}
}, [open])
@@ -80,7 +80,7 @@ export function AddItemDrawer({ table, apiClient, open, onClose, onItemAdded }:
setIsLoading(true)
try {
const body = prepareRequestBody(formData, tableFields);
const createdItem = await apiClient.call<any>(`/api/v1/entities/${table.name}`, {
const createdItem = await apiClient.call<any>(`/api/v1/entities/${table.schema.name}`, {
method: "POST",
body: body,
})
@@ -219,7 +219,7 @@ export function AddItemDrawer({ table, apiClient, open, onClose, onItemAdded }:
<X className="h-4 w-4" />
</Button>
</div>
<DrawerDescription>Create a new record in {table.name} table</DrawerDescription>
<DrawerDescription>Create a new record in {table.schema.name} table</DrawerDescription>
</DrawerHeader>
<div className="flex-1 overflow-auto">
@@ -227,7 +227,7 @@ export function AddItemDrawer({ table, apiClient, open, onClose, onItemAdded }:
<div className="p-6 space-y-6 pb-64">
<div className="text-sm text-muted-foreground">
Autogenerated fields for <Badge variant="default" className="text-sm mr-2">
{table.name}
{table.schema.name}
</Badge>table: <Badge variant="outline" className="text-xs mr-2">
id
</Badge>

View File

@@ -62,11 +62,11 @@ export function DatabaseSection({ apiClient, tables, onTablesUpdate }: DatabaseS
// Get selected entity name from path params
const selectedEntityName = route.pathParams.name || null
const filteredTables = Array.isArray(tables) ? tables?.filter((table) => table?.name?.toLowerCase().includes(searchTerm.toLowerCase())) : []
const filteredTables = Array.isArray(tables) ? tables?.filter((table) => table?.schema?.name?.toLowerCase().includes(searchTerm.toLowerCase())) : []
const handleDeleteTable = async (tableId: string) => {
try {
const res: any = await apiClient.call(`/api/v1/tables/${tableId}`, { method: "DELETE" })
const res: any = await apiClient.call(`/api/v1/schemas/${tableId}`, { method: "DELETE" })
// If the request failed, throw the error here
if (res?.error?.length > 0) throw res.error
@@ -136,7 +136,7 @@ export function DatabaseSection({ apiClient, tables, onTablesUpdate }: DatabaseS
}
const selectedEntity = selectedEntityName
? Array.isArray(tables) ? tables.find((t) => t.name === selectedEntityName) : null
? Array.isArray(tables) ? tables.find((t) => t.schema.name === selectedEntityName) : null
: null
return (
@@ -188,22 +188,22 @@ export function DatabaseSection({ apiClient, tables, onTablesUpdate }: DatabaseS
filteredTables.map((table) => (
<button
key={table.id}
onClick={() => handleEntityClick(table.name)}
onClick={() => handleEntityClick(table.schema.name)}
className={cn(
"w-full text-left p-3 rounded-lg transition-colors hover:bg-accent",
selectedEntityName === table.name && "bg-accent text-accent-foreground"
selectedEntityName === table.schema.name && "bg-accent text-accent-foreground"
)}
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 flex-1 min-w-0">
<Table className="h-4 w-4 flex-shrink-0" />
<span className="font-medium truncate">{table.name}</span>
<span className="font-medium truncate">{table.schema.name}</span>
</div>
<Badge
variant={table.type === "auth" ? "default" : table.type === "view" ? "secondary" : "outline"}
variant={table.schema.type === "auth" ? "default" : table.schema.type === "view" ? "secondary" : "outline"}
className="text-xs flex-shrink-0 ml-2"
>
{table.type}
{table.schema.type}
</Badge>
</div>
<div className="text-xs text-muted-foreground mt-1">

View File

@@ -56,7 +56,7 @@ const FilePreviewField = ({
const getFileUrl = (file: File | string): string => {
if (typeof file === "string") {
return `${getApiBaseUrl()}/api/files/${table.name}/${encodeURIComponent(file)}`;
return `${getApiBaseUrl()}/api/files/${table.schema.name}/${encodeURIComponent(file)}`;
}
return URL.createObjectURL(file); // for newly selected files
};
@@ -122,7 +122,7 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
setFormData({ ...item })
setHasUnsavedChanges(false)
setTableFields(table.schema?.fields.filter(f => !isSystemGeneratedField(f)))
setIsViewIsViewType(table?.type === "view")
setIsViewIsViewType(table?.schema?.type === "view")
}
}, [open, item])
@@ -193,7 +193,7 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
return;
}
const updatedItem = await apiClient.call<any>(`/api/v1/entities/${table.name}/${formData["id"]}`, {
const updatedItem = await apiClient.call<any>(`/api/v1/entities/${table?.schema?.name}/${formData["id"]}`, {
method: "PATCH",
body: body,
})
@@ -324,7 +324,7 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
<X className="h-4 w-4" />
</Button>
</div>
<DrawerDescription>Edit record in {table.name} table</DrawerDescription>
<DrawerDescription>Edit record in {table.schema.name} table</DrawerDescription>
</DrawerHeader>
<div className="flex-1 overflow-hidden">
@@ -396,7 +396,7 @@ export function EditItemDrawer({ table, item, apiClient, open, onClose, onItemUp
{isDisabled && (
<p className="text-xs text-muted-foreground">System generated field - cannot be modified</p>
)}
{table.type === "auth" && field.name === "password" && (
{table.schema.type === "auth" && field.name === "password" && (
<p className="text-xs text-muted-foreground">Password fields are redacted in API responses.</p>
)}
</div>

View File

@@ -61,7 +61,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
React.useEffect(() => {
if (open) {
setColumns(table.schema?.fields.map(col => ({ ...col, old_name: col.name })) || [])
setRules({ addRule: table.schema.addRule, listRule: table.schema.listRule, getRule: table.schema.getRule, updateRule: table.schema.updateRule, deletRule: table.schema.deleteRule })
setRules({ addRule: table.schema.rules.add, listRule: table.schema.rules.list, getRule: table.schema.rules.get, updateRule: table.schema.rules.update, deletRule: table.schema.rules.delete })
setHasUnsavedChanges(false)
setSystemFieldsCollapsed(true)
setDeletedColumns([])
@@ -197,7 +197,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<Cog className="h-5 w-5" />
<DrawerTitle>Configure {table.name} Table</DrawerTitle>
<DrawerTitle>Configure {table.schema.name} Table</DrawerTitle>
</div>
<Button variant="ghost" size="sm" onClick={onClose}>
<X className="h-4 w-4" />
@@ -221,7 +221,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
<h4 className="text-lg font-medium">Table Structure</h4>
<p className="text-sm text-muted-foreground">Modify columns and their properties</p>
</div>
{table.type !== "view" && (
{table.schema.type !== "view" && (
<Button type="button" variant="outline" size="sm" onClick={addColumn}>
<Plus className="h-4 w-4 mr-2" />
Add Column
@@ -229,7 +229,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
)}
</div>
{table.type === "view" ? (
{table.schema.type === "view" ? (
<div className="p-4 bg-muted rounded-lg">
<h5 className="font-medium mb-3">SQL Query</h5>
<ScrollArea className="h-32">
@@ -667,7 +667,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
</>
)}
{table.type !== "view" && (
{table.schema.type !== "view" && (
<div className="text-sm text-muted-foreground p-3 bg-muted/50 rounded-lg">
<div>
<Badge variant="outline" className="text-xs mr-2">
@@ -720,7 +720,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda
<p className="text-xs text-muted-foreground mt-1">Controls who can view individual records</p>
</div>
{table.type !== "view" && (
{table.schema.type !== "view" && (
<>
<div>
<Label htmlFor="add-rule" className="text-sm font-medium">

View File

@@ -61,8 +61,8 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
}, [currentPage, appliedFilter])
React.useEffect(() => {
setIsViewType(table.type === "view")
}, [table.type])
setIsViewType(table.schema.type === "view")
}, [table.schema.type])
React.useEffect(() => {
setVisibleColumns(table.schema.fields?.map((field) => field.name) || [])
@@ -72,7 +72,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
setIsLoading(true)
try {
const response = await apiClient.call<any>(`/api/v1/entities/${table.name}`)
const response = await apiClient.call<any>(`/api/v1/entities/${table.schema.name}`)
// If the request failed, throw the error here
if (response?.error?.length > 0) throw response.error
@@ -120,7 +120,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
// Update URL with filter query param
const queryParams = filterTerm ? { filter: filterTerm } : {}
navigate("/entities/:name", { name: table.name }, queryParams)
navigate("/entities/:name", { name: table.schema.name }, queryParams)
}
const handleFilterKeyPress = (e: React.KeyboardEvent) => {
@@ -166,7 +166,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
try {
// Delete each selected item individually
const deletePromises = selectedItems.map((itemId) =>
apiClient.call(`/api/v1/entities/${table.name}/${itemId}`, { method: "DELETE" }),
apiClient.call(`/api/v1/entities/${table.schema.name}/${itemId}`, { method: "DELETE" }),
)
await Promise.all(deletePromises)
@@ -204,13 +204,13 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
case "file":
case "files": {
if(value==="" || value.length === 0) return "N/A";
if(!value || value==="" || value.length === 0) return "N/A";
const filenames = Array.isArray(value) ? value : [value];
return (
<div className="flex gap-2 flex-wrap">
{filenames.map((filename: string, i: number) => {
const url = `${getApiBaseUrl()}/api/files/${table.name}/${encodeURIComponent(filename)}`;
const url = `${getApiBaseUrl()}/api/files/${table.schema.name}/${encodeURIComponent(filename)}`;
const ext = filename.split(".").pop()?.toLowerCase() || "";
const isImage = ["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg"].includes(ext);
@@ -248,7 +248,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
<div className="flex items-center justify-between">
<div>
<h2 className="text-2xl font-bold">
Entity <span className="text-primary font-mono italic">'{table.name}'</span> data
Entity <span className="text-primary font-mono italic">'{table.schema.name}'</span> data
</h2>
</div>
<div className="flex gap-2">
@@ -297,7 +297,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
onClick={() => {
setFilterTerm("")
setAppliedFilter("")
navigate("/entities/:name", { name: table.name }, {})
navigate("/entities/:name", { name: table.schema.name }, {})
}}
className="h-6 text-xs"
>
@@ -312,7 +312,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate }: Tab
<div className="flex items-center justify-between">
<div>
<CardTitle>Table Data</CardTitle>
<CardDescription>Current records in the {table.name} table</CardDescription>
<CardDescription>Current records in the {table.schema.name} table</CardDescription>
</div>
<div className="flex items-center gap-2">
{selectedItems.length > 0 && (

View File

@@ -29,7 +29,7 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<FileText className="h-5 w-5" />
<DrawerTitle>API Documentation - {table.name}</DrawerTitle>
<DrawerTitle>API Documentation - {table.schema.name}</DrawerTitle>
</div>
<Button variant="ghost" size="sm" onClick={onClose}>
<X className="h-4 w-4" />
@@ -43,15 +43,15 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
<div className="p-6 space-y-6">
<ApiEndpointCard
method="GET"
endpoint={`/api/v1/entities/${table.name}`}
description={`List all records in the ${table.name} table`}
endpoint={`/api/v1/entities/${table.schema.name}`}
description={`List all records in the ${table.schema.name} table`}
table={table}
operation="list"
/>
<ApiEndpointCard
method="GET"
endpoint={`/api/v1/entities/${table.name}/{id}`}
endpoint={`/api/v1/entities/${table.schema.name}/{id}`}
description="Get a specific record by ID"
table={table}
operation="get"
@@ -61,7 +61,7 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
<>
<ApiEndpointCard
method="POST"
endpoint={`/api/v1/entities/${table.name}`}
endpoint={`/api/v1/entities/${table.schema.name}`}
description="Create a new record"
table={table}
operation="create"
@@ -69,7 +69,7 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
<ApiEndpointCard
method="PATCH"
endpoint={`/api/v1/entities/${table.name}/{id}`}
endpoint={`/api/v1/entities/${table.schema.name}/{id}`}
description="Update a specific record"
table={table}
operation="update"
@@ -77,7 +77,7 @@ export function TableRecordDocsDrawer({ table, open, onClose }: TableDocsDrawerP
<ApiEndpointCard
method="DELETE"
endpoint={`/api/v1/entities/${table.name}/{id}`}
endpoint={`/api/v1/entities/${table.schema.name}/{id}`}
description="Delete a specific record"
table={table}
operation="delete"