Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(next): pass through query params from document view to find operations #10343

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

AlessioGr
Copy link
Member

Say you opened http://localhost:3000/admin/collections/posts/67786e917283ec71ce4ab058?branch=main, the branch=main query param would not be passed to the find operation.

This means that reading req.query in, say, an afterRead hook, you would get an empty object back.

This PR threads through query, search and searchParams with the main goal of making them accessible in hooks.

Use-case

Custom branch selector component in a collection's edit view.

Select branch => branch query param is added to the URL.

Collection afterRead hook then fetches the respective content from that branch (which it gets from req.query) and returns its data

@@ -31,6 +40,11 @@ export const getDocumentData = async ({
fallbackLocale: false,
locale: locale?.code,
overrideAccess: false,
req: {
Copy link
Member

Choose a reason for hiding this comment

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

Feels odd to construct a new req object here instead of passing it through outright. I imagine this is to reduce the size of the actual request as much as possible. Pretty sure you wouldn't have to send user as a stand-alone property in this case.

Copy link
Member Author

@AlessioGr AlessioGr Jan 6, 2025

Choose a reason for hiding this comment

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

imagine this is to reduce the size of the actual request as much as possible

Doesn't matter since this all runs on the server anyways.

I mainly wanted to avoid the overhead of spreading req in order to remove/isolate the transactionID

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense

@AlessioGr AlessioGr merged commit 4a15b86 into main Jan 6, 2025
74 checks passed
@AlessioGr AlessioGr deleted the feat/pass-through-queryparams branch January 6, 2025 02:31
Copy link
Contributor

github-actions bot commented Jan 7, 2025

🚀 This is included in version v3.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants