projectMetrics.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import * as Sentry from '@sentry/react';
  4. import {Button} from 'sentry/components/button';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  7. import {t, tct} from 'sentry/locale';
  8. import type {Organization} from 'sentry/types/organization';
  9. import type {Project} from 'sentry/types/project';
  10. import {METRICS_DOCS_URL} from 'sentry/utils/metrics/constants';
  11. import {hasCustomMetricsExtractionRules} from 'sentry/utils/metrics/features';
  12. import routeTitleGen from 'sentry/utils/routeTitle';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import {useMetricsOnboardingSidebar} from 'sentry/views/metrics/ddmOnboarding/useMetricsOnboardingSidebar';
  15. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  16. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  17. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  18. import {CustomMetricsTable} from 'sentry/views/settings/projectMetrics/customMetricsTable';
  19. import {MetricsExtractionRulesTable} from 'sentry/views/settings/projectMetrics/metricsExtractionRulesTable';
  20. type Props = {
  21. organization: Organization;
  22. project: Project;
  23. } & RouteComponentProps<{projectId: string}, {}>;
  24. function ProjectMetrics({project}: Props) {
  25. const organization = useOrganization();
  26. const hasExtractionRules = hasCustomMetricsExtractionRules(organization);
  27. const {activateSidebar} = useMetricsOnboardingSidebar();
  28. return (
  29. <Fragment>
  30. <SentryDocumentTitle title={routeTitleGen(t('Metrics'), project.slug, false)} />
  31. <SettingsPageHeader
  32. title={t('Metrics')}
  33. action={
  34. !hasExtractionRules && (
  35. <Button
  36. priority="primary"
  37. onClick={() => {
  38. Sentry.metrics.increment('ddm.add_custom_metric', 1, {
  39. tags: {
  40. referrer: 'settings',
  41. },
  42. });
  43. activateSidebar();
  44. }}
  45. size="sm"
  46. >
  47. {t('Add Metric')}
  48. </Button>
  49. )
  50. }
  51. />
  52. <TextBlock>
  53. {tct(
  54. `Metrics are numerical values that can track anything about your environment over time, from latency to error rates to user signups. To learn more about metrics, [link:read the docs].`,
  55. {
  56. link: <ExternalLink href={METRICS_DOCS_URL} />,
  57. }
  58. )}
  59. </TextBlock>
  60. <PermissionAlert project={project} />
  61. {hasExtractionRules && <MetricsExtractionRulesTable project={project} />}
  62. <CustomMetricsTable project={project} />
  63. </Fragment>
  64. );
  65. }
  66. export default ProjectMetrics;