cardinalityLimit.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import styled from '@emotion/styled';
  2. import Access from 'sentry/components/acl/access';
  3. import NumberField from 'sentry/components/forms/fields/numberField';
  4. import Form from 'sentry/components/forms/form';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import Panel from 'sentry/components/panels/panel';
  7. import PanelBody from 'sentry/components/panels/panelBody';
  8. import PanelHeader from 'sentry/components/panels/panelHeader';
  9. import {t} from 'sentry/locale';
  10. import type {Project} from 'sentry/types/project';
  11. type Props = {
  12. isLoading: boolean;
  13. project: Project;
  14. };
  15. function transformData(data) {
  16. const limit = data.relayCustomMetricCardinalityLimit;
  17. return {
  18. relayCustomMetricCardinalityLimit: limit === '' ? null : limit,
  19. };
  20. }
  21. export function CardinalityLimit({project, isLoading}: Props) {
  22. const endpoint = `/projects/${project.organization.slug}/${project.slug}/`;
  23. return (
  24. <Form
  25. apiEndpoint={endpoint}
  26. apiMethod="PUT"
  27. saveOnBlur
  28. initialData={{
  29. relayCustomMetricCardinalityLimit: project.relayCustomMetricCardinalityLimit,
  30. }}
  31. >
  32. <Panel>
  33. <PanelHeader>{t('Limits')}</PanelHeader>
  34. <PanelBody>
  35. {isLoading ? (
  36. <LoadingIndicator />
  37. ) : (
  38. <Access access={['project:write']} project={project}>
  39. {({hasAccess}) => (
  40. <StyledNumberField
  41. disabledReason={
  42. !hasAccess
  43. ? t('You do not have permission to edit the cardinality limit')
  44. : undefined
  45. }
  46. disabled={!hasAccess}
  47. name="relayCustomMetricCardinalityLimit"
  48. label={t('Cardinality Limit')}
  49. help={t(
  50. 'The cardinality limit defines the maximum number of unique tag combinations allowed for a metric (measured per hour). If the cardinality limit is exceeded, the metric will be blocked.'
  51. )}
  52. saveOnBlur
  53. placeholder={t('Enter a value')}
  54. flexibleControlStateSize
  55. multiple
  56. getData={transformData}
  57. />
  58. )}
  59. </Access>
  60. )}
  61. </PanelBody>
  62. </Panel>
  63. </Form>
  64. );
  65. }
  66. const StyledNumberField = styled(NumberField)`
  67. ${p => p.disabled && `cursor: not-allowed`}
  68. `;