actionButtons.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import styled from '@emotion/styled';
  2. import {Button, LinkButton} from 'sentry/components/button';
  3. import ConfirmDelete from 'sentry/components/confirmDelete';
  4. import {IconDelete, IconStats, IconUpgrade} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {SentryApp} from 'sentry/types/integrations';
  8. import type {Organization} from 'sentry/types/organization';
  9. type Props = {
  10. app: SentryApp;
  11. onDelete: (app: SentryApp) => void;
  12. org: Organization;
  13. showDelete: boolean;
  14. showPublish: boolean;
  15. disableDeleteReason?: string;
  16. // If you want to disable the publish or delete buttons, pass in a reason to display to the user in a tooltip
  17. disablePublishReason?: string;
  18. onPublish?: () => void;
  19. };
  20. function ActionButtons({
  21. org,
  22. app,
  23. showPublish,
  24. showDelete,
  25. onPublish,
  26. onDelete,
  27. disablePublishReason,
  28. disableDeleteReason,
  29. }: Props) {
  30. const appDashboardButton = (
  31. <StyledLinkButton
  32. size="xs"
  33. icon={<IconStats />}
  34. to={`/settings/${org.slug}/developer-settings/${app.slug}/dashboard/`}
  35. >
  36. {t('Dashboard')}
  37. </StyledLinkButton>
  38. );
  39. const publishRequestButton = showPublish ? (
  40. <StyledButton
  41. disabled={!!disablePublishReason}
  42. title={disablePublishReason}
  43. icon={<IconUpgrade />}
  44. size="xs"
  45. onClick={onPublish}
  46. >
  47. {t('Publish')}
  48. </StyledButton>
  49. ) : null;
  50. const deleteConfirmMessage = t(
  51. `Deleting %s will also delete any and all of its installations. This is a permanent action. Do you wish to continue?`,
  52. app.slug
  53. );
  54. const deleteButton = showDelete ? (
  55. disableDeleteReason ? (
  56. <StyledButton
  57. disabled
  58. title={disableDeleteReason}
  59. size="xs"
  60. icon={<IconDelete />}
  61. aria-label={t('Delete')}
  62. />
  63. ) : (
  64. onDelete && (
  65. <ConfirmDelete
  66. message={deleteConfirmMessage}
  67. confirmInput={app.slug}
  68. priority="danger"
  69. onConfirm={() => onDelete(app)}
  70. >
  71. <StyledButton size="xs" icon={<IconDelete />} aria-label={t('Delete')} />
  72. </ConfirmDelete>
  73. )
  74. )
  75. ) : null;
  76. return (
  77. <ButtonHolder>
  78. {appDashboardButton}
  79. {publishRequestButton}
  80. {deleteButton}
  81. </ButtonHolder>
  82. );
  83. }
  84. const ButtonHolder = styled('div')`
  85. flex-direction: row;
  86. display: flex;
  87. & > * {
  88. margin-left: ${space(0.5)};
  89. }
  90. `;
  91. const StyledButton = styled(Button)`
  92. color: ${p => p.theme.subText};
  93. `;
  94. const StyledLinkButton = styled(LinkButton)`
  95. color: ${p => p.theme.subText};
  96. `;
  97. export default ActionButtons;