index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {useState} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Input from 'sentry/components/input';
  5. import {space} from 'sentry/styles/space';
  6. import OrganizationContainer from 'sentry/views/organizationContainer';
  7. import EmptyStory from 'sentry/views/stories/emptyStory';
  8. import ErrorStory from 'sentry/views/stories/errorStory';
  9. import storiesContext from 'sentry/views/stories/storiesContext';
  10. import StoryFile from 'sentry/views/stories/storyFile';
  11. import StoryHeader from 'sentry/views/stories/storyHeader';
  12. import StoryTree from 'sentry/views/stories/storyTree';
  13. import type {StoriesQuery} from 'sentry/views/stories/types';
  14. import useStoriesLoader from 'sentry/views/stories/useStoriesLoader';
  15. type Props = RouteComponentProps<{}, {}, any, StoriesQuery>;
  16. export default function Stories({location}: Props) {
  17. const story = useStoriesLoader({filename: location.query.name});
  18. const [searchTerm, setSearchTerm] = useState('');
  19. return (
  20. <OrganizationContainer>
  21. <Layout>
  22. <div
  23. style={{
  24. gridArea: 'aside',
  25. display: 'flex',
  26. gap: `${space(2)}`,
  27. flexDirection: 'column',
  28. }}
  29. >
  30. <Input
  31. placeholder="Search files by name"
  32. onChange={e => setSearchTerm(e.target.value.toLowerCase())}
  33. />
  34. <Sidebar>
  35. <StoryTree
  36. files={storiesContext()
  37. .files()
  38. .filter(s => s.toLowerCase().includes(searchTerm))}
  39. />
  40. </Sidebar>
  41. </div>
  42. <StoryHeader style={{gridArea: 'head'}} />
  43. {story.error ? (
  44. <VerticalScroll style={{gridArea: 'body'}}>
  45. <ErrorStory error={story.error} />
  46. </VerticalScroll>
  47. ) : story.resolved ? (
  48. <Main style={{gridArea: 'body'}}>
  49. <StoryFile filename={story.filename} resolved={story.resolved} />
  50. </Main>
  51. ) : (
  52. <VerticalScroll style={{gridArea: 'body'}}>
  53. <EmptyStory />
  54. </VerticalScroll>
  55. )}
  56. </Layout>
  57. </OrganizationContainer>
  58. );
  59. }
  60. const Layout = styled('div')`
  61. --stories-grid-space: ${space(2)};
  62. display: grid;
  63. grid-template:
  64. 'head head' max-content
  65. 'aside body' auto/ ${p => p.theme.settings.sidebarWidth} 1fr;
  66. gap: var(--stories-grid-space);
  67. place-items: stretch;
  68. height: 100vh;
  69. padding: var(--stories-grid-space);
  70. `;
  71. const Sidebar = styled('aside')`
  72. overflow: auto;
  73. `;
  74. const VerticalScroll = styled('main')`
  75. overflow-x: hidden;
  76. overflow-y: scroll;
  77. `;
  78. /**
  79. * Avoid <Panel> here because nested panels will have a modified theme.
  80. * Therefore stories will look different in prod.
  81. */
  82. const Main = styled(VerticalScroll)`
  83. background: ${p => p.theme.background};
  84. border-radius: ${p => p.theme.panelBorderRadius};
  85. border: 1px solid ${p => p.theme.border};
  86. padding: var(--stories-grid-space);
  87. overflow-x: hidden;
  88. overflow-y: scroll;
  89. position: relative;
  90. `;