modal.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. import type {ModalTypes} from 'sentry/components/globalModal';
  2. import type {CreateNewIntegrationModalOptions} from 'sentry/components/modals/createNewIntegrationModal';
  3. import type {CreateReleaseIntegrationModalOptions} from 'sentry/components/modals/createReleaseIntegrationModal';
  4. import type {DashboardWidgetQuerySelectorModalOptions} from 'sentry/components/modals/dashboardWidgetQuerySelectorModal';
  5. import {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  6. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  7. import {OverwriteWidgetModalProps} from 'sentry/components/modals/widgetBuilder/overwriteWidgetModal';
  8. import type {WidgetViewerModalOptions} from 'sentry/components/modals/widgetViewerModal';
  9. import ModalStore from 'sentry/stores/modalStore';
  10. import type {
  11. Event,
  12. Group,
  13. IssueOwnership,
  14. MissingMember,
  15. Organization,
  16. OrgRole,
  17. Project,
  18. SentryApp,
  19. Team,
  20. } from 'sentry/types';
  21. import {AppStoreConnectStatusData, CustomRepoType} from 'sentry/types/debugFiles';
  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 OpenSudoModalOptions = {
  40. isSuperuser?: boolean;
  41. needsReload?: boolean;
  42. onClose?: () => void;
  43. retryRequest?: () => Promise<any>;
  44. sudo?: boolean;
  45. };
  46. type EmailVerificationModalOptions = {
  47. actionMessage?: string;
  48. emailVerified?: boolean;
  49. onClose?: () => void;
  50. };
  51. type InviteMembersModalOptions = {
  52. initialData?: Partial<InviteRow>[];
  53. onClose?: () => void;
  54. source?: string;
  55. };
  56. export async function openSudo({onClose, ...args}: OpenSudoModalOptions = {}) {
  57. const mod = await import('sentry/components/modals/sudoModal');
  58. const {default: Modal} = mod;
  59. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  60. }
  61. export async function openEmailVerification({
  62. onClose,
  63. ...args
  64. }: EmailVerificationModalOptions = {}) {
  65. const mod = await import('sentry/components/modals/emailVerificationModal');
  66. const {default: Modal} = mod;
  67. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  68. }
  69. type OpenDiffModalOptions = {
  70. baseIssueId: Group['id'];
  71. orgId: Organization['id'];
  72. project: Project;
  73. targetIssueId: string;
  74. baseEventId?: Event['id'];
  75. targetEventId?: string;
  76. };
  77. export async function openDiffModal(options: OpenDiffModalOptions) {
  78. const mod = await import('sentry/components/modals/diffModal');
  79. const {default: Modal, modalCss} = mod;
  80. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  81. }
  82. type CreateTeamModalOptions = {
  83. /**
  84. * The organization to create a team for
  85. */
  86. organization: Organization;
  87. onClose?: (team: Team) => void;
  88. /**
  89. * 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
  90. */
  91. project?: Project;
  92. };
  93. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  94. const mod = await import('sentry/components/modals/createTeamModal');
  95. const {default: Modal} = mod;
  96. openModal(deps => <Modal {...deps} {...options} />);
  97. }
  98. type CreateOwnershipRuleModalOptions = {
  99. issueId: string;
  100. /**
  101. * The organization to create a rules for
  102. */
  103. organization: Organization;
  104. /**
  105. * The project to create a rules for
  106. */
  107. project: Project;
  108. /**
  109. * Suggestions will be created from the current event
  110. */
  111. eventData?: Event;
  112. };
  113. export type EditOwnershipRulesModalOptions = {
  114. onSave: (text: string | null) => void;
  115. organization: Organization;
  116. ownership: IssueOwnership;
  117. project: Project;
  118. };
  119. /**
  120. * Open the edit ownership modal within issue details
  121. */
  122. export async function openIssueOwnershipRuleModal(
  123. options: CreateOwnershipRuleModalOptions
  124. ) {
  125. const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
  126. const {default: Modal, modalCss} = mod;
  127. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  128. }
  129. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  130. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  131. const {default: Modal, modalCss} = mod;
  132. openModal(deps => <Modal {...deps} {...options} />, {
  133. closeEvents: 'escape-key',
  134. modalCss,
  135. });
  136. }
  137. export async function openCommandPalette(options: ModalOptions = {}) {
  138. const mod = await import('sentry/components/modals/commandPalette');
  139. const {default: Modal, modalCss} = mod;
  140. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  141. }
  142. type RecoveryModalOptions = {
  143. authenticatorName: string;
  144. };
  145. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  146. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  147. const {default: Modal} = mod;
  148. openModal(deps => <Modal {...deps} {...options} />);
  149. }
  150. export type TeamAccessRequestModalOptions = {
  151. memberId: string;
  152. orgId: string;
  153. teamId: string;
  154. };
  155. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  156. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  157. const {default: Modal} = mod;
  158. openModal(deps => <Modal {...deps} {...options} />);
  159. }
  160. export async function redirectToProject(newProjectSlug: string) {
  161. const mod = await import('sentry/components/modals/redirectToProject');
  162. const {default: Modal} = mod;
  163. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  164. }
  165. type HelpSearchModalOptions = {
  166. organization?: Organization;
  167. placeholder?: string;
  168. };
  169. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  170. const mod = await import('sentry/components/modals/helpSearchModal');
  171. const {default: Modal, modalCss} = mod;
  172. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  173. }
  174. export type SentryAppDetailsModalOptions = {
  175. isInstalled: boolean;
  176. onInstall: () => Promise<void>;
  177. organization: Organization;
  178. sentryApp: SentryApp;
  179. onCloseModal?: () => void; // used for analytics
  180. };
  181. type DebugFileSourceModalOptions = {
  182. appStoreConnectSourcesQuantity: number;
  183. onSave: (data: Record<string, any>) => Promise<void>;
  184. organization: Organization;
  185. sourceType: CustomRepoType;
  186. appStoreConnectStatusData?: AppStoreConnectStatusData;
  187. onClose?: () => void;
  188. sourceConfig?: Record<string, any>;
  189. };
  190. export async function openDebugFileSourceModal({
  191. onClose,
  192. ...restOptions
  193. }: DebugFileSourceModalOptions) {
  194. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  195. const {default: Modal, modalCss} = mod;
  196. openModal(deps => <Modal {...deps} {...restOptions} />, {
  197. modalCss,
  198. onClose,
  199. });
  200. }
  201. export async function openInviteMembersModal({
  202. onClose,
  203. ...args
  204. }: InviteMembersModalOptions = {}) {
  205. const mod = await import('sentry/components/modals/inviteMembersModal');
  206. const {default: Modal, modalCss} = mod;
  207. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  208. }
  209. type InviteMissingMembersModalOptions = {
  210. allowedRoles: OrgRole[];
  211. missingMembers: {integration: string; users: MissingMember[]};
  212. onClose: () => void;
  213. organization: Organization;
  214. };
  215. export async function openInviteMissingMembersModal({
  216. onClose,
  217. ...args
  218. }: InviteMissingMembersModalOptions) {
  219. const mod = await import('sentry/components/modals/inviteMissingMembersModal');
  220. const {default: Modal, modalCss} = mod;
  221. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  222. }
  223. export async function openWidgetBuilderOverwriteModal(
  224. options: OverwriteWidgetModalProps
  225. ) {
  226. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  227. const {default: Modal, modalCss} = mod;
  228. openModal(deps => <Modal {...deps} {...options} />, {
  229. closeEvents: 'escape-key',
  230. modalCss,
  231. });
  232. }
  233. export async function openAddToDashboardModal(options) {
  234. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  235. const {default: Modal, modalCss} = mod;
  236. openModal(deps => <Modal {...deps} {...options} />, {
  237. closeEvents: 'escape-key',
  238. modalCss,
  239. });
  240. }
  241. export async function openImportDashboardFromFileModal(options) {
  242. const mod = await import('sentry/components/modals/importDashboardFromFileModal');
  243. const {default: Modal, modalCss} = mod;
  244. openModal(deps => <Modal {...deps} {...options} />, {
  245. closeEvents: 'escape-key',
  246. modalCss,
  247. });
  248. }
  249. export async function openReprocessEventModal({
  250. onClose,
  251. ...options
  252. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  253. const {ReprocessingEventModal} = await import(
  254. 'sentry/components/modals/reprocessEventModal'
  255. );
  256. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  257. }
  258. export async function demoSignupModal(options: ModalOptions = {}) {
  259. const mod = await import('sentry/components/modals/demoSignUp');
  260. const {default: Modal, modalCss} = mod;
  261. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  262. }
  263. export type DemoEndModalOptions = {
  264. orgSlug: string | null;
  265. tour: string;
  266. };
  267. export async function demoEndModal(options: DemoEndModalOptions) {
  268. const mod = await import('sentry/components/modals/demoEndModal');
  269. const {default: Modal, modalCss} = mod;
  270. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  271. }
  272. export async function openDashboardWidgetQuerySelectorModal(
  273. options: DashboardWidgetQuerySelectorModalOptions
  274. ) {
  275. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  276. const {default: Modal, modalCss} = mod;
  277. openModal(deps => <Modal {...deps} {...options} />, {
  278. closeEvents: 'escape-key',
  279. modalCss,
  280. });
  281. }
  282. export async function openWidgetViewerModal({
  283. onClose,
  284. ...options
  285. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  286. const mod = await import('sentry/components/modals/widgetViewerModal');
  287. const {default: Modal, modalCss} = mod;
  288. openModal(deps => <Modal {...deps} {...options} />, {
  289. closeEvents: 'escape-key',
  290. modalCss,
  291. onClose,
  292. });
  293. }
  294. export async function openCreateNewIntegrationModal(
  295. options: CreateNewIntegrationModalOptions
  296. ) {
  297. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  298. const {default: Modal} = mod;
  299. openModal(deps => <Modal {...deps} {...options} />);
  300. }
  301. export async function openCreateReleaseIntegration(
  302. options: CreateReleaseIntegrationModalOptions
  303. ) {
  304. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  305. const {default: Modal} = mod;
  306. openModal(deps => <Modal {...deps} {...options} />);
  307. }