diff --git a/CHANGELOG.md b/CHANGELOG.md index e8589d0e4..235620927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) - [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)) +- [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 @@ -26,6 +27,7 @@ - xo-common v0.1.2 - @xen-orchestra/fs v0.4.0 +- complex-matcher v0.5.0 - vhd-lib v0.4.0 - xen-api v0.20.0 - xo-server-usage-report v0.7.0 diff --git a/packages/complex-matcher/src/index.fixtures.js b/packages/complex-matcher/src/index.fixtures.js index a93e29358..70cfa5b54 100644 --- a/packages/complex-matcher/src/index.fixtures.js +++ b/packages/complex-matcher/src/index.fixtures.js @@ -11,7 +11,7 @@ export const ast = new CM.And([ new CM.Or([new CM.String('wonderwoman'), new CM.String('batman')]) ), 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.RegExp('^foo/bar\\.', 'i'), ]) diff --git a/packages/complex-matcher/src/index.js b/packages/complex-matcher/src/index.js index 604fd42e6..d49faad7f 100644 --- a/packages/complex-matcher/src/index.js +++ b/packages/complex-matcher/src/index.js @@ -153,6 +153,34 @@ export class NumberNode extends Node { } 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 { constructor (name, child) { super() @@ -564,7 +592,7 @@ const parser = P.grammar({ const asNum = +str return Number.isNaN(asNum) ? new GlobPattern(str) - : new NumberNode(asNum) + : new NumberOrStringNode(str) }) ), ws: P.regex(/\s*/), diff --git a/packages/complex-matcher/src/index.spec.js b/packages/complex-matcher/src/index.spec.js index 2ef5ec7fd..3396cc623 100644 --- a/packages/complex-matcher/src/index.spec.js +++ b/packages/complex-matcher/src/index.spec.js @@ -6,6 +6,7 @@ import { GlobPattern, Null, NumberNode, + NumberOrStringNode, parse, setPropertyClause, } from './' @@ -32,7 +33,7 @@ describe('parse', () => { node = parse('32') expect(node.match(32)).toBe(true) - expect(node.match('32')).toBe(false) + expect(node.match('32')).toBe(true) expect(node.toString()).toBe('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', () => { it('creates a node if none passed', () => { expect(setPropertyClause(undefined, 'foo', 'bar').toString()).toBe(