index.tsx 940 B

12345678910111213141516171819202122232425262728293031323334
  1. import React, { useState } from 'react';
  2. import { useSelector } from 'react-redux';
  3. import { ToolbarButton } from '@grafana/ui';
  4. import { ExploreId } from 'app/types';
  5. import { getExploreItemSelector } from '../state/selectors';
  6. import { AddToDashboardModal } from './AddToDashboardModal';
  7. interface Props {
  8. exploreId: ExploreId;
  9. }
  10. export const AddToDashboard = ({ exploreId }: Props) => {
  11. const [isOpen, setIsOpen] = useState(false);
  12. const selectExploreItem = getExploreItemSelector(exploreId);
  13. const explorePaneHasQueries = !!useSelector(selectExploreItem)?.queries?.length;
  14. return (
  15. <>
  16. <ToolbarButton
  17. icon="apps"
  18. onClick={() => setIsOpen(true)}
  19. aria-label="Add to dashboard"
  20. disabled={!explorePaneHasQueries}
  21. >
  22. Add to dashboard
  23. </ToolbarButton>
  24. {isOpen && <AddToDashboardModal onClose={() => setIsOpen(false)} exploreId={exploreId} />}
  25. </>
  26. );
  27. };