Skip to content

Commit 324c5b5

Browse files
Copilothotlong
andcommitted
fix: use record.name instead of record.id for grid row lookups
ObjectGrid applies $select using only column fields, which strips the `id` property from records returned by ValueDataSource.find(). This caused handleRowClick, handleEdit, and handleDelete to fail silently since objects.find(o => o.id === record.id) always returned undefined. Fixed by matching on `name` (which IS in the grid columns) instead of `id` in both ObjectManager and FieldDesigner. Also strengthened the ObjectManagerPage click-to-navigate test to assert the detail view actually renders after clicking a primary-field-link. Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/2766f2c6-b5ea-42f9-8327-dd8201c1afb7 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 1c69eaa commit 324c5b5

File tree

4 files changed

+21
-81
lines changed

4 files changed

+21
-81
lines changed

apps/console/src/__tests__/ObjectManagerPage.test.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,21 @@ describe('ObjectManagerPage', () => {
155155
it('should navigate to detail when primary field link is clicked', async () => {
156156
renderPage();
157157

158-
// ObjectGrid renders data asynchronously. Primary field links are auto-generated.
158+
// ObjectGrid renders data asynchronously via ValueDataSource.
159+
// Wait for primary-field-link buttons to appear.
159160
await waitFor(() => {
160161
const links = screen.queryAllByTestId('primary-field-link');
161-
if (links.length > 0) {
162-
fireEvent.click(links[0]);
163-
}
164-
});
162+
expect(links.length).toBeGreaterThan(0);
163+
}, { timeout: 5000 });
164+
165+
// Click the first primary field link (should be 'account')
166+
const links = screen.getAllByTestId('primary-field-link');
167+
fireEvent.click(links[0]);
165168

166-
// Either detail view shows (if link was found) or list remains
167-
const detailView = screen.queryByTestId('object-detail-view');
168-
const objectManager = screen.queryByTestId('object-manager');
169-
expect(detailView || objectManager).toBeDefined();
169+
// Should navigate to the object detail view
170+
await waitFor(() => {
171+
expect(screen.getByTestId('object-detail-view')).toBeDefined();
172+
});
170173
});
171174
});
172175
});

apps/console/src/__tests__/click_test.test.tsx

Lines changed: 0 additions & 67 deletions
This file was deleted.

packages/plugin-designer/src/FieldDesigner.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,15 @@ export function FieldDesigner({
565565
}), [gridColumns]);
566566

567567
// Handlers
568+
// Note: ObjectGrid applies $select using column fields, which strips `id`.
569+
// Use `name` (always in columns) as the lookup key instead of `id`.
568570
const handleEdit = useCallback((record: Record<string, unknown>) => {
569-
const field = fields.find((f) => f.id === record.id);
571+
const field = fields.find((f) => f.name === record.name);
570572
if (field) setEditingField(field);
571573
}, [fields]);
572574

573575
const handleDelete = useCallback(async (record: Record<string, unknown>) => {
574-
const field = fields.find((f) => f.id === record.id);
576+
const field = fields.find((f) => f.name === record.name);
575577
if (!field || field.isSystem) return;
576578
const confirmed = await confirmDialog.confirm(
577579
t('appDesigner.fieldDesigner.deleteConfirmTitle'),

packages/plugin-designer/src/ObjectManager.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,23 @@ export function ObjectManager({
120120
}), [gridColumns]);
121121

122122
// Handlers
123+
// Note: ObjectGrid applies $select using column fields, which strips `id`.
124+
// Use `name` (always in columns) as the lookup key instead of `id`.
123125
const handleRowClick = useCallback((record: Record<string, unknown>) => {
124-
const obj = objects.find((o) => o.id === record.id);
126+
const obj = objects.find((o) => o.name === record.name);
125127
if (obj) onSelectObject?.(obj);
126128
}, [objects, onSelectObject]);
127129

128130
const handleEdit = useCallback((record: Record<string, unknown>) => {
129-
const obj = objects.find((o) => o.id === record.id);
131+
const obj = objects.find((o) => o.name === record.name);
130132
if (obj) {
131133
setEditingObject(obj);
132134
setFormOpen(true);
133135
}
134136
}, [objects]);
135137

136138
const handleDelete = useCallback(async (record: Record<string, unknown>) => {
137-
const obj = objects.find((o) => o.id === record.id);
139+
const obj = objects.find((o) => o.name === record.name);
138140
if (!obj || obj.isSystem) return;
139141
const confirmed = await confirmDialog.confirm(
140142
t('appDesigner.objectManager.deleteConfirmTitle'),

0 commit comments

Comments
 (0)