@@ -315,6 +315,7 @@ impl Filter {
315
315
316
316
impl SyntaxHighlighting for TimestampFormatted < ' _ , FilterKind > {
317
317
fn syntax_highlight_into ( & self , builder : & mut SyntaxHighlightedBuilder ) {
318
+ //TODO(ab): this is weird. this entire impl should be delegated to inner structs
318
319
builder. append_keyword ( & self . inner . operator_text ( ) ) ;
319
320
builder. append_keyword ( " " ) ;
320
321
@@ -335,8 +336,8 @@ impl SyntaxHighlighting for TimestampFormatted<'_, FilterKind> {
335
336
builder. append ( float_filter) ;
336
337
}
337
338
338
- FilterKind :: StringContains ( query ) => {
339
- builder. append_string_value ( query ) ;
339
+ FilterKind :: String ( string_filter ) => {
340
+ builder. append ( string_filter ) ;
340
341
}
341
342
342
343
FilterKind :: Timestamp ( timestamp_filter) => {
@@ -364,51 +365,22 @@ impl FilterKind {
364
365
column_name : & str ,
365
366
popup_just_opened : bool ,
366
367
) -> FilterUiAction {
367
- let mut action = FilterUiAction :: None ;
368
-
369
- let operator_text = self . operator_text ( ) ;
370
-
371
368
// Reduce the default width unnecessarily expands the popup width (queries as usually vers
372
369
// small).
373
370
ui. spacing_mut ( ) . text_edit_width = 150.0 ;
374
371
375
- // TODO(ab): this is getting unwieldy. All arms should have an independent inner struct,
376
- // which all handle their own UI.
377
372
match self {
378
- Self :: NonNullableBoolean ( boolean_filter) => {
379
- boolean_filter. popup_ui ( ui, column_name, & mut action) ;
380
- }
381
-
382
- Self :: NullableBoolean ( boolean_filter) => {
383
- boolean_filter. popup_ui ( ui, column_name, & mut action) ;
384
- }
385
-
386
- Self :: Int ( int_filter) => {
387
- action = int_filter. popup_ui ( ui, column_name, popup_just_opened) ;
388
- }
389
-
390
- Self :: Float ( float_filter) => {
391
- action = float_filter. popup_ui ( ui, column_name, popup_just_opened) ;
392
- }
393
-
394
- Self :: StringContains ( query) => {
395
- basic_operation_ui ( ui, column_name, & operator_text) ;
396
-
397
- let response = ui. text_edit_singleline ( query) ;
398
-
399
- if popup_just_opened {
400
- response. request_focus ( ) ;
401
- }
402
-
403
- action = action_from_text_edit_response ( ui, & response) ;
373
+ Self :: NonNullableBoolean ( boolean_filter) => boolean_filter. popup_ui ( ui, column_name) ,
374
+ Self :: NullableBoolean ( boolean_filter) => boolean_filter. popup_ui ( ui, column_name) ,
375
+ Self :: Int ( int_filter) => int_filter. popup_ui ( ui, column_name, popup_just_opened) ,
376
+ Self :: Float ( float_filter) => float_filter. popup_ui ( ui, column_name, popup_just_opened) ,
377
+ Self :: String ( string_filter) => {
378
+ string_filter. popup_ui ( ui, column_name, popup_just_opened)
404
379
}
405
-
406
380
Self :: Timestamp ( timestamp_filter) => {
407
- timestamp_filter. popup_ui ( ui, column_name, & mut action , timestamp_format) ;
381
+ timestamp_filter. popup_ui ( ui, column_name, timestamp_format)
408
382
}
409
383
}
410
-
411
- action
412
384
}
413
385
414
386
/// Given a chance to the underlying filter struct to update/clean itself upon committing the
@@ -422,7 +394,7 @@ impl FilterKind {
422
394
| Self :: NonNullableBoolean ( _)
423
395
| Self :: Int ( _)
424
396
| Self :: Float ( _)
425
- | Self :: StringContains ( _) => { }
397
+ | Self :: String ( _) => { }
426
398
427
399
Self :: Timestamp ( timestamp_filter) => timestamp_filter. on_commit ( ) ,
428
400
}
@@ -433,7 +405,7 @@ impl FilterKind {
433
405
match self {
434
406
Self :: Int ( int_filter) => int_filter. comparison_operator ( ) . to_string ( ) ,
435
407
Self :: Float ( float_filter) => float_filter. comparison_operator ( ) . to_string ( ) ,
436
- Self :: StringContains ( _ ) => "contains" . to_owned ( ) ,
408
+ Self :: String ( string_filter ) => string_filter . operator ( ) . to_string ( ) ,
437
409
Self :: NonNullableBoolean ( _) | Self :: NullableBoolean ( _) | Self :: Timestamp ( _) => {
438
410
"is" . to_owned ( )
439
411
}
@@ -462,22 +434,23 @@ pub fn action_from_text_edit_response(ui: &egui::Ui, response: &egui::Response)
462
434
mod tests {
463
435
use super :: super :: {
464
436
ComparisonOperator , FloatFilter , IntFilter , NonNullableBooleanFilter ,
465
- NullableBooleanFilter , TimestampFilter ,
437
+ NullableBooleanFilter , StringFilter , TimestampFilter ,
466
438
} ;
467
439
use super :: * ;
440
+ use crate :: filters:: StringOperator ;
468
441
469
442
fn test_cases ( ) -> Vec < ( FilterKind , & ' static str ) > {
470
443
// Let's remember to update this test when adding new filter operations.
471
444
#[ cfg( debug_assertions) ]
472
445
let _: ( ) = {
473
446
use FilterKind :: * ;
474
- let _op = StringContains ( String :: new ( ) ) ;
447
+ let _op = String ( Default :: default ( ) ) ;
475
448
match _op {
476
449
NonNullableBoolean ( _)
477
450
| NullableBoolean ( _)
478
451
| Int ( _)
479
452
| Float ( _)
480
- | StringContains ( _)
453
+ | String ( _)
481
454
| Timestamp ( _) => { }
482
455
}
483
456
} ;
@@ -520,13 +493,17 @@ mod tests {
520
493
"float_compares_none" ,
521
494
) ,
522
495
(
523
- FilterKind :: StringContains ( "query" . to_owned ( ) ) ,
496
+ FilterKind :: String ( StringFilter :: new ( StringOperator :: Contains , "query" ) ) ,
524
497
"string_contains" ,
525
498
) ,
526
499
(
527
- FilterKind :: StringContains ( String :: new ( ) ) ,
500
+ FilterKind :: String ( StringFilter :: new ( StringOperator :: Contains , "" ) ) ,
528
501
"string_contains_empty" ,
529
502
) ,
503
+ (
504
+ FilterKind :: String ( StringFilter :: new ( StringOperator :: StartsWith , "query" ) ) ,
505
+ "string_starts_with" ,
506
+ ) ,
530
507
(
531
508
FilterKind :: Timestamp ( TimestampFilter :: after (
532
509
jiff:: Timestamp :: from_millisecond ( 100_000_000_000 ) . unwrap ( ) ,
@@ -607,18 +584,39 @@ mod tests {
607
584
let filters = vec ! [
608
585
Filter :: new(
609
586
"some:column:name" ,
610
- FilterKind :: StringContains ( "some query string" . to_owned( ) ) ,
587
+ FilterKind :: String ( StringFilter :: new(
588
+ StringOperator :: Contains ,
589
+ "some query string" . to_owned( ) ,
590
+ ) ) ,
611
591
) ,
612
592
Filter :: new(
613
593
"other:column:name" ,
614
- FilterKind :: StringContains ( "hello" . to_owned( ) ) ,
594
+ FilterKind :: String ( StringFilter :: new(
595
+ StringOperator :: Contains ,
596
+ "hello" . to_owned( ) ,
597
+ ) ) ,
598
+ ) ,
599
+ Filter :: new(
600
+ "short:name" ,
601
+ FilterKind :: String ( StringFilter :: new(
602
+ StringOperator :: Contains ,
603
+ "world" . to_owned( ) ,
604
+ ) ) ,
615
605
) ,
616
- Filter :: new( "short:name" , FilterKind :: StringContains ( "world" . to_owned( ) ) ) ,
617
606
Filter :: new(
618
607
"looooog:name" ,
619
- FilterKind :: StringContains ( "some more querying text here" . to_owned( ) ) ,
608
+ FilterKind :: String ( StringFilter :: new(
609
+ StringOperator :: Contains ,
610
+ "some more querying text here" . to_owned( ) ,
611
+ ) ) ,
612
+ ) ,
613
+ Filter :: new(
614
+ "world" ,
615
+ FilterKind :: String ( StringFilter :: new(
616
+ StringOperator :: Contains ,
617
+ ":wave:" . to_owned( ) ,
618
+ ) ) ,
620
619
) ,
621
- Filter :: new( "world" , FilterKind :: StringContains ( ":wave:" . to_owned( ) ) ) ,
622
620
] ;
623
621
624
622
let mut filters = FilterState {
0 commit comments