dashboard.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. import 'react-grid-layout/css/styles.css';
  2. import 'react-resizable/css/styles.css';
  3. import {Component} from 'react';
  4. import {Layouts, Responsive, WidthProvider} from 'react-grid-layout';
  5. import {forceCheck} from 'react-lazyload';
  6. import {InjectedRouter} from 'react-router';
  7. import {closestCenter, DndContext} from '@dnd-kit/core';
  8. import {arrayMove, rectSortingStrategy, SortableContext} from '@dnd-kit/sortable';
  9. import styled from '@emotion/styled';
  10. import {Location} from 'history';
  11. import cloneDeep from 'lodash/cloneDeep';
  12. import debounce from 'lodash/debounce';
  13. import isEqual from 'lodash/isEqual';
  14. import {validateWidget} from 'sentry/actionCreators/dashboards';
  15. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  16. import {fetchOrgMembers} from 'sentry/actionCreators/members';
  17. import {fetchMetricsFields, fetchMetricsTags} from 'sentry/actionCreators/metrics';
  18. import {openAddDashboardWidgetModal} from 'sentry/actionCreators/modal';
  19. import {loadOrganizationTags} from 'sentry/actionCreators/tags';
  20. import {Client} from 'sentry/api';
  21. import {IconResize} from 'sentry/icons';
  22. import space from 'sentry/styles/space';
  23. import {Organization, PageFilters} from 'sentry/types';
  24. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  25. import theme from 'sentry/utils/theme';
  26. import withApi from 'sentry/utils/withApi';
  27. import withPageFilters from 'sentry/utils/withPageFilters';
  28. import AddWidget, {ADD_WIDGET_BUTTON_DRAG_ID} from './addWidget';
  29. import {
  30. assignDefaultLayout,
  31. assignTempId,
  32. calculateColumnDepths,
  33. constructGridItemKey,
  34. DEFAULT_WIDGET_WIDTH,
  35. enforceWidgetHeightValues,
  36. generateWidgetId,
  37. generateWidgetsAfterCompaction,
  38. getDashboardLayout,
  39. getDefaultWidgetHeight,
  40. getMobileLayout,
  41. getNextAvailablePosition,
  42. pickDefinedStoreKeys,
  43. Position,
  44. } from './layoutUtils';
  45. import SortableWidget from './sortableWidget';
  46. import {DashboardDetails, DashboardWidgetSource, Widget, WidgetType} from './types';
  47. export const DRAG_HANDLE_CLASS = 'widget-drag';
  48. const DESKTOP = 'desktop';
  49. const MOBILE = 'mobile';
  50. export const NUM_DESKTOP_COLS = 6;
  51. const NUM_MOBILE_COLS = 2;
  52. const ROW_HEIGHT = 120;
  53. const WIDGET_MARGINS: [number, number] = [16, 16];
  54. const BOTTOM_MOBILE_VIEW_POSITION = {
  55. x: 0,
  56. y: Number.MAX_SAFE_INTEGER,
  57. };
  58. const MOBILE_BREAKPOINT = parseInt(theme.breakpoints[0], 10);
  59. const BREAKPOINTS = {[MOBILE]: 0, [DESKTOP]: MOBILE_BREAKPOINT};
  60. const COLUMNS = {[MOBILE]: NUM_MOBILE_COLS, [DESKTOP]: NUM_DESKTOP_COLS};
  61. type Props = {
  62. api: Client;
  63. dashboard: DashboardDetails;
  64. handleAddCustomWidget: (widget: Widget) => void;
  65. handleUpdateWidgetList: (widgets: Widget[]) => void;
  66. isEditing: boolean;
  67. location: Location;
  68. /**
  69. * Fired when widgets are added/removed/sorted.
  70. */
  71. onUpdate: (widgets: Widget[]) => void;
  72. organization: Organization;
  73. router: InjectedRouter;
  74. selection: PageFilters;
  75. widgetLimitReached: boolean;
  76. isPreview?: boolean;
  77. newWidget?: Widget;
  78. onSetNewWidget?: () => void;
  79. paramDashboardId?: string;
  80. paramTemplateId?: string;
  81. };
  82. type State = {
  83. isMobile: boolean;
  84. layouts: Layouts;
  85. windowWidth: number;
  86. };
  87. class Dashboard extends Component<Props, State> {
  88. constructor(props) {
  89. super(props);
  90. const {dashboard, organization} = props;
  91. const isUsingGrid = organization.features.includes('dashboard-grid-layout');
  92. const desktopLayout = getDashboardLayout(dashboard.widgets);
  93. this.state = {
  94. isMobile: false,
  95. layouts: {
  96. [DESKTOP]: isUsingGrid ? desktopLayout : [],
  97. [MOBILE]: isUsingGrid ? getMobileLayout(desktopLayout, dashboard.widgets) : [],
  98. },
  99. windowWidth: window.innerWidth,
  100. };
  101. }
  102. static getDerivedStateFromProps(props, state) {
  103. if (props.organization.features.includes('dashboard-grid-layout')) {
  104. if (state.isMobile) {
  105. // Don't need to recalculate any layout state from props in the mobile view
  106. // because we want to force different positions (i.e. new widgets added
  107. // at the bottom)
  108. return null;
  109. }
  110. // If the user clicks "Cancel" and the dashboard resets,
  111. // recalculate the layout to revert to the unmodified state
  112. const dashboardLayout = getDashboardLayout(props.dashboard.widgets);
  113. if (
  114. !isEqual(
  115. dashboardLayout.map(pickDefinedStoreKeys),
  116. state.layouts[DESKTOP].map(pickDefinedStoreKeys)
  117. )
  118. ) {
  119. return {
  120. ...state,
  121. layouts: {
  122. [DESKTOP]: dashboardLayout,
  123. [MOBILE]: getMobileLayout(dashboardLayout, props.dashboard.widgets),
  124. },
  125. };
  126. }
  127. }
  128. return null;
  129. }
  130. async componentDidMount() {
  131. const {isEditing, organization, api, selection, newWidget} = this.props;
  132. if (organization.features.includes('dashboard-grid-layout')) {
  133. window.addEventListener('resize', this.debouncedHandleResize);
  134. }
  135. if (organization.features.includes('dashboards-metrics')) {
  136. fetchMetricsFields(api, organization.slug, selection.projects);
  137. fetchMetricsTags(api, organization.slug, selection.projects);
  138. }
  139. // Load organization tags when in edit mode.
  140. if (isEditing) {
  141. this.fetchTags();
  142. }
  143. if (newWidget) {
  144. this.addNewWidget();
  145. }
  146. // Get member list data for issue widgets
  147. this.fetchMemberList();
  148. }
  149. async componentDidUpdate(prevProps: Props) {
  150. const {api, organization, selection, isEditing, newWidget} = this.props;
  151. // Load organization tags when going into edit mode.
  152. // We use tags on the add widget modal.
  153. if (prevProps.isEditing !== isEditing && isEditing) {
  154. this.fetchTags();
  155. }
  156. if (newWidget && newWidget !== prevProps.newWidget) {
  157. this.addNewWidget();
  158. }
  159. if (!isEqual(prevProps.selection.projects, selection.projects)) {
  160. this.fetchMemberList();
  161. fetchMetricsFields(api, organization.slug, selection.projects);
  162. fetchMetricsTags(api, organization.slug, selection.projects);
  163. }
  164. }
  165. componentWillUnmount() {
  166. const {organization} = this.props;
  167. if (organization.features.includes('dashboard-grid-layout')) {
  168. window.removeEventListener('resize', this.debouncedHandleResize);
  169. }
  170. }
  171. debouncedHandleResize = debounce(() => {
  172. this.setState({
  173. windowWidth: window.innerWidth,
  174. });
  175. }, 250);
  176. fetchMemberList() {
  177. const {api, selection} = this.props;
  178. // Stores MemberList in MemberListStore for use in modals and sets state for use is child components
  179. fetchOrgMembers(
  180. api,
  181. this.props.organization.slug,
  182. selection.projects?.map(projectId => String(projectId))
  183. );
  184. }
  185. async addNewWidget() {
  186. const {api, organization, newWidget, handleAddCustomWidget, onSetNewWidget} =
  187. this.props;
  188. if (newWidget) {
  189. try {
  190. await validateWidget(api, organization.slug, newWidget);
  191. handleAddCustomWidget(newWidget);
  192. onSetNewWidget?.();
  193. } catch (error) {
  194. // Don't do anything, widget isn't valid
  195. addErrorMessage(error);
  196. }
  197. }
  198. }
  199. fetchTags() {
  200. const {api, organization, selection} = this.props;
  201. loadOrganizationTags(api, organization.slug, selection);
  202. }
  203. handleStartAdd = () => {
  204. const {
  205. organization,
  206. dashboard,
  207. selection,
  208. handleUpdateWidgetList,
  209. handleAddCustomWidget,
  210. router,
  211. location,
  212. paramDashboardId,
  213. } = this.props;
  214. if (organization.features.includes('new-widget-builder-experience')) {
  215. trackAdvancedAnalyticsEvent('dashboards_views.add_widget_in_builder.opened', {
  216. organization,
  217. });
  218. if (paramDashboardId) {
  219. router.push({
  220. pathname: `/organizations/${organization.slug}/dashboard/${paramDashboardId}/widget/new/`,
  221. query: {
  222. ...location.query,
  223. source: DashboardWidgetSource.DASHBOARDS,
  224. },
  225. });
  226. return;
  227. }
  228. router.push({
  229. pathname: `/organizations/${organization.slug}/dashboards/new/widget/new/`,
  230. query: {
  231. ...location.query,
  232. source: DashboardWidgetSource.DASHBOARDS,
  233. },
  234. });
  235. return;
  236. }
  237. trackAdvancedAnalyticsEvent('dashboards_views.add_widget_modal.opened', {
  238. organization,
  239. });
  240. if (organization.features.includes('widget-library')) {
  241. trackAdvancedAnalyticsEvent('dashboards_views.widget_library.opened', {
  242. organization,
  243. });
  244. openAddDashboardWidgetModal({
  245. organization,
  246. dashboard,
  247. selection,
  248. onAddWidget: handleAddCustomWidget,
  249. onAddLibraryWidget: (widgets: Widget[]) => handleUpdateWidgetList(widgets),
  250. source: DashboardWidgetSource.LIBRARY,
  251. });
  252. return;
  253. }
  254. openAddDashboardWidgetModal({
  255. organization,
  256. dashboard,
  257. selection,
  258. onAddWidget: handleAddCustomWidget,
  259. source: DashboardWidgetSource.DASHBOARDS,
  260. });
  261. };
  262. handleUpdateComplete = (prevWidget: Widget) => (nextWidget: Widget) => {
  263. const {isEditing, onUpdate, handleUpdateWidgetList} = this.props;
  264. let nextList = [...this.props.dashboard.widgets];
  265. const updateIndex = nextList.indexOf(prevWidget);
  266. const nextWidgetData = {
  267. ...nextWidget,
  268. tempId: prevWidget.tempId,
  269. };
  270. // Only modify and re-compact if the default height has changed
  271. if (
  272. getDefaultWidgetHeight(prevWidget.displayType) !==
  273. getDefaultWidgetHeight(nextWidget.displayType)
  274. ) {
  275. nextList[updateIndex] = enforceWidgetHeightValues(nextWidgetData);
  276. nextList = generateWidgetsAfterCompaction(nextList);
  277. } else {
  278. nextList[updateIndex] = nextWidgetData;
  279. }
  280. onUpdate(nextList);
  281. if (!!!isEditing) {
  282. handleUpdateWidgetList(nextList);
  283. }
  284. };
  285. handleDeleteWidget = (widgetToDelete: Widget) => () => {
  286. const {dashboard, onUpdate, isEditing, handleUpdateWidgetList} = this.props;
  287. let nextList = dashboard.widgets.filter(widget => widget !== widgetToDelete);
  288. nextList = generateWidgetsAfterCompaction(nextList);
  289. onUpdate(nextList);
  290. if (!!!isEditing) {
  291. handleUpdateWidgetList(nextList);
  292. }
  293. };
  294. handleDuplicateWidget = (widget: Widget, index: number) => () => {
  295. const {dashboard, onUpdate, isEditing, handleUpdateWidgetList} = this.props;
  296. const widgetCopy = cloneDeep(
  297. assignTempId({...widget, id: undefined, tempId: undefined})
  298. );
  299. let nextList = [...dashboard.widgets];
  300. nextList.splice(index, 0, widgetCopy);
  301. nextList = generateWidgetsAfterCompaction(nextList);
  302. onUpdate(nextList);
  303. if (!!!isEditing) {
  304. handleUpdateWidgetList(nextList);
  305. }
  306. };
  307. handleEditWidget = (widget: Widget, index: number) => () => {
  308. const {
  309. organization,
  310. dashboard,
  311. selection,
  312. router,
  313. location,
  314. paramDashboardId,
  315. handleAddCustomWidget,
  316. isEditing,
  317. } = this.props;
  318. if (organization.features.includes('new-widget-builder-experience') && isEditing) {
  319. trackAdvancedAnalyticsEvent('dashboards_views.edit_widget_in_builder.opened', {
  320. organization,
  321. });
  322. if (paramDashboardId) {
  323. router.push({
  324. pathname: `/organizations/${organization.slug}/dashboard/${paramDashboardId}/widget/${index}/edit/`,
  325. query: {
  326. ...location.query,
  327. source: DashboardWidgetSource.DASHBOARDS,
  328. },
  329. });
  330. return;
  331. }
  332. router.push({
  333. pathname: `/organizations/${organization.slug}/dashboards/new/widget/${index}/edit/`,
  334. query: {
  335. ...location.query,
  336. source: DashboardWidgetSource.DASHBOARDS,
  337. },
  338. });
  339. return;
  340. }
  341. trackAdvancedAnalyticsEvent('dashboards_views.edit_widget_modal.opened', {
  342. organization,
  343. });
  344. const modalProps = {
  345. organization,
  346. widget,
  347. selection,
  348. onAddWidget: handleAddCustomWidget,
  349. onUpdateWidget: this.handleUpdateComplete(widget),
  350. };
  351. openAddDashboardWidgetModal({
  352. ...modalProps,
  353. dashboard,
  354. source: DashboardWidgetSource.DASHBOARDS,
  355. });
  356. };
  357. getWidgetIds() {
  358. return [
  359. ...this.props.dashboard.widgets.map((widget, index): string => {
  360. return generateWidgetId(widget, index);
  361. }),
  362. ADD_WIDGET_BUTTON_DRAG_ID,
  363. ];
  364. }
  365. renderWidget(widget: Widget, index: number) {
  366. const {isMobile, windowWidth} = this.state;
  367. const {isEditing, organization, widgetLimitReached, isPreview} = this.props;
  368. const widgetProps = {
  369. widget,
  370. isEditing,
  371. widgetLimitReached,
  372. onDelete: this.handleDeleteWidget(widget),
  373. onEdit: this.handleEditWidget(widget, index),
  374. onDuplicate: this.handleDuplicateWidget(widget, index),
  375. isPreview,
  376. };
  377. if (organization.features.includes('dashboard-grid-layout')) {
  378. const key = constructGridItemKey(widget);
  379. const dragId = key;
  380. return (
  381. <GridItem key={key} data-grid={widget.layout}>
  382. <SortableWidget
  383. {...widgetProps}
  384. dragId={dragId}
  385. isMobile={isMobile}
  386. windowWidth={windowWidth}
  387. index={String(index)}
  388. />
  389. </GridItem>
  390. );
  391. }
  392. const key = generateWidgetId(widget, index);
  393. const dragId = key;
  394. return (
  395. <SortableWidget {...widgetProps} key={key} dragId={dragId} index={String(index)} />
  396. );
  397. }
  398. handleLayoutChange = (_, allLayouts: Layouts) => {
  399. const {isMobile} = this.state;
  400. const {dashboard, onUpdate} = this.props;
  401. const isNotAddButton = ({i}) => i !== ADD_WIDGET_BUTTON_DRAG_ID;
  402. const newLayouts = {
  403. [DESKTOP]: allLayouts[DESKTOP].filter(isNotAddButton),
  404. [MOBILE]: allLayouts[MOBILE].filter(isNotAddButton),
  405. };
  406. // Generate a new list of widgets where the layouts are associated
  407. let columnDepths = calculateColumnDepths(newLayouts[DESKTOP]);
  408. const newWidgets = dashboard.widgets.map(widget => {
  409. const gridKey = constructGridItemKey(widget);
  410. let matchingLayout = newLayouts[DESKTOP].find(({i}) => i === gridKey);
  411. if (!matchingLayout) {
  412. const height = getDefaultWidgetHeight(widget.displayType);
  413. const defaultWidgetParams = {
  414. w: DEFAULT_WIDGET_WIDTH,
  415. h: height,
  416. minH: height,
  417. i: gridKey,
  418. };
  419. // Calculate the available position
  420. const [nextPosition, nextColumnDepths] = getNextAvailablePosition(
  421. columnDepths,
  422. height
  423. );
  424. columnDepths = nextColumnDepths;
  425. // Set the position for the desktop layout
  426. matchingLayout = {
  427. ...defaultWidgetParams,
  428. ...nextPosition,
  429. };
  430. if (isMobile) {
  431. // This is a new widget and it's on the mobile page so we keep it at the bottom
  432. const mobileLayout = newLayouts[MOBILE].filter(({i}) => i !== gridKey);
  433. mobileLayout.push({
  434. ...defaultWidgetParams,
  435. ...BOTTOM_MOBILE_VIEW_POSITION,
  436. });
  437. newLayouts[MOBILE] = mobileLayout;
  438. }
  439. }
  440. return {
  441. ...widget,
  442. layout: pickDefinedStoreKeys(matchingLayout),
  443. };
  444. });
  445. this.setState({
  446. layouts: newLayouts,
  447. });
  448. onUpdate(newWidgets);
  449. // Force check lazyLoad elements that might have shifted into view after (re)moving an upper widget
  450. // Unfortunately need to use setTimeout since React Grid Layout animates widgets into view when layout changes
  451. // RGL doesn't provide a handler for post animation layout change
  452. setTimeout(forceCheck, 400);
  453. };
  454. handleBreakpointChange = (newBreakpoint: string) => {
  455. const {layouts} = this.state;
  456. const {
  457. dashboard: {widgets},
  458. } = this.props;
  459. if (newBreakpoint === MOBILE) {
  460. this.setState({
  461. isMobile: true,
  462. layouts: {
  463. ...layouts,
  464. [MOBILE]: getMobileLayout(layouts[DESKTOP], widgets),
  465. },
  466. });
  467. return;
  468. }
  469. this.setState({isMobile: false});
  470. };
  471. get addWidgetLayout() {
  472. const {isMobile, layouts} = this.state;
  473. let position: Position = BOTTOM_MOBILE_VIEW_POSITION;
  474. if (!isMobile) {
  475. const columnDepths = calculateColumnDepths(layouts[DESKTOP]);
  476. const [nextPosition] = getNextAvailablePosition(columnDepths, 1);
  477. position = nextPosition;
  478. }
  479. return {
  480. ...position,
  481. w: DEFAULT_WIDGET_WIDTH,
  482. h: 1,
  483. isResizable: false,
  484. };
  485. }
  486. renderGridDashboard() {
  487. const {layouts, isMobile} = this.state;
  488. const {isEditing, dashboard, organization, widgetLimitReached} = this.props;
  489. let {widgets} = dashboard;
  490. // Filter out any issue/metrics widgets if the user does not have the feature flag
  491. widgets = widgets.filter(({widgetType}) => {
  492. if (widgetType === WidgetType.METRICS) {
  493. return organization.features.includes('dashboards-metrics');
  494. }
  495. return true;
  496. });
  497. const columnDepths = calculateColumnDepths(layouts[DESKTOP]);
  498. const widgetsWithLayout = assignDefaultLayout(widgets, columnDepths);
  499. const canModifyLayout = !isMobile && isEditing;
  500. return (
  501. <GridLayout
  502. breakpoints={BREAKPOINTS}
  503. cols={COLUMNS}
  504. rowHeight={ROW_HEIGHT}
  505. margin={WIDGET_MARGINS}
  506. draggableHandle={`.${DRAG_HANDLE_CLASS}`}
  507. layouts={layouts}
  508. onLayoutChange={this.handleLayoutChange}
  509. onBreakpointChange={this.handleBreakpointChange}
  510. isDraggable={canModifyLayout}
  511. isResizable={canModifyLayout}
  512. resizeHandle={
  513. <ResizeHandle
  514. className="react-resizable-handle"
  515. data-test-id="custom-resize-handle"
  516. >
  517. <IconResize />
  518. </ResizeHandle>
  519. }
  520. useCSSTransforms={false}
  521. isBounded
  522. >
  523. {widgetsWithLayout.map((widget, index) => this.renderWidget(widget, index))}
  524. {isEditing && !!!widgetLimitReached && (
  525. <AddWidgetWrapper
  526. key={ADD_WIDGET_BUTTON_DRAG_ID}
  527. data-grid={this.addWidgetLayout}
  528. >
  529. <AddWidget onAddWidget={this.handleStartAdd} />
  530. </AddWidgetWrapper>
  531. )}
  532. </GridLayout>
  533. );
  534. }
  535. renderDndDashboard = () => {
  536. const {isEditing, onUpdate, dashboard, organization, widgetLimitReached} = this.props;
  537. let {widgets} = dashboard;
  538. // Filter out any issue/metrics widgets if the user does not have the feature flag
  539. widgets = widgets.filter(({widgetType}) => {
  540. if (widgetType === WidgetType.METRICS) {
  541. return organization.features.includes('dashboards-metrics');
  542. }
  543. return true;
  544. });
  545. const items = this.getWidgetIds();
  546. return (
  547. <DndContext
  548. collisionDetection={closestCenter}
  549. onDragEnd={({over, active}) => {
  550. const activeDragId = active.id;
  551. const getIndex = items.indexOf.bind(items);
  552. const activeIndex = activeDragId ? getIndex(activeDragId) : -1;
  553. if (over && over.id !== ADD_WIDGET_BUTTON_DRAG_ID) {
  554. const overIndex = getIndex(over.id);
  555. if (activeIndex !== overIndex) {
  556. onUpdate(arrayMove(widgets, activeIndex, overIndex));
  557. }
  558. }
  559. }}
  560. >
  561. <WidgetContainer>
  562. <SortableContext items={items} strategy={rectSortingStrategy}>
  563. {widgets.map((widget, index) => this.renderWidget(widget, index))}
  564. {isEditing && !!!widgetLimitReached && (
  565. <AddWidget onAddWidget={this.handleStartAdd} />
  566. )}
  567. </SortableContext>
  568. </WidgetContainer>
  569. </DndContext>
  570. );
  571. };
  572. render() {
  573. const {organization} = this.props;
  574. if (organization.features.includes('dashboard-grid-layout')) {
  575. return this.renderGridDashboard();
  576. }
  577. return this.renderDndDashboard();
  578. }
  579. }
  580. export default withApi(withPageFilters(Dashboard));
  581. const WidgetContainer = styled('div')`
  582. display: grid;
  583. grid-template-columns: repeat(2, minmax(0, 1fr));
  584. grid-auto-flow: row dense;
  585. gap: ${space(2)};
  586. @media (min-width: ${p => p.theme.breakpoints[1]}) {
  587. grid-template-columns: repeat(4, minmax(0, 1fr));
  588. }
  589. @media (min-width: ${p => p.theme.breakpoints[3]}) {
  590. grid-template-columns: repeat(6, minmax(0, 1fr));
  591. }
  592. @media (min-width: ${p => p.theme.breakpoints[4]}) {
  593. grid-template-columns: repeat(8, minmax(0, 1fr));
  594. }
  595. `;
  596. // A widget being dragged has a z-index of 3
  597. // Allow the Add Widget tile to show above widgets when moved
  598. const AddWidgetWrapper = styled('div')`
  599. z-index: 5;
  600. background-color: ${p => p.theme.background};
  601. `;
  602. const GridItem = styled('div')`
  603. .react-resizable-handle {
  604. z-index: 2;
  605. }
  606. `;
  607. const GridLayout = styled(WidthProvider(Responsive))`
  608. margin: -${space(2)};
  609. .react-resizable-handle {
  610. background-image: none;
  611. }
  612. .react-grid-item > .react-resizable-handle::after {
  613. border: none;
  614. }
  615. .react-grid-item.react-grid-placeholder {
  616. background: ${p => p.theme.purple200};
  617. }
  618. `;
  619. const ResizeHandle = styled('div')`
  620. position: absolute;
  621. bottom: 2px;
  622. right: 2px;
  623. cursor: nwse-resize;
  624. `;