dashboard.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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 {openAddDashboardWidgetModal} from 'sentry/actionCreators/modal';
  18. import {loadOrganizationTags} from 'sentry/actionCreators/tags';
  19. import {Client} from 'sentry/api';
  20. import Button from 'sentry/components/button';
  21. import {IconResize} from 'sentry/icons';
  22. import {t} from 'sentry/locale';
  23. import space from 'sentry/styles/space';
  24. import {Organization, PageFilters} from 'sentry/types';
  25. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  26. import theme from 'sentry/utils/theme';
  27. import withApi from 'sentry/utils/withApi';
  28. import withPageFilters from 'sentry/utils/withPageFilters';
  29. import AddWidget, {ADD_WIDGET_BUTTON_DRAG_ID} from './addWidget';
  30. import {
  31. assignDefaultLayout,
  32. assignTempId,
  33. calculateColumnDepths,
  34. constructGridItemKey,
  35. DEFAULT_WIDGET_WIDTH,
  36. enforceWidgetHeightValues,
  37. generateWidgetId,
  38. generateWidgetsAfterCompaction,
  39. getDashboardLayout,
  40. getDefaultWidgetHeight,
  41. getMobileLayout,
  42. getNextAvailablePosition,
  43. pickDefinedStoreKeys,
  44. Position,
  45. } from './layoutUtils';
  46. import SortableWidget from './sortableWidget';
  47. import {DashboardDetails, DashboardWidgetSource, Widget, WidgetType} from './types';
  48. import {getDashboardFiltersFromURL} from './utils';
  49. export const DRAG_HANDLE_CLASS = 'widget-drag';
  50. const DRAG_RESIZE_CLASS = 'widget-resize';
  51. const DESKTOP = 'desktop';
  52. const MOBILE = 'mobile';
  53. export const NUM_DESKTOP_COLS = 6;
  54. const NUM_MOBILE_COLS = 2;
  55. const ROW_HEIGHT = 120;
  56. const WIDGET_MARGINS: [number, number] = [16, 16];
  57. const BOTTOM_MOBILE_VIEW_POSITION = {
  58. x: 0,
  59. y: Number.MAX_SAFE_INTEGER,
  60. };
  61. const MOBILE_BREAKPOINT = parseInt(theme.breakpoints.small, 10);
  62. const BREAKPOINTS = {[MOBILE]: 0, [DESKTOP]: MOBILE_BREAKPOINT};
  63. const COLUMNS = {[MOBILE]: NUM_MOBILE_COLS, [DESKTOP]: NUM_DESKTOP_COLS};
  64. type Props = {
  65. api: Client;
  66. dashboard: DashboardDetails;
  67. handleAddCustomWidget: (widget: Widget) => void;
  68. handleUpdateWidgetList: (widgets: Widget[]) => void;
  69. isEditing: boolean;
  70. location: Location;
  71. /**
  72. * Fired when widgets are added/removed/sorted.
  73. */
  74. onUpdate: (widgets: Widget[]) => void;
  75. organization: Organization;
  76. router: InjectedRouter;
  77. selection: PageFilters;
  78. widgetLimitReached: boolean;
  79. isPreview?: boolean;
  80. newWidget?: Widget;
  81. onSetNewWidget?: () => void;
  82. paramDashboardId?: string;
  83. paramTemplateId?: string;
  84. };
  85. type State = {
  86. isMobile: boolean;
  87. layouts: Layouts;
  88. windowWidth: number;
  89. };
  90. class Dashboard extends Component<Props, State> {
  91. constructor(props: Props) {
  92. super(props);
  93. const {dashboard, organization} = props;
  94. const isUsingGrid = organization.features.includes('dashboard-grid-layout');
  95. const desktopLayout = getDashboardLayout(dashboard.widgets);
  96. this.state = {
  97. isMobile: false,
  98. layouts: {
  99. [DESKTOP]: isUsingGrid ? desktopLayout : [],
  100. [MOBILE]: isUsingGrid ? getMobileLayout(desktopLayout, dashboard.widgets) : [],
  101. },
  102. windowWidth: window.innerWidth,
  103. };
  104. }
  105. static getDerivedStateFromProps(props, state) {
  106. if (props.organization.features.includes('dashboard-grid-layout')) {
  107. if (state.isMobile) {
  108. // Don't need to recalculate any layout state from props in the mobile view
  109. // because we want to force different positions (i.e. new widgets added
  110. // at the bottom)
  111. return null;
  112. }
  113. // If the user clicks "Cancel" and the dashboard resets,
  114. // recalculate the layout to revert to the unmodified state
  115. const dashboardLayout = getDashboardLayout(props.dashboard.widgets);
  116. if (
  117. !isEqual(
  118. dashboardLayout.map(pickDefinedStoreKeys),
  119. state.layouts[DESKTOP].map(pickDefinedStoreKeys)
  120. )
  121. ) {
  122. return {
  123. ...state,
  124. layouts: {
  125. [DESKTOP]: dashboardLayout,
  126. [MOBILE]: getMobileLayout(dashboardLayout, props.dashboard.widgets),
  127. },
  128. };
  129. }
  130. }
  131. return null;
  132. }
  133. componentDidMount() {
  134. const {organization, newWidget} = this.props;
  135. if (organization.features.includes('dashboard-grid-layout')) {
  136. window.addEventListener('resize', this.debouncedHandleResize);
  137. }
  138. // Always load organization tags on dashboards
  139. this.fetchTags();
  140. if (newWidget) {
  141. this.addNewWidget();
  142. }
  143. // Get member list data for issue widgets
  144. this.fetchMemberList();
  145. }
  146. componentDidUpdate(prevProps: Props) {
  147. const {selection, newWidget} = this.props;
  148. if (newWidget && newWidget !== prevProps.newWidget) {
  149. this.addNewWidget();
  150. }
  151. if (!isEqual(prevProps.selection.projects, selection.projects)) {
  152. this.fetchMemberList();
  153. }
  154. }
  155. componentWillUnmount() {
  156. if (this.props.organization.features.includes('dashboard-grid-layout')) {
  157. window.removeEventListener('resize', this.debouncedHandleResize);
  158. }
  159. window.clearTimeout(this.forceCheckTimeout);
  160. }
  161. forceCheckTimeout: number | undefined = undefined;
  162. debouncedHandleResize = debounce(() => {
  163. this.setState({
  164. windowWidth: window.innerWidth,
  165. });
  166. }, 250);
  167. fetchMemberList() {
  168. const {api, selection} = this.props;
  169. // Stores MemberList in MemberListStore for use in modals and sets state for use is child components
  170. fetchOrgMembers(
  171. api,
  172. this.props.organization.slug,
  173. selection.projects?.map(projectId => String(projectId))
  174. );
  175. }
  176. async addNewWidget() {
  177. const {api, organization, newWidget, handleAddCustomWidget, onSetNewWidget} =
  178. this.props;
  179. if (newWidget) {
  180. try {
  181. await validateWidget(api, organization.slug, newWidget);
  182. handleAddCustomWidget(newWidget);
  183. onSetNewWidget?.();
  184. } catch (error) {
  185. // Don't do anything, widget isn't valid
  186. addErrorMessage(error);
  187. }
  188. }
  189. }
  190. fetchTags() {
  191. const {api, organization, selection} = this.props;
  192. loadOrganizationTags(api, organization.slug, selection);
  193. }
  194. handleStartAdd = () => {
  195. const {
  196. organization,
  197. dashboard,
  198. selection,
  199. handleUpdateWidgetList,
  200. handleAddCustomWidget,
  201. router,
  202. location,
  203. paramDashboardId,
  204. } = this.props;
  205. if (organization.features.includes('new-widget-builder-experience-design')) {
  206. if (paramDashboardId) {
  207. router.push({
  208. pathname: `/organizations/${organization.slug}/dashboard/${paramDashboardId}/widget/new/`,
  209. query: {
  210. ...location.query,
  211. source: DashboardWidgetSource.DASHBOARDS,
  212. },
  213. });
  214. return;
  215. }
  216. router.push({
  217. pathname: `/organizations/${organization.slug}/dashboards/new/widget/new/`,
  218. query: {
  219. ...location.query,
  220. source: DashboardWidgetSource.DASHBOARDS,
  221. },
  222. });
  223. return;
  224. }
  225. trackAdvancedAnalyticsEvent('dashboards_views.add_widget_modal.opened', {
  226. organization,
  227. });
  228. trackAdvancedAnalyticsEvent('dashboards_views.widget_library.opened', {
  229. organization,
  230. });
  231. openAddDashboardWidgetModal({
  232. organization,
  233. dashboard,
  234. selection,
  235. onAddWidget: handleAddCustomWidget,
  236. onAddLibraryWidget: (widgets: Widget[]) => handleUpdateWidgetList(widgets),
  237. source: DashboardWidgetSource.LIBRARY,
  238. });
  239. };
  240. handleUpdateComplete = (prevWidget: Widget) => (nextWidget: Widget) => {
  241. const {isEditing, onUpdate, handleUpdateWidgetList} = this.props;
  242. let nextList = [...this.props.dashboard.widgets];
  243. const updateIndex = nextList.indexOf(prevWidget);
  244. const nextWidgetData = {
  245. ...nextWidget,
  246. tempId: prevWidget.tempId,
  247. };
  248. // Only modify and re-compact if the default height has changed
  249. if (
  250. getDefaultWidgetHeight(prevWidget.displayType) !==
  251. getDefaultWidgetHeight(nextWidget.displayType)
  252. ) {
  253. nextList[updateIndex] = enforceWidgetHeightValues(nextWidgetData);
  254. nextList = generateWidgetsAfterCompaction(nextList);
  255. } else {
  256. nextList[updateIndex] = nextWidgetData;
  257. }
  258. onUpdate(nextList);
  259. if (!!!isEditing) {
  260. handleUpdateWidgetList(nextList);
  261. }
  262. };
  263. handleDeleteWidget = (widgetToDelete: Widget) => () => {
  264. const {dashboard, onUpdate, isEditing, handleUpdateWidgetList} = this.props;
  265. let nextList = dashboard.widgets.filter(widget => widget !== widgetToDelete);
  266. nextList = generateWidgetsAfterCompaction(nextList);
  267. onUpdate(nextList);
  268. if (!!!isEditing) {
  269. handleUpdateWidgetList(nextList);
  270. }
  271. };
  272. handleDuplicateWidget = (widget: Widget, index: number) => () => {
  273. const {dashboard, onUpdate, isEditing, handleUpdateWidgetList} = this.props;
  274. const widgetCopy = cloneDeep(
  275. assignTempId({...widget, id: undefined, tempId: undefined})
  276. );
  277. let nextList = [...dashboard.widgets];
  278. nextList.splice(index, 0, widgetCopy);
  279. nextList = generateWidgetsAfterCompaction(nextList);
  280. onUpdate(nextList);
  281. if (!!!isEditing) {
  282. handleUpdateWidgetList(nextList);
  283. }
  284. };
  285. handleEditWidget = (widget: Widget, index: number) => () => {
  286. const {
  287. organization,
  288. dashboard,
  289. selection,
  290. router,
  291. location,
  292. paramDashboardId,
  293. handleAddCustomWidget,
  294. isEditing,
  295. } = this.props;
  296. if (
  297. organization.features.includes('new-widget-builder-experience-design') &&
  298. (!organization.features.includes('new-widget-builder-experience-modal-access') ||
  299. isEditing)
  300. ) {
  301. if (paramDashboardId) {
  302. router.push({
  303. pathname: `/organizations/${organization.slug}/dashboard/${paramDashboardId}/widget/${index}/edit/`,
  304. query: {
  305. ...location.query,
  306. source: DashboardWidgetSource.DASHBOARDS,
  307. },
  308. });
  309. return;
  310. }
  311. router.push({
  312. pathname: `/organizations/${organization.slug}/dashboards/new/widget/${index}/edit/`,
  313. query: {
  314. ...location.query,
  315. source: DashboardWidgetSource.DASHBOARDS,
  316. },
  317. });
  318. return;
  319. }
  320. trackAdvancedAnalyticsEvent('dashboards_views.edit_widget_modal.opened', {
  321. organization,
  322. });
  323. const modalProps = {
  324. organization,
  325. widget,
  326. selection,
  327. onAddWidget: handleAddCustomWidget,
  328. onUpdateWidget: this.handleUpdateComplete(widget),
  329. };
  330. openAddDashboardWidgetModal({
  331. ...modalProps,
  332. dashboard,
  333. source: DashboardWidgetSource.DASHBOARDS,
  334. });
  335. };
  336. getWidgetIds() {
  337. return [
  338. ...this.props.dashboard.widgets.map((widget, index): string => {
  339. return generateWidgetId(widget, index);
  340. }),
  341. ADD_WIDGET_BUTTON_DRAG_ID,
  342. ];
  343. }
  344. renderWidget(widget: Widget, index: number) {
  345. const {isMobile, windowWidth} = this.state;
  346. const {isEditing, organization, widgetLimitReached, isPreview, dashboard, location} =
  347. this.props;
  348. const widgetProps = {
  349. widget,
  350. isEditing,
  351. widgetLimitReached,
  352. onDelete: this.handleDeleteWidget(widget),
  353. onEdit: this.handleEditWidget(widget, index),
  354. onDuplicate: this.handleDuplicateWidget(widget, index),
  355. isPreview,
  356. dashboardFilters: getDashboardFiltersFromURL(location) ?? dashboard.filters,
  357. };
  358. if (organization.features.includes('dashboard-grid-layout')) {
  359. const key = constructGridItemKey(widget);
  360. const dragId = key;
  361. return (
  362. <div key={key} data-grid={widget.layout}>
  363. <SortableWidget
  364. {...widgetProps}
  365. dragId={dragId}
  366. isMobile={isMobile}
  367. windowWidth={windowWidth}
  368. index={String(index)}
  369. />
  370. </div>
  371. );
  372. }
  373. const key = generateWidgetId(widget, index);
  374. const dragId = key;
  375. return (
  376. <SortableWidget {...widgetProps} key={key} dragId={dragId} index={String(index)} />
  377. );
  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 window.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. window.clearTimeout(this.forceCheckTimeout);
  434. this.forceCheckTimeout = window.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/release widgets if the user does not have the feature flag
  473. widgets = widgets.filter(({widgetType}) => {
  474. if (widgetType === WidgetType.RELEASE) {
  475. return organization.features.includes('dashboards-releases');
  476. }
  477. return true;
  478. });
  479. const columnDepths = calculateColumnDepths(layouts[DESKTOP]);
  480. const widgetsWithLayout = assignDefaultLayout(widgets, columnDepths);
  481. const canModifyLayout = !isMobile && isEditing;
  482. return (
  483. <GridLayout
  484. breakpoints={BREAKPOINTS}
  485. cols={COLUMNS}
  486. rowHeight={ROW_HEIGHT}
  487. margin={WIDGET_MARGINS}
  488. draggableHandle={`.${DRAG_HANDLE_CLASS}`}
  489. draggableCancel={`.${DRAG_RESIZE_CLASS}`}
  490. layouts={layouts}
  491. onLayoutChange={this.handleLayoutChange}
  492. onBreakpointChange={this.handleBreakpointChange}
  493. isDraggable={canModifyLayout}
  494. isResizable={canModifyLayout}
  495. resizeHandle={
  496. <ResizeHandle
  497. aria-label={t('Resize Widget')}
  498. data-test-id="custom-resize-handle"
  499. className={DRAG_RESIZE_CLASS}
  500. size="xs"
  501. borderless
  502. icon={<IconResize size="xs" />}
  503. />
  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 onAddWidget={this.handleStartAdd} />
  515. </AddWidgetWrapper>
  516. )}
  517. </GridLayout>
  518. );
  519. }
  520. renderDndDashboard = () => {
  521. const {isEditing, onUpdate, dashboard, organization, widgetLimitReached} = this.props;
  522. let {widgets} = dashboard;
  523. // Filter out any issue/release widgets if the user does not have the feature flag
  524. widgets = widgets.filter(({widgetType}) => {
  525. if (widgetType === WidgetType.RELEASE) {
  526. return organization.features.includes('dashboards-releases');
  527. }
  528. return true;
  529. });
  530. const items = this.getWidgetIds();
  531. return (
  532. <DndContext
  533. collisionDetection={closestCenter}
  534. onDragEnd={({over, active}) => {
  535. const activeDragId = active.id;
  536. const getIndex = items.indexOf.bind(items);
  537. const activeIndex = activeDragId ? getIndex(activeDragId) : -1;
  538. if (over && over.id !== ADD_WIDGET_BUTTON_DRAG_ID) {
  539. const overIndex = getIndex(over.id);
  540. if (activeIndex !== overIndex) {
  541. onUpdate(arrayMove(widgets, activeIndex, overIndex));
  542. }
  543. }
  544. }}
  545. >
  546. <WidgetContainer>
  547. <SortableContext items={items} strategy={rectSortingStrategy}>
  548. {widgets.map((widget, index) => this.renderWidget(widget, index))}
  549. {isEditing && !!!widgetLimitReached && (
  550. <AddWidget onAddWidget={this.handleStartAdd} />
  551. )}
  552. </SortableContext>
  553. </WidgetContainer>
  554. </DndContext>
  555. );
  556. };
  557. render() {
  558. const {organization} = this.props;
  559. if (organization.features.includes('dashboard-grid-layout')) {
  560. return this.renderGridDashboard();
  561. }
  562. return this.renderDndDashboard();
  563. }
  564. }
  565. export default withApi(withPageFilters(Dashboard));
  566. const WidgetContainer = styled('div')`
  567. display: grid;
  568. grid-template-columns: repeat(2, minmax(0, 1fr));
  569. grid-auto-flow: row dense;
  570. gap: ${space(2)};
  571. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  572. grid-template-columns: repeat(4, minmax(0, 1fr));
  573. }
  574. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  575. grid-template-columns: repeat(6, minmax(0, 1fr));
  576. }
  577. @media (min-width: ${p => p.theme.breakpoints.xxlarge}) {
  578. grid-template-columns: repeat(8, minmax(0, 1fr));
  579. }
  580. `;
  581. // A widget being dragged has a z-index of 3
  582. // Allow the Add Widget tile to show above widgets when moved
  583. const AddWidgetWrapper = styled('div')`
  584. z-index: 5;
  585. background-color: ${p => p.theme.background};
  586. `;
  587. const GridLayout = styled(WidthProvider(Responsive))`
  588. margin: -${space(2)};
  589. .react-grid-item.react-grid-placeholder {
  590. background: ${p => p.theme.purple200};
  591. border-radius: ${p => p.theme.borderRadius};
  592. }
  593. `;
  594. const ResizeHandle = styled(Button)`
  595. position: absolute;
  596. z-index: 2;
  597. bottom: ${space(0.5)};
  598. right: ${space(0.5)};
  599. color: ${p => p.theme.subText};
  600. cursor: nwse-resize;
  601. .react-resizable-hide & {
  602. display: none;
  603. }
  604. `;