Skip to content
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

add no maching label #429

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
'no-console': 0,
'no-warning-comments': 0,
'no-undefined': 0,
'prefer-destructuring': 0,
'prefer-destructuring': 0
},
overrides: [ {
files: [ 'src/**' ],
Expand Down
5 changes: 5 additions & 0 deletions docs/components/DocProps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@
type: 'String',
defaultValue: code('"No sub-options."'),
description: 'Text displayed when a branch node has no children.',
}, {
name: 'noMatchingLabel',
type: 'String',
defaultValue: code('"unknown"'),
description: 'Label displayed when there are no matching options.',
}, {
name: 'noOptionsText',
type: 'String',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"babel-plugin-transform-vue-jsx": "^4.0.1",
"cache-loader": "^4.0.1",
"chalk": "^2.3.2",
"codecov": "^3.0.0",
"codecov": "^3.0.0",
"connect-history-api-fallback": "^1.5.0",
"copy-webpack-plugin": "^5.0.3",
"css-loader": "^3.0.0",
Expand Down
14 changes: 13 additions & 1 deletion src/mixins/treeselectMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default {
},

props: {


/**
* Whether to allow resetting value even if there are disabled selected nodes.
*/
Expand Down Expand Up @@ -408,6 +410,14 @@ export default {
default: 'No sub-options.',
},

/**
* Label displayed when there are no matching options.
*/
noMatchingLabel: {
type: String,
default: 'unknown',
},

/**
* Text displayed when there are no available options.
*/
Expand Down Expand Up @@ -976,7 +986,9 @@ export default {
// When the real data is loaded, we'll override this fake node.

const raw = this.extractNodeFromValue(id)
const label = this.enhancedNormalizer(raw).label || `${id} (unknown)`
// const label = this.enhancedNormalizer(raw).label || `${id} (unknown)`
const label = this.enhancedNormalizer(raw).label || `${this.noMatchingLabel}`

const fallbackNode = {
id,
label,
Expand Down
9 changes: 7 additions & 2 deletions test/unit/specs/Basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,19 @@ describe('Basic', () => {
const wrapper = mount(Treeselect, {
propsData: {
value: 'a',
noMatchingLabel: 'aa',
options: [],
},
})
const { vm } = wrapper

// expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
// id: 'a',
// label: 'a (unknown)',
// isFallbackNode: true,
// }))
expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
id: 'a',
label: 'a (unknown)',
label: 'aa',
isFallbackNode: true,
}))
})
Expand Down
23 changes: 19 additions & 4 deletions test/unit/specs/DynamicalLoading.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ describe('Dynamical Loading', () => {
children: null,
} ],
value: 'aa', // <- this creates a fallback node
noMatchingLabel: 'labelAA',
loadOptions({ parentNode, callback }) {
setTimeout(() => {
parentNode.children = [ {
Expand All @@ -342,12 +343,19 @@ describe('Dynamical Loading', () => {
const { vm } = wrapper
const getValueText = () => wrapper.find('.vue-treeselect__single-value').text().trim()

// expect(vm.forest.nodeMap.aa).toEqual(jasmine.objectContaining({
// id: 'aa',
// label: 'aa (unknown)',
// isFallbackNode: true,
// }))
// expect(getValueText()).toBe('aa (unknown)')

expect(vm.forest.nodeMap.aa).toEqual(jasmine.objectContaining({
id: 'aa',
label: 'aa (unknown)',
label: 'labelAA',
isFallbackNode: true,
}))
expect(getValueText()).toBe('aa (unknown)')
expect(getValueText()).toBe('labelAA')

vm.toggleExpanded(vm.forest.nodeMap.a)
await sleep(DELAY)
Expand Down Expand Up @@ -824,6 +832,7 @@ describe('Dynamical Loading', () => {
data: {
options: null,
value: 'a', // <- this creates a fallback node
noMatchingLabel: 'aa',
loadOptions({ callback }) {
setTimeout(() => {
app.options = [ {
Expand All @@ -841,19 +850,25 @@ describe('Dynamical Loading', () => {
:options="options"
:load-options="loadOptions"
:auto-load-root-options= "true"
:noMatchingLabel="noMatchingLabel"
/>
</div>
`,
}).$mount()
const vm = app.$children[0]

expect(vm.rootOptionsStates.isLoading).toBe(true)
// expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
// id: 'a',
// label: 'a (unknown)',
// isFallbackNode: true,
// }))
expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
id: 'a',
label: 'a (unknown)',
label: 'aa',
isFallbackNode: true,
}))


await sleep(DELAY)
expect(vm.rootOptionsStates.isLoading).toBe(false)
expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
Expand Down
11 changes: 8 additions & 3 deletions test/unit/specs/Props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,22 +1818,27 @@ describe('Props', () => {
propsData: {
options: [],
value: 'a', // this creates a fallback node
noMatchingLabel: 'abc',
},
})
const { vm } = wrapper

// expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
// isFallbackNode: true,
// label: 'a (unknown)',
// }))
expect(vm.forest.nodeMap.a).toEqual(jasmine.objectContaining({
isFallbackNode: true,
label: 'a (unknown)',
label: 'abc',
}))

wrapper.setProps({
options: [ {
id: 'a',
label: 'a',
label: 'abcde',
} ],
})
expect(vm.forest.nodeMap.a.label).toBe('a')
expect(vm.forest.nodeMap.a.label).toBe('abcde')
})

it('directly modify `options` prop should trigger reinitializing', async () => {
Expand Down