note.stories.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Component, useState} from 'react';
  2. import {action} from '@storybook/addon-actions';
  3. import Note from 'sentry/components/activity/note';
  4. import SentryTypes from 'sentry/sentryTypes';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import MemberListStore from 'sentry/stores/memberListStore';
  7. import ProjectsStore from 'sentry/stores/projectsStore';
  8. const user = {
  9. username: 'billy@sentry.io',
  10. identities: [],
  11. id: '1',
  12. name: 'billy',
  13. dateJoined: '2019-03-09T06:52:42.836Z',
  14. avatar: {avatarUuid: null, avatarType: 'letter_avatar'},
  15. email: 'billy@sentry.io',
  16. };
  17. const activity = {id: '123', data: {text: 'hello'}, dateCreated: new Date()};
  18. ConfigStore.set('user', {...user, isSuperuser: true, options: {}});
  19. ProjectsStore.loadInitialData([
  20. {
  21. id: '2',
  22. slug: 'project-slug',
  23. name: 'Project Name',
  24. hasAccess: true,
  25. isMember: true,
  26. isBookmarked: false,
  27. teams: [
  28. {
  29. id: '1',
  30. slug: 'team-slug',
  31. name: 'Team Name',
  32. isMember: true,
  33. memberCount: 0,
  34. },
  35. ],
  36. },
  37. ]);
  38. MemberListStore.loadInitialData([
  39. {
  40. username: 'doug@sentry.io',
  41. id: '2',
  42. name: 'doug',
  43. dateJoined: '2019-03-09T06:52:42.836Z',
  44. avatar: {avatarUuid: null, avatarType: 'letter_avatar'},
  45. email: 'doug@sentry.io',
  46. },
  47. ]);
  48. const organization = {
  49. id: '1',
  50. slug: 'org-slug',
  51. access: ['project:releases'],
  52. };
  53. class OrganizationContext extends Component {
  54. static childContextTypes = {
  55. organization: SentryTypes.Organization,
  56. };
  57. getChildContext() {
  58. return {organization};
  59. }
  60. render() {
  61. return this.props.children;
  62. }
  63. }
  64. export default {
  65. title: 'Views/Activity/Activity Note',
  66. component: Note,
  67. };
  68. export const Default = () => {
  69. const [text, setText] = useState(activity.data.text);
  70. return (
  71. <OrganizationContext>
  72. <Note
  73. showTime
  74. authorName={user.name}
  75. user={user}
  76. text={text}
  77. modelId={activity.id}
  78. dateCreated={activity.dateCreated}
  79. projectSlugs={['project-slug']}
  80. minHeight={200}
  81. onUpdate={(...props) => {
  82. action('Updated item', props);
  83. setText(props[0].text);
  84. }}
  85. onDelete={action('Deleted item')}
  86. />
  87. </OrganizationContext>
  88. );
  89. };
  90. Default.storyName = 'Note';
  91. Default.parameters = {
  92. docs: {
  93. description: {
  94. story:
  95. 'A `<Note>` is an `<ActivityItem>` that can be edited with an editor. The editor has an input mode and a preview mode.',
  96. },
  97. },
  98. };