XrayLinkConfig.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { DataSourcePicker } from '@grafana/runtime';
  5. import { Alert, InlineField, useStyles2 } from '@grafana/ui';
  6. import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
  7. const getStyles = (theme: GrafanaTheme2) => ({
  8. infoText: css`
  9. padding-bottom: ${theme.spacing(2)};
  10. color: ${theme.colors.text.secondary};
  11. `,
  12. });
  13. interface Props {
  14. datasourceUid?: string;
  15. onChange: (uid: string) => void;
  16. }
  17. const xRayDsId = 'grafana-x-ray-datasource';
  18. export function XrayLinkConfig({ datasourceUid, onChange }: Props) {
  19. const hasXrayDatasource = Boolean(getDatasourceSrv().getList({ pluginId: xRayDsId }).length);
  20. const styles = useStyles2(getStyles);
  21. return (
  22. <>
  23. <h3 className="page-heading">X-ray trace link</h3>
  24. <div className={styles.infoText}>
  25. Grafana will automatically create a link to a trace in X-ray data source if logs contain @xrayTraceId field
  26. </div>
  27. {!hasXrayDatasource && (
  28. <Alert
  29. title={
  30. 'There is no X-ray datasource to link to. First add an X-ray data source and then link it to Cloud Watch. '
  31. }
  32. severity="info"
  33. />
  34. )}
  35. <div className="gf-form-group">
  36. <InlineField
  37. htmlFor="data-source-picker"
  38. label="Data source"
  39. labelWidth={28}
  40. tooltip="X-ray data source containing traces"
  41. >
  42. <DataSourcePicker
  43. pluginId={xRayDsId}
  44. onChange={(ds) => onChange(ds.uid)}
  45. current={datasourceUid}
  46. noDefault={true}
  47. />
  48. </InlineField>
  49. </div>
  50. </>
  51. );
  52. }