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

Enhancement - collection do not render empty filter #972

Merged
merged 24 commits into from
Jan 7, 2025

Conversation

adriangohjw
Copy link
Contributor

Problem

Screenshot 2025-01-02 at 9 38 47 PM

We are returning filters with only one filter option. This doesn't make sense since clicking on it has no impact - it will only clutter the UI

Solution

Breaking Changes

  • Yes - this PR contains breaking changes
    • Details ...
  • No - this PR is backwards compatible

Improvements:

  • Only render a filter if it contains at least 2 items
  • I refactored a large function into smaller ones to improve readability and maintainability, accepting a slight performance cost from iterating three times instead of once. Since this runs only during build time, it doesn’t affect the end-user experience.

Tests

  1. go to studio and create a collection with only two items (same date, different category)
  2. publish it
  3. verify that "year" filter should not appear
  4. repeat with another collection with "same category, different year"

@adriangohjw adriangohjw added the enhancement New feature or request label Jan 2, 2025
@adriangohjw adriangohjw self-assigned this Jan 2, 2025
@adriangohjw adriangohjw requested a review from a team as a code owner January 2, 2025 13:44
@datadog-opengovsg
Copy link

datadog-opengovsg bot commented Jan 2, 2025

Datadog Report

Branch report: enhancement-collection-do-not-render-empty-filter
Commit report: 29ec0d5
Test service: isomer-studio

✅ 0 Failed, 257 Passed, 36 Skipped, 47.25s Total Time
⬆️ Test Sessions change in coverage: 1 increased (+2.33%)

…s.ts

Co-authored-by: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com>
const items: ProcessedCollectionCardProps[] = [
{
category: "guides",
} as ProcessedCollectionCardProps,
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: this type-cast is a little weird. I understand that we just want to test specific parts of the collection card props but this might hide problems if the implementation were to be changed, or if the props has changed upstream.

We can probably create a few complete test objects to be used across the different tests, or have some builder function that will automatically populate the remaining fields so that we can avoid this type casting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

might hide problems if the implementation were to be changed, or if the props has changed upstream.

hmm not quite understanding this, as this test should fail if the implementation changes (e.g. using more props), which should be the intended outcome of a test?

getCategoryFilter(items),
getYearFilter(items),
...getTagFilters(items),
].filter((filter) => filter.items.length >= 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we might be able to remove this filter? There shouldn't be a case where a filter exists but there are 0 items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently the get*Filter functions returned a Filter object regardless, and they could be empty items

for example, if all the lastUpdated are undefined (it's an optional field, though it auto set to Date.now() in Studio UI on initialization)

thought that we can keep this as a more defensive approach

Copy link
Contributor

@dcshzj dcshzj left a comment

Choose a reason for hiding this comment

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

Approving first due to urgency, let's address the type-casting issue in a separate PR

@adriangohjw adriangohjw merged commit ec7e344 into main Jan 7, 2025
17 of 18 checks passed
@adriangohjw adriangohjw deleted the enhancement-collection-do-not-render-empty-filter branch January 7, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants