modal.tsx 12 KB

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