index.tsx 893 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
  7. extends RouteComponentProps<{orgId: string; projectId: string; ruleId: string}, {}> {
  8. children?: React.ReactNode;
  9. }
  10. function RuleDetailsContainer({children, params}: Props) {
  11. const organization = useOrganization();
  12. const {projects, fetching} = useProjects({slugs: [params.projectId]});
  13. // Should almost never need to fetch project
  14. if (fetching) {
  15. return <LoadingIndicator />;
  16. }
  17. return children && isValidElement(children)
  18. ? cloneElement(children, {
  19. organization,
  20. project: projects[0],
  21. })
  22. : null;
  23. }
  24. export default RuleDetailsContainer;