@itfin/components 2.0.46 → 2.0.47
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
|
@@ -20,18 +20,16 @@
|
|
|
20
20
|
</div>
|
|
21
21
|
</div>
|
|
22
22
|
<div class="facets-list">
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<span
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
</span>
|
|
34
|
-
</div>
|
|
23
|
+
<div v-for="(val, n) of mappedValues" :key="n" class="dropdown-item px-2" :class="{'active': val.isSelected}" @click="onFilterClick(val)">
|
|
24
|
+
<span class="facet-name text-dark d-flex align-items-center">
|
|
25
|
+
<itf-checkbox ungrouped :value="val.isSelected" class="m-0" />
|
|
26
|
+
<div class="w-100 text-truncate">{{ val.label }} <span v-if="val.description" class="small"><br/>{{ val.description }}</span></div>
|
|
27
|
+
</span>
|
|
28
|
+
<span v-if="val.count" class="facet-stat">
|
|
29
|
+
{{ val.count }}
|
|
30
|
+
<span class="facet-bar"><span :style="{'--bar-width': `${getPercent(val)}%`}" class="facet-bar-progress" /></span>
|
|
31
|
+
</span>
|
|
32
|
+
</div>
|
|
35
33
|
</div>
|
|
36
34
|
|
|
37
35
|
<itf-button default class="mt-1" v-if="hasMore" small block @click="toggleMore">
|
|
@@ -113,12 +111,8 @@
|
|
|
113
111
|
}
|
|
114
112
|
</style>
|
|
115
113
|
<script>
|
|
116
|
-
import uniq from 'lodash/uniq';
|
|
117
|
-
import sortBy from 'lodash/sortBy';
|
|
118
|
-
import groupBy from 'lodash/groupBy';
|
|
119
114
|
import { Vue, Prop, Model, Component } from 'vue-property-decorator';
|
|
120
115
|
import itfTextField from '../text-field/TextField.vue';
|
|
121
|
-
import itfIcon from '../icon/Icon';
|
|
122
116
|
import itfButton from '../button/Button';
|
|
123
117
|
import itfCheckbox from '../checkbox/Checkbox.vue';
|
|
124
118
|
|
|
@@ -126,7 +120,6 @@ export default @Component({
|
|
|
126
120
|
name: 'FilterFacetsList',
|
|
127
121
|
components: {
|
|
128
122
|
itfCheckbox,
|
|
129
|
-
itfIcon,
|
|
130
123
|
itfButton,
|
|
131
124
|
itfTextField
|
|
132
125
|
}
|
|
@@ -136,7 +129,6 @@ class FilterFacetsList extends Vue {
|
|
|
136
129
|
@Prop() items;
|
|
137
130
|
@Prop() item;
|
|
138
131
|
@Prop() total;
|
|
139
|
-
@Prop() options;
|
|
140
132
|
@Prop({ type: Number, default: 5 }) limit;
|
|
141
133
|
@Prop(Boolean) multiple;
|
|
142
134
|
@Prop(Boolean) showAll;
|
|
@@ -150,44 +142,6 @@ class FilterFacetsList extends Vue {
|
|
|
150
142
|
this.showMore = !this.showMore;
|
|
151
143
|
}
|
|
152
144
|
|
|
153
|
-
get groupIcon() {
|
|
154
|
-
return this.options?.groupIcon;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
get flatList() {
|
|
158
|
-
return treeToFlat(this.items || []);
|
|
159
|
-
|
|
160
|
-
function getIdsDeep(items, mapFunc) {
|
|
161
|
-
return (items ?? []).reduce((acc, item) => {
|
|
162
|
-
const id = mapFunc(item);
|
|
163
|
-
if (id) {
|
|
164
|
-
acc.push(id);
|
|
165
|
-
}
|
|
166
|
-
if (item.items && item.items.length) {
|
|
167
|
-
acc.push(...getIdsDeep(item.items, mapFunc));
|
|
168
|
-
}
|
|
169
|
-
return acc;
|
|
170
|
-
}, []);
|
|
171
|
-
}
|
|
172
|
-
function treeToFlat(items, level = 0) {
|
|
173
|
-
return (items ?? []).reduce((acc, item) => {
|
|
174
|
-
acc.push({
|
|
175
|
-
...item,
|
|
176
|
-
level,
|
|
177
|
-
ids: [item.isGroup ? `g:${item.value}` : item.value].concat(
|
|
178
|
-
getIdsDeep(item.items, (item) => item.isGroup ? `g:${item.value}` : item.value)
|
|
179
|
-
)
|
|
180
|
-
.filter(Boolean),
|
|
181
|
-
});
|
|
182
|
-
if (item.items && item.items.length) {
|
|
183
|
-
// acc.push({ ...item, group: item.label, level });
|
|
184
|
-
acc.push(...treeToFlat(item.items, level + 1));
|
|
185
|
-
}
|
|
186
|
-
return acc;
|
|
187
|
-
}, []);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
145
|
get hasMore() {
|
|
192
146
|
if (this.showAll) {
|
|
193
147
|
return false;
|
|
@@ -195,36 +149,8 @@ class FilterFacetsList extends Vue {
|
|
|
195
149
|
return this.visibleList.length > this.limit;
|
|
196
150
|
}
|
|
197
151
|
|
|
198
|
-
get hasGroups() {
|
|
199
|
-
const groups = uniq(this.flatList && this.flatList.map(item => item.group).filter(Boolean));
|
|
200
|
-
return groups.length > 1
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
isGroupSelected(val) {
|
|
204
|
-
return (val.ids ?? []).every(id => this.value.includes(`${id}`));
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
groupSelected(value, ids) {
|
|
208
|
-
let newVal = this.value ? [...Array.isArray(this.value) ? this.value : [this.value]] : [];
|
|
209
|
-
console.info(value, ids);
|
|
210
|
-
if (value) {
|
|
211
|
-
ids.forEach((id) => {
|
|
212
|
-
const itemValue = `${id}`;
|
|
213
|
-
if (!newVal.includes(itemValue)) {
|
|
214
|
-
newVal.push(itemValue);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
} else {
|
|
218
|
-
ids.forEach((id) => {
|
|
219
|
-
const itemValue = `${id}`;
|
|
220
|
-
newVal = newVal.filter(val => val !== itemValue);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
this.$emit('input', this.multiple ? newVal : (newVal.length > 0 ? newVal[0] : null));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
152
|
get visibleList() {
|
|
227
|
-
let list = this.
|
|
153
|
+
let list = this.items.map(val => {
|
|
228
154
|
const isSelected = this.multiple
|
|
229
155
|
? Array.isArray(this.value) && this.value.map(String).includes(`${val.value}`)
|
|
230
156
|
: `${this.value}` === `${val.value}`;
|
|
@@ -237,15 +163,7 @@ class FilterFacetsList extends Vue {
|
|
|
237
163
|
if (this.isShowSelected) {
|
|
238
164
|
return list.filter((val) => val.isSelected);
|
|
239
165
|
}
|
|
240
|
-
return
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
get groupedList() {
|
|
244
|
-
if (!this.hasGroups) {
|
|
245
|
-
return this.mappedValues;
|
|
246
|
-
}
|
|
247
|
-
const groups = groupBy(this.mappedValues, (item) => item.group || '');
|
|
248
|
-
return Object.entries(groups).reduce((acc, [group, items]) => [...acc, { label: group, isGroup: true }, ...(items.map(item => ({ ...item, level: 1 })))], []);
|
|
166
|
+
return list;
|
|
249
167
|
}
|
|
250
168
|
|
|
251
169
|
get mappedValues() {
|
|
@@ -261,10 +179,6 @@ class FilterFacetsList extends Vue {
|
|
|
261
179
|
}
|
|
262
180
|
|
|
263
181
|
onFilterClick(val) {
|
|
264
|
-
if (val.isGroup) {
|
|
265
|
-
this.groupSelected(!val.isSelected, val.ids);
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
182
|
const value = `${val.value}`;
|
|
269
183
|
if (!this.multiple) {
|
|
270
184
|
return this.$emit('input', `${this.value}` === value ? null : value);
|