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.
@@ -1,106 +1 @@
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
- };
1
+ // DEPRECATED: Removed in v2 migration. See CrossJoinBlockModel.tsx.
@@ -1,33 +1 @@
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
- }
1
+ // DEPRECATED: Removed in v2 migration. Block creation now via FlowEngine model system.
@@ -1,50 +1,12 @@
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;
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ import { Plugin } from '@nocobase/client-v2';
4
+ import { CrossJoinBlockModel } from './CrossJoinBlockModel';
5
+
6
+ export class PluginBlockCrossJoinClient extends Plugin {
7
+ async load() {
8
+ this.flowEngine.registerModels({ CrossJoinBlockModel });
9
+ }
10
+ }
11
+
12
+ export default PluginBlockCrossJoinClient;
@@ -1,50 +1 @@
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
- });
1
+ // DEPRECATED: Removed in v2 migration. Settings now via CrossJoinBlockModel.registerFlow().
@@ -0,0 +1,223 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ import { BlockModel } from '@nocobase/client-v2';
4
+ import { tExpr } from '@nocobase/flow-engine';
5
+ import React from 'react';
6
+ import { Table, Empty, Spin } from 'antd';
7
+ import { CrossJoinConfigurator } from './CrossJoinConfigurator';
8
+
9
+ interface JoinDef {
10
+ dataSource: string;
11
+ collection: string;
12
+ joinType: 'left' | 'inner';
13
+ leftField: string;
14
+ rightField: string;
15
+ }
16
+
17
+ interface ColumnDef {
18
+ source: number;
19
+ field: string;
20
+ alias?: string;
21
+ jsonExpand?: string[];
22
+ }
23
+
24
+ interface CrossJoinConfig {
25
+ primarySource: { dataSource: string; collection: string };
26
+ joins: JoinDef[];
27
+ columns: ColumnDef[];
28
+ }
29
+
30
+ export class CrossJoinBlockModel extends BlockModel {
31
+ private _data: Record<string, unknown>[] = [];
32
+ private _loading = false;
33
+ private _page = 1;
34
+ private _pageSize = 20;
35
+ private _total = 0;
36
+ private _configuratorOpen = false;
37
+
38
+ get config(): CrossJoinConfig | undefined {
39
+ return this.stepParams?.crossJoinSettings?.config as CrossJoinConfig | undefined;
40
+ }
41
+
42
+ private async fetchData() {
43
+ const cfg = this.config;
44
+ if (!cfg?.primarySource?.collection) return;
45
+
46
+ this._loading = true;
47
+ this.rerender();
48
+ try {
49
+ const res = await this.context.api.request({
50
+ url: 'crossJoin:query',
51
+ method: 'post',
52
+ data: {
53
+ config: cfg,
54
+ page: this._page,
55
+ pageSize: this._pageSize,
56
+ },
57
+ });
58
+ const body = res?.data;
59
+ this._data = body?.data || [];
60
+ this._total = body?.meta?.count || 0;
61
+ } catch (err) {
62
+ console.error('CrossJoin query failed:', err);
63
+ this._data = [];
64
+ } finally {
65
+ this._loading = false;
66
+ this.rerender();
67
+ }
68
+ }
69
+
70
+ protected onMount() {
71
+ super.onMount();
72
+ this.fetchData();
73
+ }
74
+
75
+ openConfigurator() {
76
+ this._configuratorOpen = true;
77
+ this.rerender();
78
+ }
79
+
80
+ closeConfigurator() {
81
+ this._configuratorOpen = false;
82
+ this.rerender();
83
+ }
84
+
85
+ async handleConfigSubmit(config: CrossJoinConfig) {
86
+ this.setStepParams('crossJoinSettings', { config: { ...config } });
87
+ await this.save();
88
+ this._configuratorOpen = false;
89
+ this._page = 1;
90
+ await this.fetchData();
91
+ }
92
+
93
+ private buildColumns() {
94
+ const cfg = this.config;
95
+ if (cfg?.columns?.length) {
96
+ const cols: {
97
+ title: string;
98
+ dataIndex: string;
99
+ key: string;
100
+ ellipsis: boolean;
101
+ render: (val: unknown) => string;
102
+ }[] = [];
103
+ for (const col of cfg.columns) {
104
+ if (col.jsonExpand?.length) {
105
+ for (const jsonKey of col.jsonExpand) {
106
+ const alias = col.alias ? `${col.alias}.${jsonKey}` : `${col.field}.${jsonKey}`;
107
+ cols.push({
108
+ title: alias,
109
+ dataIndex: alias,
110
+ key: alias,
111
+ ellipsis: true,
112
+ render: (val: unknown) => (val != null ? String(val) : '-'),
113
+ });
114
+ }
115
+ } else {
116
+ const key = col.alias || col.field;
117
+ cols.push({
118
+ title: key,
119
+ dataIndex: key,
120
+ key,
121
+ ellipsis: true,
122
+ render: (val: unknown) => {
123
+ if (val == null) return '-';
124
+ if (typeof val === 'object') return JSON.stringify(val);
125
+ return String(val);
126
+ },
127
+ });
128
+ }
129
+ }
130
+ return cols;
131
+ }
132
+
133
+ if (this._data.length > 0) {
134
+ const firstRow = this._data[0];
135
+ return Object.keys(firstRow).map((key) => ({
136
+ title: key,
137
+ dataIndex: key,
138
+ key,
139
+ ellipsis: true,
140
+ render: (_val: unknown, record: Record<string, unknown>) => {
141
+ const val = record[key];
142
+ if (val == null) return '-';
143
+ if (typeof val === 'object') return JSON.stringify(val);
144
+ return String(val);
145
+ },
146
+ }));
147
+ }
148
+
149
+ return [];
150
+ }
151
+
152
+ // Only override renderComponent — base BlockModel.render() wraps this in BlockItemCard
153
+ // with title, description, heightMode, and settings toolbar automatically.
154
+ renderComponent() {
155
+ const columns = this.buildColumns();
156
+
157
+ return (
158
+ <>
159
+ {this._loading ? (
160
+ <div style={{ textAlign: 'center', padding: 40 }}>
161
+ <Spin />
162
+ </div>
163
+ ) : !this._data.length ? (
164
+ <Empty description={this.context.t('No data', { ns: 'plugin-block-cross-join' })} />
165
+ ) : (
166
+ <Table
167
+ dataSource={this._data}
168
+ columns={columns}
169
+ rowKey={(_, index) => String(index)}
170
+ size="middle"
171
+ scroll={{ x: 'max-content' }}
172
+ pagination={{
173
+ current: this._page,
174
+ pageSize: this._pageSize,
175
+ total: this._total,
176
+ showSizeChanger: true,
177
+ showTotal: (total) =>
178
+ this.context.t('Total {{count}} rows', { count: total, ns: 'plugin-block-cross-join' }),
179
+ onChange: (page, pageSize) => {
180
+ this._page = page;
181
+ this._pageSize = pageSize;
182
+ this.fetchData();
183
+ },
184
+ }}
185
+ />
186
+ )}
187
+ <CrossJoinConfigurator
188
+ visible={this._configuratorOpen}
189
+ onCancel={() => this.closeConfigurator()}
190
+ onSubmit={(config) => this.handleConfigSubmit(config)}
191
+ initialConfig={this.config}
192
+ />
193
+ </>
194
+ );
195
+ }
196
+ }
197
+
198
+ CrossJoinBlockModel.define({
199
+ label: tExpr('Cross Join', { ns: 'plugin-block-cross-join' }),
200
+ createModelOptions: {
201
+ use: 'CrossJoinBlockModel',
202
+ },
203
+ });
204
+
205
+ // Mapping opens from an explicit settings menu action, never from beforeRender.
206
+ // Title, description, block height, linkage rules, and remove are all inherited
207
+ // from BlockModel.registerFlow('cardSettings') automatically.
208
+ CrossJoinBlockModel.registerFlow({
209
+ key: 'crossJoinSettings',
210
+ title: tExpr('Cross Join settings', { ns: 'plugin-block-cross-join' }),
211
+ sort: -100,
212
+ manual: true,
213
+ steps: {},
214
+ });
215
+
216
+ CrossJoinBlockModel.registerExtraMenuItems((model, t) => [
217
+ {
218
+ key: 'cross-join-edit-mapping',
219
+ label: t('Edit mapping', { ns: 'plugin-block-cross-join' }),
220
+ sort: -100,
221
+ onClick: () => (model as CrossJoinBlockModel).openConfigurator(),
222
+ },
223
+ ]);