@rocketsearch/vue-uappi 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
<li v-for="(value, j) in facet.values || []" :key="'f-' + j" :data-alias="facet.alias">
|
|
75
75
|
<span class="option-title" :data-alias="facet.alias">
|
|
76
76
|
<span class="name" v-text="facet.alias + ':'" />
|
|
77
|
-
<span class="label" v-text="value" />
|
|
77
|
+
<span class="label" v-text="facet.type === 'rating' ? ratingLabel(value) : value" />
|
|
78
78
|
</span>
|
|
79
79
|
<button class="rocket-search__facets__selected__clear-filter" aria-label="Remover filtro" @click="clearFacet(value, facet)">
|
|
80
80
|
x
|
|
@@ -185,7 +185,7 @@ import '../css/search.css';
|
|
|
185
185
|
import RocketSearchFacets from './search/RocketSearchFacets.vue';
|
|
186
186
|
import RocketSearchPagination from './search/RocketSearchPagination.vue';
|
|
187
187
|
import { productImage, productPath, productPrice, formatCurrency } from '../uappi.js';
|
|
188
|
-
import { TRACKING_PARAMS, didYouMeanQuery, dispatchDidYouMeanClick } from '../listing.js';
|
|
188
|
+
import { TRACKING_PARAMS, didYouMeanQuery, dispatchDidYouMeanClick, ratingLabel } from '../listing.js';
|
|
189
189
|
|
|
190
190
|
// Parâmetros de campanha nunca viram filtro na busca.
|
|
191
191
|
function emptyContext () {
|
|
@@ -295,6 +295,7 @@ export default {
|
|
|
295
295
|
productPath,
|
|
296
296
|
productPrice,
|
|
297
297
|
formatCurrency,
|
|
298
|
+
ratingLabel,
|
|
298
299
|
|
|
299
300
|
// ---- Busca ----
|
|
300
301
|
|
|
@@ -401,17 +402,22 @@ export default {
|
|
|
401
402
|
// ---- Facets ----
|
|
402
403
|
|
|
403
404
|
isSelected (value, facet) {
|
|
405
|
+
// Avaliação: 0 e 1 são opções (Sem avaliações / 1 estrela ou mais), não o booleano.
|
|
406
|
+
if (facet.type === 'rating') {
|
|
407
|
+
const rating = (this.context.appliedFilters || []).find(f => f.field === facet.field);
|
|
408
|
+
return !!rating && (rating.values || []).includes(Number(value));
|
|
409
|
+
}
|
|
404
410
|
if (value === 0 || value === 1) {
|
|
405
411
|
const booleanFilter = (this.context.appliedFilters || []).find(f => f.type === 'boolean' && f.field === facet.field);
|
|
406
412
|
return !!booleanFilter && booleanFilter.value === (value === 1);
|
|
407
413
|
}
|
|
408
|
-
return (this.context.appliedFilters || []).some(f => (f.values || []).includes(value));
|
|
414
|
+
return (this.context.appliedFilters || []).some(f => f.type !== 'rating' && (f.values || []).includes(value));
|
|
409
415
|
},
|
|
410
416
|
|
|
411
417
|
clickFacet (value, facet) {
|
|
412
418
|
const selected = this.isSelected(value.value, facet);
|
|
413
419
|
this.updateQuery((query) => {
|
|
414
|
-
if (value.value === 0 || value.value === 1) {
|
|
420
|
+
if (facet.type !== 'rating' && (value.value === 0 || value.value === 1)) {
|
|
415
421
|
query[facet.label] = selected ? '' : String(value.value);
|
|
416
422
|
}
|
|
417
423
|
else {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<li v-for="(value, j) in facet.values || []" :key="'f-' + j" :data-alias="facet.alias">
|
|
15
15
|
<span class="option-title" :data-alias="facet.alias">
|
|
16
16
|
<span class="name" v-text="facet.alias + ':'" />
|
|
17
|
-
<span class="label" v-text="value" />
|
|
17
|
+
<span class="label" v-text="facet.type === 'rating' ? ratingLabel(value) : value" />
|
|
18
18
|
</span>
|
|
19
19
|
<button class="rocket-search__facets__selected__clear-filter" @click="$emit('clear-facet', value, facet)">
|
|
20
20
|
x
|
|
@@ -73,6 +73,22 @@
|
|
|
73
73
|
:facet="facet"
|
|
74
74
|
@apply="$emit('apply-price', $event)"
|
|
75
75
|
/>
|
|
76
|
+
<ul v-else-if="facet.type === 'rating'" class="facet-rating-list">
|
|
77
|
+
<li
|
|
78
|
+
v-for="value in facet.values || []"
|
|
79
|
+
:key="value.value"
|
|
80
|
+
:data-selected="isSelected(value.value, facet)"
|
|
81
|
+
:class="{ selected: isSelected(value.value, facet) }"
|
|
82
|
+
>
|
|
83
|
+
<a href="javascript:void(0);" @click="$emit('click-facet', value, facet)">
|
|
84
|
+
<span v-if="value.value > 0" style="display:flex;align-items:center;gap:6px;">
|
|
85
|
+
<span class="rating-stars"><span v-for="n in 5" :key="n" :class="n <= value.value ? 'star-filled' : 'star-empty'">★</span></span>
|
|
86
|
+
<span class="rating-label"><span v-text="value.value" /><span v-text="ratingSuffix(value.value)" /></span>
|
|
87
|
+
</span>
|
|
88
|
+
<span v-else class="rating-label no-reviews">Sem avaliações</span>
|
|
89
|
+
</a>
|
|
90
|
+
</li>
|
|
91
|
+
</ul>
|
|
76
92
|
<!-- terms e boolean usam a mesma lista (na Linx o boolean reaproveitava o template de terms). -->
|
|
77
93
|
<ul v-else>
|
|
78
94
|
<li
|
|
@@ -110,6 +126,7 @@
|
|
|
110
126
|
<script>
|
|
111
127
|
import RocketSearchRange from './RocketSearchRange.vue';
|
|
112
128
|
import { formatCurrency } from '../../uappi.js';
|
|
129
|
+
import { ratingLabel, ratingSuffix } from '../../listing.js';
|
|
113
130
|
|
|
114
131
|
export default {
|
|
115
132
|
name: 'RocketSearchFacets',
|
|
@@ -132,6 +149,8 @@ export default {
|
|
|
132
149
|
},
|
|
133
150
|
methods: {
|
|
134
151
|
formatCurrency,
|
|
152
|
+
ratingLabel,
|
|
153
|
+
ratingSuffix,
|
|
135
154
|
// Facet booleano (ex.: Disponibilidade/hasStock) vem como 0/1 — mesmo texto do chip aplicado.
|
|
136
155
|
valueLabel (value) {
|
|
137
156
|
if (value === 0) return 'Não';
|
package/runtime/css/search.css
CHANGED
|
@@ -717,3 +717,17 @@
|
|
|
717
717
|
text-decoration: underline;
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
|
+
|
|
721
|
+
/* Faceta de avaliação (type 'rating'). */
|
|
722
|
+
.rocket-search .facet-rating-list .star-filled {
|
|
723
|
+
color: #f5a623;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
.rocket-search .facet-rating-list .star-empty {
|
|
727
|
+
color: #d9d9d9;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
.rocket-search .facet-rating-list li.selected .rating-label {
|
|
731
|
+
color: #232626;
|
|
732
|
+
font-weight: 700;
|
|
733
|
+
}
|
package/runtime/listing.js
CHANGED
|
@@ -21,6 +21,19 @@ function splitValues (raw) {
|
|
|
21
21
|
return String(raw || '').split(';').filter(v => v !== '');
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// Faceta de avaliação (type 'rating'): opções cumulativas 5..1 e 0 = sem avaliação.
|
|
25
|
+
export function ratingSuffix (n) {
|
|
26
|
+
n = Number(n);
|
|
27
|
+
if (n === 5) return ' estrelas';
|
|
28
|
+
if (n === 1) return ' estrela ou mais';
|
|
29
|
+
return ' estrelas ou mais';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function ratingLabel (n) {
|
|
33
|
+
n = Number(n);
|
|
34
|
+
return n === 0 ? 'Sem avaliações' : n + ratingSuffix(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
24
37
|
function isForwardable (key) {
|
|
25
38
|
const lower = key.toLowerCase();
|
|
26
39
|
return !THEME_PARAMS.includes(key) && !TRACKING_PARAMS.includes(lower) && lower.indexOf('utm_') !== 0;
|
|
@@ -66,10 +79,11 @@ function facetValues (facet, query, path) {
|
|
|
66
79
|
const active = splitValues(query[facet.label]);
|
|
67
80
|
return (facet.values || []).map((v, index) => {
|
|
68
81
|
const value = String(v.value);
|
|
82
|
+
const label = facet.type === 'rating' ? ratingLabel(v.value) : value;
|
|
69
83
|
return {
|
|
70
84
|
id: index + 1,
|
|
71
|
-
nome:
|
|
72
|
-
label
|
|
85
|
+
nome: label,
|
|
86
|
+
label,
|
|
73
87
|
imagem: '',
|
|
74
88
|
imagemOriginal: '',
|
|
75
89
|
ordem: index,
|
|
@@ -109,7 +123,7 @@ export function toUappiListing (response, products, rawQuery, options) {
|
|
|
109
123
|
return;
|
|
110
124
|
}
|
|
111
125
|
// Disponibilidade (0/1) não tem par na listagem da Uappi.
|
|
112
|
-
if (facet.type !== 'terms' || facet.field === 'hasStock' || !(facet.values || []).length) return;
|
|
126
|
+
if ((facet.type !== 'terms' && facet.type !== 'rating') || facet.field === 'hasStock' || !(facet.values || []).length) return;
|
|
113
127
|
const values = facetValues(facet, query, path);
|
|
114
128
|
if (facet.field === 'brand.name') marcas.push(...values);
|
|
115
129
|
else atributos.push({ id: index + 1, nome: facet.label, tipo: 'texto', campo: facet.field, valores: values });
|