Skip to content

[8773] Handle "*" in pages/components data sources#4907

Open
jvega190 wants to merge 2 commits into
craftercms:developfrom
jvega190:bugfix/8773
Open

[8773] Handle "*" in pages/components data sources#4907
jvega190 wants to merge 2 commits into
craftercms:developfrom
jvega190:bugfix/8773

Conversation

@jvega190

@jvega190 jvega190 commented Jul 6, 2026

Copy link
Copy Markdown
Member

craftercms/craftercms#8773

Summary by CodeRabbit

  • Bug Fixes
    • Improved item selection for components and pages data sources by correctly expanding wildcard content type settings.
    • Made the available item list update when content type options change, ensuring the picker stays in sync with current content types.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@jvega190, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 14 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84b0c889-a118-4600-ba2a-0bb76dafb6bd

📥 Commits

Reviewing files that changed from the base of the PR and between 21ed5d1 and 3af892d.

📒 Files selected for processing (1)
  • ui/app/src/components/FormsEngine/dataSourceHooks/useConsolidatedItemPickerData.ts

Walkthrough

The useConsolidatedItemPickerData hook now resolves the "*" wildcard in contentTypes properties of components/pages data sources into concrete content type IDs, sourced via useContentTypeList(), before parsing. The useMemo dependency array now includes contentTypes.

Changes

Wildcard Content Type Resolution

Layer / File(s) Summary
Resolver and data source integration
ui/app/src/components/FormsEngine/dataSourceHooks/useConsolidatedItemPickerData.ts
Adds a helper resolving the "*" wildcard into comma-separated content type IDs filtered by components/pages type, sources content types via useContentTypeList(), wires the resolved IDs into the components/pages switch branch replacing raw property usage, and updates the useMemo dependency array to include contentTypes.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

Possibly related PRs

  • craftercms/studio-ui#4867: Both PRs modify useConsolidatedItemPickerData handling of pages/components data source types, building on the same routing logic.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: handling "*" in pages/components data sources.
Description check ✅ Passed The description provides the required ticket reference, but adds no actual change summary beyond the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@ui/app/src/components/FormsEngine/dataSourceHooks/useConsolidatedItemPickerData.ts`:
- Around line 37-54: The non-wildcard path in
resolveComponentsDataSourceContentTypes is coercing missing values to an empty
string, which breaks the downstream
parseComponentsDataSourceContentTypesProperty behavior and can introduce a
phantom content type id. Update the function to preserve the original
contentTypesProperty value in the non-wildcard case, and return undefined
instead of an empty string while contentTypes is still unavailable/loading. Keep
the wildcard handling intact so the filtering and id-joining logic only runs
when contentTypes is present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de592b00-07fd-4fcd-bd48-94fcf5f30a66

📥 Commits

Reviewing files that changed from the base of the PR and between 7d8ec52 and 21ed5d1.

📒 Files selected for processing (1)
  • ui/app/src/components/FormsEngine/dataSourceHooks/useConsolidatedItemPickerData.ts

…roperty for non-wildcard inputs and handle loading state for wildcard content types.
@jvega190

jvega190 commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai can you check if everything looks good? Please give it a final review before I hand over for human review

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
gh pr view 4907 --repo craftercms/studio-ui --json title,body,files,additions,deletions,changedFiles
echo "----"
gh pr diff 4907 --repo craftercms/studio-ui

Length of output: 5396


🏁 Script executed:

#!/bin/bash
fd useContentTypeList.ts
echo "---hook---"
cat ui/app/src/hooks/useContentTypeList.ts 2>/dev/null

echo "---ContentType model---"
fd ContentType.ts ui/app/src/models
cat ui/app/src/models/ContentType.ts 2>/dev/null | head -60

echo "---parseComponentsDataSourceContentTypesProperty---"
rg -n "parseComponentsDataSourceContentTypesProperty" ui/app/src/services/contentTypes.ts -A 40

Length of output: 7258


🏁 Script executed:

#!/bin/bash
grep -n "type" ui/app/src/models/ContentType.ts | head -30
echo "---"
rg -n "type:\s*'page'|type:\s*'component'|\.type ===" ui/app/src/models/ContentType.ts ui/app/src/services/contentTypes.ts | head -30
echo "---usage of contentType.type elsewhere---"
rg -n "contentType\.type\b" ui/app/src --type ts | head -20

Length of output: 4171


🏁 Script executed:

#!/bin/bash
rg -n "type:" ui/app/src/models/DataSource.ts 2>/dev/null
fd DataSource.ts ui/app/src/models
cat ui/app/src/models/DataSource.ts 2>/dev/null | head -80

Length of output: 302


🏁 Script executed:

#!/bin/bash
rg -n "interface DataSource\b|type DataSource\b|ComponentsDatasource" ui/app/src/models -r "" | head -20
rg -rn "export interface DataSource" ui/app/src/models 2>/dev/null
grep -rn "ComponentsDatasource" ui/app/src/models/*.ts

Length of output: 645


🏁 Script executed:

#!/bin/bash
sed -n '140,175p;280,400p' ui/app/src/models/ContentType.ts

Length of output: 4715


🏁 Script executed:

#!/bin/bash
fd useConsolidatedItemPickerData
rg -n "useConsolidatedItemPickerData" ui/app/src --type ts -l

Length of output: 471


@jvega190 I took a close look at the diff in useConsolidatedItemPickerData.ts and the change looks solid overall. Here's my final review before you hand it off:

What looks good:

  • resolveComponentsDataSourceContentTypes correctly expands "*" into the list of applicable content type ids, filtering by contentType.type === 'component' (for components datasources) or 'page' (for pages datasources). This matches the same filtering convention used elsewhere in the codebase (e.g., PreviewSearchPanel.tsx, PreviewBrowseComponentsPanel.tsx, PreviewDropTargetsPanel.tsx), so it's consistent with existing patterns.
  • The loading-state edge case is handled sensibly: useContentTypeList() returns null before content types are loaded, and in that case the helper returns undefined, which now short-circuits to allowedContentTypesData = {} instead of feeding undefined into parseComponentsDataSourceContentTypesProperty/.split(',').
  • Adding contentTypes to the useMemo dependency array ensures the picker data recomputes once content types finish loading — so the transient empty state self-corrects.
  • The ds.type as 'components' | 'pages' cast is necessary (not a smell) because DataSource.type is typed as a plain string in the model, so TS can't narrow it from the switch case labels alone.
  • The .trim() !== '*' check reasonably guards against accidental whitespace in the property value.

Minor, non-blocking suggestions:

  • Since resolveComponentsDataSourceContentTypes is pure logic, consider adding a small unit test for it (e.g., wildcard for components, wildcard for pages, non-wildcard passthrough, and contentTypes === null producing undefined) — it'd be cheap insurance given it's not currently exported/tested.
  • Worth double-checking there isn't a flash-of-empty-selection UX concern while content types are still loading and a wildcard datasource is present, though this seems like an acceptable transient state given the existing loading patterns in this hook.

Nothing blocking — nice, focused fix for #8773. Good to go for human review from my side.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jvega190
jvega190 marked this pull request as ready for review July 6, 2026 16:48
@jvega190
jvega190 requested a review from rart as a code owner July 6, 2026 16:48
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