Skip to content

Commit

Permalink
Rationalize a tiny bit
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Jul 15, 2022
1 parent ed3be15 commit 4bb392e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/blocks/src/blocks/ArgsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { FC, useContext, useEffect, useState, useCallback } from 'react';
import mapValues from 'lodash/mapValues';
import { ArgTypesExtractor } from '@storybook/docs-tools';
import { filterArgTypes, PropDescriptor, Story } from '@storybook/store';
import type { ModuleExport, PropDescriptor, Story } from '@storybook/store';
import { filterArgTypes } from '@storybook/store';
import {
UPDATE_STORY_ARGS,
STORY_ARGS_UPDATED,
Expand Down Expand Up @@ -38,7 +39,8 @@ type ComponentsProps = BaseProps & {
};

type StoryProps = BaseProps & {
story: '.' | '^' | string;
story?: '.' | '^' | string;
of?: ModuleExport;
showComponent?: boolean;
};

Expand Down Expand Up @@ -108,19 +110,23 @@ const isShortcut = (value?: string) => {
};

export const getStory = (props: ArgsTableProps = {}, context: DocsContextProps): Story => {
const { of } = props as OfProps;
const { story } = props as StoryProps;
const { story: storyName, of } = props as StoryProps;

if (isShortcut(of) || isShortcut(story)) {
if (isShortcut(of) || isShortcut(storyName)) {
if (of === CURRENT_SELECTION || storyName === CURRENT_SELECTION) currentSelectionWarning();
return context.storyById();
}

if (storyName) {
return context.storyById(context.storyIdByName(storyName));
}

try {
// of=storyReference
return context.storyById(context.storyIdByModuleExport(of));
if (of) return context.storyById(context.storyIdByModuleExport(of));
} catch (err) {
return null;
// of is a component reference
}
return null;
};

const addComponentTabs = (
Expand Down Expand Up @@ -202,7 +208,6 @@ export const ArgsTable: FC<ArgsTableProps> = (props) => {
} = context.storyById();

const { include, exclude, components, sort: sortProp } = props as ComponentsProps;
const { story: storyName } = props as StoryProps;

const sort = sortProp || controls?.sort;

Expand Down

0 comments on commit 4bb392e

Please sign in to comment.