LicenseWarning.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { css } from '@emotion/css';
  2. import React, { FC } from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { Alert, useStyles } from '@grafana/ui';
  5. interface WarningProps {
  6. title: string;
  7. subTitle: JSX.Element;
  8. severity: 'info' | 'error';
  9. onButtonClick?: () => void;
  10. buttonText?: string;
  11. }
  12. const Warning: FC<WarningProps> = ({ title, subTitle, severity, onButtonClick, buttonText }) => {
  13. const styles = useStyles(getStyles);
  14. return (
  15. <div className={styles.container}>
  16. <div className="page-container">
  17. <Alert title={title} severity={severity} buttonContent={buttonText} onRemove={onButtonClick}>
  18. {subTitle}
  19. </Alert>
  20. </div>
  21. </div>
  22. );
  23. };
  24. interface LicensingLinkProps {
  25. isLicensingReader: boolean;
  26. }
  27. export const LicensingLink: FC<LicensingLinkProps> = ({ isLicensingReader, children }) => {
  28. if (isLicensingReader) {
  29. return <a href="/admin/licensing">{children}</a>;
  30. }
  31. return (
  32. <a
  33. href="https://grafana.com/docs/grafana/latest/enterprise/license-expiration/"
  34. target="_blank"
  35. rel="noreferrer noopener"
  36. >
  37. {children}
  38. </a>
  39. );
  40. };
  41. interface HasExpiredProps {
  42. isLicensingReader: boolean;
  43. }
  44. export const HasExpired: FC<HasExpiredProps> = ({ isLicensingReader }) => {
  45. return (
  46. <Warning
  47. title="Your Grafana Enterprise license has expired"
  48. subTitle={
  49. <>
  50. <LicensingLink isLicensingReader={isLicensingReader}>Some features</LicensingLink> have been disabled.
  51. </>
  52. }
  53. severity="error"
  54. />
  55. );
  56. };
  57. interface IsInvalidProps {
  58. isLicensingReader: boolean;
  59. }
  60. export const IsInvalid: FC<IsInvalidProps> = ({ isLicensingReader }) => {
  61. return (
  62. <Warning
  63. title="Your Grafana Enterprise license is invalid"
  64. subTitle={
  65. <>
  66. <LicensingLink isLicensingReader={isLicensingReader}>Some features</LicensingLink> have been disabled.
  67. </>
  68. }
  69. severity="error"
  70. />
  71. );
  72. };
  73. interface ExpiresSoonProps {
  74. days: number;
  75. onCloseWarning?(): void;
  76. isLicensingReader: boolean;
  77. }
  78. export const ExpiresSoon: FC<ExpiresSoonProps> = ({ days, onCloseWarning, isLicensingReader }) => {
  79. return (
  80. <Warning
  81. onButtonClick={onCloseWarning}
  82. title="Your Grafana Enterprise license will expire soon"
  83. subTitle={
  84. <>
  85. {days} days remaining, after which{' '}
  86. <LicensingLink isLicensingReader={isLicensingReader}>Enterprise features will be disabled.</LicensingLink>
  87. </>
  88. }
  89. severity="info"
  90. buttonText="Dismiss"
  91. />
  92. );
  93. };
  94. interface TokenExpiresSoonProps {
  95. days: number;
  96. onCloseWarning?(): void;
  97. isLicensingReader: boolean;
  98. }
  99. export const TokenExpiresSoon: FC<TokenExpiresSoonProps> = ({ days, onCloseWarning, isLicensingReader }) => {
  100. return (
  101. <Warning
  102. onButtonClick={onCloseWarning}
  103. title="Your Grafana Enterprise token needs to be renewed"
  104. subTitle={
  105. <>
  106. Your license token has {days} days remaining, after which{' '}
  107. <LicensingLink isLicensingReader={isLicensingReader}>Enterprise features will be disabled.</LicensingLink>
  108. </>
  109. }
  110. severity="info"
  111. buttonText="Dismiss"
  112. />
  113. );
  114. };
  115. interface MaxUsersReachedProps {
  116. activeUsers: number;
  117. maxUsers: number;
  118. onRefreshWarning?: () => void;
  119. slug?: string;
  120. }
  121. export const MaxUsersReached: FC<MaxUsersReachedProps> = ({ activeUsers, maxUsers, slug, onRefreshWarning }) => {
  122. return (
  123. <Warning
  124. onButtonClick={onRefreshWarning}
  125. title={'You have exceeded the included number of active users'}
  126. subTitle={
  127. <>
  128. Your Grafana Enterprise license includes {maxUsers} active users; you currently have {activeUsers} active
  129. users. Please{' '}
  130. {slug ? (
  131. <a href={'https://grafana.com/orgs/' + slug + '/licenses'} target="_blank" rel="noreferrer noopener">
  132. upgrade your license.
  133. </a>
  134. ) : (
  135. 'upgrade your license.'
  136. )}
  137. </>
  138. }
  139. severity="error"
  140. buttonText="Refresh"
  141. />
  142. );
  143. };
  144. export const getStyles = (theme: GrafanaTheme) => {
  145. return {
  146. container: css`
  147. position: absolute;
  148. bottom: 0;
  149. width: 100%;
  150. display: flex;
  151. flex-direction: column;
  152. justify-content: center;
  153. z-index: 3;
  154. `,
  155. };
  156. };