-
Notifications
You must be signed in to change notification settings - Fork 1
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
adriangohjw
merged 24 commits into
main
from
enhancement-collection-do-not-render-empty-filter
Jan 7, 2025
+606
−257
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ff004f4
make 'others' a const
adriangohjw 4e5d54f
extract into consts
adriangohjw 94a6767
extract into getYearFilters
adriangohjw 16cdd63
extract getCategoryFilters
adriangohjw b355073
add correct types
adriangohjw cd0a7bf
extract getTagFilters
adriangohjw d3df2ed
rename to singular
adriangohjw 92c5a6d
move logic into each get*Filter function to improve readability
adriangohjw 368ad74
fix import
adriangohjw 1571251
remove type renaming during import
adriangohjw 929d778
refactor imports location
adriangohjw c7d7c85
refactor: standardize code structure
adriangohjw 7cc0190
only return filters with at least 2 items
adriangohjw 2a4720b
add storybook
adriangohjw cf20aa4
do not render "category" if there's no category filter
adriangohjw 7748466
Update packages/components/src/templates/next/layouts/Collection/util…
adriangohjw 5d17dd2
Merge remote-tracking branch 'origin/HEAD' into enhancement-collectio…
adriangohjw c5ab110
split methods in utils into utils folder
adriangohjw 6611f6e
sort tag filters
adriangohjw 97e2854
Merge remote-tracking branch 'origin/main' into enhancement-collectio…
adriangohjw c18d9e9
undo: shouldShowCategory
adriangohjw d8b685d
should filter out any filters with no items
adriangohjw dc06a13
add tests
adriangohjw 169fe49
update storybook
adriangohjw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
256 changes: 0 additions & 256 deletions
256
packages/components/src/templates/next/layouts/Collection/utils.ts
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...omponents/src/templates/next/layouts/Collection/utils/__tests__/getCategoryFilter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import type { ProcessedCollectionCardProps } from "~/interfaces" | ||
import { getCategoryFilter } from "../getCategoryFilter" | ||
|
||
describe("getCategoryFilter", () => { | ||
it("should return empty filter items when no items provided", () => { | ||
// Arrange | ||
const items: ProcessedCollectionCardProps[] = [] | ||
|
||
// Act | ||
const result = getCategoryFilter(items) | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
id: "category", | ||
label: "Category", | ||
items: [], | ||
}) | ||
}) | ||
|
||
it("should count and format categories correctly", () => { | ||
// Arrange | ||
const items: ProcessedCollectionCardProps[] = [ | ||
{ | ||
category: "guides", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "guides", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "articles", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "tutorials", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "tutorials", | ||
} as ProcessedCollectionCardProps, | ||
] | ||
|
||
// Act | ||
const result = getCategoryFilter(items) | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
id: "category", | ||
label: "Category", | ||
items: [ | ||
{ id: "articles", label: "Articles", count: 1 }, | ||
{ id: "guides", label: "Guides", count: 2 }, | ||
{ id: "tutorials", label: "Tutorials", count: 2 }, | ||
], | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?