groupingConfigSelect.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import styled from '@emotion/styled';
  2. import AsyncComponent from 'sentry/components/asyncComponent';
  3. import DropdownAutoComplete from 'sentry/components/dropdownAutoComplete';
  4. import DropdownButton from 'sentry/components/dropdownButton';
  5. import Tooltip from 'sentry/components/tooltip';
  6. import {t} from 'sentry/locale';
  7. import {EventGroupingConfig} from 'sentry/types';
  8. import {GroupingConfigItem} from '.';
  9. type Props = AsyncComponent['props'] & {
  10. configId: string;
  11. eventConfigId: string;
  12. onSelect: (selection: any) => void;
  13. };
  14. type State = AsyncComponent['state'] & {
  15. configs: EventGroupingConfig[];
  16. };
  17. class GroupingConfigSelect extends AsyncComponent<Props, State> {
  18. getDefaultState() {
  19. return {
  20. ...super.getDefaultState(),
  21. configs: [],
  22. };
  23. }
  24. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  25. return [['configs', '/grouping-configs/']];
  26. }
  27. renderLoading() {
  28. return this.renderBody();
  29. }
  30. renderBody() {
  31. const {configId, eventConfigId, onSelect} = this.props;
  32. const {configs} = this.state;
  33. const options = configs.map(({id, hidden}) => ({
  34. value: id,
  35. label: (
  36. <GroupingConfigItem isHidden={hidden} isActive={id === eventConfigId}>
  37. {id}
  38. </GroupingConfigItem>
  39. ),
  40. }));
  41. return (
  42. <DropdownAutoComplete onSelect={onSelect} items={options}>
  43. {({isOpen}) => (
  44. <Tooltip title={t('Click here to experiment with other grouping configs')}>
  45. <StyledDropdownButton isOpen={isOpen} size="sm">
  46. <GroupingConfigItem isActive={eventConfigId === configId}>
  47. {configId}
  48. </GroupingConfigItem>
  49. </StyledDropdownButton>
  50. </Tooltip>
  51. )}
  52. </DropdownAutoComplete>
  53. );
  54. }
  55. }
  56. const StyledDropdownButton = styled(DropdownButton)`
  57. font-weight: inherit;
  58. `;
  59. export default GroupingConfigSelect;