@@ -6,10 +6,10 @@ import {
6
6
Box ,
7
7
ThemeIcon ,
8
8
Select ,
9
- Input ,
10
9
CloseIcon ,
11
10
Pill ,
12
11
ActionIcon ,
12
+ Autocomplete ,
13
13
} from '@mantine/core' ;
14
14
import { IconFilter , IconPlus } from '@tabler/icons-react' ;
15
15
import classes from '../../styles/Querier.module.css' ;
@@ -23,7 +23,7 @@ export const FilterPlaceholder = () => {
23
23
) ;
24
24
} ;
25
25
26
- import { useCallback , useEffect } from 'react' ;
26
+ import { useCallback , useEffect , useMemo , useState } from 'react' ;
27
27
import { useFilterStore , filterStoreReducers , operatorLabelMap } from '../../providers/FilterProvider' ;
28
28
import { useLogsStore } from '../../providers/LogsProvider' ;
29
29
import {
@@ -60,6 +60,22 @@ type RuleViewType = {
60
60
const RuleView = ( props : RuleViewType ) => {
61
61
const { rule, type, groupId } = props ;
62
62
const [ fieldNames , setFilterStore ] = useFilterStore ( ( store ) => store . fieldNames ) ;
63
+ const [ pageData ] = useLogsStore ( ( store ) => store . tableOpts . pageData ) ;
64
+ const [ columnValues , setColumnValues ] = useState < string [ ] > ( [ ] ) ;
65
+
66
+ const getUniqueColValues = useMemo ( ( ) => {
67
+ if ( ! rule . field ) return [ ] ;
68
+ return Array . from (
69
+ new Set ( pageData . filter ( ( item ) => item [ rule . field ] !== null ) . map ( ( item ) => String ( item [ rule . field ] ) ) ) ,
70
+ ) ;
71
+ } , [ pageData , rule . field ] ) ;
72
+
73
+ useEffect ( ( ) => {
74
+ if ( rule . field ) {
75
+ setColumnValues ( getUniqueColValues ) ;
76
+ }
77
+ } , [ rule . field , getUniqueColValues ] ) ;
78
+
63
79
const onFieldChange = useCallback ( ( field : string | null ) => {
64
80
if ( field === null ) return ;
65
81
setFilterStore ( ( store ) => updateRule ( store , groupId , rule . id , { field } ) ) ;
@@ -70,8 +86,8 @@ const RuleView = (props: RuleViewType) => {
70
86
setFilterStore ( ( store ) => updateRule ( store , groupId , rule . id , { operator } ) ) ;
71
87
} , [ ] ) ;
72
88
73
- const onValueChange = useCallback ( ( e : React . ChangeEvent < HTMLInputElement > ) => {
74
- setFilterStore ( ( store ) => updateRule ( store , groupId , rule . id , { value : e . target . value } ) ) ;
89
+ const onValueChange = useCallback ( ( value : string ) => {
90
+ setFilterStore ( ( store ) => updateRule ( store , groupId , rule . id , { value } ) ) ;
75
91
} , [ ] ) ;
76
92
77
93
const deleteBtnHandler = useCallback ( ( ) => {
@@ -91,14 +107,15 @@ const RuleView = (props: RuleViewType) => {
91
107
onChange = { onOperatorChange }
92
108
w = "33%"
93
109
/>
94
- < Input
110
+
111
+ < Autocomplete
95
112
value = { value }
96
- onChange = { onValueChange }
97
113
w = "33%"
98
- classNames = { { input : classes . fieldInput } }
99
114
error = { isError }
100
- type = { type }
101
- disabled = { isDisabled }
115
+ limit = { 10 }
116
+ classNames = { { input : classes . fieldInput } }
117
+ onChange = { onValueChange }
118
+ data = { columnValues }
102
119
/>
103
120
< ActionIcon className = { classes . deleteRulebtn } onClick = { deleteBtnHandler } variant = "light" >
104
121
< CloseIcon />
0 commit comments