GetStartedWithDataSource.tsx 910 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, { useCallback } from 'react';
  2. import { useDispatch } from 'react-redux';
  3. import { DataSourcePluginMeta } from '@grafana/data';
  4. import { Button } from '@grafana/ui';
  5. import { addDataSource } from 'app/features/datasources/state/actions';
  6. import { isDataSourceEditor } from '../../permissions';
  7. import { CatalogPlugin } from '../../types';
  8. type Props = {
  9. plugin: CatalogPlugin;
  10. };
  11. export function GetStartedWithDataSource({ plugin }: Props): React.ReactElement | null {
  12. const dispatch = useDispatch();
  13. const onAddDataSource = useCallback(() => {
  14. const meta = {
  15. name: plugin.name,
  16. id: plugin.id,
  17. } as DataSourcePluginMeta;
  18. dispatch(addDataSource(meta));
  19. }, [dispatch, plugin]);
  20. if (!isDataSourceEditor()) {
  21. return null;
  22. }
  23. return (
  24. <Button variant="primary" onClick={onAddDataSource}>
  25. Create a {plugin.name} data source
  26. </Button>
  27. );
  28. }