Skip to content

Commit 669b80f

Browse files
Use case-insensitive substring match for quick filter field selector (#6)
* Use case-insensitive substring match for quick filter field selector * Update .nvmrc --------- Co-authored-by: Tommi Lätti <tommi.latti@paypay-corp.co.jp>
1 parent 809ff6f commit 669b80f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16
1+
20

src/components/QueryEditor/FilterEditor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ interface FilterEditorRowProps {
9595

9696
export const FilterEditorRow = ({ value, onSubmit }: FilterEditorRowProps) => {
9797
const dispatch = useDispatch();
98-
const getFields = useFields('filters', 'startsWith');
98+
const getFields = useFields('filters', 'containsCaseInsensitive');
9999
const valueInputRef = useRef<HTMLInputElement>(null);
100100

101101
return (

src/hooks/useFields.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const toSelectableValue = ({ text }: MetricFindValue): SelectableValue<string> =
4646
value: text,
4747
});
4848

49-
type MatchType = 'contains' | 'startsWith'
49+
type MatchType = 'contains' | 'containsCaseInsensitive' | 'startsWith'
5050

5151
/**
5252
* Returns a function to query the configured datasource for autocomplete values for the specified aggregation type or data types.
@@ -73,7 +73,20 @@ export const useFields = (type: AggregationType | string[], matchType: MatchType
7373
if (q === undefined) {
7474
return true;
7575
}
76-
return matchType === 'contains' ? text.includes(q) : text.startsWith(q)
76+
77+
switch (matchType) {
78+
case 'contains':
79+
return text.includes(q);
80+
81+
case 'containsCaseInsensitive':
82+
return text.toLowerCase().includes(q.toLowerCase());
83+
84+
case 'startsWith':
85+
return text.startsWith(q);
86+
87+
default:
88+
return true;
89+
}
7790
})
7891
.map(toSelectableValue);
7992
};

0 commit comments

Comments
 (0)