SaveDashboardButton.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import { selectors } from '@grafana/e2e-selectors';
  3. import { Button, ButtonVariant, ModalsController, FullWidthButtonContainer } from '@grafana/ui';
  4. import { DashboardModel } from 'app/features/dashboard/state';
  5. import { SaveDashboardDrawer } from './SaveDashboardDrawer';
  6. interface SaveDashboardButtonProps {
  7. dashboard: DashboardModel;
  8. onSaveSuccess?: () => void;
  9. }
  10. export const SaveDashboardButton: React.FC<SaveDashboardButtonProps> = ({ dashboard, onSaveSuccess }) => {
  11. return (
  12. <ModalsController>
  13. {({ showModal, hideModal }) => {
  14. return (
  15. <Button
  16. onClick={() => {
  17. showModal(SaveDashboardDrawer, {
  18. dashboard,
  19. onSaveSuccess,
  20. onDismiss: hideModal,
  21. });
  22. }}
  23. aria-label={selectors.pages.Dashboard.Settings.General.saveDashBoard}
  24. >
  25. Save dashboard
  26. </Button>
  27. );
  28. }}
  29. </ModalsController>
  30. );
  31. };
  32. export const SaveDashboardAsButton: React.FC<SaveDashboardButtonProps & { variant?: ButtonVariant }> = ({
  33. dashboard,
  34. onSaveSuccess,
  35. variant,
  36. }) => {
  37. return (
  38. <ModalsController>
  39. {({ showModal, hideModal }) => {
  40. return (
  41. <FullWidthButtonContainer>
  42. <Button
  43. onClick={() => {
  44. showModal(SaveDashboardDrawer, {
  45. dashboard,
  46. onSaveSuccess,
  47. onDismiss: hideModal,
  48. isCopy: true,
  49. });
  50. }}
  51. variant={variant}
  52. aria-label={selectors.pages.Dashboard.Settings.General.saveAsDashBoard}
  53. >
  54. Save As...
  55. </Button>
  56. </FullWidthButtonContainer>
  57. );
  58. }}
  59. </ModalsController>
  60. );
  61. };