Skip to content

Commit 2a48f52

Browse files
committed
Enhance ObjectListView with custom cell editors and link navigation
Added dynamic cell editors and formatters for number, date, boolean, and badge fields in the ObjectListView AgGrid columns. The 'name' and 'title' fields now render as clickable links for navigation, and row click navigation is removed to allow cell editing and selection without interference.
1 parent b9e490b commit 2a48f52

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

packages/client/src/components/dashboard/ObjectListView.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,66 @@ export function ObjectListView({ objectName, user, isCreating, navigate, objectS
186186
}
187187

188188
return fields.map(key => {
189+
const field = objectSchema?.fields?.[key];
189190
const type = getFieldType(key);
190191

192+
let cellEditor = 'agTextCellEditor';
193+
let cellEditorParams = {};
194+
let valueFormatter = undefined;
195+
196+
if (type === 'number') {
197+
cellEditor = 'agNumberCellEditor';
198+
} else if (type === 'date') {
199+
cellEditor = 'agDateStringCellEditor';
200+
valueFormatter = (params: any) => {
201+
if (!params.value) return '';
202+
return new Date(params.value).toLocaleDateString();
203+
};
204+
} else if (type === 'boolean') {
205+
cellEditor = 'agSelectCellEditor';
206+
cellEditorParams = {
207+
values: [true, false]
208+
};
209+
} else if (type === 'badge' && field?.options) {
210+
cellEditor = 'agSelectCellEditor';
211+
cellEditorParams = {
212+
values: field.options
213+
};
214+
}
215+
216+
// Determine if this is the primary link field (name or title)
217+
const isLinkField = key === 'name' || key === 'title';
218+
191219
return {
192-
field: key, // AgGrid uses 'field' instead of 'id'
220+
field: key,
193221
headerName: getFieldLabel(key),
222+
// If it's a link field, we might want to disable inline editing to prevent conflict,
223+
// or keep it editable but the link click takes precedence.
224+
// Usually for primary navigation fields, inline editing is disabled or requires specific action.
225+
// Let's keep it editable but render a link.
226+
// However, AgGrid editing is usually double-click.
227+
// If single click navigates, double click might be hard.
228+
// Let's assume name/title navigation is primary.
194229
editable: !['id', 'createdBy', 'updatedBy', 'createdAt', 'updatedAt'].includes(key),
195230
sortable: true,
196231
filter: true,
197232
resizable: true,
233+
cellEditor,
234+
cellEditorParams,
235+
valueFormatter,
198236
width: type === 'boolean' ? 100 : type === 'date' ? 180 : type === 'number' ? 120 : 200,
199-
// Optional: Custom cell renderers can be added here if needed
237+
cellRenderer: isLinkField ? (params: any) => (
238+
<span
239+
className="text-blue-600 hover:text-blue-800 hover:underline cursor-pointer font-medium"
240+
onClick={(e) => {
241+
// Stop row selection when clicking the link
242+
e.stopPropagation();
243+
navigate(`/object/${objectName}/${params.data.id || params.data._id}`);
244+
}}
245+
>
246+
{params.value}
247+
</span>
248+
) : undefined
200249
};
201250
});
202251
};
@@ -301,7 +350,8 @@ export function ObjectListView({ objectName, user, isCreating, navigate, objectS
301350
<AgGridView
302351
columns={columns}
303352
data={data}
304-
onRowClick={(row: any) => navigate(`/object/${objectName}/${row.id || row._id}`)}
353+
// onRowClick removed to allow cell editing/selection without navigating
354+
// Navigation is now handled by the 'name'/'title' column renderer
305355
onCellEdit={handleCellEdit}
306356
onDelete={handleDelete}
307357
enableSorting={true}

0 commit comments

Comments
 (0)