modal.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 {InsightChartModalOptions} from 'sentry/components/modals/insightChartModal';
  7. import type {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  8. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  9. import type {OverwriteWidgetModalProps} from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
  10. import type {WidgetViewerModalOptions} from 'sentry/components/modals/widgetViewerModal';
  11. import type {Category} from 'sentry/components/platformPicker';
  12. import ModalStore from 'sentry/stores/modalStore';
  13. import type {CustomRepoType} from 'sentry/types/debugFiles';
  14. import type {Event} from 'sentry/types/event';
  15. import type {Group, IssueOwnership} from 'sentry/types/group';
  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. type DebugFileSourceModalOptions = {
  157. onSave: (data: Record<string, any>) => Promise<void>;
  158. organization: Organization;
  159. sourceType: CustomRepoType;
  160. onClose?: () => void;
  161. sourceConfig?: Record<string, any>;
  162. };
  163. export async function openDebugFileSourceModal({
  164. onClose,
  165. ...restOptions
  166. }: DebugFileSourceModalOptions) {
  167. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  168. const {default: Modal, modalCss} = mod;
  169. openModal(deps => <Modal {...deps} {...restOptions} />, {
  170. modalCss,
  171. onClose,
  172. });
  173. }
  174. export async function openInviteMembersModal({
  175. onClose,
  176. ...args
  177. }: InviteMembersModalOptions = {}) {
  178. const mod = await import('sentry/components/modals/inviteMembersModal');
  179. const {default: Modal, modalCss} = mod;
  180. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  181. }
  182. type InviteMissingMembersModalOptions = {
  183. allowedRoles: OrgRole[];
  184. missingMembers: MissingMember[];
  185. onClose: () => void;
  186. organization: Organization;
  187. };
  188. export async function openInviteMissingMembersModal({
  189. onClose,
  190. ...args
  191. }: InviteMissingMembersModalOptions) {
  192. const mod = await import('sentry/components/modals/inviteMissingMembersModal');
  193. const {default: Modal, modalCss} = mod;
  194. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  195. }
  196. export async function openWidgetBuilderOverwriteModal(
  197. options: OverwriteWidgetModalProps
  198. ) {
  199. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  200. const {default: Modal, modalCss} = mod;
  201. openModal(deps => <Modal {...deps} {...options} />, {
  202. closeEvents: 'escape-key',
  203. modalCss,
  204. });
  205. }
  206. export async function openAddToDashboardModal(options) {
  207. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  208. const {default: Modal, modalCss} = mod;
  209. openModal(deps => <Modal {...deps} {...options} />, {
  210. closeEvents: 'escape-key',
  211. modalCss,
  212. });
  213. }
  214. export async function openImportDashboardFromFileModal(options) {
  215. const mod = await import('sentry/components/modals/importDashboardFromFileModal');
  216. const {default: Modal, modalCss} = mod;
  217. openModal(deps => <Modal {...deps} {...options} />, {
  218. closeEvents: 'escape-key',
  219. modalCss,
  220. });
  221. }
  222. export async function openCreateDashboardFromMetrics(options) {
  223. const mod = await import('sentry/components/modals/createDashboardFromMetricsModal');
  224. const {default: Modal, modalCss} = mod;
  225. openModal(deps => <Modal {...deps} {...options} />, {
  226. closeEvents: 'escape-key',
  227. modalCss,
  228. });
  229. }
  230. export async function openReprocessEventModal({
  231. onClose,
  232. ...options
  233. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  234. const {ReprocessingEventModal} = await import(
  235. 'sentry/components/modals/reprocessEventModal'
  236. );
  237. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  238. }
  239. export async function demoSignupModal(options: ModalOptions = {}) {
  240. const mod = await import('sentry/components/modals/demoSignUp');
  241. const {default: Modal, modalCss} = mod;
  242. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  243. }
  244. export type DemoEndModalOptions = {
  245. orgSlug: string | null;
  246. tour: string;
  247. };
  248. export async function demoEndModal(options: DemoEndModalOptions) {
  249. const mod = await import('sentry/components/modals/demoEndModal');
  250. const {default: Modal, modalCss} = mod;
  251. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  252. }
  253. export async function openDashboardWidgetQuerySelectorModal(
  254. options: DashboardWidgetQuerySelectorModalOptions
  255. ) {
  256. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  257. const {default: Modal, modalCss} = mod;
  258. openModal(deps => <Modal {...deps} {...options} />, {
  259. closeEvents: 'escape-key',
  260. modalCss,
  261. });
  262. }
  263. export async function openWidgetViewerModal({
  264. onClose,
  265. ...options
  266. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  267. const modalPromise =
  268. options.widget.widgetType === WidgetType.METRICS
  269. ? import('sentry/components/modals/metricWidgetViewerModal')
  270. : import('sentry/components/modals/widgetViewerModal');
  271. const mod = await modalPromise;
  272. const {default: Modal, modalCss} = mod;
  273. openModal(deps => <Modal {...deps} {...options} />, {
  274. closeEvents: 'none',
  275. modalCss,
  276. onClose,
  277. });
  278. }
  279. export async function openCreateNewIntegrationModal(
  280. options: CreateNewIntegrationModalOptions
  281. ) {
  282. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  283. const {default: Modal} = mod;
  284. openModal(deps => <Modal {...deps} {...options} />);
  285. }
  286. export async function openCreateReleaseIntegration(
  287. options: CreateReleaseIntegrationModalOptions
  288. ) {
  289. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  290. const {default: Modal} = mod;
  291. openModal(deps => <Modal {...deps} {...options} />);
  292. }
  293. export type NavigateToExternalLinkModalOptions = {
  294. linkText: string;
  295. };
  296. export async function openNavigateToExternalLinkModal(
  297. options: NavigateToExternalLinkModalOptions
  298. ) {
  299. const mod = await import('sentry/components/modals/navigateToExternalLinkModal');
  300. const {default: Modal} = mod;
  301. openModal(deps => <Modal {...deps} {...options} />);
  302. }
  303. export async function openProjectCreationModal(options: {defaultCategory: Category}) {
  304. const mod = await import('sentry/components/modals/projectCreationModal');
  305. const {default: Modal, modalCss} = mod;
  306. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  307. }
  308. export async function openBulkEditMonitorsModal({onClose, ...options}: ModalOptions) {
  309. const mod = await import('sentry/components/modals/bulkEditMonitorsModal');
  310. const {default: Modal, modalCss} = mod;
  311. openModal(deps => <Modal {...deps} {...options} />, {modalCss, onClose});
  312. }
  313. export async function openInsightChartModal(options: InsightChartModalOptions) {
  314. const mod = await import('sentry/components/modals/insightChartModal');
  315. const {default: Modal, modalCss} = mod;
  316. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  317. }