2019-09-17 20:57:53 +02:00
/ *
* Copyright Elasticsearch B . V . and / or licensed to Elasticsearch B . V . under one
* or more contributor license agreements . Licensed under the Elastic License ;
* you may not use this file except in compliance with the Elastic License .
* /
2020-06-26 18:43:35 +02:00
import './datapanel.scss' ;
2020-11-10 14:31:04 +01:00
import { uniq , groupBy } from 'lodash' ;
2020-09-24 09:55:32 +02:00
import React , { useState , memo , useCallback , useMemo } from 'react' ;
2019-09-17 20:57:53 +02:00
import {
EuiFlexGroup ,
EuiFlexItem ,
EuiContextMenuPanel ,
EuiContextMenuItem ,
EuiPopover ,
EuiCallOut ,
EuiFormControlLayout ,
2019-10-29 21:36:45 +01:00
EuiSpacer ,
2020-06-26 18:43:35 +02:00
EuiFilterGroup ,
EuiFilterButton ,
2020-11-25 16:57:03 +01:00
EuiScreenReaderOnly ,
2019-09-17 20:57:53 +02:00
} from '@elastic/eui' ;
import { i18n } from '@kbn/i18n' ;
import { FormattedMessage } from '@kbn/i18n/react' ;
2020-07-09 12:47:00 +02:00
import { DataPublicPluginStart , EsQueryConfig , Query , Filter } from 'src/plugins/data/public' ;
2020-11-25 16:57:03 +01:00
import { htmlIdGenerator } from '@elastic/eui' ;
2019-10-09 21:20:55 +02:00
import { DatasourceDataPanelProps , DataType , StateSetter } from '../types' ;
2019-09-17 20:57:53 +02:00
import { ChildDragDropProvider , DragContextState } from '../drag_drop' ;
2019-10-09 21:20:55 +02:00
import {
IndexPattern ,
IndexPatternPrivateState ,
IndexPatternField ,
IndexPatternRef ,
} from './types' ;
2019-10-16 05:01:43 +02:00
import { trackUiEvent } from '../lens_ui_telemetry' ;
2019-10-14 18:46:33 +02:00
import { syncExistingFields } from './loader' ;
import { fieldExists } from './pure_helpers' ;
2019-10-23 17:28:27 +02:00
import { Loader } from '../loader' ;
2020-04-15 12:22:37 +02:00
import { esQuery , IIndexPattern } from '../../../../../src/plugins/data/public' ;
2019-10-09 21:20:55 +02:00
2019-10-14 18:46:33 +02:00
export type Props = DatasourceDataPanelProps < IndexPatternPrivateState > & {
2020-04-15 12:22:37 +02:00
data : DataPublicPluginStart ;
2019-10-09 21:20:55 +02:00
changeIndexPattern : (
id : string ,
state : IndexPatternPrivateState ,
setState : StateSetter < IndexPatternPrivateState >
) = > void ;
2020-07-02 16:02:30 +02:00
charts : ChartsPluginSetup ;
2019-10-09 21:20:55 +02:00
} ;
2019-10-07 10:36:24 +02:00
import { LensFieldIcon } from './lens_field_icon' ;
2019-09-27 18:55:11 +02:00
import { ChangeIndexPattern } from './change_indexpattern' ;
2020-07-02 16:02:30 +02:00
import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public' ;
2020-09-24 09:55:32 +02:00
import { FieldGroups , FieldList } from './field_list' ;
2019-09-17 20:57:53 +02:00
function sortFields ( fieldA : IndexPatternField , fieldB : IndexPatternField ) {
2020-08-21 11:33:42 +02:00
return fieldA . displayName . localeCompare ( fieldB . displayName , undefined , { sensitivity : 'base' } ) ;
2019-09-17 20:57:53 +02:00
}
2019-10-29 21:36:45 +01:00
const supportedFieldTypes = new Set ( [ 'string' , 'number' , 'boolean' , 'date' , 'ip' , 'document' ] ) ;
2019-09-17 20:57:53 +02:00
const fieldTypeNames : Record < DataType , string > = {
2019-10-29 21:36:45 +01:00
document : i18n . translate ( 'xpack.lens.datatypes.record' , { defaultMessage : 'record' } ) ,
2019-09-17 20:57:53 +02:00
string : i18n . translate ( 'xpack.lens.datatypes.string' , { defaultMessage : 'string' } ) ,
number : i18n . translate ( 'xpack.lens.datatypes.number' , { defaultMessage : 'number' } ) ,
boolean : i18n . translate ( 'xpack.lens.datatypes.boolean' , { defaultMessage : 'boolean' } ) ,
date : i18n.translate ( 'xpack.lens.datatypes.date' , { defaultMessage : 'date' } ) ,
2019-09-24 22:05:47 +02:00
ip : i18n.translate ( 'xpack.lens.datatypes.ipAddress' , { defaultMessage : 'IP' } ) ,
2019-09-17 20:57:53 +02:00
} ;
2020-07-09 12:47:00 +02:00
// Wrapper around esQuery.buildEsQuery, handling errors (e.g. because a query can't be parsed) by
// returning a query dsl object not matching anything
function buildSafeEsQuery (
indexPattern : IIndexPattern ,
query : Query ,
filters : Filter [ ] ,
queryConfig : EsQueryConfig
) {
try {
return esQuery . buildEsQuery ( indexPattern , query , filters , queryConfig ) ;
} catch ( e ) {
return {
bool : {
must_not : {
match_all : { } ,
} ,
} ,
} ;
}
}
2019-09-17 20:57:53 +02:00
export function IndexPatternDataPanel ( {
setState ,
state ,
dragDropContext ,
core ,
2020-04-15 12:22:37 +02:00
data ,
2019-09-17 20:57:53 +02:00
query ,
2019-10-03 17:24:45 +02:00
filters ,
2019-09-17 20:57:53 +02:00
dateRange ,
2019-10-09 21:20:55 +02:00
changeIndexPattern ,
2020-07-02 16:02:30 +02:00
charts ,
2020-07-01 10:08:37 +02:00
showNoDataPopover ,
2019-10-09 21:20:55 +02:00
} : Props ) {
const { indexPatternRefs , indexPatterns , currentIndexPatternId } = state ;
2019-09-17 20:57:53 +02:00
const onChangeIndexPattern = useCallback (
2019-10-09 21:20:55 +02:00
( id : string ) = > changeIndexPattern ( id , state , setState ) ,
2020-06-26 18:43:35 +02:00
[ state , setState , changeIndexPattern ]
2019-10-23 17:28:27 +02:00
) ;
2019-09-17 20:57:53 +02:00
2019-10-14 18:46:33 +02:00
const indexPatternList = uniq (
Object . values ( state . layers )
2020-05-22 09:08:58 +02:00
. map ( ( l ) = > l . indexPatternId )
2019-10-14 18:46:33 +02:00
. concat ( currentIndexPatternId )
)
. sort ( ( a , b ) = > a . localeCompare ( b ) )
2020-05-22 09:08:58 +02:00
. filter ( ( id ) = > ! ! indexPatterns [ id ] )
. map ( ( id ) = > ( {
2020-01-14 18:39:50 +01:00
id ,
2019-10-14 18:46:33 +02:00
title : indexPatterns [ id ] . title ,
timeFieldName : indexPatterns [ id ] . timeFieldName ,
2020-07-16 09:54:46 +02:00
fields : indexPatterns [ id ] . fields ,
2020-08-26 09:09:40 +02:00
hasRestrictions : indexPatterns [ id ] . hasRestrictions ,
2019-10-14 18:46:33 +02:00
} ) ) ;
2020-07-09 12:47:00 +02:00
const dslQuery = buildSafeEsQuery (
2020-03-12 09:03:40 +01:00
indexPatterns [ currentIndexPatternId ] as IIndexPattern ,
query ,
filters ,
esQuery . getEsQueryConfig ( core . uiSettings )
) ;
2019-09-17 20:57:53 +02:00
return (
2019-10-23 17:28:27 +02:00
< >
< Loader
load = { ( ) = >
syncExistingFields ( {
dateRange ,
setState ,
2020-07-01 10:08:37 +02:00
isFirstExistenceFetch : state.isFirstExistenceFetch ,
currentIndexPatternTitle : indexPatterns [ currentIndexPatternId ] . title ,
showNoDataPopover ,
2019-10-23 17:28:27 +02:00
indexPatterns : indexPatternList ,
2020-03-12 09:03:40 +01:00
fetchJson : core.http.post ,
dslQuery ,
2019-10-23 17:28:27 +02:00
} )
}
loadDeps = { [
2020-03-12 09:03:40 +01:00
query ,
filters ,
2019-10-23 17:28:27 +02:00
dateRange . fromDate ,
dateRange . toDate ,
2020-05-22 09:08:58 +02:00
indexPatternList . map ( ( x ) = > ` ${ x . title } : ${ x . timeFieldName } ` ) . join ( ',' ) ,
2019-10-23 17:28:27 +02:00
] }
/ >
2020-05-07 16:01:51 +02:00
{ Object . keys ( indexPatterns ) . length === 0 ? (
< EuiFlexGroup
gutterSize = "m"
className = "lnsInnerIndexPatternDataPanel"
direction = "column"
responsive = { false }
>
< EuiFlexItem grow = { null } >
< EuiCallOut
data - test - subj = "indexPattern-no-indexpatterns"
title = { i18n . translate ( 'xpack.lens.indexPattern.noPatternsLabel' , {
defaultMessage : 'No index patterns' ,
} ) }
color = "warning"
iconType = "alert"
>
< p >
< FormattedMessage
id = "xpack.lens.indexPattern.noPatternsDescription"
defaultMessage = "Please create an index pattern or switch to another data source"
/ >
< / p >
< / EuiCallOut >
< / EuiFlexItem >
< / EuiFlexGroup >
) : (
< MemoizedDataPanel
currentIndexPatternId = { currentIndexPatternId }
indexPatternRefs = { indexPatternRefs }
indexPatterns = { indexPatterns }
query = { query }
dateRange = { dateRange }
filters = { filters }
dragDropContext = { dragDropContext }
core = { core }
data = { data }
2020-07-02 16:02:30 +02:00
charts = { charts }
2020-05-07 16:01:51 +02:00
onChangeIndexPattern = { onChangeIndexPattern }
existingFields = { state . existingFields }
2020-07-16 09:54:46 +02:00
existenceFetchFailed = { state . existenceFetchFailed }
2020-05-07 16:01:51 +02:00
/ >
) }
2019-10-23 17:28:27 +02:00
< / >
2019-09-17 20:57:53 +02:00
) ;
}
interface DataPanelState {
nameFilter : string ;
typeFilter : DataType [ ] ;
isTypeFilterOpen : boolean ;
2020-06-26 18:43:35 +02:00
isAvailableAccordionOpen : boolean ;
isEmptyAccordionOpen : boolean ;
2020-09-24 09:55:32 +02:00
isMetaAccordionOpen : boolean ;
2020-06-26 18:43:35 +02:00
}
2020-09-24 09:55:32 +02:00
const defaultFieldGroups : {
2020-06-26 18:43:35 +02:00
specialFields : IndexPatternField [ ] ;
availableFields : IndexPatternField [ ] ;
emptyFields : IndexPatternField [ ] ;
2020-09-24 09:55:32 +02:00
metaFields : IndexPatternField [ ] ;
} = {
2020-06-26 18:43:35 +02:00
specialFields : [ ] ,
availableFields : [ ] ,
emptyFields : [ ] ,
2020-09-24 09:55:32 +02:00
metaFields : [ ] ,
2020-06-26 18:43:35 +02:00
} ;
const fieldFiltersLabel = i18n . translate ( 'xpack.lens.indexPatterns.fieldFiltersLabel' , {
defaultMessage : 'Field filters' ,
} ) ;
2020-11-25 16:57:03 +01:00
const htmlId = htmlIdGenerator ( 'datapanel' ) ;
const fieldSearchDescriptionId = htmlId ( ) ;
2019-09-17 20:57:53 +02:00
export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel ( {
currentIndexPatternId ,
2019-10-09 21:20:55 +02:00
indexPatternRefs ,
2019-09-17 20:57:53 +02:00
indexPatterns ,
2020-07-16 09:54:46 +02:00
existenceFetchFailed ,
2019-09-17 20:57:53 +02:00
query ,
dateRange ,
2019-10-03 17:24:45 +02:00
filters ,
2019-09-17 20:57:53 +02:00
dragDropContext ,
onChangeIndexPattern ,
core ,
2020-04-15 12:22:37 +02:00
data ,
2019-10-14 18:46:33 +02:00
existingFields ,
2020-07-02 16:02:30 +02:00
charts ,
2020-07-01 10:08:37 +02:00
} : Omit < DatasourceDataPanelProps , ' state ' | ' setState ' | ' showNoDataPopover ' > & {
2020-04-15 12:22:37 +02:00
data : DataPublicPluginStart ;
2019-09-17 20:57:53 +02:00
currentIndexPatternId : string ;
2019-10-09 21:20:55 +02:00
indexPatternRefs : IndexPatternRef [ ] ;
2019-09-17 20:57:53 +02:00
indexPatterns : Record < string , IndexPattern > ;
dragDropContext : DragContextState ;
2019-09-27 18:55:11 +02:00
onChangeIndexPattern : ( newId : string ) = > void ;
2019-10-14 18:46:33 +02:00
existingFields : IndexPatternPrivateState [ 'existingFields' ] ;
2020-07-02 16:02:30 +02:00
charts : ChartsPluginSetup ;
2020-07-16 09:54:46 +02:00
existenceFetchFailed? : boolean ;
2019-09-17 20:57:53 +02:00
} ) {
const [ localState , setLocalState ] = useState < DataPanelState > ( {
nameFilter : '' ,
typeFilter : [ ] ,
isTypeFilterOpen : false ,
2020-06-26 18:43:35 +02:00
isAvailableAccordionOpen : true ,
isEmptyAccordionOpen : false ,
2020-09-24 09:55:32 +02:00
isMetaAccordionOpen : false ,
2019-09-17 20:57:53 +02:00
} ) ;
const currentIndexPattern = indexPatterns [ currentIndexPatternId ] ;
const allFields = currentIndexPattern . fields ;
2020-05-22 09:08:58 +02:00
const clearLocalState = ( ) = > setLocalState ( ( s ) = > ( { . . . s , nameFilter : '' , typeFilter : [ ] } ) ) ;
2020-06-26 18:43:35 +02:00
const hasSyncedExistingFields = existingFields [ currentIndexPattern . title ] ;
const availableFieldTypes = uniq ( allFields . map ( ( { type } ) = > type ) ) . filter (
( type ) = > type in fieldTypeNames
) ;
2019-09-17 20:57:53 +02:00
2020-09-24 09:55:32 +02:00
const fieldInfoUnavailable = existenceFetchFailed || currentIndexPattern . hasRestrictions ;
2019-09-17 20:57:53 +02:00
2020-09-24 09:55:32 +02:00
const unfilteredFieldGroups : FieldGroups = useMemo ( ( ) = > {
2020-06-26 18:43:35 +02:00
const containsData = ( field : IndexPatternField ) = > {
2020-11-10 14:31:04 +01:00
const overallField = currentIndexPattern . getFieldByName ( field . name ) ;
2019-09-17 20:57:53 +02:00
2020-06-26 18:43:35 +02:00
return (
overallField && fieldExists ( existingFields , currentIndexPattern . title , overallField . name )
) ;
} ;
2019-09-17 20:57:53 +02:00
2020-06-26 18:43:35 +02:00
const allSupportedTypesFields = allFields . filter ( ( field ) = >
supportedFieldTypes . has ( field . type )
) ;
const sorted = allSupportedTypesFields . sort ( sortFields ) ;
2020-09-24 09:55:32 +02:00
let groupedFields ;
2020-06-26 18:43:35 +02:00
// optimization before existingFields are synced
if ( ! hasSyncedExistingFields ) {
2020-09-24 09:55:32 +02:00
groupedFields = {
2020-06-26 18:43:35 +02:00
. . . defaultFieldGroups ,
. . . groupBy ( sorted , ( field ) = > {
if ( field . type === 'document' ) {
return 'specialFields' ;
2020-09-24 09:55:32 +02:00
} else if ( field . meta ) {
return 'metaFields' ;
2020-06-26 18:43:35 +02:00
} else {
return 'emptyFields' ;
}
} ) ,
} ;
2019-09-17 20:57:53 +02:00
}
2020-09-24 09:55:32 +02:00
groupedFields = {
2020-06-26 18:43:35 +02:00
. . . defaultFieldGroups ,
. . . groupBy ( sorted , ( field ) = > {
if ( field . type === 'document' ) {
return 'specialFields' ;
2020-09-24 09:55:32 +02:00
} else if ( field . meta ) {
return 'metaFields' ;
2020-06-26 18:43:35 +02:00
} else if ( containsData ( field ) ) {
return 'availableFields' ;
} else return 'emptyFields' ;
} ) ,
} ;
2019-09-17 20:57:53 +02:00
2020-09-24 09:55:32 +02:00
const fieldGroupDefinitions : FieldGroups = {
SpecialFields : {
fields : groupedFields.specialFields ,
fieldCount : 1 ,
isAffectedByGlobalFilter : false ,
isAffectedByTimeFilter : false ,
isInitiallyOpen : false ,
showInAccordion : false ,
title : '' ,
hideDetails : true ,
} ,
AvailableFields : {
fields : groupedFields.availableFields ,
fieldCount : groupedFields.availableFields.length ,
isInitiallyOpen : true ,
showInAccordion : true ,
title : fieldInfoUnavailable
? i18n . translate ( 'xpack.lens.indexPattern.allFieldsLabel' , {
defaultMessage : 'All fields' ,
} )
: i18n . translate ( 'xpack.lens.indexPattern.availableFieldsLabel' , {
defaultMessage : 'Available fields' ,
} ) ,
2020-12-15 18:23:41 +01:00
helpText : i18n.translate ( 'xpack.lens.indexPattern.allFieldsLabelHelp' , {
defaultMessage :
'Available fields have data in the first 500 documents that match your filters. To view all fields, expand Empty fields. Some field types cannot be visualized in Lens, including full text and geographic fields.' ,
} ) ,
2020-09-24 09:55:32 +02:00
isAffectedByGlobalFilter : ! ! filters . length ,
isAffectedByTimeFilter : true ,
hideDetails : fieldInfoUnavailable ,
2020-10-05 23:07:07 +02:00
defaultNoFieldsMessage : i18n.translate ( 'xpack.lens.indexPatterns.noAvailableDataLabel' , {
defaultMessage : ` There are no available fields that contain data. ` ,
} ) ,
2020-09-24 09:55:32 +02:00
} ,
EmptyFields : {
fields : groupedFields.emptyFields ,
fieldCount : groupedFields.emptyFields.length ,
isAffectedByGlobalFilter : false ,
isAffectedByTimeFilter : false ,
isInitiallyOpen : false ,
showInAccordion : true ,
hideDetails : false ,
title : i18n.translate ( 'xpack.lens.indexPattern.emptyFieldsLabel' , {
defaultMessage : 'Empty fields' ,
} ) ,
2020-10-05 23:07:07 +02:00
defaultNoFieldsMessage : i18n.translate ( 'xpack.lens.indexPatterns.noEmptyDataLabel' , {
defaultMessage : ` There are no empty fields. ` ,
} ) ,
2020-12-15 18:23:41 +01:00
helpText : i18n.translate ( 'xpack.lens.indexPattern.emptyFieldsLabelHelp' , {
defaultMessage :
'Empty fields did not contain any values in the first 500 documents based on your filters.' ,
} ) ,
2020-09-24 09:55:32 +02:00
} ,
MetaFields : {
fields : groupedFields.metaFields ,
fieldCount : groupedFields.metaFields.length ,
isAffectedByGlobalFilter : false ,
isAffectedByTimeFilter : false ,
isInitiallyOpen : false ,
showInAccordion : true ,
hideDetails : false ,
title : i18n.translate ( 'xpack.lens.indexPattern.metaFieldsLabel' , {
defaultMessage : 'Meta fields' ,
} ) ,
2020-10-05 23:07:07 +02:00
defaultNoFieldsMessage : i18n.translate ( 'xpack.lens.indexPatterns.noMetaDataLabel' , {
defaultMessage : ` There are no meta fields. ` ,
} ) ,
2020-09-24 09:55:32 +02:00
} ,
} ;
// do not show empty field accordion if there is no existence information
if ( fieldInfoUnavailable ) {
delete fieldGroupDefinitions . EmptyFields ;
}
return fieldGroupDefinitions ;
} , [
allFields ,
existingFields ,
currentIndexPattern ,
hasSyncedExistingFields ,
fieldInfoUnavailable ,
filters . length ,
] ) ;
const fieldGroups : FieldGroups = useMemo ( ( ) = > {
2020-06-26 18:43:35 +02:00
const filterFieldGroup = ( fieldGroup : IndexPatternField [ ] ) = >
fieldGroup . filter ( ( field ) = > {
if (
localState . nameFilter . length &&
2020-08-21 11:33:42 +02:00
! field . name . toLowerCase ( ) . includes ( localState . nameFilter . toLowerCase ( ) ) &&
! field . displayName . toLowerCase ( ) . includes ( localState . nameFilter . toLowerCase ( ) )
2020-06-26 18:43:35 +02:00
) {
return false ;
}
if ( localState . typeFilter . length > 0 ) {
return localState . typeFilter . includes ( field . type as DataType ) ;
}
return true ;
} ) ;
2020-09-24 09:55:32 +02:00
return Object . fromEntries (
Object . entries ( unfilteredFieldGroups ) . map ( ( [ name , group ] ) = > [
name ,
{ . . . group , fields : filterFieldGroup ( group . fields ) } ,
] )
) ;
} , [ unfilteredFieldGroups , localState . nameFilter , localState . typeFilter ] ) ;
2019-09-17 20:57:53 +02:00
2020-06-26 18:43:35 +02:00
const fieldProps = useMemo (
( ) = > ( {
core ,
data ,
indexPattern : currentIndexPattern ,
highlight : localState.nameFilter.toLowerCase ( ) ,
dateRange ,
query ,
filters ,
2020-07-02 16:02:30 +02:00
chartsThemeService : charts.theme ,
2020-06-26 18:43:35 +02:00
} ) ,
2020-08-06 10:10:09 +02:00
[
core ,
data ,
currentIndexPattern ,
dateRange ,
query ,
filters ,
localState . nameFilter ,
charts . theme ,
]
2020-06-26 18:43:35 +02:00
) ;
2020-03-04 02:26:40 +01:00
2019-09-17 20:57:53 +02:00
return (
< ChildDragDropProvider { ...dragDropContext } >
< EuiFlexGroup
gutterSize = "none"
2019-09-23 20:57:35 +02:00
className = "lnsInnerIndexPatternDataPanel"
2019-09-17 20:57:53 +02:00
direction = "column"
responsive = { false }
>
2020-06-26 18:43:35 +02:00
< EuiFlexItem grow = { false } >
2019-09-23 20:57:35 +02:00
< div className = "lnsInnerIndexPatternDataPanel__header" >
2019-10-03 19:30:33 +02:00
< ChangeIndexPattern
data - test - subj = "indexPattern-switcher"
trigger = { {
label : currentIndexPattern.title ,
title : currentIndexPattern.title ,
'data-test-subj' : 'indexPattern-switch-link' ,
2020-07-14 02:06:58 +02:00
fontWeight : 'bold' ,
2019-10-03 19:30:33 +02:00
} }
2019-12-13 17:44:58 +01:00
indexPatternId = { currentIndexPatternId }
2019-10-09 21:20:55 +02:00
indexPatternRefs = { indexPatternRefs }
2019-10-03 19:30:33 +02:00
onChangeIndexPattern = { ( newId : string ) = > {
onChangeIndexPattern ( newId ) ;
2019-10-23 17:28:27 +02:00
clearLocalState ( ) ;
2019-10-03 19:30:33 +02:00
} }
/ >
2019-09-17 20:57:53 +02:00
< / div >
< / EuiFlexItem >
2020-06-26 18:43:35 +02:00
< EuiFlexItem grow = { false } >
< EuiFormControlLayout
icon = "search"
fullWidth
clear = { {
title : i18n.translate ( 'xpack.lens.indexPatterns.clearFiltersLabel' , {
defaultMessage : 'Clear name and type filters' ,
} ) ,
'aria-label' : i18n . translate ( 'xpack.lens.indexPatterns.clearFiltersLabel' , {
defaultMessage : 'Clear name and type filters' ,
} ) ,
onClick : ( ) = > {
trackUiEvent ( 'indexpattern_filters_cleared' ) ;
clearLocalState ( ) ;
} ,
} }
>
< input
className = "euiFieldText euiFieldText--fullWidth lnsInnerIndexPatternDataPanel__textField"
data - test - subj = "lnsIndexPatternFieldSearch"
placeholder = { i18n . translate ( 'xpack.lens.indexPatterns.filterByNameLabel' , {
defaultMessage : 'Search field names' ,
description : 'Search the list of fields in the index pattern for the provided text' ,
} ) }
value = { localState . nameFilter }
onChange = { ( e ) = > {
setLocalState ( { . . . localState , nameFilter : e.target.value } ) ;
2019-10-01 15:42:27 +02:00
} }
2020-06-26 18:43:35 +02:00
aria - label = { i18n . translate ( 'xpack.lens.indexPatterns.filterByNameAriaLabel' , {
defaultMessage : 'Search fields' ,
} ) }
2020-11-25 16:57:03 +01:00
aria - describedby = { fieldSearchDescriptionId }
2020-06-26 18:43:35 +02:00
/ >
< / EuiFormControlLayout >
< EuiSpacer size = "xs" / >
< EuiFilterGroup >
2019-10-01 15:42:27 +02:00
< EuiPopover
id = "dataPanelTypeFilter"
panelClassName = "euiFilterGroup__popoverPanel"
panelPaddingSize = "none"
2020-06-26 18:43:35 +02:00
anchorPosition = "rightUp"
2019-10-01 15:42:27 +02:00
display = "block"
isOpen = { localState . isTypeFilterOpen }
2019-10-09 21:20:55 +02:00
closePopover = { ( ) = > setLocalState ( ( ) = > ( { . . . localState , isTypeFilterOpen : false } ) ) }
2019-10-01 15:42:27 +02:00
button = {
2020-06-26 18:43:35 +02:00
< EuiFilterButton
iconType = "arrowDown"
isSelected = { localState . isTypeFilterOpen }
numFilters = { localState . typeFilter . length }
hasActiveFilters = { ! ! localState . typeFilter . length }
numActiveFilters = { localState . typeFilter . length }
2019-10-01 15:42:27 +02:00
data - test - subj = "lnsIndexPatternFiltersToggle"
onClick = { ( ) = > {
2020-05-22 09:08:58 +02:00
setLocalState ( ( s ) = > ( {
2019-09-17 20:57:53 +02:00
. . . s ,
2019-10-01 15:42:27 +02:00
isTypeFilterOpen : ! localState . isTypeFilterOpen ,
2019-09-17 20:57:53 +02:00
} ) ) ;
} }
2019-10-01 15:42:27 +02:00
>
2020-06-26 18:43:35 +02:00
{ fieldFiltersLabel }
< / EuiFilterButton >
2019-10-01 15:42:27 +02:00
}
>
2020-09-24 09:55:32 +02:00
< EuiContextMenuPanel
2019-10-01 15:42:27 +02:00
watchedItemProps = { [ 'icon' , 'disabled' ] }
data - test - subj = "lnsIndexPatternTypeFilterOptions"
2020-05-22 09:08:58 +02:00
items = { ( availableFieldTypes as DataType [ ] ) . map ( ( type ) = > (
2019-10-01 15:42:27 +02:00
< EuiContextMenuItem
2020-02-22 00:28:53 +01:00
className = "lnsInnerIndexPatternDataPanel__filterType"
2019-10-01 15:42:27 +02:00
key = { type }
icon = { localState . typeFilter . includes ( type ) ? 'check' : 'empty' }
data - test - subj = { ` typeFilter- ${ type } ` }
2019-10-16 05:01:43 +02:00
onClick = { ( ) = > {
trackUiEvent ( 'indexpattern_type_filter_toggled' ) ;
2020-05-22 09:08:58 +02:00
setLocalState ( ( s ) = > ( {
2019-10-01 15:42:27 +02:00
. . . s ,
typeFilter : localState.typeFilter.includes ( type )
2020-05-22 09:08:58 +02:00
? localState . typeFilter . filter ( ( t ) = > t !== type )
2019-10-01 15:42:27 +02:00
: [ . . . localState . typeFilter , type ] ,
2019-10-16 05:01:43 +02:00
} ) ) ;
} }
2019-10-01 15:42:27 +02:00
>
2020-02-22 00:28:53 +01:00
< span className = "lnsInnerIndexPatternDataPanel__filterTypeInner" >
< LensFieldIcon type = { type } / > { fieldTypeNames [ type ] }
< / span >
2019-10-01 15:42:27 +02:00
< / EuiContextMenuItem >
) ) }
/ >
< / EuiPopover >
2020-06-26 18:43:35 +02:00
< / EuiFilterGroup >
< / EuiFlexItem >
2020-11-25 16:57:03 +01:00
< EuiScreenReaderOnly >
< div aria - live = "polite" id = { fieldSearchDescriptionId } >
{ i18n . translate ( 'xpack.lens.indexPatterns.fieldSearchLiveRegion' , {
defaultMessage :
'{availableFields} available {availableFields, plural, one {field} other {fields}}. {emptyFields} empty {emptyFields, plural, one {field} other {fields}}. {metaFields} meta {metaFields, plural, one {field} other {fields}}.' ,
values : {
availableFields : fieldGroups.AvailableFields.fields.length ,
2020-12-02 09:42:42 +01:00
// empty fields can be undefined if there is no existence information to be fetched
emptyFields : fieldGroups.EmptyFields?.fields.length || 0 ,
2020-11-25 16:57:03 +01:00
metaFields : fieldGroups.MetaFields.fields.length ,
} ,
} ) }
< / div >
< / EuiScreenReaderOnly >
2020-06-26 18:43:35 +02:00
< EuiFlexItem >
2020-09-24 09:55:32 +02:00
< FieldList
exists = { ( field ) = >
field . type === 'document' ||
fieldExists ( existingFields , currentIndexPattern . title , field . name )
}
fieldProps = { fieldProps }
fieldGroups = { fieldGroups }
hasSyncedExistingFields = { ! ! hasSyncedExistingFields }
filter = { {
nameFilter : localState.nameFilter ,
typeFilter : localState.typeFilter ,
2019-09-17 20:57:53 +02:00
} }
2020-09-24 09:55:32 +02:00
currentIndexPatternId = { currentIndexPatternId }
existenceFetchFailed = { existenceFetchFailed }
2020-09-30 18:51:18 +02:00
existFieldsInIndex = { ! ! allFields . length }
2020-09-24 09:55:32 +02:00
/ >
2019-09-17 20:57:53 +02:00
< / EuiFlexItem >
< / EuiFlexGroup >
< / ChildDragDropProvider >
) ;
} ;
export const MemoizedDataPanel = memo ( InnerIndexPatternDataPanel ) ;