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

Core: Implement Story Actions API and story options menu #29532

Closed
wants to merge 8 commits into from

Conversation

ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Nov 4, 2024

Fixes #29107, #29101
Works on #29529

Adds experimental_updateActions to enable addons to define runnable actions on stories. During some pairing we decided to simplify this API to just take an event which will be emitted along with an array of story IDs, rather than allowing the addon to define the payload.

Adds the story options menu, with ellipsis shown only on hover. Ellipsis is replaced when there's a status icon, in which case it's permanently shown.

Uses the Story Actions API to show actions in the story menu.

Screenshot 2024-11-04 at 14 56 52

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.2 MB 78.2 MB 0 B 1.16 0%
initSize 143 MB 143 MB 7.52 kB 1.23 0%
diffSize 65.1 MB 65.1 MB 7.52 kB 1.98 0%
buildSize 6.88 MB 6.88 MB 2.29 kB 5.34 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.9 MB 1.9 MB 2.29 kB 6.65 0.1%
buildSbPreviewSize 271 kB 271 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.88 MB 3.88 MB 2.29 kB 6.65 0.1%
buildPreviewSize 3 MB 3 MB -8 B 1.04 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 6.5s 23.2s 16.7s 1.32 🔺71.8%
generateTime 19.5s 19.4s -98ms -0.77 -0.5%
initTime 13.5s 13.6s 66ms -1.05 0.5%
buildTime 8.1s 10.5s 2.3s 1.45 🔺22%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.5s 7.7s 2.2s 1.85 🔺29.3%
devManagerResponsive 3.5s 5s 1.5s 2.13 🔺29.8%
devManagerHeaderVisible 473ms 725ms 252ms 1.22 34.8%
devManagerIndexVisible 500ms 799ms 299ms 1.38 🔺37.4%
devStoryVisibleUncached 602ms 1.4s 865ms 1.54 🔺59%
devStoryVisible 499ms 797ms 298ms 1.42 🔺37.4%
devAutodocsVisible 467ms 658ms 191ms 1.11 29%
devMDXVisible 450ms 585ms 135ms 0.65 23.1%
buildManagerHeaderVisible 631ms 782ms 151ms 2.06 🔺19.3%
buildManagerIndexVisible 648ms 807ms 159ms 2.05 🔺19.7%
buildStoryVisible 630ms 780ms 150ms 2.06 🔺19.2%
buildAutodocsVisible 477ms 518ms 41ms 0.75 7.9%
buildMDXVisible 478ms 523ms 45ms 0.54 8.6%

Greptile Summary

Here's a concise summary of the key changes in this pull request:

Implements a new Story Actions API and ellipsis menu in the Storybook sidebar for running story-specific actions.

  • Added new StoryMenu.tsx component with hover-activated ellipsis menu that displays status icons and runnable actions
  • Added experimental_updateActions API to enable addons to define and trigger story-specific actions
  • Updated status handling to support count aggregation and detailed status information display
  • Modified Tree component to integrate the new menu and handle action/status visibility
  • Added comprehensive test coverage through StoryMenu.stories.tsx and updated existing sidebar tests

The implementation looks solid and follows existing patterns, with proper accessibility support and consistent styling. The changes enable addons to define custom actions that appear in an intuitive UI while maintaining the existing status functionality.

Copy link

nx-cloud bot commented Nov 4, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 0efd85e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@ghengeveld ghengeveld changed the title Core: Implement story menu Core: Implement Story Actions API and story menu Nov 5, 2024
@ghengeveld ghengeveld marked this pull request as ready for review November 5, 2024 15:20
@ghengeveld ghengeveld changed the title Core: Implement Story Actions API and story menu Core: Implement Story Actions API and story options menu Nov 5, 2024
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13 file(s) reviewed, 15 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +654 to +656
if (!id || Object.keys(update).length === 0) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing validation for update object structure - could allow invalid action definitions through

}
});

await store.setState({ actions: newActions }, { persistence: 'session' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider adding error handling for setState failure

Comment on lines 116 to 117
// @ts-expect-error (non strict)
return useMemo(() => ({ hash, entries: Object.entries(hash) }), [hash]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This ts-expect-error should be fixed rather than suppressed. The CombinedDataset type likely needs updating to match the new structure.

Comment on lines 157 to 158
// @ts-expect-error (non strict)
const selected: Selection = useMemo(() => storyId && { storyId, refId }, [storyId, refId]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Another ts-expect-error that should be addressed. The Selection type may need updating to handle null values properly.

}: StoryMenuProps) => {
const [visible, setVisible] = useState(false);
const theme = useTheme();
const emit = useChannel({});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: useChannel called with empty object - no event handlers registered but events being emitted. Consider registering cleanup handlers.

const STATUS_ORDER: API_StatusValue[] = ['success', 'error', 'warn', 'pending', 'unknown'];

const MenuButton = styled(StatusButton)<{ forceVisible: boolean }>(({ forceVisible }) => ({
visibility: forceVisible ? 'visible' : ('var(--story-menu-visibility, hidden)' as any),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: CSS variable cast to any - could cause type errors. Consider using proper CSS-in-JS typing.

})),
];

if (!links.some((group) => group.some(Boolean))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Boolean check on array items may give false positives for empty objects. Use explicit length check.

title: value.title,
center: value.description,
icon: <PlayHollowIcon color={theme.textMutedColor} />,
onClick: () => emit(value.event, [storyId]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Emitting event without error handling - add try/catch to handle potential event emission failures.

Comment on lines +15 to +21
const managerContext: any = {
api: {
emit: fn().mockName('api::emit'),
on: fn().mockName('api::on'),
off: fn().mockName('api::off'),
},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: managerContext uses 'any' type - consider adding proper typing for the API interface

@ghengeveld
Copy link
Member Author

Closing in favor of #29727

@ghengeveld ghengeveld closed this Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ellipsis story dropdown menu toggle on hover
1 participant