diff --git a/x-pack/plugins/data_visualizer/common/types/field_request_config.ts b/x-pack/plugins/data_visualizer/common/types/field_request_config.ts index 34a9f5d6036f2..ee6a382c4fb95 100644 --- a/x-pack/plugins/data_visualizer/common/types/field_request_config.ts +++ b/x-pack/plugins/data_visualizer/common/types/field_request_config.ts @@ -65,7 +65,12 @@ export interface FieldVisStats { max?: number; median?: number; min?: number; - topValues?: Array<{ key: number | string; doc_count: number; percent: number }>; + topValues?: Array<{ + key: number | string; + doc_count: number; + percent: number; + key_as_string?: string; + }>; examples?: Array; timeRangeEarliest?: number; timeRangeLatest?: number; diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx index a3f5731dcb1bc..0b2475789091f 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx @@ -114,87 +114,80 @@ export const TopValues: FC = ({ stats, fieldFormat, barColor, compressed, className={classNames('fieldDataTopValuesContainer', 'dvTopValues__wrapper')} > {Array.isArray(topValues) - ? topValues.map((value) => ( - - - - - {fieldName !== undefined && value.key !== undefined && onAddFilter !== undefined ? ( -
- - onAddFilter( - fieldName, - typeof value.key === 'number' ? value.key.toString() : value.key, - '+' - ) - } - aria-label={i18n.translate( - 'xpack.dataVisualizer.dataGrid.field.addFilterAriaLabel', - { - defaultMessage: 'Filter for {fieldName}: "{value}"', - values: { fieldName, value: value.key }, - } - )} - data-test-subj={`dvFieldDataTopValuesAddFilterButton-${value.key}-${value.key}`} - style={{ - minHeight: 'auto', - minWidth: 'auto', - paddingRight: 2, - paddingLeft: 2, - paddingTop: 0, - paddingBottom: 0, - }} - /> - - onAddFilter( - fieldName, - typeof value.key === 'number' ? value.key.toString() : value.key, - '-' - ) - } - aria-label={i18n.translate( - 'xpack.dataVisualizer.dataGrid.field.removeFilterAriaLabel', - { - defaultMessage: 'Filter out {fieldName}: "{value}"', - values: { fieldName, value: value.key }, - } - )} - data-test-subj={`dvFieldDataTopValuesExcludeFilterButton-${value.key}-${value.key}`} - style={{ - minHeight: 'auto', - minWidth: 'auto', - paddingTop: 0, - paddingBottom: 0, - paddingRight: 2, - paddingLeft: 2, - }} + ? topValues.map((value) => { + const fieldValue = value.key_as_string ?? value.key.toString(); + return ( + + + -
- ) : null} -
- )) + + {fieldName !== undefined && + fieldValue !== undefined && + onAddFilter !== undefined ? ( +
+ onAddFilter(fieldName, fieldValue, '+')} + aria-label={i18n.translate( + 'xpack.dataVisualizer.dataGrid.field.addFilterAriaLabel', + { + defaultMessage: 'Filter for {fieldName}: "{value}"', + values: { fieldName, value: fieldValue }, + } + )} + data-test-subj={`dvFieldDataTopValuesAddFilterButton-${fieldName}-${fieldValue}`} + style={{ + minHeight: 'auto', + minWidth: 'auto', + paddingRight: 2, + paddingLeft: 2, + paddingTop: 0, + paddingBottom: 0, + }} + /> + onAddFilter(fieldName, fieldValue, '-')} + aria-label={i18n.translate( + 'xpack.dataVisualizer.dataGrid.field.removeFilterAriaLabel', + { + defaultMessage: 'Filter out {fieldName}: "{value}"', + values: { fieldName, value: fieldValue }, + } + )} + data-test-subj={`dvFieldDataTopValuesExcludeFilterButton-${fieldName}-${fieldValue}`} + style={{ + minHeight: 'auto', + minWidth: 'auto', + paddingTop: 0, + paddingBottom: 0, + paddingRight: 2, + paddingLeft: 2, + }} + /> +
+ ) : null} + + ); + }) : null} {topValuesOtherCount > 0 ? (