8000 fix(b-table): properly handle empty included/excluded filter fields (closes #5775) by jacobmllr95 · Pull Request #5780 · bootstrap-vue/bootstrap-vue · GitHub
[go: up one dir, main page]

Skip to content

fix(b-table): properly handle empty included/excluded filter fields (closes #5775) #5780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,7 @@ your app handles the various inconsistencies with events.
:current-page="currentPage"
:per-page="perPage"
:filter="filter"
:filterIncludedFields="filterOn"
:filter-included-fields="filterOn"
:sort-by.sync="sortBy"
:sort-desc.sync="sortDesc"
:sort-direction="sortDirection"
Expand Down
4 changes: 2 additions & 2 deletions src/components/table/helpers/mixin-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export default {
},
computed: {
computedFilterIgnored() {
return this.filterIgnoredFields ? concat(this.filterIgnoredFields).filter(identity) : null
return concat(this.filterIgnoredFields || []).filter(identity)
},
computedFilterIncluded() {
return this.filterIncludedFields ? concat(this.filterIncludedFields).filter(identity) : null
return concat(this.filterIncludedFields || []).filter(identity)
},
computedFilterDebounce() {
const ms = toInteger(this.filterDebounce, 0)
Expand Down
4 changes: 2 additions & 2 deletions src/components/table/helpers/sanitize-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const sanitizeRow = (row, ignoreFields, includeFields, fieldsObj = {}) => {
const allowedKeys = keys(formattedRow).filter(
key =>
!IGNORED_FIELD_KEYS[key] &&
!(isArray(ignoreFields) && arrayIncludes(ignoreFields, key)) &&
!(isArray(includeFields) && !arrayIncludes(includeFields, key))
!(isArray(ignoreFields) && ignoreFields.length > 0 && arrayIncludes(ignoreFields, key)) &&
!(isArray(includeFields) && includeFields.length > 0 && !arrayIncludes(includeFields, key))
)

return pick(formattedRow, allowedKeys)
Expand Down
57 changes: 57 additions & 0 deletions src/components/table/table-filtering.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207 8000 ,6 +207,63 @@ describe('table > filtering', () => {
wrapper.destroy()
})

it('`filter-ignored-fields` prop works', async () => {
const wrapper = mount(BTable, {
propsData: {
fields: testFields,
items: testItems,
filter: '',
filterIgnoredFields: []
}
})

expect(wrapper).toBeDefined()
await waitNT(wrapper.vm)

expect(wrapper.findAll('tbody > tr').length).toBe(3)

// Search for a value in "a" column
await wrapper.setProps({ filter: '3' })
await waitNT(wrapper.vm)
expect(wrapper.findAll('tbody > tr').length).toBe(1)

// Ignore "a" column from filtering
await wrapper.setProps({ filterIgnoredFields: ['a'] })
await waitNT(wrapper.vm)
expect(wrapper.findAll('tbody > tr').length).toBe(0)

wrapper.destroy()
})

it('`filter-included-fields` prop works', async () => {
const wrapper = mount(BTable, {
propsData: {
fields: testFields,
// Add a extra item with a duplicated value in another field
items: [...testItems, { a: 4, b: 'y', c: 'a' }],
filter: '',
filterIncludedFields: []
}
})

expect(wrapper).toBeDefined()
await waitNT(wrapper.vm)

expect(wrapper.findAll('tbody > tr').length).toBe(4)

// Search for "a"
await wrapper.setProps({ filter: 'a' })
await waitNT(wrapper.vm)
expect(wrapper.findAll('tbody > tr').length).toBe(2)

// Only include "a" and "b" fields
await wrapper.setProps({ filterIncludedFields: ['a', 'b'] })
await waitNT(wrapper.vm)
expect(wrapper.findAll('tbody > tr').length).toBe(1)

wrapper.destroy()
})

it('should filter for formatted values for keys which are not present in row', async () => {
const wrapper = mount(BTable, {
propsData: {
Expand Down
0