@gingkoo/pandora-metabase 1.0.157-alpha.6 → 1.0.157-alpha.7

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.
@@ -36,7 +36,9 @@ var CaseEditor = function CaseEditor(props) {
36
36
  _props$readonly = props.readonly,
37
37
  readonly = _props$readonly === void 0 ? false : _props$readonly;
38
38
  var store = (0, _useProvider.useStore)();
39
- var _useState = (0, _react.useState)(value.formulaList || []),
39
+ var _useState = (0, _react.useState)(function () {
40
+ return (0, _utils.normalizeExpressionAtoms)(value.formulaList || [], data);
41
+ }),
40
42
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
41
43
  caseList = _useState2[0],
42
44
  setCaseList = _useState2[1];
@@ -59,7 +61,7 @@ var CaseEditor = function CaseEditor(props) {
59
61
  }
60
62
  typeof onOk === 'function' && (onOk === null || onOk === void 0 ? void 0 : onOk((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, value), {}, {
61
63
  name: name,
62
- formulaList: caseList
64
+ formulaList: (0, _utils.normalizeExpressionAtoms)(caseList, data)
63
65
  })));
64
66
  };
65
67
  var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
@@ -93,7 +95,7 @@ var CaseEditor = function CaseEditor(props) {
93
95
  case 3:
94
96
  return _context.abrupt("return", function () {
95
97
  setName(result.name || name);
96
- setCaseList(result.formulaList);
98
+ setCaseList((0, _utils.normalizeExpressionAtoms)(result.formulaList, data));
97
99
  });
98
100
  case 4:
99
101
  _context.prev = 4;
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports["default"] = void 0;
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
11
10
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
12
12
  var _jsxRuntime = require("react/jsx-runtime");
13
13
  require("./index.less");
14
14
  var _react = _interopRequireWildcard(require("react"));
@@ -30,16 +30,6 @@ var _utils = require("../formula-list/utils");
30
30
  var _itemName = _interopRequireDefault(require("../../modules/components/item-name"));
31
31
  var _dateFormatPicker = require("./date-format-picker");
32
32
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
33
- var normalizeExpressionRhs = function normalizeExpressionRhs() {
34
- var rhs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
35
- return rhs.map(function (item) {
36
- if ((item === null || item === void 0 ? void 0 : item.type) !== _types.AtomsTypeEnum.INPUT_NUMBER) return item;
37
- return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
38
- type: _types.AtomsTypeEnum.INPUT_STRING,
39
- val: item.val || item.val === 0 ? String(item.val) : ''
40
- });
41
- });
42
- };
43
33
  var NUMBER_LIST = ['等于', '不等于', '大于', '小于', '介于之间', '大于或等于', '小于或等于', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
44
34
  var STRING_LIST = ['等于', '不等于', '包含', '不包含', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
45
35
  var DATE_LIST = ['等于', '早于', '晚于', '介于之间', '是空的', '不为空'];
@@ -53,6 +43,18 @@ var typeList = [{
53
43
  key: _enum.SQL_COLUMN_TYPE.DATE,
54
44
  label: _enum.SQL_COLUMN_TYPE.DATE
55
45
  }];
46
+ var getExpressionEditorType = function getExpressionEditorType(value) {
47
+ var _value$rhs;
48
+ var inputAtom = (_value$rhs = value.rhs) === null || _value$rhs === void 0 ? void 0 : _value$rhs[0];
49
+ if ((inputAtom === null || inputAtom === void 0 ? void 0 : inputAtom.type) === _types.AtomsTypeEnum.INPUT_NUMBER) return _enum.SQL_COLUMN_TYPE.FLOAT;
50
+ if ((inputAtom === null || inputAtom === void 0 ? void 0 : inputAtom.type) === _types.AtomsTypeEnum.INPUT_STRING) {
51
+ return inputAtom.format ? _enum.SQL_COLUMN_TYPE.DATE : _enum.SQL_COLUMN_TYPE.STRING;
52
+ }
53
+ if ((inputAtom === null || inputAtom === void 0 ? void 0 : inputAtom.type) === _types.AtomsTypeEnum.INPUT_STRING_LIST && inputAtom.format) {
54
+ return _enum.SQL_COLUMN_TYPE.DATE;
55
+ }
56
+ return value.database_type || _enum.SQL_COLUMN_TYPE.STRING;
57
+ };
56
58
  var SelectFilterColumn = function SelectFilterColumn(_ref) {
57
59
  var _value$lhs;
58
60
  var _ref$data = _ref.data,
@@ -67,21 +69,20 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
67
69
  _ref$filterCustomType = _ref.filterCustomType,
68
70
  filterCustomType = _ref$filterCustomType === void 0 ? false : _ref$filterCustomType,
69
71
  parentPopupChannel = _ref.parentPopupChannel;
70
- var _useState = (0, _react.useState)(value),
72
+ var normalizedInitialValue = (0, _utils.normalizeExpressionAtom)(value, data);
73
+ var _useState = (0, _react.useState)(normalizedInitialValue),
71
74
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
72
75
  curColumn = _useState2[0],
73
76
  setCurColumn = _useState2[1];
74
- var _useState3 = (0, _react.useState)(value.condition || ''),
77
+ var _useState3 = (0, _react.useState)(normalizedInitialValue.condition || ''),
75
78
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
76
79
  condition = _useState4[0],
77
80
  setCondition = _useState4[1];
78
- var _useState5 = (0, _react.useState)(function () {
79
- return (0, _cloneDeep["default"])(normalizeExpressionRhs(value.rhs || []));
80
- }),
81
+ var _useState5 = (0, _react.useState)((0, _cloneDeep["default"])(normalizedInitialValue.rhs || [])),
81
82
  _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
82
83
  rhsVal = _useState6[0],
83
84
  setRhsVal = _useState6[1];
84
- var _useState7 = (0, _react.useState)((value === null || value === void 0 ? void 0 : value.database_type) || _enum.SQL_COLUMN_TYPE.STRING),
85
+ var _useState7 = (0, _react.useState)(filterCustomType ? getExpressionEditorType(normalizedInitialValue) : normalizedInitialValue.database_type || _enum.SQL_COLUMN_TYPE.STRING),
85
86
  _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
86
87
  special_type = _useState8[0],
87
88
  setSpecial_type = _useState8[1];
@@ -147,8 +148,8 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
147
148
  return false;
148
149
  }
149
150
  var isOk = rhsVal.every(function (v) {
150
- if (v.type === _types.AtomsTypeEnum.INPUT_STRING || v.type === _types.AtomsTypeEnum.CONSTANT) {
151
- return v.val;
151
+ if (v.type === _types.AtomsTypeEnum.INPUT_STRING || v.type === _types.AtomsTypeEnum.INPUT_NUMBER || v.type === _types.AtomsTypeEnum.CONSTANT) {
152
+ return v.val || v.val === 0;
152
153
  }
153
154
  if (v.type === _types.AtomsTypeEnum.INPUT_STRING_LIST) {
154
155
  return v.val.every(function (vv) {
@@ -218,6 +219,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
218
219
  if (_val.type === _types.AtomsTypeEnum.INPUT_STRING) {
219
220
  firstVal = _val.val;
220
221
  }
222
+ if (_val.type === _types.AtomsTypeEnum.INPUT_NUMBER) {
223
+ firstVal = _val.val || _val.val === 0 ? String(_val.val) : '';
224
+ }
221
225
  if (_val.type === _types.AtomsTypeEnum.INPUT_STRING_LIST) {
222
226
  firstVal = _val.val[0] || '';
223
227
  secondVal = _val.val[1] || '';
@@ -315,13 +319,16 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
315
319
  }
316
320
  function addFilter() {
317
321
  if (disabled) return void 0;
318
- var quotes = generateQuotes(rhsVal, curColumn);
319
- typeof onChange === 'function' && onChange((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, curColumn), {}, {
322
+ var databaseType = filterCustomType ? special_type : (0, _utils.normalizeExpressionAtom)(curColumn, data).database_type;
323
+ var nextExpression = (0, _utils.normalizeExpressionAtom)((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, curColumn), {}, {
320
324
  formula: formula,
321
325
  rhs: rhsVal,
322
326
  condition: condition,
323
- quotes: quotes,
324
- database_type: filterCustomType ? special_type : ''
327
+ database_type: databaseType
328
+ }), filterCustomType ? [] : data);
329
+ var quotes = generateQuotes(nextExpression.rhs, nextExpression);
330
+ typeof onChange === 'function' && onChange((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, nextExpression), {}, {
331
+ quotes: quotes
325
332
  }));
326
333
  }
327
334
  function goPrevPage() {
@@ -359,6 +366,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
359
366
  if (_val.type === _types.AtomsTypeEnum.INPUT_STRING) {
360
367
  firstVal = _val.val;
361
368
  }
369
+ if (_val.type === _types.AtomsTypeEnum.INPUT_NUMBER) {
370
+ firstVal = _val.val || _val.val === 0 ? String(_val.val) : '';
371
+ }
362
372
  if (_val.type === _types.AtomsTypeEnum.INPUT_STRING_LIST) {
363
373
  firstVal = _val.val[0] || '';
364
374
  secondVal = _val.val[1] || '';
@@ -575,14 +585,36 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
575
585
  })
576
586
  });
577
587
  } else if (~['等于', '不等于', '大于', '小于', '大于或等于', '小于或等于', '包含', '不包含', '以...开始', '以...结束', '不以...开始', '不以...结束', '正则匹配'].indexOf(conditionText)) {
588
+ if (_val.type === _types.AtomsTypeEnum.INPUT_NUMBER) {
589
+ return (0, _jsxRuntime.jsx)("div", {
590
+ className: 'filter-value-control',
591
+ children: (0, _jsxRuntime.jsx)(_pandora.InputNumber, {
592
+ className: 'filter-number-input',
593
+ placeholder: (0, _locale.__)('filter.enterANumber'),
594
+ value: firstVal,
595
+ onChange: function onChange(val) {
596
+ var newVal = rhsVal.slice();
597
+ newVal[0] = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, newVal[0]), {}, {
598
+ type: _types.AtomsTypeEnum.INPUT_NUMBER,
599
+ val: val === null || val === undefined || val === '' ? Number.NaN : Number(val)
600
+ });
601
+ setRhsVal(newVal);
602
+ }
603
+ })
604
+ });
605
+ }
578
606
  return (0, _jsxRuntime.jsx)("div", {
607
+ className: 'filter-value-control',
579
608
  children: (0, _jsxRuntime.jsx)(_pandora.Input, {
580
609
  className: 'input',
581
610
  placeholder: (0, _locale.__)('filter.pleaseEnter'),
582
611
  value: firstVal || '',
583
612
  onInput: function onInput(e) {
584
613
  var newVal = rhsVal.slice();
585
- newVal[0].val = e.target.value;
614
+ newVal[0] = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, newVal[0]), {}, {
615
+ type: _types.AtomsTypeEnum.INPUT_STRING,
616
+ val: e.target.value
617
+ });
586
618
  setRhsVal(newVal);
587
619
  }
588
620
  })
@@ -618,7 +650,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
618
650
  });
619
651
  };
620
652
  var onRepeat = function onRepeat(e) {
653
+ var _rhsVal$7;
621
654
  setParentClosable(false);
655
+ var inputAtomType = ((_rhsVal$7 = rhsVal[0]) === null || _rhsVal$7 === void 0 ? void 0 : _rhsVal$7.type) === _types.AtomsTypeEnum.INPUT_NUMBER ? _types.AtomsTypeEnum.INPUT_NUMBER : _types.AtomsTypeEnum.INPUT_STRING;
622
656
  store.setPopup2({
623
657
  visible: true,
624
658
  node: e.currentTarget,
@@ -626,7 +660,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
626
660
  content: (0, _jsxRuntime.jsx)(_selectList["default"], {
627
661
  value: '',
628
662
  list: [{
629
- value: _types.AtomsTypeEnum.INPUT_STRING,
663
+ value: inputAtomType,
630
664
  label: (0, _locale.__)('customColumn.input')
631
665
  }, {
632
666
  value: _types.AtomsTypeEnum.CONSTANT,
@@ -637,11 +671,15 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
637
671
  }],
638
672
  onChange: function onChange(type) {
639
673
  closePopup2();
640
- if (type === _types.AtomsTypeEnum.INPUT_STRING || type === _types.AtomsTypeEnum.CONSTANT) {
641
- setRhsVal([{
674
+ if (type === _types.AtomsTypeEnum.INPUT_STRING || type === _types.AtomsTypeEnum.INPUT_NUMBER || type === _types.AtomsTypeEnum.CONSTANT) {
675
+ var nextInput = type === _types.AtomsTypeEnum.INPUT_NUMBER ? {
676
+ val: Number.NaN,
677
+ type: _types.AtomsTypeEnum.INPUT_NUMBER
678
+ } : {
642
679
  val: '',
643
680
  type: type
644
- }]);
681
+ };
682
+ setRhsVal([nextInput]);
645
683
  }
646
684
  if (type === _types.AtomsTypeEnum.FIELD) {
647
685
  setRhsVal([{
@@ -810,16 +848,25 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
810
848
  onVisibleChange: setDropdownClosable,
811
849
  getPopupContainer: getCurrentPopupContainer,
812
850
  onChange: function onChange(key) {
851
+ var _rhsVal$8;
813
852
  setCondition('');
814
- setCurColumn((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, curColumn), {}, {
815
- rhs: [{
816
- val: '',
817
- type: _types.AtomsTypeEnum.INPUT_STRING
818
- }]
819
- }));
820
- setTimeout(function () {
821
- setSpecial_type(key);
822
- }, 0);
853
+ setSpecial_type(key);
854
+ var currentValue = (_rhsVal$8 = rhsVal[0]) === null || _rhsVal$8 === void 0 ? void 0 : _rhsVal$8.val;
855
+ if (key === _enum.SQL_COLUMN_TYPE.FLOAT) {
856
+ var numberValue = Number(currentValue);
857
+ setRhsVal([{
858
+ type: _types.AtomsTypeEnum.INPUT_NUMBER,
859
+ val: currentValue !== '' && Number.isFinite(numberValue) ? numberValue : Number.NaN
860
+ }]);
861
+ } else {
862
+ var _rhsVal$9;
863
+ setRhsVal([(0, _objectSpread2["default"])({
864
+ type: _types.AtomsTypeEnum.INPUT_STRING,
865
+ val: currentValue === undefined || currentValue === null ? '' : String(currentValue)
866
+ }, key === _enum.SQL_COLUMN_TYPE.DATE ? {
867
+ format: ((_rhsVal$9 = rhsVal[0]) === null || _rhsVal$9 === void 0 ? void 0 : _rhsVal$9.format) || 'YYYY-MM-DD HH:mm'
868
+ } : {})]);
869
+ }
823
870
  },
824
871
  droplist: typeList,
825
872
  children: (0, _jsxRuntime.jsxs)(_pandora.Button, {
@@ -876,7 +923,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
876
923
  }, i)
877
924
  }, i);
878
925
  }
879
- if (v.type === _types.AtomsTypeEnum.INPUT_STRING || v.type === _types.AtomsTypeEnum.INPUT_STRING_LIST) {
926
+ if (v.type === _types.AtomsTypeEnum.INPUT_STRING || v.type === _types.AtomsTypeEnum.INPUT_NUMBER || v.type === _types.AtomsTypeEnum.INPUT_STRING_LIST) {
880
927
  return (0, _jsxRuntime.jsx)(_react["default"].Fragment, {
881
928
  children: renderFilter(fieldType, condition)
882
929
  }, i);
@@ -906,7 +953,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
906
953
  });
907
954
  }
908
955
  function setDefaultVal(_condition) {
956
+ var _rhsVal$0;
909
957
  setCondition(_condition);
958
+ var inputAtomType = ((_rhsVal$0 = rhsVal[0]) === null || _rhsVal$0 === void 0 ? void 0 : _rhsVal$0.type) === _types.AtomsTypeEnum.INPUT_NUMBER ? _types.AtomsTypeEnum.INPUT_NUMBER : _types.AtomsTypeEnum.INPUT_STRING;
910
959
  if (~['前', '下一个'].indexOf(_condition)) {
911
960
  setRhsVal([{
912
961
  val: ['30', '天'],
@@ -930,7 +979,10 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
930
979
  format: 'YYYY-MM-DD HH:mm'
931
980
  }]);
932
981
  } else {
933
- setRhsVal([{
982
+ setRhsVal(inputAtomType === _types.AtomsTypeEnum.INPUT_NUMBER ? [{
983
+ val: Number.NaN,
984
+ type: _types.AtomsTypeEnum.INPUT_NUMBER
985
+ }] : [{
934
986
  val: '',
935
987
  type: _types.AtomsTypeEnum.INPUT_STRING
936
988
  }]);
@@ -948,9 +1000,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
948
1000
  setIsNext(true);
949
1001
  },
950
1002
  onSelect: function onSelect(fields, quotes) {
951
- setCurColumn((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, curColumn), {}, {
1003
+ setCurColumn((0, _utils.normalizeExpressionAtom)((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, curColumn), {}, {
952
1004
  lhs: fields
953
- }));
1005
+ }), data));
954
1006
  setIsNext(true);
955
1007
  }
956
1008
  })
@@ -60,6 +60,7 @@
60
60
  .content {
61
61
  padding: 0.5rem;
62
62
  display: flex;
63
+ gap: 8px;
63
64
  justify-content: space-between;
64
65
  align-items: center;
65
66
  &_l {
@@ -180,6 +181,48 @@
180
181
  .w_300 {
181
182
  width: 300px;
182
183
  }
184
+ .filter-value-control {
185
+ flex: 1;
186
+ min-width: 0;
187
+
188
+ > .input,
189
+ > .filter-number-input {
190
+ width: 100%;
191
+ }
192
+
193
+ .filter-number-input {
194
+ height: 40px;
195
+ padding: 0;
196
+ border: 0;
197
+ border-radius: 4px;
198
+ background: transparent;
199
+
200
+ &.pd-Input,
201
+ .pd-Input,
202
+ .pd-Input-inner-wrapper {
203
+ width: 100%;
204
+ height: 40px;
205
+ box-sizing: border-box;
206
+ border-radius: 4px;
207
+ font-size: 16px;
208
+ color: #4c5773;
209
+ }
210
+
211
+ .pd-Input-inner-wrapper {
212
+ padding: 0 34px 0 20px;
213
+ border: 1px solid #f0f0f0;
214
+ outline: none;
215
+ }
216
+
217
+ .pd-Input {
218
+ height: 100%;
219
+ padding: 0;
220
+ border: 0;
221
+ background: transparent;
222
+ box-shadow: none;
223
+ }
224
+ }
225
+ }
183
226
  .input {
184
227
  border: 1px solid #f0f0f0;
185
228
  font-size: 16px;
@@ -411,13 +411,26 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
411
411
  });
412
412
  return map;
413
413
  }, [otherTypes]);
414
- var normalizedValue = (0, _react.useMemo)(function () {
415
- return (0, _utils2.normalizeAndOrStructure)(value || []).map(_utils2.syncAtomQuotes);
414
+ var normalizedStructureValue = (0, _react.useMemo)(function () {
415
+ return (0, _utils2.normalizeAndOrStructure)(value || []);
416
416
  }, [value]);
417
+ var normalizedExpressionValue = (0, _react.useMemo)(function () {
418
+ return (0, _utils3.normalizeExpressionAtoms)(normalizedStructureValue, data);
419
+ }, [normalizedStructureValue, data]);
420
+ var normalizedValue = (0, _react.useMemo)(function () {
421
+ return normalizedExpressionValue.map(_utils2.syncAtomQuotes);
422
+ }, [normalizedExpressionValue]);
417
423
  var caseList = normalizedValue;
418
424
  var initialValueRef = (0, _react.useRef)((0, _cloneDeep["default"])(caseList));
419
425
  var caseListRef = (0, _react.useRef)(caseList);
420
426
  caseListRef.current = caseList;
427
+ (0, _react.useEffect)(function () {
428
+ if ((0, _isEqual["default"])(normalizedExpressionValue, normalizedStructureValue)) return;
429
+ var quotes = normalizedValue.map(function (item) {
430
+ return (0, _utils2.getAtomDisplayText)(item);
431
+ }).join(' ');
432
+ onChange === null || onChange === void 0 || onChange(normalizedValue, quotes);
433
+ }, [normalizedExpressionValue, normalizedStructureValue, normalizedValue, onChange]);
421
434
  var hasFormulaSqlAction = Boolean(store.showFormulaSql && store.hasFormulaSqlCode);
422
435
  var hasFormulaDiffAction = Boolean(store.showFormulaDiff && store.hasFormulaDiffCode);
423
436
  var operatorList = (0, _react.useMemo)(function () {
@@ -626,8 +639,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
626
639
  var withSyncedQuotes = function withSyncedQuotes(item) {
627
640
  return _withSyncedQuotesInner(item, new WeakMap());
628
641
  };
629
- var setCaseList = function setCaseList(data) {
630
- var nextData = data.map(function (item) {
642
+ var setCaseList = function setCaseList(atoms) {
643
+ var nextData = (0, _utils3.normalizeExpressionAtoms)(atoms, data).map(function (item) {
631
644
  return withSyncedQuotes(item);
632
645
  });
633
646
  var quotes = nextData.map(function (item) {
@@ -1,4 +1,14 @@
1
- import { AtomsTypeEnum, AtomsItem } from '../../../store/types';
1
+ import { AtomsTypeEnum, AtomsItem, AtomsExpression } from '../../../store/types';
2
+ type ExpressionTable = {
3
+ id?: string;
4
+ name?: string;
5
+ alias?: string;
6
+ tableUuid?: string;
7
+ columns?: any[];
8
+ };
9
+ export declare const getExpressionDatabaseType: (expression: AtomsExpression, tables?: ExpressionTable[]) => string;
10
+ export declare const normalizeExpressionAtom: (expression: AtomsExpression, tables?: ExpressionTable[]) => AtomsExpression;
11
+ export declare const normalizeExpressionAtoms: (atoms?: AtomsItem[], tables?: ExpressionTable[]) => AtomsItem[];
2
12
  export declare const insertTemplateAt: (oldType: string, type: string, list: any[], index: number) => any[];
3
13
  export declare const operatorList: string[];
4
14
  export declare const customTypes: ({
@@ -20,3 +30,4 @@ export declare function validateExpressionIntegrity(list: AtomsItem[]): {
20
30
  isOver?: boolean;
21
31
  };
22
32
  export declare const getConstantLabel: (list: any[], val: string, defaultVal?: string) => any;
33
+ export {};
@@ -4,12 +4,111 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.operatorList = exports.isOk = exports.insertTemplateAt = exports.getTemplateItem = exports.getConstantLabel = exports.customTypes = void 0;
7
+ exports.operatorList = exports.normalizeExpressionAtoms = exports.normalizeExpressionAtom = exports.isOk = exports.insertTemplateAt = exports.getTemplateItem = exports.getExpressionDatabaseType = exports.getConstantLabel = exports.customTypes = void 0;
8
8
  exports.validateExpressionIntegrity = validateExpressionIntegrity;
9
9
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/createForOfIteratorHelper"));
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
11
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
12
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
11
13
  var _locale = require("../../../locale");
12
14
  var _types = require("../../../store/types");
15
+ var EMPTY_RHS_CONDITIONS = new Set(['为空', '不为空', '是空的', '不是空的']);
16
+ var isSameValue = function isSameValue(left, right) {
17
+ return left !== undefined && left !== null && left !== '' && right !== undefined && right !== null && right !== '' && String(left) === String(right);
18
+ };
19
+ var findExpressionColumn = function findExpressionColumn(expression) {
20
+ var _expression$lhs;
21
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
22
+ var field = (_expression$lhs = expression.lhs) === null || _expression$lhs === void 0 ? void 0 : _expression$lhs.find(function (item) {
23
+ return item.type === _types.AtomsTypeEnum.FIELD;
24
+ });
25
+ if (!field) return undefined;
26
+ var matchedTable = tables.find(function (table) {
27
+ return isSameValue(field.tableUuid, table.tableUuid) || isSameValue(field.tableId, table.id) || isSameValue(field.tableAlias, table.alias) || isSameValue(field.tableName, table.name);
28
+ });
29
+ var candidateColumns = matchedTable ? matchedTable.columns || [] : tables.flatMap(function (table) {
30
+ return table.columns || [];
31
+ });
32
+ var matchedColumns = candidateColumns.filter(function (column) {
33
+ return isSameValue(field.fieldUuid, column.fieldUuid) || isSameValue(field.fieldId, column.id || column.fieldId) || isSameValue(field.fieldAlias, column.fieldAlias) || isSameValue(field.fieldName, column.name || column.realName);
34
+ });
35
+ return matchedColumns.length === 1 ? matchedColumns[0] : undefined;
36
+ };
37
+ var getExpressionDatabaseType = exports.getExpressionDatabaseType = function getExpressionDatabaseType(expression) {
38
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
39
+ var column = findExpressionColumn(expression, tables);
40
+ return String((column === null || column === void 0 ? void 0 : column.database_type) || expression.database_type || '').toUpperCase();
41
+ };
42
+ var normalizeExpressionRhs = function normalizeExpressionRhs(expression) {
43
+ if (EMPTY_RHS_CONDITIONS.has(expression.condition)) return [];
44
+ return expression.rhs || [];
45
+ };
46
+ var normalizeExpressionAtom = exports.normalizeExpressionAtom = function normalizeExpressionAtom(expression) {
47
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
48
+ var databaseType = getExpressionDatabaseType(expression, tables);
49
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, expression), {}, {
50
+ lhs: expression.lhs || [],
51
+ rhs: normalizeExpressionRhs(expression),
52
+ database_type: databaseType
53
+ });
54
+ };
55
+ var normalizeExpressionAtoms = exports.normalizeExpressionAtoms = function normalizeExpressionAtoms() {
56
+ var atoms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
57
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
58
+ var normalizeList = function normalizeList() {
59
+ var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
60
+ return items.map(normalizeItem);
61
+ };
62
+ var normalizeItem = function normalizeItem(item) {
63
+ if (!item || (0, _typeof2["default"])(item) !== 'object') return item;
64
+ if (item.type === _types.AtomsTypeEnum.EXPRESSION) {
65
+ var nextExpression = normalizeExpressionAtom(item, tables);
66
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, nextExpression), {}, {
67
+ lhs: normalizeList(nextExpression.lhs),
68
+ rhs: normalizeList(nextExpression.rhs)
69
+ });
70
+ }
71
+ if (item.type === _types.AtomsTypeEnum.AND_OR) {
72
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
73
+ items: (item.items || []).map(function (logicItem) {
74
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, logicItem), {}, {
75
+ atoms: normalizeList(logicItem.atoms || [])
76
+ });
77
+ })
78
+ });
79
+ }
80
+ if (item.type === _types.AtomsTypeEnum.CASE_WHEN) {
81
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
82
+ caseAtoms: normalizeList(item.caseAtoms || []),
83
+ whenClauses: (item.whenClauses || []).map(function (clause) {
84
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, clause), {}, {
85
+ whenAtoms: normalizeList(clause.whenAtoms || []),
86
+ thenAtoms: normalizeList(clause.thenAtoms || [])
87
+ });
88
+ }),
89
+ elseAtoms: normalizeList(item.elseAtoms || [])
90
+ });
91
+ }
92
+ if (item.type === _types.AtomsTypeEnum.FORMULA) {
93
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
94
+ args: normalizeList(item.args || [])
95
+ });
96
+ }
97
+ if (item.type === _types.AtomsTypeEnum.COLLECTION) {
98
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
99
+ list: normalizeList(item.list || [])
100
+ });
101
+ }
102
+ if (item.type === _types.AtomsTypeEnum.JOIN_DEFAULT) {
103
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, item), {}, {
104
+ lhs: normalizeList(item.lhs || []),
105
+ rhs: normalizeList(item.rhs || [])
106
+ });
107
+ }
108
+ return item;
109
+ };
110
+ return normalizeList(atoms);
111
+ };
13
112
  var insertTemplateAt = exports.insertTemplateAt = function insertTemplateAt(oldType, type, list, index) {
14
113
  var temList = [];
15
114
  var needChange = ['RANK()', 'DENSE_RANK()', 'ROW_NUMBER()', 'when', 'case', 'then'].includes(oldType);
@@ -9,7 +9,7 @@ import { useState, useMemo, useRef } from 'react';
9
9
  import cx from 'classnames';
10
10
  import './index.less';
11
11
  import FormulaList from '../formula-list';
12
- import { isOk } from '../formula-list/utils';
12
+ import { isOk, normalizeExpressionAtoms } from '../formula-list/utils';
13
13
  import { __ } from '../../../locale';
14
14
  import Styled from 'styled-components';
15
15
  import { FormulaTypeEnum } from '../../../store/types';
@@ -29,7 +29,9 @@ var CaseEditor = function CaseEditor(props) {
29
29
  _props$readonly = props.readonly,
30
30
  readonly = _props$readonly === void 0 ? false : _props$readonly;
31
31
  var store = useStore();
32
- var _useState = useState(value.formulaList || []),
32
+ var _useState = useState(function () {
33
+ return normalizeExpressionAtoms(value.formulaList || [], data);
34
+ }),
33
35
  _useState2 = _slicedToArray(_useState, 2),
34
36
  caseList = _useState2[0],
35
37
  setCaseList = _useState2[1];
@@ -52,7 +54,7 @@ var CaseEditor = function CaseEditor(props) {
52
54
  }
53
55
  typeof onOk === 'function' && (onOk === null || onOk === void 0 ? void 0 : onOk(_objectSpread(_objectSpread({}, value), {}, {
54
56
  name: name,
55
- formulaList: caseList
57
+ formulaList: normalizeExpressionAtoms(caseList, data)
56
58
  })));
57
59
  };
58
60
  var parseFormulaSql = (_store$preProps = store.preProps) === null || _store$preProps === void 0 ? void 0 : _store$preProps.parseFormulaSql;
@@ -86,7 +88,7 @@ var CaseEditor = function CaseEditor(props) {
86
88
  case 3:
87
89
  return _context.abrupt("return", function () {
88
90
  setName(result.name || name);
89
- setCaseList(result.formulaList);
91
+ setCaseList(normalizeExpressionAtoms(result.formulaList, data));
90
92
  });
91
93
  case 4:
92
94
  _context.prev = 4;
@@ -1,6 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import './index.less';
6
6
  import React, { useEffect, useMemo, useState } from 'react';
@@ -19,19 +19,9 @@ import SelectColumnMultiple from '../select-column-multiple';
19
19
  import { LeftArrowIcon } from '../../icons';
20
20
  import { useStore } from '../../../hooks/use-provider';
21
21
  import cloneDeep from 'lodash/cloneDeep';
22
- import { getConstantLabel } from '../formula-list/utils';
22
+ import { getConstantLabel, normalizeExpressionAtom } from '../formula-list/utils';
23
23
  import ItemName from '../../modules/components/item-name';
24
24
  import { DateFormatPicker, DateRangeFormatPicker } from './date-format-picker';
25
- var normalizeExpressionRhs = function normalizeExpressionRhs() {
26
- var rhs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
27
- return rhs.map(function (item) {
28
- if ((item === null || item === void 0 ? void 0 : item.type) !== AtomsTypeEnum.INPUT_NUMBER) return item;
29
- return _objectSpread(_objectSpread({}, item), {}, {
30
- type: AtomsTypeEnum.INPUT_STRING,
31
- val: item.val || item.val === 0 ? String(item.val) : ''
32
- });
33
- });
34
- };
35
25
  var NUMBER_LIST = ['等于', '不等于', '大于', '小于', '介于之间', '大于或等于', '小于或等于', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
36
26
  var STRING_LIST = ['等于', '不等于', '包含', '不包含', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
37
27
  var DATE_LIST = ['等于', '早于', '晚于', '介于之间', '是空的', '不为空'];
@@ -45,6 +35,18 @@ var typeList = [{
45
35
  key: SQL_COLUMN_TYPE.DATE,
46
36
  label: SQL_COLUMN_TYPE.DATE
47
37
  }];
38
+ var getExpressionEditorType = function getExpressionEditorType(value) {
39
+ var _value$rhs;
40
+ var inputAtom = (_value$rhs = value.rhs) === null || _value$rhs === void 0 ? void 0 : _value$rhs[0];
41
+ if ((inputAtom === null || inputAtom === void 0 ? void 0 : inputAtom.type) === AtomsTypeEnum.INPUT_NUMBER) return SQL_COLUMN_TYPE.FLOAT;
42
+ if ((inputAtom === null || inputAtom === void 0 ? void 0 : inputAtom.type) === AtomsTypeEnum.INPUT_STRING) {
43
+ return inputAtom.format ? SQL_COLUMN_TYPE.DATE : SQL_COLUMN_TYPE.STRING;
44
+ }
45
+ if ((inputAtom === null || inputAtom === void 0 ? void 0 : inputAtom.type) === AtomsTypeEnum.INPUT_STRING_LIST && inputAtom.format) {
46
+ return SQL_COLUMN_TYPE.DATE;
47
+ }
48
+ return value.database_type || SQL_COLUMN_TYPE.STRING;
49
+ };
48
50
  var SelectFilterColumn = function SelectFilterColumn(_ref) {
49
51
  var _value$lhs;
50
52
  var _ref$data = _ref.data,
@@ -59,21 +61,20 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
59
61
  _ref$filterCustomType = _ref.filterCustomType,
60
62
  filterCustomType = _ref$filterCustomType === void 0 ? false : _ref$filterCustomType,
61
63
  parentPopupChannel = _ref.parentPopupChannel;
62
- var _useState = useState(value),
64
+ var normalizedInitialValue = normalizeExpressionAtom(value, data);
65
+ var _useState = useState(normalizedInitialValue),
63
66
  _useState2 = _slicedToArray(_useState, 2),
64
67
  curColumn = _useState2[0],
65
68
  setCurColumn = _useState2[1];
66
- var _useState3 = useState(value.condition || ''),
69
+ var _useState3 = useState(normalizedInitialValue.condition || ''),
67
70
  _useState4 = _slicedToArray(_useState3, 2),
68
71
  condition = _useState4[0],
69
72
  setCondition = _useState4[1];
70
- var _useState5 = useState(function () {
71
- return cloneDeep(normalizeExpressionRhs(value.rhs || []));
72
- }),
73
+ var _useState5 = useState(cloneDeep(normalizedInitialValue.rhs || [])),
73
74
  _useState6 = _slicedToArray(_useState5, 2),
74
75
  rhsVal = _useState6[0],
75
76
  setRhsVal = _useState6[1];
76
- var _useState7 = useState((value === null || value === void 0 ? void 0 : value.database_type) || SQL_COLUMN_TYPE.STRING),
77
+ var _useState7 = useState(filterCustomType ? getExpressionEditorType(normalizedInitialValue) : normalizedInitialValue.database_type || SQL_COLUMN_TYPE.STRING),
77
78
  _useState8 = _slicedToArray(_useState7, 2),
78
79
  special_type = _useState8[0],
79
80
  setSpecial_type = _useState8[1];
@@ -139,8 +140,8 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
139
140
  return false;
140
141
  }
141
142
  var isOk = rhsVal.every(function (v) {
142
- if (v.type === AtomsTypeEnum.INPUT_STRING || v.type === AtomsTypeEnum.CONSTANT) {
143
- return v.val;
143
+ if (v.type === AtomsTypeEnum.INPUT_STRING || v.type === AtomsTypeEnum.INPUT_NUMBER || v.type === AtomsTypeEnum.CONSTANT) {
144
+ return v.val || v.val === 0;
144
145
  }
145
146
  if (v.type === AtomsTypeEnum.INPUT_STRING_LIST) {
146
147
  return v.val.every(function (vv) {
@@ -210,6 +211,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
210
211
  if (_val.type === AtomsTypeEnum.INPUT_STRING) {
211
212
  firstVal = _val.val;
212
213
  }
214
+ if (_val.type === AtomsTypeEnum.INPUT_NUMBER) {
215
+ firstVal = _val.val || _val.val === 0 ? String(_val.val) : '';
216
+ }
213
217
  if (_val.type === AtomsTypeEnum.INPUT_STRING_LIST) {
214
218
  firstVal = _val.val[0] || '';
215
219
  secondVal = _val.val[1] || '';
@@ -307,13 +311,16 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
307
311
  }
308
312
  function addFilter() {
309
313
  if (disabled) return void 0;
310
- var quotes = generateQuotes(rhsVal, curColumn);
311
- typeof onChange === 'function' && onChange(_objectSpread(_objectSpread({}, curColumn), {}, {
314
+ var databaseType = filterCustomType ? special_type : normalizeExpressionAtom(curColumn, data).database_type;
315
+ var nextExpression = normalizeExpressionAtom(_objectSpread(_objectSpread({}, curColumn), {}, {
312
316
  formula: formula,
313
317
  rhs: rhsVal,
314
318
  condition: condition,
315
- quotes: quotes,
316
- database_type: filterCustomType ? special_type : ''
319
+ database_type: databaseType
320
+ }), filterCustomType ? [] : data);
321
+ var quotes = generateQuotes(nextExpression.rhs, nextExpression);
322
+ typeof onChange === 'function' && onChange(_objectSpread(_objectSpread({}, nextExpression), {}, {
323
+ quotes: quotes
317
324
  }));
318
325
  }
319
326
  function goPrevPage() {
@@ -351,6 +358,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
351
358
  if (_val.type === AtomsTypeEnum.INPUT_STRING) {
352
359
  firstVal = _val.val;
353
360
  }
361
+ if (_val.type === AtomsTypeEnum.INPUT_NUMBER) {
362
+ firstVal = _val.val || _val.val === 0 ? String(_val.val) : '';
363
+ }
354
364
  if (_val.type === AtomsTypeEnum.INPUT_STRING_LIST) {
355
365
  firstVal = _val.val[0] || '';
356
366
  secondVal = _val.val[1] || '';
@@ -567,14 +577,36 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
567
577
  })
568
578
  });
569
579
  } else if (~['等于', '不等于', '大于', '小于', '大于或等于', '小于或等于', '包含', '不包含', '以...开始', '以...结束', '不以...开始', '不以...结束', '正则匹配'].indexOf(conditionText)) {
580
+ if (_val.type === AtomsTypeEnum.INPUT_NUMBER) {
581
+ return _jsx("div", {
582
+ className: 'filter-value-control',
583
+ children: _jsx(InputNumber, {
584
+ className: 'filter-number-input',
585
+ placeholder: __('filter.enterANumber'),
586
+ value: firstVal,
587
+ onChange: function onChange(val) {
588
+ var newVal = rhsVal.slice();
589
+ newVal[0] = _objectSpread(_objectSpread({}, newVal[0]), {}, {
590
+ type: AtomsTypeEnum.INPUT_NUMBER,
591
+ val: val === null || val === undefined || val === '' ? Number.NaN : Number(val)
592
+ });
593
+ setRhsVal(newVal);
594
+ }
595
+ })
596
+ });
597
+ }
570
598
  return _jsx("div", {
599
+ className: 'filter-value-control',
571
600
  children: _jsx(Input, {
572
601
  className: 'input',
573
602
  placeholder: __('filter.pleaseEnter'),
574
603
  value: firstVal || '',
575
604
  onInput: function onInput(e) {
576
605
  var newVal = rhsVal.slice();
577
- newVal[0].val = e.target.value;
606
+ newVal[0] = _objectSpread(_objectSpread({}, newVal[0]), {}, {
607
+ type: AtomsTypeEnum.INPUT_STRING,
608
+ val: e.target.value
609
+ });
578
610
  setRhsVal(newVal);
579
611
  }
580
612
  })
@@ -610,7 +642,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
610
642
  });
611
643
  };
612
644
  var onRepeat = function onRepeat(e) {
645
+ var _rhsVal$7;
613
646
  setParentClosable(false);
647
+ var inputAtomType = ((_rhsVal$7 = rhsVal[0]) === null || _rhsVal$7 === void 0 ? void 0 : _rhsVal$7.type) === AtomsTypeEnum.INPUT_NUMBER ? AtomsTypeEnum.INPUT_NUMBER : AtomsTypeEnum.INPUT_STRING;
614
648
  store.setPopup2({
615
649
  visible: true,
616
650
  node: e.currentTarget,
@@ -618,7 +652,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
618
652
  content: _jsx(SelectList, {
619
653
  value: '',
620
654
  list: [{
621
- value: AtomsTypeEnum.INPUT_STRING,
655
+ value: inputAtomType,
622
656
  label: __('customColumn.input')
623
657
  }, {
624
658
  value: AtomsTypeEnum.CONSTANT,
@@ -629,11 +663,15 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
629
663
  }],
630
664
  onChange: function onChange(type) {
631
665
  closePopup2();
632
- if (type === AtomsTypeEnum.INPUT_STRING || type === AtomsTypeEnum.CONSTANT) {
633
- setRhsVal([{
666
+ if (type === AtomsTypeEnum.INPUT_STRING || type === AtomsTypeEnum.INPUT_NUMBER || type === AtomsTypeEnum.CONSTANT) {
667
+ var nextInput = type === AtomsTypeEnum.INPUT_NUMBER ? {
668
+ val: Number.NaN,
669
+ type: AtomsTypeEnum.INPUT_NUMBER
670
+ } : {
634
671
  val: '',
635
672
  type: type
636
- }]);
673
+ };
674
+ setRhsVal([nextInput]);
637
675
  }
638
676
  if (type === AtomsTypeEnum.FIELD) {
639
677
  setRhsVal([{
@@ -802,16 +840,25 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
802
840
  onVisibleChange: setDropdownClosable,
803
841
  getPopupContainer: getCurrentPopupContainer,
804
842
  onChange: function onChange(key) {
843
+ var _rhsVal$8;
805
844
  setCondition('');
806
- setCurColumn(_objectSpread(_objectSpread({}, curColumn), {}, {
807
- rhs: [{
808
- val: '',
809
- type: AtomsTypeEnum.INPUT_STRING
810
- }]
811
- }));
812
- setTimeout(function () {
813
- setSpecial_type(key);
814
- }, 0);
845
+ setSpecial_type(key);
846
+ var currentValue = (_rhsVal$8 = rhsVal[0]) === null || _rhsVal$8 === void 0 ? void 0 : _rhsVal$8.val;
847
+ if (key === SQL_COLUMN_TYPE.FLOAT) {
848
+ var numberValue = Number(currentValue);
849
+ setRhsVal([{
850
+ type: AtomsTypeEnum.INPUT_NUMBER,
851
+ val: currentValue !== '' && Number.isFinite(numberValue) ? numberValue : Number.NaN
852
+ }]);
853
+ } else {
854
+ var _rhsVal$9;
855
+ setRhsVal([_objectSpread({
856
+ type: AtomsTypeEnum.INPUT_STRING,
857
+ val: currentValue === undefined || currentValue === null ? '' : String(currentValue)
858
+ }, key === SQL_COLUMN_TYPE.DATE ? {
859
+ format: ((_rhsVal$9 = rhsVal[0]) === null || _rhsVal$9 === void 0 ? void 0 : _rhsVal$9.format) || 'YYYY-MM-DD HH:mm'
860
+ } : {})]);
861
+ }
815
862
  },
816
863
  droplist: typeList,
817
864
  children: _jsxs(Button, {
@@ -868,7 +915,7 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
868
915
  }, i)
869
916
  }, i);
870
917
  }
871
- if (v.type === AtomsTypeEnum.INPUT_STRING || v.type === AtomsTypeEnum.INPUT_STRING_LIST) {
918
+ if (v.type === AtomsTypeEnum.INPUT_STRING || v.type === AtomsTypeEnum.INPUT_NUMBER || v.type === AtomsTypeEnum.INPUT_STRING_LIST) {
872
919
  return _jsx(React.Fragment, {
873
920
  children: renderFilter(fieldType, condition)
874
921
  }, i);
@@ -898,7 +945,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
898
945
  });
899
946
  }
900
947
  function setDefaultVal(_condition) {
948
+ var _rhsVal$0;
901
949
  setCondition(_condition);
950
+ var inputAtomType = ((_rhsVal$0 = rhsVal[0]) === null || _rhsVal$0 === void 0 ? void 0 : _rhsVal$0.type) === AtomsTypeEnum.INPUT_NUMBER ? AtomsTypeEnum.INPUT_NUMBER : AtomsTypeEnum.INPUT_STRING;
902
951
  if (~['前', '下一个'].indexOf(_condition)) {
903
952
  setRhsVal([{
904
953
  val: ['30', '天'],
@@ -922,7 +971,10 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
922
971
  format: 'YYYY-MM-DD HH:mm'
923
972
  }]);
924
973
  } else {
925
- setRhsVal([{
974
+ setRhsVal(inputAtomType === AtomsTypeEnum.INPUT_NUMBER ? [{
975
+ val: Number.NaN,
976
+ type: AtomsTypeEnum.INPUT_NUMBER
977
+ }] : [{
926
978
  val: '',
927
979
  type: AtomsTypeEnum.INPUT_STRING
928
980
  }]);
@@ -940,9 +992,9 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
940
992
  setIsNext(true);
941
993
  },
942
994
  onSelect: function onSelect(fields, quotes) {
943
- setCurColumn(_objectSpread(_objectSpread({}, curColumn), {}, {
995
+ setCurColumn(normalizeExpressionAtom(_objectSpread(_objectSpread({}, curColumn), {}, {
944
996
  lhs: fields
945
- }));
997
+ }), data));
946
998
  setIsNext(true);
947
999
  }
948
1000
  })
@@ -60,6 +60,7 @@
60
60
  .content {
61
61
  padding: 0.5rem;
62
62
  display: flex;
63
+ gap: 8px;
63
64
  justify-content: space-between;
64
65
  align-items: center;
65
66
  &_l {
@@ -180,6 +181,48 @@
180
181
  .w_300 {
181
182
  width: 300px;
182
183
  }
184
+ .filter-value-control {
185
+ flex: 1;
186
+ min-width: 0;
187
+
188
+ > .input,
189
+ > .filter-number-input {
190
+ width: 100%;
191
+ }
192
+
193
+ .filter-number-input {
194
+ height: 40px;
195
+ padding: 0;
196
+ border: 0;
197
+ border-radius: 4px;
198
+ background: transparent;
199
+
200
+ &.pd-Input,
201
+ .pd-Input,
202
+ .pd-Input-inner-wrapper {
203
+ width: 100%;
204
+ height: 40px;
205
+ box-sizing: border-box;
206
+ border-radius: 4px;
207
+ font-size: 16px;
208
+ color: #4c5773;
209
+ }
210
+
211
+ .pd-Input-inner-wrapper {
212
+ padding: 0 34px 0 20px;
213
+ border: 1px solid #f0f0f0;
214
+ outline: none;
215
+ }
216
+
217
+ .pd-Input {
218
+ height: 100%;
219
+ padding: 0;
220
+ border: 0;
221
+ background: transparent;
222
+ box-shadow: none;
223
+ }
224
+ }
225
+ }
183
226
  .input {
184
227
  border: 1px solid #f0f0f0;
185
228
  font-size: 16px;
@@ -27,7 +27,7 @@ import { buildSqlQuery, getAtomDisplayText, isError, changeCopyField, isExistsEr
27
27
  import Formula from '../formula';
28
28
  import { AddIcon, CloseIcon } from '../../icons';
29
29
  import { Expression, SelectColumnMultiple } from '../../dialog';
30
- import { customTypes, operatorList as __operatorList, insertTemplateAt, getTemplateItem, validateExpressionIntegrity, getConstantLabel } from './utils';
30
+ import { customTypes, operatorList as __operatorList, insertTemplateAt, getTemplateItem, validateExpressionIntegrity, getConstantLabel, normalizeExpressionAtoms } from './utils';
31
31
  import SelectList from '../../dialog/select-list';
32
32
  import arrow from './arrow.svg';
33
33
  import { useStore, Provider } from '../../../hooks/use-provider';
@@ -402,13 +402,26 @@ var FormulaList = forwardRef(function (props, ref) {
402
402
  });
403
403
  return map;
404
404
  }, [otherTypes]);
405
- var normalizedValue = useMemo(function () {
406
- return normalizeAndOrStructure(value || []).map(syncAtomQuotes);
405
+ var normalizedStructureValue = useMemo(function () {
406
+ return normalizeAndOrStructure(value || []);
407
407
  }, [value]);
408
+ var normalizedExpressionValue = useMemo(function () {
409
+ return normalizeExpressionAtoms(normalizedStructureValue, data);
410
+ }, [normalizedStructureValue, data]);
411
+ var normalizedValue = useMemo(function () {
412
+ return normalizedExpressionValue.map(syncAtomQuotes);
413
+ }, [normalizedExpressionValue]);
408
414
  var caseList = normalizedValue;
409
415
  var initialValueRef = useRef(cloneDeep(caseList));
410
416
  var caseListRef = useRef(caseList);
411
417
  caseListRef.current = caseList;
418
+ useEffect(function () {
419
+ if (isEqual(normalizedExpressionValue, normalizedStructureValue)) return;
420
+ var quotes = normalizedValue.map(function (item) {
421
+ return getAtomDisplayText(item);
422
+ }).join(' ');
423
+ onChange === null || onChange === void 0 || onChange(normalizedValue, quotes);
424
+ }, [normalizedExpressionValue, normalizedStructureValue, normalizedValue, onChange]);
412
425
  var hasFormulaSqlAction = Boolean(store.showFormulaSql && store.hasFormulaSqlCode);
413
426
  var hasFormulaDiffAction = Boolean(store.showFormulaDiff && store.hasFormulaDiffCode);
414
427
  var operatorList = useMemo(function () {
@@ -617,8 +630,8 @@ var FormulaList = forwardRef(function (props, ref) {
617
630
  var withSyncedQuotes = function withSyncedQuotes(item) {
618
631
  return _withSyncedQuotesInner(item, new WeakMap());
619
632
  };
620
- var setCaseList = function setCaseList(data) {
621
- var nextData = data.map(function (item) {
633
+ var setCaseList = function setCaseList(atoms) {
634
+ var nextData = normalizeExpressionAtoms(atoms, data).map(function (item) {
622
635
  return withSyncedQuotes(item);
623
636
  });
624
637
  var quotes = nextData.map(function (item) {
@@ -1,4 +1,14 @@
1
- import { AtomsTypeEnum, AtomsItem } from '../../../store/types';
1
+ import { AtomsTypeEnum, AtomsItem, AtomsExpression } from '../../../store/types';
2
+ type ExpressionTable = {
3
+ id?: string;
4
+ name?: string;
5
+ alias?: string;
6
+ tableUuid?: string;
7
+ columns?: any[];
8
+ };
9
+ export declare const getExpressionDatabaseType: (expression: AtomsExpression, tables?: ExpressionTable[]) => string;
10
+ export declare const normalizeExpressionAtom: (expression: AtomsExpression, tables?: ExpressionTable[]) => AtomsExpression;
11
+ export declare const normalizeExpressionAtoms: (atoms?: AtomsItem[], tables?: ExpressionTable[]) => AtomsItem[];
2
12
  export declare const insertTemplateAt: (oldType: string, type: string, list: any[], index: number) => any[];
3
13
  export declare const operatorList: string[];
4
14
  export declare const customTypes: ({
@@ -20,3 +30,4 @@ export declare function validateExpressionIntegrity(list: AtomsItem[]): {
20
30
  isOver?: boolean;
21
31
  };
22
32
  export declare const getConstantLabel: (list: any[], val: string, defaultVal?: string) => any;
33
+ export {};
@@ -1,7 +1,106 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
4
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
5
  import { __ } from '../../../locale';
4
6
  import { AtomsTypeEnum } from '../../../store/types';
7
+ var EMPTY_RHS_CONDITIONS = new Set(['为空', '不为空', '是空的', '不是空的']);
8
+ var isSameValue = function isSameValue(left, right) {
9
+ return left !== undefined && left !== null && left !== '' && right !== undefined && right !== null && right !== '' && String(left) === String(right);
10
+ };
11
+ var findExpressionColumn = function findExpressionColumn(expression) {
12
+ var _expression$lhs;
13
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
14
+ var field = (_expression$lhs = expression.lhs) === null || _expression$lhs === void 0 ? void 0 : _expression$lhs.find(function (item) {
15
+ return item.type === AtomsTypeEnum.FIELD;
16
+ });
17
+ if (!field) return undefined;
18
+ var matchedTable = tables.find(function (table) {
19
+ return isSameValue(field.tableUuid, table.tableUuid) || isSameValue(field.tableId, table.id) || isSameValue(field.tableAlias, table.alias) || isSameValue(field.tableName, table.name);
20
+ });
21
+ var candidateColumns = matchedTable ? matchedTable.columns || [] : tables.flatMap(function (table) {
22
+ return table.columns || [];
23
+ });
24
+ var matchedColumns = candidateColumns.filter(function (column) {
25
+ return isSameValue(field.fieldUuid, column.fieldUuid) || isSameValue(field.fieldId, column.id || column.fieldId) || isSameValue(field.fieldAlias, column.fieldAlias) || isSameValue(field.fieldName, column.name || column.realName);
26
+ });
27
+ return matchedColumns.length === 1 ? matchedColumns[0] : undefined;
28
+ };
29
+ export var getExpressionDatabaseType = function getExpressionDatabaseType(expression) {
30
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
31
+ var column = findExpressionColumn(expression, tables);
32
+ return String((column === null || column === void 0 ? void 0 : column.database_type) || expression.database_type || '').toUpperCase();
33
+ };
34
+ var normalizeExpressionRhs = function normalizeExpressionRhs(expression) {
35
+ if (EMPTY_RHS_CONDITIONS.has(expression.condition)) return [];
36
+ return expression.rhs || [];
37
+ };
38
+ export var normalizeExpressionAtom = function normalizeExpressionAtom(expression) {
39
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
40
+ var databaseType = getExpressionDatabaseType(expression, tables);
41
+ return _objectSpread(_objectSpread({}, expression), {}, {
42
+ lhs: expression.lhs || [],
43
+ rhs: normalizeExpressionRhs(expression),
44
+ database_type: databaseType
45
+ });
46
+ };
47
+ export var normalizeExpressionAtoms = function normalizeExpressionAtoms() {
48
+ var atoms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
49
+ var tables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
50
+ var normalizeList = function normalizeList() {
51
+ var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
52
+ return items.map(normalizeItem);
53
+ };
54
+ var normalizeItem = function normalizeItem(item) {
55
+ if (!item || _typeof(item) !== 'object') return item;
56
+ if (item.type === AtomsTypeEnum.EXPRESSION) {
57
+ var nextExpression = normalizeExpressionAtom(item, tables);
58
+ return _objectSpread(_objectSpread({}, nextExpression), {}, {
59
+ lhs: normalizeList(nextExpression.lhs),
60
+ rhs: normalizeList(nextExpression.rhs)
61
+ });
62
+ }
63
+ if (item.type === AtomsTypeEnum.AND_OR) {
64
+ return _objectSpread(_objectSpread({}, item), {}, {
65
+ items: (item.items || []).map(function (logicItem) {
66
+ return _objectSpread(_objectSpread({}, logicItem), {}, {
67
+ atoms: normalizeList(logicItem.atoms || [])
68
+ });
69
+ })
70
+ });
71
+ }
72
+ if (item.type === AtomsTypeEnum.CASE_WHEN) {
73
+ return _objectSpread(_objectSpread({}, item), {}, {
74
+ caseAtoms: normalizeList(item.caseAtoms || []),
75
+ whenClauses: (item.whenClauses || []).map(function (clause) {
76
+ return _objectSpread(_objectSpread({}, clause), {}, {
77
+ whenAtoms: normalizeList(clause.whenAtoms || []),
78
+ thenAtoms: normalizeList(clause.thenAtoms || [])
79
+ });
80
+ }),
81
+ elseAtoms: normalizeList(item.elseAtoms || [])
82
+ });
83
+ }
84
+ if (item.type === AtomsTypeEnum.FORMULA) {
85
+ return _objectSpread(_objectSpread({}, item), {}, {
86
+ args: normalizeList(item.args || [])
87
+ });
88
+ }
89
+ if (item.type === AtomsTypeEnum.COLLECTION) {
90
+ return _objectSpread(_objectSpread({}, item), {}, {
91
+ list: normalizeList(item.list || [])
92
+ });
93
+ }
94
+ if (item.type === AtomsTypeEnum.JOIN_DEFAULT) {
95
+ return _objectSpread(_objectSpread({}, item), {}, {
96
+ lhs: normalizeList(item.lhs || []),
97
+ rhs: normalizeList(item.rhs || [])
98
+ });
99
+ }
100
+ return item;
101
+ };
102
+ return normalizeList(atoms);
103
+ };
5
104
  export var insertTemplateAt = function insertTemplateAt(oldType, type, list, index) {
6
105
  var temList = [];
7
106
  var needChange = ['RANK()', 'DENSE_RANK()', 'ROW_NUMBER()', 'when', 'case', 'then'].includes(oldType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.157-alpha.6",
3
+ "version": "1.0.157-alpha.7",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",