modal.tsx 12 KB

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