modal.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. Organization,
  15. Project,
  16. SentryApp,
  17. Team,
  18. } from 'sentry/types';
  19. import {AppStoreConnectStatusData, CustomRepoType} from 'sentry/types/debugFiles';
  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 OpenSudoModalOptions = {
  38. isSuperuser?: boolean;
  39. needsReload?: boolean;
  40. onClose?: () => void;
  41. retryRequest?: () => Promise<any>;
  42. sudo?: boolean;
  43. };
  44. type EmailVerificationModalOptions = {
  45. actionMessage?: string;
  46. emailVerified?: boolean;
  47. onClose?: () => void;
  48. };
  49. type InviteMembersModalOptions = {
  50. initialData?: Partial<InviteRow>[];
  51. onClose?: () => void;
  52. source?: string;
  53. };
  54. export async function openSudo({onClose, ...args}: OpenSudoModalOptions = {}) {
  55. const mod = await import('sentry/components/modals/sudoModal');
  56. const {default: Modal} = mod;
  57. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  58. }
  59. export async function openEmailVerification({
  60. onClose,
  61. ...args
  62. }: EmailVerificationModalOptions = {}) {
  63. const mod = await import('sentry/components/modals/emailVerificationModal');
  64. const {default: Modal} = mod;
  65. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  66. }
  67. type OpenDiffModalOptions = {
  68. baseIssueId: Group['id'];
  69. orgId: Organization['id'];
  70. project: Project;
  71. targetIssueId: string;
  72. baseEventId?: Event['id'];
  73. targetEventId?: string;
  74. };
  75. export async function openDiffModal(options: OpenDiffModalOptions) {
  76. const mod = await import('sentry/components/modals/diffModal');
  77. const {default: Modal, modalCss} = mod;
  78. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  79. }
  80. type CreateTeamModalOptions = {
  81. /**
  82. * The organization to create a team for
  83. */
  84. organization: Organization;
  85. onClose?: (team: Team) => void;
  86. /**
  87. * 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
  88. */
  89. project?: Project;
  90. };
  91. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  92. const mod = await import('sentry/components/modals/createTeamModal');
  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. export type EditOwnershipRulesModalOptions = {
  112. onSave: (text: string | null) => void;
  113. organization: Organization;
  114. ownership: IssueOwnership;
  115. project: Project;
  116. };
  117. /**
  118. * Open the edit ownership modal within issue details
  119. */
  120. export async function openIssueOwnershipRuleModal(
  121. options: CreateOwnershipRuleModalOptions
  122. ) {
  123. const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
  124. const {default: Modal, modalCss} = mod;
  125. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  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. export async function redirectToProject(newProjectSlug: string) {
  159. const mod = await import('sentry/components/modals/redirectToProject');
  160. const {default: Modal} = mod;
  161. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  162. }
  163. type HelpSearchModalOptions = {
  164. organization?: Organization;
  165. placeholder?: string;
  166. };
  167. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  168. const mod = await import('sentry/components/modals/helpSearchModal');
  169. const {default: Modal, modalCss} = mod;
  170. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  171. }
  172. export type SentryAppDetailsModalOptions = {
  173. isInstalled: boolean;
  174. onInstall: () => Promise<void>;
  175. organization: Organization;
  176. sentryApp: SentryApp;
  177. onCloseModal?: () => void; // used for analytics
  178. };
  179. type DebugFileSourceModalOptions = {
  180. appStoreConnectSourcesQuantity: number;
  181. onSave: (data: Record<string, any>) => Promise<void>;
  182. organization: Organization;
  183. sourceType: CustomRepoType;
  184. appStoreConnectStatusData?: AppStoreConnectStatusData;
  185. onClose?: () => void;
  186. sourceConfig?: Record<string, any>;
  187. };
  188. export async function openDebugFileSourceModal({
  189. onClose,
  190. ...restOptions
  191. }: DebugFileSourceModalOptions) {
  192. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  193. const {default: Modal, modalCss} = mod;
  194. openModal(deps => <Modal {...deps} {...restOptions} />, {
  195. modalCss,
  196. onClose,
  197. });
  198. }
  199. export async function openInviteMembersModal({
  200. onClose,
  201. ...args
  202. }: InviteMembersModalOptions = {}) {
  203. const mod = await import('sentry/components/modals/inviteMembersModal');
  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 openReprocessEventModal({
  234. onClose,
  235. ...options
  236. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  237. const {ReprocessingEventModal} = await import(
  238. 'sentry/components/modals/reprocessEventModal'
  239. );
  240. openModal(deps => <ReprocessingEventModal {...deps} {...options} />, {onClose});
  241. }
  242. export async function demoSignupModal(options: ModalOptions = {}) {
  243. const mod = await import('sentry/components/modals/demoSignUp');
  244. const {default: Modal, modalCss} = mod;
  245. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  246. }
  247. export type DemoEndModalOptions = {
  248. orgSlug: string | null;
  249. tour: string;
  250. };
  251. export async function demoEndModal(options: DemoEndModalOptions) {
  252. const mod = await import('sentry/components/modals/demoEndModal');
  253. const {default: Modal, modalCss} = mod;
  254. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  255. }
  256. export async function openDashboardWidgetQuerySelectorModal(
  257. options: DashboardWidgetQuerySelectorModalOptions
  258. ) {
  259. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  260. const {default: Modal, modalCss} = mod;
  261. openModal(deps => <Modal {...deps} {...options} />, {
  262. closeEvents: 'escape-key',
  263. modalCss,
  264. });
  265. }
  266. export async function openWidgetViewerModal({
  267. onClose,
  268. ...options
  269. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  270. const mod = await import('sentry/components/modals/widgetViewerModal');
  271. const {default: Modal, modalCss} = mod;
  272. openModal(deps => <Modal {...deps} {...options} />, {
  273. closeEvents: 'escape-key',
  274. modalCss,
  275. onClose,
  276. });
  277. }
  278. export async function openCreateNewIntegrationModal(
  279. options: CreateNewIntegrationModalOptions
  280. ) {
  281. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  282. const {default: Modal} = mod;
  283. openModal(deps => <Modal {...deps} {...options} />);
  284. }
  285. export async function openCreateReleaseIntegration(
  286. options: CreateReleaseIntegrationModalOptions
  287. ) {
  288. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  289. const {default: Modal} = mod;
  290. openModal(deps => <Modal {...deps} {...options} />);
  291. }