Fixed search matching array indexes
This commit is contained in:
parent
8bb9cb10cc
commit
e5c6459f73
|
@ -84,8 +84,8 @@ export function esonToJson (eson) {
|
|||
* Transform an eson object, traverse over the whole object (excluding the _meta)
|
||||
* objects, and allow replacing Objects/Arrays/values
|
||||
* @param {ESON} eson
|
||||
* @param {function (eson, path)} callback
|
||||
* @param {Path} path
|
||||
* @param {function (ESON, Path) : ESON} callback
|
||||
* @param {Path} [path]
|
||||
* @return {ESON}
|
||||
*/
|
||||
export function transform (eson, callback, path = []) {
|
||||
|
@ -243,7 +243,8 @@ export function search (eson, text) {
|
|||
|
||||
// check property name
|
||||
const prop = last(path)
|
||||
if (typeof prop === 'string' && text !== '' && containsCaseInsensitive(prop, text)) {
|
||||
if (text !== '' && containsCaseInsensitive(prop, text) &&
|
||||
getIn(eson, initial(path))[META].type === 'Object') { // parent must be an Object
|
||||
const searchState = isEmpty(matches) ? 'active' : 'normal'
|
||||
matches.push({path, area: 'property'})
|
||||
updatedValue = setIn(updatedValue, [META, 'searchProperty'], searchState)
|
||||
|
|
|
@ -268,6 +268,21 @@ test('search', () => {
|
|||
assertDeepEqualEson(esonWithSearch, expected)
|
||||
})
|
||||
|
||||
test('search number', () => {
|
||||
const eson = jsonToEson({
|
||||
"2": "two",
|
||||
"arr": ["a", "b", "c", "2"]
|
||||
})
|
||||
const result = search(eson, '2')
|
||||
const matches = result.searchResult.matches
|
||||
|
||||
// should not match an array index, only props and values
|
||||
expect(matches).toEqual([
|
||||
{path: ['2'], area: 'property'},
|
||||
{path: ['arr', '3'], area: 'value'}
|
||||
])
|
||||
})
|
||||
|
||||
test('nextSearchResult', () => {
|
||||
const eson = jsonToEson({
|
||||
"obj": {
|
||||
|
|
Loading…
Reference in New Issue