bulkController.stories.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import BulkController from 'sentry/components/bulkController';
  4. import Checkbox from 'sentry/components/checkbox';
  5. import {PanelTable} from 'sentry/components/panels';
  6. const dummy = [
  7. {
  8. id: 1,
  9. text: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium autem placeat corrupti sapiente optio. Sapiente, aut exercitationem nisi nesciunt molestiae perspiciatis ad illo at officiis porro quam voluptas explicabo quod.',
  10. },
  11. {
  12. id: 2,
  13. text: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium autem placeat corrupti sapiente optio. Sapiente, aut exercitationem nisi nesciunt molestiae perspiciatis ad illo at officiis porro quam voluptas explicabo quod.',
  14. },
  15. {
  16. id: 3,
  17. text: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium autem placeat corrupti sapiente optio. Sapiente, aut exercitationem nisi nesciunt molestiae perspiciatis ad illo at officiis porro quam voluptas explicabo quod.',
  18. },
  19. {
  20. id: 4,
  21. text: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium autem placeat corrupti sapiente optio. Sapiente, aut exercitationem nisi nesciunt molestiae perspiciatis ad illo at officiis porro quam voluptas explicabo quod.',
  22. },
  23. {
  24. id: 5,
  25. text: 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium autem placeat corrupti sapiente optio. Sapiente, aut exercitationem nisi nesciunt molestiae perspiciatis ad illo at officiis porro quam voluptas explicabo quod.',
  26. },
  27. ];
  28. const pageIds = dummy.map(d => d.id);
  29. export default {
  30. title: 'Components/Tables/BulkController',
  31. component: BulkController,
  32. };
  33. export const _BulkController = () => (
  34. <BulkController
  35. pageIds={pageIds}
  36. defaultSelectedIds={pageIds.slice(0, 2)}
  37. allRowsCount={23}
  38. columnsCount={3}
  39. bulkLimit={1000}
  40. >
  41. {({selectedIds, onPageRowsToggle, onRowToggle, isPageSelected, renderBulkNotice}) => (
  42. <PanelTable
  43. headers={[
  44. <StyledCheckbox
  45. key="bulk-checkbox"
  46. checked={isPageSelected}
  47. onChange={e => onPageRowsToggle(e.target.checked)}
  48. />,
  49. 'Id',
  50. 'Text',
  51. ]}
  52. >
  53. {renderBulkNotice()}
  54. {dummy.map(d => (
  55. <Fragment key={d.id}>
  56. <div>
  57. <StyledCheckbox
  58. checked={selectedIds.includes(d.id)}
  59. onChange={() => onRowToggle(d.id)}
  60. />
  61. </div>
  62. <div>{d.id}</div>
  63. <div>{d.text}</div>
  64. </Fragment>
  65. ))}
  66. </PanelTable>
  67. )}
  68. </BulkController>
  69. );
  70. _BulkController.storyName = 'BulkController';
  71. _BulkController.parameters = {
  72. docs: {
  73. description: {
  74. story: 'Nearly empty state will still show 1 bar if there are any miserable users',
  75. },
  76. },
  77. };
  78. const StyledCheckbox = styled(Checkbox)`
  79. margin-top: 0 !important;
  80. `;