kibana/packages/kbn-spec-to-console/lib/convert/parts.js
Yulia Čech 04b3d1741c
[Console] Update dynamic parameters for the new script (#162917)
## Summary
Fixes https://github.com/elastic/kibana/issues/160539

This PR updates the logic for dynamic parameters in the Console
autocomplete engine in preparation for the new script.

#### Changes
- The old script `packages/spec-to-console` contained some logic that
would rename parameters in the json specs: `{index} -> {indices`},
`{node_id} -> {nodes}, {metric} -> {metrics}`. I don't think we need
this anymore because such logic only introduces more hidden mechanics to
the script. There is no significant improvements to autocomplete
suggestions due to these replacements.
- The dynamic parameters defined in the Console autocomplete engine: 
- `indices` - is deleted and only `index` is used instead. Originally,
there was a minor difference between `indices` and `index`: the former
should accept several index names, the latter only 1. [But this logic is
not working for urls currently
anyways](https://github.com/elastic/kibana/issues/163000). I don't think
there is a significant improvement for UX to keep this distinction. The
main useful feature of this parameter is to display a list of indices in
the deployment.
- `type` and `types` - deleted because `index mapping types` is a
removed ES feature (see this
[doc](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html))
- `id`, `transform_id`, `ids`, `task_id` - deleted as not working. Also
definitions using these parameters don't intend them to be autofilled.
For example, in the url `/_async_search/{id}` the parameter `{id}` can
be any string.
- `user` and `username` - deleted as incorrectly being resolved to a
list of indices. Also definitions using these parameters don't intend
them to be autofilled, for example `_security/user/{username}` when
creating a new user.
  - `node` - delete because it was just an empty list
- `nodes` - deleted because the suggestions of the form `['_local',
'_master', 'data:true', 'data:false', 'master:true', 'master:false']`
are not correct for definitions where a node ID is expected.
- Renamed `variables` to `dynamic parameters` in the Console README
file: I first used the word `variables` in readme for the values defined
in the file
[`kb.js`](6e1445b66a/src/plugins/console/public/lib/kb/kb.js).
But then variables support was added to Console and there were several
sections in the readme using the word `variables` for different
concepts. Since in the autocomplete engine code, the function is called
`parametrizedComponentFactories` I think calling these values `dynamic
parameters` makes more sense and avoids confusion.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
2023-08-04 06:42:41 -07:00

23 lines
725 B
JavaScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
const replacePattern = require('../replace_pattern');
module.exports = (parts) => {
const result = {};
Object.keys(parts).forEach((part) => {
const key = replacePattern(part);
const options = parts[part].options;
if (options && options.length) {
result[key] = options.sort();
} else {
result[key] = null;
}
});
return result;
};