-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathConfigEditor.tsx
110 lines (104 loc) · 3.92 KB
/
ConfigEditor.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, { useCallback } from 'react';
import { DataSourceHttpSettings, Input, InlineField, FieldSet } from '@grafana/ui';
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
import { QuickwitOptions } from '../quickwit';
import { coerceOptions } from './utils';
import { Divider } from '../components/Divider';
import { DataLinks } from './DataLinks';
import _ from 'lodash';
interface Props extends DataSourcePluginOptionsEditorProps<QuickwitOptions> {}
export const ConfigEditor = (props: Props) => {
const { options: originalOptions, onOptionsChange } = props;
const options = coerceOptions(originalOptions);
const onSettingsChange = useCallback(
(change: Partial<DataSourceSettings<any, any>>) => {
onOptionsChange({
...options,
...change,
});
},
[options, onOptionsChange]
);
return (
<>
<DataSourceHttpSettings
defaultUrl="http://localhost:7280/api/v1"
dataSourceConfig={options}
onChange={onOptionsChange}
/>
<QuickwitDetails value={options} onChange={onSettingsChange} />
<QuickwitDataLinks value={options} onChange={onOptionsChange} />
</>
);
};
type DetailsProps = {
value: DataSourceSettings<QuickwitOptions>;
onChange: (value: DataSourceSettings<QuickwitOptions>) => void;
};
export const QuickwitDataLinks = ({ value, onChange }: DetailsProps) => {
return (
<div className="gf-form-group">
<Divider hideLine />
<DataLinks
value={value.jsonData.dataLinks}
onChange={(newValue) => {
onChange({
...value,
jsonData: {
...value.jsonData,
dataLinks: newValue,
},
});
}}
/>
</div>
)
};
export const QuickwitDetails = ({ value, onChange }: DetailsProps) => {
return (
<>
<div className="gf-form-group">
<FieldSet label="Index settings">
<InlineField label="Index ID" labelWidth={26} tooltip="Index ID. Required.">
<Input
id="quickwit_index_id"
value={value.jsonData.index}
onChange={(event) => onChange({ ...value, jsonData: {...value.jsonData, index: event.currentTarget.value}})}
placeholder="otel-logs-v0"
width={40}
/>
</InlineField>
<InlineField label="Message field name" labelWidth={26} tooltip="Field used to display a log line in the Explore view">
<Input
id="quickwit_log_message_field"
value={value.jsonData.logMessageField}
onChange={(event) => onChange({ ...value, jsonData: {...value.jsonData, logMessageField: event.currentTarget.value}})}
placeholder="body.message"
width={40}
/>
</InlineField>
<InlineField label="Log level field" labelWidth={26} tooltip="The log level field must be a fast field">
<Input
id="quickwit_log_level_field"
value={value.jsonData.logLevelField}
onChange={(event) => onChange({ ...value, jsonData: {...value.jsonData, logLevelField: event.currentTarget.value}})}
placeholder="level"
width={40}
/>
</InlineField>
</FieldSet>
<FieldSet label="Editor settings">
<InlineField label="Default logs limit" labelWidth={26} tooltip="The log level field must be a fast field">
<Input
id="quickwit_defaults_metricaggregation_logs_limit"
value={value.jsonData.queryEditorConfig?.defaults?.['metricAggregation.logs.settings.limit']}
onChange={(event) => onChange(_.merge(value, {jsonData:{queryEditorConfig:{defaults:{'metricAggregation.logs.settings.limit':event.currentTarget.value}}}}))}
placeholder="100"
width={40}
/>
</InlineField>
</FieldSet>
</div>
</>
);
};