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

Addon-docs: Fix Vue source snippets for function attributes #13288

Merged
merged 3 commits into from Nov 27, 2020
Merged

Addon-docs: Fix Vue source snippets for function attributes #13288

merged 3 commits into from Nov 27, 2020

Conversation

leettaylor
Copy link
Contributor

@leettaylor leettaylor commented Nov 26, 2020

Followup to the excellent work done in #12812 by @pocka

What I did

The sourceDecorator currently throws an error if for some reason the value of an attribute is a function so I've added a simple check for the typeof the value:

Failed to generate dynamic story source: TypeError: Cannot read property 'includes' of undefined

I'm not sure what the underlying issue is that causes the type to be a function but it seems to be related to event handlers.

Here's some example code for a component/story (Not committed to the repo as it breaks storyshot tests) that causes the source to not be generated.

Example component:

<template>
  <div class="pagination">
    <button :disabled="isPreviousButtonDisabled" @click="previousPage">
      « Previous
    </button>

    <button :disabled="isNextButtonDisabled" @click="nextPage">
      Next »
    </button>
  </div>
</template>

<script>
export default {
  name: 'simple-pagination',
  props: {
    currentPage: {
      type: Number,
      required: true,
    },
    pageCount: {
      type: Number,
      required: true,
    },
  },
  computed: {
    isPreviousButtonDisabled() {
      return this.currentPage === 1;
    },
    isNextButtonDisabled() {
      return this.currentPage >= this.pageCount;
    },
  },
  methods: {
    nextPage() {
      this.$emit('next-page');
    },
    previousPage() {
      this.$emit('previous-page');
    },
  },
};
</script>
import SimplePagination from './SimplePagination.vue';

export default {
  title: 'Components/Pagination/SimplePagination',
  component: SimplePagination,
  argTypes: {
    nextPage: { action: 'Next page' },
    previousPage: { action: 'Previous page' },
  },
  args: {
    currentPage: 2,
    pageCount: 3,
  },
};

const Template = (args, { argTypes }) => ({
  props: Object.keys(argTypes),
  components: { SimplePagination },
  template:
    '<simple-pagination @next-page="nextPage" @previous-page="previousPage" v-bind="$props" />',
});

export const Default = Template.bind({});

For some reason the value of the @previous-page attribute is being passed through as a function instead of just being undefined like @next-page:

 actionHandler() {
    var channel = _addons.addons.getChannel();

    var id = (0, _uuid.v4)();
    var minDepth = 5; // anything less is really just storybook internals

    for (var _len = argument…

How to test

  • Is this testable with Jest or Chromatic screenshots? yes
  • Does this need a new example in the kitchen sink apps? no
  • Does this need an update to the documentation? no

If your answer is yes to any of these, please make sure to include it in your PR. ... done (addons/docs/src/frameworks/vue/sourceDecorator.test.ts)

@shilman shilman requested a review from pocka November 26, 2020 16:46
@shilman shilman changed the title Fix issue with Vue story source not generating correctly Addon-docs: Fix Vue source snippets for function attributes Nov 26, 2020
Copy link
Contributor

@pocka pocka left a comment

Choose a reason for hiding this comment

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

@leettaylor
Thank you for the fix! Could you add a test at sourceDecorator.test.ts?

@leettaylor
Copy link
Contributor Author

Thank you for the fix! Could you add a test at sourceDecorator.test.ts?

@pocka I've now updated the attributes test to have coverage for a prop being set to a function, undefined, or true.

Copy link
Contributor

@pocka pocka left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@shilman shilman merged commit 813b4dd into storybookjs:next Nov 27, 2020
@shilman shilman added the bug label Nov 27, 2020
@shilman shilman added this to the 6.1.x milestone Nov 27, 2020
@leettaylor leettaylor deleted the lt/fix/vue-source branch November 27, 2020 14:29
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.

None yet

3 participants