Skip to content

Commit a16957e

Browse files
Zylphrexlzhao-sentry
authored andcommitted
feat(explore): Persist explore toolbar state with local storage (#97952)
We want the open/closed state of the toolbar to persist across sessions. Closes EXP-443
1 parent 9c794c4 commit a16957e

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {parsePeriodToHours} from 'sentry/utils/duration/parsePeriodToHours';
1919
import {AggregationKey} from 'sentry/utils/fields';
2020
import {HOUR} from 'sentry/utils/formatters';
2121
import {useQueryClient, type InfiniteData} from 'sentry/utils/queryClient';
22+
import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
2223
import useOrganization from 'sentry/utils/useOrganization';
2324
import usePageFilters from 'sentry/utils/usePageFilters';
2425
import SchemaHintsList, {
@@ -131,7 +132,7 @@ export function LogsTabContent({
131132
return sortBys.map(formatSort);
132133
}, [sortBys]);
133134

134-
const [sidebarOpen, setSidebarOpen] = useState(
135+
const [sidebarOpen, setSidebarOpen] = useSidebarOpen(
135136
!!(
136137
groupBys.some(Boolean) ||
137138
visualizes.some(
@@ -256,7 +257,7 @@ export function LogsTabContent({
256257
setMode(Mode.SAMPLES);
257258
}
258259
},
259-
[setMode]
260+
[setSidebarOpen, setMode]
260261
);
261262

262263
const saveAsItems = useSaveAsItems({
@@ -360,7 +361,7 @@ export function LogsTabContent({
360361
size="xs"
361362
/>
362363
}
363-
onClick={() => setSidebarOpen(x => !x)}
364+
onClick={() => setSidebarOpen(!sidebarOpen)}
364365
/>
365366
</Feature>
366367
<LogsGraphContainer>
@@ -424,3 +425,18 @@ export function LogsTabContent({
424425
</SearchQueryBuilderProvider>
425426
);
426427
}
428+
429+
function useSidebarOpen(defaultExpanded: boolean) {
430+
const [sidebarOpen, _setSidebarOpen] = useLocalStorageState(
431+
'explore-logs-toolbar',
432+
defaultExpanded ? 'expanded' : ''
433+
);
434+
435+
const setSidebarOpen = useCallback(
436+
(expanded: boolean) => {
437+
_setSidebarOpen(expanded ? 'expanded' : '');
438+
},
439+
[_setSidebarOpen]
440+
);
441+
return [sidebarOpen === 'expanded', setSidebarOpen] as const;
442+
}

static/app/views/explore/spans/spansTab.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ import {
3131
ALLOWED_EXPLORE_VISUALIZE_AGGREGATES,
3232
type AggregationKey,
3333
} from 'sentry/utils/fields';
34-
import {decodeScalar} from 'sentry/utils/queryString';
3534
import {chonkStyled} from 'sentry/utils/theme/theme.chonk';
3635
import {withChonk} from 'sentry/utils/theme/withChonk';
3736
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
38-
import {useLocation} from 'sentry/utils/useLocation';
39-
import {useNavigate} from 'sentry/utils/useNavigate';
37+
import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
4038
import useOrganization from 'sentry/utils/useOrganization';
4139
import usePageFilters from 'sentry/utils/usePageFilters';
4240
import usePrevious from 'sentry/utils/usePrevious';
@@ -104,24 +102,19 @@ export function SpansTabOnboarding({
104102
}
105103

106104
function useControlSectionExpanded() {
107-
const location = useLocation();
108-
const navigate = useNavigate();
109-
const controlSectionExpanded = decodeScalar(location.query.toolbar);
105+
const [controlSectionExpanded, _setControlSectionExpanded] = useLocalStorageState(
106+
'explore-spans-toolbar',
107+
'expanded'
108+
);
109+
110110
const setControlSectionExpanded = useCallback(
111111
(expanded: boolean) => {
112-
const newControlSectionExpanded = expanded ? undefined : 'collapsed';
113-
navigate({
114-
...location,
115-
query: {
116-
...location.query,
117-
toolbar: newControlSectionExpanded,
118-
},
119-
});
112+
_setControlSectionExpanded(expanded ? 'expanded' : '');
120113
},
121-
[location, navigate]
114+
[_setControlSectionExpanded]
122115
);
123116

124-
return [controlSectionExpanded !== 'collapsed', setControlSectionExpanded] as const;
117+
return [controlSectionExpanded === 'expanded', setControlSectionExpanded] as const;
125118
}
126119

127120
interface SpanTabProps {

0 commit comments

Comments
 (0)