@gingkoo/pandora-metabase 0.0.18 → 0.0.20

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/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @gingkoo/pandora-metabase v0.0.18
2
+ * @gingkoo/pandora-metabase v0.0.20
3
3
  */
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
@@ -108,6 +108,140 @@ var EleComponentEnum;
108
108
  EleComponentEnum["select"] = "select";
109
109
  })(EleComponentEnum || (EleComponentEnum = {}));
110
110
 
111
+ const findIndex = (arr, item) => {
112
+ return arr.indexOf(item);
113
+ };
114
+ const getHelper = (list, item) => {
115
+ let types = list.map(v => v.type);
116
+ let curIndex = list.indexOf(item);
117
+ let leftTypes = types.slice(0, curIndex); // 当前元素上面的所有元素 (不包含自己)
118
+ let rightTypes = types.slice(curIndex + 1); // 当前元素下面的所有元素 (不包含自己)
119
+ let leftList = list.slice(0, curIndex);
120
+ let rightList = list.slice(curIndex + 1);
121
+ let ExistAboveGroupBy = false;
122
+ let ExistBelowGroupBy = false;
123
+ let prevTypes = [];
124
+ let nextTypes = [];
125
+ let prevList = [];
126
+ let nextList = [];
127
+ let prevGroupBy;
128
+ let nextGroupBy;
129
+ if (~leftTypes.indexOf(TypeEnum.summarize)) {
130
+ ExistAboveGroupBy = true;
131
+ let i = leftTypes.lastIndexOf(TypeEnum.summarize);
132
+ prevTypes = leftTypes.slice(i + 1);
133
+ prevList = leftList.slice(i + 1);
134
+ prevGroupBy = list[i];
135
+ }
136
+ if (~rightTypes.indexOf(TypeEnum.summarize)) {
137
+ ExistBelowGroupBy = true;
138
+ let i = rightTypes.indexOf(TypeEnum.summarize);
139
+ nextTypes = rightTypes.slice(0, i);
140
+ nextList = rightList.slice(0, i);
141
+ nextGroupBy = list[curIndex + i + 1];
142
+ }
143
+ return {
144
+ ExistAboveGroupBy,
145
+ ExistBelowGroupBy,
146
+ prevTypes,
147
+ nextTypes,
148
+ prevList,
149
+ nextList,
150
+ prevGroupBy,
151
+ nextGroupBy
152
+ };
153
+ };
154
+ // 获取子查询的字段
155
+ const getSubColumns = metaList => {
156
+ let obj = {
157
+ metaKey: -1,
158
+ type: TypeEnum.customColumn,
159
+ customColumn: [{
160
+ name: '',
161
+ // 用户起的别名
162
+ formula: '' // 公式}];
163
+ }]
164
+ };
165
+ let {
166
+ ExistAboveGroupBy,
167
+ prevList,
168
+ prevGroupBy
169
+ } = getHelper([...metaList, obj], obj);
170
+ let data;
171
+ if (ExistAboveGroupBy) {
172
+ let _data = {
173
+ table: prevGroupBy.alias,
174
+ alias: prevGroupBy.alias,
175
+ columns: []
176
+ };
177
+ if (prevGroupBy?.group?.length) {
178
+ _data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
179
+ return {
180
+ name_zh: v.quotes,
181
+ ...v,
182
+ name: v.quotes,
183
+ realName: v.sql?.split(' AS ')?.[1] || '',
184
+ // name_zh: '',
185
+ database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
186
+ special_type: '',
187
+ select: true
188
+ };
189
+ }));
190
+ }
191
+ if (prevGroupBy?.by?.length) {
192
+ _data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
193
+ return {
194
+ name_zh: v.quotes,
195
+ ...v,
196
+ name: v.quotes,
197
+ realName: v.sql?.split(' AS ')?.[1] || '',
198
+ // name_zh: '',
199
+ database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
200
+ special_type: '',
201
+ select: true
202
+ };
203
+ }));
204
+ }
205
+ data = [_data];
206
+ let joinData = prevList.filter(v => v.type === TypeEnum.joinData)
207
+ // @ts-ignore
208
+ .filter(v => v && v.table2.name);
209
+ if (joinData.length) {
210
+ data = data.concat(
211
+ // @ts-ignore
212
+ joinData.map(v => {
213
+ return {
214
+ alias: v.table2.alias,
215
+ table: v.table2.name,
216
+ columns: v.columns
217
+ };
218
+ }));
219
+ }
220
+ } else {
221
+ // @ts-ignore
222
+ data = metaList.slice().map(v => {
223
+ if (v.type === TypeEnum.data) {
224
+ return {
225
+ alias: v.table.alias,
226
+ table: v.table.name,
227
+ columns: v.columns
228
+ };
229
+ } else if (v.type === TypeEnum.joinData) {
230
+ return {
231
+ alias: v.table2.alias,
232
+ table: v.table2.name,
233
+ columns: v.columns
234
+ };
235
+ } else {
236
+ return {
237
+ table: null
238
+ };
239
+ }
240
+ }).filter(v => v.table);
241
+ }
242
+ return data;
243
+ };
244
+
111
245
  let metaKey = 1;
112
246
  const SummarizeAlias$1 = 'source';
113
247
  const useStore = () => {
@@ -202,7 +336,14 @@ const useStore = () => {
202
336
  if (v.table2?.datasourceId && v.columns.length < 1) {
203
337
  let newMeta = data.slice();
204
338
  fetchColumns(newMeta[i].table2, newMeta[i].table2.datasourceId, columns => {
205
- newMeta[i].columns = columns;
339
+ if (v.isSubquery) {
340
+ let newColumns = [];
341
+ const items = getSubColumns(v.subquery);
342
+ newColumns = items.flatMap(item => item.columns);
343
+ newMeta[i].columns = newColumns;
344
+ } else {
345
+ newMeta[i].columns = columns;
346
+ }
206
347
  setMeta(newMeta);
207
348
  });
208
349
  return {
@@ -213,7 +354,14 @@ const useStore = () => {
213
354
  if (v.table?.datasourceId && v.columns.length < 1) {
214
355
  let newMeta = data.slice();
215
356
  fetchColumns(newMeta[i].table, newMeta[i].table.datasourceId, columns => {
216
- newMeta[i].columns = columns;
357
+ if (v.isSubquery) {
358
+ let newColumns = [];
359
+ const items = getSubColumns(v.subquery);
360
+ newColumns = items.flatMap(item => item.columns);
361
+ newMeta[i].columns = newColumns;
362
+ } else {
363
+ newMeta[i].columns = columns;
364
+ }
217
365
  setMeta(newMeta);
218
366
  });
219
367
  return {
@@ -4813,50 +4961,6 @@ const Wrapper = ({
4813
4961
  });
4814
4962
  };
4815
4963
 
4816
- const findIndex = (arr, item) => {
4817
- return arr.indexOf(item);
4818
- };
4819
- const getHelper = (list, item) => {
4820
- let types = list.map(v => v.type);
4821
- let curIndex = list.indexOf(item);
4822
- let leftTypes = types.slice(0, curIndex); // 当前元素上面的所有元素 (不包含自己)
4823
- let rightTypes = types.slice(curIndex + 1); // 当前元素下面的所有元素 (不包含自己)
4824
- let leftList = list.slice(0, curIndex);
4825
- let rightList = list.slice(curIndex + 1);
4826
- let ExistAboveGroupBy = false;
4827
- let ExistBelowGroupBy = false;
4828
- let prevTypes = [];
4829
- let nextTypes = [];
4830
- let prevList = [];
4831
- let nextList = [];
4832
- let prevGroupBy;
4833
- let nextGroupBy;
4834
- if (~leftTypes.indexOf(TypeEnum.summarize)) {
4835
- ExistAboveGroupBy = true;
4836
- let i = leftTypes.lastIndexOf(TypeEnum.summarize);
4837
- prevTypes = leftTypes.slice(i + 1);
4838
- prevList = leftList.slice(i + 1);
4839
- prevGroupBy = list[i];
4840
- }
4841
- if (~rightTypes.indexOf(TypeEnum.summarize)) {
4842
- ExistBelowGroupBy = true;
4843
- let i = rightTypes.indexOf(TypeEnum.summarize);
4844
- nextTypes = rightTypes.slice(0, i);
4845
- nextList = rightList.slice(0, i);
4846
- nextGroupBy = list[curIndex + i + 1];
4847
- }
4848
- return {
4849
- ExistAboveGroupBy,
4850
- ExistBelowGroupBy,
4851
- prevTypes,
4852
- nextTypes,
4853
- prevList,
4854
- nextList,
4855
- prevGroupBy,
4856
- nextGroupBy
4857
- };
4858
- };
4859
-
4860
4964
  var IconSIzeEnum;
4861
4965
  (function (IconSIzeEnum) {
4862
4966
  IconSIzeEnum["SMALL"] = "small";
@@ -5279,95 +5383,6 @@ const JoinData = props => {
5279
5383
  })
5280
5384
  });
5281
5385
  }
5282
- function _getColumns(metaList) {
5283
- let obj = {
5284
- metaKey: -1,
5285
- type: TypeEnum.customColumn,
5286
- customColumn: [{
5287
- name: '',
5288
- // 用户起的别名
5289
- formula: '' // 公式}];
5290
- }]
5291
- };
5292
- let {
5293
- ExistAboveGroupBy,
5294
- prevList,
5295
- prevGroupBy
5296
- } = getHelper([...metaList, obj], obj);
5297
- let data;
5298
- if (ExistAboveGroupBy) {
5299
- let _data = {
5300
- table: prevGroupBy.alias,
5301
- alias: prevGroupBy.alias,
5302
- columns: []
5303
- };
5304
- if (prevGroupBy?.group?.length) {
5305
- _data.columns = _data.columns.concat(prevGroupBy.group.map(v => {
5306
- return {
5307
- name_zh: v.quotes,
5308
- ...v,
5309
- name: v.quotes,
5310
- realName: v.sql?.split(' AS ')?.[1] || '',
5311
- // name_zh: '',
5312
- database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
5313
- special_type: '',
5314
- select: true
5315
- };
5316
- }));
5317
- }
5318
- if (prevGroupBy?.by?.length) {
5319
- _data.columns = _data.columns.concat(prevGroupBy.by.map(v => {
5320
- return {
5321
- name_zh: v.quotes,
5322
- ...v,
5323
- name: v.quotes,
5324
- realName: v.sql?.split(' AS ')?.[1] || '',
5325
- // name_zh: '',
5326
- database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
5327
- special_type: '',
5328
- select: true
5329
- };
5330
- }));
5331
- }
5332
- data = [_data];
5333
- let joinData = prevList.filter(v => v.type === TypeEnum.joinData)
5334
- // @ts-ignore
5335
- .filter(v => v && v.table2.name);
5336
- if (joinData.length) {
5337
- data = data.concat(
5338
- // @ts-ignore
5339
- joinData.map(v => {
5340
- return {
5341
- alias: v.table2.alias,
5342
- table: v.table2.name,
5343
- columns: v.columns
5344
- };
5345
- }));
5346
- }
5347
- } else {
5348
- // @ts-ignore
5349
- data = metaList.slice(0, index).map(v => {
5350
- if (v.type === TypeEnum.data) {
5351
- return {
5352
- alias: v.table.alias,
5353
- table: v.table.name,
5354
- columns: v.columns
5355
- };
5356
- } else if (v.type === TypeEnum.joinData) {
5357
- return {
5358
- alias: v.table2.alias,
5359
- table: v.table2.name,
5360
- columns: v.columns
5361
- };
5362
- } else {
5363
- return {
5364
- table: null
5365
- };
5366
- }
5367
- }).filter(v => v.table);
5368
- }
5369
- return data;
5370
- }
5371
5386
  function selectTable(e) {
5372
5387
  let value = {
5373
5388
  name: meta.table2.name,
@@ -5739,6 +5754,7 @@ const JoinData = props => {
5739
5754
  let oldList = cloneDeep(newMeta[index].subquery);
5740
5755
  let o = Modal2.openModal({
5741
5756
  title: __('SqlQueryBuilder.subquery'),
5757
+ transparentMask: true,
5742
5758
  content: jsx(Fragment, {
5743
5759
  children: jsx(SqlVisionBuilder, {
5744
5760
  ...other,
@@ -5759,11 +5775,11 @@ const JoinData = props => {
5759
5775
  column: '',
5760
5776
  column_id: ''
5761
5777
  };
5762
- const items = _getColumns(newList);
5778
+ const items = getSubColumns(newList);
5763
5779
  const newColumns = items.flatMap(item => item.columns);
5764
5780
  newMeta[index].columns = newColumns;
5765
5781
  newMeta[index].expressions = [];
5766
- store.setPreData(newMeta);
5782
+ store.setMeta(newMeta);
5767
5783
  o.close();
5768
5784
  } catch (e) {
5769
5785
  console.warn(e);