modal.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 {
  11. Group,
  12. IssueOwnership,
  13. Organization,
  14. Project,
  15. SentryApp,
  16. Team,
  17. } from 'sentry/types';
  18. import {AppStoreConnectStatusData, CustomRepoType} from 'sentry/types/debugFiles';
  19. import {Event} from 'sentry/types/event';
  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. export type EditOwnershipRulesModalOptions = {
  108. onSave: (text: string | null) => void;
  109. organization: Organization;
  110. ownership: IssueOwnership;
  111. project: Project;
  112. };
  113. export async function openCreateOwnershipRule(options: CreateOwnershipRuleModalOptions) {
  114. const mod = await import('sentry/components/modals/createOwnershipRuleModal');
  115. const {default: Modal, modalCss} = mod;
  116. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  117. }
  118. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  119. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  120. const {default: Modal, modalCss} = mod;
  121. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  122. }
  123. export async function openCommandPalette(options: ModalOptions = {}) {
  124. const mod = await import('sentry/components/modals/commandPalette');
  125. const {default: Modal, modalCss} = mod;
  126. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  127. }
  128. type RecoveryModalOptions = {
  129. authenticatorName: string;
  130. };
  131. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  132. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  133. const {default: Modal} = mod;
  134. openModal(deps => <Modal {...deps} {...options} />);
  135. }
  136. export type TeamAccessRequestModalOptions = {
  137. memberId: string;
  138. orgId: string;
  139. teamId: string;
  140. };
  141. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  142. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  143. const {default: Modal} = mod;
  144. openModal(deps => <Modal {...deps} {...options} />);
  145. }
  146. export async function redirectToProject(newProjectSlug: string) {
  147. const mod = await import('sentry/components/modals/redirectToProject');
  148. const {default: Modal} = mod;
  149. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  150. }
  151. type HelpSearchModalOptions = {
  152. organization?: Organization;
  153. placeholder?: string;
  154. };
  155. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  156. const mod = await import('sentry/components/modals/helpSearchModal');
  157. const {default: Modal, modalCss} = mod;
  158. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  159. }
  160. export type SentryAppDetailsModalOptions = {
  161. isInstalled: boolean;
  162. onInstall: () => Promise<void>;
  163. organization: Organization;
  164. sentryApp: SentryApp;
  165. onCloseModal?: () => void; // used for analytics
  166. };
  167. type DebugFileSourceModalOptions = {
  168. appStoreConnectSourcesQuantity: number;
  169. onSave: (data: Record<string, any>) => Promise<void>;
  170. organization: Organization;
  171. sourceType: CustomRepoType;
  172. appStoreConnectStatusData?: AppStoreConnectStatusData;
  173. onClose?: () => void;
  174. sourceConfig?: Record<string, any>;
  175. };
  176. export async function openDebugFileSourceModal({
  177. onClose,
  178. ...restOptions
  179. }: DebugFileSourceModalOptions) {
  180. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  181. const {default: Modal, modalCss} = mod;
  182. openModal(deps => <Modal {...deps} {...restOptions} />, {
  183. modalCss,
  184. onClose,
  185. });
  186. }
  187. export async function openInviteMembersModal({
  188. onClose,
  189. ...args
  190. }: inviteMembersModalOptions = {}) {
  191. const mod = await import('sentry/components/modals/inviteMembersModal');
  192. const {default: Modal, modalCss} = mod;
  193. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  194. }
  195. export async function openWidgetBuilderOverwriteModal(
  196. options: OverwriteWidgetModalProps
  197. ) {
  198. const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
  199. const {default: Modal, modalCss} = mod;
  200. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  201. }
  202. export async function openAddToDashboardModal(options) {
  203. const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
  204. const {default: Modal, modalCss} = mod;
  205. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  206. }
  207. export async function openReprocessEventModal({
  208. onClose,
  209. ...options
  210. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  211. const mod = await import('sentry/components/modals/reprocessEventModal');
  212. const {default: Modal} = mod;
  213. openModal(deps => <Modal {...deps} {...options} />, {onClose});
  214. }
  215. export async function demoSignupModal(options: ModalOptions = {}) {
  216. const mod = await import('sentry/components/modals/demoSignUp');
  217. const {default: Modal, modalCss} = mod;
  218. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  219. }
  220. export async function demoSignupModalV2(options: ModalOptions = {}) {
  221. const mod = await import('sentry/components/modals/demoSignUpV2');
  222. const {default: Modal, modalCss} = mod;
  223. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  224. }
  225. export async function openDashboardWidgetQuerySelectorModal(
  226. options: DashboardWidgetQuerySelectorModalOptions
  227. ) {
  228. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  229. const {default: Modal, modalCss} = mod;
  230. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  231. }
  232. export async function openWidgetViewerModal({
  233. onClose,
  234. ...options
  235. }: WidgetViewerModalOptions & {onClose?: () => void}) {
  236. const mod = await import('sentry/components/modals/widgetViewerModal');
  237. const {default: Modal, modalCss} = mod;
  238. openModal(deps => <Modal {...deps} {...options} />, {
  239. backdrop: 'static',
  240. modalCss,
  241. onClose,
  242. });
  243. }
  244. export async function openCreateNewIntegrationModal(
  245. options: CreateNewIntegrationModalOptions
  246. ) {
  247. const mod = await import('sentry/components/modals/createNewIntegrationModal');
  248. const {default: Modal} = mod;
  249. openModal(deps => <Modal {...deps} {...options} />);
  250. }
  251. export async function openCreateReleaseIntegration(
  252. options: CreateReleaseIntegrationModalOptions
  253. ) {
  254. const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
  255. const {default: Modal} = mod;
  256. openModal(deps => <Modal {...deps} {...options} />);
  257. }