-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
be4f1f9
[Docs][Dashboards API] Add field descriptions to controls schemas
florent-leborgne 5edcd9c
[Docs][Dashboards API] Simplify use_global_filters description
florent-leborgne 6c2904a
[Docs][Dashboards API] Improve controls schema descriptions
florent-leborgne 81c2b9c
[Docs][Dashboards API] Remove redundant min/max/default from time sli…
florent-leborgne e5ffb59
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne 96592e3
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine 5c1f0f0
Apply suggestion from @florent-leborgne
florent-leborgne ad08eb5
Apply suggestion from @nreese
florent-leborgne 6e2122a
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne d91d1b4
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne 16d2d8e
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne 7341c7e
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne 8ba56fa
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne 6b1e354
Apply suggestions from code review
florent-leborgne 3a53891
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine 214d9b3
Merge branch 'main' into dashboards-api-docs-2d
florent-leborgne 89191e5
argh
florent-leborgne ae3bad8
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,27 +18,83 @@ 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( | ||
| 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 search bar, sorting options, and select all toggle 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 +103,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 +188,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.', | ||
| }, | ||
| } | ||
| ), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.