sentryFunctionSubscriptions.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import styled from '@emotion/styled';
  2. import {EVENT_CHOICES} from './constants';
  3. import SubscriptionBox from './subscriptionBox';
  4. type Resource = (typeof EVENT_CHOICES)[number];
  5. type Props = {
  6. events: string[];
  7. setEvents: (events: string[]) => void;
  8. };
  9. function SentryFunctionSubscriptions(props: Props) {
  10. const {events, setEvents} = props;
  11. function onChange(resource: Resource, checked: boolean) {
  12. if (checked && !events.includes(resource)) {
  13. setEvents(events.concat(resource));
  14. } else if (!checked && events.includes(resource)) {
  15. setEvents(events.filter(e => e !== resource));
  16. }
  17. }
  18. return (
  19. <SentryFunctionsSubscriptionGrid>
  20. {EVENT_CHOICES.map(resource => (
  21. <SubscriptionBox
  22. key={resource}
  23. disabledFromPermissions={false}
  24. webhookDisabled={false}
  25. checked={props.events.includes(resource)}
  26. resource={resource}
  27. onChange={onChange}
  28. isNew={false}
  29. />
  30. ))}
  31. </SentryFunctionsSubscriptionGrid>
  32. );
  33. }
  34. export default SentryFunctionSubscriptions;
  35. const SentryFunctionsSubscriptionGrid = styled('div')`
  36. display: grid;
  37. grid-template: auto / 1fr 1fr 1fr;
  38. @media (max-width: ${props => props.theme.breakpoints.large}) {
  39. grid-template: 1fr 1fr 1fr / auto;
  40. }
  41. `;