Skip to content

Commit 0cf2105

Browse files
Zylphrexandrewshie-sentry
authored andcommitted
feat(logs): Use query params for logs fields (#98860)
This uses query params to set logs fields.
1 parent 7a1a70f commit 0cf2105

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

static/app/views/explore/contexts/logs/logsPageParams.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,20 +393,6 @@ export function useLogsProjectIds() {
393393
return projectIds;
394394
}
395395

396-
export function useSetLogsFields() {
397-
const setPageParams = useSetLogsPageParams();
398-
399-
const [_, setPersistentParams] = usePersistedLogsPageParams();
400-
401-
return useCallback(
402-
(fields: string[]) => {
403-
setPageParams({fields});
404-
setPersistentParams(prev => ({...prev, fields}));
405-
},
406-
[setPageParams, setPersistentParams]
407-
);
408-
}
409-
410396
export function useSetLogsSavedQueryInfo() {
411397
const setPageParams = useSetLogsPageParams();
412398
return useCallback(

static/app/views/explore/logs/logsLocationQueryParamsProvider.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type {ReactNode} from 'react';
22
import {useCallback, useMemo} from 'react';
33

4+
import {defined} from 'sentry/utils';
45
import {useLocation} from 'sentry/utils/useLocation';
56
import {useNavigate} from 'sentry/utils/useNavigate';
7+
import {usePersistedLogsPageParams} from 'sentry/views/explore/contexts/logs/logsPageParams';
68
import {
79
getReadableQueryParamsFromLocation,
810
getTargetWithReadableQueryParams,
@@ -21,17 +23,27 @@ export function LogsLocationQueryParamsProvider({
2123
const location = useLocation();
2224
const navigate = useNavigate();
2325

26+
const [_, setPersistentParams] = usePersistedLogsPageParams();
27+
2428
const readableQueryParams = useMemo(
2529
() => getReadableQueryParamsFromLocation(location),
2630
[location]
2731
);
2832

2933
const setWritableQueryParams = useCallback(
3034
(writableQueryParams: WritableQueryParams) => {
35+
const fields = writableQueryParams.fields;
36+
if (defined(fields)) {
37+
setPersistentParams(prev => ({
38+
...prev,
39+
fields,
40+
}));
41+
}
42+
3143
const target = getTargetWithReadableQueryParams(location, writableQueryParams);
3244
navigate(target);
3345
},
34-
[location, navigate]
46+
[location, navigate, setPersistentParams]
3547
);
3648

3749
const isUsingDefaultFields = isDefaultFields(location);

static/app/views/explore/logs/logsQueryParams.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ export function getTargetWithReadableQueryParams(
8585
): Location {
8686
const target: Location = {...location, query: {...location.query}};
8787

88-
updateNullableLocation(target, LOGS_CURSOR_KEY, writableQueryParams.cursor);
8988
updateNullableLocation(target, LOGS_MODE_KEY, writableQueryParams.mode);
89+
90+
updateNullableLocation(target, LOGS_CURSOR_KEY, writableQueryParams.cursor);
91+
updateNullableLocation(target, LOGS_FIELDS_KEY, writableQueryParams.fields);
92+
9093
updateNullableLocation(
9194
target,
9295
LOGS_AGGREGATE_CURSOR_KEY,

static/app/views/explore/logs/logsTab.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ import {TraceItemSearchQueryBuilder} from 'sentry/views/explore/components/trace
2626
import {defaultLogFields} from 'sentry/views/explore/contexts/logs/fields';
2727
import {useLogsAutoRefreshEnabled} from 'sentry/views/explore/contexts/logs/logsAutoRefreshContext';
2828
import {useLogsPageDataQueryResult} from 'sentry/views/explore/contexts/logs/logsPageData';
29-
import {
30-
useLogsSearch,
31-
useSetLogsFields,
32-
} from 'sentry/views/explore/contexts/logs/logsPageParams';
29+
import {useLogsSearch} from 'sentry/views/explore/contexts/logs/logsPageParams';
3330
import {Mode} from 'sentry/views/explore/contexts/pageParamsContext/mode';
3431
import {formatSort} from 'sentry/views/explore/contexts/pageParamsContext/sortBys';
3532
import {useTraceItemAttributes} from 'sentry/views/explore/contexts/traceItemAttributeContext';
@@ -82,6 +79,7 @@ import {
8279
useQueryParamsSortBys,
8380
useQueryParamsTopEventsLimit,
8481
useQueryParamsVisualizes,
82+
useSetQueryParamsFields,
8583
useSetQueryParamsMode,
8684
} from 'sentry/views/explore/queryParams/context';
8785
import {ColumnEditorModal} from 'sentry/views/explore/tables/columnEditorModal';
@@ -108,7 +106,7 @@ export function LogsTabContent({
108106
const sortBys = useQueryParamsSortBys();
109107
const aggregateSortBys = useQueryParamsAggregateSortBys();
110108
const setMode = useSetQueryParamsMode();
111-
const setFields = useSetLogsFields();
109+
const setFields = useSetQueryParamsFields();
112110
const tableData = useLogsPageDataQueryResult();
113111
const autorefreshEnabled = useLogsAutoRefreshEnabled();
114112
const [timeseriesIngestDelay, setTimeseriesIngestDelay] = useState<bigint>(

static/app/views/explore/logs/useLogAttributesTreeActions.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import {t} from 'sentry/locale';
55
import type {AttributesTreeContent} from 'sentry/views/explore/components/traceItemAttributes/attributesTree';
66
import {
77
useLogsSearch,
8-
useSetLogsFields,
98
useSetLogsSearch,
109
} from 'sentry/views/explore/contexts/logs/logsPageParams';
1110
import {OurLogKnownFieldKey} from 'sentry/views/explore/logs/types';
12-
import {useQueryParamsFields} from 'sentry/views/explore/queryParams/context';
11+
import {
12+
useQueryParamsFields,
13+
useSetQueryParamsFields,
14+
} from 'sentry/views/explore/queryParams/context';
1315

1416
export function useLogAttributesTreeActions({embedded}: {embedded: boolean}) {
1517
const setLogsSearch = useSetLogsSearch();
1618
const search = useLogsSearch();
1719
const fields = useQueryParamsFields();
18-
const setLogFields = useSetLogsFields();
20+
const setLogFields = useSetQueryParamsFields();
1921

2022
const addSearchFilter = useCallback(
2123
(content: AttributesTreeContent, negated?: boolean) => {

static/app/views/explore/queryParams/context.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ export function useQueryParamsFields(): readonly string[] {
145145
return queryParams.fields;
146146
}
147147

148+
export function useSetQueryParamsFields() {
149+
const setQueryParams = useSetQueryParams();
150+
151+
return useCallback(
152+
(fields: string[]) => {
153+
setQueryParams({fields});
154+
},
155+
[setQueryParams]
156+
);
157+
}
158+
148159
export function useQueryParamsSortBys(): readonly Sort[] {
149160
const queryParams = useQueryParams();
150161
return queryParams.sortBys;

0 commit comments

Comments
 (0)