import React, {Component} from 'react'; import LazyLoad from 'react-lazyload'; // eslint-disable-next-line no-restricted-imports import {withRouter, WithRouterProps} from 'react-router'; import {useSortable} from '@dnd-kit/sortable'; import styled from '@emotion/styled'; import {Location} from 'history'; import {Client} from 'sentry/api'; import Feature from 'sentry/components/acl/feature'; import Alert from 'sentry/components/alert'; import Button from 'sentry/components/button'; import {HeaderTitle} from 'sentry/components/charts/styles'; import DateTime from 'sentry/components/dateTime'; import ErrorBoundary from 'sentry/components/errorBoundary'; import ExternalLink from 'sentry/components/links/externalLink'; import {Panel} from 'sentry/components/panels'; import Placeholder from 'sentry/components/placeholder'; import Tooltip from 'sentry/components/tooltip'; import {IconCopy, IconDelete, IconEdit, IconGrabbable} from 'sentry/icons'; import {t, tct} from 'sentry/locale'; import space from 'sentry/styles/space'; import {Organization, PageFilters} from 'sentry/types'; import {Series} from 'sentry/types/echarts'; import {statsPeriodToDays} from 'sentry/utils/dates'; import {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery'; import withApi from 'sentry/utils/withApi'; import withOrganization from 'sentry/utils/withOrganization'; import withPageFilters from 'sentry/utils/withPageFilters'; import {DRAG_HANDLE_CLASS} from '../dashboard'; import {DisplayType, Widget, WidgetType} from '../types'; import {isCustomMeasurementWidget} from '../utils'; import {DEFAULT_RESULTS_LIMIT} from '../widgetBuilder/utils'; import {DashboardsMEPConsumer, DashboardsMEPProvider} from './dashboardsMEPContext'; import WidgetCardChartContainer from './widgetCardChartContainer'; import WidgetCardContextMenu from './widgetCardContextMenu'; type DraggableProps = Pick, 'attributes' | 'listeners'>; type Props = WithRouterProps & { api: Client; currentWidgetDragging: boolean; isEditing: boolean; isSorting: boolean; location: Location; organization: Organization; selection: PageFilters; widget: Widget; widgetLimitReached: boolean; draggableProps?: DraggableProps; hideToolbar?: boolean; index?: string; isMobile?: boolean; isPreview?: boolean; noDashboardsMEPProvider?: boolean; noLazyLoad?: boolean; onDelete?: () => void; onDuplicate?: () => void; onEdit?: () => void; renderErrorMessage?: (errorMessage?: string) => React.ReactNode; showContextMenu?: boolean; showStoredAlert?: boolean; showWidgetViewerButton?: boolean; tableItemLimit?: number; windowWidth?: number; }; type State = { pageLinks?: string; seriesData?: Series[]; tableData?: TableDataWithTitle[]; totalIssuesCount?: string; }; const METRICS_BACKED_SESSIONS_START_DATE = new Date('2022-04-12'); class WidgetCard extends Component { state: State = {}; renderToolbar() { const { onEdit, onDelete, onDuplicate, draggableProps, hideToolbar, isEditing, isMobile, } = this.props; if (!isEditing) { return null; } return ( {!isMobile && ( } borderless className={DRAG_HANDLE_CLASS} {...draggableProps?.listeners} {...draggableProps?.attributes} /> )}