modal.tsx 12 KB

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