CreateReportTab.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2, urlUtil } from '@grafana/data';
  4. import { featureEnabled } from '@grafana/runtime';
  5. import { LinkButton, useStyles2 } from '@grafana/ui';
  6. import { UpgradeBox, UpgradeContentVertical } from 'app/core/components/Upgrade/UpgradeBox';
  7. import { highlightTrial } from 'app/features/admin/utils';
  8. import { ShareModalTabProps } from 'app/features/dashboard/components/ShareModal';
  9. import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
  10. import { getVariablesUrlParams } from 'app/features/variables/getAllVariableValuesForUrl';
  11. export const CreateReportTab = ({ dashboard, onDismiss }: ShareModalTabProps) => {
  12. const styles = useStyles2(getStyles);
  13. const getUrl = () => {
  14. const variablesQuery = urlUtil.toUrlParams(getVariablesUrlParams());
  15. const timeRangeUrl = urlUtil.toUrlParams(getTimeSrv().timeRangeForUrl());
  16. return `?${variablesQuery}&${timeRangeUrl}&db-uid=${dashboard.uid}&db-id=${dashboard.id}&db-name=${dashboard.title}`;
  17. };
  18. const isReportsCreationDisabled = !featureEnabled('reports.creation');
  19. if (isReportsCreationDisabled) {
  20. return (
  21. <div className={styles.container}>
  22. <UpgradeBox featureName={'reporting'} featureId={'reporting-tab'} />
  23. <UpgradeContentVertical
  24. image={'reporting-email.png'}
  25. featureName={'reporting'}
  26. featureUrl={'https://grafana.com/docs/grafana/latest/enterprise/reporting'}
  27. description={
  28. 'Reporting allows you to automatically generate PDFs from any of your dashboards and have Grafana email them to interested parties on a schedule.'
  29. }
  30. />
  31. </div>
  32. );
  33. }
  34. return (
  35. <>
  36. {highlightTrial() && (
  37. <div className={styles.highlight}>
  38. <UpgradeBox
  39. featureId={'reporting-tab'}
  40. eventVariant={'trial'}
  41. featureName={'reporting'}
  42. text={'Create unlimited reports during your trial of Grafana Pro.'}
  43. />
  44. <h3>Get started with reporting</h3>
  45. <h6>
  46. Reporting allows you to automatically generate PDFs from any of your dashboards and have Grafana email them
  47. to interested parties on a schedule.
  48. </h6>
  49. </div>
  50. )}
  51. <LinkButton href={`reports/new/${getUrl()}`} onClick={onDismiss} className={styles.button}>
  52. Create report using this dashboard
  53. </LinkButton>
  54. {highlightTrial() && (
  55. <LinkButton fill="text" href={'https://grafana.com/docs/grafana/latest/enterprise/reporting'}>
  56. Learn more
  57. </LinkButton>
  58. )}
  59. </>
  60. );
  61. };
  62. const getStyles = (theme: GrafanaTheme2) => {
  63. return {
  64. container: css`
  65. display: flex;
  66. flex-direction: column;
  67. align-items: flex-start;
  68. `,
  69. button: css`
  70. margin-right: ${theme.spacing(2)};
  71. `,
  72. highlight: css`
  73. margin-bottom: ${theme.spacing(3)};
  74. h6 {
  75. font-weight: ${theme.typography.fontWeightLight};
  76. }
  77. `,
  78. };
  79. };