@@ -8,23 +8,14 @@ import './filters.scss';
88import React , { MouseEventHandler , useState } from 'react' ;
99import { omit } from 'lodash' ;
1010import { i18n } from '@kbn/i18n' ;
11- import {
12- EuiDragDropContext ,
13- EuiDraggable ,
14- EuiDroppable ,
15- euiDragDropReorder ,
16- EuiButtonEmpty ,
17- EuiFormRow ,
18- EuiLink ,
19- htmlIdGenerator ,
20- } from '@elastic/eui' ;
11+ import { EuiFormRow , EuiLink , htmlIdGenerator } from '@elastic/eui' ;
2112import { updateColumnParam } from '../../../state_helpers' ;
2213import { OperationDefinition } from '../index' ;
2314import { FieldBasedIndexPatternColumn } from '../column_types' ;
2415import { FilterPopover } from './filter_popover' ;
2516import { IndexPattern } from '../../../types' ;
2617import { Query , esKuery , esQuery } from '../../../../../../../../src/plugins/data/public' ;
27- import { CustomBucketContainer } from '../shared_components' ;
18+ import { NewBucketButton , DragDropBuckets , DraggableBucketContainer } from '../shared_components' ;
2819
2920const generateId = htmlIdGenerator ( ) ;
3021
@@ -33,10 +24,11 @@ export interface Filter {
3324 input : Query ;
3425 label : string ;
3526}
27+
3628export interface FilterValue {
29+ id : string ;
3730 input : Query ;
3831 label : string ;
39- id : string ;
4032}
4133
4234const customQueryLabel = i18n . translate ( 'xpack.lens.indexPattern.customQuery' , {
@@ -69,11 +61,6 @@ export const isQueryValid = (input: Query, indexPattern: IndexPattern) => {
6961 }
7062} ;
7163
72- interface DraggableLocation {
73- droppableId : string ;
74- index : number ;
75- }
76-
7764export interface FiltersIndexPatternColumn extends FieldBasedIndexPatternColumn {
7865 operationType : 'filters' ;
7966 params : {
@@ -215,92 +202,67 @@ export const FilterList = ({
215202 )
216203 ) ;
217204
218- const onDragEnd = ( {
219- source,
220- destination,
221- } : {
222- source ?: DraggableLocation ;
223- destination ?: DraggableLocation ;
224- } ) => {
225- if ( source && destination ) {
226- const items = euiDragDropReorder ( localFilters , source . index , destination . index ) ;
227- updateFilters ( items ) ;
228- }
229- } ;
230-
231205 return (
232206 < >
233- < EuiDragDropContext onDragEnd = { onDragEnd } onDragStart = { ( ) => setIsOpenByCreation ( false ) } >
234- < EuiDroppable droppableId = "FILTERS_DROPPABLE_AREA" spacing = "s" >
235- { localFilters ?. map ( ( filter : FilterValue , idx : number ) => {
236- const { input, label, id } = filter ;
237- const isInvalid = ! isQueryValid ( input , indexPattern ) ;
207+ < DragDropBuckets
208+ onDragEnd = { updateFilters }
209+ onDragStart = { ( ) => setIsOpenByCreation ( false ) }
210+ droppableId = "FILTERS_DROPPABLE_AREA"
211+ items = { localFilters }
212+ >
213+ { localFilters ?. map ( ( filter : FilterValue , idx : number ) => {
214+ const isInvalid = ! isQueryValid ( filter . input , indexPattern ) ;
238215
239- return (
240- < EuiDraggable
241- spacing = "m"
242- key = { id }
243- index = { idx }
244- draggableId = { id }
245- disableInteractiveElementBlocking
246- >
247- { ( provided ) => (
248- < CustomBucketContainer
249- isInvalid = { isInvalid }
250- invalidMessage = { i18n . translate ( 'xpack.lens.indexPattern.filters.isInvalid' , {
251- defaultMessage : 'This query is invalid' ,
216+ return (
217+ < DraggableBucketContainer
218+ id = { filter . id }
219+ key = { filter . id }
220+ idx = { idx }
221+ isInvalid = { isInvalid }
222+ invalidMessage = { i18n . translate ( 'xpack.lens.indexPattern.filters.isInvalid' , {
223+ defaultMessage : 'This query is invalid' ,
224+ } ) }
225+ onRemoveClick = { ( ) => onRemoveFilter ( filter . id ) }
226+ removeTitle = { i18n . translate ( 'xpack.lens.indexPattern.filters.removeCustomQuery' , {
227+ defaultMessage : 'Remove custom query' ,
228+ } ) }
229+ >
230+ < FilterPopover
231+ data-test-subj = "indexPattern-filters-existingFilterContainer"
232+ isOpenByCreation = { idx === localFilters . length - 1 && isOpenByCreation }
233+ setIsOpenByCreation = { setIsOpenByCreation }
234+ indexPattern = { indexPattern }
235+ filter = { filter }
236+ setFilter = { ( f : FilterValue ) => {
237+ onChangeValue ( f . id , f . input , f . label ) ;
238+ } }
239+ Button = { ( { onClick } : { onClick : MouseEventHandler } ) => (
240+ < EuiLink
241+ className = "lnsFiltersOperation__popoverButton"
242+ data-test-subj = "indexPattern-filters-existingFilterTrigger"
243+ onClick = { onClick }
244+ color = { isInvalid ? 'danger' : 'text' }
245+ title = { i18n . translate ( 'xpack.lens.indexPattern.filters.clickToEdit' , {
246+ defaultMessage : 'Click to edit' ,
252247 } ) }
253- onRemoveClick = { ( ) => onRemoveFilter ( filter . id ) }
254- removeTitle = { i18n . translate (
255- 'xpack.lens.indexPattern.filters.removeCustomQuery' ,
256- {
257- defaultMessage : 'Remove custom query' ,
258- }
259- ) }
260248 >
261- < FilterPopover
262- data-test-subj = "indexPattern-filters-existingFilterContainer"
263- isOpenByCreation = { idx === localFilters . length - 1 && isOpenByCreation }
264- setIsOpenByCreation = { setIsOpenByCreation }
265- indexPattern = { indexPattern }
266- filter = { filter }
267- setFilter = { ( f : FilterValue ) => {
268- onChangeValue ( f . id , f . input , f . label ) ;
269- } }
270- Button = { ( { onClick } : { onClick : MouseEventHandler } ) => (
271- < EuiLink
272- className = "lnsFiltersOperation__popoverButton"
273- data-test-subj = "indexPattern-filters-existingFilterTrigger"
274- onClick = { onClick }
275- color = { isInvalid ? 'danger' : 'text' }
276- title = { i18n . translate ( 'xpack.lens.indexPattern.filters.clickToEdit' , {
277- defaultMessage : 'Click to edit' ,
278- } ) }
279- >
280- { label || input . query || defaultLabel }
281- </ EuiLink >
282- ) }
283- />
284- </ CustomBucketContainer >
249+ { filter . label || filter . input . query || defaultLabel }
250+ </ EuiLink >
285251 ) }
286- </ EuiDraggable >
287- ) ;
288- } ) }
289- </ EuiDroppable >
290- </ EuiDragDropContext >
291-
292- < EuiButtonEmpty
293- size = "xs"
294- iconType = "plusInCircle"
252+ />
253+ </ DraggableBucketContainer >
254+ ) ;
255+ } ) }
256+ </ DragDropBuckets >
257+ < NewBucketButton
295258 onClick = { ( ) => {
296259 onAddFilter ( ) ;
297260 setIsOpenByCreation ( true ) ;
298261 } }
299- >
300- { i18n . translate ( 'xpack.lens.indexPattern.filters.addCustomQuery' , {
262+ label = { i18n . translate ( 'xpack.lens.indexPattern.filters.addCustomQuery' , {
301263 defaultMessage : 'Add a custom query' ,
302264 } ) }
303- </ EuiButtonEmpty >
265+ / >
304266 </ >
305267 ) ;
306268} ;
0 commit comments