modal.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 type {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  6. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  7. import type {OverwriteWidgetModalProps} from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
  8. import type {WidgetViewerModalOptions} from 'sentry/components/modals/widgetViewerModal';
  9. import type {Category} from 'sentry/components/platformPicker';
  10. import ModalStore from 'sentry/stores/modalStore';
  11. import type {
  12. Event,
  13. Group,
  14. IssueOwnership,
  15. MissingMember,
  16. Organization,
  17. OrgRole,
  18. Project,
  19. SentryApp,
  20. Team,
  21. } from 'sentry/types';
  22. import type {AppStoreConnectStatusData, CustomRepoType} from 'sentry/types/debugFiles';
  23. export type ModalOptions = ModalTypes['options'];
  24. export type ModalRenderProps = ModalTypes['renderProps'];
  25. /**
  26. * Show a modal
  27. */
  28. export function openModal(
  29. renderer: (renderProps: ModalRenderProps) => React.ReactNode,
  30. options?: ModalOptions
  31. ) {
  32. ModalStore.openModal(renderer, options ?? {});
  33. }
  34. /**
  35. * Close modal
  36. */
  37. export function closeModal() {
  38. ModalStore.closeModal();
  39. }
  40. type EmailVerificationModalOptions = {
  41. actionMessage?: string;
  42. emailVerified?: boolean;
  43. onClose?: () => void;
  44. };
  45. type InviteMembersModalOptions = {
  46. initialData?: Partial<InviteRow>[];
  47. onClose?: () => void;
  48. source?: string;
  49. };
  50. export async function openEmailVerification({
  51. onClose,
  52. ...args
  53. }: EmailVerificationModalOptions = {}) {
  54. const mod = await import('sentry/components/modals/emailVerificationModal');
  55. const {default: Modal} = mod;
  56. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  57. }
  58. type OpenDiffModalOptions = {
  59. baseIssueId: Group['id'];
  60. orgId: Organization['id'];
  61. project: Project;
  62. targetIssueId: string;
  63. baseEventId?: Event['id'];
  64. targetEventId?: string;
  65. };
  66. export async function openDiffModal(options: OpenDiffModalOptions) {
  67. const mod = await import('sentry/components/modals/diffModal');
  68. const {default: Modal, modalCss} = mod;
  69. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  70. }
  71. type CreateTeamModalOptions = {
  72. /**
  73. * The organization to create a team for
  74. */
  75. organization: Organization;
  76. onClose?: (team: Team) => void;
  77. /**
  78. * 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
  79. */
  80. project?: Project;
  81. };
  82. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  83. const mod = await import('sentry/components/modals/createTeamModal');
  84. const {default: Modal} = mod;
  85. openModal(deps => <Modal {...deps} {...options} />);
  86. }
  87. type CreateOwnershipRuleModalOptions = {
  88. issueId: string;
  89. /**
  90. * The organization to create a rules for
  91. */
  92. organization: Organization;
  93. /**
  94. * The project to create a rules for
  95. */
  96. project: Project;
  97. /**
  98. * Suggestions will be created from the current event
  99. */
  100. eventData?: Event;
  101. };
  102. export type EditOwnershipRulesModalOptions = {
  103. onSave: (text: string | null) => void;
  104. organization: Organization;
  105. ownership: IssueOwnership;
  106. project: Project;
  107. };
  108. /**
  109. * Open the edit ownership modal within issue details
  110. */
  111. export async function openIssueOwnershipRuleModal(
  112. options: CreateOwnershipRuleModalOptions
  113. ) {
  114. const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
  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. type HelpSearchModalOptions = {
  150. organization?: Organization;
  151. placeholder?: string;
  152. };
  153. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  154. const mod = await import('sentry/components/modals/helpSearchModal');
  155. const {default: Modal, modalCss} = mod;
  156. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  157. }
  158. export type SentryAppDetailsModalOptions = {
  159. isInstalled: boolean;
  160. onInstall: () => Promise<void>;
  161. organization: Organization;
  162. sentryApp: SentryApp;
  163. onCloseModal?: () => void; // used for analytics
  164. };
  165. type DebugFileSourceModalOptions = {
  166. appStoreConnectSourcesQuantity: number;
  167. onSave: (data: Record<string, any>) => Promise<void>;
  168. organization: Organization;
  169. sourceType: CustomRepoType;
  170. appStoreConnectStatusData?: AppStoreConnectStatusData;
  171. onClose?: () => void;
  172. sourceConfig?: Record<string, any>;
  173. };
  174. export async function openDebugFileSourceModal({
  175. onClose,
  176. ...restOptions
  177. }: DebugFileSourceModalOptions) {
  178. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  179. const {default: Modal, modalCss} = mod;
  180. openModal(deps => <Modal {...deps} {...restOptions} />, {
  181. modalCss,
  182. onClose,
  183. });
  184. }
  185. export async function openInviteMembersModal({
  186. onClose,
  187. ...args
  188. }: InviteMembersModalOptions = {}) {
  189. const mod = await import('sentry/components/modals/inviteMembersModal');
  190. const {default: Modal, modalCss} = mod;
  191. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  192. }
  193. type InviteMissingMembersModalOptions = {
  194. allowedRoles: OrgRole[];
  195. missingMembers: MissingMember[];
  196. onClose: () => void;
  197. organization: Organization;
  198. };
  199. export async function openInviteMissingMembersModal({
  200. onClose,
  201. ...args
  202. }: InviteMissingMembersModalOptions) {
  203. const mod = await import('sentry/components/modals/inviteMissingMembersModal');
  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 openImportDashboardFromFileModal(options) {
  226. const mod = await import('sentry/components/modals/importDashboardFromFileModal');
  227. const {default: Modal, modalCss} = mod;
  228. openModal(deps => <Modal {...deps} {...options} />, {
  229. closeEvents: 'escape-key',
  230. modalCss,
  231. });
  232. }
  233. export async function openCreateDashboardFromScratchpad(options) {
  234. const mod = await import('sentry/components/modals/createDashboardFromScratchpadModal');
  235. const {default: Modal, modalCss} = mod;
  236. openModal(deps => <Modal {...deps} {...options} />, {
  237. closeEvents: 'escape-key',
  238. modalCss,
  239. });
  240. }
  241. export async function openReprocessEventModal({
  242. onClose,
  243. ...options
  244. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  245. const {ReprocessingEventModal} = await import(
  246. 'sentry/components/modals/reprocessEventModal'
  247. );
  248. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  249. }
  250. export async function demoSignupModal(options: ModalOptions = {}) {
  251. const mod = await import('sentry/components/modals/demoSignUp');
  252. const {default: Modal, modalCss} = mod;
  253. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  254. }
  255. export type DemoEndModalOptions = {
  256. orgSlug: string | null;
  257. tour: string;
  258. };
  259. export async function demoEndModal(options: DemoEndModalOptions) {
  260. const mod = await import('sentry/components/modals/demoEndModal');
  261. const {default: Modal, modalCss} = mod;
  262. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  263. }
  264. export async function openDashboardWidgetQuerySelectorModal(
  265. options: DashboardWidgetQuerySelectorModalOptions
  266. ) {
  267. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  268. const {default: Modal, modalCss} = mod;
  269. openModal(deps => <Modal {...deps} {...options} />, {
  270. closeEvents: 'escape-key',
  271. modalCss,
  272. });
  273. }
  274. export async function openWidgetViewerModal({
  275. onClose,
  276. ...options
  277. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  278. const mod = await import('sentry/components/modals/widgetViewerModal');
  279. const {default: Modal, modalCss} = mod;
  280. openModal(deps => <Modal {...deps} {...options} />, {
  281. closeEvents: 'escape-key',
  282. modalCss,
  283. onClose,
  284. });
  285. }
  286. export async function openCreateNewIntegrationModal(
  287. options: CreateNewIntegrationModalOptions
  288. ) {
  289. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  290. const {default: Modal} = mod;
  291. openModal(deps => <Modal {...deps} {...options} />);
  292. }
  293. export async function openCreateReleaseIntegration(
  294. options: CreateReleaseIntegrationModalOptions
  295. ) {
  296. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  297. const {default: Modal} = mod;
  298. openModal(deps => <Modal {...deps} {...options} />);
  299. }
  300. export type NavigateToExternalLinkModalOptions = {
  301. linkText: string;
  302. };
  303. export async function openNavigateToExternalLinkModal(
  304. options: NavigateToExternalLinkModalOptions
  305. ) {
  306. const mod = await import('sentry/components/modals/navigateToExternalLinkModal');
  307. const {default: Modal} = mod;
  308. openModal(deps => <Modal {...deps} {...options} />);
  309. }
  310. export async function openProjectCreationModal(options: {defaultCategory: Category}) {
  311. const mod = await import('sentry/components/modals/projectCreationModal');
  312. const {default: Modal, modalCss} = mod;
  313. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  314. }
  315. export async function openBulkEditMonitorsModal({onClose, ...options}: ModalOptions) {
  316. const mod = await import('sentry/components/modals/bulkEditMonitorsModal');
  317. const {default: Modal, modalCss} = mod;
  318. openModal(deps => <Modal {...deps} {...options} />, {modalCss, onClose});
  319. }