index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {Fragment} from 'react';
  2. import type {Client} from 'sentry/api';
  3. import ErrorBoundary from 'sentry/components/errorBoundary';
  4. import NotFound from 'sentry/components/errors/notFound';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  7. import type {Organization} from 'sentry/types/organization';
  8. import withApi from 'sentry/utils/withApi';
  9. import withOrganization from 'sentry/utils/withOrganization';
  10. import DashboardDetail from './detail';
  11. import OrgDashboards from './orgDashboards';
  12. import {DashboardState} from './types';
  13. import {DashboardBasicFeature} from './view';
  14. type Props = RouteComponentProps<{}, {}> & {
  15. api: Client;
  16. children: React.ReactNode;
  17. organization: Organization;
  18. };
  19. function DashboardsV2Container(props: Props) {
  20. const {organization, children} = props;
  21. if (organization.features.includes('dashboards-edit')) {
  22. return <Fragment>{children}</Fragment>;
  23. }
  24. return (
  25. <DashboardBasicFeature organization={organization}>
  26. <OrgDashboards>
  27. {({dashboard, dashboards, error, onDashboardUpdate}) => {
  28. return error ? (
  29. <NotFound />
  30. ) : dashboard ? (
  31. <ErrorBoundary>
  32. <DashboardDetail
  33. {...props}
  34. initialState={DashboardState.VIEW}
  35. dashboard={dashboard}
  36. dashboards={dashboards}
  37. onDashboardUpdate={onDashboardUpdate}
  38. />
  39. </ErrorBoundary>
  40. ) : (
  41. <LoadingIndicator />
  42. );
  43. }}
  44. </OrgDashboards>
  45. </DashboardBasicFeature>
  46. );
  47. }
  48. export default withApi(withOrganization(DashboardsV2Container));