forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Controls] Fix error thrown on numeric options list (elastic#188789)
## Summary This PR makes the suggestions returned from the options list route more type safe by ensuring that strings are **always** returned - previously, it sometimes returned numbers, which was inconsistent with our defined types. Unfortunately, this messed with the field formatter for date fields specifically - so, to get around this, I've had to convert date fields back to a number specifically for the formatter **only**. This resolves the error that was getting thrown for numeric options list controls, which was happening because we were returning **numbers** from the suggestions route rather than strings and some recent changes to the `EuiSelectable` component require strings: **Before:** https://github.com/user-attachments/assets/0e723e2f-e8f0-4466-b857-8164088cd1e7 **After** https://github.com/user-attachments/assets/d9b138b9-de27-4e14-8c85-0ce4bfde16ce ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed ### 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) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
5859c69
commit 28b6179
Showing
21 changed files
with
305 additions
and
115 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/plugins/controls/common/options_list/options_list_selections.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { FieldSpec } from '@kbn/data-views-plugin/common'; | ||
|
||
export type OptionsListSelection = string | number; | ||
|
||
export const getSelectionAsFieldType = (field: FieldSpec, key: string): OptionsListSelection => { | ||
const storeAsNumber = field.type === 'number' || field.type === 'date'; | ||
return storeAsNumber ? +key : key; | ||
}; |
This file contains 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 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 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 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 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 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 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.