Skip to content

Commit c74bbd8

Browse files
davemarcoMarco
andauthored
fix(webui): Respect case sensitivity setting in search queries (fixes #1060); refactor Zustand usages. (#1063)
Co-authored-by: Marco <[email protected]>
1 parent 6bfc677 commit c74bbd8

File tree

3 files changed

+56
-41
lines changed

3 files changed

+56
-41
lines changed

components/webui/client/src/pages/SearchPage/SearchControls/QueryInput/index.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {
2+
ChangeEvent,
3+
useCallback,
24
useEffect,
35
useRef,
46
useState,
@@ -21,16 +23,22 @@ import {
2123
* @return
2224
*/
2325
const QueryInput = () => {
24-
const {
25-
queryString,
26-
queryIsCaseSensitive,
27-
updateQueryString,
28-
updateQueryIsCaseSensitive,
29-
searchUiState,
30-
} = useSearchStore();
26+
const queryIsCaseSensitive = useSearchStore((state) => state.queryIsCaseSensitive);
27+
const queryString = useSearchStore((state) => state.queryString);
28+
const searchUiState = useSearchStore((state) => state.searchUiState);
3129
const [pseudoProgress, setPseudoProgress] = useState<Nullable<number>>(null);
3230
const intervalIdRef = useRef<number>(0);
3331

32+
const handleCaseSensitiveChange = useCallback((newValue: boolean) => {
33+
const {updateQueryIsCaseSensitive} = useSearchStore.getState();
34+
updateQueryIsCaseSensitive(newValue);
35+
}, []);
36+
37+
const handleChange = useCallback((ev: ChangeEvent<HTMLInputElement>) => {
38+
const {updateQueryString} = useSearchStore.getState();
39+
updateQueryString(ev.target.value);
40+
}, []);
41+
3442
useEffect(() => {
3543
if (searchUiState === SEARCH_UI_STATE.QUERY_ID_PENDING) {
3644
if (0 !== intervalIdRef.current) {
@@ -70,12 +78,8 @@ const QueryInput = () => {
7078
searchUiState === SEARCH_UI_STATE.QUERY_ID_PENDING ||
7179
searchUiState === SEARCH_UI_STATE.QUERYING
7280
}
73-
onCaseSensitiveChange={(newValue) => {
74-
updateQueryIsCaseSensitive(newValue);
75-
}}
76-
onChange={(e) => {
77-
updateQueryString(e.target.value);
78-
}}/>
81+
onCaseSensitiveChange={handleCaseSensitiveChange}
82+
onChange={handleChange}/>
7983
);
8084
};
8185

components/webui/client/src/pages/SearchPage/SearchControls/SearchButton/SubmitButton.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,29 @@ import styles from "./index.module.css";
1919
* @return
2020
*/
2121
const SubmitButton = () => {
22-
const {searchUiState, timeRange, queryString, updateTimelineConfig} = useSearchStore();
22+
const searchUiState = useSearchStore((state) => state.searchUiState);
23+
const queryString = useSearchStore((state) => state.queryString);
24+
const queryIsCaseSensitive = useSearchStore((state) => state.queryIsCaseSensitive);
25+
const timeRange = useSearchStore((state) => state.timeRange);
2326

2427
/**
2528
* Submits search query.
2629
*/
2730
const handleSubmitButtonClick = useCallback(() => {
2831
// Update timeline to match range picker selection.
2932
const newTimelineConfig = computeTimelineConfig(timeRange);
33+
const {updateTimelineConfig} = useSearchStore.getState();
3034
updateTimelineConfig(newTimelineConfig);
3135

3236
handleQuerySubmit({
33-
ignoreCase: false,
37+
ignoreCase: false === queryIsCaseSensitive,
3438
queryString: queryString,
3539
timeRangeBucketSizeMillis: newTimelineConfig.bucketDuration.asMilliseconds(),
3640
timestampBegin: timeRange[0].valueOf(),
3741
timestampEnd: timeRange[1].valueOf(),
3842
});
3943
}, [queryString,
40-
updateTimelineConfig,
44+
queryIsCaseSensitive,
4145
timeRange]);
4246

4347
const isQueryStringEmpty = queryString === SEARCH_STATE_DEFAULT.queryString;

components/webui/client/src/pages/SearchPage/SearchResults/SearchResultsTimeline/index.tsx

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import {useEffect} from "react";
1+
import {
2+
useCallback,
3+
useEffect,
4+
} from "react";
25

36
import {Card} from "antd";
47
import {Dayjs} from "dayjs";
@@ -19,32 +22,18 @@ import {computeTimelineConfig} from "./utils";
1922
* @return
2023
*/
2124
const SearchResultsTimeline = () => {
22-
const {
23-
queryString,
24-
updateTimeRange,
25-
updateTimeRangeOption,
26-
timelineConfig,
27-
searchUiState,
28-
updateTimelineConfig,
29-
updateNumSearchResultsTimeline,
30-
} = useSearchStore();
25+
const queryIsCaseSensitive = useSearchStore((state) => state.queryIsCaseSensitive);
26+
const queryString = useSearchStore((state) => state.queryString);
27+
const searchUiState = useSearchStore((state) => state.searchUiState);
28+
const timelineConfig = useSearchStore((state) => state.timelineConfig);
3129

3230
const aggregationResults = useAggregationResults();
3331

34-
useEffect(() => {
35-
const numSearchResultsTimeline = aggregationResults?.reduce(
36-
(acc, curr) => acc + curr.count,
37-
0
38-
) ?? 0;
39-
40-
updateNumSearchResultsTimeline(numSearchResultsTimeline);
41-
}, [
42-
aggregationResults,
43-
updateNumSearchResultsTimeline,
44-
]);
45-
46-
const handleTimelineZoom = (newTimeRange: [Dayjs, Dayjs]) => {
32+
const handleTimelineZoom = useCallback((newTimeRange: [Dayjs, Dayjs]) => {
4733
const newTimelineConfig: TimelineConfig = computeTimelineConfig(newTimeRange);
34+
const {
35+
updateTimeRange, updateTimeRangeOption, updateTimelineConfig,
36+
} = useSearchStore.getState();
4837

4938
// Update range picker selection to match zoomed range.
5039
updateTimeRange(newTimeRange);
@@ -57,13 +46,31 @@ const SearchResultsTimeline = () => {
5746
}
5847

5948
handleQuerySubmit({
60-
ignoreCase: false,
49+
ignoreCase: false === queryIsCaseSensitive,
6150
queryString: queryString,
6251
timeRangeBucketSizeMillis: newTimelineConfig.bucketDuration.asMilliseconds(),
6352
timestampBegin: newTimeRange[0].valueOf(),
6453
timestampEnd: newTimeRange[1].valueOf(),
6554
});
66-
};
55+
}, [
56+
queryIsCaseSensitive,
57+
queryString,
58+
]);
59+
60+
useEffect(() => {
61+
const numSearchResultsTimeline = aggregationResults?.reduce(
62+
(acc, curr) => acc + curr.count,
63+
0
64+
) ?? 0;
65+
66+
const {
67+
updateNumSearchResultsTimeline,
68+
} = useSearchStore.getState();
69+
70+
updateNumSearchResultsTimeline(numSearchResultsTimeline);
71+
}, [
72+
aggregationResults,
73+
]);
6774

6875
return (
6976
<Card>

0 commit comments

Comments
 (0)