modal.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 {
  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. 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. export type EditOwnershipRulesModalOptions = {
  108. onSave: (text: string | null) => void;
  109. organization: Organization;
  110. ownership: IssueOwnership;
  111. project: Project;
  112. };
  113. export async function openCreateOwnershipRule(options: CreateOwnershipRuleModalOptions) {
  114. const mod = await import('sentry/components/modals/createOwnershipRuleModal');
  115. const {default: Modal, modalCss} = mod;
  116. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  117. }
  118. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  119. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  120. const {default: Modal, modalCss} = mod;
  121. openModal(deps => <Modal {...deps} {...options} />, {
  122. closeEvents: 'escape-key',
  123. modalCss,
  124. });
  125. }
  126. export async function openCommandPalette(options: ModalOptions = {}) {
  127. const mod = await import('sentry/components/modals/commandPalette');
  128. const {default: Modal, modalCss} = mod;
  129. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  130. }
  131. type RecoveryModalOptions = {
  132. authenticatorName: string;
  133. };
  134. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  135. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  136. const {default: Modal} = mod;
  137. openModal(deps => <Modal {...deps} {...options} />);
  138. }
  139. export type TeamAccessRequestModalOptions = {
  140. memberId: string;
  141. orgId: string;
  142. teamId: string;
  143. };
  144. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  145. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  146. const {default: Modal} = mod;
  147. openModal(deps => <Modal {...deps} {...options} />);
  148. }
  149. export async function redirectToProject(newProjectSlug: string) {
  150. const mod = await import('sentry/components/modals/redirectToProject');
  151. const {default: Modal} = mod;
  152. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  153. }
  154. type HelpSearchModalOptions = {
  155. organization?: Organization;
  156. placeholder?: string;
  157. };
  158. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  159. const mod = await import('sentry/components/modals/helpSearchModal');
  160. const {default: Modal, modalCss} = mod;
  161. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  162. }
  163. export type SentryAppDetailsModalOptions = {
  164. isInstalled: boolean;
  165. onInstall: () => Promise<void>;
  166. organization: Organization;
  167. sentryApp: SentryApp;
  168. onCloseModal?: () => void; // used for analytics
  169. };
  170. type DebugFileSourceModalOptions = {
  171. appStoreConnectSourcesQuantity: number;
  172. onSave: (data: Record<string, any>) => Promise<void>;
  173. organization: Organization;
  174. sourceType: CustomRepoType;
  175. appStoreConnectStatusData?: AppStoreConnectStatusData;
  176. onClose?: () => void;
  177. sourceConfig?: Record<string, any>;
  178. };
  179. export async function openDebugFileSourceModal({
  180. onClose,
  181. ...restOptions
  182. }: DebugFileSourceModalOptions) {
  183. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  184. const {default: Modal, modalCss} = mod;
  185. openModal(deps => <Modal {...deps} {...restOptions} />, {
  186. modalCss,
  187. onClose,
  188. });
  189. }
  190. export async function openInviteMembersModal({
  191. onClose,
  192. ...args
  193. }: inviteMembersModalOptions = {}) {
  194. const mod = await import('sentry/components/modals/inviteMembersModal');
  195. const {default: Modal, modalCss} = mod;
  196. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  197. }
  198. export async function openWidgetBuilderOverwriteModal(
  199. options: OverwriteWidgetModalProps
  200. ) {
  201. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  202. const {default: Modal, modalCss} = mod;
  203. openModal(deps => <Modal {...deps} {...options} />, {
  204. closeEvents: 'escape-key',
  205. modalCss,
  206. });
  207. }
  208. export async function openAddToDashboardModal(options) {
  209. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  210. const {default: Modal, modalCss} = mod;
  211. openModal(deps => <Modal {...deps} {...options} />, {
  212. closeEvents: 'escape-key',
  213. modalCss,
  214. });
  215. }
  216. export async function openReprocessEventModal({
  217. onClose,
  218. ...options
  219. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  220. const {ReprocessingEventModal} = await import(
  221. 'sentry/components/modals/reprocessEventModal'
  222. );
  223. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  224. }
  225. export async function demoSignupModal(options: ModalOptions = {}) {
  226. const mod = await import('sentry/components/modals/demoSignUp');
  227. const {default: Modal, modalCss} = mod;
  228. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  229. }
  230. export type DemoEndModalOptions = {
  231. orgSlug: string | null;
  232. tour: string;
  233. };
  234. export async function demoEndModal(options: DemoEndModalOptions) {
  235. const mod = await import('sentry/components/modals/demoEndModal');
  236. const {default: Modal, modalCss} = mod;
  237. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  238. }
  239. export async function openDashboardWidgetQuerySelectorModal(
  240. options: DashboardWidgetQuerySelectorModalOptions
  241. ) {
  242. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  243. const {default: Modal, modalCss} = mod;
  244. openModal(deps => <Modal {...deps} {...options} />, {
  245. closeEvents: 'escape-key',
  246. modalCss,
  247. });
  248. }
  249. export async function openWidgetViewerModal({
  250. onClose,
  251. ...options
  252. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  253. const mod = await import('sentry/components/modals/widgetViewerModal');
  254. const {default: Modal, modalCss} = mod;
  255. openModal(deps => <Modal {...deps} {...options} />, {
  256. closeEvents: 'escape-key',
  257. modalCss,
  258. onClose,
  259. });
  260. }
  261. export async function openCreateNewIntegrationModal(
  262. options: CreateNewIntegrationModalOptions
  263. ) {
  264. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  265. const {default: Modal} = mod;
  266. openModal(deps => <Modal {...deps} {...options} />);
  267. }
  268. export async function openCreateReleaseIntegration(
  269. options: CreateReleaseIntegrationModalOptions
  270. ) {
  271. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  272. const {default: Modal} = mod;
  273. openModal(deps => <Modal {...deps} {...options} />);
  274. }