2022-04-22 21:33:13 +08:00
|
|
|
import { css } from '@emotion/css';
|
2024-06-25 19:43:47 +08:00
|
|
|
import { MouseEvent } from 'react';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2022-10-26 20:28:12 +08:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2025-05-30 01:13:25 +08:00
|
|
|
import { useTranslate } from '@grafana/i18n';
|
2024-01-19 17:50:56 +08:00
|
|
|
import { reportInteraction } from '@grafana/runtime';
|
|
|
|
import { useStyles2 } from '@grafana/ui';
|
2020-05-13 14:00:40 +08:00
|
|
|
import store from 'app/core/store';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2020-05-13 16:02:20 +08:00
|
|
|
import { TutorialCardType } from '../types';
|
2020-05-13 14:00:40 +08:00
|
|
|
|
2024-01-19 17:50:56 +08:00
|
|
|
import { cardContent, cardStyle } from './sharedStyles';
|
2022-04-22 21:33:13 +08:00
|
|
|
|
2020-05-13 14:00:40 +08:00
|
|
|
interface Props {
|
2020-05-13 16:02:20 +08:00
|
|
|
card: TutorialCardType;
|
2020-05-13 14:00:40 +08:00
|
|
|
}
|
|
|
|
|
2023-01-06 01:55:55 +08:00
|
|
|
export const TutorialCard = ({ card }: Props) => {
|
2025-05-30 01:13:25 +08:00
|
|
|
const { t } = useTranslate();
|
2023-10-09 17:49:08 +08:00
|
|
|
const styles = useStyles2(getStyles, card.done);
|
2020-05-13 14:00:40 +08:00
|
|
|
|
|
|
|
return (
|
2022-10-21 15:13:32 +08:00
|
|
|
<a
|
|
|
|
className={styles.card}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
href={`${card.href}?utm_source=grafana_gettingstarted`}
|
|
|
|
onClick={(event: MouseEvent<HTMLAnchorElement>) => handleTutorialClick(event, card)}
|
|
|
|
>
|
2020-05-13 14:00:40 +08:00
|
|
|
<div className={cardContent}>
|
|
|
|
<div className={styles.type}>{card.type}</div>
|
2025-05-30 01:13:25 +08:00
|
|
|
<div className={styles.heading}>
|
|
|
|
{card.done ? t('gettingstarted.tutorial-card.complete', 'complete') : card.heading}
|
|
|
|
</div>
|
2021-05-11 22:34:44 +08:00
|
|
|
<h4 className={styles.cardTitle}>{card.title}</h4>
|
2020-05-13 14:00:40 +08:00
|
|
|
<div className={styles.info}>{card.info}</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-13 16:02:20 +08:00
|
|
|
const handleTutorialClick = (event: MouseEvent<HTMLAnchorElement>, card: TutorialCardType) => {
|
2020-05-13 14:00:40 +08:00
|
|
|
const isSet = store.get(card.key);
|
|
|
|
if (!isSet) {
|
|
|
|
store.set(card.key, true);
|
|
|
|
}
|
2024-01-19 17:50:56 +08:00
|
|
|
reportInteraction('grafana_getting_started_tutorial', { title: card.title });
|
2020-05-13 14:00:40 +08:00
|
|
|
};
|
|
|
|
|
2022-10-26 20:28:12 +08:00
|
|
|
const getStyles = (theme: GrafanaTheme2, complete: boolean) => {
|
2020-05-13 14:00:40 +08:00
|
|
|
return {
|
2024-10-25 21:50:28 +08:00
|
|
|
card: css({
|
|
|
|
...cardStyle(theme, complete),
|
|
|
|
width: '460px',
|
|
|
|
minWidth: '460px',
|
2020-05-13 14:00:40 +08:00
|
|
|
|
2024-10-25 21:50:28 +08:00
|
|
|
[theme.breakpoints.down('xl')]: {
|
|
|
|
minWidth: '368px',
|
|
|
|
},
|
2020-05-13 14:00:40 +08:00
|
|
|
|
2024-10-25 21:50:28 +08:00
|
|
|
[theme.breakpoints.down('lg')]: {
|
|
|
|
minWidth: '272px',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
type: css({
|
|
|
|
color: theme.colors.primary.text,
|
|
|
|
textTransform: 'uppercase',
|
|
|
|
}),
|
|
|
|
heading: css({
|
|
|
|
textTransform: 'uppercase',
|
|
|
|
color: theme.colors.primary.text,
|
|
|
|
marginBottom: theme.spacing(1),
|
|
|
|
}),
|
|
|
|
cardTitle: css({
|
|
|
|
marginBottom: theme.spacing(2),
|
|
|
|
}),
|
|
|
|
info: css({
|
|
|
|
marginBottom: theme.spacing(2),
|
|
|
|
}),
|
|
|
|
status: css({
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'flex-end',
|
|
|
|
}),
|
2020-05-13 14:00:40 +08:00
|
|
|
};
|
2022-10-26 20:28:12 +08:00
|
|
|
};
|