dashboard.tsx 20 KB

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