@gingkoo/pandora-metabase 1.0.143 → 1.0.145

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,9 +1,11 @@
1
1
  import './index.less';
2
- import { MetaData_ColumnsType } from '../../../store/types';
2
+ import { MetaData_ColumnsType, MetaData_TableType } from '../../../store/types';
3
3
  interface PropsType {
4
4
  data: MetaData_ColumnsType[];
5
+ table?: Partial<MetaData_TableType>;
6
+ metaIndex?: number;
5
7
  groupIndex: number;
6
8
  onChange: (record: MetaData_ColumnsType[], newMetaList?: any[]) => void;
7
9
  }
8
- declare const SelectColumn: ({ data, groupIndex, onChange }: PropsType) => import("react/jsx-runtime").JSX.Element;
10
+ declare const SelectColumn: ({ data, table, metaIndex, groupIndex, onChange }: PropsType) => import("react/jsx-runtime").JSX.Element;
9
11
  export default SelectColumn;
@@ -16,6 +16,7 @@ var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
16
16
  var _classnames = _interopRequireDefault(require("classnames"));
17
17
  var _pandora = require("@gingkoo/pandora");
18
18
  var _types = require("../../../store/types");
19
+ var _enum = require("../../../store/enum");
19
20
  var _locale = require("../../../locale");
20
21
  var _icons = require("../../icons");
21
22
  var _useProvider = require("../../../hooks/use-provider");
@@ -24,6 +25,8 @@ var _utils = require("../../../utils");
24
25
  var SelectColumn = function SelectColumn(_ref) {
25
26
  var _ref$data = _ref.data,
26
27
  data = _ref$data === void 0 ? [] : _ref$data,
28
+ table = _ref.table,
29
+ metaIndex = _ref.metaIndex,
27
30
  groupIndex = _ref.groupIndex,
28
31
  onChange = _ref.onChange;
29
32
  var _useState = (0, _react.useState)([]),
@@ -104,6 +107,7 @@ var SelectColumn = function SelectColumn(_ref) {
104
107
  }
105
108
  var onChangeFieldAlias = function onChangeFieldAlias(val, i) {
106
109
  var fieldAlias = val || '';
110
+ var currentColumn = columns[i];
107
111
  _pandora.Modal.confirm({
108
112
  title: (0, _locale.__)('SqlQueryBuilder.alias'),
109
113
  content: (0, _jsxRuntime.jsx)(_pandora.Input, {
@@ -114,7 +118,7 @@ var SelectColumn = function SelectColumn(_ref) {
114
118
  }),
115
119
  onOk: function () {
116
120
  var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
117
- var newColumns, newMetaList;
121
+ var newColumns, newMetaList, changedColumn, targetMetaIndex, targetMeta;
118
122
  return _regenerator["default"].wrap(function (_context) {
119
123
  while (1) switch (_context.prev = _context.next) {
120
124
  case 0:
@@ -129,9 +133,29 @@ var SelectColumn = function SelectColumn(_ref) {
129
133
  newMetaList = store.metaList[groupIndex].list.slice();
130
134
  newColumns[i].fieldAlias = fieldAlias;
131
135
  newColumns[i].fieldUuid = newColumns[i].fieldUuid || (0, _helper.uuidv4)('field');
132
- newMetaList = (0, _utils.changeFieldAlias)(newMetaList, newColumns[i]);
136
+ changedColumn = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, newColumns[i]), {}, {
137
+ datasourceId: newColumns[i].datasourceId || (table === null || table === void 0 ? void 0 : table.datasourceId) || '',
138
+ datasourceName: newColumns[i].datasourceName || (table === null || table === void 0 ? void 0 : table.datasourceName) || '',
139
+ tableId: newColumns[i].tableId || (table === null || table === void 0 ? void 0 : table.id) || '',
140
+ tableUuid: newColumns[i].tableUuid || (table === null || table === void 0 ? void 0 : table.tableUuid) || '',
141
+ table: (table === null || table === void 0 ? void 0 : table.name) || ''
142
+ });
143
+ newColumns = originList.map(function (item) {
144
+ return (0, _helper.isSameColumnByIdFirst)(item, currentColumn) ? changedColumn : item;
145
+ });
146
+ newMetaList = (0, _utils.changeFieldAlias)(newMetaList, changedColumn);
147
+ targetMetaIndex = typeof metaIndex === 'number' ? metaIndex : newMetaList.findIndex(function (item) {
148
+ return item.type === _enum.TypeEnum.data;
149
+ });
150
+ targetMeta = newMetaList[targetMetaIndex];
151
+ if ((targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.type) === _enum.TypeEnum.data) {
152
+ targetMeta.columns = newColumns;
153
+ }
154
+ if ((targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.type) === _enum.TypeEnum.joinData) {
155
+ targetMeta.columns = newColumns;
156
+ }
133
157
  store.setMeta(newMetaList, groupIndex, {
134
- obj: newColumns[i],
158
+ obj: changedColumn,
135
159
  type: _types.ChangeType.fieldAlias
136
160
  });
137
161
  onSelect(newColumns, newMetaList, true);
@@ -85,7 +85,7 @@ var SelectPermissionTable = function SelectPermissionTable(_ref) {
85
85
  })]
86
86
  })
87
87
  })
88
- }, (0, _helper.getTableIdFirstKey)(v));
88
+ }, (0, _helper.getTableIdNameKey)(v));
89
89
  })]
90
90
  })
91
91
  })
@@ -351,7 +351,7 @@ var SelectTable = function SelectTable(_ref) {
351
351
  })]
352
352
  })
353
353
  })
354
- }, (0, _helper.getTableIdFirstKey)(tableValue));
354
+ }, (0, _helper.getTableIdNameKey)(tableValue));
355
355
  }))]
356
356
  }, table.datasourceId);
357
357
  })]
@@ -473,7 +473,7 @@ var SelectTable = function SelectTable(_ref) {
473
473
  })]
474
474
  })
475
475
  })
476
- }, (0, _helper.getTableIdFirstKey)(tableValue));
476
+ }, (0, _helper.getTableIdNameKey)(tableValue));
477
477
  })]
478
478
  })]
479
479
  })
@@ -112,7 +112,7 @@ var JoinData = function JoinData(props) {
112
112
  case 2:
113
113
  tables = _context.sent;
114
114
  if (!(tables !== null && tables !== void 0 && tables.some(function (v) {
115
- return (0, _helper.isSameTableByIdFirst)(tableInfo, v);
115
+ return (0, _helper.isSameTableByIdName)(tableInfo, v);
116
116
  }))) {
117
117
  setIsDel(true);
118
118
  } else {
@@ -374,6 +374,8 @@ var JoinData = function JoinData(props) {
374
374
  node: e.currentTarget,
375
375
  content: (0, _jsxRuntime.jsx)(_dialog.SelectColumn, {
376
376
  data: columns,
377
+ table: meta.table2,
378
+ metaIndex: index,
377
379
  groupIndex: groupIndex,
378
380
  onChange: function onChange(data, newMetaList) {
379
381
  var _newMetaList = newMetaList || store.metaList[groupIndex].list.slice();
@@ -501,7 +503,7 @@ var JoinData = function JoinData(props) {
501
503
  value: value,
502
504
  onChange: function onChange(data) {
503
505
  var tableName = data.name;
504
- if (!(0, _helper.isSameTableByIdFirst)(meta.table2, data)) {
506
+ if (!(0, _helper.isSameTableByIdName)(meta.table2, data)) {
505
507
  var _store$preProps;
506
508
  var newMeta = (0, _cloneDeep["default"])(store.metaList[groupIndex].list);
507
509
  var aliasMetaList = newMeta.filter(function (_, i) {
@@ -96,7 +96,7 @@ var PermissionTable = function PermissionTable(props) {
96
96
  data: data,
97
97
  value: meta.table,
98
98
  onChange: function onChange(data) {
99
- if (!(0, _helper.isSameTableByIdFirst)(meta.table, data)) {
99
+ if (!(0, _helper.isSameTableByIdName)(meta.table, data)) {
100
100
  meta.table = data;
101
101
  }
102
102
  store.setPopup({
@@ -62,7 +62,7 @@ var TableData = function TableData(props) {
62
62
  case 2:
63
63
  tables = _context.sent;
64
64
  if (!(tables !== null && tables !== void 0 && tables.some(function (v) {
65
- return (0, _helper.isSameTableByIdFirst)(tableInfo, v);
65
+ return (0, _helper.isSameTableByIdName)(tableInfo, v);
66
66
  }))) {
67
67
  setIsDel(true);
68
68
  } else {
@@ -93,7 +93,7 @@ var TableData = function TableData(props) {
93
93
  sourceTable: store.sourceTable || [],
94
94
  value: meta.table,
95
95
  onChange: function onChange(data) {
96
- if (!(0, _helper.isSameTableByIdFirst)(meta.table, data)) {
96
+ if (!(0, _helper.isSameTableByIdName)(meta.table, data)) {
97
97
  var _store$preProps;
98
98
  var newMetaList = store.metaList[groupIndex].list.slice()[0];
99
99
  newMetaList.table = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, data), {}, {
@@ -125,6 +125,8 @@ var TableData = function TableData(props) {
125
125
  node: e.currentTarget || e.target,
126
126
  content: (0, _jsxRuntime.jsx)(_dialog.SelectColumn, {
127
127
  groupIndex: groupIndex,
128
+ table: meta.table,
129
+ metaIndex: 0,
128
130
  data: columns,
129
131
  onChange: function onChange(data, newMetaList) {
130
132
  var _newMetaList = newMetaList || store.metaList[groupIndex].list.slice();
@@ -569,6 +569,8 @@ var useStore = function useStore() {
569
569
  _metaList,
570
570
  prevMeta,
571
571
  newMeta,
572
+ oldData,
573
+ newData,
572
574
  isChange,
573
575
  _args9 = arguments;
574
576
  return _regenerator["default"].wrap(function (_context9) {
@@ -588,10 +590,12 @@ var useStore = function useStore() {
588
590
  }
589
591
  return _context9.abrupt("return");
590
592
  case 1:
593
+ oldData = (0, _utils.splitByUnion)(prevMeta);
594
+ newData = (0, _utils.splitByUnion)(newMeta);
591
595
  _context9.next = 2;
592
- return fetchChangeFn.current((0, _utils.splitByUnion)(newMeta), changeObj, {
596
+ return fetchChangeFn.current(oldData, changeObj, {
593
597
  isExit: isExit
594
- });
598
+ }, newData);
595
599
  case 2:
596
600
  isChange = _context9.sent;
597
601
  if (isChange === false) {
@@ -59,10 +59,10 @@ export interface MetabaseProps {
59
59
  groupByEnableAlias?: boolean;
60
60
  isSelectFields?: boolean;
61
61
  tableFlat?: boolean;
62
- onChange?: (newData: MetaListType[], curData: {
62
+ onChange?: (oldData: MetaListType[], curData: {
63
63
  data: any;
64
64
  type: ChangeType;
65
- }, options: FetchOptions) => Promise<void | Boolean>;
65
+ }, options: FetchOptions, newData: MetaListType[]) => Promise<void | Boolean>;
66
66
  copyType?: (FormulaTypeEnum | string)[];
67
67
  metabaseCopy?: boolean;
68
68
  moduleDiff?: boolean;
@@ -2,6 +2,7 @@ import type { MetaListType } from '../store/types';
2
2
  export declare const isSameTableByIdName: (left?: any, right?: any) => boolean;
3
3
  export declare const isSameColumnByIdName: (left?: any, right?: any) => boolean;
4
4
  export declare const getTableIdFirstKey: (table?: any) => string;
5
+ export declare const getTableIdNameKey: (table?: any) => string;
5
6
  export declare const isSameTableByIdFirst: (left?: any, right?: any) => boolean;
6
7
  export declare const getColumnIdFirstKey: (column?: any) => string;
7
8
  export declare const isSameColumnByIdFirst: (left?: any, right?: any) => boolean;
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.uuidv4 = exports.throttle = exports.sleep = exports.replaceTpl = exports.mobx2Object = exports.mergeNameAlias = exports.isSameTableByIdName = exports.isSameTableByIdFirst = exports.isSameColumnByIdName = exports.isSameColumnByIdFirst = exports.getUrlParams = exports.getTableIdFirstKey = exports.getScreenInfo = exports.getColumnIdFirstKey = exports.getAlias = exports.fullScreen = exports.flatArray = exports.exitFullscreen = exports.debounce = void 0;
7
+ exports.uuidv4 = exports.throttle = exports.sleep = exports.replaceTpl = exports.mobx2Object = exports.mergeNameAlias = exports.isSameTableByIdName = exports.isSameTableByIdFirst = exports.isSameColumnByIdName = exports.isSameColumnByIdFirst = exports.getUrlParams = exports.getTableIdNameKey = exports.getTableIdFirstKey = exports.getScreenInfo = exports.getColumnIdFirstKey = exports.getAlias = exports.fullScreen = exports.flatArray = exports.exitFullscreen = exports.debounce = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
9
9
  var _enum = require("../store/enum");
10
10
  var normalizeId = function normalizeId(val) {
@@ -59,6 +59,18 @@ var getTableIdFirstKey = exports.getTableIdFirstKey = function getTableIdFirstKe
59
59
  var tableAlias = normalizeId(table.alias || table.tableAlias);
60
60
  return tableName ? "".concat(datasourceId, "|name:").concat(tableName, "|alias:").concat(tableAlias) : datasourceId;
61
61
  };
62
+ var getTableIdNameKey = exports.getTableIdNameKey = function getTableIdNameKey() {
63
+ var table = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
+ var datasourceId = normalizeId(table.datasourceId);
65
+ var tableId = normalizeId(table.id || table.tableId);
66
+ var tableName = normalizeId(table.name || table.tableName || table.table);
67
+ var tableAlias = normalizeId(table.alias || table.tableAlias);
68
+ if (tableId || tableName) {
69
+ return "".concat(datasourceId, "|id:").concat(tableId, "|name:").concat(tableName, "|alias:").concat(tableAlias);
70
+ }
71
+ var tableUuid = normalizeId(table.tableUuid);
72
+ return tableUuid ? "".concat(datasourceId, "|uuid:").concat(tableUuid) : datasourceId;
73
+ };
62
74
  var isSameTableByIdFirst = exports.isSameTableByIdFirst = function isSameTableByIdFirst() {
63
75
  var left = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
76
  var right = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -1,9 +1,11 @@
1
1
  import './index.less';
2
- import { MetaData_ColumnsType } from '../../../store/types';
2
+ import { MetaData_ColumnsType, MetaData_TableType } from '../../../store/types';
3
3
  interface PropsType {
4
4
  data: MetaData_ColumnsType[];
5
+ table?: Partial<MetaData_TableType>;
6
+ metaIndex?: number;
5
7
  groupIndex: number;
6
8
  onChange: (record: MetaData_ColumnsType[], newMetaList?: any[]) => void;
7
9
  }
8
- declare const SelectColumn: ({ data, groupIndex, onChange }: PropsType) => import("react/jsx-runtime").JSX.Element;
10
+ declare const SelectColumn: ({ data, table, metaIndex, groupIndex, onChange }: PropsType) => import("react/jsx-runtime").JSX.Element;
9
11
  export default SelectColumn;
@@ -9,6 +9,7 @@ import cloneDeep from 'lodash/cloneDeep';
9
9
  import cx from 'classnames';
10
10
  import { Button, Modal, Input, Tooltip, Toast } from '@gingkoo/pandora';
11
11
  import { ChangeType } from '../../../store/types';
12
+ import { TypeEnum } from '../../../store/enum';
12
13
  import { __ } from '../../../locale';
13
14
  import { NotSelectIcon, SelectIcon } from '../../icons';
14
15
  import { useStore } from '../../../hooks/use-provider';
@@ -18,6 +19,8 @@ import { SearchIcon } from '../../icons';
18
19
  var SelectColumn = function SelectColumn(_ref) {
19
20
  var _ref$data = _ref.data,
20
21
  data = _ref$data === void 0 ? [] : _ref$data,
22
+ table = _ref.table,
23
+ metaIndex = _ref.metaIndex,
21
24
  groupIndex = _ref.groupIndex,
22
25
  onChange = _ref.onChange;
23
26
  var _useState = useState([]),
@@ -98,6 +101,7 @@ var SelectColumn = function SelectColumn(_ref) {
98
101
  }
99
102
  var onChangeFieldAlias = function onChangeFieldAlias(val, i) {
100
103
  var fieldAlias = val || '';
104
+ var currentColumn = columns[i];
101
105
  Modal.confirm({
102
106
  title: __('SqlQueryBuilder.alias'),
103
107
  content: _jsx(Input, {
@@ -108,7 +112,7 @@ var SelectColumn = function SelectColumn(_ref) {
108
112
  }),
109
113
  onOk: function () {
110
114
  var _onOk = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
111
- var newColumns, newMetaList;
115
+ var newColumns, newMetaList, changedColumn, targetMetaIndex, targetMeta;
112
116
  return _regeneratorRuntime.wrap(function (_context) {
113
117
  while (1) switch (_context.prev = _context.next) {
114
118
  case 0:
@@ -123,9 +127,29 @@ var SelectColumn = function SelectColumn(_ref) {
123
127
  newMetaList = store.metaList[groupIndex].list.slice();
124
128
  newColumns[i].fieldAlias = fieldAlias;
125
129
  newColumns[i].fieldUuid = newColumns[i].fieldUuid || uuidv4('field');
126
- newMetaList = changeFieldAlias(newMetaList, newColumns[i]);
130
+ changedColumn = _objectSpread(_objectSpread({}, newColumns[i]), {}, {
131
+ datasourceId: newColumns[i].datasourceId || (table === null || table === void 0 ? void 0 : table.datasourceId) || '',
132
+ datasourceName: newColumns[i].datasourceName || (table === null || table === void 0 ? void 0 : table.datasourceName) || '',
133
+ tableId: newColumns[i].tableId || (table === null || table === void 0 ? void 0 : table.id) || '',
134
+ tableUuid: newColumns[i].tableUuid || (table === null || table === void 0 ? void 0 : table.tableUuid) || '',
135
+ table: (table === null || table === void 0 ? void 0 : table.name) || ''
136
+ });
137
+ newColumns = originList.map(function (item) {
138
+ return isSameColumnByIdFirst(item, currentColumn) ? changedColumn : item;
139
+ });
140
+ newMetaList = changeFieldAlias(newMetaList, changedColumn);
141
+ targetMetaIndex = typeof metaIndex === 'number' ? metaIndex : newMetaList.findIndex(function (item) {
142
+ return item.type === TypeEnum.data;
143
+ });
144
+ targetMeta = newMetaList[targetMetaIndex];
145
+ if ((targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.type) === TypeEnum.data) {
146
+ targetMeta.columns = newColumns;
147
+ }
148
+ if ((targetMeta === null || targetMeta === void 0 ? void 0 : targetMeta.type) === TypeEnum.joinData) {
149
+ targetMeta.columns = newColumns;
150
+ }
127
151
  store.setMeta(newMetaList, groupIndex, {
128
- obj: newColumns[i],
152
+ obj: changedColumn,
129
153
  type: ChangeType.fieldAlias
130
154
  });
131
155
  onSelect(newColumns, newMetaList, true);
@@ -6,7 +6,7 @@ import cx from 'classnames';
6
6
  import cloneDeep from 'lodash/cloneDeep';
7
7
  import { __ } from '../../../locale';
8
8
  import { TableIcon, SearchIcon } from '../../icons';
9
- import { getTableIdFirstKey, isSameTableByIdName, mergeNameAlias } from '../../../utils/helper';
9
+ import { getTableIdNameKey, isSameTableByIdName, mergeNameAlias } from '../../../utils/helper';
10
10
  var PrevResult = 'Previous results';
11
11
  var SelectPermissionTable = function SelectPermissionTable(_ref) {
12
12
  var _ref$data = _ref.data,
@@ -78,7 +78,7 @@ var SelectPermissionTable = function SelectPermissionTable(_ref) {
78
78
  })]
79
79
  })
80
80
  })
81
- }, getTableIdFirstKey(v));
81
+ }, getTableIdNameKey(v));
82
82
  })]
83
83
  })
84
84
  })
@@ -8,7 +8,7 @@ import './index.less';
8
8
  import React, { useState, useEffect, useMemo, useRef } from 'react';
9
9
  import cx from 'classnames';
10
10
  import { Tag } from '@gingkoo/pandora';
11
- import { getTableIdFirstKey, isSameTableByIdName, uuidv4 } from '../../../utils/helper';
11
+ import { getTableIdNameKey, isSameTableByIdName, uuidv4 } from '../../../utils/helper';
12
12
  import { useStore } from '../../../hooks/use-provider';
13
13
  import Loading from '../../../common/Loading';
14
14
  import { __ } from '../../../locale';
@@ -343,7 +343,7 @@ var SelectTable = function SelectTable(_ref) {
343
343
  })]
344
344
  })
345
345
  })
346
- }, getTableIdFirstKey(tableValue));
346
+ }, getTableIdNameKey(tableValue));
347
347
  }))]
348
348
  }, table.datasourceId);
349
349
  })]
@@ -465,7 +465,7 @@ var SelectTable = function SelectTable(_ref) {
465
465
  })]
466
466
  })
467
467
  })
468
- }, getTableIdFirstKey(tableValue));
468
+ }, getTableIdNameKey(tableValue));
469
469
  })]
470
470
  })]
471
471
  })
@@ -12,7 +12,7 @@ import { Button, Tooltip, Input, Modal2, Modal, Toast, Dropdown, InputNumber } f
12
12
  import { FfPlus, FfLine, Repeat, RelatedWork } from '@gingkoo/pandora-icons';
13
13
  import Metabase from '../../index';
14
14
  import cloneDeep from 'lodash/cloneDeep';
15
- import { uuidv4, getAlias, mergeNameAlias, isSameTableByIdFirst } from '../../utils/helper';
15
+ import { uuidv4, getAlias, mergeNameAlias, isSameTableByIdName } from '../../utils/helper';
16
16
  import { getTopLayerZIndex } from '../../utils/helper-dom';
17
17
  import { getConstantLabel } from '../dialog/formula-list/utils';
18
18
  import { __ } from '../../locale';
@@ -107,7 +107,7 @@ var JoinData = function JoinData(props) {
107
107
  case 2:
108
108
  tables = _context.sent;
109
109
  if (!(tables !== null && tables !== void 0 && tables.some(function (v) {
110
- return isSameTableByIdFirst(tableInfo, v);
110
+ return isSameTableByIdName(tableInfo, v);
111
111
  }))) {
112
112
  setIsDel(true);
113
113
  } else {
@@ -369,6 +369,8 @@ var JoinData = function JoinData(props) {
369
369
  node: e.currentTarget,
370
370
  content: _jsx(SelectColumn, {
371
371
  data: columns,
372
+ table: meta.table2,
373
+ metaIndex: index,
372
374
  groupIndex: groupIndex,
373
375
  onChange: function onChange(data, newMetaList) {
374
376
  var _newMetaList = newMetaList || store.metaList[groupIndex].list.slice();
@@ -496,7 +498,7 @@ var JoinData = function JoinData(props) {
496
498
  value: value,
497
499
  onChange: function onChange(data) {
498
500
  var tableName = data.name;
499
- if (!isSameTableByIdFirst(meta.table2, data)) {
501
+ if (!isSameTableByIdName(meta.table2, data)) {
500
502
  var _store$preProps;
501
503
  var newMeta = cloneDeep(store.metaList[groupIndex].list);
502
504
  var aliasMetaList = newMeta.filter(function (_, i) {
@@ -10,7 +10,7 @@ import NextDom from './components/meta-icon';
10
10
  import Header from './components/header';
11
11
  import ItemWrapper from './components/item-wrapper';
12
12
  import { useStore } from '../../hooks/use-provider';
13
- import { isSameTableByIdFirst, uuidv4 } from '../../utils/helper';
13
+ import { isSameTableByIdName, uuidv4 } from '../../utils/helper';
14
14
  import ItemName from './components/item-name';
15
15
  import { SummarizeAlias } from '../../store/helper';
16
16
  var PrevResult = 'Previous results';
@@ -90,7 +90,7 @@ var PermissionTable = function PermissionTable(props) {
90
90
  data: data,
91
91
  value: meta.table,
92
92
  onChange: function onChange(data) {
93
- if (!isSameTableByIdFirst(meta.table, data)) {
93
+ if (!isSameTableByIdName(meta.table, data)) {
94
94
  meta.table = data;
95
95
  }
96
96
  store.setPopup({
@@ -12,7 +12,7 @@ import { __ } from '../../locale';
12
12
  import { ChangeType } from '../../store/types';
13
13
  import { Tooltip, Button, Modal, Modal2, Input, Toast } from '@gingkoo/pandora';
14
14
  import Metabase from '../../index';
15
- import { uuidv4, getAlias, isSameTableByIdFirst } from '../../utils/helper';
15
+ import { uuidv4, getAlias, isSameTableByIdName } from '../../utils/helper';
16
16
  import { getTopLayerZIndex } from '../../utils/helper-dom';
17
17
  import { changeTableAlias, getSubColumns, mergeSubQueryColumns, isValidSQLAlias, isExistsError, syncSubQueryFieldReferences } from '../../utils';
18
18
  import { RelatedWork } from '@gingkoo/pandora-icons';
@@ -56,7 +56,7 @@ var TableData = function TableData(props) {
56
56
  case 2:
57
57
  tables = _context.sent;
58
58
  if (!(tables !== null && tables !== void 0 && tables.some(function (v) {
59
- return isSameTableByIdFirst(tableInfo, v);
59
+ return isSameTableByIdName(tableInfo, v);
60
60
  }))) {
61
61
  setIsDel(true);
62
62
  } else {
@@ -87,7 +87,7 @@ var TableData = function TableData(props) {
87
87
  sourceTable: store.sourceTable || [],
88
88
  value: meta.table,
89
89
  onChange: function onChange(data) {
90
- if (!isSameTableByIdFirst(meta.table, data)) {
90
+ if (!isSameTableByIdName(meta.table, data)) {
91
91
  var _store$preProps;
92
92
  var newMetaList = store.metaList[groupIndex].list.slice()[0];
93
93
  newMetaList.table = _objectSpread(_objectSpread({}, data), {}, {
@@ -119,6 +119,8 @@ var TableData = function TableData(props) {
119
119
  node: e.currentTarget || e.target,
120
120
  content: _jsx(SelectColumn, {
121
121
  groupIndex: groupIndex,
122
+ table: meta.table,
123
+ metaIndex: 0,
122
124
  data: columns,
123
125
  onChange: function onChange(data, newMetaList) {
124
126
  var _newMetaList = newMetaList || store.metaList[groupIndex].list.slice();
@@ -563,6 +563,8 @@ var useStore = function useStore() {
563
563
  _metaList,
564
564
  prevMeta,
565
565
  newMeta,
566
+ oldData,
567
+ newData,
566
568
  isChange,
567
569
  _args9 = arguments;
568
570
  return _regeneratorRuntime.wrap(function (_context9) {
@@ -582,10 +584,12 @@ var useStore = function useStore() {
582
584
  }
583
585
  return _context9.abrupt("return");
584
586
  case 1:
587
+ oldData = splitByUnion(prevMeta);
588
+ newData = splitByUnion(newMeta);
585
589
  _context9.next = 2;
586
- return fetchChangeFn.current(splitByUnion(newMeta), changeObj, {
590
+ return fetchChangeFn.current(oldData, changeObj, {
587
591
  isExit: isExit
588
- });
592
+ }, newData);
589
593
  case 2:
590
594
  isChange = _context9.sent;
591
595
  if (isChange === false) {
package/lib/es/types.d.ts CHANGED
@@ -59,10 +59,10 @@ export interface MetabaseProps {
59
59
  groupByEnableAlias?: boolean;
60
60
  isSelectFields?: boolean;
61
61
  tableFlat?: boolean;
62
- onChange?: (newData: MetaListType[], curData: {
62
+ onChange?: (oldData: MetaListType[], curData: {
63
63
  data: any;
64
64
  type: ChangeType;
65
- }, options: FetchOptions) => Promise<void | Boolean>;
65
+ }, options: FetchOptions, newData: MetaListType[]) => Promise<void | Boolean>;
66
66
  copyType?: (FormulaTypeEnum | string)[];
67
67
  metabaseCopy?: boolean;
68
68
  moduleDiff?: boolean;
@@ -2,6 +2,7 @@ import type { MetaListType } from '../store/types';
2
2
  export declare const isSameTableByIdName: (left?: any, right?: any) => boolean;
3
3
  export declare const isSameColumnByIdName: (left?: any, right?: any) => boolean;
4
4
  export declare const getTableIdFirstKey: (table?: any) => string;
5
+ export declare const getTableIdNameKey: (table?: any) => string;
5
6
  export declare const isSameTableByIdFirst: (left?: any, right?: any) => boolean;
6
7
  export declare const getColumnIdFirstKey: (column?: any) => string;
7
8
  export declare const isSameColumnByIdFirst: (left?: any, right?: any) => boolean;
@@ -52,6 +52,18 @@ export var getTableIdFirstKey = function getTableIdFirstKey() {
52
52
  var tableAlias = normalizeId(table.alias || table.tableAlias);
53
53
  return tableName ? "".concat(datasourceId, "|name:").concat(tableName, "|alias:").concat(tableAlias) : datasourceId;
54
54
  };
55
+ export var getTableIdNameKey = function getTableIdNameKey() {
56
+ var table = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
57
+ var datasourceId = normalizeId(table.datasourceId);
58
+ var tableId = normalizeId(table.id || table.tableId);
59
+ var tableName = normalizeId(table.name || table.tableName || table.table);
60
+ var tableAlias = normalizeId(table.alias || table.tableAlias);
61
+ if (tableId || tableName) {
62
+ return "".concat(datasourceId, "|id:").concat(tableId, "|name:").concat(tableName, "|alias:").concat(tableAlias);
63
+ }
64
+ var tableUuid = normalizeId(table.tableUuid);
65
+ return tableUuid ? "".concat(datasourceId, "|uuid:").concat(tableUuid) : datasourceId;
66
+ };
55
67
  export var isSameTableByIdFirst = function isSameTableByIdFirst() {
56
68
  var left = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
57
69
  var right = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.143",
3
+ "version": "1.0.145",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",