fix(next): ensure query preset from url is applied#15323
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
| } | ||
| } | ||
|
|
||
| if (collectionPreferences?.preset) { |
There was a problem hiding this comment.
Moved this piece of code to the top of the function, as data returned here needs to be used earlier to apply the preset
| collectionConfig: clientCollectionConfig, | ||
| collectionSlug, | ||
| columns: collectionPreferences?.columns, | ||
| columns: columnPreference, |
There was a problem hiding this comment.
columns can now come from the preset => we shouldn't just blindly take them from the preferences
| await expect(field.locator('.react-select--single-value')).toHaveText(fieldLabel) | ||
|
|
||
| await expect(page).toHaveURL(new RegExp(`&groupBy=${fieldPath}`)) | ||
| await expect(page).toHaveURL(new RegExp(`[&?]groupBy=${fieldPath}`)) |
There was a problem hiding this comment.
The position of groupBy in the URL does not matter, we only need to assert that it is present
| if (queryPreset?.where && !query.where) { | ||
| query.where = queryPreset.where | ||
| } | ||
| query.groupBy = query.groupBy ?? queryPreset?.groupBy ?? collectionPreferences?.groupBy |
There was a problem hiding this comment.
The priority: query > preset > preferences.
The expectation is that if ONLY preset is present in query params, we take the where/groupBy from the preset.
If preset is present with the where query, we need to respect the where query even if it differs from the preset's where query. Otherwise, the following will not work anymore:
- select preset
- update where query in ui
- click on "update preset". Wouldn't work if we don't respect the where query update
|
🚀 This is included in version v3.74.0 |
Previously, if you visited the list view from a URL that contains the
presetparam (e.g.http://localhost:3000/admin/collections/pages?preset=69728460f29c932fb002feb9), the preset would not be applied.This PR is ensured the preset is applied and adds an e2e test to verify this functionality