ButtonRow.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { FC } from 'react';
  2. import { selectors } from '@grafana/e2e-selectors';
  3. import { Button, LinkButton } from '@grafana/ui';
  4. import { contextSrv } from 'app/core/core';
  5. import { AccessControlAction } from 'app/types/';
  6. export interface Props {
  7. exploreUrl: string;
  8. canSave: boolean;
  9. canDelete: boolean;
  10. onDelete: () => void;
  11. onSubmit: (event: any) => void;
  12. onTest: (event: any) => void;
  13. }
  14. const ButtonRow: FC<Props> = ({ canSave, canDelete, onDelete, onSubmit, onTest, exploreUrl }) => {
  15. const canExploreDataSources = contextSrv.hasPermission(AccessControlAction.DataSourcesExplore);
  16. return (
  17. <div className="gf-form-button-row">
  18. <Button variant="secondary" fill="solid" type="button" onClick={() => history.back()}>
  19. Back
  20. </Button>
  21. <LinkButton variant="secondary" fill="solid" href={exploreUrl} disabled={!canExploreDataSources}>
  22. Explore
  23. </LinkButton>
  24. <Button
  25. type="button"
  26. variant="destructive"
  27. disabled={!canDelete}
  28. onClick={onDelete}
  29. aria-label={selectors.pages.DataSource.delete}
  30. >
  31. Delete
  32. </Button>
  33. {canSave && (
  34. <Button
  35. type="submit"
  36. variant="primary"
  37. disabled={!canSave}
  38. onClick={(event) => onSubmit(event)}
  39. aria-label={selectors.pages.DataSource.saveAndTest}
  40. >
  41. Save &amp; test
  42. </Button>
  43. )}
  44. {!canSave && (
  45. <Button type="submit" variant="primary" onClick={onTest}>
  46. Test
  47. </Button>
  48. )}
  49. </div>
  50. );
  51. };
  52. export default ButtonRow;