Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Use the correct list of filters for All content #844

Merged
merged 3 commits into from Feb 10, 2022
Merged

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Feb 10, 2022

Description

This PR fixes the mixup between the mediaFilterKeys and mediaSpecificFilters objects in the search store.

The first is used to keep all the filter types that are used for the content type, and the second has a list of filters that are only used for the specific content type, and not used in other content types (such as duration for audio).

One of the places where the mediaSpecificFilters was used was the search/CLEAR_OTHER_MEDIA_TYPE_FILTERS. This action is dispatched when changing a content type to clear filters that do not apply to current content type. So, when changing from "All Content" to "Images", it would set all the filters that are specific for "All Content" and "Audio" to not checked. With the bug that is fixed here, it would also uncheck the following filters: ['licenses', 'licenseTypes', 'searchBy', 'mature']. And because mature filter is not an object, but a boolean, it would crash when iterated over, as the state.filters['mature'] is not an array here, so we can't use map here:

    Object.keys(state.filters).forEach((filterType) => {
      if (filterKeysToClear.includes(filterType)) {
        state.filters[filterType] = state.filters[filterType].map((f) => ({
          ...f,
          checked: false,
        }))
      }
    })

This did not actually cause an crash because we were only clearing the supportedMediaTypes, and not the supportedContentTypes (i.e. did not include ALL_MEDIA).

Testing Instructions

Simply running the unit and e2e tests should be enough.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

In search.js/CLEAR_OTHER_MEDIA_TYPE_FILTERS, all `mediaSpecificFilters`, including `mature`, were iterated over. Using all `ALL_CONTENT` filters as the `ALL_CONTENT` `mediaSpecificFilters` meant that all the common filters were cleared, instead of clearing only the filters for other media types.
@obulat obulat added 🟨 priority: medium Not blocking but should be addressed soon 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Feb 10, 2022
@obulat obulat requested a review from a team as a code owner February 10, 2022 06:17
@dhruvkb dhruvkb added this to Needs review in Openverse PRs Feb 10, 2022
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

Nice! Thank you for the explanation and the detailed documentation on each object. It makes me wonder if we could rename mediaFilterKeys to something more descriptive 🤔 sharedFilterKeys maybe? 🤷

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

lgtm! definitely want to clean up some of this naming in the future.

Openverse PRs automation moved this from Needs review to Reviewer approved Feb 10, 2022
@obulat
Copy link
Contributor Author

obulat commented Feb 10, 2022

Nice! Thank you for the explanation and the detailed documentation on each object. It makes me wonder if we could rename mediaFilterKeys to something more descriptive 🤔 sharedFilterKeys maybe? 🤷

I was also wondering about a better name, but couldn't find it yet. shared wouldn't be correct for this, because the object actually contains all filter keys for all media types.

@obulat obulat merged commit 204d558 into main Feb 10, 2022
@obulat obulat deleted the fix/filter_bug branch February 10, 2022 14:13
Openverse PRs automation moved this from Reviewer approved to Merged! Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟨 priority: medium Not blocking but should be addressed soon
Projects
No open projects
Openverse PRs
  
Merged!
Development

Successfully merging this pull request may close these issues.

None yet

3 participants