-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathServerAndEncryptionSection.tsx
More file actions
218 lines (212 loc) · 7.22 KB
/
ServerAndEncryptionSection.tsx
File metadata and controls
218 lines (212 loc) · 7.22 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import React from 'react';
import {
DataSourcePluginOptionsEditorProps,
GrafanaTheme2,
onUpdateDatasourceJsonDataOption,
onUpdateDatasourceJsonDataOptionChecked,
} from '@grafana/data';
import {
Box,
CollapsableSection,
TextLink,
Field,
Input,
Toggletip,
IconButton,
RadioButtonGroup,
Text,
useStyles2,
Checkbox,
} from '@grafana/ui';
import allLabels from './labelsV2';
import { CHConfig, CHSecureConfig, Protocol } from 'types/config';
import { CONFIG_SECTION_HEADERS, CONTAINER_MIN_WIDTH, PROTOCOL_OPTIONS } from './constants';
import { css } from '@emotion/css';
import {
trackClickhouseConfigV2HostInput,
trackClickhouseConfigV2NativeHttpToggleClicked,
trackClickhouseConfigV2PortInput,
trackClickhouseConfigV2SecureConnectionChecked,
} from './tracking';
import { HttpProtocolSettingsSection } from './HttpProtocolSettingsSection';
export interface Props extends DataSourcePluginOptionsEditorProps<CHConfig, CHSecureConfig> {}
export const ServerAndEncryptionSection = (props: Props) => {
const { options, onOptionsChange } = props;
const { jsonData } = options;
const labels = allLabels.components.Config.ConfigEditor;
const defaultPort = jsonData.secure
? jsonData.protocol === Protocol.Native
? labels.serverPort.secureNativePort
: labels.serverPort.secureHttpPort
: jsonData.protocol === Protocol.Native
? labels.serverPort.insecureNativePort
: labels.serverPort.insecureHttpPort;
const portDescription = `${labels.serverPort.tooltip} (default for ${jsonData.secure ? 'secure' : ''} ${jsonData.protocol}: ${defaultPort})`;
const styles = useStyles2(getStyles);
const onProtocolToggle = (protocol: Protocol) => {
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
protocol: protocol,
},
});
};
const onPortChange = (port: string) => {
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
port: +port,
},
});
};
return (
<Box
borderStyle="solid"
borderColor="weak"
padding={2}
marginBottom={4}
id={`${CONFIG_SECTION_HEADERS[0].id}`}
minWidth={CONTAINER_MIN_WIDTH}
>
<CollapsableSection
label={<Text variant="h3">1. {CONFIG_SECTION_HEADERS[0].label}</Text>}
isOpen={!!CONFIG_SECTION_HEADERS[0].isOpen}
>
<Text variant="body" color="secondary">
Enter the server address of your Clickhouse instance. Then select your protocol, port and security options. If
you need further guidance, visit the{' '}
<TextLink
href="https://grafana.com/grafana/plugins/grafana-clickhouse-datasource/"
icon="external-link-alt"
external
>
Grafana docs
</TextLink>
</Text>
<Field required label={labels.serverAddress.label} style={{ marginTop: '30px' }}>
<Input
name="host"
value={jsonData.host || ''}
onChange={(e) => onUpdateDatasourceJsonDataOption(props, 'host')(e)}
label={labels.serverAddress.label}
aria-label={labels.serverAddress.label}
data-testid="clickhouse-v2-config-host-input"
placeholder={labels.serverAddress.placeholder}
onBlur={trackClickhouseConfigV2HostInput}
/>
</Field>
<div className={styles.protocolPortRow}>
<div className={styles.protocolSection}>
<div className={styles.protocolLabel}>
<Text variant="bodySmall" weight="bold">
{labels.protocol.label}
</Text>
<Toggletip
theme="info"
placement="top"
content={
<div className={styles.toggleTipText}>
<Text>
ClickHouse supports two server protocols: Native TCP and HTTP. Both protocols can be secured with
TLS.
<br />
<br />
<TextLink href="https://clickhouse.com/docs/interfaces/tcp" variant="bodySmall" external>
Native TCP
</TextLink>{' '}
is the default and recommended option.
<br />
<TextLink href="https://clickhouse.com/docs/interfaces/http" variant="bodySmall" external>
HTTP
</TextLink>{' '}
is for servers configured to accept HTTP connections.
</Text>
</div>
}
>
<IconButton
name="question-circle"
aria-label="More info about Protocol"
size="xs"
className={styles.toggleTipIcon}
/>
</Toggletip>
</div>
<Field label="" description={<div className={styles.toggleTipText}>{labels.protocol.tooltip}</div>}>
<RadioButtonGroup<Protocol>
options={PROTOCOL_OPTIONS}
value={jsonData.protocol || Protocol.Native}
onChange={(e) => {
trackClickhouseConfigV2NativeHttpToggleClicked({ nativeHttpToggle: e });
onProtocolToggle(e!);
}}
/>
</Field>
</div>
<div className={styles.portSection}>
<Field required label={labels.serverPort.label} description={portDescription}>
<Input
name="port"
type="number"
value={jsonData.port || ''}
onChange={(e) => onPortChange(e.currentTarget.value)}
label={labels.serverPort.label}
aria-label={labels.serverPort.label}
data-testid="clickhouse-v2-config-port-input"
placeholder={defaultPort}
onBlur={(e) => trackClickhouseConfigV2PortInput({ port: e.currentTarget.value })}
/>
</Field>
</div>
</div>
<div className={styles.secureToggle}>
<Checkbox
label={labels.secure.label}
description={labels.secure.tooltip}
checked={jsonData.secure || false}
onChange={(e) => {
trackClickhouseConfigV2SecureConnectionChecked({ secureConnection: e.currentTarget.checked });
onUpdateDatasourceJsonDataOptionChecked(props, 'secure')(e);
}}
/>
</div>
<HttpProtocolSettingsSection {...props} />
</CollapsableSection>
</Box>
);
};
const getStyles = (theme: GrafanaTheme2) => ({
protocolPortRow: css({
display: 'flex',
alignItems: 'center',
}),
protocolLabel: css({
display: 'flex',
height: 15,
width: '205px',
}),
protocolSection: css({
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
gap: theme.spacing(0),
marginRight: theme.spacing(5),
}),
toggleTipIcon: css({
marginLeft: theme.spacing(0.5),
padding: 0,
}),
portSection: css({
width: '100%',
}),
toggleTipText: css({
whiteSpace: 'pre-line',
}),
secureToggle: css({
display: 'flex',
alignItems: 'center',
marginTop: theme.spacing(1),
}),
});