-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigEditor.tsx
132 lines (122 loc) · 3.54 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { InlineField, Input, SecretInput } from '@grafana/ui';
import React, { ChangeEvent } from 'react';
import { TpDataSourceOptions, TpSecureJsonData } from '../types';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
interface Props extends DataSourcePluginOptionsEditorProps<TpDataSourceOptions, TpSecureJsonData> {}
export function ConfigEditor(props: Props) {
const { onOptionsChange, options } = props;
const { jsonData, secureJsonFields, secureJsonData } = options;
const onHostChange = (event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({
...options,
jsonData: {
...jsonData,
host: event.target.value,
},
});
};
const onUsernameChange = (event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({
...options,
jsonData: {
...jsonData,
username: event.target.value,
},
});
};
const onTCPPortChange = (event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({
...options,
jsonData: {
...jsonData,
tcpPort: parseInt(event.target.value, 10),
},
});
};
const onHTTPPortChange = (event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({
...options,
jsonData: {
...jsonData,
httpPort: parseInt(event.target.value, 10),
},
});
};
// Secure field (only sent to the backend)
const onPasswordChange = (event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({
...options,
secureJsonData: {
password: event.target.value,
},
});
};
const onResetPassword = () => {
onOptionsChange({
...options,
secureJsonFields: {
...options.secureJsonFields,
password: false,
},
secureJsonData: {
...options.secureJsonData,
password: '',
},
});
};
return (
<>
<InlineField required={true} label="Host" labelWidth={14} interactive tooltip={'Hostname'}>
<Input
required={true}
id="config-editor-host"
onChange={onHostChange}
value={jsonData.host}
placeholder="Enter the host, e.g. localhost"
width={40}
/>
</InlineField>
<InlineField label="TCP Port" labelWidth={14} interactive tooltip={'TCP Port'}>
<Input
id="config-editor-tcp-port"
type="number"
onChange={onTCPPortChange}
value={jsonData.tcpPort}
placeholder="8463"
width={40}
/>
</InlineField>
<InlineField label="HTTP Port" labelWidth={14} interactive tooltip={'HTTP Port'}>
<Input
id="config-editor-http-port"
type="number"
onChange={onHTTPPortChange}
value={jsonData.httpPort}
placeholder="3218"
width={40}
/>
</InlineField>
<InlineField label="Username" labelWidth={14} interactive tooltip={'Username'}>
<Input
id="config-editor-username"
onChange={onUsernameChange}
value={jsonData.username}
placeholder="default"
width={40}
/>
</InlineField>
<InlineField label="Password" labelWidth={14} interactive tooltip={'Password'}>
<SecretInput
required
id="config-editor-password"
isConfigured={secureJsonFields.password}
value={secureJsonData?.password}
placeholder="Enter your password"
width={40}
onReset={onResetPassword}
onChange={onPasswordChange}
/>
</InlineField>
</>
);
}