Add support for nested property names of same value#40
Add support for nested property names of same value#40
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for disambiguating same-named fields that exist at different nesting levels (notably within collections) by allowing ui.fields entries to be resolved via qualified IDs (e.g., sightings.name) instead of only local property names.
Changes:
- Extend
createControl/generateCollectionUISchemaInternalto propagate and use acollectionIdso collection-itemui.fieldscan be resolved via qualified IDs. - Update V2 mock schema data to match the new server format using qualified field IDs for collection item fields.
- Add a unit test covering the collision scenario (top-level
namevs.sightings[].name).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/v2.test.ts | Adds a regression test validating correct resolution of same-named fields via qualified IDs. |
| src/v2/utils.ts | Implements qualified-id lookup for collection item UI field configuration and propagates collectionId for nested collections. |
| src/v2/mockData.ts | Updates mock V2 schema ui.fields and collection column entries to use qualified IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const qualifiedId = `${collectionId}.${localName}`; | ||
| const itemUiField = schema.ui.fields[qualifiedId] ?? schema.ui.fields[localName]; | ||
|
|
||
| if (itemUiField) { | ||
| return createControl( | ||
| fieldName, | ||
| localName, | ||
| property as V2Property, | ||
| itemUiField, | ||
| schema, | ||
| undefined, | ||
| qualifiedId, | ||
| ); |
There was a problem hiding this comment.
itemUiField falls back to schema.ui.fields[localName] when the qualified entry is missing. In schemas with same-named fields at different levels, this can still accidentally pick up an unrelated UI config (e.g., the top-level name) and apply it to a collection item field, effectively reintroducing the collision when only one side is qualified. Consider restricting the fallback to cases where the unqualified field's parent matches the current collection (e.g., itemUiField.parent === collectionId or === collectionId.split('.').pop()) so an unrelated top-level field config is not applied to collection items.
Adds support for #39
Proposed Changes
src/v2/utils.ts
createControlcollectionId?: stringparametergenerateCollectionUISchemaInternalcollectionId: stringparametersrc/v2/mockData.ts
v2.test.ts
ui.fieldsentry via the qualified IDImplementation Test
In React Native client app, e.g. EarthRanger
Unit Tests