feat(complex-matcher) : raw numbers can match strings (#3552)
Fixes #2906
This commit is contained in:
parent
64d295ee3f
commit
1a528adfbb
@ -13,6 +13,7 @@
|
|||||||
- [Usage Report] Add top 3 VMs which use the most IOPS read/write/total [#3308](https://github.com/vatesfr/xen-orchestra/issues/3308) (PR [#3463](https://github.com/vatesfr/xen-orchestra/pull/3463))
|
- [Usage Report] Add top 3 VMs which use the most IOPS read/write/total [#3308](https://github.com/vatesfr/xen-orchestra/issues/3308) (PR [#3463](https://github.com/vatesfr/xen-orchestra/pull/3463))
|
||||||
- [Settings/logs] Homogenize action buttons in table and enable bulk deletion [#3179](https://github.com/vatesfr/xen-orchestra/issues/3179) (PR [#3528](https://github.com/vatesfr/xen-orchestra/pull/3528))
|
- [Settings/logs] Homogenize action buttons in table and enable bulk deletion [#3179](https://github.com/vatesfr/xen-orchestra/issues/3179) (PR [#3528](https://github.com/vatesfr/xen-orchestra/pull/3528))
|
||||||
- [Settings/acls] Add bulk deletion [#3179](https://github.com/vatesfr/xen-orchestra/issues/3179) (PR [#3536](https://github.com/vatesfr/xen-orchestra/pull/3536))
|
- [Settings/acls] Add bulk deletion [#3179](https://github.com/vatesfr/xen-orchestra/issues/3179) (PR [#3536](https://github.com/vatesfr/xen-orchestra/pull/3536))
|
||||||
|
- [Home] Improve search usage: raw numbers also match in names [#2906](https://github.com/vatesfr/xen-orchestra/issues/2906) (PR [#3552](https://github.com/vatesfr/xen-orchestra/pull/3552))
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
@ -26,6 +27,7 @@
|
|||||||
|
|
||||||
- xo-common v0.1.2
|
- xo-common v0.1.2
|
||||||
- @xen-orchestra/fs v0.4.0
|
- @xen-orchestra/fs v0.4.0
|
||||||
|
- complex-matcher v0.5.0
|
||||||
- vhd-lib v0.4.0
|
- vhd-lib v0.4.0
|
||||||
- xen-api v0.20.0
|
- xen-api v0.20.0
|
||||||
- xo-server-usage-report v0.7.0
|
- xo-server-usage-report v0.7.0
|
||||||
|
@ -11,7 +11,7 @@ export const ast = new CM.And([
|
|||||||
new CM.Or([new CM.String('wonderwoman'), new CM.String('batman')])
|
new CM.Or([new CM.String('wonderwoman'), new CM.String('batman')])
|
||||||
),
|
),
|
||||||
new CM.TruthyProperty('hasCape'),
|
new CM.TruthyProperty('hasCape'),
|
||||||
new CM.Property('age', new CM.Number(32)),
|
new CM.Property('age', new CM.NumberOrStringNode('32')),
|
||||||
new CM.GlobPattern('chi*go'),
|
new CM.GlobPattern('chi*go'),
|
||||||
new CM.RegExp('^foo/bar\\.', 'i'),
|
new CM.RegExp('^foo/bar\\.', 'i'),
|
||||||
])
|
])
|
||||||
|
@ -153,6 +153,34 @@ export class NumberNode extends Node {
|
|||||||
}
|
}
|
||||||
export { NumberNode as Number }
|
export { NumberNode as Number }
|
||||||
|
|
||||||
|
export class NumberOrStringNode extends Node {
|
||||||
|
constructor (value) {
|
||||||
|
super()
|
||||||
|
|
||||||
|
this.value = value
|
||||||
|
|
||||||
|
// should not be enumerable for the tests
|
||||||
|
Object.defineProperty(this, 'match', {
|
||||||
|
value: this.match.bind(this, value.toLowerCase(), +value),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
match (lcValue, numValue, value) {
|
||||||
|
return (
|
||||||
|
value === numValue ||
|
||||||
|
(typeof value === 'string'
|
||||||
|
? value.toLowerCase().indexOf(lcValue) !== -1
|
||||||
|
: (Array.isArray(value) || isPlainObject(value)) &&
|
||||||
|
some(value, this.match))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
toString () {
|
||||||
|
return this.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export { NumberOrStringNode as NumberOrString }
|
||||||
|
|
||||||
export class Property extends Node {
|
export class Property extends Node {
|
||||||
constructor (name, child) {
|
constructor (name, child) {
|
||||||
super()
|
super()
|
||||||
@ -564,7 +592,7 @@ const parser = P.grammar({
|
|||||||
const asNum = +str
|
const asNum = +str
|
||||||
return Number.isNaN(asNum)
|
return Number.isNaN(asNum)
|
||||||
? new GlobPattern(str)
|
? new GlobPattern(str)
|
||||||
: new NumberNode(asNum)
|
: new NumberOrStringNode(str)
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
ws: P.regex(/\s*/),
|
ws: P.regex(/\s*/),
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
GlobPattern,
|
GlobPattern,
|
||||||
Null,
|
Null,
|
||||||
NumberNode,
|
NumberNode,
|
||||||
|
NumberOrStringNode,
|
||||||
parse,
|
parse,
|
||||||
setPropertyClause,
|
setPropertyClause,
|
||||||
} from './'
|
} from './'
|
||||||
@ -32,7 +33,7 @@ describe('parse', () => {
|
|||||||
|
|
||||||
node = parse('32')
|
node = parse('32')
|
||||||
expect(node.match(32)).toBe(true)
|
expect(node.match(32)).toBe(true)
|
||||||
expect(node.match('32')).toBe(false)
|
expect(node.match('32')).toBe(true)
|
||||||
expect(node.toString()).toBe('32')
|
expect(node.toString()).toBe('32')
|
||||||
|
|
||||||
node = parse('"32"')
|
node = parse('"32"')
|
||||||
@ -54,6 +55,12 @@ describe('Number', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('NumberOrStringNode', () => {
|
||||||
|
it('match a string', () => {
|
||||||
|
expect(new NumberOrStringNode('123').match([{ foo: '123' }])).toBe(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('setPropertyClause', () => {
|
describe('setPropertyClause', () => {
|
||||||
it('creates a node if none passed', () => {
|
it('creates a node if none passed', () => {
|
||||||
expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe(
|
expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe(
|
||||||
|
Loading…
Reference in New Issue
Block a user