sentryAppInstallations.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {
  2. addErrorMessage,
  3. addLoadingMessage,
  4. addSuccessMessage,
  5. clearIndicators,
  6. } from 'sentry/actionCreators/indicator';
  7. import {Client} from 'sentry/api';
  8. import {t} from 'sentry/locale';
  9. import {SentryApp, SentryAppInstallation} from 'sentry/types';
  10. /**
  11. * Install a sentry application
  12. *
  13. * @param {Object} client ApiClient
  14. * @param {String} orgId Organization Slug
  15. * @param {Object} app SentryApp
  16. */
  17. export function installSentryApp(
  18. client: Client,
  19. orgId: string,
  20. app: SentryApp
  21. ): Promise<SentryAppInstallation> {
  22. addLoadingMessage();
  23. const promise = client.requestPromise(
  24. `/organizations/${orgId}/sentry-app-installations/`,
  25. {
  26. method: 'POST',
  27. data: {slug: app.slug},
  28. }
  29. );
  30. promise.then(
  31. () => clearIndicators(),
  32. () => addErrorMessage(t(`Unable to install ${app.name}`))
  33. );
  34. return promise;
  35. }
  36. /**
  37. * Uninstall a sentry application
  38. *
  39. * @param {Object} client ApiClient
  40. * @param {Object} install SentryAppInstallation
  41. */
  42. export function uninstallSentryApp(
  43. client: Client,
  44. install: SentryAppInstallation
  45. ): Promise<void> {
  46. addLoadingMessage();
  47. const promise = client.requestPromise(`/sentry-app-installations/${install.uuid}/`, {
  48. method: 'DELETE',
  49. });
  50. const capitalizedAppSlug =
  51. install.app.slug.charAt(0).toUpperCase() + install.app.slug.slice(1);
  52. promise.then(
  53. () => {
  54. addSuccessMessage(t(`${capitalizedAppSlug} successfully uninstalled.`));
  55. },
  56. () => clearIndicators()
  57. );
  58. return promise;
  59. }