index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {useEffect} from 'react';
  2. import Feature from 'sentry/components/acl/feature';
  3. import {Alert} from 'sentry/components/alert';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import NoProjectMessage from 'sentry/components/noProjectMessage';
  6. import {t} from 'sentry/locale';
  7. import {Organization} from 'sentry/types';
  8. import {QueryClient, QueryClientProvider} from 'sentry/utils/queryClient';
  9. import {useLocation} from 'sentry/utils/useLocation';
  10. import useRouter from 'sentry/utils/useRouter';
  11. import withOrganization from 'sentry/utils/withOrganization';
  12. type Props = {
  13. children: React.ReactChildren;
  14. organization: Organization;
  15. };
  16. const queryClient = new QueryClient();
  17. function StarfishContainer({organization, children}: Props) {
  18. const location = useLocation();
  19. const router = useRouter();
  20. const {slug} = organization;
  21. const projectId =
  22. slug === 'sentry' ? '1' : slug === 'cramer' ? '4504120414765056' : null;
  23. useEffect(() => {
  24. if (projectId && location.query.project !== projectId) {
  25. router.replace({
  26. pathname: location.pathname,
  27. query: {...location.query, project: projectId},
  28. });
  29. }
  30. }, [location.pathname, location.query, projectId, router]);
  31. return (
  32. <Feature
  33. hookName="feature-disabled:starfish-view"
  34. features={['starfish-view']}
  35. organization={organization}
  36. renderDisabled={NoAccess}
  37. >
  38. <NoProjectMessage organization={organization}>
  39. <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
  40. </NoProjectMessage>
  41. </Feature>
  42. );
  43. }
  44. function NoAccess() {
  45. return (
  46. <Layout.Page withPadding>
  47. <Alert type="warning">{t("You don't have access to this feature")}</Alert>
  48. </Layout.Page>
  49. );
  50. }
  51. export default withOrganization(StarfishContainer);