This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Facets.js
105 lines (99 loc) · 2.59 KB
/
Facets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from "react";
import FilterLink from "./FilterLink";
import RemoveFilterLink from "./RemoveFilterLink";
function Facet({ name, children }) {
return (
<div>
<div className="facets__title">{name}</div>
<ul className="facets__list">{children}</ul>
</div>
);
}
function FacetValue({ facetName, facetValue, queryState }) {
return (
<li className="facet">
<FilterLink
name={facetName}
value={facetValue["value"]}
queryState={queryState}
>
{facetValue["value"]}
</FilterLink>{" "}
<span className="facet__count">{facetValue["count"]}</span>
</li>
);
}
function SelectedFacetValue({ facetName, value, queryState }) {
return (
<li className="facet__selected">
{value}{" "}
<span className="facet__remove">
(<RemoveFilterLink name={facetName} queryState={queryState}>
Remove
</RemoveFilterLink>)
</span>
</li>
);
}
function SingleValueFacetSelection({
displayName,
facetName,
facet,
filter,
queryState
}) {
if (!facet || facet[0].data.length === 0) return null;
return (
<Facet name={displayName}>
{!!filter && (
<SelectedFacetValue
facetName={facetName}
value={filter}
queryState={queryState}
/>
)}
{!filter &&
facet[0].data.map((facetValue, index) => (
<FacetValue
facetName={facetName}
facetValue={facetValue}
key={`${facetValue["name"]}-${index}`}
queryState={queryState}
/>
))}
</Facet>
);
}
export default function Facets({ facets, filters, queryState }) {
return (
<div className="facets with-counts">
<div className="facets__control facets__control--license">
<SingleValueFacetSelection
displayName="License"
facetName="license"
facet={facets.license}
filter={filters.license}
queryState={queryState}
/>
</div>
<div className="facets__control facets__control--keywords">
<SingleValueFacetSelection
displayName="Keywords"
facetName="keywords"
facet={facets.keywords}
filter={filters.keywords}
queryState={queryState}
/>
</div>
<div className="facets__control facets__control--dependencies">
<SingleValueFacetSelection
displayName="Dependencies"
facetName="dependencies"
facet={facets.dependencies}
filter={filters.dependencies}
queryState={queryState}
/>
</div>
</div>
);
}