2021-01-15 16:20:20 +01:00
|
|
|
import { Button, InlineField, InlineSwitch, Input } from '@grafana/ui';
|
2021-03-18 10:44:26 +01:00
|
|
|
import { DataSourcePicker } from '@grafana/runtime';
|
2021-01-15 16:20:20 +01:00
|
|
|
import { css } from 'emotion';
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { ExemplarTraceIdDestination } from '../types';
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
value: ExemplarTraceIdDestination;
|
|
|
|
|
onChange: (value: ExemplarTraceIdDestination) => void;
|
|
|
|
|
onDelete: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function ExemplarSetting({ value, onChange, onDelete }: Props) {
|
|
|
|
|
const [isInternalLink, setIsInternalLink] = useState(Boolean(value.datasourceUid));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="gf-form-group">
|
|
|
|
|
<InlineField label="Internal link" labelWidth={24}>
|
|
|
|
|
<>
|
2021-01-20 07:59:48 +01:00
|
|
|
<InlineSwitch value={isInternalLink} onChange={(ev) => setIsInternalLink(ev.currentTarget.checked)} />
|
2021-01-15 16:20:20 +01:00
|
|
|
<Button
|
|
|
|
|
variant="destructive"
|
|
|
|
|
title="Remove link"
|
|
|
|
|
icon="times"
|
2021-01-20 07:59:48 +01:00
|
|
|
onClick={(event) => {
|
2021-01-15 16:20:20 +01:00
|
|
|
event.preventDefault();
|
|
|
|
|
onDelete();
|
|
|
|
|
}}
|
|
|
|
|
className={css`
|
|
|
|
|
margin-left: 8px;
|
|
|
|
|
`}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
</InlineField>
|
|
|
|
|
|
|
|
|
|
{isInternalLink ? (
|
|
|
|
|
<InlineField
|
|
|
|
|
label="Data source"
|
|
|
|
|
labelWidth={24}
|
|
|
|
|
tooltip="The data source the exemplar is going to navigate to."
|
|
|
|
|
>
|
|
|
|
|
<DataSourcePicker
|
|
|
|
|
tracing={true}
|
|
|
|
|
current={value.datasourceUid}
|
|
|
|
|
noDefault={true}
|
2021-01-20 07:59:48 +01:00
|
|
|
onChange={(ds) =>
|
2021-01-15 16:20:20 +01:00
|
|
|
onChange({
|
|
|
|
|
datasourceUid: ds.uid,
|
|
|
|
|
name: value.name,
|
|
|
|
|
url: undefined,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</InlineField>
|
|
|
|
|
) : (
|
|
|
|
|
<InlineField
|
|
|
|
|
label="URL"
|
|
|
|
|
labelWidth={24}
|
|
|
|
|
tooltip="The URL of the trace backend the user would go to see its trace."
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="https://example.com/${__value.raw}"
|
|
|
|
|
spellCheck={false}
|
|
|
|
|
width={40}
|
|
|
|
|
value={value.url}
|
2021-01-20 07:59:48 +01:00
|
|
|
onChange={(event) =>
|
2021-01-15 16:20:20 +01:00
|
|
|
onChange({
|
|
|
|
|
datasourceUid: undefined,
|
|
|
|
|
name: value.name,
|
|
|
|
|
url: event.currentTarget.value,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</InlineField>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<InlineField
|
|
|
|
|
label="Label name"
|
|
|
|
|
labelWidth={24}
|
|
|
|
|
tooltip="The name of the field in the labels object that should be used to get the traceID."
|
|
|
|
|
>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="traceID"
|
|
|
|
|
spellCheck={false}
|
|
|
|
|
width={40}
|
|
|
|
|
value={value.name}
|
2021-01-20 07:59:48 +01:00
|
|
|
onChange={(event) =>
|
2021-01-15 16:20:20 +01:00
|
|
|
onChange({
|
|
|
|
|
...value,
|
|
|
|
|
name: event.currentTarget.value,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</InlineField>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|