modal.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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 RemoteConfigCreateFeatureModalProps = {
  86. createFeature: (key: string, value: string) => void;
  87. isValid: (key: string) => boolean;
  88. };
  89. export async function openRemoteConfigCreateFeatureModal(
  90. options: RemoteConfigCreateFeatureModalProps
  91. ) {
  92. const mod = await import('sentry/components/modals/remoteConfigCreateFeatureModal');
  93. const {default: Modal} = mod;
  94. openModal(deps => <Modal {...deps} {...options} />);
  95. }
  96. type CreateOwnershipRuleModalOptions = {
  97. issueId: string;
  98. /**
  99. * The organization to create a rules for
  100. */
  101. organization: Organization;
  102. /**
  103. * The project to create a rules for
  104. */
  105. project: Project;
  106. /**
  107. * Suggestions will be created from the current event
  108. */
  109. eventData?: Event;
  110. };
  111. /**
  112. * Open the edit ownership modal within issue details
  113. */
  114. export async function openIssueOwnershipRuleModal(
  115. options: CreateOwnershipRuleModalOptions
  116. ) {
  117. const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
  118. const {default: Modal, modalCss} = mod;
  119. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  120. }
  121. export type EditOwnershipRulesModalOptions = {
  122. onSave: (ownership: IssueOwnership) => void;
  123. organization: Organization;
  124. ownership: IssueOwnership;
  125. project: Project;
  126. };
  127. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  128. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  129. const {default: Modal, modalCss} = mod;
  130. openModal(deps => <Modal {...deps} {...options} />, {
  131. closeEvents: 'escape-key',
  132. modalCss,
  133. });
  134. }
  135. export async function openCommandPalette(options: ModalOptions = {}) {
  136. const mod = await import('sentry/components/modals/commandPalette');
  137. const {default: Modal, modalCss} = mod;
  138. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  139. }
  140. type RecoveryModalOptions = {
  141. authenticatorName: string;
  142. };
  143. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  144. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  145. const {default: Modal} = mod;
  146. openModal(deps => <Modal {...deps} {...options} />);
  147. }
  148. export type TeamAccessRequestModalOptions = {
  149. memberId: string;
  150. orgId: string;
  151. teamId: string;
  152. };
  153. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  154. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  155. const {default: Modal} = mod;
  156. openModal(deps => <Modal {...deps} {...options} />);
  157. }
  158. type HelpSearchModalOptions = {
  159. organization?: Organization;
  160. placeholder?: string;
  161. };
  162. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  163. const mod = await import('sentry/components/modals/helpSearchModal');
  164. const {default: Modal, modalCss} = mod;
  165. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  166. }
  167. type DebugFileSourceModalOptions = {
  168. onSave: (data: Record<string, any>) => Promise<void>;
  169. organization: Organization;
  170. sourceType: CustomRepoType;
  171. onClose?: () => void;
  172. sourceConfig?: Record<string, any>;
  173. };
  174. export async function openDebugFileSourceModal({
  175. onClose,
  176. ...restOptions
  177. }: DebugFileSourceModalOptions) {
  178. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  179. const {default: Modal, modalCss} = mod;
  180. openModal(deps => <Modal {...deps} {...restOptions} />, {
  181. modalCss,
  182. onClose,
  183. });
  184. }
  185. export async function openInviteMembersModal({
  186. onClose,
  187. ...args
  188. }: InviteMembersModalOptions = {}) {
  189. const mod = await import('sentry/components/modals/inviteMembersModal');
  190. const {default: Modal, modalCss} = mod;
  191. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  192. }
  193. type InviteMissingMembersModalOptions = {
  194. allowedRoles: OrgRole[];
  195. missingMembers: MissingMember[];
  196. onClose: () => void;
  197. organization: Organization;
  198. };
  199. export async function openInviteMissingMembersModal({
  200. onClose,
  201. ...args
  202. }: InviteMissingMembersModalOptions) {
  203. const mod = await import('sentry/components/modals/inviteMissingMembersModal');
  204. const {default: Modal, modalCss} = mod;
  205. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  206. }
  207. export async function openWidgetBuilderOverwriteModal(
  208. options: OverwriteWidgetModalProps
  209. ) {
  210. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  211. const {default: Modal, modalCss} = mod;
  212. openModal(deps => <Modal {...deps} {...options} />, {
  213. closeEvents: 'escape-key',
  214. modalCss,
  215. });
  216. }
  217. export async function openAddToDashboardModal(options) {
  218. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  219. const {default: Modal, modalCss} = mod;
  220. openModal(deps => <Modal {...deps} {...options} />, {
  221. closeEvents: 'escape-key',
  222. modalCss,
  223. });
  224. }
  225. export async function openImportDashboardFromFileModal(options) {
  226. const mod = await import('sentry/components/modals/importDashboardFromFileModal');
  227. const {default: Modal, modalCss} = mod;
  228. openModal(deps => <Modal {...deps} {...options} />, {
  229. closeEvents: 'escape-key',
  230. modalCss,
  231. });
  232. }
  233. export async function openCreateDashboardFromMetrics(options) {
  234. const mod = await import('sentry/components/modals/createDashboardFromMetricsModal');
  235. const {default: Modal, modalCss} = mod;
  236. openModal(deps => <Modal {...deps} {...options} />, {
  237. closeEvents: 'escape-key',
  238. modalCss,
  239. });
  240. }
  241. export async function openReprocessEventModal({
  242. onClose,
  243. ...options
  244. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  245. const {ReprocessingEventModal} = await import(
  246. 'sentry/components/modals/reprocessEventModal'
  247. );
  248. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  249. }
  250. export async function demoSignupModal(options: ModalOptions = {}) {
  251. const mod = await import('sentry/components/modals/demoSignUp');
  252. const {default: Modal, modalCss} = mod;
  253. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  254. }
  255. export type DemoEndModalOptions = {
  256. orgSlug: string | null;
  257. tour: string;
  258. };
  259. export async function demoEndModal(options: DemoEndModalOptions) {
  260. const mod = await import('sentry/components/modals/demoEndModal');
  261. const {default: Modal, modalCss} = mod;
  262. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  263. }
  264. export async function openDashboardWidgetQuerySelectorModal(
  265. options: DashboardWidgetQuerySelectorModalOptions
  266. ) {
  267. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  268. const {default: Modal, modalCss} = mod;
  269. openModal(deps => <Modal {...deps} {...options} />, {
  270. closeEvents: 'escape-key',
  271. modalCss,
  272. });
  273. }
  274. export async function openWidgetViewerModal({
  275. onClose,
  276. ...options
  277. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  278. const modalPromise =
  279. options.widget.widgetType === WidgetType.METRICS
  280. ? import('sentry/components/modals/metricWidgetViewerModal')
  281. : import('sentry/components/modals/widgetViewerModal');
  282. const mod = await modalPromise;
  283. const {default: Modal, modalCss} = mod;
  284. openModal(deps => <Modal {...deps} {...options} />, {
  285. closeEvents: 'none',
  286. modalCss,
  287. onClose,
  288. });
  289. }
  290. export async function openCreateNewIntegrationModal(
  291. options: CreateNewIntegrationModalOptions
  292. ) {
  293. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  294. const {default: Modal} = mod;
  295. openModal(deps => <Modal {...deps} {...options} />);
  296. }
  297. export async function openCreateReleaseIntegration(
  298. options: CreateReleaseIntegrationModalOptions
  299. ) {
  300. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  301. const {default: Modal} = mod;
  302. openModal(deps => <Modal {...deps} {...options} />);
  303. }
  304. export type NavigateToExternalLinkModalOptions = {
  305. linkText: string;
  306. };
  307. export async function openNavigateToExternalLinkModal(
  308. options: NavigateToExternalLinkModalOptions
  309. ) {
  310. const mod = await import('sentry/components/modals/navigateToExternalLinkModal');
  311. const {default: Modal} = mod;
  312. openModal(deps => <Modal {...deps} {...options} />);
  313. }
  314. export async function openProjectCreationModal(options: {defaultCategory: Category}) {
  315. const mod = await import('sentry/components/modals/projectCreationModal');
  316. const {default: Modal, modalCss} = mod;
  317. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  318. }
  319. export async function openBulkEditMonitorsModal({onClose, ...options}: ModalOptions) {
  320. const mod = await import('sentry/components/modals/bulkEditMonitorsModal');
  321. const {default: Modal, modalCss} = mod;
  322. openModal(deps => <Modal {...deps} {...options} />, {modalCss, onClose});
  323. }
  324. export async function openInsightChartModal(options: InsightChartModalOptions) {
  325. const mod = await import('sentry/components/modals/insightChartModal');
  326. const {default: Modal, modalCss} = mod;
  327. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  328. }