Repository navigation
feat: open saved searches with a saved default time range #3593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ab81696
437ab94
3a4b8b1
cc804aa
1a26463
d8d2de0
80fb4ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@hyperdx/api': minor | ||
| '@hyperdx/app': minor | ||
| '@hyperdx/common-utils': minor | ||
| --- | ||
|
|
||
| feat: saved searches remember the selected time range (e.g. past 1 day or a live tail interval) and open with it instead of live tail |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,11 @@ import { recordAction } from '@/utils/browserTelemetry'; | |
| import ChartSQLPreview, { SQLPreview } from './components/ChartSQLPreview'; | ||
| import DBSqlRowTableWithSideBar from './components/DBSqlRowTableWithSidebar'; | ||
| import PatternTable from './components/PatternTable'; | ||
| import { getSavedSearchLanding } from './components/SavedSearches/savedSearchTimeRange'; | ||
| import { | ||
| SaveTimeRangeField, | ||
| useSaveTimeRangeField, | ||
| } from './components/SavedSearches/SaveTimeRangeField'; | ||
| import { DBSearchHeatmapChart } from './components/Search/DBSearchHeatmapChart'; | ||
| import DirectTraceSidePanel from './components/Search/DirectTraceSidePanel'; | ||
| import { | ||
|
|
@@ -490,13 +495,21 @@ function SaveSearchModalComponent({ | |
| onCreate, | ||
| isUpdate, | ||
| savedSearchId, | ||
| isLive, | ||
| liveIntervalMs, | ||
| searchedTimeRange, | ||
| openedAtMs, | ||
| }: { | ||
| searchedConfig: SearchConfig; | ||
| opened: boolean; | ||
| onClose: () => void; | ||
| onCreate: (savedSearchId: string) => Promise<void>; | ||
| isUpdate: boolean; | ||
| savedSearchId: string | undefined | null; | ||
| isLive: boolean; | ||
| liveIntervalMs: number; | ||
| searchedTimeRange: [Date, Date]; | ||
| openedAtMs: number | null; | ||
| }) { | ||
| const { data: savedSearch } = useSavedSearch( | ||
| { id: savedSearchId ?? '' }, | ||
|
|
@@ -505,6 +518,15 @@ function SaveSearchModalComponent({ | |
| }, | ||
| ); | ||
|
|
||
| const timeRangeOutcome = useSaveTimeRangeField({ | ||
| openedAtMs, | ||
| isLive, | ||
| liveIntervalMs, | ||
| searchedTimeRange, | ||
| isUpdate, | ||
| stored: savedSearch?.defaultTimeRange, | ||
| }); | ||
|
|
||
| const { | ||
| control, | ||
| handleSubmit, | ||
|
|
@@ -553,6 +575,9 @@ function SaveSearchModalComponent({ | |
| e.preventDefault(); | ||
|
|
||
| handleSubmit(async ({ name }) => { | ||
| const timeRange = timeRangeOutcome.value; | ||
| const defaultTimeRangeUpdate = | ||
| timeRange === undefined ? {} : { defaultTimeRange: timeRange }; | ||
| if (isUpdate) { | ||
| if (savedSearchId == null) { | ||
| throw new Error('savedSearchId is required for update'); | ||
|
|
@@ -570,6 +595,7 @@ function SaveSearchModalComponent({ | |
| orderBy: searchedConfig.orderBy ?? '', | ||
| filters: searchedConfig.filters ?? [], | ||
| tags: tags, | ||
| ...defaultTimeRangeUpdate, | ||
| }, | ||
| { | ||
| onSuccess: () => { | ||
|
|
@@ -598,6 +624,7 @@ function SaveSearchModalComponent({ | |
| orderBy: searchedConfig.orderBy ?? '', | ||
| filters: searchedConfig.filters ?? [], | ||
| tags: tags, | ||
| ...defaultTimeRangeUpdate, | ||
| }); | ||
|
|
||
| await onCreate(savedSearch.id); | ||
|
|
@@ -726,6 +753,10 @@ function SaveSearchModalComponent({ | |
| </Tags> | ||
| </Group> | ||
| </Box> | ||
| <SaveTimeRangeField | ||
| opensWith={timeRangeOutcome.opensWith} | ||
| customRangeIgnored={timeRangeOutcome.customRangeIgnored} | ||
| /> | ||
| <Button | ||
| data-testid="save-search-submit-button" | ||
| variant="primary" | ||
|
|
@@ -1162,6 +1193,10 @@ function DBSearchPageContent() { | |
| 'isLive', | ||
| parseAsBoolean.withDefault(true), | ||
| ); | ||
| const [interval, setInterval] = useQueryState( | ||
| 'liveInterval', | ||
| parseAsInteger.withDefault(LIVE_TAIL_DURATION_MS), | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (analysisMode === 'delta' || analysisMode === 'pattern') { | ||
|
|
@@ -1361,6 +1396,28 @@ function DBSearchPageContent() { | |
| savedSearch.id === savedSearchId && // Make sure we've loaded the correct saved search | ||
| isSearchConfigEmpty // Only populate if URL doesn't have explicit config | ||
| ) { | ||
| const nowMs = performance.timeOrigin + performance.now(); | ||
| const landing = getSavedSearchLanding( | ||
| savedSearch.defaultTimeRange, | ||
| window.location.search, | ||
| nowMs, | ||
| ); | ||
| // Replace, not push: a pushed entry would leave the bare URL behind, | ||
| // and Back would land on it and re-apply the range forever. | ||
| if (landing?.kind === 'live') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — The live-tail landing branch re-implements This branch copies the writes from Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| // Same writes as picking a live tail range in the time picker. | ||
| const [start, end] = parseRelativeTimeQuery(landing.intervalMs, nowMs); | ||
| setIsLive(true, { history: 'replace' }); | ||
| setInterval(landing.intervalMs, { history: 'replace' }); | ||
| onTimeRangeSelect(start, end, null, { history: 'replace' }); | ||
| const label = getRelativeTimeOptionLabel(landing.intervalMs); | ||
| if (label) setDisplayedTimeInputValue(label); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Live-tail landing sets the input label without updating the applied value Call Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| } else if (landing?.kind === 'window') { | ||
| setIsLive(false, { history: 'replace' }); | ||
| onTimeRangeSelect(landing.range[0], landing.range[1], undefined, { | ||
| history: 'replace', | ||
| }); | ||
| } | ||
| setSearchedConfig({ | ||
| source: savedSearch.source, | ||
| where: savedSearch.where, | ||
|
|
@@ -1397,6 +1454,9 @@ function DBSearchPageContent() { | |
| defaultSourceId, | ||
| directTraceId, | ||
| sources, | ||
| setIsLive, | ||
| setInterval, | ||
| onTimeRangeSelect, | ||
| ]); | ||
|
|
||
| const [_queryErrors, setQueryErrors] = useState<{ | ||
|
|
@@ -1725,9 +1785,19 @@ function DBSearchPageContent() { | |
| }, [setIsLive]); | ||
|
|
||
| const [modelFormExpanded, setModelFormExpanded] = useState(false); // Used in local mode | ||
| // openedAtMs is read in the click handler: the modal compares it with the | ||
| // searched window to decide whether that window reads as "the past N". | ||
| const [saveSearchModalState, setSaveSearchModalState] = useState< | ||
| 'create' | 'update' | undefined | ||
| { mode: 'create' | 'update'; openedAtMs: number } | undefined | ||
| >(undefined); | ||
| const openSaveSearchModal = useCallback( | ||
| (mode: 'create' | 'update') => | ||
| setSaveSearchModalState({ | ||
| mode, | ||
| openedAtMs: performance.timeOrigin + performance.now(), | ||
| }), | ||
| [], | ||
| ); | ||
| const chartSearchConfig = useMemo( | ||
| () => ({ | ||
| select: searchedConfig.select ?? '', | ||
|
|
@@ -1776,7 +1846,7 @@ function DBSearchPageContent() { | |
| const deleteSavedSearch = useDeleteSavedSearch(); | ||
| const onSaveSearch = useCallback(() => { | ||
| if (savedSearch == null) { | ||
| setSaveSearchModalState('create'); | ||
| openSaveSearchModal('create'); | ||
| } else { | ||
| handleSubmit(s => { | ||
| updateSavedSearch.mutate( | ||
|
|
@@ -1793,7 +1863,13 @@ function DBSearchPageContent() { | |
| ); | ||
| })(); | ||
| } | ||
| }, [savedSearch, updateSavedSearch, onSubmit, handleSubmit]); | ||
| }, [ | ||
| savedSearch, | ||
| updateSavedSearch, | ||
| onSubmit, | ||
| handleSubmit, | ||
| openSaveSearchModal, | ||
| ]); | ||
|
|
||
| const handleUpdateTags = useCallback( | ||
| (newTags: string[]) => { | ||
|
|
@@ -1863,11 +1939,6 @@ function DBSearchPageContent() { | |
| // State for collapsing all expanded rows when resuming live tail | ||
| const [collapseAllRows, setCollapseAllRows] = useState(false); | ||
|
|
||
| const [interval, setInterval] = useQueryState( | ||
| 'liveInterval', | ||
| parseAsInteger.withDefault(LIVE_TAIL_DURATION_MS), | ||
| ); | ||
|
|
||
| const [refreshFrequency, setRefreshFrequency] = useQueryState( | ||
| 'refreshFrequency', | ||
| parseAsInteger.withDefault(DEFAULT_REFRESH_FREQUENCY), | ||
|
|
@@ -2692,7 +2763,7 @@ function DBSearchPageContent() { | |
| }); | ||
| }} | ||
| onClickSaveAsNew={() => { | ||
| setSaveSearchModalState('create'); | ||
| openSaveSearchModal('create'); | ||
| }} | ||
| /> | ||
| </Group> | ||
|
|
@@ -2753,7 +2824,7 @@ function DBSearchPageContent() { | |
| variant="secondary" | ||
| size="xs" | ||
| onClick={() => { | ||
| setSaveSearchModalState('update'); | ||
| openSaveSearchModal('update'); | ||
| }} | ||
| style={{ flexShrink: 0 }} | ||
| > | ||
|
|
@@ -2880,8 +2951,12 @@ function DBSearchPageContent() { | |
| onClose={clearSaveSearchModalState} | ||
| onCreate={onSavedSearchCreated} | ||
| searchedConfig={searchedConfig} | ||
| isUpdate={saveSearchModalState === 'update'} | ||
| isUpdate={saveSearchModalState?.mode === 'update'} | ||
| savedSearchId={savedSearchId} | ||
| isLive={isLive} | ||
| liveIntervalMs={interval} | ||
| searchedTimeRange={searchedTimeRange} | ||
| openedAtMs={saveSearchModalState?.openedAtMs ?? null} | ||
| /> | ||
| )} | ||
| <DirectTraceSidePanel | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 minor —
performance.timeOrigin + performance.now()is used to get around theDate.now()lint ruleHere and in
openSaveSearchModal, both inside an effect/callback, which the rule's message says is fine. UseDate.now()with// eslint-disable-next-line no-restricted-syntax, asparseRelativeTimeQueryintimeQuery.tsalready does, so the intent stays obvious.Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond