Skip to content

Commit

Permalink
[Embeddable Rebuild] [Controls] Add ignoreValidations support to op…
Browse files Browse the repository at this point in the history
…tions list control (#191303)

Closes #191295

## Summary

This PR makes it so that the options list control respects the
`ignoreParentSettings.ignoreValidations` setting when validating its
selections:



https://github.com/user-attachments/assets/abd41283-aafd-4802-8e2e-2f55d9551df3

Note that in the above video, we are "dropping" invalid selections in
the UI when this setting is active, which means that the only way to
unselect "empty" options is to click the "Show only selected" option in
the UI. While I considered changing that behaviour in this PR, I opted
to keep this PR as simple as possible by keeping the behaviour
consistent with the non-React options list (i.e. the behaviour
demonstrated in the video above is consistent with how options list work
in Dashboards on `main`). We can always revisit that behaviour later,
since it is a very easy change to make.

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
Heenawter authored Aug 27, 2024
1 parent e2a0381 commit fae0139
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/plugins/controls/common/options_list/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface OptionsListRequestBody
> {
runtimeFieldMap?: Record<string, RuntimeFieldSpec>;
allowExpensiveQueries: boolean;
ignoreValidations?: boolean;
filters?: Array<{ bool: BoolQuery }>;
runPastTimeout?: boolean;
searchString?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function fetchAndValidate$({
api.field$,
api.controlFetch$,
api.parentApi.allowExpensiveQueries$,
api.parentApi.ignoreParentSettings$,
api.debouncedSearchString,
stateManager.sort,
stateManager.searchTechnique,
Expand Down Expand Up @@ -86,6 +87,7 @@ export function fetchAndValidate$({
field,
controlFetchContext,
allowExpensiveQueries,
ignoreParentSettings,
searchString,
sort,
searchTechnique,
Expand Down Expand Up @@ -116,6 +118,7 @@ export function fetchAndValidate$({
field: field.toSpec(),
size: requestSize,
allowExpensiveQueries,
ignoreValidations: ignoreParentSettings?.ignoreValidations,
...controlFetchContext,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class OptionsListFetchCache {
runPastTimeout,
selectedOptions,
searchTechnique,
ignoreValidations,
field: { name: fieldName },
dataView: { title: dataViewTitle },
} = request;
Expand All @@ -67,6 +68,7 @@ export class OptionsListFetchCache {
query,
sort,
searchTechnique,
ignoreValidations,
runPastTimeout,
dataViewTitle,
searchString: searchString ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const setupOptionsListSuggestionsRoute = (
filters: schema.maybe(schema.any()),
fieldSpec: schema.maybe(schema.any()),
allowExpensiveQueries: schema.boolean(),
ignoreValidations: schema.maybe(schema.boolean()),
searchString: schema.maybe(schema.string()),
searchTechnique: schema.maybe(
schema.oneOf([
Expand Down Expand Up @@ -102,7 +103,7 @@ export const setupOptionsListSuggestionsRoute = (
/**
* Build ES Query
*/
const { runPastTimeout, filters, runtimeFieldMap } = request;
const { runPastTimeout, filters, runtimeFieldMap, ignoreValidations } = request;
const { terminateAfter, timeout } = getAutocompleteSettings();
const timeoutSettings = runPastTimeout
? {}
Expand All @@ -112,7 +113,9 @@ export const setupOptionsListSuggestionsRoute = (
const validationBuilder = getValidationAggregationBuilder();

const suggestionAggregation: any = suggestionBuilder.buildAggregation(request) ?? {};
const validationAggregation: any = validationBuilder.buildAggregation(request);
const validationAggregation: any = ignoreValidations
? {}
: validationBuilder.buildAggregation(request);

const body: SearchRequest['body'] = {
size: 0,
Expand Down Expand Up @@ -141,7 +144,9 @@ export const setupOptionsListSuggestionsRoute = (
*/
const results = suggestionBuilder.parse(rawEsResult, request);
const totalCardinality = results.totalCardinality;
const invalidSelections = validationBuilder.parse(rawEsResult, request);
const invalidSelections = ignoreValidations
? []
: validationBuilder.parse(rawEsResult, request);

return {
suggestions: results.suggestions,
Expand Down

0 comments on commit fae0139

Please sign in to comment.