Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions apps/web-dashboard/src/components/CollectionTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,31 @@ const DraggableColumnHeader = ({ header, children, style: propStyle, className }
export default function CollectionTable({ data, activeCollection, onDelete, onView, onEdit }) {
// 1. Column Definitions
const columns = useMemo(() => {
if (!activeCollection?.model) return [];
if (!activeCollection) return [];

const SYSTEM_FIELDS = ['_id', '__v', 'createdAt', 'updatedAt'];

const inferType = (value) => {
if (typeof value === 'boolean') return 'BOOLEAN';
if (typeof value === 'number') return 'NUMBER';
if (Array.isArray(value)) return 'ARRAY';
return 'STRING';
};
Comment thread
KushagraJaiswar02 marked this conversation as resolved.

const baseColumns = activeCollection.model?.length > 0
? activeCollection.model.map(field => ({
key: field.key,
type: field.type
}))
: data?.length > 0
Comment thread
KushagraJaiswar02 marked this conversation as resolved.
? Object.entries(data[0])
.filter(([key]) => !SYSTEM_FIELDS.includes(key))
.map(([key, value]) => ({
key,
type: inferType(value)
}))
Comment thread
KushagraJaiswar02 marked this conversation as resolved.
: [];
Comment thread
KushagraJaiswar02 marked this conversation as resolved.
Comment thread
KushagraJaiswar02 marked this conversation as resolved.

return [
{
id: "rowNumber",
Expand All @@ -87,11 +111,10 @@ export default function CollectionTable({ data, activeCollection, onDelete, onVi
enableResizing: false,
enableHiding: false,
},
...activeCollection.model.map((field) => ({
id: field.key, // Explicit ID matches accessorKey usually
...baseColumns.map((field) => ({
id: field.key,
header: () => (
<div className="th-content">
{/* Drag Handle Indicator (Visual only, whole header is draggable) */}
<GripVertical size={12} className="drag-handle" style={{ marginRight: 6, opacity: 0.5 }} />
{field.key}
<span className="type-badge">{field.type}</span>
Expand All @@ -103,15 +126,15 @@ export default function CollectionTable({ data, activeCollection, onDelete, onVi
maxSize: 500,
cell: (info) => {
const value = info.getValue();
if (value === null || value === undefined) return <span className="text-muted">—</span>;
if (typeof value === "boolean") {
return (
<span className={`status-badge ${value ? "success" : "danger"}`}>
{String(value)}
</span>
);
}
// Object type — show preview
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
if (typeof value === "object" && !Array.isArray(value)) {
const keys = Object.keys(value).filter(k => !k.startsWith('_'));
return (
<div className="cell-content" title={JSON.stringify(value, null, 2)}
Expand All @@ -120,7 +143,6 @@ export default function CollectionTable({ data, activeCollection, onDelete, onVi
</div>
);
}
// Array type — show count
if (Array.isArray(value)) {
return (
<div className="cell-content" title={JSON.stringify(value, null, 2)}
Expand All @@ -130,8 +152,8 @@ export default function CollectionTable({ data, activeCollection, onDelete, onVi
);
}
return (
<div className="cell-content" title={String(value ?? '')}>
{String(value ?? '')}
<div className="cell-content" title={String(value)}>
{String(value)}
</div>
);
},
Expand Down Expand Up @@ -183,7 +205,7 @@ export default function CollectionTable({ data, activeCollection, onDelete, onVi
),
},
];
}, [activeCollection, onDelete, onView, onEdit]);
}, [activeCollection, data, onDelete, onView, onEdit]);

// 2. Load Persisted State
const storageKey = `table-settings-${activeCollection?._id}`;
Expand Down
54 changes: 28 additions & 26 deletions apps/web-dashboard/src/pages/Database.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,32 +413,34 @@ export default function Database() {
<div className="header-actions">
<span className="record-count">{data.length} Records</span>

<div className="view-toggle">
<button
className={`toggle-btn ${viewMode === "list" ? "active" : ""
}`}
onClick={() => setViewMode("list")}
title="List View"
>
<ListIcon size={16} />
</button>
<button
className={`toggle-btn ${viewMode === "table" ? "active" : ""
}`}
onClick={() => setViewMode("table")}
title="Table View (Advanced)"
>
<TableIcon size={16} />
</button>
<button
className={`toggle-btn ${viewMode === "json" ? "active" : ""
}`}
onClick={() => setViewMode("json")}
title="JSON View"
>
<Code size={16} />
</button>
</div>
{(activeCollection?.model?.length > 0 || data?.length > 0) && (
<div className="view-toggle">
<button
className={`toggle-btn ${viewMode === "list" ? "active" : ""
}`}
onClick={() => setViewMode("list")}
title="List View"
>
<ListIcon size={16} />
</button>
<button
className={`toggle-btn ${viewMode === "table" ? "active" : ""
}`}
onClick={() => setViewMode("table")}
title="Table View (Advanced)"
>
<TableIcon size={16} />
</button>
<button
className={`toggle-btn ${viewMode === "json" ? "active" : ""
}`}
onClick={() => setViewMode("json")}
title="JSON View"
>
<Code size={16} />
</button>
</div>
)}

<div style={{ position: 'relative' }}>
<button
Expand Down
Loading