ExemplarSetting.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { css } from '@emotion/css';
  2. import React, { useState } from 'react';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { DataSourcePicker } from '@grafana/runtime';
  5. import { Button, InlineField, InlineSwitch, Input } from '@grafana/ui';
  6. import { ExemplarTraceIdDestination } from '../types';
  7. type Props = {
  8. value: ExemplarTraceIdDestination;
  9. onChange: (value: ExemplarTraceIdDestination) => void;
  10. onDelete: () => void;
  11. };
  12. export default function ExemplarSetting({ value, onChange, onDelete }: Props) {
  13. const [isInternalLink, setIsInternalLink] = useState(Boolean(value.datasourceUid));
  14. return (
  15. <div className="gf-form-group">
  16. <InlineField label="Internal link" labelWidth={24}>
  17. <>
  18. <InlineSwitch
  19. value={isInternalLink}
  20. aria-label={selectors.components.DataSource.Prometheus.configPage.internalLinkSwitch}
  21. onChange={(ev) => setIsInternalLink(ev.currentTarget.checked)}
  22. />
  23. <Button
  24. variant="destructive"
  25. title="Remove link"
  26. icon="times"
  27. onClick={(event) => {
  28. event.preventDefault();
  29. onDelete();
  30. }}
  31. className={css`
  32. margin-left: 8px;
  33. `}
  34. />
  35. </>
  36. </InlineField>
  37. {isInternalLink ? (
  38. <InlineField
  39. label="Data source"
  40. labelWidth={24}
  41. tooltip="The data source the exemplar is going to navigate to."
  42. >
  43. <DataSourcePicker
  44. tracing={true}
  45. current={value.datasourceUid}
  46. noDefault={true}
  47. width={40}
  48. onChange={(ds) =>
  49. onChange({
  50. ...value,
  51. datasourceUid: ds.uid,
  52. url: undefined,
  53. })
  54. }
  55. />
  56. </InlineField>
  57. ) : (
  58. <InlineField
  59. label="URL"
  60. labelWidth={24}
  61. tooltip="The URL of the trace backend the user would go to see its trace."
  62. >
  63. <Input
  64. placeholder="https://example.com/${__value.raw}"
  65. spellCheck={false}
  66. width={40}
  67. value={value.url}
  68. onChange={(event) =>
  69. onChange({
  70. ...value,
  71. datasourceUid: undefined,
  72. url: event.currentTarget.value,
  73. })
  74. }
  75. />
  76. </InlineField>
  77. )}
  78. <InlineField
  79. label="URL Label"
  80. labelWidth={24}
  81. tooltip="Use to override the button label on the exemplar traceID field."
  82. >
  83. <Input
  84. placeholder="Go to example.com"
  85. spellCheck={false}
  86. width={40}
  87. value={value.urlDisplayLabel}
  88. onChange={(event) =>
  89. onChange({
  90. ...value,
  91. urlDisplayLabel: event.currentTarget.value,
  92. })
  93. }
  94. />
  95. </InlineField>
  96. <InlineField
  97. label="Label name"
  98. labelWidth={24}
  99. tooltip="The name of the field in the labels object that should be used to get the traceID."
  100. >
  101. <Input
  102. placeholder="traceID"
  103. spellCheck={false}
  104. width={40}
  105. value={value.name}
  106. onChange={(event) =>
  107. onChange({
  108. ...value,
  109. name: event.currentTarget.value,
  110. })
  111. }
  112. />
  113. </InlineField>
  114. </div>
  115. );
  116. }