plugin-block-cross-join 0.1.7 → 0.1.8
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/LICENSE +201 -0
- package/client.d.ts +1 -1
- package/client.js +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +7 -6
- package/dist/locale/en-US.json +37 -23
- package/dist/locale/zh-CN.json +37 -23
- package/dist/server/actions/cross-join-query.js +61 -16
- package/dist/server/plugin.js +15 -1
- package/package.json +12 -1
- package/server.d.ts +1 -1
- package/server.js +1 -1
- package/src/client/CrossJoinBlockInitializer.tsx +1 -34
- package/src/client/CrossJoinBlockModel.tsx +219 -0
- package/src/client/CrossJoinBlockProvider.tsx +1 -88
- package/src/client/CrossJoinConfigurator.tsx +408 -415
- package/src/client/CrossJoinTable.tsx +1 -106
- package/src/client/createBlockUISchema.ts +1 -33
- package/src/client/index.tsx +12 -50
- package/src/client/schemaSettings.tsx +1 -50
- package/src/client-v2/CrossJoinBlockModel.tsx +223 -0
- package/src/client-v2/CrossJoinConfigurator.tsx +453 -0
- package/src/client-v2/__tests__/settings.test.tsx +29 -0
- package/src/client-v2/plugin.tsx +4 -1
- package/src/index.ts +4 -11
- package/src/locale/en-US.json +37 -23
- package/src/locale/zh-CN.json +37 -23
- package/src/server/__tests__/query-integration.test.ts +74 -0
- package/src/server/__tests__/query.test.ts +85 -0
- package/src/server/actions/cross-join-query.ts +287 -246
- package/src/server/index.ts +3 -10
- package/src/server/plugin.ts +44 -36
|
@@ -1,415 +1,408 @@
|
|
|
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
|
-
primaryDs
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
title: '
|
|
301
|
-
dataIndex: '
|
|
302
|
-
width:
|
|
303
|
-
render: (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
),
|
|
410
|
-
},
|
|
411
|
-
]}
|
|
412
|
-
/>
|
|
413
|
-
</Modal>
|
|
414
|
-
);
|
|
415
|
-
};
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import React, { useState, useMemo, useCallback } from 'react';
|
|
4
|
+
import { Modal, Tabs, Form, Select, Button, Space, Radio, Input, Table, Checkbox, Typography, Divider } from 'antd';
|
|
5
|
+
import { PlusOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
6
|
+
import { useApp } from '@nocobase/client-v2';
|
|
7
|
+
|
|
8
|
+
const { Text } = Typography;
|
|
9
|
+
|
|
10
|
+
interface JoinDef {
|
|
11
|
+
dataSource: string;
|
|
12
|
+
collection: string;
|
|
13
|
+
joinType: 'left' | 'inner';
|
|
14
|
+
leftField: string;
|
|
15
|
+
rightField: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ColumnDef {
|
|
19
|
+
source: number;
|
|
20
|
+
field: string;
|
|
21
|
+
alias?: string;
|
|
22
|
+
jsonExpand?: string[];
|
|
23
|
+
selected?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface CrossJoinConfig {
|
|
27
|
+
primarySource: { dataSource: string; collection: string };
|
|
28
|
+
joins: JoinDef[];
|
|
29
|
+
columns: ColumnDef[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
visible: boolean;
|
|
34
|
+
onCancel: () => void;
|
|
35
|
+
onSubmit: (config: CrossJoinConfig) => void;
|
|
36
|
+
initialConfig?: CrossJoinConfig;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function useDataSourceOptions() {
|
|
40
|
+
const app = useApp();
|
|
41
|
+
const dataSources = app?.dataSourceManager?.dataSources ? [...app.dataSourceManager.dataSources.values()] : [] || [];
|
|
42
|
+
|
|
43
|
+
return useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
dataSources
|
|
46
|
+
.filter((ds) => ds.status === 'loaded')
|
|
47
|
+
.map((ds) => ({
|
|
48
|
+
label: ds.displayName || ds.key,
|
|
49
|
+
value: ds.key,
|
|
50
|
+
ds,
|
|
51
|
+
})),
|
|
52
|
+
[app],
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function useCollectionOptions(dsKey: string) {
|
|
57
|
+
const app = useApp();
|
|
58
|
+
return useMemo(() => {
|
|
59
|
+
if (!dsKey || !dm) return [];
|
|
60
|
+
const ds = app?.dataSourceManager?.get(dsKey);
|
|
61
|
+
if (!ds) return [];
|
|
62
|
+
const collections = ds.collectionManager.getCollections() || [];
|
|
63
|
+
return collections.map((c) => ({
|
|
64
|
+
label: c.title || c.name,
|
|
65
|
+
value: c.name,
|
|
66
|
+
}));
|
|
67
|
+
}, [app, dsKey]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function useFieldOptions(dsKey: string, collectionName: string) {
|
|
71
|
+
const app = useApp();
|
|
72
|
+
return useMemo(() => {
|
|
73
|
+
if (!dsKey || !collectionName || !dm) return [];
|
|
74
|
+
const ds = app?.dataSourceManager?.get(dsKey);
|
|
75
|
+
if (!ds) return [];
|
|
76
|
+
const collection = ds.collectionManager.getCollection(collectionName);
|
|
77
|
+
if (!collection) return [];
|
|
78
|
+
const fields = collection.getFields() || [];
|
|
79
|
+
return fields.map((f) => ({
|
|
80
|
+
label: f.uiSchema?.title || f.name,
|
|
81
|
+
value: f.name,
|
|
82
|
+
type: f.type,
|
|
83
|
+
interface: f.interface,
|
|
84
|
+
}));
|
|
85
|
+
}, [app, dsKey, collectionName]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Tab 1: Primary Source
|
|
89
|
+
const PrimarySourceTab: React.FC<{
|
|
90
|
+
value: { dataSource: string; collection: string };
|
|
91
|
+
onChange: (val: { dataSource: string; collection: string }) => void;
|
|
92
|
+
}> = ({ value, onChange }) => {
|
|
93
|
+
const dsOptions = useDataSourceOptions();
|
|
94
|
+
const collectionOptions = useCollectionOptions(value.dataSource);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Form layout="vertical">
|
|
98
|
+
<Form.Item label="Datasource">
|
|
99
|
+
<Select
|
|
100
|
+
value={value.dataSource}
|
|
101
|
+
options={dsOptions}
|
|
102
|
+
placeholder="Select datasource"
|
|
103
|
+
onChange={(v) => onChange({ dataSource: v, collection: '' })}
|
|
104
|
+
showSearch
|
|
105
|
+
filterOption={(input, option) => (option?.label as string)?.toLowerCase().includes(input.toLowerCase())}
|
|
106
|
+
/>
|
|
107
|
+
</Form.Item>
|
|
108
|
+
<Form.Item label="Collection">
|
|
109
|
+
<Select
|
|
110
|
+
value={value.collection || undefined}
|
|
111
|
+
options={collectionOptions}
|
|
112
|
+
placeholder="Select collection"
|
|
113
|
+
onChange={(v) => onChange({ ...value, collection: v })}
|
|
114
|
+
showSearch
|
|
115
|
+
filterOption={(input, option) => (option?.label as string)?.toLowerCase().includes(input.toLowerCase())}
|
|
116
|
+
disabled={!value.dataSource}
|
|
117
|
+
/>
|
|
118
|
+
</Form.Item>
|
|
119
|
+
</Form>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Tab 2: Joins
|
|
124
|
+
const JoinRow: React.FC<{
|
|
125
|
+
join: JoinDef;
|
|
126
|
+
index: number;
|
|
127
|
+
primaryDs: string;
|
|
128
|
+
primaryCollection: string;
|
|
129
|
+
onChange: (index: number, join: JoinDef) => void;
|
|
130
|
+
onRemove: (index: number) => void;
|
|
131
|
+
}> = ({ join, index, primaryDs, primaryCollection, onChange, onRemove }) => {
|
|
132
|
+
const dsOptions = useDataSourceOptions();
|
|
133
|
+
const collectionOptions = useCollectionOptions(join.dataSource);
|
|
134
|
+
const leftFieldOptions = useFieldOptions(primaryDs, primaryCollection);
|
|
135
|
+
const rightFieldOptions = useFieldOptions(join.dataSource, join.collection);
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div style={{ border: '1px solid #d9d9d9', borderRadius: 6, padding: 16, marginBottom: 12 }}>
|
|
139
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
|
|
140
|
+
<Text strong>Join #{index + 1}</Text>
|
|
141
|
+
<Button type="text" danger icon={<DeleteOutlined />} onClick={() => onRemove(index)} />
|
|
142
|
+
</div>
|
|
143
|
+
<Form layout="vertical" size="small">
|
|
144
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
|
145
|
+
<Form.Item label="Datasource" style={{ marginBottom: 8 }}>
|
|
146
|
+
<Select
|
|
147
|
+
value={join.dataSource}
|
|
148
|
+
options={dsOptions}
|
|
149
|
+
onChange={(v) => onChange(index, { ...join, dataSource: v, collection: '', rightField: '' })}
|
|
150
|
+
showSearch
|
|
151
|
+
filterOption={(input, option) => (option?.label as string)?.toLowerCase().includes(input.toLowerCase())}
|
|
152
|
+
/>
|
|
153
|
+
</Form.Item>
|
|
154
|
+
<Form.Item label="Collection" style={{ marginBottom: 8 }}>
|
|
155
|
+
<Select
|
|
156
|
+
value={join.collection || undefined}
|
|
157
|
+
options={collectionOptions}
|
|
158
|
+
onChange={(v) => onChange(index, { ...join, collection: v, rightField: '' })}
|
|
159
|
+
disabled={!join.dataSource}
|
|
160
|
+
showSearch
|
|
161
|
+
filterOption={(input, option) => (option?.label as string)?.toLowerCase().includes(input.toLowerCase())}
|
|
162
|
+
/>
|
|
163
|
+
</Form.Item>
|
|
164
|
+
</div>
|
|
165
|
+
<Form.Item label="Join Type" style={{ marginBottom: 8 }}>
|
|
166
|
+
<Radio.Group value={join.joinType} onChange={(e) => onChange(index, { ...join, joinType: e.target.value })}>
|
|
167
|
+
<Radio value="left">Left Join</Radio>
|
|
168
|
+
<Radio value="inner">Inner Join</Radio>
|
|
169
|
+
</Radio.Group>
|
|
170
|
+
</Form.Item>
|
|
171
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
|
172
|
+
<Form.Item label="Left Field (primary)" style={{ marginBottom: 0 }}>
|
|
173
|
+
<Select
|
|
174
|
+
value={join.leftField || undefined}
|
|
175
|
+
options={leftFieldOptions}
|
|
176
|
+
onChange={(v) => onChange(index, { ...join, leftField: v })}
|
|
177
|
+
placeholder="Field from primary"
|
|
178
|
+
showSearch
|
|
179
|
+
filterOption={(input, option) => (option?.label as string)?.toLowerCase().includes(input.toLowerCase())}
|
|
180
|
+
/>
|
|
181
|
+
</Form.Item>
|
|
182
|
+
<Form.Item label="Right Field (join)" style={{ marginBottom: 0 }}>
|
|
183
|
+
<Select
|
|
184
|
+
value={join.rightField || undefined}
|
|
185
|
+
options={rightFieldOptions}
|
|
186
|
+
onChange={(v) => onChange(index, { ...join, rightField: v })}
|
|
187
|
+
placeholder="Field from join table"
|
|
188
|
+
disabled={!join.collection}
|
|
189
|
+
showSearch
|
|
190
|
+
filterOption={(input, option) => (option?.label as string)?.toLowerCase().includes(input.toLowerCase())}
|
|
191
|
+
/>
|
|
192
|
+
</Form.Item>
|
|
193
|
+
</div>
|
|
194
|
+
</Form>
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const JoinsTab: React.FC<{
|
|
200
|
+
joins: JoinDef[];
|
|
201
|
+
primaryDs: string;
|
|
202
|
+
primaryCollection: string;
|
|
203
|
+
onChange: (joins: JoinDef[]) => void;
|
|
204
|
+
}> = ({ joins, primaryDs, primaryCollection, onChange }) => {
|
|
205
|
+
const handleAdd = () => {
|
|
206
|
+
onChange([...joins, { dataSource: 'main', collection: '', joinType: 'left', leftField: '', rightField: '' }]);
|
|
207
|
+
};
|
|
208
|
+
const handleChange = (index: number, join: JoinDef) => {
|
|
209
|
+
const next = [...joins];
|
|
210
|
+
next[index] = join;
|
|
211
|
+
onChange(next);
|
|
212
|
+
};
|
|
213
|
+
const handleRemove = (index: number) => {
|
|
214
|
+
onChange(joins.filter((_, i) => i !== index));
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<div>
|
|
219
|
+
{joins.map((join, i) => (
|
|
220
|
+
<JoinRow
|
|
221
|
+
key={i}
|
|
222
|
+
join={join}
|
|
223
|
+
index={i}
|
|
224
|
+
primaryDs={primaryDs}
|
|
225
|
+
primaryCollection={primaryCollection}
|
|
226
|
+
onChange={handleChange}
|
|
227
|
+
onRemove={handleRemove}
|
|
228
|
+
/>
|
|
229
|
+
))}
|
|
230
|
+
<Button type="dashed" icon={<PlusOutlined />} onClick={handleAdd} block>
|
|
231
|
+
Add Join
|
|
232
|
+
</Button>
|
|
233
|
+
</div>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Tab 3: Columns
|
|
238
|
+
const ColumnsTab: React.FC<{
|
|
239
|
+
columns: ColumnDef[];
|
|
240
|
+
primaryDs: string;
|
|
241
|
+
primaryCollection: string;
|
|
242
|
+
joins: JoinDef[];
|
|
243
|
+
onChange: (cols: ColumnDef[]) => void;
|
|
244
|
+
}> = ({ columns, primaryDs, primaryCollection, joins, onChange }) => {
|
|
245
|
+
const primaryFields = useFieldOptions(primaryDs, primaryCollection);
|
|
246
|
+
|
|
247
|
+
// Build all available fields from all sources
|
|
248
|
+
const allFields = useMemo(() => {
|
|
249
|
+
const fields: { source: number; sourceName: string; field: string; label: string; type: string }[] = [];
|
|
250
|
+
|
|
251
|
+
for (const f of primaryFields) {
|
|
252
|
+
fields.push({
|
|
253
|
+
source: 0,
|
|
254
|
+
sourceName: primaryCollection,
|
|
255
|
+
field: f.value,
|
|
256
|
+
label: `${primaryCollection}.${f.label}`,
|
|
257
|
+
type: f.type,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return fields;
|
|
262
|
+
}, [primaryFields, primaryCollection]);
|
|
263
|
+
|
|
264
|
+
// Auto-populate columns if empty
|
|
265
|
+
const handleAutoPopulate = useCallback(() => {
|
|
266
|
+
const cols: ColumnDef[] = allFields.map((f) => ({
|
|
267
|
+
source: f.source,
|
|
268
|
+
field: f.field,
|
|
269
|
+
selected: true,
|
|
270
|
+
}));
|
|
271
|
+
// Add join fields
|
|
272
|
+
// (join fields will be added dynamically when they're loaded)
|
|
273
|
+
onChange(cols);
|
|
274
|
+
}, [allFields, onChange]);
|
|
275
|
+
|
|
276
|
+
const tableColumns = [
|
|
277
|
+
{
|
|
278
|
+
title: 'Include',
|
|
279
|
+
dataIndex: 'selected',
|
|
280
|
+
width: 70,
|
|
281
|
+
render: (_: any, record: ColumnDef, index: number) => (
|
|
282
|
+
<Checkbox
|
|
283
|
+
checked={record.selected !== false}
|
|
284
|
+
onChange={(e) => {
|
|
285
|
+
const next = [...columns];
|
|
286
|
+
next[index] = { ...next[index], selected: e.target.checked };
|
|
287
|
+
onChange(next);
|
|
288
|
+
}}
|
|
289
|
+
/>
|
|
290
|
+
),
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
title: 'Source',
|
|
294
|
+
dataIndex: 'source',
|
|
295
|
+
width: 100,
|
|
296
|
+
render: (val: number) => (val === 0 ? 'Primary' : `Join #${val}`),
|
|
297
|
+
},
|
|
298
|
+
{ title: 'Field', dataIndex: 'field', width: 150 },
|
|
299
|
+
{
|
|
300
|
+
title: 'Alias',
|
|
301
|
+
dataIndex: 'alias',
|
|
302
|
+
width: 150,
|
|
303
|
+
render: (_: any, record: ColumnDef, index: number) => (
|
|
304
|
+
<Input
|
|
305
|
+
size="small"
|
|
306
|
+
value={record.alias || ''}
|
|
307
|
+
placeholder={record.field}
|
|
308
|
+
onChange={(e) => {
|
|
309
|
+
const next = [...columns];
|
|
310
|
+
next[index] = { ...next[index], alias: e.target.value || undefined };
|
|
311
|
+
onChange(next);
|
|
312
|
+
}}
|
|
313
|
+
/>
|
|
314
|
+
),
|
|
315
|
+
},
|
|
316
|
+
];
|
|
317
|
+
|
|
318
|
+
return (
|
|
319
|
+
<div>
|
|
320
|
+
<div style={{ marginBottom: 12 }}>
|
|
321
|
+
<Button size="small" onClick={handleAutoPopulate}>
|
|
322
|
+
Auto-populate from sources
|
|
323
|
+
</Button>
|
|
324
|
+
</div>
|
|
325
|
+
{columns.length > 0 ? (
|
|
326
|
+
<Table
|
|
327
|
+
dataSource={columns}
|
|
328
|
+
columns={tableColumns}
|
|
329
|
+
rowKey={(_, i) => String(i)}
|
|
330
|
+
size="small"
|
|
331
|
+
pagination={false}
|
|
332
|
+
scroll={{ y: 300 }}
|
|
333
|
+
/>
|
|
334
|
+
) : (
|
|
335
|
+
<Text type="secondary">
|
|
336
|
+
Click "Auto-populate" to add fields from all configured sources, or they will be auto-detected at
|
|
337
|
+
runtime.
|
|
338
|
+
</Text>
|
|
339
|
+
)}
|
|
340
|
+
</div>
|
|
341
|
+
);
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export const CrossJoinConfigurator: React.FC<Props> = ({ visible, onCancel, onSubmit, initialConfig }) => {
|
|
345
|
+
const [primarySource, setPrimarySource] = useState<{ dataSource: string; collection: string }>(
|
|
346
|
+
initialConfig?.primarySource || { dataSource: 'main', collection: '' },
|
|
347
|
+
);
|
|
348
|
+
const [joins, setJoins] = useState<JoinDef[]>(initialConfig?.joins || []);
|
|
349
|
+
const [columns, setColumns] = useState<ColumnDef[]>(initialConfig?.columns || []);
|
|
350
|
+
|
|
351
|
+
const handleOk = () => {
|
|
352
|
+
const selectedColumns = columns.filter((c) => c.selected !== false);
|
|
353
|
+
onSubmit({
|
|
354
|
+
primarySource,
|
|
355
|
+
joins,
|
|
356
|
+
columns: selectedColumns.map(({ selected, ...rest }) => rest),
|
|
357
|
+
});
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const isValid = primarySource.dataSource && primarySource.collection;
|
|
361
|
+
|
|
362
|
+
return (
|
|
363
|
+
<Modal
|
|
364
|
+
title="Configure Cross Join"
|
|
365
|
+
open={visible}
|
|
366
|
+
onCancel={onCancel}
|
|
367
|
+
onOk={handleOk}
|
|
368
|
+
okButtonProps={{ disabled: !isValid }}
|
|
369
|
+
width={720}
|
|
370
|
+
destroyOnClose
|
|
371
|
+
>
|
|
372
|
+
<Tabs
|
|
373
|
+
items={[
|
|
374
|
+
{
|
|
375
|
+
key: 'primary',
|
|
376
|
+
label: 'Primary Source',
|
|
377
|
+
children: <PrimarySourceTab value={primarySource} onChange={setPrimarySource} />,
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
key: 'joins',
|
|
381
|
+
label: `Joins (${joins.length})`,
|
|
382
|
+
children: (
|
|
383
|
+
<JoinsTab
|
|
384
|
+
joins={joins}
|
|
385
|
+
primaryDs={primarySource.dataSource}
|
|
386
|
+
primaryCollection={primarySource.collection}
|
|
387
|
+
onChange={setJoins}
|
|
388
|
+
/>
|
|
389
|
+
),
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
key: 'columns',
|
|
393
|
+
label: 'Columns',
|
|
394
|
+
children: (
|
|
395
|
+
<ColumnsTab
|
|
396
|
+
columns={columns}
|
|
397
|
+
primaryDs={primarySource.dataSource}
|
|
398
|
+
primaryCollection={primarySource.collection}
|
|
399
|
+
joins={joins}
|
|
400
|
+
onChange={setColumns}
|
|
401
|
+
/>
|
|
402
|
+
),
|
|
403
|
+
},
|
|
404
|
+
]}
|
|
405
|
+
/>
|
|
406
|
+
</Modal>
|
|
407
|
+
);
|
|
408
|
+
};
|