create.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import Feature from 'app/components/acl/feature';
  4. import Alert from 'app/components/alert';
  5. import {t} from 'app/locale';
  6. import {PageContent} from 'app/styles/organization';
  7. import {Organization} from 'app/types';
  8. import withOrganization from 'app/utils/withOrganization';
  9. import {EMPTY_DASHBOARD} from './data';
  10. import DashboardDetail from './detail';
  11. import {DashboardState} from './types';
  12. import {cloneDashboard, constructWidgetFromQuery} from './utils';
  13. type Props = RouteComponentProps<{orgId: string}, {}> & {
  14. organization: Organization;
  15. children: React.ReactNode;
  16. };
  17. function CreateDashboard(props: Props) {
  18. const {location} = props;
  19. function renderDisabled() {
  20. return (
  21. <PageContent>
  22. <Alert type="warning">{t("You don't have access to this feature")}</Alert>
  23. </PageContent>
  24. );
  25. }
  26. const dashboard = cloneDashboard(EMPTY_DASHBOARD);
  27. const newWidget = constructWidgetFromQuery(location.query);
  28. if (newWidget) {
  29. browserHistory.replace(location.pathname);
  30. }
  31. return (
  32. <Feature
  33. features={['dashboards-edit']}
  34. organization={props.organization}
  35. renderDisabled={renderDisabled}
  36. >
  37. <DashboardDetail
  38. {...props}
  39. initialState={DashboardState.CREATE}
  40. dashboard={dashboard}
  41. dashboards={[]}
  42. newWidget={newWidget}
  43. />
  44. </Feature>
  45. );
  46. }
  47. export default withOrganization(CreateDashboard);