| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | import { css, cx } from '@emotion/css'; | 
					
						
							| 
									
										
										
										
											2024-06-25 19:43:47 +08:00
										 |  |  |  | import { HTMLAttributes, useEffect } from 'react'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | import { GrafanaTheme2 } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  | import { reportExperimentView } from '@grafana/runtime/src'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  |  | import { Button, Icon, LinkButton, useStyles2 } from '@grafana/ui'; | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  | import { t, Trans } from 'app/core/internationalization'; | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 15:15:45 +08:00
										 |  |  |  | type ComponentSize = 'sm' | 'md'; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | export interface Props extends HTMLAttributes<HTMLOrSVGElement> { | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |   featureName: string; | 
					
						
							| 
									
										
										
										
											2022-01-26 15:15:45 +08:00
										 |  |  |  |   size?: ComponentSize; | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  |   text?: string; | 
					
						
							|  |  |  |  |   eventVariant?: string; | 
					
						
							|  |  |  |  |   featureId: string; | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  | export const UpgradeBox = ({ | 
					
						
							|  |  |  |  |   featureName, | 
					
						
							|  |  |  |  |   className, | 
					
						
							|  |  |  |  |   children, | 
					
						
							|  |  |  |  |   text, | 
					
						
							|  |  |  |  |   featureId, | 
					
						
							|  |  |  |  |   eventVariant = '', | 
					
						
							|  |  |  |  |   size = 'md', | 
					
						
							|  |  |  |  |   ...htmlProps | 
					
						
							|  |  |  |  | }: Props) => { | 
					
						
							| 
									
										
										
										
											2023-10-09 17:49:08 +08:00
										 |  |  |  |   const styles = useStyles2(getUpgradeBoxStyles, size); | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |  |     reportExperimentView(`feature-highlights-${featureId}`, 'test', eventVariant); | 
					
						
							|  |  |  |  |   }, [eventVariant, featureId]); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  |   return ( | 
					
						
							|  |  |  |  |     <div className={cx(styles.box, className)} {...htmlProps}> | 
					
						
							| 
									
										
										
										
											2022-02-08 15:53:57 +08:00
										 |  |  |  |       <Icon name={'rocket'} className={styles.icon} /> | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |       <div className={styles.inner}> | 
					
						
							|  |  |  |  |         <p className={styles.text}> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  |           <Trans i18nKey="upgrade-box.discovery-text">You’ve discovered a Pro feature!</Trans>{' '} | 
					
						
							|  |  |  |  |           {text || | 
					
						
							|  |  |  |  |             t('upgrade-box.discovery-text-continued', 'Get the Grafana Pro plan to access {{featureName}}.', { | 
					
						
							|  |  |  |  |               featureName, | 
					
						
							|  |  |  |  |             })} | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |         </p> | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  |         <LinkButton | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |           variant="secondary" | 
					
						
							| 
									
										
										
										
											2022-01-26 15:15:45 +08:00
										 |  |  |  |           size={size} | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  |           className={styles.button} | 
					
						
							|  |  |  |  |           href="https://grafana.com/profile/org/subscription" | 
					
						
							|  |  |  |  |           target="__blank" | 
					
						
							|  |  |  |  |           rel="noopener noreferrer" | 
					
						
							|  |  |  |  |         > | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  |           <Trans i18nKey="upgrade-box.upgrade-button">Upgrade</Trans> | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  |         </LinkButton> | 
					
						
							|  |  |  |  |       </div> | 
					
						
							|  |  |  |  |     </div> | 
					
						
							|  |  |  |  |   ); | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 15:15:45 +08:00
										 |  |  |  | const getUpgradeBoxStyles = (theme: GrafanaTheme2, size: ComponentSize) => { | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  |   const borderRadius = theme.shape.borderRadius(2); | 
					
						
							| 
									
										
										
										
											2022-01-26 15:15:45 +08:00
										 |  |  |  |   const fontBase = size === 'md' ? 'body' : 'bodySmall'; | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |     box: css({ | 
					
						
							|  |  |  |  |       display: 'flex', | 
					
						
							|  |  |  |  |       alignItems: 'center', | 
					
						
							|  |  |  |  |       position: 'relative', | 
					
						
							|  |  |  |  |       borderRadius: borderRadius, | 
					
						
							|  |  |  |  |       background: theme.colors.success.transparent, | 
					
						
							|  |  |  |  |       padding: theme.spacing(2), | 
					
						
							|  |  |  |  |       color: theme.colors.success.text, | 
					
						
							|  |  |  |  |       fontSize: theme.typography[fontBase].fontSize, | 
					
						
							|  |  |  |  |       textAlign: 'left', | 
					
						
							|  |  |  |  |       lineHeight: '16px', | 
					
						
							|  |  |  |  |       margin: theme.spacing(0, 'auto', 3, 'auto'), | 
					
						
							|  |  |  |  |       maxWidth: `${theme.breakpoints.values.xxl}px`, | 
					
						
							|  |  |  |  |       width: '100%', | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     inner: css({ | 
					
						
							|  |  |  |  |       display: 'flex', | 
					
						
							|  |  |  |  |       alignItems: 'center', | 
					
						
							|  |  |  |  |       width: '100%', | 
					
						
							|  |  |  |  |       justifyContent: 'space-between', | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     text: css({ | 
					
						
							|  |  |  |  |       margin: 0, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     button: css({ | 
					
						
							|  |  |  |  |       backgroundColor: theme.colors.success.main, | 
					
						
							|  |  |  |  |       fontWeight: theme.typography.fontWeightLight, | 
					
						
							|  |  |  |  |       color: 'white', | 
					
						
							| 
									
										
										
										
											2022-01-26 15:15:45 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |       '&:hover': { | 
					
						
							|  |  |  |  |         backgroundColor: theme.colors.success.main, | 
					
						
							|  |  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-02-08 15:53:57 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |       '&:focus-visible': { | 
					
						
							|  |  |  |  |         boxShadow: 'none', | 
					
						
							|  |  |  |  |         color: theme.colors.text.primary, | 
					
						
							|  |  |  |  |         outline: `2px solid ${theme.colors.primary.main}`, | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     icon: css({ | 
					
						
							|  |  |  |  |       margin: theme.spacing(0.5, 1, 0.5, 0.5), | 
					
						
							|  |  |  |  |     }), | 
					
						
							| 
									
										
										
										
											2022-01-25 16:04:44 +08:00
										 |  |  |  |   }; | 
					
						
							|  |  |  |  | }; | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | export interface UpgradeContentProps { | 
					
						
							|  |  |  |  |   image: string; | 
					
						
							|  |  |  |  |   featureUrl?: string; | 
					
						
							|  |  |  |  |   featureName: string; | 
					
						
							|  |  |  |  |   description?: string; | 
					
						
							|  |  |  |  |   listItems: string[]; | 
					
						
							|  |  |  |  |   caption?: string; | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  |   action?: { | 
					
						
							|  |  |  |  |     text: string; | 
					
						
							|  |  |  |  |     link?: string; | 
					
						
							|  |  |  |  |     onClick?: () => void; | 
					
						
							|  |  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | export const UpgradeContent = ({ | 
					
						
							|  |  |  |  |   listItems, | 
					
						
							|  |  |  |  |   image, | 
					
						
							|  |  |  |  |   featureUrl, | 
					
						
							|  |  |  |  |   featureName, | 
					
						
							|  |  |  |  |   description, | 
					
						
							|  |  |  |  |   caption, | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  |   action, | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  | }: UpgradeContentProps) => { | 
					
						
							|  |  |  |  |   const styles = useStyles2(getUpgradeContentStyles); | 
					
						
							|  |  |  |  |   return ( | 
					
						
							|  |  |  |  |     <div className={styles.container}> | 
					
						
							|  |  |  |  |       <div className={styles.content}> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  |         <h3 className={styles.title}> | 
					
						
							|  |  |  |  |           <Trans i18nKey="upgrade-box.get-started">Get started with {{ featureName }}</Trans> | 
					
						
							|  |  |  |  |         </h3> | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |         {description && <h6 className={styles.description}>{description}</h6>} | 
					
						
							|  |  |  |  |         <ul className={styles.list}> | 
					
						
							|  |  |  |  |           {listItems.map((item, index) => ( | 
					
						
							|  |  |  |  |             <li key={index}> | 
					
						
							|  |  |  |  |               <Icon name={'check'} size={'xl'} className={styles.icon} /> {item} | 
					
						
							|  |  |  |  |             </li> | 
					
						
							|  |  |  |  |           ))} | 
					
						
							|  |  |  |  |         </ul> | 
					
						
							| 
									
										
										
										
											2022-04-20 20:08:49 +08:00
										 |  |  |  |         {action?.link && ( | 
					
						
							|  |  |  |  |           <LinkButton variant={'primary'} href={action.link}> | 
					
						
							|  |  |  |  |             {action.text} | 
					
						
							|  |  |  |  |           </LinkButton> | 
					
						
							|  |  |  |  |         )} | 
					
						
							|  |  |  |  |         {action?.onClick && ( | 
					
						
							|  |  |  |  |           <Button variant={'primary'} onClick={action.onClick}> | 
					
						
							|  |  |  |  |             {action.text} | 
					
						
							|  |  |  |  |           </Button> | 
					
						
							|  |  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |         {featureUrl && ( | 
					
						
							|  |  |  |  |           <LinkButton fill={'text'} href={featureUrl} className={styles.link} target="_blank" rel="noreferrer noopener"> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  |             <Trans i18nKey="upgrade-box.learn-more">Learn more</Trans> | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |           </LinkButton> | 
					
						
							|  |  |  |  |         )} | 
					
						
							|  |  |  |  |       </div> | 
					
						
							|  |  |  |  |       <div className={styles.media}> | 
					
						
							|  |  |  |  |         <img src={getImgUrl(image)} alt={'Feature screenshot'} /> | 
					
						
							|  |  |  |  |         {caption && <p className={styles.caption}>{caption}</p>} | 
					
						
							|  |  |  |  |       </div> | 
					
						
							|  |  |  |  |     </div> | 
					
						
							|  |  |  |  |   ); | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const getUpgradeContentStyles = (theme: GrafanaTheme2) => { | 
					
						
							|  |  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |     container: css({ | 
					
						
							|  |  |  |  |       display: 'flex', | 
					
						
							|  |  |  |  |       justifyContent: 'space-between', | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     content: css({ | 
					
						
							|  |  |  |  |       width: '45%', | 
					
						
							|  |  |  |  |       marginRight: theme.spacing(4), | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     media: css({ | 
					
						
							|  |  |  |  |       width: '55%', | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |       img: { | 
					
						
							|  |  |  |  |         width: '100%', | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     title: css({ | 
					
						
							|  |  |  |  |       color: theme.colors.text.maxContrast, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     description: css({ | 
					
						
							|  |  |  |  |       color: theme.colors.text.primary, | 
					
						
							|  |  |  |  |       fontWeight: theme.typography.fontWeightLight, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     list: css({ | 
					
						
							|  |  |  |  |       listStyle: 'none', | 
					
						
							|  |  |  |  |       margin: theme.spacing(4, 0, 2, 0), | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |       li: { | 
					
						
							|  |  |  |  |         display: 'flex', | 
					
						
							|  |  |  |  |         alignItems: 'flex-start', | 
					
						
							|  |  |  |  |         color: theme.colors.text.primary, | 
					
						
							|  |  |  |  |         padding: theme.spacing(1, 0), | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     icon: css({ | 
					
						
							|  |  |  |  |       color: theme.colors.success.main, | 
					
						
							|  |  |  |  |       marginRight: theme.spacing(1), | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     link: css({ | 
					
						
							|  |  |  |  |       marginLeft: theme.spacing(2), | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     caption: css({ | 
					
						
							|  |  |  |  |       fontWeight: theme.typography.fontWeightLight, | 
					
						
							|  |  |  |  |       margin: theme.spacing(1, 0, 0), | 
					
						
							|  |  |  |  |     }), | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |   }; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | export const UpgradeContentVertical = ({ | 
					
						
							|  |  |  |  |   featureName, | 
					
						
							|  |  |  |  |   description, | 
					
						
							|  |  |  |  |   featureUrl, | 
					
						
							|  |  |  |  |   image, | 
					
						
							|  |  |  |  | }: Omit<UpgradeContentProps, 'listItems' | 'caption'>) => { | 
					
						
							|  |  |  |  |   const styles = useStyles2(getContentVerticalStyles); | 
					
						
							|  |  |  |  |   return ( | 
					
						
							|  |  |  |  |     <div className={styles.container}> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  |       <h3 className={styles.title}> | 
					
						
							|  |  |  |  |         <Trans i18nKey="upgrade-box.get-started">Get started with {{ featureName }}</Trans> | 
					
						
							|  |  |  |  |       </h3> | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |       {description && <h6 className={styles.description}>{description}</h6>} | 
					
						
							|  |  |  |  |       <LinkButton fill={'text'} href={featureUrl} target="_blank" rel="noreferrer noopener"> | 
					
						
							| 
									
										
										
										
											2024-11-21 20:59:14 +08:00
										 |  |  |  |         <Trans i18nKey="upgrade-box.learn-more">Learn more</Trans> | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |       </LinkButton> | 
					
						
							|  |  |  |  |       <div className={styles.media}> | 
					
						
							|  |  |  |  |         <img src={getImgUrl(image)} alt={'Feature screenshot'} /> | 
					
						
							|  |  |  |  |       </div> | 
					
						
							|  |  |  |  |     </div> | 
					
						
							|  |  |  |  |   ); | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const getContentVerticalStyles = (theme: GrafanaTheme2) => { | 
					
						
							|  |  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |     container: css({ | 
					
						
							|  |  |  |  |       overflow: 'auto', | 
					
						
							|  |  |  |  |       height: '100%', | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     title: css({ | 
					
						
							|  |  |  |  |       color: theme.colors.text.maxContrast, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     description: css({ | 
					
						
							|  |  |  |  |       color: theme.colors.text.primary, | 
					
						
							|  |  |  |  |       fontWeight: theme.typography.fontWeightLight, | 
					
						
							|  |  |  |  |     }), | 
					
						
							|  |  |  |  |     media: css({ | 
					
						
							|  |  |  |  |       width: '100%', | 
					
						
							|  |  |  |  |       marginTop: theme.spacing(2), | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-23 22:25:28 +08:00
										 |  |  |  |       img: { | 
					
						
							|  |  |  |  |         width: '100%', | 
					
						
							|  |  |  |  |       }, | 
					
						
							|  |  |  |  |     }), | 
					
						
							| 
									
										
										
										
											2022-03-30 20:46:56 +08:00
										 |  |  |  |   }; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | const getImgUrl = (urlOrId: string) => { | 
					
						
							|  |  |  |  |   if (urlOrId.startsWith('http')) { | 
					
						
							|  |  |  |  |     return urlOrId; | 
					
						
							|  |  |  |  |   } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return '/public/img/enterprise/highlights/' + urlOrId; | 
					
						
							|  |  |  |  | }; |