Skip to content

Set up API access in GitLab storybook

What does this MR do and why?

It improves gitlab-org/gitlab storybook instance to allow writing stories for components that depend on the Rest or GraphQL apis.

How does it work?

We use Storybook’s environment variables feature to inject a GitLab instance’s URL and a personal access token. Storybook sets up axios and exposes the personal access token in the arguments object so users can pass it to the Apollo Client for GraphQL.

This MR also introduces a custom panel where users can enter the API access parameters:

Screenshot 2023-05-18 at 1.12.51 PM.png

Motivation

I will work in replacing the "Open project in" popover that appears in the Repository view with a more advanced component in the current milestone. I will have to create a feature flag to control the rollout of the new UI. Feature flags create significant overhead in the development and code review processes. Implementing this component in Storybook separates the complexity of rolling out the component from the complexity of the implementing the component itself. This, in turn, creates more focused code reviews.

Demo stories

I modified the Content Editor story to connect with the Markdown REST API.

See demo

demo_one.gif

I also created a Workspaces UI story that demonstrates the GraphQL API:

See demo

Screenshot 2023-05-17 at 12.18.29 PM.png

Deprecate storybook-mirage

This Merge Request removes the storybook-mirage dependency. It wasn’t used by any of the stories, and it is a difficult and error-prone approach to mocking server-side requests.

How to set up and validate locally

  1. Follow the instructions in the documentation to set the GitLab instance URL and the personal access token.
  2. Run yarn storybook:start
  3. Try the Content Editor story or the Workspaces UI story.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Enrique Alcántara

Merge request reports