import { css } from '@emotion/css'; import { useMemo } from 'react'; import { useAsync } from 'react-use'; import AutoSizer from 'react-virtualized-auto-sizer'; import { of } from 'rxjs'; import { GrafanaTheme2, PluginMeta, PluginType } from '@grafana/data'; import { config } from '@grafana/runtime'; import { Alert, Spinner, useStyles2 } from '@grafana/ui'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import { SearchResultsTable } from 'app/features/search/page/components/SearchResultsTable'; import { getGrafanaSearcher } from 'app/features/search/service/searcher'; import { SearchQuery } from 'app/features/search/service/types'; type Props = { plugin: PluginMeta; }; export function PluginUsage({ plugin }: Props) { const styles = useStyles2(getStyles); const searchQuery = useMemo(() => { if (plugin.type === PluginType.datasource) { return { query: '*', ds_type: plugin.id, kind: ['dashboard'], }; } return { query: '*', panel_type: plugin.id, kind: ['panel'], }; }, [plugin]); const results = useAsync(() => { return getGrafanaSearcher().search(searchQuery); }, [searchQuery]); const found = results.value; if (found?.totalRows) { return (
{plugin.name} is used {found.totalRows} times.
{({ width, height }) => { return ( {}} keyboardEvents={of()} onTagSelected={() => {}} /> ); }}
); } if (results.loading) { return ; } if (!config.featureToggles.panelTitleSearch) { return ( Plugin usage requires the new search index to find usage across dashboards ); } return ( ); } export const getStyles = (theme: GrafanaTheme2) => { return { wrap: css({ width: '100%', height: '90%', }), info: css({ paddingBottom: '30px', }), }; };