From 32c7669b28148c04e1611ce30c840a91f4a36a27 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:45:42 -0500 Subject: [PATCH] Search UI tweaks (#13965) * Prevent keyboard shortcuts from running when input is focused * fix reset button and update time pickers when using input * simplify css * consistent button order and spacing --- .../components/filter/SearchFilterGroup.tsx | 26 +++++++-------- web/src/components/input/InputWithTags.tsx | 32 +++++++++++-------- web/src/components/ui/calendar-range.tsx | 22 ++++++------- web/src/hooks/use-keyboard-listener.tsx | 5 +-- web/src/views/search/SearchView.tsx | 14 ++++++-- 5 files changed, 56 insertions(+), 43 deletions(-) diff --git a/web/src/components/filter/SearchFilterGroup.tsx b/web/src/components/filter/SearchFilterGroup.tsx index 54618aefc..09d38c442 100644 --- a/web/src/components/filter/SearchFilterGroup.tsx +++ b/web/src/components/filter/SearchFilterGroup.tsx @@ -430,6 +430,13 @@ function TimeRangeFilterButton({ const formattedSelectedAfter = useFormattedHour(config, selectedAfterHour); const formattedSelectedBefore = useFormattedHour(config, selectedBeforeHour); + useEffect(() => { + setSelectedAfterHour(afterHour); + setSelectedBeforeHour(beforeHour); + // only refresh when state changes + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [timeRange]); + const trigger = ( - + - +
)} -
- +
+
); diff --git a/web/src/hooks/use-keyboard-listener.tsx b/web/src/hooks/use-keyboard-listener.tsx index ad9462a05..ad776b303 100644 --- a/web/src/hooks/use-keyboard-listener.tsx +++ b/web/src/hooks/use-keyboard-listener.tsx @@ -10,6 +10,7 @@ export type KeyModifiers = { export default function useKeyboardListener( keys: string[], listener: (key: string | null, modifiers: KeyModifiers) => void, + preventDefault: boolean = true, ) { const keyDownListener = useCallback( (e: KeyboardEvent) => { @@ -25,13 +26,13 @@ export default function useKeyboardListener( }; if (keys.includes(e.key)) { - e.preventDefault(); + if (preventDefault) e.preventDefault(); listener(e.key, modifiers); } else if (e.key === "Shift" || e.key === "Control" || e.key === "Meta") { listener(null, modifiers); } }, - [keys, listener], + [keys, listener, preventDefault], ); const keyUpListener = useCallback( diff --git a/web/src/views/search/SearchView.tsx b/web/src/views/search/SearchView.tsx index 28f9ed579..3677612c7 100644 --- a/web/src/views/search/SearchView.tsx +++ b/web/src/views/search/SearchView.tsx @@ -209,9 +209,11 @@ export default function SearchView({ // keyboard listener + const [inputFocused, setInputFocused] = useState(false); + const onKeyboardShortcut = useCallback( (key: string | null, modifiers: KeyModifiers) => { - if (!modifiers.down || !uniqueResults) { + if (!modifiers.down || !uniqueResults || inputFocused) { return; } @@ -236,10 +238,14 @@ export default function SearchView({ break; } }, - [uniqueResults], + [uniqueResults, inputFocused], ); - useKeyboardListener(["ArrowLeft", "ArrowRight"], onKeyboardShortcut); + useKeyboardListener( + ["ArrowLeft", "ArrowRight"], + onKeyboardShortcut, + !inputFocused, + ); // scroll into view @@ -310,6 +316,8 @@ export default function SearchView({ {config?.semantic_search?.enabled && (