modal.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import * as React from 'react';
  2. import ModalActions from 'sentry/actions/modalActions';
  3. import type {ModalTypes} from 'sentry/components/globalModal';
  4. import type {DashboardIssueWidgetModalOptions} from 'sentry/components/modals/addDashboardIssueWidgetModal';
  5. import type {DashboardWidgetModalOptions} from 'sentry/components/modals/addDashboardWidgetModal';
  6. import {DashboardWidgetLibraryModalOptions} from 'sentry/components/modals/dashboardWidgetLibraryModal';
  7. import type {DashboardWidgetQuerySelectorModalOptions} from 'sentry/components/modals/dashboardWidgetQuerySelectorModal';
  8. import {InviteRow} from 'sentry/components/modals/inviteMembersModal/types';
  9. import type {ReprocessEventModalOptions} from 'sentry/components/modals/reprocessEventModal';
  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. ModalActions.openModal(renderer, options ?? {});
  30. }
  31. /**
  32. * Close modal
  33. */
  34. export function closeModal() {
  35. ModalActions.closeModal();
  36. }
  37. type OpenSudoModalOptions = {
  38. onClose?: () => void;
  39. superuser?: boolean;
  40. sudo?: boolean;
  41. retryRequest?: () => Promise<any>;
  42. };
  43. type emailVerificationModalOptions = {
  44. onClose?: () => void;
  45. emailVerified?: boolean;
  46. actionMessage?: string;
  47. };
  48. type inviteMembersModalOptions = {
  49. onClose?: () => void;
  50. initialData?: Partial<InviteRow>[];
  51. source?: string;
  52. };
  53. export async function openSudo({onClose, ...args}: OpenSudoModalOptions = {}) {
  54. const mod = await import('sentry/components/modals/sudoModal');
  55. const {default: Modal} = mod;
  56. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  57. }
  58. export async function openEmailVerification({
  59. onClose,
  60. ...args
  61. }: emailVerificationModalOptions = {}) {
  62. const mod = await import('sentry/components/modals/emailVerificationModal');
  63. const {default: Modal} = mod;
  64. openModal(deps => <Modal {...deps} {...args} />, {onClose});
  65. }
  66. type OpenDiffModalOptions = {
  67. targetIssueId: string;
  68. project: Project;
  69. baseIssueId: Group['id'];
  70. orgId: Organization['id'];
  71. baseEventId?: Event['id'];
  72. targetEventId?: string;
  73. };
  74. export async function openDiffModal(options: OpenDiffModalOptions) {
  75. const mod = await import('sentry/components/modals/diffModal');
  76. const {default: Modal, modalCss} = mod;
  77. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  78. }
  79. type CreateTeamModalOptions = {
  80. /**
  81. * The organization to create a team for
  82. */
  83. organization: Organization;
  84. /**
  85. * 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
  86. */
  87. project?: Project;
  88. onClose?: (team: Team) => void;
  89. };
  90. export async function openCreateTeamModal(options: CreateTeamModalOptions) {
  91. const mod = await import('sentry/components/modals/createTeamModal');
  92. const {default: Modal} = mod;
  93. openModal(deps => <Modal {...deps} {...options} />);
  94. }
  95. type CreateOwnershipRuleModalOptions = {
  96. /**
  97. * The organization to create a rules for
  98. */
  99. organization: Organization;
  100. /**
  101. * The project to create a rules for
  102. */
  103. project: Project;
  104. issueId: string;
  105. };
  106. export type EditOwnershipRulesModalOptions = {
  107. organization: Organization;
  108. project: Project;
  109. ownership: IssueOwnership;
  110. onSave: (text: string | null) => void;
  111. };
  112. export async function openCreateOwnershipRule(options: CreateOwnershipRuleModalOptions) {
  113. const mod = await import('sentry/components/modals/createOwnershipRuleModal');
  114. const {default: Modal, modalCss} = mod;
  115. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  116. }
  117. export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
  118. const mod = await import('sentry/components/modals/editOwnershipRulesModal');
  119. const {default: Modal, modalCss} = mod;
  120. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  121. }
  122. export async function openCommandPalette(options: ModalOptions = {}) {
  123. const mod = await import('sentry/components/modals/commandPalette');
  124. const {default: Modal, modalCss} = mod;
  125. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  126. }
  127. type RecoveryModalOptions = {
  128. authenticatorName: string;
  129. };
  130. export async function openRecoveryOptions(options: RecoveryModalOptions) {
  131. const mod = await import('sentry/components/modals/recoveryOptionsModal');
  132. const {default: Modal} = mod;
  133. openModal(deps => <Modal {...deps} {...options} />);
  134. }
  135. export type TeamAccessRequestModalOptions = {
  136. memberId: string;
  137. teamId: string;
  138. orgId: string;
  139. };
  140. export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
  141. const mod = await import('sentry/components/modals/teamAccessRequestModal');
  142. const {default: Modal} = mod;
  143. openModal(deps => <Modal {...deps} {...options} />);
  144. }
  145. export async function redirectToProject(newProjectSlug: string) {
  146. const mod = await import('sentry/components/modals/redirectToProject');
  147. const {default: Modal} = mod;
  148. openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
  149. }
  150. type HelpSearchModalOptions = {
  151. organization?: Organization;
  152. placeholder?: string;
  153. };
  154. export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
  155. const mod = await import('sentry/components/modals/helpSearchModal');
  156. const {default: Modal, modalCss} = mod;
  157. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  158. }
  159. export type SentryAppDetailsModalOptions = {
  160. sentryApp: SentryApp;
  161. isInstalled: boolean;
  162. onInstall: () => Promise<void>;
  163. organization: Organization;
  164. onCloseModal?: () => void; // used for analytics
  165. };
  166. type DebugFileSourceModalOptions = {
  167. sourceType: CustomRepoType;
  168. onSave: (data: Record<string, any>) => Promise<void>;
  169. appStoreConnectStatusData?: AppStoreConnectStatusData;
  170. onClose?: () => void;
  171. sourceConfig?: Record<string, any>;
  172. };
  173. export async function openDebugFileSourceModal({
  174. onClose,
  175. ...restOptions
  176. }: DebugFileSourceModalOptions) {
  177. const mod = await import('sentry/components/modals/debugFileCustomRepository');
  178. const {default: Modal, modalCss} = mod;
  179. openModal(deps => <Modal {...deps} {...restOptions} />, {
  180. modalCss,
  181. onClose,
  182. });
  183. }
  184. export async function openInviteMembersModal({
  185. onClose,
  186. ...args
  187. }: inviteMembersModalOptions = {}) {
  188. const mod = await import('sentry/components/modals/inviteMembersModal');
  189. const {default: Modal, modalCss} = mod;
  190. openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
  191. }
  192. export async function openAddDashboardWidgetModal(options: DashboardWidgetModalOptions) {
  193. const mod = await import('sentry/components/modals/addDashboardWidgetModal');
  194. const {default: Modal, modalCss} = mod;
  195. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  196. }
  197. export async function openAddDashboardIssueWidgetModal(
  198. options: DashboardIssueWidgetModalOptions
  199. ) {
  200. const issuesModal = await import(
  201. 'sentry/components/modals/addDashboardIssueWidgetModal'
  202. );
  203. const {default: Modal, modalCss} = issuesModal;
  204. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  205. }
  206. export async function openReprocessEventModal({
  207. onClose,
  208. ...options
  209. }: ReprocessEventModalOptions & {onClose?: () => void}) {
  210. const mod = await import('sentry/components/modals/reprocessEventModal');
  211. const {default: Modal} = mod;
  212. openModal(deps => <Modal {...deps} {...options} />, {onClose});
  213. }
  214. export async function demoSignupModal(options: ModalOptions = {}) {
  215. const mod = await import('sentry/components/modals/demoSignUp');
  216. const {default: Modal, modalCss} = mod;
  217. openModal(deps => <Modal {...deps} {...options} />, {modalCss});
  218. }
  219. export async function openDashboardWidgetQuerySelectorModal(
  220. options: DashboardWidgetQuerySelectorModalOptions
  221. ) {
  222. const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
  223. const {default: Modal, modalCss} = mod;
  224. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  225. }
  226. export async function openDashboardWidgetLibraryModal(
  227. options: DashboardWidgetLibraryModalOptions
  228. ) {
  229. const mod = await import('sentry/components/modals/dashboardWidgetLibraryModal');
  230. const {default: Modal, modalCss} = mod;
  231. openModal(deps => <Modal {...deps} {...options} />, {backdrop: 'static', modalCss});
  232. }