elastic / elastic/sense

make autocomplete __one_of work with multiple types

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
379
Forks
128
PR merge metrics
No merged PRs in 30d

Description

We have a few cases where a field can legally be different types. The most prominent example of this is the Script API where a script can be specified as a string (example in kb rules format):

``` javascript
"script": ""
```

or as an object:

``` javascript
"script": {
__template: {
inline: ""
},
inline: "",
file: "",
id: "",
lang: "",
params: {}
}
```

We want script to be a global rule and support either of these suggestions but the following does not work:

``` javascript
api.addGlobalAutocompleteRules('script', { __one_of: [ "", {
__template: {
inline: ""
},
inline: "",
file: "",
id: "",
lang: "",
params: {}
} ] });
```

At runtime when asking for autocomplete for a script field this logs a warning as follows as does not suggest anything:

```
error while getting completion terms TypeError: component.getTerms is not a function
at http://sense.dev/app/autocomplete/body_completer.js:290:47
at Function.forEach (http://sense.dev/vendor/lodash.js:3639:15)
at ScopeResolver.cls.getTerms (http://sense.dev/app/autocomplete/body_completer.js:289:9)
at http://sense.dev/app/autocomplete/engine.js:331:30
at Function.forEach (http://sense.dev/vendor/lodash.js:3639:15)
at http://sense.dev/app/autocomplete/engine.js:330:13
at Function.forEach (http://sense.dev/vendor/lodash.js:3639:15)
at Object.exports.populateContext (http://sense.dev/app/autocomplete/engine.js:328:11)
at addBodyAutoCompleteSetToContext (http://sense.dev/app/autocomplete.js:618:29)
at getAutoCompleteContext (http://sense.dev/app/autocomplete.js:246:13)
```

I think the problem might be because `json_rule_walker.js` expects that all entries in __one_of are the same type in the `getRulesType()` method

Contributor guide

Open the contributing guide

Research direction

Start in json_rule_walker.js by reading getRulesType(), then follow the failing path through body_completer.js at ScopeResolver.getTerms() and the autocomplete.js context setup. Done means a global __one_of rule containing both a string and an object produces autocomplete suggestions for the script field without the getTerms warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
developer-experience, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.