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

remove deprecated features in lib/api #19539

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions code/lib/api/src/lib/stories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import memoize from 'memoizerific';
import React from 'react';
import deprecate from 'util-deprecate';
import { dedent } from 'ts-dedent';
import mapValues from 'lodash/mapValues';
import countBy from 'lodash/countBy';
import global from 'global';
import { toId, sanitize } from '@storybook/csf';
import type {
StoryId,
Expand All @@ -23,8 +21,6 @@ import merge from './merge';
import type { Provider } from '../modules/provider';
import type { ViewMode } from '../modules/addons';

const { FEATURES } = global;

export type { StoryId };

export interface BaseEntry {
Expand Down Expand Up @@ -222,15 +218,6 @@ export interface StoryIndex {
entries: Record<StoryId, IndexEntry>;
}

const warnChangedDefaultHierarchySeparators = deprecate(
() => {},
dedent`
The default hierarchy separators changed in Storybook 6.0.
'|' and '.' will no longer create a hierarchy, but codemods are available.
Read more about it in the migration guide: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md
`
);

export const denormalizeStoryParameters = ({
globalParameters,
kindParameters,
Expand Down Expand Up @@ -366,12 +353,8 @@ export const transformStoryIndexToStoriesHash = (
const entryValues = Object.values(v4Index.entries);
const { sidebar = {} } = provider.getConfig();
const { showRoots, collapsedRoots = [], renderLabel } = sidebar;
const usesOldHierarchySeparator = entryValues.some(({ title }) => title.match(/\.|\|/)); // dot or pipe

const setShowRoots = typeof showRoots !== 'undefined';
if (usesOldHierarchySeparator && !setShowRoots && FEATURES?.warnOnLegacyHierarchySeparator) {
warnChangedDefaultHierarchySeparators();
}

const storiesHashOutOfOrder = Object.values(entryValues).reduce((acc, item) => {
if (docsOptions.docsMode && item.type !== 'docs') return acc;
Expand Down
11 changes: 0 additions & 11 deletions code/lib/api/src/modules/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { dequal as deepEqual } from 'dequal';
import { create } from '@storybook/theming/create';
import { SET_CONFIG } from '@storybook/core-events';
import type { ThemeVars } from '@storybook/theming';
import { deprecate } from '@storybook/client-logger';
import { dedent } from 'ts-dedent';

import merge from '../lib/merge';
import type { State, ModuleFn } from '../index';
Expand Down Expand Up @@ -225,15 +223,6 @@ export const init: ModuleFn = ({ store, provider, singleStory, fullAPI }) => {
getInitialOptions() {
const { theme, selectedPanel, ...options } = provider.getConfig();

if (options.layout?.isToolshown !== undefined) {
deprecate(dedent`
The "isToolshown" option is deprecated. Please use "showToolbar" instead.

See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#renamed-istoolshown-to-showtoolbar
`);
options.layout.showToolbar = options.layout.isToolshown;
}

return {
...defaultState,
layout: {
Expand Down
41 changes: 15 additions & 26 deletions code/lib/api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
STORY_INDEX_INVALIDATED,
CONFIG_ERROR,
} from '@storybook/core-events';
import deprecate from 'util-deprecate';
import { logger } from '@storybook/client-logger';

import { getEventMetadata } from '../lib/events';
Expand Down Expand Up @@ -92,28 +91,21 @@ export interface SubAPI {
updateStory: (storyId: StoryId, update: StoryUpdate, ref?: ComposedRef) => Promise<void>;
}

const deprecatedOptionsParameterWarnings: Record<string, () => void> = [
'enableShortcuts',
'theme',
'showRoots',
].reduce((acc, option: string) => {
acc[option] = deprecate(
() => {},
`parameters.options.${option} is deprecated and will be removed in Storybook 7.0.
To change this setting, use \`addons.setConfig\`. See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-immutable-options-parameters
`
);
return acc;
}, {} as Record<string, () => void>);
function checkDeprecatedOptionParameters(options?: Record<string, any>) {
if (!options) {
return;
const removedOptions = ['enableShortcuts', 'theme', 'showRoots'];

function removeRemovedOptions<T extends Record<string, any> = Record<string, any>>(options?: T): T {
if (!options || typeof options === 'string') {
return options;
}
Object.keys(options).forEach((option: string) => {
if (deprecatedOptionsParameterWarnings[option]) {
deprecatedOptionsParameterWarnings[option]();
const result: T = { ...options } as T;

removedOptions.forEach((option) => {
if (option in result) {
delete result[option];
}
});

return result;
}

export const init: ModuleFn<SubAPI, SubState, true> = ({
Expand Down Expand Up @@ -424,8 +416,7 @@ export const init: ModuleFn<SubAPI, SubState, true> = ({
const options = fullAPI.getCurrentParameter('options');

if (options) {
checkDeprecatedOptionParameters(options);
fullAPI.setOptions(options);
fullAPI.setOptions(removeRemovedOptions(options));
}
}
});
Expand All @@ -437,8 +428,7 @@ export const init: ModuleFn<SubAPI, SubState, true> = ({
if (!ref) {
if (!store.getState().hasCalledSetOptions) {
const { options } = update.parameters;
checkDeprecatedOptionParameters(options);
fullAPI.setOptions(options);
fullAPI.setOptions(removeRemovedOptions(options));
store.setState({ hasCalledSetOptions: true });
}
} else {
Expand Down Expand Up @@ -474,8 +464,7 @@ export const init: ModuleFn<SubAPI, SubState, true> = ({

fullAPI.setStories(setStoriesData);
const options = fullAPI.getCurrentParameter('options');
checkDeprecatedOptionParameters(options);
fullAPI.setOptions(options);
fullAPI.setOptions(removeRemovedOptions(options));
} else {
fullAPI.setRef(ref.id, { ...ref, setStoriesData }, true);
}
Expand Down
50 changes: 1 addition & 49 deletions code/lib/api/src/modules/url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { deprecate } from '@storybook/client-logger';
import {
NAVIGATE_URL,
STORY_ARGS_UPDATED,
Expand All @@ -8,10 +7,8 @@ import {
} from '@storybook/core-events';
import type { NavigateOptions } from '@storybook/router';
import { queryFromLocation, buildArgsParam } from '@storybook/router';
import { toId, sanitize } from '@storybook/csf';
import { dequal as deepEqual } from 'dequal';
import global from 'global';
import { dedent } from 'ts-dedent';

import { ModuleArgs, ModuleFn } from '../index';
import { Layout, UI } from './layout';
Expand Down Expand Up @@ -49,11 +46,6 @@ const initialUrlSupport = ({
shortcuts,
addonPanel,
tabs,
addons, // deprecated
panelRight, // deprecated
stories, // deprecated
selectedKind, // deprecated
selectedStory, // deprecated
path: queryPath,
...otherParams // the rest gets passed to the iframe
} = queryFromLocation(location);
Expand All @@ -70,47 +62,7 @@ const initialUrlSupport = ({
};
const selectedPanel = addonPanel || undefined;

// @deprecated Superceded by `panel=false`, to be removed in 7.0
if (addons === '0') {
deprecate(dedent`
The 'addons' query param is deprecated and will be removed in Storybook 7.0. Use 'panel=false' instead.

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params
`);
layout.showPanel = false;
}
// @deprecated Superceded by `panel=right`, to be removed in 7.0
if (panelRight === '1') {
deprecate(dedent`
The 'panelRight' query param is deprecated and will be removed in Storybook 7.0. Use 'panel=right' instead.

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params
`);
layout.panelPosition = 'right';
}
// @deprecated Superceded by `nav=false`, to be removed in 7.0
if (stories === '0') {
deprecate(dedent`
The 'stories' query param is deprecated and will be removed in Storybook 7.0. Use 'nav=false' instead.

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params
`);
layout.showNav = false;
}

// @deprecated To be removed in 7.0
// If the user hasn't set the storyId on the URL, we support legacy URLs (selectedKind/selectedStory)
// NOTE: this "storyId" can just be a prefix of a storyId, really it is a storyIdSpecifier.
let storyId = storyIdFromUrl;
if (!storyId && selectedKind) {
deprecate(dedent`
The 'selectedKind' and 'selectedStory' query params are deprecated and will be removed in Storybook 7.0. Use 'path' instead.

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params
`);
storyId = selectedStory ? toId(selectedKind, selectedStory) : sanitize(selectedKind);
}

const storyId = storyIdFromUrl;
// Avoid returning a new object each time if no params actually changed.
const customQueryParams = deepEqual(prevParams, otherParams) ? prevParams : otherParams;
prevParams = customQueryParams;
Expand Down
59 changes: 0 additions & 59 deletions code/lib/api/src/tests/url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,65 +77,6 @@ describe('initial state', () => {
expect(layout).toEqual({ showPanel: false });
});
});

describe('deprecated query parameters', () => {
const defaultDeprecatedParameters = {
selectedKind: 'kind',
selectedStory: 'story',
addons: '1',
stories: '1',
panelRight: '0',
};

it('sets sensible storyId for selectedKind/Story', () => {
const location = { search: qs.stringify(defaultDeprecatedParameters) };
const {
state: { layout, storyId },
} = initURL({ state: { location, viewMode } });

// Nothing unexpected in layout
expect(layout).toEqual({});
expect(storyId).toEqual('kind--story');
});

it('sets sensible storyId for selectedKind only', () => {
const location = { search: { selectedKind: 'kind' } };
const {
state: { storyId },
} = initURL({ state: { location, viewMode } });

expect(storyId).toEqual('kind');
});

it('handles addons and stories parameters', () => {
const location = {
search: qs.stringify({
...defaultDeprecatedParameters,
addons: '0',
stories: '0',
}),
};
const {
state: { layout },
} = initURL({ state: { location } });

expect(layout).toEqual({ showNav: false, showPanel: false });
});

it('handles panelRight parameter', () => {
const location = {
search: qs.stringify({
...defaultDeprecatedParameters,
panelRight: '1',
}),
};
const {
state: { layout },
} = initURL({ state: { location } });

expect(layout).toEqual({ panelPosition: 'right' });
});
});
});

describe('queryParams', () => {
Expand Down