Skip to content

Commit 5b7ceb6

Browse files
committed
Show how many extensions are in the list.
1 parent 425b155 commit 5b7ceb6

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

src/components/extensions-list.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ const Extensions = styled.ol`
2121
width: 100%;
2222
`
2323

24+
const RightColumn = styled.div`
25+
display: flex;
26+
flex-direction: column;
27+
flex-wrap: wrap;
28+
width: 100%;
29+
`
30+
31+
const ExtensionCount = styled.div`
32+
margin-top: 1.25rem;
33+
margin-left: 3.25rem;
34+
width: 100%;
35+
`
36+
2437
const ExtensionsList = ({ extensions, categories }) => {
2538
// Do some pre-filtering for content we will never want, like superseded extensions
2639
const allExtensions = extensions.filter(extension => !extension.isSuperseded)
@@ -29,27 +42,41 @@ const ExtensionsList = ({ extensions, categories }) => {
2942

3043
// TODO why is this guard necessary?
3144
if (allExtensions) {
45+
// Exclude unlisted extensions from the count, even though we sometimes show them if there's a direct search for it
46+
const extensionCount = allExtensions.filter(
47+
extension => !extension.metadata.unlisted
48+
).length
49+
3250
// Sort alphabetically, in the absence of a better idea (for now)
3351
filteredExtensions.sort((a, b) =>
3452
a.sortableName > b.sortableName ? 1 : -1
3553
)
3654

55+
const countMessage =
56+
extensionCount === filteredExtensions.length
57+
? `Showing ${extensionCount} extensions.`
58+
: `Showing ${filteredExtensions.length} of ${extensionCount} extensions.`
59+
3760
return (
3861
<FilterableList className="extensions-list">
3962
<Filters
4063
extensions={allExtensions}
4164
categories={categories}
4265
filterAction={setExtensions}
4366
/>
44-
<Extensions>
45-
{filteredExtensions.map(extension => {
46-
return (
47-
<li key={extension.id}>
48-
<ExtensionCard extension={extension} />
49-
</li>
50-
)
51-
})}
52-
</Extensions>
67+
<RightColumn>
68+
{" "}
69+
<ExtensionCount>{countMessage}</ExtensionCount>
70+
<Extensions>
71+
{filteredExtensions.map(extension => {
72+
return (
73+
<li key={extension.id}>
74+
<ExtensionCard extension={extension} />
75+
</li>
76+
)
77+
})}
78+
</Extensions>{" "}
79+
</RightColumn>
5380
</FilterableList>
5481
)
5582
} else {

src/components/extensions-list.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ describe("extension list", () => {
8585
expect(screen.queryByText(maybeObsolete.name)).toBeInTheDocument()
8686
})
8787

88+
it("displays a brief message about how many extensions there are", async () => {
89+
// The superceded extension should not be counted
90+
const num = extensions.length - 1
91+
expect(screen.getByText(`Showing ${num} extensions.`)).toBeTruthy()
92+
})
93+
8894
describe("searching and filtering", () => {
8995
describe("searching", () => {
9096
it("filters out extensions which do not match the search filter", async () => {
@@ -126,6 +132,15 @@ describe("extension list", () => {
126132

127133
expect(screen.queryByText(molluscs.name)).toBeFalsy()
128134
})
135+
136+
it("displays a longer message about how many extensions are still shown", async () => {
137+
fireEvent.click(screen.getByText(displayCategory))
138+
139+
const total = extensions.length - 1
140+
expect(
141+
screen.getByText(`Showing 2 of ${total} extensions.`)
142+
).toBeTruthy()
143+
})
129144
})
130145

131146
describe("platform filter", () => {

src/components/filters/filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import StatusFilter from "./status-filter"
88

99
const FilterBar = styled.aside`
1010
width: 224px;
11-
padding-top: 31px; // TODO can we do better than this rather specific hardcoding to align with the cards?
11+
margin-top: 1.25rem;
1212
display: flex;
1313
flex-direction: column;
1414
justify-content: flex-start;

0 commit comments

Comments
 (0)