mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
feat: Save last source as default source on search page load (#790)
fixes HDX-1680
This commit is contained in:
parent
5254a6f555
commit
6dc6989fdc
2 changed files with 30 additions and 3 deletions
5
.changeset/happy-hornets-join.md
Normal file
5
.changeset/happy-hornets-join.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@hyperdx/app": patch
|
||||
---
|
||||
|
||||
feat: Automatically use last used source when loading search page
|
||||
|
|
@ -92,7 +92,7 @@ import {
|
|||
useSources,
|
||||
} from '@/source';
|
||||
import { parseTimeQuery, useNewTimeQuery } from '@/timeQuery';
|
||||
import { QUERY_LOCAL_STORAGE, usePrevious } from '@/utils';
|
||||
import { QUERY_LOCAL_STORAGE, useLocalStorage, usePrevious } from '@/utils';
|
||||
|
||||
import { SQLPreview } from './components/ChartSQLPreview';
|
||||
import PatternTable from './components/PatternTable';
|
||||
|
|
@ -472,6 +472,10 @@ function DBSearchPage() {
|
|||
);
|
||||
|
||||
const { data: sources } = useSources();
|
||||
const [lastSelectedSourceId, setLastSelectedSourceId] = useLocalStorage(
|
||||
'hdx-last-selected-source-id',
|
||||
'',
|
||||
);
|
||||
const { data: searchedSource } = useSource({
|
||||
id: searchedConfig.source,
|
||||
});
|
||||
|
|
@ -514,7 +518,13 @@ function DBSearchPage() {
|
|||
select: searchedConfig.select || '',
|
||||
where: searchedConfig.where || '',
|
||||
whereLanguage: searchedConfig.whereLanguage ?? 'lucene',
|
||||
source: searchedConfig.source ?? sources?.[0]?.id ?? '',
|
||||
source:
|
||||
searchedConfig.source ??
|
||||
(lastSelectedSourceId &&
|
||||
sources?.some(s => s.id === lastSelectedSourceId)
|
||||
? lastSelectedSourceId
|
||||
: sources?.[0]?.id) ??
|
||||
'',
|
||||
filters: searchedConfig.filters ?? [],
|
||||
orderBy: searchedConfig.orderBy ?? '',
|
||||
},
|
||||
|
|
@ -623,6 +633,8 @@ function DBSearchPage() {
|
|||
setSearchedConfig,
|
||||
savedSearchId,
|
||||
inputSource,
|
||||
lastSelectedSourceId,
|
||||
sources,
|
||||
]);
|
||||
|
||||
const [_queryErrors, setQueryErrors] = useState<{
|
||||
|
|
@ -676,6 +688,9 @@ function DBSearchPage() {
|
|||
s => s.id === data.source,
|
||||
);
|
||||
if (newInputSourceObj != null) {
|
||||
// Save the selected source ID to localStorage
|
||||
setLastSelectedSourceId(newInputSourceObj.id);
|
||||
|
||||
setValue(
|
||||
'select',
|
||||
newInputSourceObj?.defaultTableSelectExpression ?? '',
|
||||
|
|
@ -692,7 +707,14 @@ function DBSearchPage() {
|
|||
}
|
||||
});
|
||||
return () => unsubscribe();
|
||||
}, [watch, inputSourceObj, setValue, inputSourceObjs, searchFilters]);
|
||||
}, [
|
||||
watch,
|
||||
inputSourceObj,
|
||||
setValue,
|
||||
inputSourceObjs,
|
||||
searchFilters,
|
||||
setLastSelectedSourceId,
|
||||
]);
|
||||
|
||||
const onTableScroll = useCallback(
|
||||
(scrollTop: number) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue