LokiSearchSettings.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { DataSourcePluginOptionsEditorProps, GrafanaTheme, updateDatasourcePluginJsonDataOption } from '@grafana/data';
  4. import { DataSourcePicker } from '@grafana/runtime';
  5. import { Button, InlineField, InlineFieldRow, useStyles } from '@grafana/ui';
  6. import { TempoJsonData } from '../datasource';
  7. interface Props extends DataSourcePluginOptionsEditorProps<TempoJsonData> {}
  8. export function LokiSearchSettings({ options, onOptionsChange }: Props) {
  9. const styles = useStyles(getStyles);
  10. // Default to the trace to logs datasource if configured and loki search was enabled
  11. // but only if jsonData.lokiSearch hasn't been set
  12. const legacyDatasource =
  13. options.jsonData.tracesToLogs?.lokiSearch !== false ? options.jsonData.tracesToLogs?.datasourceUid : undefined;
  14. if (legacyDatasource && options.jsonData.lokiSearch === undefined) {
  15. updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'lokiSearch', {
  16. datasourceUid: legacyDatasource,
  17. });
  18. }
  19. return (
  20. <div className={css({ width: '100%' })}>
  21. <h3 className="page-heading">Loki Search</h3>
  22. <div className={styles.infoText}>
  23. Select a Loki datasource to search for traces. Derived fields must be configured in the Loki data source.
  24. </div>
  25. <InlineFieldRow className={styles.row}>
  26. <InlineField tooltip="The Loki data source with the service graph data" label="Data source" labelWidth={26}>
  27. <DataSourcePicker
  28. inputId="loki-search-data-source-picker"
  29. pluginId="loki"
  30. current={options.jsonData.lokiSearch?.datasourceUid}
  31. noDefault={true}
  32. width={40}
  33. onChange={(ds) =>
  34. updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'lokiSearch', {
  35. datasourceUid: ds.uid,
  36. })
  37. }
  38. />
  39. </InlineField>
  40. {options.jsonData.lokiSearch?.datasourceUid ? (
  41. <Button
  42. type={'button'}
  43. variant={'secondary'}
  44. size={'sm'}
  45. fill={'text'}
  46. onClick={() => {
  47. updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'lokiSearch', {
  48. datasourceUid: undefined,
  49. });
  50. }}
  51. >
  52. Clear
  53. </Button>
  54. ) : null}
  55. </InlineFieldRow>
  56. </div>
  57. );
  58. }
  59. const getStyles = (theme: GrafanaTheme) => ({
  60. infoText: css`
  61. label: infoText;
  62. padding-bottom: ${theme.spacing.md};
  63. color: ${theme.colors.textSemiWeak};
  64. `,
  65. row: css`
  66. label: row;
  67. align-items: baseline;
  68. `,
  69. });