thresholdGroupRow.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {DropdownMenu, MenuItemProps} from 'sentry/components/dropdownMenu';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import {IconEllipsis} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import {getExactDuration} from 'sentry/utils/formatters';
  9. import {Threshold} from '../utils/types';
  10. type Props = {
  11. thresholds: {[key: string]: any};
  12. };
  13. export function ThresholdGroupRow({thresholds}: Props) {
  14. const actions: MenuItemProps[] = [
  15. {
  16. key: 'edit',
  17. label: t('Edit'),
  18. onAction: () => {},
  19. },
  20. {
  21. key: 'delete',
  22. label: t('Delete'),
  23. priority: 'danger',
  24. onAction: () => {
  25. // console.log('oops');
  26. },
  27. },
  28. ];
  29. return thresholds.map((threshold: Threshold, idx: number) => (
  30. <Fragment key={idx}>
  31. <FlexCenter>
  32. {idx === 0 ? (
  33. <ProjectBadge
  34. project={threshold.project}
  35. avatarSize={16}
  36. hideOverflow
  37. disableLink
  38. />
  39. ) : (
  40. ''
  41. )}
  42. </FlexCenter>
  43. <FlexCenter>{idx === 0 ? threshold.environment.name || 'None' : ''}</FlexCenter>
  44. <FlexCenter>{getExactDuration(threshold.window_in_seconds)}</FlexCenter>
  45. <FlexCenter>
  46. {threshold.trigger_type === 'over' ? '>' : '<'} {threshold.threshold_type}
  47. </FlexCenter>
  48. <ActionsColumn>
  49. <DropdownMenu
  50. items={actions}
  51. position="bottom-end"
  52. triggerProps={{
  53. 'aria-label': t('Actions'),
  54. size: 'xs',
  55. icon: <IconEllipsis size="xs" />,
  56. showChevron: false,
  57. }}
  58. // disabledKeys={hasAccess && canEdit ? [] : ['delete']}
  59. />
  60. </ActionsColumn>
  61. </Fragment>
  62. ));
  63. }
  64. const FlexCenter = styled('div')`
  65. display: flex;
  66. align-items: center;
  67. `;
  68. const ActionsColumn = styled('div')`
  69. display: flex;
  70. align-items: center;
  71. justify-content: center;
  72. padding: ${space(1)};
  73. `;