mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-11 23:59:00 +08:00
feat: added blur event to having input in query section (#5684)
* feat: added blur event to having input in query section * feat: added a error message for incomplete having clause and improved handleBlur * feat: added focus event to remove error message --------- Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
parent
fc8391c5aa
commit
6e3141a4ce
@ -1,3 +1,4 @@
|
|||||||
|
import { Color } from '@signozhq/design-tokens';
|
||||||
import { Select } from 'antd';
|
import { Select } from 'antd';
|
||||||
import { ENTITY_VERSION_V4 } from 'constants/app';
|
import { ENTITY_VERSION_V4 } from 'constants/app';
|
||||||
// ** Constants
|
// ** Constants
|
||||||
@ -34,6 +35,7 @@ export function HavingFilter({
|
|||||||
const [currentFormValue, setCurrentFormValue] = useState<HavingForm>(
|
const [currentFormValue, setCurrentFormValue] = useState<HavingForm>(
|
||||||
initialHavingValues,
|
initialHavingValues,
|
||||||
);
|
);
|
||||||
|
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
const { isMulti } = useTagValidation(
|
const { isMulti } = useTagValidation(
|
||||||
currentFormValue.op,
|
currentFormValue.op,
|
||||||
@ -198,6 +200,29 @@ export function HavingFilter({
|
|||||||
resetChanges();
|
resetChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFocus = useCallback(() => {
|
||||||
|
setErrorMessage(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleBlur = useCallback((): void => {
|
||||||
|
if (searchText) {
|
||||||
|
const { columnName, op, value } = getHavingObject(searchText);
|
||||||
|
const isCompleteHavingClause =
|
||||||
|
columnName && op && value.every((v) => v !== '');
|
||||||
|
|
||||||
|
if (isCompleteHavingClause && isValidHavingValue(searchText)) {
|
||||||
|
setLocalValues((prev) => {
|
||||||
|
const updatedValues = [...prev, searchText];
|
||||||
|
onChange(updatedValues.map(transformFromStringToHaving));
|
||||||
|
return updatedValues;
|
||||||
|
});
|
||||||
|
setSearchText('');
|
||||||
|
} else {
|
||||||
|
setErrorMessage('Invalid HAVING clause');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [searchText, onChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
parseSearchText(searchText);
|
parseSearchText(searchText);
|
||||||
}, [searchText, parseSearchText]);
|
}, [searchText, parseSearchText]);
|
||||||
@ -209,6 +234,7 @@ export function HavingFilter({
|
|||||||
const isMetricsDataSource = query.dataSource === DataSource.METRICS;
|
const isMetricsDataSource = query.dataSource === DataSource.METRICS;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Select
|
<Select
|
||||||
getPopupContainer={popupContainer}
|
getPopupContainer={popupContainer}
|
||||||
autoClearSearchValue={false}
|
autoClearSearchValue={false}
|
||||||
@ -225,6 +251,9 @@ export function HavingFilter({
|
|||||||
onDeselect={handleDeselect}
|
onDeselect={handleDeselect}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
status={errorMessage ? 'error' : undefined}
|
||||||
>
|
>
|
||||||
{options.map((opt) => (
|
{options.map((opt) => (
|
||||||
<Select.Option key={opt.value} value={opt.value} title="havingOption">
|
<Select.Option key={opt.value} value={opt.value} title="havingOption">
|
||||||
@ -232,5 +261,9 @@ export function HavingFilter({
|
|||||||
</Select.Option>
|
</Select.Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
{errorMessage && (
|
||||||
|
<div style={{ color: Color.BG_CHERRY_500 }}>{errorMessage}</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user