@phoenix-cg/v-filters 0.2.6 → 0.2.7
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 +1 -1
- package/src/components/VFilters.vue +12 -6
package/package.json
CHANGED
|
@@ -146,6 +146,9 @@ export default {
|
|
|
146
146
|
fieldProps: {
|
|
147
147
|
type: Object,
|
|
148
148
|
default: () => ({})
|
|
149
|
+
},
|
|
150
|
+
noDefaultValueForEmptyFields: {
|
|
151
|
+
type: Boolean
|
|
149
152
|
}
|
|
150
153
|
},
|
|
151
154
|
data () {
|
|
@@ -176,8 +179,11 @@ export default {
|
|
|
176
179
|
Object.keys(this.filters).forEach(name => {
|
|
177
180
|
if (fieldsToInclude.includes(name) || this.sendAllFields) {
|
|
178
181
|
const filtersValue = this.filters[name]
|
|
179
|
-
const wrappedValue = getType(filtersValue) === '
|
|
180
|
-
|
|
182
|
+
const wrappedValue = getType(filtersValue) === 'Array' ? filtersValue : [filtersValue]
|
|
183
|
+
const [value] = wrappedValue
|
|
184
|
+
if (value) {
|
|
185
|
+
filters[name] = wrappedValue.map(value => value?._id || value)
|
|
186
|
+
}
|
|
181
187
|
}
|
|
182
188
|
})
|
|
183
189
|
return filters
|
|
@@ -228,9 +234,9 @@ export default {
|
|
|
228
234
|
this.addEditedField(field._name)
|
|
229
235
|
} else if (params[field._name] && isUpdate && field._type !== 'range') {
|
|
230
236
|
if (valueNotArray) {
|
|
231
|
-
const isValueInData = field.data.some(dataValue => dataValue._id === value
|
|
237
|
+
const isValueInData = field.data.some(dataValue => dataValue._id === value?._id || dataValue._id === value)
|
|
232
238
|
if (!isValueInData) {
|
|
233
|
-
value = field.data[0]
|
|
239
|
+
value = this.noDefaultValueForEmptyFields ? [] : field.data[0]
|
|
234
240
|
}
|
|
235
241
|
} else {
|
|
236
242
|
value = field.value.reduce((acc, currentValue) => {
|
|
@@ -310,7 +316,7 @@ export default {
|
|
|
310
316
|
const params = rewriteParams || { ...this.flatFilters, ...this.paramsToInclude }
|
|
311
317
|
const currentParams = this.getUrlParams()
|
|
312
318
|
const newParamsLength = Object.keys(params).length
|
|
313
|
-
if ((
|
|
319
|
+
if ((!equals(params, currentParams) || isUpdate || rewriteParams) && !this.humanLink) {
|
|
314
320
|
const query = serialize(params)
|
|
315
321
|
const url = window.location.origin + window.location.pathname + `${newParamsLength ? '?' : ''}${query}`
|
|
316
322
|
history.replaceState({ state: url }, '', url)
|
|
@@ -318,7 +324,7 @@ export default {
|
|
|
318
324
|
}
|
|
319
325
|
},
|
|
320
326
|
handleFieldChange (name, value) {
|
|
321
|
-
if (value
|
|
327
|
+
if (value) {
|
|
322
328
|
this.addEditedField(name)
|
|
323
329
|
this.removeDependentFieldsFromEdited(name)
|
|
324
330
|
} else {
|