modal.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import type {ModalTypes} from 'sentry/components/globalModal';
  2. import type {CreateNewIntegrationModalOptions} from 'sentry/components/modals/createNewIntegrationModal';
  3. import type {CreateReleaseIntegrationModalOptions} from 'sentry/components/modals/createReleaseIntegrationModal';
  4. import type {DashboardWidgetQuerySelectorModalOptions} from 'sentry/components/modals/dashboardWidgetQuerySelectorModal';
  5. import {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  6. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  7. import {OverwriteWidgetModalProps} from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
  8. import type {WidgetViewerModalOptions} from 'sentry/components/modals/widgetViewerModal';
  9. import ModalStore from 'sentry/stores/modalStore';
  10. import type {
  11. Event,
  12. Group,
  13. IssueOwnership,
  14. Organization,
  15. Project,
  16. SentryApp,
  17. Team,
  18. } from 'sentry/types';
  19. import {AppStoreConnectStatusData, CustomRepoType} from 'sentry/types/debugFiles';
  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. ModalStore.openModal(renderer, options ?? {});
  30. }
  31. /**
  32. * Close modal
  33. */
  34. export function closeModal() {
  35. ModalStore.closeModal();
  36. }
  37. type OpenSudoModalOptions = {
  38. isSuperuser?: boolean;
  39. needsReload?: boolean;
  40. onClose?: () => void;
  41. retryRequest?: () => Promise<any>;
  42. sudo?: boolean;
  43. };
  44. type EmailVerificationModalOptions = {
  45. actionMessage?: string;
  46. emailVerified?: boolean;
  47. onClose?: () => void;
  48. };
  49. type InviteMembersModalOptions = {
  50. initialData?: Partial<InviteRow>[];
  51. onClose?: () => void;
  52. source?: string;
  53. };
  54. export async function openSudo({onClose, ...args}: OpenSudoModalOptions = {}) {
  55. const mod = await import('sentry/components/modals/sudoModal');
  56. const {default: Modal} = mod;
  57. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  58. }
  59. export async function openEmailVerification({
  60. onClose,
  61. ...args
  62. }: EmailVerificationModalOptions = {}) {
  63. const mod = await import('sentry/components/modals/emailVerificationModal');
  64. const {default: Modal} = mod;
  65. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  66. }
  67. type OpenDiffModalOptions = {
  68. baseIssueId: Group['id'];
  69. orgId: Organization['id'];
  70. project: Project;
  71. targetIssueId: string;
  72. baseEventId?: Event['id'];
  73. targetEventId?: string;
  74. };
  75. export async function openDiffModal(options: OpenDiffModalOptions) {
  76. const mod = await import('sentry/components/modals/diffModal');
  77. const {default: Modal, modalCss} = mod;
  78. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  79. }
  80. type CreateTeamModalOptions = {
  81. /**
  82. * The organization to create a team for
  83. */
  84. organization: Organization;
  85. onClose?: (team: Team) => void;
  86. /**
  87. * 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
  88. */
  89. project?: Project;
  90. };
  91. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  92. const mod = await import('sentry/components/modals/createTeamModal');
  93. const {default: Modal} = mod;
  94. openModal(deps => <Modal {...deps} {...options} />);
  95. }
  96. type CreateOwnershipRuleModalOptions = {
  97. issueId: string;
  98. /**
  99. * The organization to create a rules for
  100. */
  101. organization: Organization;
  102. /**
  103. * The project to create a rules for
  104. */
  105. project: Project;
  106. /**
  107. * Suggestions will be created from the current event
  108. */
  109. eventData?: Event;
  110. };
  111. export type EditOwnershipRulesModalOptions = {
  112. onSave: (text: string | null) => void;
  113. organization: Organization;
  114. ownership: IssueOwnership;
  115. project: Project;
  116. };
  117. /**
  118. * Open the edit ownership modal within issue details
  119. */
  120. export async function openIssueOwnershipRuleModal(
  121. options: CreateOwnershipRuleModalOptions
  122. ) {
  123. const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
  124. const {default: Modal, modalCss} = mod;
  125. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  126. }
  127. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  128. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  129. const {default: Modal, modalCss} = mod;
  130. openModal(deps => <Modal {...deps} {...options} />, {
  131. closeEvents: 'escape-key',
  132. modalCss,
  133. });
  134. }
  135. export async function openCommandPalette(options: ModalOptions = {}) {
  136. const mod = await import('sentry/components/modals/commandPalette');
  137. const {default: Modal, modalCss} = mod;
  138. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  139. }
  140. type RecoveryModalOptions = {
  141. authenticatorName: string;
  142. };
  143. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  144. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  145. const {default: Modal} = mod;
  146. openModal(deps => <Modal {...deps} {...options} />);
  147. }
  148. export type TeamAccessRequestModalOptions = {
  149. memberId: string;
  150. orgId: string;
  151. teamId: string;
  152. };
  153. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  154. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  155. const {default: Modal} = mod;
  156. openModal(deps => <Modal {...deps} {...options} />);
  157. }
  158. export async function redirectToProject(newProjectSlug: string) {
  159. const mod = await import('sentry/components/modals/redirectToProject');
  160. const {default: Modal} = mod;
  161. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  162. }
  163. type HelpSearchModalOptions = {
  164. organization?: Organization;
  165. placeholder?: string;
  166. };
  167. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  168. const mod = await import('sentry/components/modals/helpSearchModal');
  169. const {default: Modal, modalCss} = mod;
  170. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  171. }
  172. export type SentryAppDetailsModalOptions = {
  173. isInstalled: boolean;
  174. onInstall: () => Promise<void>;
  175. organization: Organization;
  176. sentryApp: SentryApp;
  177. onCloseModal?: () => void; // used for analytics
  178. };
  179. type DebugFileSourceModalOptions = {
  180. appStoreConnectSourcesQuantity: number;
  181. onSave: (data: Record<string, any>) => Promise<void>;
  182. organization: Organization;
  183. sourceType: CustomRepoType;
  184. appStoreConnectStatusData?: AppStoreConnectStatusData;
  185. onClose?: () => void;
  186. sourceConfig?: Record<string, any>;
  187. };
  188. export async function openDebugFileSourceModal({
  189. onClose,
  190. ...restOptions
  191. }: DebugFileSourceModalOptions) {
  192. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  193. const {default: Modal, modalCss} = mod;
  194. openModal(deps => <Modal {...deps} {...restOptions} />, {
  195. modalCss,
  196. onClose,
  197. });
  198. }
  199. export async function openInviteMembersModal({
  200. onClose,
  201. ...args
  202. }: InviteMembersModalOptions = {}) {
  203. const mod = await import('sentry/components/modals/inviteMembersModal');
  204. const {default: Modal, modalCss} = mod;
  205. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  206. }
  207. export async function openWidgetBuilderOverwriteModal(
  208. options: OverwriteWidgetModalProps
  209. ) {
  210. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  211. const {default: Modal, modalCss} = mod;
  212. openModal(deps => <Modal {...deps} {...options} />, {
  213. closeEvents: 'escape-key',
  214. modalCss,
  215. });
  216. }
  217. export async function openAddToDashboardModal(options) {
  218. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  219. const {default: Modal, modalCss} = mod;
  220. openModal(deps => <Modal {...deps} {...options} />, {
  221. closeEvents: 'escape-key',
  222. modalCss,
  223. });
  224. }
  225. export async function openReprocessEventModal({
  226. onClose,
  227. ...options
  228. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  229. const {ReprocessingEventModal} = await import(
  230. 'sentry/components/modals/reprocessEventModal'
  231. );
  232. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  233. }
  234. export async function demoSignupModal(options: ModalOptions = {}) {
  235. const mod = await import('sentry/components/modals/demoSignUp');
  236. const {default: Modal, modalCss} = mod;
  237. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  238. }
  239. export type DemoEndModalOptions = {
  240. orgSlug: string | null;
  241. tour: string;
  242. };
  243. export async function demoEndModal(options: DemoEndModalOptions) {
  244. const mod = await import('sentry/components/modals/demoEndModal');
  245. const {default: Modal, modalCss} = mod;
  246. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  247. }
  248. export async function openDashboardWidgetQuerySelectorModal(
  249. options: DashboardWidgetQuerySelectorModalOptions
  250. ) {
  251. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  252. const {default: Modal, modalCss} = mod;
  253. openModal(deps => <Modal {...deps} {...options} />, {
  254. closeEvents: 'escape-key',
  255. modalCss,
  256. });
  257. }
  258. export async function openWidgetViewerModal({
  259. onClose,
  260. ...options
  261. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  262. const mod = await import('sentry/components/modals/widgetViewerModal');
  263. const {default: Modal, modalCss} = mod;
  264. openModal(deps => <Modal {...deps} {...options} />, {
  265. closeEvents: 'escape-key',
  266. modalCss,
  267. onClose,
  268. });
  269. }
  270. export async function openCreateNewIntegrationModal(
  271. options: CreateNewIntegrationModalOptions
  272. ) {
  273. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  274. const {default: Modal} = mod;
  275. openModal(deps => <Modal {...deps} {...options} />);
  276. }
  277. export async function openCreateReleaseIntegration(
  278. options: CreateReleaseIntegrationModalOptions
  279. ) {
  280. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  281. const {default: Modal} = mod;
  282. openModal(deps => <Modal {...deps} {...options} />);
  283. }