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