2023-04-19 08:08:09 -05:00
|
|
|
import { css, cx } from '@emotion/css';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { DataSourceInstanceSettings, GrafanaTheme2 } from '@grafana/data';
|
|
|
|
import { Card, TagList, useStyles2 } from '@grafana/ui';
|
|
|
|
|
|
|
|
interface DataSourceCardProps {
|
|
|
|
ds: DataSourceInstanceSettings;
|
|
|
|
onClick: () => void;
|
|
|
|
selected: boolean;
|
2023-05-10 13:56:00 -05:00
|
|
|
description?: string;
|
2023-04-19 08:08:09 -05:00
|
|
|
}
|
|
|
|
|
2023-05-10 13:56:00 -05:00
|
|
|
export function DataSourceCard({ ds, onClick, selected, description, ...htmlProps }: DataSourceCardProps) {
|
2023-04-19 08:08:09 -05:00
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
|
|
|
|
return (
|
2023-04-28 11:19:31 -05:00
|
|
|
<Card
|
|
|
|
key={ds.uid}
|
|
|
|
onClick={onClick}
|
|
|
|
className={cx(styles.card, selected ? styles.selected : undefined)}
|
|
|
|
{...htmlProps}
|
|
|
|
>
|
2023-04-21 04:25:03 -05:00
|
|
|
<Card.Heading className={styles.heading}>
|
|
|
|
<div className={styles.headingContent}>
|
2023-04-25 03:41:31 -05:00
|
|
|
<span className={styles.name}>{ds.name}</span>
|
|
|
|
<span className={styles.separator}>|</span>
|
2023-05-10 13:56:00 -05:00
|
|
|
<small className={styles.type}>{description || ds.meta.name}</small>
|
2023-04-21 04:25:03 -05:00
|
|
|
</div>
|
|
|
|
</Card.Heading>
|
2023-04-25 03:41:31 -05:00
|
|
|
<Card.Figure className={styles.logo}>
|
|
|
|
<img src={ds.meta.info.logos.small} alt={`${ds.meta.name} Logo`} />
|
2023-04-19 08:08:09 -05:00
|
|
|
</Card.Figure>
|
|
|
|
<Card.Tags>{ds.isDefault ? <TagList tags={['default']} /> : null}</Card.Tags>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get styles for the component
|
|
|
|
function getStyles(theme: GrafanaTheme2) {
|
|
|
|
return {
|
|
|
|
card: css`
|
|
|
|
cursor: pointer;
|
|
|
|
background-color: ${theme.colors.background.primary};
|
|
|
|
border-bottom: 1px solid ${theme.colors.border.weak};
|
|
|
|
// Move to list component
|
|
|
|
margin-bottom: 0;
|
|
|
|
border-radius: 0;
|
2023-04-21 04:25:03 -05:00
|
|
|
padding: ${theme.spacing(1.5)};
|
|
|
|
`,
|
|
|
|
heading: css`
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
// This is needed to enable ellipsis when text overlfows
|
|
|
|
> button {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
headingContent: css`
|
|
|
|
color: ${theme.colors.text.secondary};
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
`,
|
2023-04-25 03:41:31 -05:00
|
|
|
logo: css`
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
2023-04-26 08:07:51 -05:00
|
|
|
padding-right: ${theme.spacing(1.5)};
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
> img {
|
|
|
|
max-height: 100%;
|
|
|
|
min-width: 32px;
|
|
|
|
}
|
2023-04-25 03:41:31 -05:00
|
|
|
`,
|
|
|
|
name: css`
|
2023-04-21 04:25:03 -05:00
|
|
|
color: ${theme.colors.text.primary};
|
|
|
|
`,
|
2023-04-25 03:41:31 -05:00
|
|
|
type: css`
|
2023-04-21 04:25:03 -05:00
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
`,
|
2023-04-25 03:41:31 -05:00
|
|
|
separator: css`
|
2023-04-21 04:25:03 -05:00
|
|
|
margin: 0 ${theme.spacing(1)};
|
|
|
|
color: ${theme.colors.border.weak};
|
2023-04-19 08:08:09 -05:00
|
|
|
`,
|
|
|
|
selected: css`
|
|
|
|
background-color: ${theme.colors.background.secondary};
|
|
|
|
`,
|
|
|
|
meta: css`
|
|
|
|
display: block;
|
|
|
|
overflow-wrap: unset;
|
|
|
|
white-space: nowrap;
|
|
|
|
width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
}
|