Skip to content

chore(table): break out code into helper modules and add additional tests #2805

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 300 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
300 commits
Select commit Hold shift + click to select a range
1867fa4
Update table.js
tmorehouse Mar 9, 2019
1019b06
Update table.js
tmorehouse Mar 9, 2019
54bdd66
Update mixin-empty.js
tmorehouse Mar 9, 2019
160cfd9
Update mixin-empty.js
tmorehouse Mar 9, 2019
2e254a1
Update mixin-busy.js
tmorehouse Mar 9, 2019
819acfd
Update mixin-caption.js
tmorehouse Mar 9, 2019
cdab809
Update mixin-empty.js
tmorehouse Mar 9, 2019
b0a2eb7
Update mixin-busy.js
tmorehouse Mar 9, 2019
4ac30b7
Update mixin-busy.js
tmorehouse Mar 9, 2019
de13937
Update mixin-busy.js
tmorehouse Mar 9, 2019
aa1f0ea
Update package.json
tmorehouse Mar 9, 2019
b8219b6
Update package.json
tmorehouse Mar 9, 2019
a4cebc3
Update mixin-thead.js
tmorehouse Mar 9, 2019
bf418da
Create normalize-fields.spec.js
tmorehouse Mar 9, 2019
523ed8c
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
ed8eb5f
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
e2f1113
lint
tmorehouse Mar 9, 2019
bd0db80
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
9306166
lint
tmorehouse Mar 9, 2019
c1f0352
lint
tmorehouse Mar 9, 2019
ddc5e0e
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
a31b5e0
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
11ea5eb
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
3a51473
Update normalize-fields.js
tmorehouse Mar 9, 2019
edc1d7e
Update normalize-fields.spec.js
tmorehouse Mar 9, 2019
db2c365
lint
tmorehouse Mar 9, 2019
ab5362a
/tests/utils.js should be ignored for coverage
tmorehouse Mar 9, 2019
1337410
Merge branch 'dev' into tmorehouse/table-code
tmorehouse Mar 9, 2019
54a2f24
Update package.json
tmorehouse Mar 9, 2019
5a049f7
Create mixin-tbody-row.js
tmorehouse Mar 9, 2019
d4bb487
lint
tmorehouse Mar 9, 2019
fbde5f7
Update mixin-tbody-row.js
tmorehouse Mar 9, 2019
eb7364c
Update table.js
tmorehouse Mar 9, 2019
d0a30d2
Update mixin-tbody-row.js
tmorehouse Mar 9, 2019
5702b43
Update mixin-tbody-row.js
tmorehouse Mar 9, 2019
c1b7303
Update table.js
tmorehouse Mar 9, 2019
460e11b
lint
tmorehouse Mar 9, 2019
b6cc2bd
Update utils.js
tmorehouse Mar 9, 2019
aec6794
Update table.js
tmorehouse Mar 9, 2019
ee37572
Create table-slots.spec.js
tmorehouse Mar 10, 2019
78bf151
Update table-slots.spec.js
tmorehouse Mar 10, 2019
fda41aa
Update table-slots.spec.js
tmorehouse Mar 10, 2019
492fed8
Merge branch 'dev' into tmorehouse/table-code
tmorehouse Mar 10, 2019
892513d
lint
tmorehouse Mar 10, 2019
70e33ee
Update table-slots.spec.js
tmorehouse Mar 10, 2019
27dbc06
Update table-slots.spec.js
tmorehouse Mar 10, 2019
dfe4c74
Update table-slots.spec.js
tmorehouse Mar 10, 2019
2ac4129
Update table-slots.spec.js
tmorehouse Mar 10, 2019
1da107d
Update mixin-colgroup.js
tmorehouse Mar 10, 2019
2b8cbe6
Update mixin-colgroup.js
tmorehouse Mar 10, 2019
857ec23
Update table-slots.spec.js
tmorehouse Mar 10, 2019
5a18b52
Update table-slots.spec.js
tmorehouse Mar 10, 2019
c9872cf
Update table-slots.spec.js
tmorehouse Mar 10, 2019
91d359d
Update table-slots.spec.js
tmorehouse Mar 10, 2019
a2e9fe7
Update table-slots.spec.js
tmorehouse Mar 10, 2019
6579009
Update table-slots.spec.js
tmorehouse Mar 10, 2019
4424d51
lint
tmorehouse Mar 10, 2019
ec1f338
Update table-slots.spec.js
tmorehouse Mar 10, 2019
c798c1f
Update table-slots.spec.js
tmorehouse Mar 10, 2019
0d23acf
Update table-slots.spec.js
tmorehouse Mar 10, 2019
2005e94
Update table-slots.spec.js
tmorehouse Mar 10, 2019
e0a2afa
Update mixin-caption.js
tmorehouse Mar 10, 2019
44b3704
Rename table-slots.spec.js to table-colgroup.spec.js
tmorehouse Mar 10, 2019
bd26f40
Create table-caption.spec.js
tmorehouse Mar 11, 2019
9bfc6a5
Update table-colgroup.spec.js
tmorehouse Mar 11, 2019
f923c58
Update table-caption.spec.js
tmorehouse Mar 11, 2019
13d091a
Create table-top-row.spec.js
tmorehouse Mar 11, 2019
2bbcaaa
Update table-top-row.spec.js
tmorehouse Mar 11, 2019
80224dc
Create table-bottom-row.spec.js
tmorehouse Mar 11, 2019
e6b79e5
Update table-bottom-row.spec.js
tmorehouse Mar 11, 2019
8ca4039
Create table-thead-top.spec.js
tmorehouse Mar 11, 2019
fcdf8d3
lint
tmorehouse Mar 11, 2019
934e25c
lint
tmorehouse Mar 11, 2019
d7ccedb
Update mixin-thead.js
tmorehouse Mar 11, 2019
6741521
Update mixin-thead.js
tmorehouse Mar 11, 2019
1d0391e
Update mixin-thead.js
tmorehouse Mar 11, 2019
f9142d4
Update mixin-tfoot.js
tmorehouse Mar 11, 2019
38cb1c0
Update table.js
tmorehouse Mar 11, 2019
87dfcd4
Update mixin-caption.js
tmorehouse Mar 11, 2019
4dafe41
Update mixin-colgroup.js
tmorehouse Mar 11, 2019
e0bc53f
Update mixin-bottom-row.js
tmorehouse Mar 11, 2019
ef11ecd
Update mixin-top-row.js
tmorehouse Mar 11, 2019
875a271
Update table.js
tmorehouse Mar 11, 2019
d93d6b2
Update mixin-busy.js
tmorehouse Mar 11, 2019
6382ec6
Update mixin-empty.js
tmorehouse Mar 11, 2019
df79539
Update mixin-tbody-row.js
tmorehouse Mar 11, 2019
5d7c692
Update table.js
tmorehouse Mar 11, 2019
ef73ee3
Create mixin-tbody.js
tmorehouse Mar 11, 2019
ace8841
Update table.js
tmorehouse Mar 11, 2019
9d58183
Update mixin-tbody-row.js
tmorehouse Mar 11, 2019
4967e00
Update table.js
tmorehouse Mar 11, 2019
8056910
Update mixin-tbody.js
tmorehouse Mar 11, 2019
8135e53
Create default-sort-compare.spec.js
tmorehouse Mar 11, 2019
455f2a6
Update default-sort-compare.spec.js
tmorehouse Mar 11, 2019
cb563bb
Update default-sort-compare.js
tmorehouse Mar 11, 2019
14a9cad
Update default-sort-compare.spec.js
tmorehouse Mar 11, 2019
06ff1c8
Update default-sort-compare.spec.js
tmorehouse Mar 11, 2019
1e5ccbd
lint
tmorehouse Mar 11, 2019
bfaf2dd
Update table.js
tmorehouse Mar 11, 2019
7f2a9d4
Create table-sort.spec.js
tmorehouse Mar 11, 2019
957f4ff
Update table-sort.spec.js
tmorehouse Mar 11, 2019
e82ff6e
Update table-sort.spec.js
tmorehouse Mar 11, 2019
7866210
Update table-sort.spec.js
tmorehouse Mar 11, 2019
30e3a6c
Update table-sort.spec.js
tmorehouse Mar 11, 2019
2f7c6de
Update table-sort.spec.js
tmorehouse Mar 11, 2019
c1c46e7
Update table-sort.spec.js
tmorehouse Mar 11, 2019
dead9ee
Update table-sort.spec.js
tmorehouse Mar 11, 2019
83db5d9
Update table-sort.spec.js
tmorehouse Mar 11, 2019
090ba4b
Update table-sort.spec.js
tmorehouse Mar 11, 2019
a2e95c7
Update table-sort.spec.js
tmorehouse Mar 11, 2019
aaf050e
lint
tmorehouse Mar 11, 2019
0e199a6
Update normalize-fields.js
tmorehouse Mar 11, 2019
615e5b1
Update normalize-fields.spec.js
tmorehouse Mar 11, 2019
e0c0804
Update table-sort.spec.js
tmorehouse Mar 11, 2019
22ea673
Update table-sort.spec.js
tmorehouse Mar 11, 2019
e5cbd4b
Update table-sort.spec.js
tmorehouse Mar 11, 2019
c3b6634
Update table-sort.spec.js
tmorehouse Mar 11, 2019
588daf3
Update stringify-record-values.js
tmorehouse Mar 11, 2019
024480e
Update table-sort.spec.js
tmorehouse Mar 11, 2019
038bd60
Update table-sort.spec.js
tmorehouse Mar 11, 2019
e18cc0c
Update table-sort.spec.js
tmorehouse Mar 11, 2019
ac3c79d
Update table-sort.spec.js
tmorehouse Mar 11, 2019
fa708e4
Create table-select.spec.js
tmorehouse Mar 11, 2019
403c6ba
Update table-select.spec.js
tmorehouse Mar 11, 2019
7f21609
Update table-select.spec.js
tmorehouse Mar 11, 2019
9f7fba6
Update table-select.spec.js
tmorehouse Mar 11, 2019
8ce2711
Update table-select.spec.js
tmorehouse Mar 11, 2019
69300c9
Update table-select.spec.js
tmorehouse Mar 11, 2019
847f30f
Update table-select.spec.js
tmorehouse Mar 11, 2019
2af3afa
lint
tmorehouse Mar 11, 2019
ed86a25
Update table-select.spec.js
tmorehouse Mar 11, 2019
2c9f41b
Update table-select.spec.js
tmorehouse Mar 11, 2019
8cad69a
lint
tmorehouse Mar 11, 2019
3d4fc1e
Update table-sort.spec.js
tmorehouse Mar 11, 2019
28bc442
Update text-selection-active.js
tmorehouse Mar 11, 2019
198d828
Update mixin-thead.js
tmorehouse Mar 11, 2019
b92ffc7
Update text-selection-active.js
tmorehouse Mar 11, 2019
5583048
Update filter-event.js
tmorehouse Mar 11, 2019
aa8afb4
Merge branch 'dev' into tmorehouse/table-code
tmorehouse Mar 11, 2019
3993506
remove deprecated inverse prop
tmorehouse Mar 11, 2019
c1c055c
Create mixin-provider.js
tmorehouse Mar 11, 2019
fa6dcb3
Update mixin-provider.js
tmorehouse Mar 11, 2019
7dc9aa2
Update table.js
tmorehouse Mar 11, 2019
55f96f4
Update mixin-tbody.js
tmorehouse Mar 11, 2019
60edbf4
Update table.js
tmorehouse Mar 11, 2019
e66a3c7
Update mixin-tbody-row.js
tmorehouse Mar 11, 2019
a61133e
Update mixin-tbody.js
tmorehouse Mar 11, 2019
375eeb9
Update table.js
tmorehouse Mar 11, 2019
3feec3e
Update mixin-busy.js
tmorehouse Mar 11, 2019
b2bfbc1
Update table.js
tmorehouse Mar 11, 2019
68823f9
Update mixin-busy.js
tmorehouse Mar 11, 2019
81bc7c1
Create mixin-selectable.js
tmorehouse Mar 11, 2019
2c2fa9b
Update mixin-selectable.js
tmorehouse Mar 11, 2019
5e15ace
Update mixin-selectable.js
tmorehouse Mar 11, 2019
0d46790
Update mixin-selectable.js
tmorehouse Mar 11, 2019
62ec85d
Update mixin-selectable.js
tmorehouse Mar 11, 2019
96a25c5
Update mixin-selectable.js
tmorehouse Mar 11, 2019
fe1f1f5
Update table.js
tmorehouse Mar 11, 2019
7d1f09d
Update mixin-selectable.js
tmorehouse Mar 11, 2019
46c282f
Update mixin-tbody-row.js
tmorehouse Mar 11, 2019
9044ffd
Update table.js
tmorehouse Mar 11, 2019
db78972
lint
tmorehouse Mar 11, 2019
912363c
Update mixin-selectable.js
tmorehouse Mar 11, 2019
6ce2373
Update loose-equal.spec.js
tmorehouse Mar 11, 2019
34e19e5
Update loose-equal.spec.js
tmorehouse Mar 11, 2019
45e2aeb
Update loose-equal.spec.js
tmorehouse Mar 11, 2019
f8a8e92
Merge branch 'dev' into tmorehouse/table-code
tmorehouse Mar 11, 2019
f6c02e3
Update mixin-selectable.js
tmorehouse Mar 11, 2019
e699a3c
Update mixin-selectable.js
tmorehouse Mar 11, 2019
21ef039
Update mixin-selectable.js
tmorehouse Mar 11, 2019
240fef6
Update mixin-selectable.js
tmorehouse Mar 11, 2019
31afbc0
Update mixin-selectable.js
tmorehouse Mar 11, 2019
f8af66e
Update and rename table-select.spec.js to table-selectable.spec.js
tmorehouse Mar 11, 2019
91c8320
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
3102353
lint
tmorehouse Mar 11, 2019
ce5e4da
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
f88ff83
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
4f8952e
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
18bb3e7
lint
tmorehouse Mar 11, 2019
88048d8
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
641c2d3
Update mixin-thead.js
tmorehouse Mar 11, 2019
806a2ec
Update mixin-selectable.js
tmorehouse Mar 11, 2019
8ede419
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
b32f355
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
82d6bc2
Update table-selectable.spec.js
tmorehouse Mar 11, 2019
2f53128
Update mixin-selectable.js
tmorehouse Mar 11, 2019
88e2144
Update mixin-busy.js
tmorehouse Mar 11, 2019
e96eaa3
Update table.js
tmorehouse Mar 11, 2019
6a46a70
Create table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
2752c62
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
b5466fc
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
c823f65
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
9c63b45
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
1ef2b38
lint
tmorehouse Mar 12, 2019
13c08d7
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
271d931
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
b6c2912
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
ff0ac99
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
52fb284
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
22d5018
Update table-tbody-transition.spec.js
tmorehouse Mar 12, 2019
3f963d2
Create table-body-row-events.spec.js
tmorehouse Mar 12, 2019
1b420e0
Update and rename table-body-row-events.spec.js to table-tbody-row-ev…
tmorehouse Mar 12, 2019
ef8eafa
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
64703ac
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
f9e66d2
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
1e31bbc
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
1da7de9
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
42d00af
lint
tmorehouse Mar 12, 2019
32fe357
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
45b5c2c
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
b65792d
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
f6c332c
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
cba0eb5
Update table-tbody-row-events.spec.js
tmorehouse Mar 12, 2019
007507e
Update loose-equal.spec.js
tmorehouse Mar 12, 2019
1c90758
Update text-selection-active.js
tmorehouse Mar 12, 2019
c26670d
lint
tmorehouse Mar 12, 2019
d0e3436
Update text-selection-active.js
tmorehouse Mar 12, 2019
1b8a57f
Update mixin-thead.js
tmorehouse Mar 12, 2019
2ed8a6e
Update mixin-tbody-row.js
tmorehouse Mar 12, 2019
47a4f58
Update text-selection-active.js
tmorehouse Mar 12, 2019
a22611b
Update mixin-thead.js
tmorehouse Mar 12, 2019
fa56ec5
Update text-selection-active.js
tmorehouse Mar 12, 2019
3aaeb48
Update text-selection-active.js
tmorehouse Mar 12, 2019
ab4f073
Update _table.scss
tmorehouse Mar 12, 2019
b837461
Merge branch 'dev' into tmorehouse/table-code
tmorehouse Mar 12, 2019
5669a5f
Update mixin-busy.js
tmorehouse Mar 12, 2019
3bb21fe
Update table.js
tmorehouse Mar 12, 2019
6bf5d67
Update text-selection-active.js
tmorehouse Mar 12, 2019
e3c01f3
lint
tmorehouse Mar 12, 2019
3691dd6
Update text-selection-active.js
tmorehouse Mar 12, 2019
f816ce7
Create table-thead-events.spec.js
tmorehouse Mar 12, 2019
d9fa5c1
lint
tmorehouse Mar 12, 2019
7395bd1
Update table-thead-events.spec.js
tmorehouse Mar 12, 2019
99212d0
Update table-thead-events.spec.js
tmorehouse Mar 12, 2019
15f22ff
Update table-thead-events.spec.js
tmorehouse Mar 12, 2019
09f501e
Merge branch 'dev' into tmorehouse/table-code
tmorehouse Mar 12, 2019
f0c69f4
Update mixin-thead.js
tmorehouse Mar 12, 2019
dda2c0b
Create table-row-details.spec.js
tmorehouse Mar 12, 2019
e939781
lint
tmorehouse Mar 12, 2019
65af056
Update table-row-details.spec.js
tmorehouse Mar 12, 2019
f15138a
Update mixin-tbody-row.js
tmorehouse Mar 12, 2019
5ae81cb
Update mixin-thead.js
tmorehouse Mar 12, 2019
e417700
Update mixin-tbody.js
tmorehouse Mar 12, 2019
ea74bb0
Update mixin-top-row.js
tmorehouse Mar 12, 2019
71953d1
Update mixin-bottom-row.js
tmorehouse Mar 12, 2019
2550163
Update mixin-tbody-row.js
tmorehouse Mar 12, 2019
d072559
lint
tmorehouse Mar 12, 2019
c4cbd20
Update mixin-thead.js
tmorehouse Mar 12, 2019
5de750e
Create table-tfoot-events.spec.js
tmorehouse Mar 12, 2019
9c46ff9
Update table-tfoot-events.spec.js
tmorehouse Mar 12, 2019
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/_table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@
/* b-table: selectable rows */
table.b-table.b-table-selectable > tbody > tr {
cursor: pointer;
user-select: none;
// user-select: none;
}
25 changes: 25 additions & 0 deletions src/components/table/helpers/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Constants used by table helpers

// Object of item keys that should be ignored for headers and stringification and filter events
export const IGNORED_FIELD_KEYS = {
_rowVariant: true,
_cellVariants: true,
_showDetails: true
}

// Filter CSS Selector for click/dblclick/etc events
// If any of these selectors match the clicked element, we ignore the event
export const EVENT_FILTER = [
'a',
'a *', // include content inside links
'button',
'button *', // include content inside buttons
'input:not(.disabled):not([disabled])',
'select:not(.disabled):not([disabled])',
'textarea:not(.disabled):not([disabled])',
'[role="link"]',
'[role="link"] *',
'[role="button"]',
'[role="button"] *',
'[tabindex]:not(.disabled):not([disabled])'
].join(',')
32 changes: 32 additions & 0 deletions src/components/table/helpers/default-sort-compare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import get from '../../../utils/get'
import stringifyObjectValues from './stringify-object-values'

// Default sort compare routine
//
// TODO: add option to sort by multiple columns (tri-state per column, plus order of columns in sort)
// where sprtBy could be an array of objects [ {key: 'foo', sortDir: 'asc'}, {key:'bar', sortDir: 'desc'} ...]
// or an array of arrays [ ['foo','asc'], ['bar','desc'] ]

export default function defaultSortCompare(a, b, sortBy) {
a = get(a, sortBy, '')
b = get(b, sortBy, '')
if (
(a instanceof Date && b instanceof Date) ||
(typeof a === 'number' && typeof b === 'number')
) {
// Special case for comparing Dates and Numbers
// Internally dates are compared via their epoch number values
if (a < b) {
return -1
} else if (a > b) {
return 1
} else {
return 0
}
} else {
// Do localized string comparison
return stringifyObjectValues(a).localeCompare(stringifyObjectValues(b), undefined, {
numeric: true
})
}
}
46 changes: 46 additions & 0 deletions src/components/table/helpers/default-sort-compare.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import defaultSortCompare from './default-sort-compare'

describe('table/helpers/default-sort-compare', () => {
it('sorts numbers correctly', async () => {
expect(defaultSortCompare({ a: 1 }, { a: 2 }, 'a')).toBe(-1)
expect(defaultSortCompare({ a: 2 }, { a: 1 }, 'a')).toBe(1)
expect(defaultSortCompare({ a: 1 }, { a: 1 }, 'a')).toBe(0)
expect(defaultSortCompare({ a: -1 }, { a: 1 }, 'a')).toBe(-1)
expect(defaultSortCompare({ a: 1 }, { a: -1 }, 'a')).toBe(1)
expect(defaultSortCompare({ a: 0 }, { a: 0 }, 'a')).toBe(0)
expect(defaultSortCompare({ a: 1.234 }, { a: 1.567 }, 'a')).toBe(-1)
expect(defaultSortCompare({ a: 1.561 }, { a: 1.234 }, 'a')).toBe(1)
})

it('sorts dates correctly', async () => {
const date1 = { a: new Date(2019, 1, 1) }
const date2 = { a: new Date(1999, 11, 31) }
const date3 = { a: new Date(1999, 1, 1) }
const date4 = { a: new Date(1999, 1, 1, 12, 12, 12, 12) }

expect(defaultSortCompare(date1, date2, 'a')).toBe(1)
expect(defaultSortCompare(date1, date1, 'a')).toBe(0)
expect(defaultSortCompare(date2, date1, 'a')).toBe(-1)
expect(defaultSortCompare(date2, date3, 'a')).toBe(1)
expect(defaultSortCompare(date3, date2, 'a')).toBe(-1)
expect(defaultSortCompare(date3, date4, 'a')).toBe(-1)
expect(defaultSortCompare(date4, date3, 'a')).toBe(1)
expect(defaultSortCompare(date4, date4, 'a')).toBe(0)
})

it('sorts strings correctly', async () => {
// Note: string comparisons are locale based
expect(defaultSortCompare({ a: 'a' }, { a: 'b' }, 'a')).toBe(-1)
expect(defaultSortCompare({ a: 'b' }, { a: 'a' }, 'a')).toBe(1)
expect(defaultSortCompare({ a: 'a' }, { a: 'a' }, 'a')).toBe(0)
expect(defaultSortCompare({ a: 'a' }, { a: 'aaa' }, 'a')).toBe(-1)
})

it('sorts by nested key correctly', async () => {
// Note: string comparisons are locale based
expect(defaultSortCompare({ a: { b: 'a' } }, { a: { b: 'b' } }, 'a.b')).toBe(-1)
expect(defaultSortCompare({ a: { b: 'b' } }, { a: { b: 'a' } }, 'a.b')).toBe(1)
expect(defaultSortCompare({ a: { b: 'a' } }, { a: { b: 'a' } }, 'a.b')).toBe(0)
expect(defaultSortCompare({ a: { b: 'a' } }, { a: { b: 'aaa' } }, 'a.b')).toBe(-1)
})
})
29 changes: 29 additions & 0 deletions src/components/table/helpers/filter-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { closest, matches } from '../../../utils/dom'
import { EVENT_FILTER } from './constants'

// Returns true of we should ignore the click/dbclick/keypress event
// Avoids having the user need to use @click.stop on the form control

export default function filterEvent(evt) {
if (!evt || !evt.target) {
/* istanbul ignore next */
return
}
const el = evt.target
if (el.tagName === 'TD' || el.tagName === 'TH' || el.tagName === 'TR' || el.disabled) {
// Shortut all the following tests for efficiency
return false
}
if (closest('.dropdown-menu', el)) {
// Click was in a dropdown menu, so ignore
return true
}
const label = el.tagName === 'LABEL' ? el : closest('label', el)
if (label && label.control && !label.control.disabled) {
// If the label's form control is not disabled then we don't propagate evt
return true
}
// Else check to see if the event target matches one of the selectors in the event filter
// i.e. anchors, non disabled inputs, etc. Return true if we should ignore the event.
return matches(el, EVENT_FILTER)
}
30 changes: 30 additions & 0 deletions src/components/table/helpers/mixin-bottom-row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default {
methods: {
renderBottomRow() {
const h = this.$createElement

// Static bottom row slot (hidden in visibly stacked mode as we can't control the data-label)
// If in always stacked mode, we don't bother rendering the row
if (!this.hasNormalizedSlot('bottom-row') || this.isStacked === true) {
return h(false)
}

const fields = this.computedFields

return h(
'tr',
{
key: '__b-table-bottom-row__',
staticClass: 'b-table-bottom-row',
class: [
typeof this.tbodyTrClass === 'function'
? this.tbodyTrClass(null, 'row-bottom')
: this.tbodyTrClass
],
attrs: { role: 'row' }
},
this.normalizeSlot('bottom-row', { columns: fields.length, fields: fields })
)
}
}
}
71 changes: 71 additions & 0 deletions src/components/table/helpers/mixin-busy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export default {
props: {
busy: {
type: Boolean,
default: false
}
},
data() {
return {
localBusy: false
}
},
computed: {
computedBusy() {
return this.busy || this.localBusy
}
},
watch: {
localBusy(newVal, oldVal) {
if (newVal !== oldVal) {
this.$emit('update:busy', newVal)
}
}
},
methods: {
// Event handler helper
stopIfBusy(evt) {
if (this.computedBusy) {
// If table is busy (via provider) then don't propagate
evt.preventDefault()
evt.stopPropagation()
return true
}
return false
},
// Renter the busy indecator or return null if not busy
renderBusy() {
const h = this.$createElement

// Return a busy indicator row, or null if not busy
if (this.computedBusy && this.hasNormalizedSlot('table-busy')) {
// Show the busy slot
const trAttrs = {
role: this.isStacked ? 'row' : null
}
const tdAttrs = {
colspan: String(this.computedFields.length),
role: this.isStacked ? 'cell' : null
}
return h(
'tr',
{
key: 'table-busy-slot',
staticClass: 'b-table-busy-slot',
class: [
typeof this.tbodyTrClass === 'function'
? this.tbodyTrClass(null, 'table-busy')
: this.tbodyTrClass
],
attrs: trAttrs
},
[h('td', { attrs: tdAttrs }, [this.normalizeSlot('table-busy', {})])]
)
} else {
// We return null here so that we can determine if we need to
// render the table items rows or not.
return null
}
}
}
}
52 changes: 52 additions & 0 deletions src/components/table/helpers/mixin-caption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { htmlOrText } from '../../../utils/html'

export default {
props: {
caption: {
type: String,
default: null
},
captionHtml: {
type: String
},
captionTop: {
type: Boolean,
default: false
}
},
computed: {
captionClasses() {
return {
'b-table-caption-top': this.captionTop
}
},
captionId() {
// Even though this.safeId looks like a method, it is a computed prop
// that returns a new function if the underlying ID changes
return this.isStacked ? this.safeId('_caption_') : null
}
},
methods: {
renderCaption() {
const h = this.$createElement

// Build the caption
const $captionSlot = this.normalizeSlot('table-caption', {})
let $caption = h(false)

if ($captionSlot || this.caption || this.captionHtml) {
const data = {
key: 'caption',
class: this.captionClasses,
attrs: { id: this.captionId }
}
if (!$captionSlot) {
data.domProps = htmlOrText(this.captionHtml, this.caption)
}
$caption = h('caption', data, [$captionSlot])
}

return $caption
}
}
}
18 changes: 18 additions & 0 deletions src/components/table/helpers/mixin-colgroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
methods: {
renderColgroup() {
const h = this.$createElement

const fields = this.computedFields
let $colgroup = h(false)

if (this.hasNormalizedSlot('table-colgroup')) {
$colgroup = h('colgroup', { key: 'colgroup' }, [
this.normalizeSlot('table-colgroup', { columns: fields.length, fields: fields })
])
}

return $colgroup
}
}
}
81 changes: 81 additions & 0 deletions src/components/table/helpers/mixin-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { htmlOrText } from '../../../utils/html'

export default {
props: {
showEmpty: {
type: Boolean,
default: false
},
emptyText: {
type: String,
default: 'There are no records to show'
},
emptyHtml: {
type: String
},
emptyFilteredText: {
type: String,
default: 'There are no records matching your request'
},
emptyFilteredHtml: {
type: String
}
},
methods: {
renderEmpty() {
const h = this.$createElement
const items = this.computedItems
let $empty

if (
this.showEmpty &&
(!items || items.length === 0) &&
!(this.computedBusy && this.hasNormalizedSlot('table-busy'))
) {
$empty = this.normalizeSlot(this.isFiltered ? 'emptyfiltered' : 'empty', {
emptyFilteredHtml: this.emptyFilteredHtml,
emptyFilteredText: this.emptyFilteredText,
emptyHtml: this.emptyHtml,
emptyText: this.emptyText,
fields: this.computedFields,
// Not sure why this is included, as it will always be an empty array
items: this.computedItems
})
if (!$empty) {
$empty = h('div', {
class: ['text-center', 'my-2'],
domProps: this.isFiltered
? htmlOrText(this.emptyFilteredHtml, this.emptyFilteredText)
: htmlOrText(this.emptyHtml, this.emptyText)
})
}
$empty = h(
'td',
{
attrs: {
colspan: String(this.computedFields.length),
role: this.isStacked ? 'cell' : null
}
},
[h('div', { attrs: { role: 'alert', 'aria-live': 'polite' } }, [$empty])]
)
$empty = h(
'tr',
{
key: this.isFiltered ? '_b-table-empty-filtered-row_' : '_b-table-empty-row_',
staticClass: 'b-table-empty-row',
class: [
typeof this.tbodyTrClass === 'function'
? this.tbodyTrClass(null, 'row-empty')
: this.tbodyTrClass
],
attrs: this.isStacked ? { role: 'row' } : {}
},
[$empty]
)
}

return $empty || h(false)
}
}
}
Loading