CloudInfoBox.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { FC } from 'react';
  2. import { DataSourceSettings } from '@grafana/data';
  3. import { GrafanaEdition } from '@grafana/data/src/types/config';
  4. import { Alert } from '@grafana/ui';
  5. import { LocalStorageValueProvider } from 'app/core/components/LocalStorageValueProvider';
  6. import { config } from 'app/core/config';
  7. const LOCAL_STORAGE_KEY = 'datasources.settings.cloudInfoBox.isDismissed';
  8. export interface Props {
  9. dataSource: DataSourceSettings;
  10. }
  11. export const CloudInfoBox: FC<Props> = ({ dataSource }) => {
  12. let mainDS = '';
  13. let extraDS = '';
  14. // don't show for already configured data sources or provisioned data sources
  15. if (dataSource.readOnly || (dataSource.version ?? 0) > 2) {
  16. return null;
  17. }
  18. // Skip showing this info box in some editions
  19. if (config.buildInfo.edition !== GrafanaEdition.OpenSource) {
  20. return null;
  21. }
  22. switch (dataSource.type) {
  23. case 'prometheus':
  24. mainDS = 'Prometheus';
  25. extraDS = 'Loki';
  26. break;
  27. case 'loki':
  28. mainDS = 'Loki';
  29. extraDS = 'Prometheus';
  30. break;
  31. default:
  32. return null;
  33. }
  34. return (
  35. <LocalStorageValueProvider<boolean> storageKey={LOCAL_STORAGE_KEY} defaultValue={false}>
  36. {(isDismissed, onDismiss) => {
  37. if (isDismissed) {
  38. return null;
  39. }
  40. return (
  41. <Alert
  42. title={`Configure your ${mainDS} data source below`}
  43. severity="info"
  44. bottomSpacing={4}
  45. onRemove={() => {
  46. onDismiss(true);
  47. }}
  48. >
  49. Or skip the effort and get {mainDS} (and {extraDS}) as fully-managed, scalable, and hosted data sources from
  50. Grafana Labs with the{' '}
  51. <a
  52. className="external-link"
  53. href={`https://grafana.com/signup/cloud/connect-account?src=grafana-oss&cnt=${dataSource.type}-settings`}
  54. target="_blank"
  55. rel="noreferrer"
  56. title="The free plan includes 10k active metrics and 50gb storage."
  57. >
  58. free-forever Grafana Cloud plan
  59. </a>
  60. .
  61. </Alert>
  62. );
  63. }}
  64. </LocalStorageValueProvider>
  65. );
  66. };