index.tsx 913 B

123456789101112131415161718192021222324252627282930
  1. import {cloneElement, isValidElement} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import useProjects from 'sentry/utils/useProjects';
  6. interface Props extends RouteComponentProps<{projectId: string; ruleId: string}, {}> {
  7. children?: React.ReactNode;
  8. }
  9. function RuleDetailsContainer({children, params}: Props) {
  10. const organization = useOrganization();
  11. const {projects, fetching} = useProjects();
  12. const project = projects.find(({slug}) => slug === params.projectId);
  13. // Should almost never need to fetch project
  14. if (fetching) {
  15. return <LoadingIndicator />;
  16. }
  17. return children && isValidElement(children)
  18. ? cloneElement<any>(children, {
  19. organization,
  20. project,
  21. })
  22. : null;
  23. }
  24. export default RuleDetailsContainer;