-
-
Notifications
You must be signed in to change notification settings - Fork 73
Issue 545 - Case (in)sensitive filtering #893
Changes from 4 commits
f5783de
ee42e93
0b7897b
8d19241
49773fd
99aa5a9
d5fddb0
551cd3a
d76ae04
c07a701
8ddf84e
d0c744a
5c69ae7
e686aea
ada8456
6f012c3
4697136
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ export interface ILexerResult { | |
|
||
export interface ILexemeResult { | ||
lexeme: ILexeme; | ||
flags?: string; | ||
value?: string; | ||
} | ||
|
||
|
@@ -37,8 +38,10 @@ export default function lexer(lexicon: Lexicon, query: string): ILexerResult { | |
return {lexemes: result, valid: false, error: query}; | ||
} | ||
|
||
const value = (query.match(next.regexp) || [])[next.regexpMatch || 0]; | ||
result.push({lexeme: next, value}); | ||
const match = query.match(next.regexp) ?? []; | ||
const value = match[next.regexpMatch || 0]; | ||
const flags = match[next.regexpFlags || -1]; | ||
result.push({lexeme: next, flags, value}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a lexicon perspective treat |
||
|
||
query = query.substring(value.length); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,20 @@ import React, {CSSProperties, PureComponent} from 'react'; | |
|
||
import IsolatedInput from 'core/components/IsolatedInput'; | ||
|
||
import {ColumnId} from 'dash-table/components/Table/props'; | ||
import {ColumnId, FilterCase} from 'dash-table/components/Table/props'; | ||
import TableClipboardHelper from 'dash-table/utils/TableClipboardHelper'; | ||
import FilterOptions from 'dash-table/components/Filter/FilterOptions'; | ||
|
||
type SetFilter = (ev: any) => void; | ||
|
||
interface IColumnFilterProps { | ||
className: string; | ||
columnId: ColumnId; | ||
filterOptions: FilterCase; | ||
isValid: boolean; | ||
setFilter: SetFilter; | ||
style?: CSSProperties; | ||
toggleFilterOptions: () => void; | ||
value?: string; | ||
} | ||
|
||
|
@@ -41,7 +44,15 @@ export default class ColumnFilter extends PureComponent< | |
}; | ||
|
||
render() { | ||
const {className, columnId, isValid, style, value} = this.props; | ||
const { | ||
className, | ||
columnId, | ||
filterOptions, | ||
isValid, | ||
style, | ||
toggleFilterOptions, | ||
value | ||
} = this.props; | ||
|
||
return ( | ||
<th | ||
|
@@ -62,6 +73,10 @@ export default class ColumnFilter extends PureComponent< | |
stopPropagation={true} | ||
submit={this.submit} | ||
/> | ||
<FilterOptions | ||
filterOptions={filterOptions} | ||
toggleFilterOptions={toggleFilterOptions} | ||
/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New component displayed in the filter cell to toggle filtering options |
||
</th> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
|
||
import {FilterCase} from 'dash-table/components/Table/props'; | ||
|
||
interface IFilterCaseButtonProps { | ||
filterOptions: FilterCase; | ||
toggleFilterOptions: () => void; | ||
} | ||
|
||
export default ({ | ||
filterOptions, | ||
toggleFilterOptions | ||
}: IFilterCaseButtonProps) => (<input | ||
type='button' | ||
className={`dash-filter--case ${filterOptions === FilterCase.Sensitive | ||
? 'dash-filter--case--sensitive' | ||
: 'dash-filter--case--insensitive' | ||
}`} | ||
onClick={toggleFilterOptions} | ||
value='Aa' | ||
/>); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,13 +57,27 @@ export default class FilterFactory { | |
updateColumnFilter(map, column, operator, value, setFilter); | ||
}; | ||
|
||
private onToggleChange = ( | ||
column: IColumn, | ||
map: Map<string, SingleColumnSyntaxTree>, | ||
operator: FilterLogicalOperator, | ||
setFilter: SetFilter, | ||
toggleFilterOptions: (column: IColumn) => IColumn, | ||
value: any | ||
) => { | ||
const newColumn = toggleFilterOptions(column); | ||
|
||
updateColumnFilter(map, newColumn, operator, value, setFilter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trigger a |
||
}; | ||
|
||
private filter = memoizerCache<[ColumnId, number]>()( | ||
( | ||
column: IColumn, | ||
index: number, | ||
map: Map<string, SingleColumnSyntaxTree>, | ||
operator: FilterLogicalOperator, | ||
setFilter: SetFilter | ||
setFilter: SetFilter, | ||
toggleFilterOptions: (column: IColumn) => IColumn | ||
) => { | ||
const ast = map.get(column.id.toString()); | ||
|
||
|
@@ -72,6 +86,7 @@ export default class FilterFactory { | |
key={`column-${index}`} | ||
className={`dash-filter column-${index}`} | ||
columnId={column.id} | ||
filterOptions={column.filter_options} | ||
isValid={!ast || ast.isValid} | ||
setFilter={this.onChange.bind( | ||
this, | ||
|
@@ -80,6 +95,11 @@ export default class FilterFactory { | |
operator, | ||
setFilter | ||
)} | ||
// Running into TypeScript binding issues with many parameters.. | ||
// bind with no more than 4 params each time.. sigh.. | ||
toggleFilterOptions={this.onToggleChange | ||
.bind(this, column, map, operator, setFilter) | ||
.bind(this, toggleFilterOptions, ast && ast.query)} | ||
wbrgss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value={ast && ast.query} | ||
/> | ||
); | ||
|
@@ -107,6 +127,7 @@ export default class FilterFactory { | |
style_cell_conditional, | ||
style_filter, | ||
style_filter_conditional, | ||
toggleFilterOptions, | ||
visibleColumns | ||
} = this.props; | ||
|
||
|
@@ -139,7 +160,8 @@ export default class FilterFactory { | |
index, | ||
map, | ||
filter_action.operator, | ||
setFilter | ||
setFilter, | ||
toggleFilterOptions | ||
); | ||
}, | ||
visibleColumns | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,11 @@ export enum ExportHeaders { | |
Display = 'display' | ||
} | ||
|
||
export enum FilterCase { | ||
Insensitive = 'insensitive', | ||
Sensitive = 'sensitive' | ||
} | ||
|
||
export enum SortMode { | ||
Single = 'single', | ||
Multi = 'multi' | ||
|
@@ -193,6 +198,7 @@ export interface IBaseColumn { | |
clearable?: boolean | boolean[] | 'first' | 'last'; | ||
deletable?: boolean | boolean[] | 'first' | 'last'; | ||
editable: boolean; | ||
filter_options: FilterCase; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FilterCase vs. |
||
hideable?: boolean | boolean[] | 'first' | 'last'; | ||
renamable?: boolean | boolean[] | 'first' | 'last'; | ||
selectable?: boolean | boolean[] | 'first' | 'last'; | ||
|
@@ -327,6 +333,7 @@ export interface IProps { | |
data?: Data; | ||
editable?: boolean; | ||
fill_width?: boolean; | ||
filter_options?: FilterCase; | ||
filter_query?: string; | ||
filter_action?: TableAction | IFilterAction; | ||
hidden_columns?: string[]; | ||
|
@@ -381,6 +388,7 @@ interface IDefaultProps { | |
export_format: ExportFormat; | ||
export_headers: ExportHeaders; | ||
fill_width: boolean; | ||
filter_options: FilterCase; | ||
filter_query: string; | ||
filter_action: TableAction; | ||
fixed_columns: Fixed; | ||
|
@@ -492,6 +500,7 @@ export interface IFilterFactoryProps { | |
style_cell_conditional: Cells; | ||
style_filter: Style; | ||
style_filter_conditional: BasicFilters; | ||
toggleFilterOptions: (column: IColumn) => IColumn; | ||
visibleColumns: Columns; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; | |
import {asyncDecorator} from '@plotly/dash-component-plugins'; | ||
|
||
import LazyLoader from 'dash-table/LazyLoader'; | ||
import {FilterCase} from 'dash-table/components/Table/props'; | ||
|
||
/** | ||
* Dash DataTable is an interactive table component designed for | ||
|
@@ -56,6 +57,7 @@ export const defaultProps = { | |
dropdown_data: [], | ||
|
||
fill_width: true, | ||
filter_options: FilterCase.Sensitive, | ||
fixed_columns: { | ||
headers: false, | ||
data: 0 | ||
|
@@ -181,6 +183,17 @@ export const propTypes = { | |
*/ | ||
editable: PropTypes.bool, | ||
|
||
/** | ||
* There are two `filter_options` props in the table. | ||
* This is the column-level filter_options prop and there is | ||
* also the table-level `filter_options` prop. | ||
* These props determine whether the applicable filter relational | ||
* operators will default to `sensitive` or `insensitive` comparison. | ||
* If the column-level `filter_options` prop is set it overrides | ||
* the table-level `filter_options` prop for that column. | ||
*/ | ||
filter_options: PropTypes.oneOf(['sensitive', 'insensitive']), | ||
|
||
/** | ||
* If true, the user can hide the column by clicking on the `hide` | ||
* action button on the column. If there are multiple header rows, true | ||
|
@@ -1142,6 +1155,17 @@ export const propTypes = { | |
}) | ||
]), | ||
|
||
/** | ||
* There are two `filter_options` props in the table. | ||
* This is the table-level filter_options prop and there is | ||
* also the column-level `filter_options` prop. | ||
* These props determine whether the applicable filter relational | ||
* operators will default to `sensitive` or `insensitive` comparison. | ||
* If the column-level `filter_options` prop is set it overrides | ||
* the table-level `filter_options` prop for that column. | ||
*/ | ||
filter_options: PropTypes.oneOf(['sensitive', 'insensitive']), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After a bit of a slack convo with @Marc-Andre-Rivet I think we concluded we should change this to The alternative would be to make a single specific prop now, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this to an object works for me. I knew @Marc-Andre-Rivet wrote this with extensibility in mind and I agree this more cleanly allows for various filter-option combinations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
/** | ||
* The `sort_action` property enables data to be | ||
* sorted on a per-column basis. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export default (tableFlag: boolean, columnFlag: boolean | undefined): boolean => | ||
export default <T>(tableFlag: T, columnFlag: T | undefined): T => | ||
columnFlag === undefined ? tableFlag : columnFlag; |
Uh oh!
There was an error while loading. Please reload this page.