Merge pull request #19539 from storybookjs/deprecate/api-remaining

remove deprecated features in lib/api
This commit is contained in:
Norbert de Langen 2022-10-19 18:15:27 +03:00 committed by GitHub
commit ec061e5e31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 162 deletions

View File

@ -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,
@ -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 {
@ -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,
@ -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;

View File

@ -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';
@ -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: {

View File

@ -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';
@ -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> = ({
@ -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));
}
}
});
@ -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 {
@ -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);
}

View File

@ -1,4 +1,3 @@
import { deprecate } from '@storybook/client-logger';
import {
NAVIGATE_URL,
STORY_ARGS_UPDATED,
@ -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';
@ -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);
@ -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;

View File

@ -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', () => {