Skip to content

Commit fadc33a

Browse files
authored
fix(new-webui): Disable case sensitivity toggle while querying. (#988)
1 parent d994430 commit fadc33a

File tree

3 files changed

+106
-60
lines changed

3 files changed

+106
-60
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {useCallback} from "react";
2+
3+
import {
4+
Button,
5+
Tooltip,
6+
Typography,
7+
} from "antd";
8+
9+
10+
interface CaseSensitiveToggleProps {
11+
disabled: boolean;
12+
isCaseSensitive: boolean;
13+
onCaseSensitiveChange: (newValue: boolean) => void;
14+
}
15+
16+
/**
17+
* A toggle button component that switches between case-sensitive and case-insensitive
18+
* modes when clicked.
19+
*
20+
* @param props
21+
* @param props.disabled
22+
* @param props.isCaseSensitive
23+
* @param props.onCaseSensitiveChange
24+
* @return
25+
*/
26+
const CaseSensitiveToggle = ({
27+
disabled,
28+
isCaseSensitive,
29+
onCaseSensitiveChange,
30+
}: CaseSensitiveToggleProps) => {
31+
const handleButtonClick = useCallback(() => {
32+
onCaseSensitiveChange(!isCaseSensitive);
33+
}, [
34+
isCaseSensitive,
35+
onCaseSensitiveChange,
36+
]);
37+
38+
return (
39+
<Tooltip
40+
title={"Match case"}
41+
>
42+
<Button
43+
color={"default"}
44+
disabled={disabled}
45+
size={"small"}
46+
icon={
47+
<Typography.Text disabled={disabled}>
48+
Aa
49+
</Typography.Text>
50+
}
51+
variant={isCaseSensitive ?
52+
"outlined" :
53+
"text"}
54+
onClick={handleButtonClick}/>
55+
</Tooltip>
56+
);
57+
};
58+
59+
60+
export type {CaseSensitiveToggleProps};
61+
export default CaseSensitiveToggle;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
Input,
3+
InputProps,
4+
} from "antd";
5+
6+
import CaseSensitiveToggle, {CaseSensitiveToggleProps} from "./CaseSenstiveToggle";
7+
8+
9+
/**
10+
* Antd Input props and case sensitive toggle props with suffix omitted since set by component.
11+
*/
12+
type InputWithCaseSensitiveProps = Omit<InputProps, "suffix"> & CaseSensitiveToggleProps;
13+
14+
/**
15+
* Antd Input with a built-in case sensitivity toggle.
16+
*
17+
* @param props
18+
* @param props.isCaseSensitive
19+
* @param props.onCaseSensitiveChange
20+
* @param props.inputProps
21+
* @return
22+
*/
23+
const InputWithCaseSensitive = ({
24+
isCaseSensitive,
25+
onCaseSensitiveChange,
26+
...inputProps
27+
}: InputWithCaseSensitiveProps) => {
28+
return (
29+
<Input
30+
{...inputProps}
31+
suffix={
32+
<CaseSensitiveToggle
33+
disabled={inputProps.disabled}
34+
isCaseSensitive={isCaseSensitive}
35+
onCaseSensitiveChange={onCaseSensitiveChange}/>
36+
}/>
37+
);
38+
};
39+
40+
export type {InputWithCaseSensitiveProps};
41+
export default InputWithCaseSensitive;

components/log-viewer-webui/client/src/components/QueryBox/index.tsx

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,36 @@
1-
import {useCallback} from "react";
2-
31
import {
4-
Button,
5-
Input,
6-
InputProps,
72
Progress,
83
theme,
9-
Tooltip,
10-
Typography,
114
} from "antd";
125
import {Nullable} from "src/typings/common";
136

147
import styles from "./index.module.css";
8+
import InputWithCaseSensitive, {InputWithCaseSensitiveProps} from "./InputWithCaseSensitive";
159

1610

17-
interface CaseSensitiveToggleProps {
18-
isCaseSensitive: boolean;
19-
onCaseSensitiveChange: (newValue: boolean) => void;
20-
}
21-
22-
/**
23-
* A toggle button component that switches between case-sensitive and case-insensitive modes.
24-
*
25-
* This component displays a button labeled "Aa". When clicked, it toggles the `isCaseSensitive`
26-
* state and invokes the `onCaseSensitiveChange` callback with the new value.
27-
*
28-
* @param props
29-
* @param props.isCaseSensitive
30-
* @param props.onCaseSensitiveChange
31-
* @return
32-
*/
33-
const CaseSensitiveToggle = ({
34-
isCaseSensitive,
35-
onCaseSensitiveChange,
36-
}: CaseSensitiveToggleProps) => {
37-
const handleButtonClick = useCallback(() => {
38-
onCaseSensitiveChange(!isCaseSensitive);
39-
}, [
40-
isCaseSensitive,
41-
onCaseSensitiveChange,
42-
]);
43-
44-
return (
45-
<Tooltip title={"Match case"}>
46-
<Button
47-
color={"default"}
48-
icon={<Typography.Text disabled={!isCaseSensitive}>Aa</Typography.Text>}
49-
size={"small"}
50-
variant={isCaseSensitive ?
51-
"filled" :
52-
"text"}
53-
onClick={handleButtonClick}/>
54-
</Tooltip>
55-
);
56-
};
57-
58-
59-
interface QueryBoxProps extends InputProps, CaseSensitiveToggleProps {
11+
interface QueryBoxProps extends InputWithCaseSensitiveProps {
6012
/**
6113
* The progress of the progress bar from `0` to `100`. Hides the bar if `null`.
6214
*/
6315
progress: Nullable<number>;
6416
}
6517

6618
/**
67-
* Renders an Input with a progress bar.
19+
* Renders an Input with a case sensitivity toggle and progress bar.
6820
*
6921
* @param props
7022
* @param props.progress
7123
* @param props.inputProps
72-
* @param props.onCaseSensitiveChange
73-
* @param props.isCaseSensitive
7424
* @return
7525
*/
7626
const QueryBox = ({
7727
progress,
78-
isCaseSensitive,
79-
onCaseSensitiveChange,
8028
...inputProps
8129
}: QueryBoxProps) => {
8230
const {token} = theme.useToken();
8331
return (
8432
<div className={styles["queryBox"]}>
85-
<Input
86-
{...inputProps}
87-
suffix={<CaseSensitiveToggle
88-
isCaseSensitive={isCaseSensitive}
89-
onCaseSensitiveChange={onCaseSensitiveChange}/>}/>
33+
<InputWithCaseSensitive {...inputProps}/>
9034
<div
9135
className={styles["progressBarMask"]}
9236
style={{borderRadius: token.borderRadiusLG}}

0 commit comments

Comments
 (0)