-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Docs][Dashboards API] Add field descriptions to controls schemas #263282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
be4f1f9
5edcd9c
6c2904a
81c2b9c
e5ffb59
96592e3
5c1f0f0
ad08eb5
6e2122a
d91d1b4
16d2d8e
7341c7e
8ba56fa
6b1e354
3a53891
214d9b3
89191e5
ae3bad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,27 +18,82 @@ import { controlTitleSchema, dataControlSchema } from './control_schema'; | |
| const SELECTIONS_MAX = 10000; | ||
|
|
||
| export const optionsListDisplaySettingsSchema = schema.object({ | ||
| placeholder: schema.maybe(schema.string()), | ||
| hide_action_bar: schema.maybe(schema.boolean()), | ||
| hide_exclude: schema.maybe(schema.boolean()), | ||
| hide_exists: schema.maybe(schema.boolean()), | ||
| hide_sort: schema.maybe(schema.boolean()), | ||
| placeholder: schema.maybe( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's neat to have these extra options well defined. This is a good example of a pattern we'll make more use of in the future, where extra customizability is available via the API that doesn't have a direct way to be set via the UI. |
||
| schema.string({ | ||
| meta: { | ||
| description: 'Placeholder text displayed in the control input when no option is selected.', | ||
| }, | ||
| }) | ||
| ), | ||
| hide_action_bar: schema.maybe( | ||
| schema.boolean({ | ||
| meta: { | ||
| description: 'When `true`, the apply and clear actions are hidden from the control.', | ||
| }, | ||
| }) | ||
| ), | ||
|
florent-leborgne marked this conversation as resolved.
|
||
| hide_exclude: schema.maybe( | ||
| schema.boolean({ | ||
| meta: { | ||
| description: 'When `true`, the exclude mode toggle is hidden from the control.', | ||
| }, | ||
| }) | ||
| ), | ||
| hide_exists: schema.maybe( | ||
| schema.boolean({ | ||
| meta: { | ||
| description: 'When `true`, the exists filter option is hidden from the control.', | ||
| }, | ||
| }) | ||
| ), | ||
| hide_sort: schema.maybe( | ||
| schema.boolean({ | ||
| meta: { | ||
| description: 'When `true`, the sort selector is hidden from the control.', | ||
| }, | ||
| }) | ||
| ), | ||
| }); | ||
|
|
||
| export const optionsListSearchTechniqueSchema = schema.oneOf( | ||
| [schema.literal('prefix'), schema.literal('wildcard'), schema.literal('exact')], | ||
| { defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.search_technique } | ||
| { | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.search_technique, | ||
| meta: { | ||
| description: | ||
| 'The matching technique used when searching available options. `prefix` matches values starting with the search term, `wildcard` matches values containing the search term, and `exact` requires a complete match. Only applies to string and IP fields. Defaults to `wildcard`.', | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| export const optionsListSortSchema = schema.object( | ||
| { | ||
| by: schema.oneOf([schema.literal('_count'), schema.literal('_key')]), | ||
| direction: schema.oneOf([schema.literal('asc'), schema.literal('desc')]), | ||
| by: schema.oneOf([schema.literal('_count'), schema.literal('_key')], { | ||
| meta: { | ||
| description: | ||
| 'The field used to sort the available options list. `_count` sorts by document count and `_key` sorts alphabetically by option value.', | ||
| }, | ||
| }), | ||
| direction: schema.oneOf([schema.literal('asc'), schema.literal('desc')], { | ||
| meta: { | ||
| description: 'The sort direction. `asc` sorts ascending and `desc` sorts descending.', | ||
| }, | ||
| }), | ||
| }, | ||
| { defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.sort } | ||
| { | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.sort, | ||
| meta: { | ||
| description: | ||
| 'Defines how the available options are sorted in the control popover. Defaults to `{ by: "_count", direction: "desc" }`.', | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| export const optionsListSelectionSchema = schema.oneOf([schema.string(), schema.number()]); | ||
| export const optionsListSelectionSchema = schema.oneOf([schema.string(), schema.number()], { | ||
| meta: { | ||
| description: 'A selected option value. Accepts a string or a number.', | ||
| }, | ||
| }); | ||
|
|
||
| const optionsListControlBaseParameters = schema.object({ | ||
| display_settings: schema.maybe(optionsListDisplaySettingsSchema), | ||
|
|
@@ -47,35 +102,82 @@ const optionsListControlBaseParameters = schema.object({ | |
| export const optionsListDSLControlSchema = schema.object({ | ||
| ...optionsListControlBaseParameters.getPropSchemas(), | ||
| ...dataControlSchema.getPropSchemas(), | ||
| exclude: schema.boolean({ defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.exclude }), | ||
| exclude: schema.boolean({ | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.exclude, | ||
| meta: { | ||
| description: | ||
| 'When `true`, the control filters to documents that do NOT match the selected options. Defaults to `false`.', | ||
| }, | ||
| }), | ||
| exists_selected: schema.boolean({ | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.exists_selected, | ||
| meta: { | ||
| description: | ||
| "When `true`, the control filters to documents where the field exists, regardless of the field's value. Defaults to `false`.", | ||
| }, | ||
| }), | ||
| run_past_timeout: schema.boolean({ | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.run_past_timeout, | ||
| meta: { | ||
| description: | ||
| 'When `true`, the options list query continues running even if it exceeds the configured timeout threshold. Defaults to `false`.', | ||
| }, | ||
| }), | ||
| search_technique: optionsListSearchTechniqueSchema, | ||
| selected_options: schema.arrayOf(optionsListSelectionSchema, { | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.selected_options, | ||
| maxSize: SELECTIONS_MAX, | ||
| meta: { | ||
| description: 'The list of currently selected option values.', | ||
| }, | ||
| }), | ||
| single_select: schema.boolean({ | ||
| defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.single_select, | ||
| meta: { | ||
| description: | ||
| 'When `true`, only one option can be selected at a time. Selecting a new option deselects any previously selected option. Defaults to `false`.', | ||
| }, | ||
| }), | ||
| single_select: schema.boolean({ defaultValue: DEFAULT_DSL_OPTIONS_LIST_STATE.single_select }), | ||
| sort: optionsListSortSchema, | ||
| }); | ||
|
|
||
| const baseEsqlControl = { | ||
| ...controlTitleSchema.getPropSchemas(), | ||
| ...optionsListControlBaseParameters.getPropSchemas(), | ||
| selected_options: schema.arrayOf(schema.string(), { maxSize: SELECTIONS_MAX }), | ||
| single_select: schema.boolean({ defaultValue: DEFAULT_ESQL_OPTIONS_LIST_STATE.single_select }), | ||
| variable_name: schema.string(), | ||
| variable_type: schema.oneOf([ | ||
| schema.literal('fields'), | ||
| schema.literal('values'), | ||
| schema.literal('functions'), | ||
| schema.literal('time_literal'), | ||
| schema.literal('multi_values'), | ||
| ]), | ||
| selected_options: schema.arrayOf(schema.string(), { | ||
| maxSize: SELECTIONS_MAX, | ||
| meta: { | ||
| description: 'The list of currently selected option values.', | ||
| }, | ||
| }), | ||
| single_select: schema.boolean({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting that we have this duplicated rather than reusing the same schema |
||
| defaultValue: DEFAULT_ESQL_OPTIONS_LIST_STATE.single_select, | ||
| meta: { | ||
| description: | ||
| 'When `true`, only one option can be selected at a time. Selecting a new option deselects any previously selected option. Defaults to `true`.', | ||
| }, | ||
| }), | ||
| variable_name: schema.string({ | ||
| meta: { | ||
| description: | ||
| 'The name of the ES|QL variable that this control populates. The variable is referenced in ES|QL queries using the `?variable_name` syntax.', | ||
| }, | ||
| }), | ||
| variable_type: schema.oneOf( | ||
| [ | ||
| schema.literal('fields'), | ||
| schema.literal('values'), | ||
| schema.literal('functions'), | ||
| schema.literal('time_literal'), | ||
| schema.literal('multi_values'), | ||
| ], | ||
| { | ||
| meta: { | ||
| description: | ||
| 'The ES|QL variable type that determines how the selected value is substituted into the query. Accepts `fields`, `values`, `functions`, `time_literal`, or `multi_values`.', | ||
| }, | ||
| } | ||
| ), | ||
| }; | ||
|
|
||
| export const optionsListESQLControlSchema = schema.discriminatedUnion('control_type', [ | ||
|
|
@@ -85,23 +187,37 @@ export const optionsListESQLControlSchema = schema.discriminatedUnion('control_t | |
| control_type: schema.literal('STATIC_VALUES'), | ||
| available_options: schema.arrayOf(schema.string(), { | ||
| maxSize: MAX_OPTIONS_LIST_REQUEST_SIZE, | ||
| meta: { | ||
| description: 'A fixed list of option strings displayed in the control.', | ||
| }, | ||
| }), | ||
| }, | ||
| { | ||
| meta: { | ||
| id: 'kbn-controls-schemas-options-list-esql-control-schema-static-values', | ||
| title: 'STATIC_VALUES', | ||
| description: | ||
| 'An ES|QL variable control with a fixed list of selectable options defined directly in `available_options`.', | ||
| }, | ||
| } | ||
| ), | ||
| schema.object( | ||
| { | ||
| ...baseEsqlControl, | ||
| control_type: schema.literal('VALUES_FROM_QUERY'), | ||
| esql_query: schema.string(), | ||
| esql_query: schema.string({ | ||
| meta: { | ||
| description: | ||
| 'An ES|QL query whose results populate the list of available options in the control popover.', | ||
| }, | ||
| }), | ||
| }, | ||
| { | ||
| meta: { | ||
| id: 'kbn-controls-schemas-options-list-esql-control-schema-values-from-query', | ||
| title: 'VALUES_FROM_QUERY', | ||
| description: | ||
| 'An ES|QL variable control whose selectable options are dynamically retrieved by running an ES|QL query.', | ||
| }, | ||
| } | ||
| ), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.