import { css } from '@emotion/css'; import React from 'react'; import { useDispatch } from 'react-redux'; import { CoreApp, GrafanaTheme2, PanelDataSummary, VisualizationSuggestionsBuilder } from '@grafana/data'; import { PanelDataErrorViewProps } from '@grafana/runtime'; import { usePanelContext, useStyles2 } from '@grafana/ui'; import { CardButton } from 'app/core/components/CardButton'; import { LS_VISUALIZATION_SELECT_TAB_KEY } from 'app/core/constants'; import store from 'app/core/store'; import { toggleVizPicker } from 'app/features/dashboard/components/PanelEditor/state/reducers'; import { VisualizationSelectPaneTab } from 'app/features/dashboard/components/PanelEditor/types'; import { getDashboardSrv } from 'app/features/dashboard/services/DashboardSrv'; import { changePanelPlugin } from '../state/actions'; export function PanelDataErrorView(props: PanelDataErrorViewProps) { const styles = useStyles2(getStyles); const context = usePanelContext(); const builder = new VisualizationSuggestionsBuilder(props.data); const { dataSummary } = builder; const message = getMessageFor(props, dataSummary); const dispatch = useDispatch(); const openVizPicker = () => { store.setObject(LS_VISUALIZATION_SELECT_TAB_KEY, VisualizationSelectPaneTab.Suggestions); dispatch(toggleVizPicker(true)); }; const switchToTable = () => { const panel = getDashboardSrv().getCurrent()?.getPanelById(props.panelId); if (!panel) { return; } dispatch( changePanelPlugin({ panel, pluginId: 'table', }) ); }; return (