modal.tsx 13 KB

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