dashboard.tsx 21 KB

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