Skip to content

fix: WhereBuilder component does not accept all valid Where queries#3087

Merged
AlessioGr merged 15 commits intomasterfrom
fix/3082
Aug 15, 2023
Merged

fix: WhereBuilder component does not accept all valid Where queries#3087
AlessioGr merged 15 commits intomasterfrom
fix/3082

Conversation

@AlessioGr
Copy link
Copy Markdown
Member

Description

Fixes #3082. This update brings both enhanced validation and additional flexibility to Where queries passed into the WhereBuilder from the URL search query params (the filter in the admin panel), while also adding valuable jsDocs for clarity.

Improvements:

  • The validateWhereQuery function has been reinforced to catch and reject any malformed or nonsensical queries that previously could cause errors.

  • Simplified Where queries are now supported. Queries such as where[text][equals]=example%20post, which do not fit the [or][and] format, were previously causing errors. The newly introduced transformWhereQuery function elegantly handles such queries, transforming them to fit the [or][and] constraints required by the component.

  • I have read and understand the CONTRIBUTING.md document in this repository

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have added tests that prove my fix is effective or that my feature works
  • Existing test suite passes locally with my changes
  • I have made corresponding changes to the documentation

…ting old ones got transformed and are not valid, as that would cause duplicates
@AlessioGr
Copy link
Copy Markdown
Member Author

AlessioGr commented Jul 26, 2023

One thing we could also do now is to make sure that the query is always simplified in the URL, by using a simplifyWhereQuery function. This will keep URLs simple and easier to understand.

The more complex, forced or[]and[] format can then only be used internally.

I don't know if that's a good idea, though. I also do not understand the way the current search query params are updated here: https://github.com/payloadcms/payload/blob/fix/3082/src/admin/components/elements/WhereBuilder/index.tsx#L106

Why do we care about the existing where params in the URL, which are merged with the new ones in newWhereQuery?
And what's the deal with paramsToKeep?

@jmikrut maybe you can chime in and give some input regarding that (& if that's a good thing to do in the first place)

@DanRibbens
Copy link
Copy Markdown
Contributor

Does this also address #2905? After reading the code, it seems like it would.

@AlessioGr
Copy link
Copy Markdown
Member Author

Does this also address #2905? After reading the code, it seems like it would.

Yep! This would also be addressed with this PR.

return whereFromSearch.or;
}
if (modifySearchQuery && whereFromSearch) {
if (validateWhereQuery(whereFromSearch)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Validating the where query here seems unnecessary, couldn't you just simply transform it? The transformer function will ensure it's returned in the correct format no matter what. No extra validation needed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jacobsfletch So, I have tried experimenting with removing that validate and ALWAYS transforming those where queries.

The problem here is, that for a valid where query, it would result in additional map operations in the transform step. With that additional validate step, we can skip the unnecessary transform for valid where queries, which will improve the performance. And valid where queries will happen a lot more common than invalid ones anyways.

I'd thus vote for keeping it this way

@AlessioGr AlessioGr merged commit fdfdfc8 into master Aug 15, 2023
@AlessioGr AlessioGr deleted the fix/3082 branch August 15, 2023 17:22
DanRibbens added a commit that referenced this pull request Aug 22, 2023
Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com>
Co-authored-by: Alessio Gravili <alessio@gravili.de>
Co-authored-by: PatrikKozak <patrik@trbl.design>
Co-authored-by: Lucas Blancas <lablancas@gmail.com>
Co-authored-by: Stef Gootzen <37367280+stefgootzen@users.noreply.github.com>
Co-authored-by: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com>
Co-authored-by: Jessica Chowdhury <67977755+JessChowdhury@users.noreply.github.com>
Co-authored-by: PatrikKozak <35232443+PatrikKozak@users.noreply.github.com>
Co-authored-by: Greg Willard <Wickett06@gmail.com>
Co-authored-by: James Mikrut <james@payloadcms.com>
Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
Co-authored-by: Elliot DeNolf <denolfe@gmail.com>
fix: WhereBuilder component does not accept all valid Where queries (#3087)
fix: passes in height to resizeOptions upload option to allow height resize (#3171)
AlessioGr added a commit that referenced this pull request Aug 22, 2023
BREAKING CHANGE:
- Unhandled Errors are now omitted by default. This can be breaking if people depend on those error messages. Now, it will just say "Something went wrong.".

* chore: slightly improved testing of registration via graphql

Signed-off-by: Vsevolod Volkov <st.lyn4@gmail.com>

* chore: hiding details of internal errors from responses

Signed-off-by: Vsevolod Volkov <st.lyn4@gmail.com>

* feat: ability to remove authorization tokens from response bodies

Signed-off-by: Vsevolod Volkov <st.lyn4@gmail.com>

* chore: add section for design contributions in contributing.md

* feat: add afterOperation hook (#2697)

* feat: add afterOperation hook for Find operation

* docs: change #afterOperation to #afteroperation

* chore: extract afterOperation in function

* chore: implement afterChange in operations

* docs: use proper CollectionAfterOperationHook

* chore: remove outdated info

* chore: types afterOperation hook

* chore: improves afterOperation tests

* docs: updates description of afterOperation hook

* chore: improve typings

* chore: improve types

* chore: rename index.tsx => index.ts

---------

Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com>
Co-authored-by: Alessio Gravili <alessio@gravili.de>

* chore: remove swc version pin (#3179)

* fix: WhereBuilder component does not accept all valid Where queries (#3087)

* chore: add jsDocs for ListControls

* chore: add jsDocs for ListView

* chore: add jsDocs for WhereBuilder

* chore: add comment

* chore: remove unnecessary console log

* chore: improve operator type

* fix: transform where queries which aren't necessarily incorrect, and improve their validation

* chore: add type to import

* fix: do not merge existing old query params with new ones if the existing old ones got transformed and are not valid, as that would cause duplicates

* chore: sort imports and remove extra validation

* fix: transformWhereQuery logic

* chore: add back extra validation

* chore: add e2e tests

* chore(test): adds test to ensure relationship returns over 10 docs (#3181)

* chore(test): adds test to ensure relationship returns over 10 docs

* chore: remove unnecessary movieDocs variable

* fix: passes in height to resizeOptions upload option to allow height resize (#3171)

* docs: fixes syntax error in rich-text.mdx that was breaking build

* docs: removes auto-formatting from rich-text.mdx (#3188)

* feat: Improve admin dashboard accessibility (#3053)

Co-authored-by: Alessio Gravili <alessio@gravili.de>

* feat: improve field ops (#3172)

Co-authored-by: PatrikKozak <patrik@trbl.design>

* chore: file cleanup (#3190)

* chore(release): v1.14.0

* chore: improve ts typing in sanitization functions (#3194)

* chore(templates): default port on website

* chore(templates): safely handles bad network requests

* chore(templates): implements draft preview and on-demand revalidation

* chore(templates): renders static cart page fallback

* chore(examples): updates draft-preview next-app example to use revalidateTag (#3199)

* feat: query support for geo within and intersects + dynamic GraphQL operator types (#3183)

Co-authored-by: Lucas Blancas <lablancas@gmail.com>

* chore: improve checkboxes (#3191)

* chore: improve filtering for hasMany number field (#3193)

* chore: improve fiiltering for hasMany number field

* chore: add translation for 'items' and replace rows with items

* chore: new exceededLimit key

* Revert "chore: add translation for 'items' and replace rows with items"

This reverts commit 3a91dab.

* chore: undo adding items key in translation schema

* chore: new limitReached key

* chore: remove unnecessary exceededLimit key

* chore: spelling improvements

* chore: update test build config import

---------

Signed-off-by: Vsevolod Volkov <st.lyn4@gmail.com>
Co-authored-by: Vsevolod Volkov <st.lyn4@gmail.com>
Co-authored-by: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com>
imgbot bot pushed a commit to akadop/payload that referenced this pull request May 13, 2024
…ayloadcms#3087)

* chore: add jsDocs for ListControls

* chore: add jsDocs for ListView

* chore: add jsDocs for WhereBuilder

* chore: add comment

* chore: remove unnecessary console log

* chore: improve operator type

* fix: transform where queries which aren't necessarily incorrect, and improve their validation

* chore: add type to import

* fix: do not merge existing old query params with new ones if the existing old ones got transformed and are not valid, as that would cause duplicates

* chore: sort imports and remove extra validation

* fix: transformWhereQuery logic

* chore: add back extra validation

* chore: add e2e tests
imgbot bot pushed a commit to akadop/payload that referenced this pull request Jul 22, 2024
…ayloadcms#3087)

* chore: add jsDocs for ListControls

* chore: add jsDocs for ListView

* chore: add jsDocs for WhereBuilder

* chore: add comment

* chore: remove unnecessary console log

* chore: improve operator type

* fix: transform where queries which aren't necessarily incorrect, and improve their validation

* chore: add type to import

* fix: do not merge existing old query params with new ones if the existing old ones got transformed and are not valid, as that would cause duplicates

* chore: sort imports and remove extra validation

* fix: transformWhereQuery logic

* chore: add back extra validation

* chore: add e2e tests
imgbot bot pushed a commit to akadop/payload that referenced this pull request Jul 24, 2024
…ayloadcms#3087)

* chore: add jsDocs for ListControls

* chore: add jsDocs for ListView

* chore: add jsDocs for WhereBuilder

* chore: add comment

* chore: remove unnecessary console log

* chore: improve operator type

* fix: transform where queries which aren't necessarily incorrect, and improve their validation

* chore: add type to import

* fix: do not merge existing old query params with new ones if the existing old ones got transformed and are not valid, as that would cause duplicates

* chore: sort imports and remove extra validation

* fix: transformWhereQuery logic

* chore: add back extra validation

* chore: add e2e tests
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.

Filter state out of sync when loading a collection URL with search params

3 participants