Skip to content

Commit

Permalink
chore: fix filter editing issue in infra monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
amlannandy committed Jan 29, 2025
1 parent 88084af commit 354d82f
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function QueryBuilderSearch({
[pathname],
);

const [isEditingTag, setIsEditingTag] = useState(false);

const {
updateTag,
handleClearTag,
Expand Down Expand Up @@ -133,6 +135,16 @@ function QueryBuilderSearch({

const { handleRunQuery, currentQuery } = useQueryBuilder();

const toggleEditMode = useCallback(
(value: boolean) => {
// Editing mode is required only in infra monitoring mode
if (isInfraMonitoring) {
setIsEditingTag(value);
}
},
[isInfraMonitoring],
);

const onTagRender = ({
value,
closable,
Expand All @@ -146,12 +158,16 @@ function QueryBuilderSearch({

const onCloseHandler = (): void => {
onClose();
// Editing is done after closing a tag
toggleEditMode(false);
handleSearch('');
setSearchKey('');
};

const tagEditHandler = (value: string): void => {
updateTag(value);
// Editing starts
toggleEditMode(true);
if (isInfraMonitoring) {
setSearchValue(value);
} else {
Expand Down Expand Up @@ -188,6 +204,11 @@ function QueryBuilderSearch({
if (isMulti || event.key === 'Backspace') handleKeyDown(event);
if (isExistsNotExistsOperator(searchValue)) handleKeyDown(event);

// Editing is done after enter key press
if (event.key === 'Enter') {
toggleEditMode(false);
}

if (
!disableNavigationShortcuts &&
(event.ctrlKey || event.metaKey) &&
Expand Down Expand Up @@ -270,7 +291,14 @@ function QueryBuilderSearch({
};
});

onChange(initialTagFilters);
// If in infra monitoring, only run the onChange query when editing is finsished.
if (isInfraMonitoring) {
if (!isEditingTag) {
onChange(initialTagFilters);
}
} else {
onChange(initialTagFilters);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [sourceKeys]);

Expand Down Expand Up @@ -367,7 +395,11 @@ function QueryBuilderSearch({
)
}
showAction={['focus']}
onBlur={handleOnBlur}
onBlur={(e: React.FocusEvent<HTMLInputElement>): void => {
handleOnBlur(e);
// Editing is done after tapping out of the input
toggleEditMode(false);
}}
popupClassName={isLogsExplorerPage ? 'logs-explorer-popup' : ''}
dropdownRender={(menu): ReactElement => (
<div>
Expand Down

0 comments on commit 354d82f

Please sign in to comment.