Skip to content

Commit b8f774f

Browse files
authored
feat(connectCurrentRefinements): add a root label (PART 1) (#3515)
* feat(connectCurrentRefinements): add a root label (PART 1) This will always be identical to the attribute, and will be the thing which will be displayed. The reason why you'd want a key like this is if you e.g. want to rename a single key or transform all keys to be upper case, without actually changing which attribute will be changed. * chore(CurrentRefinements): use label instead of attribute (PART 2) (#3518) Thinking about it, I think this might be a major change unfortunately
1 parent 70b3ecd commit b8f774f

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

src/components/CurrentRefinements/CurrentRefinements.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ const CurrentRefinements = ({ items, cssClasses }) => (
2222
<ul className={cssClasses.list}>
2323
{items.map((item, index) => (
2424
<li key={`${item.attribute}-${index}`} className={cssClasses.item}>
25-
<span className={cssClasses.label}>
26-
{capitalize(item.attribute)}:
27-
</span>
25+
<span className={cssClasses.label}>{capitalize(item.label)}:</span>
2826

2927
{item.refinements.map(refinement => (
3028
<span

src/components/CurrentRefinements/__tests__/CurrentRefinements-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('CurrentRefinements', () => {
2020
items: [
2121
{
2222
attribute: 'facet',
23+
label: 'facet',
2324
refine: () => {},
2425
refinements: [
2526
{
@@ -38,6 +39,7 @@ describe('CurrentRefinements', () => {
3839
},
3940
{
4041
attribute: 'facetExclude',
42+
label: 'facetExclude',
4143
refine: () => {},
4244
refinements: [
4345
{
@@ -51,6 +53,7 @@ describe('CurrentRefinements', () => {
5153
},
5254
{
5355
attribute: 'disjunctive',
56+
label: 'disjunctive',
5457
refine: () => {},
5558
refinements: [
5659
{
@@ -63,6 +66,7 @@ describe('CurrentRefinements', () => {
6366
},
6467
{
6568
attribute: 'hierarchical',
69+
label: 'hierarchical',
6670
refine: () => {},
6771
refinements: [
6872
{
@@ -75,6 +79,7 @@ describe('CurrentRefinements', () => {
7579
},
7680
{
7781
attribute: 'numeric',
82+
label: 'numeric',
7883
refine: () => {},
7984
refinements: [
8085
{
@@ -88,6 +93,7 @@ describe('CurrentRefinements', () => {
8893
},
8994
{
9095
attribute: 'tag',
96+
label: 'tag',
9197
refine: () => {},
9298
refinements: [
9399
{
@@ -113,6 +119,7 @@ describe('CurrentRefinements', () => {
113119
items: [
114120
{
115121
attribute: 'customFacet',
122+
label: 'customFacet',
116123
refine: () => {},
117124
refinements: [
118125
{
@@ -137,6 +144,7 @@ describe('CurrentRefinements', () => {
137144
items: [
138145
{
139146
attribute: 'customExcludeFacet',
147+
label: 'customExcludeFacet',
140148
refine: () => {},
141149
refinements: [
142150
{
@@ -162,6 +170,7 @@ describe('CurrentRefinements', () => {
162170
items: [
163171
{
164172
attribute: 'customDisjunctiveFacet',
173+
label: 'customDisjunctiveFacet',
165174
refine: () => {},
166175
refinements: [
167176
{
@@ -186,6 +195,7 @@ describe('CurrentRefinements', () => {
186195
items: [
187196
{
188197
attribute: 'customHierarchicalFacet',
198+
label: 'customHierarchicalFacet',
189199
refine: () => {},
190200
refinements: [
191201
{
@@ -210,6 +220,7 @@ describe('CurrentRefinements', () => {
210220
items: [
211221
{
212222
attribute: 'customNumericFilter',
223+
label: 'customNumericFilter',
213224
refine: () => {},
214225
refinements: [
215226
{
@@ -223,6 +234,7 @@ describe('CurrentRefinements', () => {
223234
},
224235
{
225236
attribute: 'customNumericFilter',
237+
label: 'customNumericFilter',
226238
refine: () => {},
227239
refinements: [
228240
{
@@ -236,6 +248,7 @@ describe('CurrentRefinements', () => {
236248
},
237249
{
238250
attribute: 'customNumericFilter',
251+
label: 'customNumericFilter',
239252
refine: () => {},
240253
refinements: [
241254
{
@@ -261,6 +274,7 @@ describe('CurrentRefinements', () => {
261274
items: [
262275
{
263276
attribute: '_tags',
277+
label: '_tags',
264278
refine: () => {},
265279
refinements: [
266280
{
@@ -285,6 +299,7 @@ describe('CurrentRefinements', () => {
285299
items: [
286300
{
287301
attribute: 'query',
302+
label: 'query',
288303
refine: () => {},
289304
refinements: [
290305
{

src/connectors/current-refinements/connectCurrentRefinements.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ function groupItemsByRefinements(items, helper) {
273273
...results.filter(result => result.attribute !== currentItem.attribute),
274274
{
275275
attribute: currentItem.attribute,
276+
label: currentItem.attribute,
276277
refinements: items
277278
.filter(result => result.attribute === currentItem.attribute)
278279
// We want to keep the order of refinements except the numeric ones.

src/widgets/current-refinements/__tests__/__snapshots__/current-refinements-test.js.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
1717
Array [
1818
Object {
1919
"attribute": "extraFacet",
20+
"label": "extraFacet",
2021
"refine": [Function],
2122
"refinements": Array [
2223
Object {
@@ -31,6 +32,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
3132
},
3233
Object {
3334
"attribute": "facet",
35+
"label": "facet",
3436
"refine": [Function],
3537
"refinements": Array [
3638
Object {
@@ -53,6 +55,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
5355
},
5456
Object {
5557
"attribute": "facetExclude",
58+
"label": "facetExclude",
5659
"refine": [Function],
5760
"refinements": Array [
5861
Object {
@@ -71,6 +74,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
7174
},
7275
Object {
7376
"attribute": "disjunctiveFacet",
77+
"label": "disjunctiveFacet",
7478
"refine": [Function],
7579
"refinements": Array [
7680
Object {
@@ -93,6 +97,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
9397
},
9498
Object {
9599
"attribute": "hierarchicalFacet",
100+
"label": "hierarchicalFacet",
96101
"refine": [Function],
97102
"refinements": Array [
98103
Object {
@@ -107,6 +112,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
107112
},
108113
Object {
109114
"attribute": "numericFacet",
115+
"label": "numericFacet",
110116
"refine": [Function],
111117
"refinements": Array [
112118
Object {
@@ -127,6 +133,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
127133
},
128134
Object {
129135
"attribute": "numericDisjunctiveFacet",
136+
"label": "numericDisjunctiveFacet",
130137
"refine": [Function],
131138
"refinements": Array [
132139
Object {
@@ -147,6 +154,7 @@ exports[`currentRefinements() render() DOM output renders correctly 1`] = `
147154
},
148155
Object {
149156
"attribute": "_tags",
157+
"label": "_tags",
150158
"refine": [Function],
151159
"refinements": Array [
152160
Object {
@@ -219,6 +227,7 @@ exports[`currentRefinements() render() should render twice <CurrentRefinements .
219227
Array [
220228
Object {
221229
"attribute": "facet",
230+
"label": "facet",
222231
"refine": [Function],
223232
"refinements": Array [
224233
Object {
@@ -252,6 +261,7 @@ exports[`currentRefinements() render() should render twice <CurrentRefinements .
252261
Array [
253262
Object {
254263
"attribute": "facet",
264+
"label": "facet",
255265
"refine": [Function],
256266
"refinements": Array [
257267
Object {

0 commit comments

Comments
 (0)