index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import type {Client} from 'sentry/api';
  4. import ErrorBoundary from 'sentry/components/errorBoundary';
  5. import NotFound from 'sentry/components/errors/notFound';
  6. import LoadingIndicator from 'sentry/components/loadingIndicator';
  7. import type {Organization} from 'sentry/types';
  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, api, location, children} = props;
  21. if (organization.features.includes('dashboards-edit')) {
  22. return <Fragment>{children}</Fragment>;
  23. }
  24. const params = {...props.params, orgId: organization.slug};
  25. return (
  26. <DashboardBasicFeature organization={organization}>
  27. <OrgDashboards
  28. api={api}
  29. location={location}
  30. params={params}
  31. organization={organization}
  32. >
  33. {({dashboard, dashboards, error, onDashboardUpdate}) => {
  34. return error ? (
  35. <NotFound />
  36. ) : dashboard ? (
  37. <ErrorBoundary>
  38. <DashboardDetail
  39. {...props}
  40. initialState={DashboardState.VIEW}
  41. dashboard={dashboard}
  42. dashboards={dashboards}
  43. onDashboardUpdate={onDashboardUpdate}
  44. />
  45. </ErrorBoundary>
  46. ) : (
  47. <LoadingIndicator />
  48. );
  49. }}
  50. </OrgDashboards>
  51. </DashboardBasicFeature>
  52. );
  53. }
  54. export default withApi(withOrganization(DashboardsV2Container));