dashboard.tsx 20 KB

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