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

Re-add deprecated fields to lib/api #18488

Merged
merged 3 commits into from
Jun 18, 2022
Merged
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
74 changes: 74 additions & 0 deletions lib/api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,76 @@ export interface BaseEntry {
name: string;
refId?: string;
renderLabel?: (item: BaseEntry) => React.ReactNode;

/** @deprecated */
isRoot: boolean;
/** @deprecated */
isComponent: boolean;
/** @deprecated */
isLeaf: boolean;
}

export interface RootEntry extends BaseEntry {
type: 'root';
startCollapsed?: boolean;
children: StoryId[];

/** @deprecated */
isRoot: true;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: false;
}

export interface GroupEntry extends BaseEntry {
type: 'group';
parent?: StoryId;
children: StoryId[];

/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: false;
}

export interface ComponentEntry extends BaseEntry {
type: 'component';
parent?: StoryId;
children: StoryId[];

/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: true;
/** @deprecated */
isLeaf: false;
}

export interface DocsEntry extends BaseEntry {
type: 'docs';
parent: StoryId;
title: ComponentTitle;
/** @deprecated */
kind: ComponentTitle;
importPath: Path;

/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: true;
}

export interface StoryEntry extends BaseEntry {
type: 'story';
parent: StoryId;
title: ComponentTitle;
/** @deprecated */
kind: ComponentTitle;
importPath: Path;
prepared: boolean;
parameters?: {
Expand All @@ -69,8 +108,24 @@ export interface StoryEntry extends BaseEntry {
args?: Args;
argTypes?: ArgTypes;
initialArgs?: Args;

/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: true;
}

/** @deprecated */
export type Root = RootEntry;

/** @deprecated */
export type Group = GroupEntry | ComponentEntry;

/** @deprecated */
export type Story = DocsEntry | StoryEntry;

export type HashEntry = RootEntry | GroupEntry | ComponentEntry | DocsEntry | StoryEntry;

/**
Expand Down Expand Up @@ -308,6 +363,11 @@ export const transformStoryIndexToStoriesHash = (
startCollapsed: collapsedRoots.includes(id),
// Note that this will later get appended to the previous list of children (see below)
children: [childId],

// deprecated fields
isRoot: true,
isComponent: false,
isLeaf: false,
});
// Usually the last path/name pair will be displayed as a component,
// *unless* there are other stories that are more deeply nested under it
Expand All @@ -328,6 +388,10 @@ export const transformStoryIndexToStoriesHash = (
...(childId && {
children: [childId],
}),
// deprecated fields
isRoot: false,
isComponent: true,
isLeaf: false,
});
} else {
acc[id] = merge<GroupEntry>((acc[id] || {}) as GroupEntry, {
Expand All @@ -340,6 +404,10 @@ export const transformStoryIndexToStoriesHash = (
...(childId && {
children: [childId],
}),
// deprecated fields
isRoot: false,
isComponent: false,
isLeaf: false,
});
}
});
Expand All @@ -352,6 +420,12 @@ export const transformStoryIndexToStoriesHash = (
parent: paths[paths.length - 1],
renderLabel,
...(item.type !== 'docs' && { prepared: !!item.parameters }),

// deprecated fields
kind: item.title,
isRoot: false,
isComponent: false,
isLeaf: true,
} as DocsEntry | StoryEntry;

return acc;
Expand Down