Skip to content

[8216] Update dropTargetsLookup in parseLegacyFormDefinition to use new DataSource type instead of legacy.#4806

Open
jvega190 wants to merge 2 commits intocraftercms:developfrom
jvega190:enhancement/8216
Open

[8216] Update dropTargetsLookup in parseLegacyFormDefinition to use new DataSource type instead of legacy.#4806
jvega190 wants to merge 2 commits intocraftercms:developfrom
jvega190:enhancement/8216

Conversation

@jvega190
Copy link
Member

@jvega190 jvega190 commented Feb 18, 2026

  • Update dropTargetsLookup in parseLegacyFormDefinition to use new DataSource type instead of legacy
  • Fix node selector create component

craftercms/craftercms#8216

Summary by CodeRabbit

  • Refactor
    • Enhanced data source creation logic with improved handling of embedded and non-embedded strategies
    • Improved backward compatibility for legacy data source configurations while supporting newer formats
    • Modernized internal type system for more consistent data handling across the forms engine

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Walkthrough

The changes update data source handling across multiple components to support an embedded flag in the node selector creation flow and transition from LegacyDataSource to DataSource types in content type parsing, while maintaining backward compatibility with legacy property names (baseRepoPath).

Changes

Cohort / File(s) Summary
Node Selector Component
ui/app/src/components/FormsEngine/controls/NodeSelector.tsx
Updated create flow to include embedded flag derived from selected strategy. Key derivation now uses result.values.objectId for embedded items or result.path for non-embedded, replacing previous fileName/objectId combination logic.
Data Source Type Migration & Utilities
ui/app/src/components/FormsEngine/dataSourceHooks/useConsolidatedItemPickerData.ts, ui/app/src/services/contentTypes.ts
Migrated from LegacyDataSource to DataSource types across content type parsing and validation. Updated property access patterns to support both baseRepositoryPath (new) and baseRepoPath (legacy) properties. Simplified allowEmbedded/allowShared/allowSharedExisting checks using direct property values instead of derived lookups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • Issue #8216 addresses the same parseComponentsDataSourceContentTypesProperty signature change and dropTargetsLookup type migration from LegacyDataSource to DataSource in contentTypes.ts.

Possibly related PRs

  • PR #4421 modifies NodeSelector key derivation by removing .xml suffix for embedded items, relating to the embedded flag key logic changes in this PR.
  • PR #4528 adds datasource parameter handling to newInsertItem in NodeSelector, connecting to the updated create payload and key derivation flow.

Suggested reviewers

  • rart
  • sumerjabri
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: updating dropTargetsLookup to use new DataSource type instead of legacy, which is reflected across the contentTypes.ts file changes.
Description check ✅ Passed The description covers the main objectives (updating DataSource type and fixing NodeSelector) and includes the ticket reference, meeting the template requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
ui/app/src/components/FormsEngine/controls/NodeSelector.tsx (1)

529-530: isEmbedded is already defined on line 524 — reuse it.

Both path and embedded recompute pickerChoice.strategy === 'embedded' inline, which is redundant.

♻️ Proposed simplification
-            path: pickerChoice.strategy === 'embedded' ? contextItem.path : processPath(pickerChoice.path),
-            embedded: pickerChoice.strategy === 'embedded'
+            path: isEmbedded ? contextItem.path : processPath(pickerChoice.path),
+            embedded: isEmbedded
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ui/app/src/components/FormsEngine/controls/NodeSelector.tsx` around lines 529
- 530, The code redundantly recomputes pickerChoice.strategy === 'embedded' for
both path and embedded; reuse the already-computed boolean isEmbedded (declared
earlier on line 524) instead: set path to isEmbedded ? contextItem.path :
processPath(pickerChoice.path) and set embedded to isEmbedded, leaving
pickerChoice and processPath unchanged so the logic and semantics remain
identical.
ui/app/src/services/contentTypes.ts (1)

428-432: Stale comment and dead legacyDatasource mutation after the dropTargetsLookup assignment change.

Since dropTargetsLookup[datasource.id] now points to dataSources[datasource.id] (line 432), the legacyDatasource variable serves no purpose:

  • The comment on line 428 ("Also update legacyDatasource, since dropTargetsLookup references it…") is no longer true.
  • Line 429 (legacyDatasource.properties[property.name] = value;) is dead from dropTargetsLookup's perspective, but it also silently mutates datasource.properties (same object reference via the shallow copy) — an unintended side-effect.
  • legacyDatasource.type on line 431 is always equal to datasource.type.
♻️ Proposed cleanup
-    const legacyDatasource = { ...datasource };
     asArray(datasource.properties?.property).forEach((property) => {
       let value: unknown = property.value;
       // ...
       dataSources[datasource.id].properties[property.name] = value;
-      // Also update legacyDatasource, since dropTargetsLookup references it for 'components' type datasources.
-      legacyDatasource.properties[property.name] = value;
     });
-    if (legacyDatasource.type === 'components') {
+    if (datasource.type === 'components') {
       dropTargetsLookup[datasource.id] = dataSources[datasource.id];
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ui/app/src/services/contentTypes.ts` around lines 428 - 432, Remove the stale
comment and the dead mutation of legacyDatasource.properties — do not mutate
datasource.properties via legacyDatasource; instead delete the line setting
legacyDatasource.properties[property.name] and any comment claiming
dropTargetsLookup references legacyDatasource; ensure the conditional uses
datasource.type (e.g., if (datasource.type === 'components')) and keep the
assignment dropTargetsLookup[datasource.id] = dataSources[datasource.id] as-is
so we no longer rely on legacyDatasource or unintentionally mutate datasource
objects.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ui/app/src/components/FormsEngine/controls/NodeSelector.tsx`:
- Line 533: The create-flow key derivation is inconsistent: change the
isEmbedded branch that sets key (currently using result.values.objectId) to
mirror handleOpenItem's onSave logic by deriving the key from
(values[XmlKeys.fileName] || values.objectId), stripping a trailing ".xml" via
.replace(/\.xml$/, ''), so key generation for embedded items uses the same
preference and normalization as handleOpenItem's onSave (refer to key,
isEmbedded, result.values, XmlKeys.fileName, and handleOpenItem onSave).

In `@ui/app/src/services/contentTypes.ts`:
- Around line 172-183: The call to parseComponentsDataSourceContentTypesProperty
is using a stale narrow cast and passing non-strings to split; change the first
argument to be a DataSource (remove or replace the ComponentsDatasource cast)
when calling parseComponentsDataSourceContentTypesProperty, and ensure the
property value passed (and any other place using value?.split(',')) is
coerced/checked as a string (e.g. use typeof value === 'string' ? value :
String(value) or default to '' before splitting) so split is only invoked on
strings; update references to dropTargetsLookup[itemManagerId].properties,
systemValidationsKeysMap, validations, and immutableEmptyArray accordingly.

---

Nitpick comments:
In `@ui/app/src/components/FormsEngine/controls/NodeSelector.tsx`:
- Around line 529-530: The code redundantly recomputes pickerChoice.strategy ===
'embedded' for both path and embedded; reuse the already-computed boolean
isEmbedded (declared earlier on line 524) instead: set path to isEmbedded ?
contextItem.path : processPath(pickerChoice.path) and set embedded to
isEmbedded, leaving pickerChoice and processPath unchanged so the logic and
semantics remain identical.

In `@ui/app/src/services/contentTypes.ts`:
- Around line 428-432: Remove the stale comment and the dead mutation of
legacyDatasource.properties — do not mutate datasource.properties via
legacyDatasource; instead delete the line setting
legacyDatasource.properties[property.name] and any comment claiming
dropTargetsLookup references legacyDatasource; ensure the conditional uses
datasource.type (e.g., if (datasource.type === 'components')) and keep the
assignment dropTargetsLookup[datasource.id] = dataSources[datasource.id] as-is
so we no longer rely on legacyDatasource or unintentionally mutate datasource
objects.

@jvega190 jvega190 marked this pull request as ready for review February 18, 2026 16:07
@jvega190 jvega190 requested a review from rart as a code owner February 18, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments