index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import Feature from 'sentry/components/acl/feature';
  4. import {Alert} from 'sentry/components/alert';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import NoProjectMessage from 'sentry/components/noProjectMessage';
  7. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import AiAnalyticsFilters from 'sentry/views/aiAnalytics/filters';
  12. import TokenUsageChart from 'sentry/views/aiAnalytics/tokenUsageChart';
  13. function NoAccessComponent() {
  14. return (
  15. <Layout.Page withPadding>
  16. <Alert type="warning">{t("You don't have access to this feature")}</Alert>
  17. </Layout.Page>
  18. );
  19. }
  20. function AiAnalyticsContainer() {
  21. const [search, setSearch] = useState('');
  22. const organization = useOrganization();
  23. return (
  24. <Feature
  25. features="ai-analytics"
  26. organization={organization}
  27. renderDisabled={NoAccessComponent}
  28. >
  29. <NoProjectMessage organization={organization}>
  30. <Layout.Page>
  31. <StyledBody>
  32. <StyledMain>
  33. <PageFiltersContainer>
  34. <AiAnalyticsFilters onSearch={x => setSearch(x)} query={search} />
  35. </PageFiltersContainer>
  36. <TwoColumns>
  37. <TokenUsageChart metric="ai.prompt_tokens.used" />
  38. <TokenUsageChart metric="ai.completion_tokens.used" />
  39. </TwoColumns>
  40. </StyledMain>
  41. </StyledBody>
  42. </Layout.Page>
  43. </NoProjectMessage>
  44. </Feature>
  45. );
  46. }
  47. const StyledBody = styled('div')`
  48. background-color: ${p => p.theme.background};
  49. flex: 1;
  50. display: grid;
  51. gap: 0;
  52. padding: 0;
  53. grid-template-rows: 1fr;
  54. grid-template-columns: minmax(0, 1fr) auto;
  55. grid-template-areas: 'content saved-searches';
  56. `;
  57. const TwoColumns = styled('div')`
  58. display: flex;
  59. gap: ${space(2)};
  60. `;
  61. const StyledMain = styled('section')`
  62. grid-area: content;
  63. padding: ${space(2)};
  64. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  65. padding: ${space(3)} ${space(4)};
  66. }
  67. `;
  68. export default AiAnalyticsContainer;