plugin-block-cross-join 0.1.6 → 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
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import React, { useState, useMemo, useCallback, useEffect } from 'react';
|
|
4
|
+
import { App, Modal, Tabs, Form, Select, Button, Radio, Input, Table, Checkbox, Typography } from 'antd';
|
|
5
|
+
import { PlusOutlined, DeleteOutlined } from '@ant-design/icons';
|
|
6
|
+
import { useFlowContext } from '@nocobase/flow-engine';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
|
|
9
|
+
const { Text } = Typography;
|
|
10
|
+
|
|
11
|
+
interface JoinDef {
|
|
12
|
+
dataSource: string;
|
|
13
|
+
collection: string;
|
|
14
|
+
joinType: 'left' | 'inner';
|
|
15
|
+
leftField: string;
|
|
16
|
+
rightField: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface ColumnDef {
|
|
20
|
+
source: number;
|
|
21
|
+
field: string;
|
|
22
|
+
alias?: string;
|
|
23
|
+
jsonExpand?: string[];
|
|
24
|
+
selected?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface CrossJoinConfig {
|
|
28
|
+
primarySource: { dataSource: string; collection: string };
|
|
29
|
+
joins: JoinDef[];
|
|
30
|
+
columns: ColumnDef[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Props {
|
|
34
|
+
visible: boolean;
|
|
35
|
+
onCancel: () => void;
|
|
36
|
+
onSubmit: (config: CrossJoinConfig) => void | Promise<void>;
|
|
37
|
+
initialConfig?: CrossJoinConfig;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function useDataSourceOptions() {
|
|
41
|
+
const { dataSourceManager } = useFlowContext();
|
|
42
|
+
return dataSourceManager.getDataSources().map((ds) => ({
|
|
43
|
+
label: ds.displayName || ds.key,
|
|
44
|
+
value: ds.key,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function useCollectionOptions(dsKey: string) {
|
|
49
|
+
const { dataSourceManager } = useFlowContext();
|
|
50
|
+
return useMemo(() => {
|
|
51
|
+
if (!dsKey) return [];
|
|
52
|
+
const ds = dataSourceManager.getDataSource(dsKey);
|
|
53
|
+
if (!ds) return [];
|
|
54
|
+
const collections = ds.collectionManager.getCollections() || [];
|
|
55
|
+
return collections.map((c) => ({
|
|
56
|
+
label: c.title || c.name,
|
|
57
|
+
value: c.name,
|
|
58
|
+
}));
|
|
59
|
+
}, [dataSourceManager, dsKey]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function useFieldOptions(dsKey: string, collectionName: string) {
|
|
63
|
+
const { dataSourceManager } = useFlowContext();
|
|
64
|
+
return useMemo(() => {
|
|
65
|
+
if (!dsKey || !collectionName) return [];
|
|
66
|
+
const ds = dataSourceManager.getDataSource(dsKey);
|
|
67
|
+
if (!ds) return [];
|
|
68
|
+
const collection = ds.collectionManager.getCollection(collectionName);
|
|
69
|
+
if (!collection) return [];
|
|
70
|
+
const fields = collection.getFields() || [];
|
|
71
|
+
return fields.map((f) => ({
|
|
72
|
+
label: f.uiSchema?.title || f.name,
|
|
73
|
+
value: f.name,
|
|
74
|
+
type: f.type,
|
|
75
|
+
interface: f.interface,
|
|
76
|
+
}));
|
|
77
|
+
}, [dataSourceManager, dsKey, collectionName]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Tab 1: Primary Source
|
|
81
|
+
const PrimarySourceTab: React.FC<{
|
|
82
|
+
value: { dataSource: string; collection: string };
|
|
83
|
+
onChange: (val: { dataSource: string; collection: string }) => void;
|
|
84
|
+
}> = ({ value, onChange }) => {
|
|
85
|
+
const { t } = useTranslation('plugin-block-cross-join');
|
|
86
|
+
const dsOptions = useDataSourceOptions();
|
|
87
|
+
const collectionOptions = useCollectionOptions(value.dataSource);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Form layout="vertical">
|
|
91
|
+
<Form.Item label={t('Datasource')}>
|
|
92
|
+
<Select
|
|
93
|
+
value={value.dataSource}
|
|
94
|
+
options={dsOptions}
|
|
95
|
+
placeholder={t('Select datasource')}
|
|
96
|
+
onChange={(v) => onChange({ dataSource: v, collection: '' })}
|
|
97
|
+
showSearch
|
|
98
|
+
filterOption={(input, option) =>
|
|
99
|
+
String(option?.label ?? '')
|
|
100
|
+
.toLowerCase()
|
|
101
|
+
.includes(input.toLowerCase())
|
|
102
|
+
}
|
|
103
|
+
/>
|
|
104
|
+
</Form.Item>
|
|
105
|
+
<Form.Item label={t('Collection')}>
|
|
106
|
+
<Select
|
|
107
|
+
value={value.collection || undefined}
|
|
108
|
+
options={collectionOptions}
|
|
109
|
+
placeholder={t('Select collection')}
|
|
110
|
+
onChange={(v) => onChange({ ...value, collection: v })}
|
|
111
|
+
showSearch
|
|
112
|
+
filterOption={(input, option) =>
|
|
113
|
+
String(option?.label ?? '')
|
|
114
|
+
.toLowerCase()
|
|
115
|
+
.includes(input.toLowerCase())
|
|
116
|
+
}
|
|
117
|
+
disabled={!value.dataSource}
|
|
118
|
+
/>
|
|
119
|
+
</Form.Item>
|
|
120
|
+
</Form>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Tab 2: Joins
|
|
125
|
+
const JoinRow: React.FC<{
|
|
126
|
+
join: JoinDef;
|
|
127
|
+
index: number;
|
|
128
|
+
primaryDs: string;
|
|
129
|
+
primaryCollection: string;
|
|
130
|
+
onChange: (index: number, join: JoinDef) => void;
|
|
131
|
+
onRemove: (index: number) => void;
|
|
132
|
+
}> = ({ join, index, primaryDs, primaryCollection, onChange, onRemove }) => {
|
|
133
|
+
const { t } = useTranslation('plugin-block-cross-join');
|
|
134
|
+
const dsOptions = useDataSourceOptions();
|
|
135
|
+
const collectionOptions = useCollectionOptions(join.dataSource);
|
|
136
|
+
const leftFieldOptions = useFieldOptions(primaryDs, primaryCollection);
|
|
137
|
+
const rightFieldOptions = useFieldOptions(join.dataSource, join.collection);
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div style={{ border: '1px solid #d9d9d9', borderRadius: 6, padding: 16, marginBottom: 12 }}>
|
|
141
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
|
|
142
|
+
<Text strong>{t('Join #{{number}}', { number: index + 1 })}</Text>
|
|
143
|
+
<Button
|
|
144
|
+
type="text"
|
|
145
|
+
danger
|
|
146
|
+
aria-label={t('Remove join')}
|
|
147
|
+
icon={<DeleteOutlined />}
|
|
148
|
+
onClick={() => onRemove(index)}
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
<Form layout="vertical" size="small">
|
|
152
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
|
153
|
+
<Form.Item label={t('Datasource')} style={{ marginBottom: 8 }}>
|
|
154
|
+
<Select
|
|
155
|
+
value={join.dataSource}
|
|
156
|
+
options={dsOptions}
|
|
157
|
+
onChange={(v) => onChange(index, { ...join, dataSource: v, collection: '', rightField: '' })}
|
|
158
|
+
showSearch
|
|
159
|
+
filterOption={(input, option) =>
|
|
160
|
+
String(option?.label ?? '')
|
|
161
|
+
.toLowerCase()
|
|
162
|
+
.includes(input.toLowerCase())
|
|
163
|
+
}
|
|
164
|
+
/>
|
|
165
|
+
</Form.Item>
|
|
166
|
+
<Form.Item label={t('Collection')} style={{ marginBottom: 8 }}>
|
|
167
|
+
<Select
|
|
168
|
+
value={join.collection || undefined}
|
|
169
|
+
options={collectionOptions}
|
|
170
|
+
onChange={(v) => onChange(index, { ...join, collection: v, rightField: '' })}
|
|
171
|
+
disabled={!join.dataSource}
|
|
172
|
+
showSearch
|
|
173
|
+
filterOption={(input, option) =>
|
|
174
|
+
String(option?.label ?? '')
|
|
175
|
+
.toLowerCase()
|
|
176
|
+
.includes(input.toLowerCase())
|
|
177
|
+
}
|
|
178
|
+
/>
|
|
179
|
+
</Form.Item>
|
|
180
|
+
</div>
|
|
181
|
+
<Form.Item label={t('Join Type')} style={{ marginBottom: 8 }}>
|
|
182
|
+
<Radio.Group value={join.joinType} onChange={(e) => onChange(index, { ...join, joinType: e.target.value })}>
|
|
183
|
+
<Radio value="left">{t('Left Join')}</Radio>
|
|
184
|
+
<Radio value="inner">{t('Inner Join')}</Radio>
|
|
185
|
+
</Radio.Group>
|
|
186
|
+
</Form.Item>
|
|
187
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
|
|
188
|
+
<Form.Item label={t('Left Field (primary)')} style={{ marginBottom: 0 }}>
|
|
189
|
+
<Select
|
|
190
|
+
value={join.leftField || undefined}
|
|
191
|
+
options={leftFieldOptions}
|
|
192
|
+
onChange={(v) => onChange(index, { ...join, leftField: v })}
|
|
193
|
+
placeholder={t('Field from primary')}
|
|
194
|
+
showSearch
|
|
195
|
+
filterOption={(input, option) =>
|
|
196
|
+
String(option?.label ?? '')
|
|
197
|
+
.toLowerCase()
|
|
198
|
+
.includes(input.toLowerCase())
|
|
199
|
+
}
|
|
200
|
+
/>
|
|
201
|
+
</Form.Item>
|
|
202
|
+
<Form.Item label={t('Right Field (join)')} style={{ marginBottom: 0 }}>
|
|
203
|
+
<Select
|
|
204
|
+
value={join.rightField || undefined}
|
|
205
|
+
options={rightFieldOptions}
|
|
206
|
+
onChange={(v) => onChange(index, { ...join, rightField: v })}
|
|
207
|
+
placeholder={t('Field from join table')}
|
|
208
|
+
disabled={!join.collection}
|
|
209
|
+
showSearch
|
|
210
|
+
filterOption={(input, option) =>
|
|
211
|
+
String(option?.label ?? '')
|
|
212
|
+
.toLowerCase()
|
|
213
|
+
.includes(input.toLowerCase())
|
|
214
|
+
}
|
|
215
|
+
/>
|
|
216
|
+
</Form.Item>
|
|
217
|
+
</div>
|
|
218
|
+
</Form>
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const JoinsTab: React.FC<{
|
|
224
|
+
joins: JoinDef[];
|
|
225
|
+
primaryDs: string;
|
|
226
|
+
primaryCollection: string;
|
|
227
|
+
onChange: (joins: JoinDef[]) => void;
|
|
228
|
+
}> = ({ joins, primaryDs, primaryCollection, onChange }) => {
|
|
229
|
+
const { t } = useTranslation('plugin-block-cross-join');
|
|
230
|
+
const handleAdd = () => {
|
|
231
|
+
onChange([...joins, { dataSource: 'main', collection: '', joinType: 'left', leftField: '', rightField: '' }]);
|
|
232
|
+
};
|
|
233
|
+
const handleChange = (index: number, join: JoinDef) => {
|
|
234
|
+
const next = [...joins];
|
|
235
|
+
next[index] = join;
|
|
236
|
+
onChange(next);
|
|
237
|
+
};
|
|
238
|
+
const handleRemove = (index: number) => {
|
|
239
|
+
onChange(joins.filter((_, i) => i !== index));
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<div>
|
|
244
|
+
{joins.map((join, i) => (
|
|
245
|
+
<JoinRow
|
|
246
|
+
key={i}
|
|
247
|
+
join={join}
|
|
248
|
+
index={i}
|
|
249
|
+
primaryDs={primaryDs}
|
|
250
|
+
primaryCollection={primaryCollection}
|
|
251
|
+
onChange={handleChange}
|
|
252
|
+
onRemove={handleRemove}
|
|
253
|
+
/>
|
|
254
|
+
))}
|
|
255
|
+
<Button type="dashed" icon={<PlusOutlined />} onClick={handleAdd} block>
|
|
256
|
+
{t('Add Join')}
|
|
257
|
+
</Button>
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Tab 3: Columns
|
|
263
|
+
const ColumnsTab: React.FC<{
|
|
264
|
+
columns: ColumnDef[];
|
|
265
|
+
primaryDs: string;
|
|
266
|
+
primaryCollection: string;
|
|
267
|
+
joins: JoinDef[];
|
|
268
|
+
onChange: (cols: ColumnDef[]) => void;
|
|
269
|
+
}> = ({ columns, primaryDs, primaryCollection, joins, onChange }) => {
|
|
270
|
+
const { t } = useTranslation('plugin-block-cross-join');
|
|
271
|
+
const { dataSourceManager } = useFlowContext();
|
|
272
|
+
|
|
273
|
+
// Build all available fields from all sources
|
|
274
|
+
const allFields = useMemo(() => {
|
|
275
|
+
const fields: { source: number; sourceName: string; field: string; label: string; type: string }[] = [];
|
|
276
|
+
|
|
277
|
+
const sources = [{ dataSource: primaryDs, collection: primaryCollection }, ...joins];
|
|
278
|
+
for (const [source, item] of sources.entries()) {
|
|
279
|
+
const collection = dataSourceManager.getCollection(item.dataSource, item.collection);
|
|
280
|
+
for (const field of collection?.getFields() || []) {
|
|
281
|
+
fields.push({
|
|
282
|
+
source,
|
|
283
|
+
sourceName: item.collection,
|
|
284
|
+
field: field.name,
|
|
285
|
+
label: `${item.collection}.${field.title || field.name}`,
|
|
286
|
+
type: field.type,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return fields;
|
|
292
|
+
}, [dataSourceManager, primaryDs, primaryCollection, joins]);
|
|
293
|
+
|
|
294
|
+
// Auto-populate columns if empty
|
|
295
|
+
const handleAutoPopulate = useCallback(() => {
|
|
296
|
+
const cols: ColumnDef[] = allFields.map((f) => ({
|
|
297
|
+
source: f.source,
|
|
298
|
+
field: f.field,
|
|
299
|
+
selected: true,
|
|
300
|
+
}));
|
|
301
|
+
onChange(cols);
|
|
302
|
+
}, [allFields, onChange]);
|
|
303
|
+
|
|
304
|
+
const tableColumns = [
|
|
305
|
+
{
|
|
306
|
+
title: t('Include'),
|
|
307
|
+
dataIndex: 'selected',
|
|
308
|
+
width: 70,
|
|
309
|
+
render: (_: unknown, record: ColumnDef, index: number) => (
|
|
310
|
+
<Checkbox
|
|
311
|
+
checked={record.selected !== false}
|
|
312
|
+
onChange={(e) => {
|
|
313
|
+
const next = [...columns];
|
|
314
|
+
next[index] = { ...next[index], selected: e.target.checked };
|
|
315
|
+
onChange(next);
|
|
316
|
+
}}
|
|
317
|
+
/>
|
|
318
|
+
),
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
title: t('Source'),
|
|
322
|
+
dataIndex: 'source',
|
|
323
|
+
width: 100,
|
|
324
|
+
render: (val: number) => (val === 0 ? t('Primary Source') : t('Join #{{number}}', { number: val })),
|
|
325
|
+
},
|
|
326
|
+
{ title: t('Field'), dataIndex: 'field', width: 150 },
|
|
327
|
+
{
|
|
328
|
+
title: t('Alias'),
|
|
329
|
+
dataIndex: 'alias',
|
|
330
|
+
width: 150,
|
|
331
|
+
render: (_: unknown, record: ColumnDef, index: number) => (
|
|
332
|
+
<Input
|
|
333
|
+
size="small"
|
|
334
|
+
value={record.alias || ''}
|
|
335
|
+
placeholder={record.field}
|
|
336
|
+
onChange={(e) => {
|
|
337
|
+
const next = [...columns];
|
|
338
|
+
next[index] = { ...next[index], alias: e.target.value || undefined };
|
|
339
|
+
onChange(next);
|
|
340
|
+
}}
|
|
341
|
+
/>
|
|
342
|
+
),
|
|
343
|
+
},
|
|
344
|
+
];
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<div>
|
|
348
|
+
<div style={{ marginBottom: 12 }}>
|
|
349
|
+
<Button size="small" onClick={handleAutoPopulate}>
|
|
350
|
+
{t('Auto-populate from sources')}
|
|
351
|
+
</Button>
|
|
352
|
+
</div>
|
|
353
|
+
{columns.length > 0 ? (
|
|
354
|
+
<Table
|
|
355
|
+
dataSource={columns}
|
|
356
|
+
columns={tableColumns}
|
|
357
|
+
rowKey={(_, i) => String(i)}
|
|
358
|
+
size="small"
|
|
359
|
+
pagination={false}
|
|
360
|
+
scroll={{ y: 300 }}
|
|
361
|
+
/>
|
|
362
|
+
) : (
|
|
363
|
+
<Text type="secondary">
|
|
364
|
+
{t('Auto-populate fields from the configured sources, or leave empty to detect columns at runtime.')}
|
|
365
|
+
</Text>
|
|
366
|
+
)}
|
|
367
|
+
</div>
|
|
368
|
+
);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
export const CrossJoinConfigurator: React.FC<Props> = ({ visible, onCancel, onSubmit, initialConfig }) => {
|
|
372
|
+
const { t } = useTranslation('plugin-block-cross-join');
|
|
373
|
+
const { message } = App.useApp();
|
|
374
|
+
const [saving, setSaving] = useState(false);
|
|
375
|
+
const [primarySource, setPrimarySource] = useState<{ dataSource: string; collection: string }>(
|
|
376
|
+
initialConfig?.primarySource || { dataSource: 'main', collection: '' },
|
|
377
|
+
);
|
|
378
|
+
const [joins, setJoins] = useState<JoinDef[]>(initialConfig?.joins || []);
|
|
379
|
+
const [columns, setColumns] = useState<ColumnDef[]>(initialConfig?.columns || []);
|
|
380
|
+
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
if (!visible) return;
|
|
383
|
+
setPrimarySource(initialConfig?.primarySource || { dataSource: 'main', collection: '' });
|
|
384
|
+
setJoins(initialConfig?.joins || []);
|
|
385
|
+
setColumns(initialConfig?.columns || []);
|
|
386
|
+
}, [visible, initialConfig]);
|
|
387
|
+
|
|
388
|
+
const handleOk = async () => {
|
|
389
|
+
const selectedColumns = columns.filter((c) => c.selected !== false);
|
|
390
|
+
setSaving(true);
|
|
391
|
+
try {
|
|
392
|
+
await onSubmit({
|
|
393
|
+
primarySource,
|
|
394
|
+
joins,
|
|
395
|
+
columns: selectedColumns.map(({ selected, ...rest }) => rest),
|
|
396
|
+
});
|
|
397
|
+
} catch (error) {
|
|
398
|
+
message.error(error instanceof Error ? error.message : t('Operation failed'));
|
|
399
|
+
} finally {
|
|
400
|
+
setSaving(false);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const isValid = primarySource.dataSource && primarySource.collection;
|
|
405
|
+
|
|
406
|
+
return (
|
|
407
|
+
<Modal
|
|
408
|
+
title={t('Configure cross join')}
|
|
409
|
+
open={visible}
|
|
410
|
+
onCancel={onCancel}
|
|
411
|
+
onOk={handleOk}
|
|
412
|
+
confirmLoading={saving}
|
|
413
|
+
okButtonProps={{ disabled: !isValid }}
|
|
414
|
+
width={720}
|
|
415
|
+
destroyOnClose
|
|
416
|
+
>
|
|
417
|
+
<Tabs
|
|
418
|
+
items={[
|
|
419
|
+
{
|
|
420
|
+
key: 'primary',
|
|
421
|
+
label: t('Primary Source'),
|
|
422
|
+
children: <PrimarySourceTab value={primarySource} onChange={setPrimarySource} />,
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
key: 'joins',
|
|
426
|
+
label: `${t('Joins')} (${joins.length})`,
|
|
427
|
+
children: (
|
|
428
|
+
<JoinsTab
|
|
429
|
+
joins={joins}
|
|
430
|
+
primaryDs={primarySource.dataSource}
|
|
431
|
+
primaryCollection={primarySource.collection}
|
|
432
|
+
onChange={setJoins}
|
|
433
|
+
/>
|
|
434
|
+
),
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
key: 'columns',
|
|
438
|
+
label: t('Columns'),
|
|
439
|
+
children: (
|
|
440
|
+
<ColumnsTab
|
|
441
|
+
columns={columns}
|
|
442
|
+
primaryDs={primarySource.dataSource}
|
|
443
|
+
primaryCollection={primarySource.collection}
|
|
444
|
+
joins={joins}
|
|
445
|
+
onChange={setColumns}
|
|
446
|
+
/>
|
|
447
|
+
),
|
|
448
|
+
},
|
|
449
|
+
]}
|
|
450
|
+
/>
|
|
451
|
+
</Modal>
|
|
452
|
+
);
|
|
453
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import { FlowEngine } from '@nocobase/flow-engine';
|
|
4
|
+
import { expect, it, vi } from 'vitest';
|
|
5
|
+
import { CrossJoinBlockModel } from '../CrossJoinBlockModel';
|
|
6
|
+
|
|
7
|
+
vi.mock('@nocobase/client-v2', async () => {
|
|
8
|
+
const { FlowModel } = await import('@nocobase/flow-engine');
|
|
9
|
+
return { BlockModel: class extends FlowModel {} };
|
|
10
|
+
});
|
|
11
|
+
vi.mock('../CrossJoinConfigurator', () => ({ CrossJoinConfigurator: () => null }));
|
|
12
|
+
|
|
13
|
+
it('keeps the mapping modal closed on render and opens it only from the settings menu', async () => {
|
|
14
|
+
const engine = new FlowEngine();
|
|
15
|
+
engine.registerModels({ CrossJoinBlockModel });
|
|
16
|
+
const model = engine.createModel<CrossJoinBlockModel>({ use: 'CrossJoinBlockModel' });
|
|
17
|
+
const open = vi.spyOn(model, 'openConfigurator');
|
|
18
|
+
vi.spyOn(model, 'rerender').mockResolvedValue(undefined);
|
|
19
|
+
await model.dispatchEvent('beforeRender');
|
|
20
|
+
expect(open).not.toHaveBeenCalled();
|
|
21
|
+
const items = await CrossJoinBlockModel.getExtraMenuItems(model, (key) => key);
|
|
22
|
+
const edit = items.find((item) => item.key === 'cross-join-edit-mapping');
|
|
23
|
+
expect(edit?.label).toBe('Edit mapping');
|
|
24
|
+
edit.onClick();
|
|
25
|
+
expect(open).toHaveBeenCalledOnce();
|
|
26
|
+
model.closeConfigurator();
|
|
27
|
+
await model.dispatchEvent('beforeRender');
|
|
28
|
+
expect(open).toHaveBeenCalledOnce();
|
|
29
|
+
});
|
package/src/client-v2/plugin.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Plugin, Application } from '@nocobase/client-v2';
|
|
2
|
+
import { CrossJoinBlockModel } from './CrossJoinBlockModel';
|
|
2
3
|
|
|
3
4
|
export class PluginBlockCrossJoinClient extends Plugin<Record<string, never>, Application> {
|
|
4
|
-
async load() {
|
|
5
|
+
async load() {
|
|
6
|
+
this.flowEngine.registerModels({ CrossJoinBlockModel });
|
|
7
|
+
}
|
|
5
8
|
}
|
|
6
9
|
|
|
7
10
|
export default PluginBlockCrossJoinClient;
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export * from './server';
|
|
11
|
-
export { default } from './server';
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
export * from './server';
|
|
4
|
+
export { default } from './server';
|
package/src/locale/en-US.json
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Cross Join": "Cross Join",
|
|
3
|
-
"Cross Join Block": "Cross Join Block",
|
|
4
|
-
"Configure cross join": "Configure cross join",
|
|
5
|
-
"Primary Source": "Primary Source",
|
|
6
|
-
"Joins": "Joins",
|
|
7
|
-
"Columns": "Columns",
|
|
8
|
-
"Datasource": "Datasource",
|
|
9
|
-
"Collection": "Collection",
|
|
10
|
-
"Join Type": "Join Type",
|
|
11
|
-
"Left Join": "Left Join",
|
|
12
|
-
"Inner Join": "Inner Join",
|
|
13
|
-
"Left Field": "Left Field",
|
|
14
|
-
"Right Field": "Right Field",
|
|
15
|
-
"Add Join": "Add Join",
|
|
16
|
-
"Field": "Field",
|
|
17
|
-
"Alias": "Alias",
|
|
18
|
-
"Source": "Source",
|
|
19
|
-
"Edit mapping": "Edit mapping",
|
|
20
|
-
"Expand JSON keys": "Expand JSON keys",
|
|
21
|
-
"No data": "No data",
|
|
22
|
-
"Loading...": "Loading..."
|
|
23
|
-
|
|
1
|
+
{
|
|
2
|
+
"Cross Join": "Cross Join",
|
|
3
|
+
"Cross Join Block": "Cross Join Block",
|
|
4
|
+
"Configure cross join": "Configure cross join",
|
|
5
|
+
"Primary Source": "Primary Source",
|
|
6
|
+
"Joins": "Joins",
|
|
7
|
+
"Columns": "Columns",
|
|
8
|
+
"Datasource": "Datasource",
|
|
9
|
+
"Collection": "Collection",
|
|
10
|
+
"Join Type": "Join Type",
|
|
11
|
+
"Left Join": "Left Join",
|
|
12
|
+
"Inner Join": "Inner Join",
|
|
13
|
+
"Left Field": "Left Field",
|
|
14
|
+
"Right Field": "Right Field",
|
|
15
|
+
"Add Join": "Add Join",
|
|
16
|
+
"Field": "Field",
|
|
17
|
+
"Alias": "Alias",
|
|
18
|
+
"Source": "Source",
|
|
19
|
+
"Edit mapping": "Edit mapping",
|
|
20
|
+
"Expand JSON keys": "Expand JSON keys",
|
|
21
|
+
"No data": "No data",
|
|
22
|
+
"Loading...": "Loading...",
|
|
23
|
+
"Cross Join settings": "Cross Join settings",
|
|
24
|
+
"Total {{count}} rows": "Total {{count}} rows",
|
|
25
|
+
"Join #{{number}}": "Join #{{number}}",
|
|
26
|
+
"Remove join": "Remove join",
|
|
27
|
+
"Select datasource": "Select datasource",
|
|
28
|
+
"Select collection": "Select collection",
|
|
29
|
+
"Left Field (primary)": "Left Field (primary)",
|
|
30
|
+
"Right Field (join)": "Right Field (join)",
|
|
31
|
+
"Field from primary": "Field from primary",
|
|
32
|
+
"Field from join table": "Field from join table",
|
|
33
|
+
"Include": "Include",
|
|
34
|
+
"Auto-populate from sources": "Auto-populate from sources",
|
|
35
|
+
"Auto-populate fields from the configured sources, or leave empty to detect columns at runtime.": "Auto-populate fields from the configured sources, or leave empty to detect columns at runtime.",
|
|
36
|
+
"Operation failed": "Operation failed"
|
|
37
|
+
}
|
package/src/locale/zh-CN.json
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Cross Join": "跨源联合",
|
|
3
|
-
"Cross Join Block": "跨源联合区块",
|
|
4
|
-
"Configure cross join": "配置跨源联合",
|
|
5
|
-
"Primary Source": "主数据源",
|
|
6
|
-
"Joins": "联合配置",
|
|
7
|
-
"Columns": "列配置",
|
|
8
|
-
"Datasource": "数据源",
|
|
9
|
-
"Collection": "数据表",
|
|
10
|
-
"Join Type": "联合类型",
|
|
11
|
-
"Left Join": "左联合",
|
|
12
|
-
"Inner Join": "内联合",
|
|
13
|
-
"Left Field": "左字段",
|
|
14
|
-
"Right Field": "右字段",
|
|
15
|
-
"Add Join": "添加联合",
|
|
16
|
-
"Field": "字段",
|
|
17
|
-
"Alias": "别名",
|
|
18
|
-
"Source": "来源",
|
|
19
|
-
"Edit mapping": "编辑映射",
|
|
20
|
-
"Expand JSON keys": "展开JSON键",
|
|
21
|
-
"No data": "暂无数据",
|
|
22
|
-
"Loading...": "加载中..."
|
|
23
|
-
|
|
1
|
+
{
|
|
2
|
+
"Cross Join": "跨源联合",
|
|
3
|
+
"Cross Join Block": "跨源联合区块",
|
|
4
|
+
"Configure cross join": "配置跨源联合",
|
|
5
|
+
"Primary Source": "主数据源",
|
|
6
|
+
"Joins": "联合配置",
|
|
7
|
+
"Columns": "列配置",
|
|
8
|
+
"Datasource": "数据源",
|
|
9
|
+
"Collection": "数据表",
|
|
10
|
+
"Join Type": "联合类型",
|
|
11
|
+
"Left Join": "左联合",
|
|
12
|
+
"Inner Join": "内联合",
|
|
13
|
+
"Left Field": "左字段",
|
|
14
|
+
"Right Field": "右字段",
|
|
15
|
+
"Add Join": "添加联合",
|
|
16
|
+
"Field": "字段",
|
|
17
|
+
"Alias": "别名",
|
|
18
|
+
"Source": "来源",
|
|
19
|
+
"Edit mapping": "编辑映射",
|
|
20
|
+
"Expand JSON keys": "展开JSON键",
|
|
21
|
+
"No data": "暂无数据",
|
|
22
|
+
"Loading...": "加载中...",
|
|
23
|
+
"Cross Join settings": "跨源联合设置",
|
|
24
|
+
"Total {{count}} rows": "共 {{count}} 行",
|
|
25
|
+
"Join #{{number}}": "联合 #{{number}}",
|
|
26
|
+
"Remove join": "删除联合",
|
|
27
|
+
"Select datasource": "选择数据源",
|
|
28
|
+
"Select collection": "选择数据表",
|
|
29
|
+
"Left Field (primary)": "左字段(主表)",
|
|
30
|
+
"Right Field (join)": "右字段(联合表)",
|
|
31
|
+
"Field from primary": "主表字段",
|
|
32
|
+
"Field from join table": "联合表字段",
|
|
33
|
+
"Include": "包含",
|
|
34
|
+
"Auto-populate from sources": "从数据源填充字段",
|
|
35
|
+
"Auto-populate fields from the configured sources, or leave empty to detect columns at runtime.": "从已配置的数据源填充字段,留空则在运行时自动检测列。",
|
|
36
|
+
"Operation failed": "操作失败"
|
|
37
|
+
}
|