Skip to content
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

Manager: Update store.settings.lastTrackedStoryId #24115

4 changes: 4 additions & 0 deletions code/lib/manager-api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ export const init: ModuleFn<SubAPI, SubState> = ({

if (!entry) throw new Error(`Unknown id or title: '${titleOrId}'`);

store.setState({
settings: { ...store.getState().settings, lastTrackedStoryId: entry.id },
});

// We want to navigate to the first ancestor entry that is a leaf
const leafEntry = api.findLeafEntry(hash, entry.id);
const fullId = leafEntry.refId ? `${leafEntry.refId}_${leafEntry.id}` : leafEntry.id;
Expand Down
10 changes: 10 additions & 0 deletions code/lib/manager-api/src/tests/stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,16 @@ describe('stories API', () => {
api.selectStory('intro');
expect(navigate).toHaveBeenCalledWith('/docs/intro--docs');
});
it('updates lastTrackedStoryId', () => {
const initialState = { path: '/story/a--1', storyId: 'a--1', viewMode: 'story' };
const moduleArgs = createMockModuleArgs({ initialState });
const { api } = initStories(moduleArgs as unknown as ModuleArgs);
const { store } = moduleArgs;

api.setIndex({ v: 4, entries: navigationEntries });
api.selectStory('a--1');
expect(store.getState().settings.lastTrackedStoryId).toBe('a--1');
});
describe('deprecated api', () => {
it('allows navigating to a combination of title + name', () => {
const initialState = { path: '/story/a--1', storyId: 'a--1', viewMode: 'story' };
Expand Down