modal.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 {ImportDashboardFromFileModalProps} from 'sentry/components/modals/importDashboardFromFileModal';
  7. import type {InsightChartModalOptions} from 'sentry/components/modals/insightChartModal';
  8. import type {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  9. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  10. import type {AddToDashboardModalProps} from 'sentry/components/modals/widgetBuilder/addToDashboardModal';
  11. import type {OverwriteWidgetModalProps} from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
  12. import type {WidgetViewerModalOptions} from 'sentry/components/modals/widgetViewerModal';
  13. import type {Category} from 'sentry/components/platformPicker';
  14. import ModalStore from 'sentry/stores/modalStore';
  15. import type {CustomRepoType} from 'sentry/types/debugFiles';
  16. import type {Event} from 'sentry/types/event';
  17. import type {Group, IssueOwnership} from 'sentry/types/group';
  18. import type {MissingMember, Organization, OrgRole, Team} from 'sentry/types/organization';
  19. import type {Project} from 'sentry/types/project';
  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 EmailVerificationModalOptions = {
  38. actionMessage?: string;
  39. emailVerified?: boolean;
  40. onClose?: () => void;
  41. };
  42. type InviteMembersModalOptions = {
  43. initialData?: Array<Partial<InviteRow>>;
  44. onClose?: () => void;
  45. source?: string;
  46. };
  47. export async function openEmailVerification({
  48. onClose,
  49. ...args
  50. }: EmailVerificationModalOptions = {}) {
  51. const mod = await import('sentry/components/modals/emailVerificationModal');
  52. const {default: Modal} = mod;
  53. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  54. }
  55. type OpenDiffModalOptions = {
  56. baseIssueId: Group['id'];
  57. location: Location;
  58. orgId: Organization['id'];
  59. project: Project;
  60. targetIssueId: string;
  61. baseEventId?: Event['id'];
  62. shouldBeGrouped?: string;
  63. targetEventId?: string;
  64. };
  65. export async function openDiffModal(options: OpenDiffModalOptions) {
  66. const mod = await import('sentry/components/modals/diffModal');
  67. const {default: Modal, modalCss} = mod;
  68. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  69. }
  70. type CreateTeamModalOptions = {
  71. /**
  72. * The organization to create a team for
  73. */
  74. organization: Organization;
  75. onClose?: (team: Team) => void;
  76. /**
  77. * 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
  78. */
  79. project?: Project;
  80. };
  81. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  82. const mod = await import('sentry/components/modals/createTeamModal');
  83. const {default: Modal} = mod;
  84. openModal(deps => <Modal {...deps} {...options} />);
  85. }
  86. type CreateOwnershipRuleModalOptions = {
  87. issueId: string;
  88. /**
  89. * The organization to create a rules for
  90. */
  91. organization: Organization;
  92. /**
  93. * The project to create a rules for
  94. */
  95. project: Project;
  96. /**
  97. * Suggestions will be created from the current event
  98. */
  99. eventData?: Event;
  100. };
  101. /**
  102. * Open the edit ownership modal within issue details
  103. */
  104. export async function openIssueOwnershipRuleModal(
  105. options: CreateOwnershipRuleModalOptions
  106. ) {
  107. const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
  108. const {default: Modal, modalCss} = mod;
  109. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  110. }
  111. export type EditOwnershipRulesModalOptions = {
  112. onSave: (ownership: IssueOwnership) => void;
  113. organization: Organization;
  114. ownership: IssueOwnership;
  115. project: Project;
  116. };
  117. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  118. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  119. const {default: Modal, modalCss} = mod;
  120. openModal(deps => <Modal {...deps} {...options} />, {
  121. closeEvents: 'escape-key',
  122. modalCss,
  123. });
  124. }
  125. export async function openCommandPalette(options: ModalOptions = {}) {
  126. const mod = await import('sentry/components/modals/commandPalette');
  127. const {default: Modal, modalCss} = mod;
  128. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  129. }
  130. type RecoveryModalOptions = {
  131. authenticatorName: string;
  132. };
  133. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  134. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  135. const {default: Modal} = mod;
  136. openModal(deps => <Modal {...deps} {...options} />);
  137. }
  138. export type TeamAccessRequestModalOptions = {
  139. memberId: string;
  140. orgId: string;
  141. teamId: string;
  142. };
  143. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  144. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  145. const {default: Modal} = mod;
  146. openModal(deps => <Modal {...deps} {...options} />);
  147. }
  148. type HelpSearchModalOptions = {
  149. organization?: Organization;
  150. placeholder?: string;
  151. };
  152. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  153. const mod = await import('sentry/components/modals/helpSearchModal');
  154. const {default: Modal, modalCss} = mod;
  155. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  156. }
  157. type DebugFileSourceModalOptions = {
  158. onSave: (data: Record<string, any>) => Promise<void>;
  159. organization: Organization;
  160. sourceType: CustomRepoType;
  161. onClose?: () => void;
  162. sourceConfig?: Record<string, any>;
  163. };
  164. export async function openDebugFileSourceModal({
  165. onClose,
  166. ...restOptions
  167. }: DebugFileSourceModalOptions) {
  168. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  169. const {default: Modal, modalCss} = mod;
  170. openModal(deps => <Modal {...deps} {...restOptions} />, {
  171. modalCss,
  172. onClose,
  173. });
  174. }
  175. export async function openInviteMembersModal({
  176. onClose,
  177. ...args
  178. }: InviteMembersModalOptions = {}) {
  179. const mod = await import('sentry/components/modals/inviteMembersModal');
  180. const {default: Modal, modalCss} = mod;
  181. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  182. }
  183. type InviteMissingMembersModalOptions = {
  184. allowedRoles: OrgRole[];
  185. missingMembers: MissingMember[];
  186. onClose: () => void;
  187. organization: Organization;
  188. };
  189. export async function openInviteMissingMembersModal({
  190. onClose,
  191. ...args
  192. }: InviteMissingMembersModalOptions) {
  193. const mod = await import('sentry/components/modals/inviteMissingMembersModal');
  194. const {default: Modal, modalCss} = mod;
  195. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  196. }
  197. export async function openWidgetBuilderOverwriteModal(
  198. options: OverwriteWidgetModalProps
  199. ) {
  200. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  201. const {default: Modal, modalCss} = mod;
  202. openModal(deps => <Modal {...deps} {...options} />, {
  203. closeEvents: 'escape-key',
  204. modalCss,
  205. });
  206. }
  207. export async function openAddToDashboardModal(options: AddToDashboardModalProps) {
  208. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  209. const {default: Modal, modalCss} = mod;
  210. openModal(deps => <Modal {...deps} {...options} />, {
  211. closeEvents: 'escape-key',
  212. modalCss,
  213. });
  214. }
  215. export async function openImportDashboardFromFileModal(
  216. options: ImportDashboardFromFileModalProps
  217. ) {
  218. const mod = await import('sentry/components/modals/importDashboardFromFileModal');
  219. const {default: Modal, modalCss} = mod;
  220. openModal(deps => <Modal {...deps} {...options} />, {
  221. closeEvents: 'escape-key',
  222. modalCss,
  223. });
  224. }
  225. export async function openReprocessEventModal({
  226. onClose,
  227. ...options
  228. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  229. const {ReprocessingEventModal} = await import(
  230. 'sentry/components/modals/reprocessEventModal'
  231. );
  232. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  233. }
  234. export async function demoSignupModal(options: ModalOptions = {}) {
  235. const mod = await import('sentry/components/modals/demoSignUp');
  236. const {default: Modal, modalCss} = mod;
  237. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  238. }
  239. export type DemoEndModalOptions = {
  240. orgSlug: string | null;
  241. tour: string;
  242. };
  243. export async function demoEndModal(options: DemoEndModalOptions) {
  244. const mod = await import('sentry/components/modals/demoEndModal');
  245. const {default: Modal, modalCss} = mod;
  246. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  247. }
  248. export type DemoEmailModalOptions = {
  249. onAddedEmail: (email: string) => void;
  250. onFailure: () => void;
  251. };
  252. export async function demoEmailModal(options: DemoEmailModalOptions) {
  253. const mod = await import('sentry/components/modals/demoEmailModal');
  254. const {default: Modal, modalCss} = mod;
  255. openModal(deps => <Modal {...deps} {...options} />, {closeEvents: 'none', modalCss});
  256. }
  257. export async function openDashboardWidgetQuerySelectorModal(
  258. options: DashboardWidgetQuerySelectorModalOptions
  259. ) {
  260. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  261. const {default: Modal, modalCss} = mod;
  262. openModal(deps => <Modal {...deps} {...options} />, {
  263. closeEvents: 'escape-key',
  264. modalCss,
  265. });
  266. }
  267. export async function openWidgetViewerModal({
  268. onClose,
  269. ...options
  270. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  271. const mod = await import('sentry/components/modals/widgetViewerModal');
  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. }
  318. export async function openAddTempestCredentialsModal(options: {
  319. organization: Organization;
  320. project: Project;
  321. }) {
  322. const mod = await import('sentry/components/modals/addTempestCredentialsModal');
  323. const {default: Modal} = mod;
  324. openModal(deps => <Modal {...deps} {...options} />);
  325. }