This is an automated email from the ASF dual-hosted git repository. cwylie pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-druid.git
The following commit(s) were added to refs/heads/master by this push: new c8bffd9 Add exact match filtering to console table (#7448) c8bffd9 is described below commit c8bffd9351ac0003f285b5225f6aecc1fbe40580 Author: Qi Shu <shuqi...@gmail.com> AuthorDate: Wed Apr 17 23:05:44 2019 -0700 Add exact match filtering to console table (#7448) * Add exact filtering * Bug fix * Extract filter as a function * change code position --- web-console/src/bootstrap/react-table-defaults.tsx | 5 ++-- web-console/src/utils/general.tsx | 27 ++++++++++++++++++++++ web-console/src/views/segments-view.tsx | 6 ++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/web-console/src/bootstrap/react-table-defaults.tsx b/web-console/src/bootstrap/react-table-defaults.tsx index 728781c..d582312 100644 --- a/web-console/src/bootstrap/react-table-defaults.tsx +++ b/web-console/src/bootstrap/react-table-defaults.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import { Filter, ReactTableDefaults } from 'react-table'; import { Loader } from '../components/loader'; -import { countBy, makeTextFilter } from '../utils'; +import { countBy, customTableFilter, makeTextFilter } from '../utils'; import { ReactTableCustomPagination } from './react-table-custom-pagination'; @@ -38,8 +38,7 @@ class NoData extends React.Component { Object.assign(ReactTableDefaults, { defaultFilterMethod: (filter: Filter, row: any, column: any) => { - const id = filter.pivotId || filter.id; - return row[id] !== undefined ? String(row[id]).includes(filter.value) : true; + return customTableFilter(filter, row); }, LoadingComponent: Loader, loadingText: '', diff --git a/web-console/src/utils/general.tsx b/web-console/src/utils/general.tsx index eab8666..03ccdd1 100644 --- a/web-console/src/utils/general.tsx +++ b/web-console/src/utils/general.tsx @@ -23,6 +23,7 @@ import * as React from 'react'; import { Filter, FilterRender } from 'react-table'; export function addFilter(filters: Filter[], id: string, value: string): Filter[] { + value = `"${value}"`; const currentFilter = filters.find(f => f.id === id); if (currentFilter) { filters = filters.filter(f => f.id !== id); @@ -65,6 +66,32 @@ export function makeBooleanFilter(): FilterRender { }; } +export function customTableFilter(filter: Filter, row?: any): boolean | string { + const id = filter.pivotId || filter.id; + const clientSideFilter: boolean = row !== undefined; + if (clientSideFilter && row[id] === undefined) { + return true; + } + const targetValue = (clientSideFilter && String(row[id].toLowerCase())) || JSON.stringify(filter.id).toLowerCase(); + let filterValue = filter.value.toLowerCase(); + if (filterValue.startsWith(`"`) && filterValue.endsWith(`"`)) { + const exactString = filterValue.slice(1, -1); + if (clientSideFilter) { + return String(targetValue) === exactString; + } else { + return `${targetValue} = '${exactString}'`; + } + } + if (filterValue.startsWith(`"`)) { + filterValue = filterValue.substring(1); + } + if (clientSideFilter) { + return targetValue.includes(filterValue); + } else { + return `${targetValue} LIKE '%${filterValue}%'`; + } +} + // ---------------------------- export function countBy<T>(array: T[], fn: (x: T, index: number) => string = String): Record<string, number> { diff --git a/web-console/src/views/segments-view.tsx b/web-console/src/views/segments-view.tsx index 43bcb01..94ff64d 100644 --- a/web-console/src/views/segments-view.tsx +++ b/web-console/src/views/segments-view.tsx @@ -29,7 +29,7 @@ import { TableColumnSelection } from '../components/table-column-selection'; import { ViewControlBar } from '../components/view-control-bar'; import { AppToaster } from '../singletons/toaster'; import { - addFilter, + addFilter, customTableFilter, formatBytes, formatNumber, LocalStorageKeys, makeBooleanFilter, @@ -123,7 +123,7 @@ export class SegmentsView extends React.Component<SegmentsViewProps, SegmentsVie if (f.value === 'all') return null; return `${JSON.stringify(f.id)} = ${f.value === 'true' ? 1 : 0}`; } else { - return `${JSON.stringify(f.id)} LIKE '%${f.value}%'`; + return customTableFilter(f); } }).filter(Boolean); @@ -176,7 +176,7 @@ export class SegmentsView extends React.Component<SegmentsViewProps, SegmentsVie accessor: 'datasource', Cell: row => { const value = row.value; - return <a onClick={() => { this.setState({ segmentFilter: addFilter(segmentFilter, 'datasource', value) }); }}>{value}</a>; + return <a onClick={() => { this.setState({ segmentFilter: addFilter(segmentFilter, 'datasource', value)}); }}>{value}</a>; }, show: tableColumnSelectionHandler.showColumn('Datasource') }, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org