|
12 | 12 |
|
13 | 13 | let lastRenderArgs |
14 | 14 |
|
15 | | - const transformItems = (items) => { |
16 | | - return items.map((item) => { |
17 | | - let label = Object.keys(item.hierarchy).reduce((acc, key) => { |
18 | | - const highlight = item._highlightResult.hierarchy[key] |
19 | | - if (highlight && highlight.matchLevel !== 'none') { |
20 | | - return item._highlightResult.hierarchy[key] |
21 | | - } |
22 | | - return acc |
23 | | - }, '') |
24 | | - if (!label) { |
25 | | - label = Object.keys(item.hierarchy).reduce((acc, key) => { |
26 | | - const highlight = item._highlightResult.hierarchy[key] |
27 | | - if (highlight) { |
28 | | - return item._highlightResult.hierarchy[key] |
29 | | - } |
30 | | - return acc |
31 | | - }, '') |
32 | | - } |
33 | | - return { |
34 | | - ...item, |
35 | | - _highlightResult: { |
36 | | - ...item._highlightResult, |
37 | | - label: label, |
38 | | - }, |
39 | | - } |
40 | | - }) |
41 | | - } |
42 | | - |
43 | 15 | const infiniteHits = instantsearch.connectors.connectInfiniteHits((renderArgs, isFirstRender) => { |
44 | 16 | const { hits, showMore, widgetParams } = renderArgs |
45 | 17 | const { container } = widgetParams |
|
51 | 23 | container.appendChild(sentinel) |
52 | 24 | return |
53 | 25 | } |
54 | | - const _hits = transformItems(hits) |
| 26 | + const _hits = [...hits] |
55 | 27 | if (container.querySelector('#page-showmore')) { |
56 | 28 | container.removeChild(container.querySelector('#page-showmore')) |
57 | 29 | } |
|
72 | 44 | .map((hit) => { |
73 | 45 | let content = '' |
74 | 46 | let breadcrumbs = '' |
| 47 | + let label = '' |
75 | 48 |
|
76 | 49 | if (hit.content) { |
77 | 50 | content = `<p class="hit-description"> |
|
90 | 63 | </div>` |
91 | 64 | } |
92 | 65 |
|
| 66 | + label = Object.keys(hit.hierarchy) |
| 67 | + .map((key, index) => { |
| 68 | + if (index > 0 && hit) { |
| 69 | + return instantsearch.highlight({ hit: hit, attribute: 'hierarchy.' + key }) |
| 70 | + } |
| 71 | + return null |
| 72 | + }) |
| 73 | + .filter((item) => !!item) |
| 74 | + .join(' - ') |
| 75 | + |
93 | 76 | return `<li> |
94 | 77 | <a href="${hit.url}" class="ais-Hits-item"> |
95 | 78 | <div class="hit-name"> |
96 | | - ${instantsearch.highlight({ hit: hit, attribute: 'label' })} |
| 79 | + ${label} |
97 | 80 | </div> |
98 | 81 | ${breadcrumbs} |
99 | 82 | ${content} |
|
0 commit comments