modal.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import * as React from 'react';
  2. import ModalActions from 'sentry/actions/modalActions';
  3. import type {ModalTypes} from 'sentry/components/globalModal';
  4. import type {DashboardWidgetModalOptions} from 'sentry/components/modals/addDashboardWidgetModal';
  5. import {DashboardWidgetLibraryModalOptions} from 'sentry/components/modals/dashboardWidgetLibraryModal';
  6. import type {DashboardWidgetQuerySelectorModalOptions} from 'sentry/components/modals/dashboardWidgetQuerySelectorModal';
  7. import {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  8. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  9. import type {WidgetViewerModalOptions} from 'sentry/components/modals/widgetViewerModal';
  10. import {
  11. Group,
  12. IssueOwnership,
  13. Organization,
  14. Project,
  15. SentryApp,
  16. Team,
  17. } from 'sentry/types';
  18. import {AppStoreConnectStatusData, CustomRepoType} from 'sentry/types/debugFiles';
  19. import {Event} from 'sentry/types/event';
  20. export type ModalOptions = ModalTypes['options'];
  21. export type ModalRenderProps = ModalTypes['renderProps'];
  22. /**
  23. * Show a modal
  24. */
  25. export function openModal(
  26. renderer: (renderProps: ModalRenderProps) => React.ReactNode,
  27. options?: ModalOptions
  28. ) {
  29. ModalActions.openModal(renderer, options ?? {});
  30. }
  31. /**
  32. * Close modal
  33. */
  34. export function closeModal() {
  35. ModalActions.closeModal();
  36. }
  37. type OpenSudoModalOptions = {
  38. onClose?: () => void;
  39. retryRequest?: () => Promise<any>;
  40. sudo?: boolean;
  41. superuser?: boolean;
  42. };
  43. type emailVerificationModalOptions = {
  44. actionMessage?: string;
  45. emailVerified?: boolean;
  46. onClose?: () => void;
  47. };
  48. type inviteMembersModalOptions = {
  49. initialData?: Partial<InviteRow>[];
  50. onClose?: () => void;
  51. source?: string;
  52. };
  53. export async function openSudo({onClose, ...args}: OpenSudoModalOptions = {}) {
  54. const mod = await import('sentry/components/modals/sudoModal');
  55. const {default: Modal} = mod;
  56. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  57. }
  58. export async function openEmailVerification({
  59. onClose,
  60. ...args
  61. }: emailVerificationModalOptions = {}) {
  62. const mod = await import('sentry/components/modals/emailVerificationModal');
  63. const {default: Modal} = mod;
  64. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  65. }
  66. type OpenDiffModalOptions = {
  67. baseIssueId: Group['id'];
  68. orgId: Organization['id'];
  69. project: Project;
  70. targetIssueId: string;
  71. baseEventId?: Event['id'];
  72. targetEventId?: string;
  73. };
  74. export async function openDiffModal(options: OpenDiffModalOptions) {
  75. const mod = await import('sentry/components/modals/diffModal');
  76. const {default: Modal, modalCss} = mod;
  77. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  78. }
  79. type CreateTeamModalOptions = {
  80. /**
  81. * The organization to create a team for
  82. */
  83. organization: Organization;
  84. onClose?: (team: Team) => void;
  85. /**
  86. * An initial project to add the team to. This may be deprecated soon as we may add a project selection inside of the modal flow
  87. */
  88. project?: Project;
  89. };
  90. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  91. const mod = await import('sentry/components/modals/createTeamModal');
  92. const {default: Modal} = mod;
  93. openModal(deps => <Modal {...deps} {...options} />);
  94. }
  95. type CreateOwnershipRuleModalOptions = {
  96. issueId: string;
  97. /**
  98. * The organization to create a rules for
  99. */
  100. organization: Organization;
  101. /**
  102. * The project to create a rules for
  103. */
  104. project: Project;
  105. };
  106. export type EditOwnershipRulesModalOptions = {
  107. onSave: (text: string | null) => void;
  108. organization: Organization;
  109. ownership: IssueOwnership;
  110. project: Project;
  111. };
  112. export async function openCreateOwnershipRule(options: CreateOwnershipRuleModalOptions) {
  113. const mod = await import('sentry/components/modals/createOwnershipRuleModal');
  114. const {default: Modal, modalCss} = mod;
  115. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  116. }
  117. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  118. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  119. const {default: Modal, modalCss} = mod;
  120. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  121. }
  122. export async function openCommandPalette(options: ModalOptions = {}) {
  123. const mod = await import('sentry/components/modals/commandPalette');
  124. const {default: Modal, modalCss} = mod;
  125. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  126. }
  127. type RecoveryModalOptions = {
  128. authenticatorName: string;
  129. };
  130. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  131. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  132. const {default: Modal} = mod;
  133. openModal(deps => <Modal {...deps} {...options} />);
  134. }
  135. export type TeamAccessRequestModalOptions = {
  136. memberId: string;
  137. orgId: string;
  138. teamId: string;
  139. };
  140. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  141. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  142. const {default: Modal} = mod;
  143. openModal(deps => <Modal {...deps} {...options} />);
  144. }
  145. export async function redirectToProject(newProjectSlug: string) {
  146. const mod = await import('sentry/components/modals/redirectToProject');
  147. const {default: Modal} = mod;
  148. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  149. }
  150. type HelpSearchModalOptions = {
  151. organization?: Organization;
  152. placeholder?: string;
  153. };
  154. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  155. const mod = await import('sentry/components/modals/helpSearchModal');
  156. const {default: Modal, modalCss} = mod;
  157. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  158. }
  159. export type SentryAppDetailsModalOptions = {
  160. isInstalled: boolean;
  161. onInstall: () => Promise<void>;
  162. organization: Organization;
  163. sentryApp: SentryApp;
  164. onCloseModal?: () => void; // used for analytics
  165. };
  166. type DebugFileSourceModalOptions = {
  167. appStoreConnectSourcesQuantity: number;
  168. onSave: (data: Record<string, any>) => Promise<void>;
  169. organization: Organization;
  170. sourceType: CustomRepoType;
  171. appStoreConnectStatusData?: AppStoreConnectStatusData;
  172. onClose?: () => void;
  173. sourceConfig?: Record<string, any>;
  174. };
  175. export async function openDebugFileSourceModal({
  176. onClose,
  177. ...restOptions
  178. }: DebugFileSourceModalOptions) {
  179. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  180. const {default: Modal, modalCss} = mod;
  181. openModal(deps => <Modal {...deps} {...restOptions} />, {
  182. modalCss,
  183. onClose,
  184. });
  185. }
  186. export async function openInviteMembersModal({
  187. onClose,
  188. ...args
  189. }: inviteMembersModalOptions = {}) {
  190. const mod = await import('sentry/components/modals/inviteMembersModal');
  191. const {default: Modal, modalCss} = mod;
  192. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  193. }
  194. export async function openAddDashboardWidgetModal(options: DashboardWidgetModalOptions) {
  195. const mod = await import('sentry/components/modals/addDashboardWidgetModal');
  196. const {default: Modal, modalCss} = mod;
  197. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  198. }
  199. export async function openReprocessEventModal({
  200. onClose,
  201. ...options
  202. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  203. const mod = await import('sentry/components/modals/reprocessEventModal');
  204. const {default: Modal} = mod;
  205. openModal(deps => <Modal {...deps} {...options} />, {onClose});
  206. }
  207. export async function demoSignupModal(options: ModalOptions = {}) {
  208. const mod = await import('sentry/components/modals/demoSignUp');
  209. const {default: Modal, modalCss} = mod;
  210. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  211. }
  212. export async function openDashboardWidgetQuerySelectorModal(
  213. options: DashboardWidgetQuerySelectorModalOptions
  214. ) {
  215. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  216. const {default: Modal, modalCss} = mod;
  217. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  218. }
  219. export async function openDashboardWidgetLibraryModal(
  220. options: DashboardWidgetLibraryModalOptions
  221. ) {
  222. const mod = await import('sentry/components/modals/dashboardWidgetLibraryModal');
  223. const {default: Modal, modalCss} = mod;
  224. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  225. }
  226. export async function openWidgetViewerModal(options: WidgetViewerModalOptions) {
  227. const mod = await import('sentry/components/modals/widgetViewerModal');
  228. const {default: Modal, modalCss} = mod;
  229. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  230. }