modal.tsx 7.8 KB

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