8000 fix(b-table): make sure to apply all formatters of field configuratio… · bootstrap-vue/bootstrap-vue@c7c14ea · GitHub
[go: up one dir, main page]

Skip to content

Commit c7c14ea

Browse files
authored
fix(b-table): make sure to apply all formatters of field configuration (closes #5672) (#5674)
* fix(b-table): make sure to apply all formatters of field configuration * Update .bundlewatch.config.json * Update .bundlewatch.config.json * Update table-filtering.spec.js
1 parent 11f8fab commit c7c14ea

File tree

3 files changed

+68
-31
lines changed

3 files changed

+68
-31
lines changed

.bundlewatch.config.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@
3434
},
3535
{
3636
"path": "./dist/bootstrap-vue.js",
37-
"maxSize": "230 kB"
37+
"maxSize": "235 kB"
3838
},
3939
{
4040
"path": "./dist/bootstrap-vue.min.js",
41-
"maxSize": "100 kB"
41+
"maxSize": "105 kB"
4242
},
4343
{
4444
"path": "./dist/bootstrap-vue.common.js",
45-
"maxSize": "305 kB"
45+
"maxSize": "310 kB"
4646
},
4747
{
4848
"path": "./dist/bootstrap-vue.common.min.js",
49-
"maxSize": "190 kB"
49+
"maxSize": "195 kB"
5050
},
5151
{
5252
"path": "./dist/bootstrap-vue.esm.js",
53-
"maxSize": "300 kB"
53+
"maxSize": "310 kB"
5454
},
5555
{
5656
"path": "./dist/bootstrap-vue.esm.min.js",
57-
"maxSize": "190 k 8000 B"
57+
"maxSize": "195 kB"
5858
},
5959
{
6060
"path": "./dist/bootstrap-vue.css",
Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
import { keys } from '../../../utils/object'
2-
import { arrayIncludes } from '../../../utils/array'
1+
import { arrayIncludes, isArray } from '../../../utils/array'
32
import { isFunction } from '../../../utils/inspect'
3+
import { clone, keys, pick } from '../../../utils/object'
44
import { IGNORED_FIELD_KEYS } from './constants'
55

66
// Return a copy of a row after all reserved fields have been filtered out
7-
const sanitizeRow = (row, ignoreFields, includeFields, fieldsObj = {}) =>
8-
keys(row).reduce((obj, key) => {
9-
// Ignore special fields that start with `_`
10-
// Ignore fields in the `ignoreFields` array
11-
// Include only fields in the `includeFields` array
12-
if (
13-
!IGNORED_FIELD_KEYS[key] &&
14-
!(ignoreFields && ignoreFields.length > 0 && arrayIncludes(ignoreFields, key)) &&
15-
!(includeFields && includeFields.length > 0 && !arrayIncludes(includeFields, key))
16-
) {
17-
const f = fieldsObj[key] || {}
18-
const val = row[key]
19-
// `f.filterByFormatted` will either be a function or boolean
20-
// `f.formater` will have already been noramlized into a function ref
21-
const filterByFormatted = f.filterByFormatted
22-
const formatter = isFunction(filterByFormatted)
23-
? /* istanbul ignore next */ filterByFormatted
24-
: filterByFormatted
25-
? /* istanbul ignore next */ f.formatter
26-
: null
27-
obj[key] = isFunction(formatter) ? formatter(val, key, row) : val
7+
const sanitizeRow = (row, ignoreFields, includeFields, fieldsObj = {}) => {
8+
// We first need to format the row based on the field configurations
9+
// This ensures that we add formatted values for keys that may not
10+
// exist in the row itself
11+
const formattedRow = keys(fieldsObj).reduce((result, key) => {
12+
const field = fieldsObj[key]
13+
const { filterByFormatted } = field
14+
const formatter = isFunction(filterByFormatted)
15+
? /* istanbul ignore next */ filterByFormatted
16+
: filterByFormatted
17+
? /* istanbul ignore next */ field.formatter
18+
: null
19+
20+
if (isFunction(formatter)) {
21+
result[key] = formatter(row[key], key, row)
2822
}
29-
return obj
30-
}, {})
23+
24+
return result
25+
}, clone(row))
26+
27+
// Determine the allowed keys:
28+
// - Ignore special fields that start with `_`
29+
// - Ignore fields in the `ignoreFields` array
30+
// - Include only fields in the `includeFields` array
31+
const allowedKeys = keys(formattedRow).filter(
32+
key =>
33+
!IGNORED_FIELD_KEYS[key] &&
34+
!(isArray(ignoreFields) && arrayIncludes(ignoreFields, key)) &&
35+
!(isArray(includeFields) && !arrayIncludes(includeFields, key))
36+
)
37+
38+
return pick(formattedRow, allowedKeys)
39+
}
3140

3241
export default sanitizeRow

src/components/table/table-filtering.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,34 @@ describe('table > filtering', () => {
207207
wrapper.destroy()
208208
})
209209

210+
it('should filter for formatted values for keys which are not present in row', async () => {
211+
const wrapper = mount(BTable, {
212+
propsData: {
213+
items: [{ a: 'A', b: 'B' }],
214+
fields: [
215+
{ key: 'a' },
216+
{
217+
key: 'b',
218+
formatter: () => 'Foo',
219+
filterByFormatted: true
220+
},
221+
{
222+
key: 'c',
223+
formatter: () => 'Bar',
224+
filterByFormatted: true
225+
}
226+
],
227+
filter: 'Bar'
228+
}
229+
})
230+
expect(wrapper).toBeDefined()
231+
await waitNT(wrapper.vm)
232+
233+
expect(wrapper.findAll('tbody > tr').length).toBe(1)
234+
235+
wrapper.destroy()
236+
})
237+
210238
it('should show empty filtered message when no matches and show-empty=true', async () => {
211239
const wrapper = mount(BTable, {
212240
propsData: {

0 commit comments

Comments
 (0)
0