Skip to content

Commit 8c3b7cf

Browse files
authored
fix(stories): update footer navigation (#95582)
Follow-up to #95442, which updated sidebar and search routing behavior but did not update the footer navigation. This PR refactors the story footer cards to use the new URL scheme rather than the old query scheme.
1 parent 558ce17 commit 8c3b7cf

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

static/app/stories/view/storyFooter.tsx

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,36 @@
11
import styled from '@emotion/styled';
2-
import qs from 'query-string';
32

43
import {LinkButton} from 'sentry/components/core/button/linkButton';
54
import {Flex} from 'sentry/components/core/layout';
65
import {IconArrow} from 'sentry/icons';
7-
import {useStoryBookFilesByCategory} from 'sentry/stories/view/storySidebar';
8-
import type {StoryTreeNode} from 'sentry/stories/view/storyTree';
9-
import type {StoryDescriptor} from 'sentry/stories/view/useStoriesLoader';
10-
import {useStory} from 'sentry/stories/view/useStory';
116
import {space} from 'sentry/styles/space';
12-
import {useLocation} from 'sentry/utils/useLocation';
137

14-
export function StoryFooter() {
15-
const location = useLocation();
8+
import {useStoryBookFilesByCategory} from './storySidebar';
9+
import type {StoryTreeNode} from './storyTree';
10+
import {type StoryDescriptor} from './useStoriesLoader';
11+
import {useStory} from './useStory';
1612

13+
export function StoryFooter() {
1714
const {story} = useStory();
18-
const categories = useStoryBookFilesByCategory();
19-
const pagination = findPreviousAndNextStory(story, categories);
20-
21-
const prevLocationDescriptor = qs.stringify({
22-
...location.query,
23-
name: pagination?.prev?.story.filesystemPath,
24-
});
25-
const nextLocationDescriptor = qs.stringify({
26-
...location.query,
27-
name: pagination?.next?.story.filesystemPath,
28-
});
15+
const stories = useStoryBookFilesByCategory();
16+
const pagination = findPreviousAndNextStory(story, stories);
2917

3018
return (
3119
<Flex align="center" justify="space-between" gap={space(2)}>
3220
{pagination?.prev && (
33-
<Card
34-
to={`/stories/?${prevLocationDescriptor}`}
35-
icon={<IconArrow direction="left" />}
36-
>
21+
<Card to={pagination.prev.location} icon={<IconArrow direction="left" />}>
3722
<CardLabel>Previous</CardLabel>
38-
<CardTitle>{pagination.prev.story.label}</CardTitle>
23+
<CardTitle>{pagination.prev.label}</CardTitle>
3924
</Card>
4025
)}
4126
{pagination?.next && (
4227
<Card
4328
data-flip
44-
to={`/stories/?${nextLocationDescriptor}`}
29+
to={pagination.next.location}
4530
icon={<IconArrow direction="right" />}
4631
>
4732
<CardLabel>Next</CardLabel>
48-
<CardTitle>{pagination.next.story.label}</CardTitle>
33+
<CardTitle>{pagination.next.label}</CardTitle>
4934
</Card>
5035
)}
5136
</Flex>
@@ -56,14 +41,11 @@ function findPreviousAndNextStory(
5641
story: StoryDescriptor,
5742
categories: ReturnType<typeof useStoryBookFilesByCategory>
5843
): {
59-
next: {category: string; story: StoryTreeNode} | undefined;
60-
prev: {category: string; story: StoryTreeNode} | undefined;
44+
next?: StoryTreeNode;
45+
prev?: StoryTreeNode;
6146
} | null {
62-
const stories = Object.entries(categories).flatMap(([key, category]) =>
63-
category.map(s => ({category: key, story: s}))
64-
);
65-
66-
const currentIndex = stories.findIndex(s => s.story.filesystemPath === story.filename);
47+
const stories = Object.values(categories).flat();
48+
const currentIndex = stories.findIndex(s => s.filesystemPath === story.filename);
6749

6850
if (currentIndex === -1) {
6951
return null;

0 commit comments

Comments
 (0)