detail.tsx 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. import {cloneElement, Component, Fragment, isValidElement} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import isEqual from 'lodash/isEqual';
  5. import isEqualWith from 'lodash/isEqualWith';
  6. import omit from 'lodash/omit';
  7. import pick from 'lodash/pick';
  8. import {
  9. createDashboard,
  10. deleteDashboard,
  11. updateDashboard,
  12. updateDashboardPermissions,
  13. } from 'sentry/actionCreators/dashboards';
  14. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  15. import {openWidgetViewerModal} from 'sentry/actionCreators/modal';
  16. import type {Client} from 'sentry/api';
  17. import {hasEveryAccess} from 'sentry/components/acl/access';
  18. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  19. import HookOrDefault from 'sentry/components/hookOrDefault';
  20. import * as Layout from 'sentry/components/layouts/thirds';
  21. import {
  22. isWidgetViewerPath,
  23. WidgetViewerQueryField,
  24. } from 'sentry/components/modals/widgetViewerModal/utils';
  25. import NoProjectMessage from 'sentry/components/noProjectMessage';
  26. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  27. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  28. import {USING_CUSTOMER_DOMAIN} from 'sentry/constants';
  29. import {t} from 'sentry/locale';
  30. import {space} from 'sentry/styles/space';
  31. import type {PageFilters} from 'sentry/types/core';
  32. import type {PlainRoute, RouteComponentProps} from 'sentry/types/legacyReactRouter';
  33. import type {Organization, Team} from 'sentry/types/organization';
  34. import type {Project} from 'sentry/types/project';
  35. import type {User} from 'sentry/types/user';
  36. import {defined} from 'sentry/utils';
  37. import {trackAnalytics} from 'sentry/utils/analytics';
  38. import {browserHistory} from 'sentry/utils/browserHistory';
  39. import EventView from 'sentry/utils/discover/eventView';
  40. import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
  41. import {MetricsResultsMetaProvider} from 'sentry/utils/performance/contexts/metricsEnhancedPerformanceDataContext';
  42. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  43. import {OnDemandControlProvider} from 'sentry/utils/performance/contexts/onDemandControl';
  44. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  45. import withApi from 'sentry/utils/withApi';
  46. import withOrganization from 'sentry/utils/withOrganization';
  47. import withPageFilters from 'sentry/utils/withPageFilters';
  48. import withProjects from 'sentry/utils/withProjects';
  49. import {defaultMetricWidget} from 'sentry/views/dashboards/metrics/utils';
  50. import {
  51. cloneDashboard,
  52. getCurrentPageFilters,
  53. getDashboardFiltersFromURL,
  54. hasUnsavedFilterChanges,
  55. isWidgetUsingTransactionName,
  56. resetPageFilters,
  57. } from 'sentry/views/dashboards/utils';
  58. import WidgetBuilderV2 from 'sentry/views/dashboards/widgetBuilder/components/newWidgetBuilder';
  59. import {DataSet} from 'sentry/views/dashboards/widgetBuilder/utils';
  60. import {convertWidgetToBuilderStateParams} from 'sentry/views/dashboards/widgetBuilder/utils/convertWidgetToBuilderStateParams';
  61. import WidgetLegendNameEncoderDecoder from 'sentry/views/dashboards/widgetLegendNameEncoderDecoder';
  62. import {MetricsDataSwitcherAlert} from 'sentry/views/performance/landing/metricsDataSwitcherAlert';
  63. import {generatePerformanceEventView} from '../performance/data';
  64. import {MetricsDataSwitcher} from '../performance/landing/metricsDataSwitcher';
  65. import {DiscoverQueryPageSource} from '../performance/utils';
  66. import type {WidgetViewerContextProps} from './widgetViewer/widgetViewerContext';
  67. import {WidgetViewerContext} from './widgetViewer/widgetViewerContext';
  68. import Controls from './controls';
  69. import Dashboard from './dashboard';
  70. import {DEFAULT_STATS_PERIOD} from './data';
  71. import FiltersBar from './filtersBar';
  72. import {
  73. assignDefaultLayout,
  74. assignTempId,
  75. calculateColumnDepths,
  76. generateWidgetsAfterCompaction,
  77. getDashboardLayout,
  78. } from './layoutUtils';
  79. import DashboardTitle from './title';
  80. import type {
  81. DashboardDetails,
  82. DashboardFilters,
  83. DashboardListItem,
  84. DashboardPermissions,
  85. Widget,
  86. } from './types';
  87. import {
  88. DashboardFilterKeys,
  89. DashboardState,
  90. DashboardWidgetSource,
  91. MAX_WIDGETS,
  92. WidgetType,
  93. } from './types';
  94. import WidgetLegendSelectionState from './widgetLegendSelectionState';
  95. const UNSAVED_MESSAGE = t('You have unsaved changes, are you sure you want to leave?');
  96. export const UNSAVED_FILTERS_MESSAGE = t(
  97. 'You have unsaved dashboard filters. You can save or discard them.'
  98. );
  99. const HookHeader = HookOrDefault({hookName: 'component:dashboards-header'});
  100. type RouteParams = {
  101. dashboardId?: string;
  102. templateId?: string;
  103. widgetId?: number | string;
  104. widgetIndex?: number;
  105. };
  106. type Props = RouteComponentProps<RouteParams, {}> & {
  107. api: Client;
  108. dashboard: DashboardDetails;
  109. dashboards: DashboardListItem[];
  110. initialState: DashboardState;
  111. organization: Organization;
  112. projects: Project[];
  113. route: PlainRoute;
  114. selection: PageFilters;
  115. children?: React.ReactNode;
  116. newWidget?: Widget;
  117. onDashboardUpdate?: (updatedDashboard: DashboardDetails) => void;
  118. onSetNewWidget?: () => void;
  119. };
  120. type State = {
  121. dashboardState: DashboardState;
  122. isWidgetBuilderOpen: boolean;
  123. modifiedDashboard: DashboardDetails | null;
  124. widgetLegendState: WidgetLegendSelectionState;
  125. widgetLimitReached: boolean;
  126. } & WidgetViewerContextProps;
  127. export function handleUpdateDashboardSplit({
  128. widgetId,
  129. splitDecision,
  130. dashboard,
  131. onDashboardUpdate,
  132. modifiedDashboard,
  133. stateSetter,
  134. }: {
  135. dashboard: DashboardDetails;
  136. modifiedDashboard: DashboardDetails | null;
  137. splitDecision: WidgetType;
  138. stateSetter: Component<Props, State, any>['setState'];
  139. widgetId: string;
  140. onDashboardUpdate?: (updatedDashboard: DashboardDetails) => void;
  141. }) {
  142. // The underlying dashboard needs to be updated with the split decision
  143. // because the backend has evaluated the query and stored that value
  144. const updatedDashboard = cloneDashboard(dashboard);
  145. const widgetIndex = updatedDashboard.widgets.findIndex(
  146. widget => widget.id === widgetId
  147. );
  148. if (widgetIndex >= 0) {
  149. updatedDashboard.widgets[widgetIndex].widgetType = splitDecision;
  150. }
  151. onDashboardUpdate?.(updatedDashboard);
  152. // The modified dashboard also needs to be updated because that dashboard
  153. // is rendered instead of the original dashboard when editing
  154. if (modifiedDashboard) {
  155. stateSetter(state => ({
  156. ...state,
  157. modifiedDashboard: {
  158. ...state.modifiedDashboard!,
  159. widgets: state.modifiedDashboard!.widgets.map(widget =>
  160. widget.id === widgetId ? {...widget, widgetType: splitDecision} : widget
  161. ),
  162. },
  163. }));
  164. }
  165. }
  166. /* Checks if current user has permissions to edit dashboard */
  167. export function checkUserHasEditAccess(
  168. currentUser: User,
  169. userTeams: Team[],
  170. organization: Organization,
  171. dashboardPermissions?: DashboardPermissions,
  172. dashboardCreator?: User
  173. ): boolean {
  174. if (
  175. !organization.features.includes('dashboards-edit-access') ||
  176. hasEveryAccess(['org:write'], {organization}) || // Managers and Owners
  177. !dashboardPermissions ||
  178. dashboardPermissions.isEditableByEveryone ||
  179. dashboardCreator?.id === currentUser.id
  180. ) {
  181. return true;
  182. }
  183. if (dashboardPermissions.teamsWithEditAccess?.length) {
  184. const userTeamIds = userTeams.map(team => Number(team.id));
  185. return dashboardPermissions.teamsWithEditAccess.some(teamId =>
  186. userTeamIds.includes(teamId)
  187. );
  188. }
  189. return false;
  190. }
  191. function getDashboardLocation({
  192. organization,
  193. dashboardId,
  194. location,
  195. }: {
  196. location: Location<any>;
  197. organization: Organization;
  198. dashboardId?: string;
  199. }) {
  200. // Preserve important filter params
  201. const filterParams = pick(location.query, [
  202. 'release',
  203. 'environment',
  204. 'project',
  205. 'statsPeriod',
  206. 'start',
  207. 'end',
  208. ]);
  209. const commonPath = defined(dashboardId)
  210. ? `/dashboard/${dashboardId}/`
  211. : `/dashboards/new/`;
  212. const dashboardUrl = USING_CUSTOMER_DOMAIN
  213. ? commonPath
  214. : `/organizations/${organization.slug}${commonPath}`;
  215. return normalizeUrl({
  216. pathname: dashboardUrl,
  217. query: filterParams,
  218. });
  219. }
  220. class DashboardDetail extends Component<Props, State> {
  221. state: State = {
  222. dashboardState: this.props.initialState,
  223. modifiedDashboard: this.updateModifiedDashboard(this.props.initialState),
  224. widgetLimitReached: this.props.dashboard.widgets.length >= MAX_WIDGETS,
  225. setData: data => {
  226. this.setState(data);
  227. },
  228. widgetLegendState: new WidgetLegendSelectionState({
  229. dashboard: this.props.dashboard,
  230. organization: this.props.organization,
  231. location: this.props.location,
  232. router: this.props.router,
  233. }),
  234. isWidgetBuilderOpen: this.isRedesignedWidgetBuilder,
  235. };
  236. componentDidMount() {
  237. this.checkIfShouldMountWidgetViewerModal();
  238. }
  239. componentDidUpdate(prevProps: Props) {
  240. this.checkIfShouldMountWidgetViewerModal();
  241. if (prevProps.initialState !== this.props.initialState) {
  242. // Widget builder can toggle Edit state when saving
  243. this.setState({dashboardState: this.props.initialState});
  244. }
  245. if (
  246. prevProps.organization !== this.props.organization ||
  247. prevProps.location !== this.props.location ||
  248. prevProps.router !== this.props.router ||
  249. prevProps.dashboard !== this.props.dashboard
  250. ) {
  251. this.setState({
  252. widgetLegendState: new WidgetLegendSelectionState({
  253. organization: this.props.organization,
  254. location: this.props.location,
  255. router: this.props.router,
  256. dashboard: this.props.dashboard,
  257. }),
  258. });
  259. }
  260. }
  261. checkIfShouldMountWidgetViewerModal() {
  262. const {
  263. params: {widgetId, dashboardId},
  264. organization,
  265. dashboard,
  266. location,
  267. router,
  268. } = this.props;
  269. const {seriesData, tableData, pageLinks, totalIssuesCount, seriesResultsType} =
  270. this.state;
  271. if (isWidgetViewerPath(location.pathname)) {
  272. const widget =
  273. defined(widgetId) &&
  274. (dashboard.widgets.find(({id}) => {
  275. // This ternary exists because widgetId is in some places typed as string, while
  276. // in other cases it is typed as number. Instead of changing the type everywhere,
  277. // we check for both cases at runtime as I am not sure which is the correct type.
  278. return typeof widgetId === 'number' ? id === String(widgetId) : id === widgetId;
  279. }) ??
  280. dashboard.widgets[widgetId]);
  281. if (widget) {
  282. openWidgetViewerModal({
  283. organization,
  284. widget,
  285. seriesData: WidgetLegendNameEncoderDecoder.modifyTimeseriesNames(
  286. widget,
  287. seriesData
  288. ),
  289. seriesResultsType,
  290. tableData,
  291. pageLinks,
  292. totalIssuesCount,
  293. widgetLegendState: this.state.widgetLegendState,
  294. dashboardFilters: getDashboardFiltersFromURL(location) ?? dashboard.filters,
  295. dashboardPermissions: dashboard.permissions,
  296. dashboardCreator: dashboard.createdBy,
  297. onMetricWidgetEdit: (updatedWidget: Widget) => {
  298. const widgets = [...dashboard.widgets];
  299. const widgetIndex = dashboard.widgets.indexOf(widget);
  300. widgets[widgetIndex] = {...widgets[widgetIndex], ...updatedWidget};
  301. this.handleUpdateWidgetList(widgets);
  302. },
  303. onClose: () => {
  304. // Filter out Widget Viewer Modal query params when exiting the Modal
  305. const query = omit(location.query, Object.values(WidgetViewerQueryField));
  306. router.push({
  307. pathname: location.pathname.replace(/widget\/[0-9]+\/$/, ''),
  308. query,
  309. });
  310. },
  311. onEdit: () => {
  312. const widgetIndex = dashboard.widgets.indexOf(widget);
  313. if (organization.features.includes('dashboards-widget-builder-redesign')) {
  314. this.onEditWidget(widget);
  315. return;
  316. }
  317. if (dashboardId) {
  318. const query = omit(location.query, Object.values(WidgetViewerQueryField));
  319. router.push(
  320. normalizeUrl({
  321. pathname: `/organizations/${organization.slug}/dashboard/${dashboardId}/widget/${widgetIndex}/edit/`,
  322. query: {
  323. ...query,
  324. source: DashboardWidgetSource.DASHBOARDS,
  325. },
  326. })
  327. );
  328. return;
  329. }
  330. },
  331. });
  332. trackAnalytics('dashboards_views.widget_viewer.open', {
  333. organization,
  334. widget_type: widget.widgetType ?? WidgetType.DISCOVER,
  335. display_type: widget.displayType,
  336. });
  337. } else {
  338. // Replace the URL if the widget isn't found and raise an error in toast
  339. router.replace(
  340. normalizeUrl({
  341. pathname: `/organizations/${organization.slug}/dashboard/${dashboard.id}/`,
  342. query: location.query,
  343. })
  344. );
  345. addErrorMessage(t('Widget not found'));
  346. }
  347. }
  348. }
  349. updateModifiedDashboard(dashboardState: DashboardState) {
  350. const {dashboard} = this.props;
  351. switch (dashboardState) {
  352. case DashboardState.PREVIEW:
  353. case DashboardState.CREATE:
  354. case DashboardState.EDIT:
  355. return cloneDashboard(dashboard);
  356. default: {
  357. return null;
  358. }
  359. }
  360. }
  361. get isPreview() {
  362. const {dashboardState} = this.state;
  363. return DashboardState.PREVIEW === dashboardState;
  364. }
  365. get isEditingDashboard() {
  366. const {dashboardState} = this.state;
  367. return [
  368. DashboardState.EDIT,
  369. DashboardState.CREATE,
  370. DashboardState.PENDING_DELETE,
  371. ].includes(dashboardState);
  372. }
  373. get isWidgetBuilderRouter() {
  374. const {location, params, organization} = this.props;
  375. const {dashboardId, widgetIndex} = params;
  376. const widgetBuilderRoutes = [
  377. `/organizations/${organization.slug}/dashboards/new/widget/new/`,
  378. `/organizations/${organization.slug}/dashboard/${dashboardId}/widget/new/`,
  379. `/organizations/${organization.slug}/dashboards/new/widget/${widgetIndex}/edit/`,
  380. `/organizations/${organization.slug}/dashboard/${dashboardId}/widget/${widgetIndex}/edit/`,
  381. ];
  382. if (USING_CUSTOMER_DOMAIN) {
  383. // TODO: replace with url generation later on.
  384. widgetBuilderRoutes.push(
  385. ...[
  386. `/dashboards/new/widget/new/`,
  387. `/dashboard/${dashboardId}/widget/new/`,
  388. `/dashboards/new/widget/${widgetIndex}/edit/`,
  389. `/dashboard/${dashboardId}/widget/${widgetIndex}/edit/`,
  390. ]
  391. );
  392. }
  393. return widgetBuilderRoutes.includes(location.pathname);
  394. }
  395. get isRedesignedWidgetBuilder() {
  396. const {organization, location, params} = this.props;
  397. const {dashboardId, widgetIndex} = params;
  398. if (!organization.features.includes('dashboards-widget-builder-redesign')) {
  399. return false;
  400. }
  401. const widgetBuilderRoutes = [
  402. `/organizations/${organization.slug}/dashboard/new/widget-builder/widget/new/`,
  403. `/organizations/${organization.slug}/dashboard/${dashboardId}/widget-builder/widget/new/`,
  404. `/organizations/${organization.slug}/dashboard/new/widget-builder/widget/${widgetIndex}/edit/`,
  405. `/organizations/${organization.slug}/dashboard/${dashboardId}/widget-builder/widget/${widgetIndex}/edit/`,
  406. ];
  407. if (USING_CUSTOMER_DOMAIN) {
  408. widgetBuilderRoutes.push(
  409. ...[
  410. `/dashboards/new/widget-builder/widget/new/`,
  411. `/dashboard/${dashboardId}/widget-builder/widget/new/`,
  412. `/dashboards/new/widget-builder/widget/${widgetIndex}/edit/`,
  413. `/dashboard/${dashboardId}/widget-builder/widget/${widgetIndex}/edit/`,
  414. ]
  415. );
  416. }
  417. return widgetBuilderRoutes.includes(location.pathname);
  418. }
  419. get dashboardTitle() {
  420. const {dashboard} = this.props;
  421. const {modifiedDashboard} = this.state;
  422. return modifiedDashboard ? modifiedDashboard.title : dashboard.title;
  423. }
  424. onEdit = () => {
  425. const {dashboard, organization} = this.props;
  426. trackAnalytics('dashboards2.edit.start', {organization});
  427. this.setState({
  428. dashboardState: DashboardState.EDIT,
  429. modifiedDashboard: cloneDashboard(dashboard),
  430. });
  431. };
  432. onDelete = (dashboard: State['modifiedDashboard']) => () => {
  433. const {api, organization, location} = this.props;
  434. if (!dashboard?.id) {
  435. return;
  436. }
  437. const previousDashboardState = this.state.dashboardState;
  438. this.setState({dashboardState: DashboardState.PENDING_DELETE}, () => {
  439. deleteDashboard(api, organization.slug, dashboard.id)
  440. .then(() => {
  441. addSuccessMessage(t('Dashboard deleted'));
  442. trackAnalytics('dashboards2.delete', {organization});
  443. browserHistory.replace({
  444. pathname: `/organizations/${organization.slug}/dashboards/`,
  445. query: location.query,
  446. });
  447. })
  448. .catch(() => {
  449. this.setState({
  450. dashboardState: previousDashboardState,
  451. });
  452. });
  453. });
  454. };
  455. onCancel = () => {
  456. const {organization, dashboard, location, params} = this.props;
  457. const {modifiedDashboard} = this.state;
  458. let hasDashboardChanged = !isEqual(modifiedDashboard, dashboard);
  459. // If a dashboard has every layout undefined, then ignore the layout field
  460. // when checking equality because it is a dashboard from before the grid feature
  461. const isLegacyLayout = dashboard.widgets.every(({layout}) => !defined(layout));
  462. if (isLegacyLayout) {
  463. hasDashboardChanged = !isEqual(
  464. {
  465. ...modifiedDashboard,
  466. widgets: modifiedDashboard?.widgets.map(widget => omit(widget, 'layout')),
  467. },
  468. {...dashboard, widgets: dashboard.widgets.map(widget => omit(widget, 'layout'))}
  469. );
  470. }
  471. // Don't confirm preview cancellation regardless of dashboard state
  472. if (hasDashboardChanged && !this.isPreview) {
  473. // Ignore no-alert here, so that the confirm on cancel matches onUnload & onRouteLeave
  474. /* eslint no-alert:0 */
  475. if (!confirm(UNSAVED_MESSAGE)) {
  476. return;
  477. }
  478. }
  479. if (params.dashboardId) {
  480. trackAnalytics('dashboards2.edit.cancel', {organization});
  481. this.setState({
  482. dashboardState: DashboardState.VIEW,
  483. modifiedDashboard: null,
  484. });
  485. return;
  486. }
  487. trackAnalytics('dashboards2.create.cancel', {organization});
  488. browserHistory.replace(
  489. normalizeUrl({
  490. pathname: `/organizations/${organization.slug}/dashboards/`,
  491. query: location.query,
  492. })
  493. );
  494. };
  495. handleChangeFilter = (activeFilters: DashboardFilters) => {
  496. const {dashboard, location} = this.props;
  497. const {modifiedDashboard} = this.state;
  498. const newModifiedDashboard = modifiedDashboard || dashboard;
  499. if (
  500. Object.keys(activeFilters).every(
  501. key => !newModifiedDashboard.filters?.[key] && activeFilters[key].length === 0
  502. )
  503. ) {
  504. return;
  505. }
  506. const filterParams: DashboardFilters = {};
  507. Object.keys(activeFilters).forEach(key => {
  508. filterParams[key] = activeFilters[key].length ? activeFilters[key] : '';
  509. });
  510. if (
  511. !isEqualWith(activeFilters, dashboard.filters, (a, b) => {
  512. // This is to handle the case where dashboard filters has release:[] and the new filter is release:""
  513. if (a.length === 0 && b.length === 0) {
  514. return a === b;
  515. }
  516. return undefined;
  517. })
  518. ) {
  519. browserHistory.push({
  520. ...location,
  521. query: {
  522. ...location.query,
  523. ...filterParams,
  524. },
  525. });
  526. }
  527. };
  528. handleUpdateWidgetList = (widgets: Widget[]) => {
  529. const {organization, dashboard, api, onDashboardUpdate, location} = this.props;
  530. const {modifiedDashboard} = this.state;
  531. // Use the new widgets for calculating layout because widgets has
  532. // the most up to date information in edit state
  533. const currentLayout = getDashboardLayout(widgets);
  534. const layoutColumnDepths = calculateColumnDepths(currentLayout);
  535. const newModifiedDashboard = {
  536. ...cloneDashboard(modifiedDashboard || dashboard),
  537. widgets: assignDefaultLayout(widgets, layoutColumnDepths),
  538. };
  539. this.setState({
  540. modifiedDashboard: newModifiedDashboard,
  541. widgetLimitReached: widgets.length >= MAX_WIDGETS,
  542. });
  543. if (this.isEditingDashboard || this.isPreview) {
  544. return null;
  545. }
  546. return updateDashboard(api, organization.slug, newModifiedDashboard).then(
  547. (newDashboard: DashboardDetails) => {
  548. if (onDashboardUpdate) {
  549. onDashboardUpdate(newDashboard);
  550. this.setState({
  551. modifiedDashboard: null,
  552. });
  553. }
  554. const legendQuery =
  555. this.state.widgetLegendState.setMultipleWidgetSelectionStateURL(newDashboard);
  556. if (dashboard && newDashboard.id !== dashboard.id) {
  557. this.props.router.replace(
  558. normalizeUrl({
  559. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  560. query: {
  561. ...location.query,
  562. unselectedSeries: legendQuery,
  563. },
  564. })
  565. );
  566. } else {
  567. browserHistory.replace(
  568. normalizeUrl({
  569. pathname: `/organizations/${organization.slug}/dashboard/${dashboard.id}/`,
  570. query: {
  571. ...location.query,
  572. unselectedSeries: legendQuery,
  573. },
  574. })
  575. );
  576. }
  577. addSuccessMessage(t('Dashboard updated'));
  578. return newDashboard;
  579. },
  580. // `updateDashboard` does its own error handling
  581. () => undefined
  582. );
  583. };
  584. handleAddCustomWidget = (widget: Widget) => {
  585. const {dashboard} = this.props;
  586. const {modifiedDashboard} = this.state;
  587. const newModifiedDashboard = modifiedDashboard || dashboard;
  588. this.onUpdateWidget([...newModifiedDashboard.widgets, widget]);
  589. };
  590. handleAddMetricWidget = (layout?: Widget['layout']) => {
  591. const widgetCopy = assignTempId({
  592. layout,
  593. ...defaultMetricWidget(),
  594. });
  595. const currentWidgets =
  596. this.state.modifiedDashboard?.widgets ?? this.props.dashboard.widgets;
  597. openWidgetViewerModal({
  598. organization: this.props.organization,
  599. widget: widgetCopy,
  600. widgetLegendState: this.state.widgetLegendState,
  601. onMetricWidgetEdit: widget => {
  602. const nextList = generateWidgetsAfterCompaction([...currentWidgets, widget]);
  603. this.onUpdateWidget(nextList);
  604. this.handleUpdateWidgetList(nextList);
  605. },
  606. });
  607. };
  608. onAddWidget = (dataset?: DataSet) => {
  609. const {
  610. organization,
  611. dashboard,
  612. router,
  613. location,
  614. params: {dashboardId},
  615. } = this.props;
  616. const {modifiedDashboard} = this.state;
  617. if (dataset === DataSet.METRICS) {
  618. this.handleAddMetricWidget();
  619. return;
  620. }
  621. if (organization.features.includes('dashboards-widget-builder-redesign')) {
  622. this.setState(
  623. {
  624. modifiedDashboard: cloneDashboard(modifiedDashboard ?? dashboard),
  625. },
  626. () => {
  627. this.setState({isWidgetBuilderOpen: true});
  628. let pathname = `/organizations/${organization.slug}/dashboard/${dashboardId}/widget-builder/widget/new/`;
  629. if (!defined(dashboardId)) {
  630. pathname = `/organizations/${organization.slug}/dashboards/new/widget-builder/widget/new/`;
  631. }
  632. router.push(
  633. normalizeUrl({
  634. // TODO: Replace with the old widget builder path when swapping over
  635. pathname,
  636. query: {
  637. ...location.query,
  638. dataset,
  639. },
  640. })
  641. );
  642. }
  643. );
  644. return;
  645. }
  646. this.setState(
  647. {
  648. modifiedDashboard: cloneDashboard(dashboard),
  649. },
  650. () => {
  651. if (dashboardId) {
  652. router.push(
  653. normalizeUrl({
  654. pathname: `/organizations/${organization.slug}/dashboard/${dashboardId}/widget/new/`,
  655. query: {
  656. ...location.query,
  657. source: DashboardWidgetSource.DASHBOARDS,
  658. dataset,
  659. },
  660. })
  661. );
  662. }
  663. }
  664. );
  665. };
  666. onEditWidget = (widget: Widget) => {
  667. const {router, organization, params, location, dashboard} = this.props;
  668. const {modifiedDashboard} = this.state;
  669. const currentDashboard = modifiedDashboard ?? dashboard;
  670. const {dashboardId} = params;
  671. const widgetIndex = currentDashboard.widgets.indexOf(widget);
  672. this.setState({
  673. isWidgetBuilderOpen: true,
  674. });
  675. const path = defined(dashboardId)
  676. ? `/organizations/${organization.slug}/dashboard/${dashboardId}/widget-builder/widget/${widgetIndex}/edit/`
  677. : `/organizations/${organization.slug}/dashboards/new/widget-builder/widget/${widgetIndex}/edit/`;
  678. router.push(
  679. normalizeUrl({
  680. pathname: path,
  681. query: {
  682. ...location.query,
  683. ...convertWidgetToBuilderStateParams(widget),
  684. },
  685. })
  686. );
  687. };
  688. handleSaveWidget = async ({
  689. index,
  690. widget,
  691. }: {
  692. index: number | undefined;
  693. widget: Widget;
  694. }) => {
  695. if (
  696. !this.props.organization.features.includes('dashboards-widget-builder-redesign')
  697. ) {
  698. return;
  699. }
  700. const currentDashboard = this.state.modifiedDashboard ?? this.props.dashboard;
  701. // Get the "base" widget and merge the changes to persist information like tempIds and layout
  702. const baseWidget = defined(index) ? currentDashboard.widgets[index] : {};
  703. const mergedWidget = {...baseWidget, ...widget};
  704. const newWidgets = defined(index)
  705. ? [
  706. ...currentDashboard.widgets.slice(0, index),
  707. mergedWidget,
  708. ...currentDashboard.widgets.slice(index + 1),
  709. ]
  710. : [...currentDashboard.widgets, mergedWidget];
  711. try {
  712. if (!this.isEditingDashboard) {
  713. // If we're not in edit mode, send a request to update the dashboard
  714. await this.handleUpdateWidgetList(newWidgets);
  715. } else {
  716. // If we're in edit mode, update the edit state
  717. this.onUpdateWidget(newWidgets);
  718. }
  719. this.handleCloseWidgetBuilder();
  720. } catch (error) {
  721. addErrorMessage(t('Failed to save widget'));
  722. }
  723. };
  724. /* Handles POST request for Edit Access Selector Changes */
  725. onChangeEditAccess = (newDashboardPermissions: DashboardPermissions) => {
  726. const {dashboard, api, organization} = this.props;
  727. const dashboardCopy = cloneDashboard(dashboard);
  728. dashboardCopy.permissions = newDashboardPermissions;
  729. updateDashboardPermissions(api, organization.slug, dashboardCopy).then(
  730. (newDashboard: DashboardDetails) => {
  731. addSuccessMessage(t('Dashboard Edit Access updated.'));
  732. this.props.onDashboardUpdate?.(newDashboard);
  733. this.setState({
  734. modifiedDashboard: null,
  735. });
  736. return newDashboard;
  737. }
  738. );
  739. };
  740. handleCloseWidgetBuilder = () => {
  741. const {organization, router, location, params} = this.props;
  742. this.setState({isWidgetBuilderOpen: false});
  743. router.push(
  744. getDashboardLocation({
  745. organization,
  746. dashboardId: params.dashboardId,
  747. location,
  748. })
  749. );
  750. };
  751. onCommit = () => {
  752. const {api, organization, location, dashboard, onDashboardUpdate} = this.props;
  753. const {modifiedDashboard, dashboardState} = this.state;
  754. switch (dashboardState) {
  755. case DashboardState.PREVIEW:
  756. case DashboardState.CREATE: {
  757. if (modifiedDashboard) {
  758. if (this.isPreview) {
  759. trackAnalytics('dashboards_manage.templates.add', {
  760. organization,
  761. dashboard_id: dashboard.id,
  762. dashboard_title: dashboard.title,
  763. was_previewed: true,
  764. });
  765. }
  766. const newModifiedDashboard = {
  767. ...cloneDashboard(modifiedDashboard),
  768. ...getCurrentPageFilters(location),
  769. filters: getDashboardFiltersFromURL(location) ?? modifiedDashboard.filters,
  770. };
  771. createDashboard(
  772. api,
  773. organization.slug,
  774. newModifiedDashboard,
  775. this.isPreview
  776. ).then(
  777. (newDashboard: DashboardDetails) => {
  778. addSuccessMessage(t('Dashboard created'));
  779. trackAnalytics('dashboards2.create.complete', {organization});
  780. this.setState(
  781. {
  782. dashboardState: DashboardState.VIEW,
  783. },
  784. () => {
  785. // redirect to new dashboard
  786. browserHistory.replace(
  787. normalizeUrl({
  788. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  789. query: {
  790. query: omit(location.query, Object.values(DashboardFilterKeys)),
  791. },
  792. })
  793. );
  794. }
  795. );
  796. },
  797. () => undefined
  798. );
  799. }
  800. break;
  801. }
  802. case DashboardState.EDIT: {
  803. // only update the dashboard if there are changes
  804. if (modifiedDashboard) {
  805. if (isEqual(dashboard, modifiedDashboard)) {
  806. this.setState({
  807. dashboardState: DashboardState.VIEW,
  808. modifiedDashboard: null,
  809. });
  810. return;
  811. }
  812. updateDashboard(api, organization.slug, modifiedDashboard).then(
  813. (newDashboard: DashboardDetails) => {
  814. if (onDashboardUpdate) {
  815. onDashboardUpdate(newDashboard);
  816. }
  817. addSuccessMessage(t('Dashboard updated'));
  818. trackAnalytics('dashboards2.edit.complete', {organization});
  819. this.setState(
  820. {
  821. dashboardState: DashboardState.VIEW,
  822. modifiedDashboard: null,
  823. },
  824. () => {
  825. if (dashboard && newDashboard.id !== dashboard.id) {
  826. browserHistory.replace(
  827. normalizeUrl({
  828. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  829. query: {
  830. ...location.query,
  831. },
  832. })
  833. );
  834. }
  835. }
  836. );
  837. },
  838. // `updateDashboard` does its own error handling
  839. () => undefined
  840. );
  841. return;
  842. }
  843. this.setState({
  844. dashboardState: DashboardState.VIEW,
  845. modifiedDashboard: null,
  846. });
  847. break;
  848. }
  849. case DashboardState.VIEW:
  850. default: {
  851. this.setState({
  852. dashboardState: DashboardState.VIEW,
  853. modifiedDashboard: null,
  854. });
  855. break;
  856. }
  857. }
  858. };
  859. setModifiedDashboard = (dashboard: DashboardDetails) => {
  860. this.setState({
  861. modifiedDashboard: dashboard,
  862. });
  863. };
  864. onUpdateWidget = (widgets: Widget[]) => {
  865. this.setState((state: State) => ({
  866. ...state,
  867. widgetLimitReached: widgets.length >= MAX_WIDGETS,
  868. modifiedDashboard: {
  869. ...(state.modifiedDashboard || this.props.dashboard),
  870. widgets,
  871. },
  872. }));
  873. };
  874. renderWidgetBuilder = () => {
  875. const {children, dashboard, onDashboardUpdate} = this.props;
  876. const {modifiedDashboard} = this.state;
  877. return (
  878. <Fragment>
  879. {isValidElement(children)
  880. ? cloneElement<any>(children, {
  881. dashboard: modifiedDashboard ?? dashboard,
  882. onSave: this.isEditingDashboard
  883. ? this.onUpdateWidget
  884. : this.handleUpdateWidgetList,
  885. updateDashboardSplitDecision: (
  886. widgetId: string,
  887. splitDecision: WidgetType
  888. ) => {
  889. handleUpdateDashboardSplit({
  890. widgetId,
  891. splitDecision,
  892. dashboard,
  893. modifiedDashboard,
  894. stateSetter: this.setState.bind(this),
  895. onDashboardUpdate,
  896. });
  897. },
  898. })
  899. : children}
  900. </Fragment>
  901. );
  902. };
  903. renderDefaultDashboardDetail() {
  904. const {organization, dashboard, dashboards, params, router, location} = this.props;
  905. const {modifiedDashboard, dashboardState, widgetLimitReached} = this.state;
  906. const {dashboardId} = params;
  907. return (
  908. <PageFiltersContainer
  909. disablePersistence
  910. defaultSelection={{
  911. datetime: {
  912. start: null,
  913. end: null,
  914. utc: false,
  915. period: DEFAULT_STATS_PERIOD,
  916. },
  917. }}
  918. >
  919. <Layout.Page withPadding>
  920. <OnDemandControlProvider location={location}>
  921. <MetricsResultsMetaProvider>
  922. <NoProjectMessage organization={organization}>
  923. <StyledPageHeader>
  924. <Layout.Title>
  925. <DashboardTitle
  926. dashboard={modifiedDashboard ?? dashboard}
  927. onUpdate={this.setModifiedDashboard}
  928. isEditingDashboard={this.isEditingDashboard}
  929. />
  930. </Layout.Title>
  931. <Controls
  932. organization={organization}
  933. dashboards={dashboards}
  934. dashboard={dashboard}
  935. onEdit={this.onEdit}
  936. onCancel={this.onCancel}
  937. onCommit={this.onCommit}
  938. onAddWidget={this.onAddWidget}
  939. onChangeEditAccess={this.onChangeEditAccess}
  940. onDelete={this.onDelete(dashboard)}
  941. dashboardState={dashboardState}
  942. widgetLimitReached={widgetLimitReached}
  943. />
  944. </StyledPageHeader>
  945. <HookHeader organization={organization} />
  946. <FiltersBar
  947. dashboardPermissions={dashboard.permissions}
  948. dashboardCreator={dashboard.createdBy}
  949. filters={{}} // Default Dashboards don't have filters set
  950. location={location}
  951. hasUnsavedChanges={false}
  952. isEditingDashboard={false}
  953. isPreview={false}
  954. onDashboardFilterChange={this.handleChangeFilter}
  955. />
  956. <MetricsCardinalityProvider
  957. organization={organization}
  958. location={location}
  959. >
  960. <MetricsDataSwitcher
  961. organization={organization}
  962. eventView={EventView.fromLocation(location)}
  963. location={location}
  964. >
  965. {metricsDataSide => (
  966. <MEPSettingProvider
  967. location={location}
  968. forceTransactions={metricsDataSide.forceTransactionsOnly}
  969. >
  970. <Dashboard
  971. paramDashboardId={dashboardId}
  972. dashboard={modifiedDashboard ?? dashboard}
  973. organization={organization}
  974. isEditingDashboard={this.isEditingDashboard}
  975. widgetLimitReached={widgetLimitReached}
  976. onUpdate={this.onUpdateWidget}
  977. handleUpdateWidgetList={this.handleUpdateWidgetList}
  978. handleAddCustomWidget={this.handleAddCustomWidget}
  979. handleAddMetricWidget={this.handleAddMetricWidget}
  980. isPreview={this.isPreview}
  981. router={router}
  982. location={location}
  983. widgetLegendState={this.state.widgetLegendState}
  984. />
  985. </MEPSettingProvider>
  986. )}
  987. </MetricsDataSwitcher>
  988. </MetricsCardinalityProvider>
  989. </NoProjectMessage>
  990. </MetricsResultsMetaProvider>
  991. </OnDemandControlProvider>
  992. </Layout.Page>
  993. </PageFiltersContainer>
  994. );
  995. }
  996. getBreadcrumbLabel() {
  997. const {dashboardState} = this.state;
  998. let label = this.dashboardTitle;
  999. if (dashboardState === DashboardState.CREATE) {
  1000. label = t('Create Dashboard');
  1001. } else if (this.isPreview) {
  1002. label = t('Preview Dashboard');
  1003. }
  1004. return label;
  1005. }
  1006. renderDashboardDetail() {
  1007. const {
  1008. api,
  1009. organization,
  1010. dashboard,
  1011. dashboards,
  1012. params,
  1013. router,
  1014. location,
  1015. newWidget,
  1016. onSetNewWidget,
  1017. onDashboardUpdate,
  1018. projects,
  1019. } = this.props;
  1020. const {modifiedDashboard, dashboardState, widgetLimitReached, seriesData, setData} =
  1021. this.state;
  1022. const {dashboardId} = params;
  1023. const hasUnsavedFilters =
  1024. dashboard.id !== 'default-overview' &&
  1025. dashboardState !== DashboardState.CREATE &&
  1026. hasUnsavedFilterChanges(dashboard, location);
  1027. const eventView = generatePerformanceEventView(location, projects, {}, organization);
  1028. const isDashboardUsingTransaction = dashboard.widgets.some(
  1029. isWidgetUsingTransactionName
  1030. );
  1031. return (
  1032. <SentryDocumentTitle title={dashboard.title} orgSlug={organization.slug}>
  1033. <PageFiltersContainer
  1034. disablePersistence
  1035. defaultSelection={{
  1036. datetime: {
  1037. start: null,
  1038. end: null,
  1039. utc: false,
  1040. period: DEFAULT_STATS_PERIOD,
  1041. },
  1042. }}
  1043. >
  1044. <Layout.Page>
  1045. <OnDemandControlProvider location={location}>
  1046. <MetricsResultsMetaProvider>
  1047. <NoProjectMessage organization={organization}>
  1048. <Layout.Header>
  1049. <Layout.HeaderContent>
  1050. <Breadcrumbs
  1051. crumbs={[
  1052. {
  1053. label: t('Dashboards'),
  1054. to: `/organizations/${organization.slug}/dashboards/`,
  1055. },
  1056. {
  1057. label: this.getBreadcrumbLabel(),
  1058. },
  1059. ]}
  1060. />
  1061. <Layout.Title>
  1062. <DashboardTitle
  1063. dashboard={modifiedDashboard ?? dashboard}
  1064. onUpdate={this.setModifiedDashboard}
  1065. isEditingDashboard={this.isEditingDashboard}
  1066. />
  1067. </Layout.Title>
  1068. </Layout.HeaderContent>
  1069. <Layout.HeaderActions>
  1070. <Controls
  1071. organization={organization}
  1072. dashboards={dashboards}
  1073. dashboard={dashboard}
  1074. hasUnsavedFilters={hasUnsavedFilters}
  1075. onEdit={this.onEdit}
  1076. onCancel={this.onCancel}
  1077. onCommit={this.onCommit}
  1078. onAddWidget={this.onAddWidget}
  1079. onDelete={this.onDelete(dashboard)}
  1080. onChangeEditAccess={this.onChangeEditAccess}
  1081. dashboardState={dashboardState}
  1082. widgetLimitReached={widgetLimitReached}
  1083. />
  1084. </Layout.HeaderActions>
  1085. </Layout.Header>
  1086. <Layout.Body>
  1087. <Layout.Main fullWidth>
  1088. <MetricsCardinalityProvider
  1089. organization={organization}
  1090. location={location}
  1091. >
  1092. <MetricsDataSwitcher
  1093. organization={organization}
  1094. eventView={eventView}
  1095. location={location}
  1096. >
  1097. {metricsDataSide => (
  1098. <MEPSettingProvider
  1099. location={location}
  1100. forceTransactions={metricsDataSide.forceTransactionsOnly}
  1101. >
  1102. {isDashboardUsingTransaction ? (
  1103. <MetricsDataSwitcherAlert
  1104. organization={organization}
  1105. eventView={eventView}
  1106. projects={projects}
  1107. location={location}
  1108. router={router}
  1109. source={DiscoverQueryPageSource.DISCOVER}
  1110. {...metricsDataSide}
  1111. />
  1112. ) : null}
  1113. <FiltersBar
  1114. filters={(modifiedDashboard ?? dashboard).filters}
  1115. dashboardPermissions={dashboard.permissions}
  1116. dashboardCreator={dashboard.createdBy}
  1117. location={location}
  1118. hasUnsavedChanges={hasUnsavedFilters}
  1119. isEditingDashboard={
  1120. dashboardState !== DashboardState.CREATE &&
  1121. this.isEditingDashboard
  1122. }
  1123. isPreview={this.isPreview}
  1124. onDashboardFilterChange={this.handleChangeFilter}
  1125. onCancel={() => {
  1126. resetPageFilters(dashboard, location);
  1127. trackAnalytics('dashboards2.filter.cancel', {
  1128. organization,
  1129. });
  1130. this.setState({
  1131. modifiedDashboard: {
  1132. ...(modifiedDashboard ?? dashboard),
  1133. filters: dashboard.filters,
  1134. },
  1135. });
  1136. }}
  1137. onSave={() => {
  1138. const newModifiedDashboard = {
  1139. ...cloneDashboard(modifiedDashboard ?? dashboard),
  1140. ...getCurrentPageFilters(location),
  1141. filters:
  1142. getDashboardFiltersFromURL(location) ??
  1143. (modifiedDashboard ?? dashboard).filters,
  1144. };
  1145. updateDashboard(
  1146. api,
  1147. organization.slug,
  1148. newModifiedDashboard
  1149. ).then(
  1150. (newDashboard: DashboardDetails) => {
  1151. addSuccessMessage(t('Dashboard filters updated'));
  1152. trackAnalytics('dashboards2.filter.save', {
  1153. organization,
  1154. });
  1155. const navigateToDashboard = () => {
  1156. browserHistory.replace(
  1157. normalizeUrl({
  1158. pathname: `/organizations/${organization.slug}/dashboard/${newDashboard.id}/`,
  1159. query: omit(
  1160. location.query,
  1161. Object.values(DashboardFilterKeys)
  1162. ),
  1163. })
  1164. );
  1165. };
  1166. if (onDashboardUpdate) {
  1167. onDashboardUpdate(newDashboard);
  1168. this.setState(
  1169. {
  1170. modifiedDashboard: null,
  1171. },
  1172. () => {
  1173. // Wait for modifiedDashboard state to update before navigating
  1174. navigateToDashboard();
  1175. }
  1176. );
  1177. return;
  1178. }
  1179. navigateToDashboard();
  1180. },
  1181. // `updateDashboard` does its own error handling
  1182. () => undefined
  1183. );
  1184. }}
  1185. />
  1186. <WidgetViewerContext.Provider value={{seriesData, setData}}>
  1187. <Fragment>
  1188. <Dashboard
  1189. paramDashboardId={dashboardId}
  1190. dashboard={modifiedDashboard ?? dashboard}
  1191. organization={organization}
  1192. isEditingDashboard={this.isEditingDashboard}
  1193. widgetLimitReached={widgetLimitReached}
  1194. onUpdate={this.onUpdateWidget}
  1195. handleUpdateWidgetList={this.handleUpdateWidgetList}
  1196. handleAddCustomWidget={this.handleAddCustomWidget}
  1197. handleAddMetricWidget={this.handleAddMetricWidget}
  1198. router={router}
  1199. location={location}
  1200. newWidget={newWidget}
  1201. onSetNewWidget={onSetNewWidget}
  1202. isPreview={this.isPreview}
  1203. widgetLegendState={this.state.widgetLegendState}
  1204. onAddWidget={this.onAddWidget}
  1205. onEditWidget={this.onEditWidget}
  1206. />
  1207. <WidgetBuilderV2
  1208. isOpen={this.state.isWidgetBuilderOpen}
  1209. onClose={this.handleCloseWidgetBuilder}
  1210. dashboardFilters={
  1211. getDashboardFiltersFromURL(location) ??
  1212. dashboard.filters
  1213. }
  1214. dashboard={modifiedDashboard ?? dashboard}
  1215. onSave={this.handleSaveWidget}
  1216. />
  1217. </Fragment>
  1218. </WidgetViewerContext.Provider>
  1219. </MEPSettingProvider>
  1220. )}
  1221. </MetricsDataSwitcher>
  1222. </MetricsCardinalityProvider>
  1223. </Layout.Main>
  1224. </Layout.Body>
  1225. </NoProjectMessage>
  1226. </MetricsResultsMetaProvider>
  1227. </OnDemandControlProvider>
  1228. </Layout.Page>
  1229. </PageFiltersContainer>
  1230. </SentryDocumentTitle>
  1231. );
  1232. }
  1233. render() {
  1234. const {organization} = this.props;
  1235. if (this.isWidgetBuilderRouter) {
  1236. return this.renderWidgetBuilder();
  1237. }
  1238. if (organization.features.includes('dashboards-edit')) {
  1239. return this.renderDashboardDetail();
  1240. }
  1241. return this.renderDefaultDashboardDetail();
  1242. }
  1243. }
  1244. const StyledPageHeader = styled('div')`
  1245. display: grid;
  1246. grid-template-columns: minmax(0, 1fr);
  1247. grid-row-gap: ${space(2)};
  1248. align-items: center;
  1249. margin-bottom: ${space(2)};
  1250. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  1251. grid-template-columns: minmax(0, 1fr) max-content;
  1252. grid-column-gap: ${space(2)};
  1253. height: 40px;
  1254. }
  1255. `;
  1256. export default withPageFilters(withProjects(withApi(withOrganization(DashboardDetail))));