detail.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. import {cloneElement, Component, isValidElement} from 'react';
  2. import {browserHistory, PlainRoute, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import isEqual from 'lodash/isEqual';
  5. import omit from 'lodash/omit';
  6. import {
  7. createDashboard,
  8. deleteDashboard,
  9. updateDashboard,
  10. } from 'sentry/actionCreators/dashboards';
  11. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  12. import {openAddDashboardWidgetModal} from 'sentry/actionCreators/modal';
  13. import {Client} from 'sentry/api';
  14. import Breadcrumbs from 'sentry/components/breadcrumbs';
  15. import HookOrDefault from 'sentry/components/hookOrDefault';
  16. import * as Layout from 'sentry/components/layouts/thirds';
  17. import NoProjectMessage from 'sentry/components/noProjectMessage';
  18. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  19. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  20. import {t} from 'sentry/locale';
  21. import {PageContent} from 'sentry/styles/organization';
  22. import space from 'sentry/styles/space';
  23. import {Organization} from 'sentry/types';
  24. import {defined} from 'sentry/utils';
  25. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  26. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  27. import withApi from 'sentry/utils/withApi';
  28. import withOrganization from 'sentry/utils/withOrganization';
  29. import Controls from './controls';
  30. import Dashboard from './dashboard';
  31. import {DEFAULT_STATS_PERIOD} from './data';
  32. import {
  33. assignDefaultLayout,
  34. calculateColumnDepths,
  35. getDashboardLayout,
  36. } from './layoutUtils';
  37. import DashboardTitle from './title';
  38. import {
  39. DashboardDetails,
  40. DashboardListItem,
  41. DashboardState,
  42. DashboardWidgetSource,
  43. MAX_WIDGETS,
  44. Widget,
  45. } from './types';
  46. import {cloneDashboard} from './utils';
  47. const UNSAVED_MESSAGE = t('You have unsaved changes, are you sure you want to leave?');
  48. const HookHeader = HookOrDefault({hookName: 'component:dashboards-header'});
  49. type RouteParams = {
  50. orgId: string;
  51. dashboardId?: string;
  52. widgetId?: number;
  53. };
  54. type Props = RouteComponentProps<RouteParams, {}> & {
  55. api: Client;
  56. organization: Organization;
  57. initialState: DashboardState;
  58. dashboard: DashboardDetails;
  59. dashboards: DashboardListItem[];
  60. route: PlainRoute;
  61. onDashboardUpdate?: (updatedDashboard: DashboardDetails) => void;
  62. newWidget?: Widget;
  63. };
  64. type State = {
  65. dashboardState: DashboardState;
  66. modifiedDashboard: DashboardDetails | null;
  67. widgetLimitReached: boolean;
  68. widgetToBeUpdated?: Widget;
  69. };
  70. class DashboardDetail extends Component<Props, State> {
  71. state: State = {
  72. dashboardState: this.props.initialState,
  73. modifiedDashboard: this.updateModifiedDashboard(this.props.initialState),
  74. widgetLimitReached: this.props.dashboard.widgets.length >= MAX_WIDGETS,
  75. };
  76. componentDidMount() {
  77. const {route, router} = this.props;
  78. this.checkStateRoute();
  79. router.setRouteLeaveHook(route, this.onRouteLeave);
  80. window.addEventListener('beforeunload', this.onUnload);
  81. }
  82. componentDidUpdate(prevProps: Props) {
  83. if (prevProps.location.pathname !== this.props.location.pathname) {
  84. this.checkStateRoute();
  85. }
  86. }
  87. componentWillUnmount() {
  88. window.removeEventListener('beforeunload', this.onUnload);
  89. }
  90. checkStateRoute() {
  91. const {router, organization, params} = this.props;
  92. const {dashboardId} = params;
  93. const dashboardDetailsRoute = `/organizations/${organization.slug}/dashboard/${dashboardId}/`;
  94. if (this.isWidgetBuilderRouter && !this.isEditing) {
  95. router.replace(dashboardDetailsRoute);
  96. }
  97. if (location.pathname === dashboardDetailsRoute && !!this.state.widgetToBeUpdated) {
  98. this.onSetWidgetToBeUpdated(undefined);
  99. }
  100. }
  101. updateRouteAfterSavingWidget() {
  102. if (this.isWidgetBuilderRouter) {
  103. const {router, organization, params} = this.props;
  104. const {dashboardId} = params;
  105. if (dashboardId) {
  106. router.replace(`/organizations/${organization.slug}/dashboard/${dashboardId}/`);
  107. return;
  108. }
  109. router.replace(`/organizations/${organization.slug}/dashboards/new/`);
  110. }
  111. }
  112. updateModifiedDashboard(dashboardState: DashboardState) {
  113. const {dashboard} = this.props;
  114. switch (dashboardState) {
  115. case DashboardState.PREVIEW:
  116. case DashboardState.CREATE:
  117. case DashboardState.EDIT:
  118. return cloneDashboard(dashboard);
  119. default: {
  120. return null;
  121. }
  122. }
  123. }
  124. get isPreview() {
  125. const {dashboardState} = this.state;
  126. return DashboardState.PREVIEW === dashboardState;
  127. }
  128. get isEditing() {
  129. const {dashboardState} = this.state;
  130. return [
  131. DashboardState.EDIT,
  132. DashboardState.CREATE,
  133. DashboardState.PENDING_DELETE,
  134. ].includes(dashboardState);
  135. }
  136. get isWidgetBuilderRouter() {
  137. const {location, params, organization} = this.props;
  138. const {dashboardId} = params;
  139. const newWidgetRoutes = [
  140. `/organizations/${organization.slug}/dashboards/new/widget/new/`,
  141. `/organizations/${organization.slug}/dashboard/${dashboardId}/widget/new/`,
  142. ];
  143. return newWidgetRoutes.includes(location.pathname) || this.isWidgetBuilderEditRouter;
  144. }
  145. get isWidgetBuilderEditRouter() {
  146. const {location, params, organization} = this.props;
  147. const {dashboardId, widgetId} = params;
  148. const widgetEditRoutes = [
  149. `/organizations/${organization.slug}/dashboards/new/widget/${widgetId}/edit/`,
  150. `/organizations/${organization.slug}/dashboard/${dashboardId}/widget/${widgetId}/edit/`,
  151. ];
  152. return widgetEditRoutes.includes(location.pathname);
  153. }
  154. get dashboardTitle() {
  155. const {dashboard} = this.props;
  156. const {modifiedDashboard} = this.state;
  157. return modifiedDashboard ? modifiedDashboard.title : dashboard.title;
  158. }
  159. onEdit = () => {
  160. const {dashboard} = this.props;
  161. trackAnalyticsEvent({
  162. eventKey: 'dashboards2.edit.start',
  163. eventName: 'Dashboards2: Edit start',
  164. organization_id: parseInt(this.props.organization.id, 10),
  165. });
  166. this.setState({
  167. dashboardState: DashboardState.EDIT,
  168. modifiedDashboard: cloneDashboard(dashboard),
  169. });
  170. };
  171. onRouteLeave = () => {
  172. const {dashboard} = this.props;
  173. const {modifiedDashboard} = this.state;
  174. if (
  175. ![
  176. DashboardState.VIEW,
  177. DashboardState.PENDING_DELETE,
  178. DashboardState.PREVIEW,
  179. ].includes(this.state.dashboardState) &&
  180. !isEqual(modifiedDashboard, dashboard)
  181. ) {
  182. return UNSAVED_MESSAGE;
  183. }
  184. return undefined;
  185. };
  186. onUnload = (event: BeforeUnloadEvent) => {
  187. const {dashboard} = this.props;
  188. const {modifiedDashboard} = this.state;
  189. if (
  190. [
  191. DashboardState.VIEW,
  192. DashboardState.PENDING_DELETE,
  193. DashboardState.PREVIEW,
  194. ].includes(this.state.dashboardState) ||
  195. isEqual(modifiedDashboard, dashboard)
  196. ) {
  197. return;
  198. }
  199. event.preventDefault();
  200. event.returnValue = UNSAVED_MESSAGE;
  201. };
  202. onDelete = (dashboard: State['modifiedDashboard']) => () => {
  203. const {api, organization, location} = this.props;
  204. if (!dashboard?.id) {
  205. return;
  206. }
  207. const previousDashboardState = this.state.dashboardState;
  208. this.setState({dashboardState: DashboardState.PENDING_DELETE}, () => {
  209. deleteDashboard(api, organization.slug, dashboard.id)
  210. .then(() => {
  211. addSuccessMessage(t('Dashboard deleted'));
  212. trackAnalyticsEvent({
  213. eventKey: 'dashboards2.delete',
  214. eventName: 'Dashboards2: Delete',
  215. organization_id: parseInt(this.props.organization.id, 10),
  216. });
  217. browserHistory.replace({
  218. pathname: `/organizations/${organization.slug}/dashboards/`,
  219. query: location.query,
  220. });
  221. })
  222. .catch(() => {
  223. this.setState({
  224. dashboardState: previousDashboardState,
  225. });
  226. });
  227. });
  228. };
  229. onCancel = () => {
  230. const {organization, dashboard, location, params} = this.props;
  231. const {modifiedDashboard} = this.state;
  232. let hasDashboardChanged = !isEqual(modifiedDashboard, dashboard);
  233. // If a dashboard has every layout undefined, then ignore the layout field
  234. // when checking equality because it is a dashboard from before the grid feature
  235. const isLegacyLayout = dashboard.widgets.every(({layout}) => !defined(layout));
  236. if (isLegacyLayout) {
  237. hasDashboardChanged = !isEqual(
  238. {
  239. ...modifiedDashboard,
  240. widgets: modifiedDashboard?.widgets.map(widget => omit(widget, 'layout')),
  241. },
  242. {...dashboard, widgets: dashboard.widgets.map(widget => omit(widget, 'layout'))}
  243. );
  244. }
  245. // Don't confirm preview cancellation regardless of dashboard state
  246. if (hasDashboardChanged && !this.isPreview) {
  247. // Ignore no-alert here, so that the confirm on cancel matches onUnload & onRouteLeave
  248. /* eslint no-alert:0 */
  249. if (!confirm(UNSAVED_MESSAGE)) {
  250. return;
  251. }
  252. }
  253. if (params.dashboardId) {
  254. trackAnalyticsEvent({
  255. eventKey: 'dashboards2.edit.cancel',
  256. eventName: 'Dashboards2: Edit cancel',
  257. organization_id: parseInt(this.props.organization.id, 10),
  258. });
  259. this.setState({
  260. dashboardState: DashboardState.VIEW,
  261. modifiedDashboard: null,
  262. });
  263. return;
  264. }
  265. trackAnalyticsEvent({
  266. eventKey: 'dashboards2.create.cancel',
  267. eventName: 'Dashboards2: Create cancel',
  268. organization_id: parseInt(this.props.organization.id, 10),
  269. });
  270. browserHistory.replace({
  271. pathname: `/organizations/${organization.slug}/dashboards/`,
  272. query: location.query,
  273. });
  274. };
  275. handleUpdateWidgetList = (widgets: Widget[]) => {
  276. const {organization, dashboard, api, onDashboardUpdate, location} = this.props;
  277. const {modifiedDashboard} = this.state;
  278. // Use the new widgets for calculating layout because widgets has
  279. // the most up to date information in edit state
  280. const currentLayout = getDashboardLayout(widgets);
  281. const layoutColumnDepths = calculateColumnDepths(currentLayout);
  282. const newModifiedDashboard = {
  283. ...cloneDashboard(modifiedDashboard || dashboard),
  284. widgets: assignDefaultLayout(widgets, layoutColumnDepths),
  285. };
  286. this.setState({
  287. modifiedDashboard: newModifiedDashboard,
  288. widgetLimitReached: widgets.length >= MAX_WIDGETS,
  289. });
  290. if (this.isEditing || this.isPreview) {
  291. return;
  292. }
  293. updateDashboard(api, organization.slug, newModifiedDashboard).then(
  294. (newDashboard: DashboardDetails) => {
  295. if (onDashboardUpdate) {
  296. onDashboardUpdate(newDashboard);
  297. this.setState({
  298. modifiedDashboard: null,
  299. });
  300. }
  301. addSuccessMessage(t('Dashboard updated'));
  302. if (dashboard && newDashboard.id !== dashboard.id) {
  303. browserHistory.replace({
  304. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  305. query: {
  306. ...location.query,
  307. },
  308. });
  309. return;
  310. }
  311. },
  312. () => undefined
  313. );
  314. };
  315. handleAddCustomWidget = (widget: Widget) => {
  316. const {dashboard} = this.props;
  317. const {modifiedDashboard} = this.state;
  318. const newModifiedDashboard = modifiedDashboard || dashboard;
  319. this.onUpdateWidget([...newModifiedDashboard.widgets, widget]);
  320. };
  321. onAddWidget = () => {
  322. const {organization, dashboard} = this.props;
  323. this.setState({
  324. modifiedDashboard: cloneDashboard(dashboard),
  325. });
  326. openAddDashboardWidgetModal({
  327. organization,
  328. dashboard,
  329. onAddLibraryWidget: (widgets: Widget[]) => this.handleUpdateWidgetList(widgets),
  330. source: DashboardWidgetSource.LIBRARY,
  331. });
  332. };
  333. onCommit = () => {
  334. const {api, organization, location, dashboard, onDashboardUpdate} = this.props;
  335. const {modifiedDashboard, dashboardState} = this.state;
  336. switch (dashboardState) {
  337. case DashboardState.PREVIEW:
  338. case DashboardState.CREATE: {
  339. if (modifiedDashboard) {
  340. if (this.isPreview) {
  341. trackAdvancedAnalyticsEvent('dashboards_manage.templates.add', {
  342. organization,
  343. dashboard_id: dashboard.id,
  344. dashboard_title: dashboard.title,
  345. was_previewed: true,
  346. });
  347. }
  348. createDashboard(api, organization.slug, modifiedDashboard, this.isPreview).then(
  349. (newDashboard: DashboardDetails) => {
  350. addSuccessMessage(t('Dashboard created'));
  351. trackAnalyticsEvent({
  352. eventKey: 'dashboards2.create.complete',
  353. eventName: 'Dashboards2: Create complete',
  354. organization_id: parseInt(organization.id, 10),
  355. });
  356. this.setState({
  357. dashboardState: DashboardState.VIEW,
  358. });
  359. // redirect to new dashboard
  360. browserHistory.replace({
  361. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  362. query: {
  363. ...location.query,
  364. },
  365. });
  366. },
  367. () => undefined
  368. );
  369. }
  370. break;
  371. }
  372. case DashboardState.EDIT: {
  373. // only update the dashboard if there are changes
  374. if (modifiedDashboard) {
  375. if (isEqual(dashboard, modifiedDashboard)) {
  376. this.setState({
  377. dashboardState: DashboardState.VIEW,
  378. modifiedDashboard: null,
  379. });
  380. return;
  381. }
  382. updateDashboard(api, organization.slug, modifiedDashboard).then(
  383. (newDashboard: DashboardDetails) => {
  384. if (onDashboardUpdate) {
  385. onDashboardUpdate(newDashboard);
  386. }
  387. addSuccessMessage(t('Dashboard updated'));
  388. trackAnalyticsEvent({
  389. eventKey: 'dashboards2.edit.complete',
  390. eventName: 'Dashboards2: Edit complete',
  391. organization_id: parseInt(organization.id, 10),
  392. });
  393. this.setState({
  394. dashboardState: DashboardState.VIEW,
  395. modifiedDashboard: null,
  396. });
  397. if (dashboard && newDashboard.id !== dashboard.id) {
  398. browserHistory.replace({
  399. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  400. query: {
  401. ...location.query,
  402. },
  403. });
  404. return;
  405. }
  406. },
  407. () => undefined
  408. );
  409. return;
  410. }
  411. this.setState({
  412. dashboardState: DashboardState.VIEW,
  413. modifiedDashboard: null,
  414. });
  415. break;
  416. }
  417. case DashboardState.VIEW:
  418. default: {
  419. this.setState({
  420. dashboardState: DashboardState.VIEW,
  421. modifiedDashboard: null,
  422. });
  423. break;
  424. }
  425. }
  426. };
  427. setModifiedDashboard = (dashboard: DashboardDetails) => {
  428. this.setState({
  429. modifiedDashboard: dashboard,
  430. });
  431. };
  432. onSetWidgetToBeUpdated = (widget?: Widget) => {
  433. this.setState({widgetToBeUpdated: widget});
  434. };
  435. onUpdateWidget = (widgets: Widget[]) => {
  436. this.setState(
  437. (state: State) => ({
  438. ...state,
  439. widgetToBeUpdated: undefined,
  440. widgetLimitReached: widgets.length >= MAX_WIDGETS,
  441. modifiedDashboard: {
  442. ...(state.modifiedDashboard || this.props.dashboard),
  443. widgets,
  444. },
  445. }),
  446. this.updateRouteAfterSavingWidget
  447. );
  448. };
  449. renderWidgetBuilder(dashboard: DashboardDetails) {
  450. const {children} = this.props;
  451. const {modifiedDashboard, widgetToBeUpdated} = this.state;
  452. return isValidElement(children)
  453. ? cloneElement(children, {
  454. dashboard: modifiedDashboard ?? dashboard,
  455. onSave: this.onUpdateWidget,
  456. widget: widgetToBeUpdated,
  457. })
  458. : children;
  459. }
  460. renderDefaultDashboardDetail() {
  461. const {organization, dashboard, dashboards, params, router, location} = this.props;
  462. const {modifiedDashboard, dashboardState, widgetLimitReached} = this.state;
  463. const {dashboardId} = params;
  464. return (
  465. <PageFiltersContainer
  466. skipLoadLastUsed={organization.features.includes('global-views')}
  467. defaultSelection={{
  468. datetime: {
  469. start: null,
  470. end: null,
  471. utc: false,
  472. period: DEFAULT_STATS_PERIOD,
  473. },
  474. }}
  475. >
  476. <PageContent>
  477. <NoProjectMessage organization={organization}>
  478. <StyledPageHeader>
  479. <DashboardTitle
  480. dashboard={modifiedDashboard ?? dashboard}
  481. onUpdate={this.setModifiedDashboard}
  482. isEditing={this.isEditing}
  483. />
  484. <Controls
  485. organization={organization}
  486. dashboards={dashboards}
  487. onEdit={this.onEdit}
  488. onCancel={this.onCancel}
  489. onCommit={this.onCommit}
  490. onAddWidget={this.onAddWidget}
  491. onDelete={this.onDelete(dashboard)}
  492. dashboardState={dashboardState}
  493. widgetLimitReached={widgetLimitReached}
  494. />
  495. </StyledPageHeader>
  496. <HookHeader organization={organization} />
  497. <Dashboard
  498. paramDashboardId={dashboardId}
  499. dashboard={modifiedDashboard ?? dashboard}
  500. organization={organization}
  501. isEditing={this.isEditing}
  502. widgetLimitReached={widgetLimitReached}
  503. onUpdate={this.onUpdateWidget}
  504. onSetWidgetToBeUpdated={this.onSetWidgetToBeUpdated}
  505. handleUpdateWidgetList={this.handleUpdateWidgetList}
  506. handleAddCustomWidget={this.handleAddCustomWidget}
  507. isPreview={this.isPreview}
  508. router={router}
  509. location={location}
  510. />
  511. </NoProjectMessage>
  512. </PageContent>
  513. </PageFiltersContainer>
  514. );
  515. }
  516. getBreadcrumbLabel() {
  517. const {organization, dashboard} = this.props;
  518. const {dashboardState} = this.state;
  519. let label = this.dashboardTitle;
  520. if (dashboardState === DashboardState.CREATE) {
  521. label = t('Create Dashboard');
  522. } else if (this.isPreview) {
  523. label = t('Preview Dashboard');
  524. } else if (
  525. organization.features.includes('dashboards-edit') &&
  526. dashboard.id === 'default-overview'
  527. ) {
  528. label = t('Default Dashboard');
  529. }
  530. return label;
  531. }
  532. renderDashboardDetail() {
  533. const {organization, dashboard, dashboards, params, router, location, newWidget} =
  534. this.props;
  535. const {modifiedDashboard, dashboardState, widgetLimitReached} = this.state;
  536. const {dashboardId} = params;
  537. return (
  538. <SentryDocumentTitle title={dashboard.title} orgSlug={organization.slug}>
  539. <PageFiltersContainer
  540. skipLoadLastUsed={organization.features.includes('global-views')}
  541. defaultSelection={{
  542. datetime: {
  543. start: null,
  544. end: null,
  545. utc: false,
  546. period: DEFAULT_STATS_PERIOD,
  547. },
  548. }}
  549. >
  550. <StyledPageContent>
  551. <NoProjectMessage organization={organization}>
  552. <Layout.Header>
  553. <Layout.HeaderContent>
  554. <Breadcrumbs
  555. crumbs={[
  556. {
  557. label: t('Dashboards'),
  558. to: `/organizations/${organization.slug}/dashboards/`,
  559. },
  560. {
  561. label: this.getBreadcrumbLabel(),
  562. },
  563. ]}
  564. />
  565. <Layout.Title>
  566. <DashboardTitle
  567. dashboard={modifiedDashboard ?? dashboard}
  568. onUpdate={this.setModifiedDashboard}
  569. isEditing={this.isEditing}
  570. />
  571. </Layout.Title>
  572. </Layout.HeaderContent>
  573. <Layout.HeaderActions>
  574. <Controls
  575. organization={organization}
  576. dashboards={dashboards}
  577. onEdit={this.onEdit}
  578. onCancel={this.onCancel}
  579. onCommit={this.onCommit}
  580. onAddWidget={this.onAddWidget}
  581. onDelete={this.onDelete(dashboard)}
  582. dashboardState={dashboardState}
  583. widgetLimitReached={widgetLimitReached}
  584. />
  585. </Layout.HeaderActions>
  586. </Layout.Header>
  587. <Layout.Body>
  588. <Layout.Main fullWidth>
  589. <Dashboard
  590. paramDashboardId={dashboardId}
  591. dashboard={modifiedDashboard ?? dashboard}
  592. organization={organization}
  593. isEditing={this.isEditing}
  594. widgetLimitReached={widgetLimitReached}
  595. onUpdate={this.onUpdateWidget}
  596. handleUpdateWidgetList={this.handleUpdateWidgetList}
  597. handleAddCustomWidget={this.handleAddCustomWidget}
  598. onSetWidgetToBeUpdated={this.onSetWidgetToBeUpdated}
  599. router={router}
  600. location={location}
  601. newWidget={newWidget}
  602. isPreview={this.isPreview}
  603. />
  604. </Layout.Main>
  605. </Layout.Body>
  606. </NoProjectMessage>
  607. </StyledPageContent>
  608. </PageFiltersContainer>
  609. </SentryDocumentTitle>
  610. );
  611. }
  612. render() {
  613. const {organization, dashboard} = this.props;
  614. if (this.isEditing && this.isWidgetBuilderRouter) {
  615. return this.renderWidgetBuilder(dashboard);
  616. }
  617. if (organization.features.includes('dashboards-edit')) {
  618. return this.renderDashboardDetail();
  619. }
  620. return this.renderDefaultDashboardDetail();
  621. }
  622. }
  623. const StyledPageHeader = styled('div')`
  624. display: grid;
  625. grid-template-columns: minmax(0, 1fr);
  626. grid-row-gap: ${space(2)};
  627. align-items: center;
  628. margin-bottom: ${space(2)};
  629. @media (min-width: ${p => p.theme.breakpoints[1]}) {
  630. grid-template-columns: minmax(0, 1fr) max-content;
  631. grid-column-gap: ${space(2)};
  632. height: 40px;
  633. }
  634. `;
  635. const StyledPageContent = styled(PageContent)`
  636. padding: 0;
  637. `;
  638. export default withApi(withOrganization(DashboardDetail));