plugin-data-source-postgres 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/constants.js +3 -0
- package/dist/externalVersion.js +10 -9
- package/dist/locale/en-US.json +8 -1
- package/dist/locale/zh-CN.json +8 -1
- package/dist/server/plugin.js +126 -5
- package/package.json +2 -2
- package/src/client/ConfigurationForm.tsx +312 -133
- package/src/client/__tests__/client-v1.test.tsx +80 -0
- package/src/client-v2/PostgresConfigForm.tsx +133 -6
- package/src/client-v2/__tests__/plugin.test.tsx +69 -0
- package/src/client-v2/plugin.tsx +2 -2
- package/src/constants.ts +15 -0
- package/src/locale/en-US.json +8 -1
- package/src/locale/zh-CN.json +8 -1
- package/src/server/__tests__/postgres-datasource.unit.test.ts +153 -0
- package/src/server/plugin.ts +160 -1
- package/dist/client-v2/985.34da95acdf7743ab.js +0 -10
|
@@ -8,19 +8,79 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { FormTab } from '@formily/antd-v5';
|
|
11
|
+
import { onFieldInputValueChange } from '@formily/core';
|
|
11
12
|
import { useForm } from '@formily/react';
|
|
12
|
-
import { SchemaComponent } from '@nocobase/client';
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
13
|
+
import { SchemaComponent, useAPIClient } from '@nocobase/client';
|
|
14
|
+
import { Select } from 'antd';
|
|
15
|
+
import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
16
|
+
import { useTranslation } from 'react-i18next';
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_PORT,
|
|
19
|
+
DEFAULT_SCHEMA,
|
|
20
|
+
LIST_SAVED_CONNECTIONS_ACTION,
|
|
21
|
+
NAMESPACE,
|
|
22
|
+
type SavedPostgresConnection,
|
|
23
|
+
} from '../constants';
|
|
15
24
|
|
|
16
25
|
const nsT = (key: string) => `{{t(${JSON.stringify(key)}, { ns: "${NAMESPACE}" })}}`;
|
|
17
26
|
|
|
27
|
+
function formatSavedConnectionLabel(item: SavedPostgresConnection): string {
|
|
28
|
+
const target = item.database ? `/${item.database}` : '';
|
|
29
|
+
return `${item.displayName} (${item.username}@${item.host}:${item.port}${target})`;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
interface ConfigurationFormProps {
|
|
19
33
|
from?: 'create' | 'edit';
|
|
20
34
|
}
|
|
21
35
|
|
|
36
|
+
interface SavedConnectionSelectProps {
|
|
37
|
+
value?: string;
|
|
38
|
+
onChange?: (value?: string) => void;
|
|
39
|
+
options?: Array<{ label: string; value: string }>;
|
|
40
|
+
placeholder?: string;
|
|
41
|
+
notFoundContent?: string;
|
|
42
|
+
ariaLabel?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const SavedConnectionsContext = createContext<Array<{ label: string; value: string }>>([]);
|
|
46
|
+
|
|
47
|
+
const SavedConnectionSelect: React.FC<SavedConnectionSelectProps> = ({
|
|
48
|
+
value,
|
|
49
|
+
onChange,
|
|
50
|
+
options,
|
|
51
|
+
placeholder,
|
|
52
|
+
notFoundContent,
|
|
53
|
+
ariaLabel,
|
|
54
|
+
}) => {
|
|
55
|
+
const contextOptions = useContext(SavedConnectionsContext);
|
|
56
|
+
const resolvedOptions = contextOptions.length > 0 ? contextOptions : options;
|
|
57
|
+
return (
|
|
58
|
+
<Select
|
|
59
|
+
allowClear
|
|
60
|
+
showSearch
|
|
61
|
+
optionFilterProp="label"
|
|
62
|
+
value={value || undefined}
|
|
63
|
+
onChange={(nextValue) => onChange?.(nextValue || undefined)}
|
|
64
|
+
options={resolvedOptions}
|
|
65
|
+
placeholder={placeholder}
|
|
66
|
+
notFoundContent={notFoundContent}
|
|
67
|
+
aria-label={ariaLabel}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
22
72
|
export const ConfigurationForm: React.FC<ConfigurationFormProps> = ({ from }) => {
|
|
23
73
|
const form = useForm();
|
|
74
|
+
const api = useAPIClient();
|
|
75
|
+
const apiRef = useRef(api);
|
|
76
|
+
apiRef.current = api;
|
|
77
|
+
const { t } = useTranslation(NAMESPACE);
|
|
78
|
+
const [savedConnections, setSavedConnections] = useState<SavedPostgresConnection[]>([]);
|
|
79
|
+
const savedConnectionsRef = useRef<SavedPostgresConnection[]>([]);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
savedConnectionsRef.current = savedConnections;
|
|
83
|
+
}, [savedConnections]);
|
|
24
84
|
|
|
25
85
|
useEffect(() => {
|
|
26
86
|
const options = (form?.values?.options || {}) as Record<string, unknown>;
|
|
@@ -47,148 +107,262 @@ export const ConfigurationForm: React.FC<ConfigurationFormProps> = ({ from }) =>
|
|
|
47
107
|
}
|
|
48
108
|
}, [form, from]);
|
|
49
109
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
let cancelled = false;
|
|
112
|
+
const loadSavedConnections = async () => {
|
|
113
|
+
try {
|
|
114
|
+
const response = await apiRef.current.request<{ data?: SavedPostgresConnection[] }>({
|
|
115
|
+
url: LIST_SAVED_CONNECTIONS_ACTION,
|
|
116
|
+
method: 'get',
|
|
117
|
+
});
|
|
118
|
+
if (cancelled) return;
|
|
119
|
+
const items = Array.isArray(response?.data?.data) ? response.data.data : [];
|
|
120
|
+
const currentKey = typeof form?.values?.key === 'string' ? form.values.key : '';
|
|
121
|
+
setSavedConnections(from === 'edit' && currentKey ? items.filter((item) => item.key !== currentKey) : items);
|
|
122
|
+
} catch {
|
|
123
|
+
if (!cancelled) setSavedConnections([]);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
loadSavedConnections();
|
|
127
|
+
return () => {
|
|
128
|
+
cancelled = true;
|
|
129
|
+
};
|
|
130
|
+
}, [form, from]);
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
const effectId = 'postgres-saved-connection-sync';
|
|
134
|
+
const updateSecretPlaceholders = (selected?: SavedPostgresConnection) => {
|
|
135
|
+
form.setFieldState('options.password', (state) => {
|
|
136
|
+
state.componentProps = {
|
|
137
|
+
...state.componentProps,
|
|
138
|
+
placeholder: selected?.hasPassword ? t('Leave blank to reuse saved password') : undefined,
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
form.setFieldState('options.sslCa', (state) => {
|
|
142
|
+
state.componentProps = {
|
|
143
|
+
...state.componentProps,
|
|
144
|
+
placeholder: selected?.hasSslCa ? t('Leave blank to reuse saved CA certificate') : undefined,
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
form.addEffects(effectId, () => {
|
|
150
|
+
onFieldInputValueChange('options.sourceConnectionKey', (field) => {
|
|
151
|
+
const key = typeof field.value === 'string' ? field.value : '';
|
|
152
|
+
const selected = savedConnectionsRef.current.find((item) => item.key === key);
|
|
153
|
+
updateSecretPlaceholders(selected);
|
|
154
|
+
if (!selected) return;
|
|
155
|
+
form.setValuesIn('options.host', selected.host);
|
|
156
|
+
form.setValuesIn('options.port', selected.port);
|
|
157
|
+
form.setValuesIn('options.database', selected.database);
|
|
158
|
+
form.setValuesIn('options.schema', selected.schema);
|
|
159
|
+
form.setValuesIn('options.username', selected.username);
|
|
160
|
+
form.setValuesIn('options.ssl', selected.ssl);
|
|
161
|
+
form.setValuesIn('options.password', '');
|
|
162
|
+
form.setValuesIn('options.sslCa', '');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const clearSavedConnectionIfEndpointChanged = () => {
|
|
166
|
+
const currentKey = form.getValuesIn('options.sourceConnectionKey');
|
|
167
|
+
if (typeof currentKey !== 'string' || !currentKey) return;
|
|
168
|
+
const selected = savedConnectionsRef.current.find((item) => item.key === currentKey);
|
|
169
|
+
if (!selected) return;
|
|
170
|
+
const currentHost = String(form.getValuesIn('options.host') || '').trim();
|
|
171
|
+
const currentPort = Number(form.getValuesIn('options.port') ?? DEFAULT_PORT);
|
|
172
|
+
const currentUsername = String(form.getValuesIn('options.username') || '').trim();
|
|
173
|
+
if (currentHost !== selected.host || currentPort !== selected.port || currentUsername !== selected.username) {
|
|
174
|
+
form.setValuesIn('options.sourceConnectionKey', undefined);
|
|
175
|
+
updateSecretPlaceholders(undefined);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
onFieldInputValueChange('options.host', clearSavedConnectionIfEndpointChanged);
|
|
180
|
+
onFieldInputValueChange('options.port', clearSavedConnectionIfEndpointChanged);
|
|
181
|
+
onFieldInputValueChange('options.username', clearSavedConnectionIfEndpointChanged);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return () => {
|
|
185
|
+
form.removeEffects(effectId);
|
|
186
|
+
};
|
|
187
|
+
}, [form, t]);
|
|
188
|
+
|
|
189
|
+
const savedConnectionOptions = useMemo(
|
|
190
|
+
() =>
|
|
191
|
+
savedConnections.map((item) => ({
|
|
192
|
+
value: item.key,
|
|
193
|
+
label: formatSavedConnectionLabel(item),
|
|
194
|
+
})),
|
|
195
|
+
[savedConnections],
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
form.setFieldState('options.sourceConnectionKey', (state) => {
|
|
200
|
+
state.componentProps = {
|
|
201
|
+
...state.componentProps,
|
|
202
|
+
options: savedConnectionOptions,
|
|
203
|
+
};
|
|
204
|
+
});
|
|
205
|
+
}, [form, savedConnectionOptions]);
|
|
206
|
+
|
|
207
|
+
const schema = useMemo(
|
|
208
|
+
() => ({
|
|
209
|
+
type: 'object',
|
|
210
|
+
properties: {
|
|
211
|
+
displayName: {
|
|
212
|
+
type: 'string',
|
|
213
|
+
title: nsT('Display Name'),
|
|
214
|
+
'x-decorator': 'FormItem',
|
|
215
|
+
'x-component': 'Input',
|
|
216
|
+
'x-decorator-props': {
|
|
217
|
+
tooltip: nsT('The connection name to display in NocoBase'),
|
|
218
|
+
},
|
|
219
|
+
required: true,
|
|
60
220
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
'x-component-props': {
|
|
75
|
-
tab: nsT('Connection Settings'),
|
|
76
|
-
},
|
|
77
|
-
properties: {
|
|
78
|
-
host: {
|
|
79
|
-
type: 'string',
|
|
80
|
-
title: nsT('Host'),
|
|
81
|
-
'x-decorator': 'FormItem',
|
|
82
|
-
'x-component': 'Input',
|
|
83
|
-
'x-decorator-props': {
|
|
84
|
-
tooltip: nsT('PostgreSQL server hostname or IP address'),
|
|
85
|
-
},
|
|
86
|
-
default: 'localhost',
|
|
87
|
-
required: true,
|
|
221
|
+
options: {
|
|
222
|
+
type: 'object',
|
|
223
|
+
properties: {
|
|
224
|
+
tabs: {
|
|
225
|
+
type: 'void',
|
|
226
|
+
'x-component': 'FormTab',
|
|
227
|
+
'x-component-props': {},
|
|
228
|
+
properties: {
|
|
229
|
+
connection: {
|
|
230
|
+
type: 'void',
|
|
231
|
+
'x-component': 'FormTab.TabPane',
|
|
232
|
+
'x-component-props': {
|
|
233
|
+
tab: t('Connection Settings'),
|
|
88
234
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
235
|
+
properties: {
|
|
236
|
+
sourceConnectionKey: {
|
|
237
|
+
type: 'string',
|
|
238
|
+
title: nsT('Saved connection'),
|
|
239
|
+
'x-decorator': 'FormItem',
|
|
240
|
+
'x-component': 'SavedConnectionSelect',
|
|
241
|
+
'x-decorator-props': {
|
|
242
|
+
tooltip: nsT('Reuse an existing PostgreSQL connection or leave blank to create a new one'),
|
|
243
|
+
},
|
|
244
|
+
'x-component-props': {
|
|
245
|
+
options: savedConnectionOptions,
|
|
246
|
+
placeholder: t('Create new connection'),
|
|
247
|
+
notFoundContent: t('No saved PostgreSQL connections'),
|
|
248
|
+
ariaLabel: t('Saved connection'),
|
|
249
|
+
},
|
|
96
250
|
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
251
|
+
host: {
|
|
252
|
+
type: 'string',
|
|
253
|
+
title: nsT('Host'),
|
|
254
|
+
'x-decorator': 'FormItem',
|
|
255
|
+
'x-component': 'Input',
|
|
256
|
+
'x-decorator-props': {
|
|
257
|
+
tooltip: nsT('PostgreSQL server hostname or IP address'),
|
|
258
|
+
},
|
|
259
|
+
default: 'localhost',
|
|
260
|
+
required: true,
|
|
101
261
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
262
|
+
port: {
|
|
263
|
+
type: 'number',
|
|
264
|
+
title: nsT('Port'),
|
|
265
|
+
'x-decorator': 'FormItem',
|
|
266
|
+
'x-component': 'InputNumber',
|
|
267
|
+
'x-decorator-props': {
|
|
268
|
+
tooltip: nsT('PostgreSQL server port number'),
|
|
269
|
+
},
|
|
270
|
+
'x-component-props': {
|
|
271
|
+
min: 1,
|
|
272
|
+
max: 65535,
|
|
273
|
+
style: { width: '100%' },
|
|
274
|
+
},
|
|
275
|
+
default: DEFAULT_PORT,
|
|
276
|
+
required: true,
|
|
112
277
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
278
|
+
database: {
|
|
279
|
+
type: 'string',
|
|
280
|
+
title: nsT('Database'),
|
|
281
|
+
'x-decorator': 'FormItem',
|
|
282
|
+
'x-component': 'Input',
|
|
283
|
+
'x-decorator-props': {
|
|
284
|
+
tooltip: nsT('Name of the PostgreSQL database'),
|
|
285
|
+
},
|
|
286
|
+
required: true,
|
|
122
287
|
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
288
|
+
username: {
|
|
289
|
+
type: 'string',
|
|
290
|
+
title: nsT('Username'),
|
|
291
|
+
'x-decorator': 'FormItem',
|
|
292
|
+
'x-component': 'Input',
|
|
293
|
+
'x-decorator-props': {
|
|
294
|
+
tooltip: nsT('Database username for authentication'),
|
|
295
|
+
},
|
|
296
|
+
required: true,
|
|
297
|
+
},
|
|
298
|
+
password: {
|
|
299
|
+
type: 'string',
|
|
300
|
+
title: nsT('Password'),
|
|
301
|
+
'x-decorator': 'FormItem',
|
|
302
|
+
'x-component': 'Password',
|
|
303
|
+
'x-decorator-props': {
|
|
304
|
+
tooltip: nsT('Database password for authentication'),
|
|
305
|
+
},
|
|
132
306
|
},
|
|
133
307
|
},
|
|
134
308
|
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
tab: nsT('Advanced Settings'),
|
|
141
|
-
},
|
|
142
|
-
properties: {
|
|
143
|
-
schema: {
|
|
144
|
-
type: 'string',
|
|
145
|
-
title: nsT('Schema'),
|
|
146
|
-
'x-decorator': 'FormItem',
|
|
147
|
-
'x-component': 'Input',
|
|
148
|
-
'x-decorator-props': {
|
|
149
|
-
tooltip: nsT('PostgreSQL schema name, defaults to public'),
|
|
150
|
-
},
|
|
151
|
-
default: DEFAULT_SCHEMA,
|
|
309
|
+
advanced: {
|
|
310
|
+
type: 'void',
|
|
311
|
+
'x-component': 'FormTab.TabPane',
|
|
312
|
+
'x-component-props': {
|
|
313
|
+
tab: t('Advanced Settings'),
|
|
152
314
|
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
315
|
+
properties: {
|
|
316
|
+
schema: {
|
|
317
|
+
type: 'string',
|
|
318
|
+
title: nsT('Schema'),
|
|
319
|
+
'x-decorator': 'FormItem',
|
|
320
|
+
'x-component': 'Input',
|
|
321
|
+
'x-decorator-props': {
|
|
322
|
+
tooltip: nsT('PostgreSQL schema name, defaults to public'),
|
|
323
|
+
},
|
|
324
|
+
default: DEFAULT_SCHEMA,
|
|
160
325
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
326
|
+
ssl: {
|
|
327
|
+
type: 'boolean',
|
|
328
|
+
title: nsT('Use SSL'),
|
|
329
|
+
'x-decorator': 'FormItem',
|
|
330
|
+
'x-component': 'Checkbox',
|
|
331
|
+
'x-decorator-props': {
|
|
332
|
+
tooltip: nsT('Enable SSL/TLS connection'),
|
|
333
|
+
},
|
|
334
|
+
default: false,
|
|
335
|
+
},
|
|
336
|
+
sslCa: {
|
|
337
|
+
type: 'string',
|
|
338
|
+
title: nsT('CA certificate (PEM)'),
|
|
339
|
+
'x-decorator': 'FormItem',
|
|
340
|
+
'x-component': 'Input.TextArea',
|
|
341
|
+
'x-component-props': { rows: 4 },
|
|
177
342
|
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
343
|
+
addAllCollections: {
|
|
344
|
+
type: 'boolean',
|
|
345
|
+
title: nsT('Auto Discover Tables'),
|
|
346
|
+
'x-decorator': 'FormItem',
|
|
347
|
+
'x-component': 'Checkbox',
|
|
348
|
+
'x-decorator-props': {
|
|
349
|
+
tooltip: nsT('Automatically discover tables from the database'),
|
|
350
|
+
},
|
|
351
|
+
'x-reactions': {
|
|
352
|
+
target: 'options.autoDiscover',
|
|
353
|
+
fulfill: {
|
|
354
|
+
state: {
|
|
355
|
+
value: '{{$self.value}}',
|
|
356
|
+
},
|
|
183
357
|
},
|
|
184
358
|
},
|
|
359
|
+
default: true,
|
|
360
|
+
},
|
|
361
|
+
autoDiscover: {
|
|
362
|
+
type: 'boolean',
|
|
363
|
+
'x-hidden': true,
|
|
364
|
+
default: true,
|
|
185
365
|
},
|
|
186
|
-
default: true,
|
|
187
|
-
},
|
|
188
|
-
autoDiscover: {
|
|
189
|
-
type: 'boolean',
|
|
190
|
-
'x-hidden': true,
|
|
191
|
-
default: true,
|
|
192
366
|
},
|
|
193
367
|
},
|
|
194
368
|
},
|
|
@@ -196,8 +370,13 @@ export const ConfigurationForm: React.FC<ConfigurationFormProps> = ({ from }) =>
|
|
|
196
370
|
},
|
|
197
371
|
},
|
|
198
372
|
},
|
|
199
|
-
},
|
|
200
|
-
|
|
373
|
+
}),
|
|
374
|
+
[savedConnectionOptions, t],
|
|
375
|
+
);
|
|
201
376
|
|
|
202
|
-
return
|
|
377
|
+
return (
|
|
378
|
+
<SavedConnectionsContext.Provider value={savedConnectionOptions}>
|
|
379
|
+
<SchemaComponent schema={schema} components={{ FormTab, SavedConnectionSelect }} />
|
|
380
|
+
</SavedConnectionsContext.Provider>
|
|
381
|
+
);
|
|
203
382
|
};
|
|
@@ -262,4 +262,84 @@ describe('PostgreSQL legacy client v1', () => {
|
|
|
262
262
|
expect(refreshCMSpy).toHaveBeenCalledOnce();
|
|
263
263
|
expect(refreshResourceSpy).toHaveBeenCalledOnce();
|
|
264
264
|
});
|
|
265
|
+
|
|
266
|
+
it('loads saved PostgreSQL connections in v1 ConfigurationForm, translates tab labels directly, and populates fields on selection', async () => {
|
|
267
|
+
apiRequestSpy.mockResolvedValueOnce({
|
|
268
|
+
data: {
|
|
269
|
+
data: [
|
|
270
|
+
{
|
|
271
|
+
key: 'pg_existing',
|
|
272
|
+
displayName: 'Existing PG',
|
|
273
|
+
host: 'pg.internal',
|
|
274
|
+
port: 5433,
|
|
275
|
+
database: 'sales',
|
|
276
|
+
schema: 'public',
|
|
277
|
+
username: 'pg_user',
|
|
278
|
+
ssl: true,
|
|
279
|
+
hasPassword: true,
|
|
280
|
+
hasSslCa: false,
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
const form = createForm({ values: { options: {} } });
|
|
286
|
+
|
|
287
|
+
render(
|
|
288
|
+
<FormProvider form={form}>
|
|
289
|
+
<ConfigurationForm from="create" />
|
|
290
|
+
</FormProvider>,
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
await waitFor(() => {
|
|
294
|
+
expect(apiRequestSpy).toHaveBeenCalledWith({
|
|
295
|
+
url: 'dataSources:listPostgresConnections',
|
|
296
|
+
method: 'get',
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const schemaProps = capturedSchema?.properties as
|
|
301
|
+
| {
|
|
302
|
+
options?: {
|
|
303
|
+
properties?: {
|
|
304
|
+
tabs?: {
|
|
305
|
+
properties?: {
|
|
306
|
+
connection?: {
|
|
307
|
+
'x-component-props'?: { tab?: string };
|
|
308
|
+
properties?: {
|
|
309
|
+
sourceConnectionKey?: { 'x-component-props'?: { options?: unknown } };
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
advanced?: { 'x-component-props'?: { tab?: string } };
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
| undefined;
|
|
319
|
+
const tabs = schemaProps?.options?.properties?.tabs?.properties;
|
|
320
|
+
expect(tabs?.connection?.['x-component-props']?.tab).toBe('Connection Settings');
|
|
321
|
+
expect(tabs?.advanced?.['x-component-props']?.tab).toBe('Advanced Settings');
|
|
322
|
+
expect(tabs?.connection?.properties?.sourceConnectionKey?.['x-component-props']?.options).toEqual([
|
|
323
|
+
{ value: 'pg_existing', label: 'Existing PG (pg_user@pg.internal:5433/sales)' },
|
|
324
|
+
]);
|
|
325
|
+
|
|
326
|
+
const sourceField = form.createField({ name: 'options.sourceConnectionKey' });
|
|
327
|
+
const hostField = form.createField({ name: 'options.host' });
|
|
328
|
+
sourceField.onInput('pg_existing');
|
|
329
|
+
|
|
330
|
+
expect(form.values.options).toMatchObject({
|
|
331
|
+
sourceConnectionKey: 'pg_existing',
|
|
332
|
+
host: 'pg.internal',
|
|
333
|
+
port: 5433,
|
|
334
|
+
database: 'sales',
|
|
335
|
+
schema: 'public',
|
|
336
|
+
username: 'pg_user',
|
|
337
|
+
password: '',
|
|
338
|
+
ssl: true,
|
|
339
|
+
sslCa: '',
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
hostField.onInput('other.host');
|
|
343
|
+
expect(form.values.options.sourceConnectionKey).toBeUndefined();
|
|
344
|
+
});
|
|
265
345
|
});
|