@gingkoo/pandora-metabase 1.0.0-alpha.25 → 1.0.0-alpha.26

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 v1.0.0-alpha.25
2
+ * @gingkoo/pandora-metabase v1.0.0-alpha.26
3
3
  */
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
@@ -154,6 +154,36 @@ var EleComponentEnum;
154
154
  EleComponentEnum["select"] = "select";
155
155
  })(EleComponentEnum || (EleComponentEnum = {}));
156
156
 
157
+ //获取指定名称的cookie值
158
+ function getCookie(name) {
159
+ // (^| )name=([^;]*)(;|$),match[0]为与整个正则表达式匹配的字符串,match[i]为正则表达式捕获数组相匹配的数组;
160
+ var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
161
+ if (arr != null) {
162
+ console.log(arr);
163
+ return arr[2];
164
+ }
165
+ return null;
166
+ }
167
+
168
+ const locales = {};
169
+ const activeLocale = getCookie('LOCALE') || 'zh';
170
+ const isEn = activeLocale === 'en';
171
+ const register = (name, data) => {
172
+ if (name in locales) {
173
+ console.warn(`[i18n] ${name} has been registered`);
174
+ } else {
175
+ locales[name] = data;
176
+ }
177
+ };
178
+ const __ = name => {
179
+ if (activeLocale in locales) {
180
+ return locales[activeLocale][name] || '';
181
+ } else {
182
+ console.warn(`[i18n] locale not found`);
183
+ return '';
184
+ }
185
+ };
186
+
157
187
  // import { SummarizeAlias } from './index';
158
188
  const SummarizeAlias$1 = 'source';
159
189
  const NUMBER_GROUP$1 = [SQL_COLUMN_TYPE.FLOAT, SQL_COLUMN_TYPE.LONG, SQL_COLUMN_TYPE.CURRENCY];
@@ -649,7 +679,9 @@ const getSubColumns = metaList => {
649
679
  return {
650
680
  name_zh: v.quotes,
651
681
  ...v,
652
- name: v.fieldAlias,
682
+ name: v.fieldAlias || v.name,
683
+ fieldAlias: '',
684
+ fieldUuid: uuidv4('field'),
653
685
  realName: v.sql?.split(' AS ')?.[1] || '',
654
686
  // name_zh: '',
655
687
  database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
@@ -663,7 +695,9 @@ const getSubColumns = metaList => {
663
695
  return {
664
696
  name_zh: v.quotes,
665
697
  ...v,
666
- name: v.fieldAlias,
698
+ name: v.fieldAlias || v.name,
699
+ fieldAlias: '',
700
+ fieldUuid: uuidv4('field'),
667
701
  realName: v.sql?.split(' AS ')?.[1] || '',
668
702
  // name_zh: '',
669
703
  database_type: v?.database_type || SQL_COLUMN_TYPE.FLOAT,
@@ -680,10 +714,18 @@ const getSubColumns = metaList => {
680
714
  data = data.concat(
681
715
  // @ts-ignore
682
716
  joinData.map(v => {
717
+ const columns = v.columns.map(column => {
718
+ return {
719
+ ...column,
720
+ name: column.fieldAlias || column.name,
721
+ fieldAlias: '',
722
+ fieldUuid: uuidv4('field')
723
+ };
724
+ });
683
725
  return {
684
726
  alias: v.table2.alias,
685
727
  table: v.table2.name,
686
- columns: v.columns
728
+ columns: columns
687
729
  };
688
730
  }));
689
731
  }
@@ -691,16 +733,49 @@ const getSubColumns = metaList => {
691
733
  // @ts-ignore
692
734
  data = metaList.slice().map(v => {
693
735
  if (v.type === TypeEnum.data) {
736
+ const columns = v.columns.map(column => {
737
+ return {
738
+ ...column,
739
+ name: column.fieldAlias || column.name,
740
+ fieldAlias: '',
741
+ fieldUuid: uuidv4('field')
742
+ };
743
+ });
694
744
  return {
695
745
  alias: v.table.alias,
696
746
  table: v.table.name,
697
- columns: v.columns
747
+ columns: columns
698
748
  };
699
749
  } else if (v.type === TypeEnum.joinData) {
750
+ const columns = v.columns.map(column => {
751
+ return {
752
+ ...column,
753
+ name: column.fieldAlias || column.name,
754
+ fieldAlias: '',
755
+ fieldUuid: uuidv4('field')
756
+ };
757
+ });
700
758
  return {
701
759
  alias: v.table2.alias,
702
760
  table: v.table2.name,
703
- columns: v.columns
761
+ columns: columns
762
+ };
763
+ } else if (v.type === TypeEnum.customColumn) {
764
+ const {
765
+ customColumn
766
+ } = v;
767
+ const columns = customColumn.map(v => {
768
+ return {
769
+ name_zh: __('SqlQueryBuilder.customColumn'),
770
+ name: v.name,
771
+ fieldAlias: '',
772
+ fieldUuid: uuidv4('field')
773
+ };
774
+ });
775
+ return {
776
+ columns: columns,
777
+ alias: '',
778
+ table: __('SqlQueryBuilder.customColumn')
704
779
  };
705
780
  } else {
706
781
  return {
@@ -934,6 +1009,9 @@ const changeFieldAlias = (list, curObj) => {
934
1009
  }
935
1010
  });
936
1011
  }
1012
+ return {
1013
+ ...v
1014
+ };
937
1015
  }) || [];
938
1016
  };
939
1017
  function splitByUnion(data) {
@@ -1574,36 +1652,6 @@ const useStore = () => {
1574
1652
  };
1575
1653
  };
1576
1654
 
1577
- //获取指定名称的cookie值
1578
- function getCookie(name) {
1579
- // (^| )name=([^;]*)(;|$),match[0]为与整个正则表达式匹配的字符串,match[i]为正则表达式捕获数组相匹配的数组;
1580
- var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
1581
- if (arr != null) {
1582
- console.log(arr);
1583
- return arr[2];
1584
- }
1585
- return null;
1586
- }
1587
-
1588
- const locales = {};
1589
- const activeLocale = getCookie('LOCALE') || 'zh';
1590
- const isEn = activeLocale === 'en';
1591
- const register = (name, data) => {
1592
- if (name in locales) {
1593
- console.warn(`[i18n] ${name} has been registered`);
1594
- } else {
1595
- locales[name] = data;
1596
- }
1597
- };
1598
- const __ = name => {
1599
- if (activeLocale in locales) {
1600
- return locales[activeLocale][name] || '';
1601
- } else {
1602
- console.warn(`[i18n] locale not found`);
1603
- return '';
1604
- }
1605
- };
1606
-
1607
1655
  register('en', {
1608
1656
  'data.pleaseSelectDataTable': 'please select data table',
1609
1657
  'data.calculatingNow': 'calculating now...',
@@ -2216,13 +2264,13 @@ const LeftJoinIcon = ({
2216
2264
  })
2217
2265
  });
2218
2266
  const InnerJoinIcon = ({
2219
- width: _width10 = 32,
2220
- height: _height10 = 32,
2267
+ width: _width0 = 32,
2268
+ height: _height0 = 32,
2221
2269
  style
2222
2270
  }) => jsx("svg", {
2223
2271
  viewBox: '0 0 32 32',
2224
- width: _width10,
2225
- height: _height10,
2272
+ width: _width0,
2273
+ height: _height0,
2226
2274
  fill: 'currentcolor',
2227
2275
  role: 'img',
2228
2276
  "aria-label": 'join_inner icon',
@@ -2232,13 +2280,13 @@ const InnerJoinIcon = ({
2232
2280
  })
2233
2281
  });
2234
2282
  const UpArrowIcon = ({
2235
- width: _width11 = 16,
2236
- height: _height11 = 17
2283
+ width: _width1 = 16,
2284
+ height: _height1 = 17
2237
2285
  }) => jsx("svg", {
2238
2286
  className: 'sort-arrow',
2239
2287
  viewBox: '0 0 32 34',
2240
- width: _width11,
2241
- height: _height11,
2288
+ width: _width1,
2289
+ height: _height1,
2242
2290
  fill: 'currentcolor',
2243
2291
  role: 'img',
2244
2292
  "aria-label": 'arrow_up icon',
@@ -2247,13 +2295,13 @@ const UpArrowIcon = ({
2247
2295
  })
2248
2296
  });
2249
2297
  const DownArrowIcon = ({
2250
- width: _width12 = 16,
2251
- height: _height12 = 17
2298
+ width: _width10 = 16,
2299
+ height: _height10 = 17
2252
2300
  }) => jsx("svg", {
2253
2301
  className: 'sort-arrow',
2254
2302
  viewBox: '0 0 32 34',
2255
- width: _width12,
2256
- height: _height12,
2303
+ width: _width10,
2304
+ height: _height10,
2257
2305
  fill: 'currentcolor',
2258
2306
  role: 'img',
2259
2307
  "aria-label": 'arrow_down icon',
@@ -2262,13 +2310,13 @@ const DownArrowIcon = ({
2262
2310
  })
2263
2311
  });
2264
2312
  const CloseIcon = ({
2265
- width: _width13 = 16,
2266
- height: _height13 = 16
2313
+ width: _width11 = 16,
2314
+ height: _height11 = 16
2267
2315
  }) => jsx("svg", {
2268
2316
  className: 'closeIcon',
2269
2317
  viewBox: '0 0 32 32',
2270
- width: _width13,
2271
- height: _height13,
2318
+ width: _width11,
2319
+ height: _height11,
2272
2320
  fill: 'currentcolor',
2273
2321
  role: 'img',
2274
2322
  "aria-label": 'close icon',
@@ -2277,12 +2325,12 @@ const CloseIcon = ({
2277
2325
  })
2278
2326
  });
2279
2327
  const AddIcon = ({
2280
- width: _width14 = 16,
2281
- height: _height14 = 16
2328
+ width: _width12 = 16,
2329
+ height: _height12 = 16
2282
2330
  }) => jsx("svg", {
2283
2331
  viewBox: '0 0 32 32',
2284
- width: _width14,
2285
- height: _height14,
2332
+ width: _width12,
2333
+ height: _height12,
2286
2334
  fill: 'currentcolor',
2287
2335
  role: 'img',
2288
2336
  "aria-label": 'add icon',
@@ -2291,12 +2339,12 @@ const AddIcon = ({
2291
2339
  })
2292
2340
  });
2293
2341
  const TableIcon = ({
2294
- width: _width15 = 18,
2295
- height: _height15 = 18
2342
+ width: _width13 = 18,
2343
+ height: _height13 = 18
2296
2344
  }) => jsx("svg", {
2297
2345
  viewBox: '0 0 32 32',
2298
- width: _width15,
2299
- height: _height15,
2346
+ width: _width13,
2347
+ height: _height13,
2300
2348
  fill: 'currentcolor',
2301
2349
  role: 'img',
2302
2350
  "aria-label": 'table2 icon',
@@ -2305,12 +2353,12 @@ const TableIcon = ({
2305
2353
  })
2306
2354
  });
2307
2355
  const SearchIcon = ({
2308
- width: _width16 = 16,
2309
- height: _height16 = 16
2356
+ width: _width14 = 16,
2357
+ height: _height14 = 16
2310
2358
  }) => jsx("svg", {
2311
2359
  viewBox: '0 0 32 32',
2312
- width: _width16,
2313
- height: _height16,
2360
+ width: _width14,
2361
+ height: _height14,
2314
2362
  fill: 'currentcolor',
2315
2363
  role: 'img',
2316
2364
  "aria-label": 'search icon',
@@ -3695,7 +3743,6 @@ function generateTrigger(PortalComponent) {
3695
3743
  borderRadius: 6
3696
3744
  },
3697
3745
  onClick: e => this.props.closable && e.stopPropagation(),
3698
- onMouseDown: e => e.stopPropagation(),
3699
3746
  children: /*#__PURE__*/React.cloneElement(this.props.children, {
3700
3747
  key: posKey,
3701
3748
  didUpdate: this.didUpdate
@@ -3825,10 +3872,14 @@ const SelectColumn = ({
3825
3872
  newMetaList = changeFieldAlias(newMetaList, newColumns[i]);
3826
3873
  store.setMeta(newMetaList, groupIndex);
3827
3874
  onSelect(newColumns);
3828
- store.setClosable(true);
3875
+ setTimeout(() => {
3876
+ store.setClosable(true);
3877
+ }, 0);
3829
3878
  },
3830
3879
  onCancel: () => {
3831
- store.setClosable(true);
3880
+ setTimeout(() => {
3881
+ store.setClosable(true);
3882
+ }, 0);
3832
3883
  }
3833
3884
  });
3834
3885
  };
@@ -3928,10 +3979,10 @@ const SelectJoinColumn = ({
3928
3979
  }) => {
3929
3980
  const store = useStore$1();
3930
3981
  const [value, setValue] = useState(_value); // 当前选择的字段
3931
- const [curTable, setCurTable] = useState(_value.alias); // 当前选择的表
3982
+ const [curTable, setCurTable] = useState(_value.tableUuid); // 当前选择的表
3932
3983
  const [curColumn, setCurColumn] = useState(_value.name); // 当前选择的字段
3933
3984
  const [tableList, setTableList] = useState(_data.map((v, i) => {
3934
- let open = !i && !_value.alias ? true : v.alias === _value.alias; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3985
+ let open = !i && !_value.tableUuid ? true : v.tableUuid === _value.tableUuid; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3935
3986
  return {
3936
3987
  ...v,
3937
3988
  open,
@@ -3941,12 +3992,12 @@ const SelectJoinColumn = ({
3941
3992
  }));
3942
3993
  useEffect(() => {
3943
3994
  setValue(_value);
3944
- setCurTable(_value.alias);
3995
+ setCurTable(_value.tableUuid);
3945
3996
  setCurColumn(_value.name);
3946
3997
  }, [_value]);
3947
3998
  useEffect(() => {
3948
3999
  setTableList(_data.map((v, i) => {
3949
- let open = !i && !_value.alias ? true : v.alias === _value.alias; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
4000
+ let open = !i && !_value.tableUuid ? true : v.tableUuid === _value.tableUuid; // TODO.这里只判断表名相等 没有用了 因为表上面加了一层数据源 先这样吧
3950
4001
  return {
3951
4002
  ...v,
3952
4003
  open,
@@ -4006,12 +4057,12 @@ const SelectJoinColumn = ({
4006
4057
  if (open) {
4007
4058
  setTableList(newTables.map(v => ({
4008
4059
  ...v,
4009
- open: tableAlias === v.alias ? false : v.open
4060
+ open: tableUuid === v.tableUuid ? false : v.open
4010
4061
  })));
4011
4062
  } else {
4012
4063
  setTableList(newTables.map(v => ({
4013
4064
  ...v,
4014
- open: tableAlias === v.alias || v.alias === SummarizeAlias$1
4065
+ open: tableUuid === v.tableUuid || v.alias === SummarizeAlias$1
4015
4066
  })));
4016
4067
  }
4017
4068
  },
@@ -5714,7 +5765,9 @@ const TableData = props => {
5714
5765
  }
5715
5766
  newMetaList.subquery = newList;
5716
5767
  newMetaList.table = {
5717
- ...newList[0].table
5768
+ ...newList[0].table,
5769
+ alias: '',
5770
+ tableUuid: uuidv4('table')
5718
5771
  };
5719
5772
  const items = getSubColumns(newList);
5720
5773
  const newColumns = items.flatMap(item => item.columns);
@@ -6383,14 +6436,14 @@ const JoinData = props => {
6383
6436
  }
6384
6437
  newMeta[index].subquery = newList;
6385
6438
  newMeta[index].table2 = {
6386
- ...newList[0].table,
6387
- fieldAlias: '',
6388
- fieldUuid: ''
6439
+ ...newList[0].table
6389
6440
  };
6390
6441
  const items = getSubColumns(newList);
6391
6442
  const newColumns = items.flatMap(item => item.columns);
6392
6443
  newMeta[index].columns = newColumns;
6393
6444
  newMeta[index].expressions = [];
6445
+ // 关联表变了 下面模块全部删除
6446
+ newMeta = newMeta.filter((v, i) => i <= index);
6394
6447
  store.setMeta(newMeta, groupIndex);
6395
6448
  o.close();
6396
6449
  } catch (e) {
@@ -7682,7 +7735,7 @@ const Filter = props => {
7682
7735
  showNotExists(i, '');
7683
7736
  return;
7684
7737
  }
7685
- let data = [...getColumns(), ...cloneDeep(notExistsColumns)];
7738
+ let data = [...getColumns(), ...cloneDeep(notExistsColumns || [])];
7686
7739
  store.setPopup({
7687
7740
  visible: true,
7688
7741
  node: e.currentTarget,
@@ -7700,8 +7753,8 @@ const Filter = props => {
7700
7753
  function handleAdd(e) {
7701
7754
  let node = e.currentTarget;
7702
7755
  let newMeta = store.metaList[groupIndex].list.slice();
7703
- let data = getColumns();
7704
- let _index = node.getAttribute('v-index');
7756
+ let data = [...getColumns(), ...cloneDeep(notExistsColumns || [])];
7757
+ let _index = Number(node.getAttribute('v-index'));
7705
7758
  let _type = node.getAttribute('v-type');
7706
7759
  let value = {
7707
7760
  table: '',
@@ -7737,15 +7790,16 @@ const Filter = props => {
7737
7790
  content: jsx(SelectFilter, {
7738
7791
  data: data,
7739
7792
  value: value,
7740
- onChange: data => {
7793
+ onChange: val => {
7741
7794
  if (_type) {
7742
7795
  if (_type === 'before') {
7743
- newMeta[index].filter.splice(_index, 0, data);
7796
+ newMeta[index].filter.splice(_index, 0, val);
7744
7797
  } else {
7745
- newMeta[index].filter.splice(_index + 1, 0, data);
7798
+ console.log('🚀 ~ ', newMeta[index].filter);
7799
+ newMeta[index].filter.splice(_index + 1, 0, val);
7746
7800
  }
7747
7801
  } else {
7748
- newMeta[index].filter.push(data);
7802
+ newMeta[index].filter.push(val);
7749
7803
  }
7750
7804
  store.setMeta(newMeta, groupIndex);
7751
7805
  closePopup();