@gingkoo/pandora-metabase 1.0.104 → 1.0.106

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.
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ interface DateRangeFormatPickerProps {
3
+ value?: string[];
4
+ format?: string;
5
+ onChange?: (val: string[], format?: string) => void;
6
+ }
7
+ export declare const DateRangeFormatPicker: React.FC<DateRangeFormatPickerProps>;
8
+ interface DateFormatPickerProps {
9
+ value?: string;
10
+ format?: string;
11
+ onChange?: (val: string, format?: string) => void;
12
+ }
13
+ export declare const DateFormatPicker: React.FC<DateFormatPickerProps>;
14
+ export {};
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DateRangeFormatPicker = exports.DateFormatPicker = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ var _react = require("react");
11
+ var _pandora = require("@gingkoo/pandora");
12
+ var _dayjs = _interopRequireDefault(require("dayjs"));
13
+ var RangePicker = _pandora.DatePicker.RangePicker,
14
+ YearPicker = _pandora.DatePicker.YearPicker,
15
+ MonthPicker = _pandora.DatePicker.MonthPicker;
16
+ var DATE_FORMAT_OPTIONS = [{
17
+ value: 'YYYY',
18
+ label: 'YYYY'
19
+ }, {
20
+ value: 'YYYY-MM',
21
+ label: 'YYYY-MM'
22
+ }, {
23
+ value: 'YYYY-MM-DD',
24
+ label: 'YYYY-MM-DD'
25
+ }, {
26
+ value: 'YYYY-MM-DD HH:mm',
27
+ label: 'YYYY-MM-DD HH:mm'
28
+ }, {
29
+ value: 'YYYY/MM',
30
+ label: 'YYYY/MM'
31
+ }, {
32
+ value: 'YYYY/MM/DD',
33
+ label: 'YYYY/MM/DD'
34
+ }, {
35
+ value: 'YYYY/MM/DD HH:mm',
36
+ label: 'YYYY/MM/DD HH:mm'
37
+ }];
38
+ var DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm';
39
+ var DateRangeFormatPicker = exports.DateRangeFormatPicker = function DateRangeFormatPicker(_ref) {
40
+ var value = _ref.value,
41
+ format = _ref.format,
42
+ onChange = _ref.onChange;
43
+ var _useState = (0, _react.useState)(format || DEFAULT_FORMAT),
44
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
45
+ currentFormat = _useState2[0],
46
+ setCurrentFormat = _useState2[1];
47
+ (0, _react.useEffect)(function () {
48
+ if (format) {
49
+ setCurrentFormat(format);
50
+ }
51
+ }, [format]);
52
+ var showTime = currentFormat.includes('HH:mm');
53
+ // 根据格式确定 RangePicker 的 mode
54
+ var getRangePickerMode = function getRangePickerMode() {
55
+ if (currentFormat === 'YYYY') return 'year';
56
+ if (currentFormat === 'YYYY-MM' || currentFormat === 'YYYY/MM') return 'month';
57
+ return 'date';
58
+ };
59
+ var handleFormatChange = function handleFormatChange(newFormat) {
60
+ // 切换格式时,用新格式重新格式化当前值
61
+ if (value && value.length > 0) {
62
+ var formattedValues = value.map(function (v) {
63
+ if (!v) return '';
64
+ var parsed = (0, _dayjs["default"])(v);
65
+ if (!parsed.isValid()) return '';
66
+ return parsed.format(newFormat);
67
+ });
68
+ // 只调用 onChange,传递新格式化的值和新格式
69
+ onChange === null || onChange === void 0 || onChange(formattedValues, newFormat);
70
+ }
71
+ setCurrentFormat(newFormat);
72
+ };
73
+ // 将字符串数组转为 dayjs 对象数组,供 RangePicker 使用
74
+ var rangeValue = (value === null || value === void 0 ? void 0 : value.map(function (v) {
75
+ if (!v) return null;
76
+ // 尝试用当前格式解析,失败则用 dayjs 默认解析
77
+ var parsed = (0, _dayjs["default"])(v, currentFormat, true);
78
+ if (parsed.isValid()) return parsed;
79
+ // 尝试不用严格模式解析
80
+ var looseParsed = (0, _dayjs["default"])(v, currentFormat);
81
+ if (looseParsed.isValid()) return looseParsed;
82
+ // 最后尝试不指定格式
83
+ var anyParsed = (0, _dayjs["default"])(v);
84
+ return anyParsed.isValid() ? anyParsed : null;
85
+ })) || undefined;
86
+ var handleRangeChange = function handleRangeChange(date, dateString) {
87
+ // 确保日期值按 currentFormat 格式化
88
+ var formattedValues = (date === null || date === void 0 ? void 0 : date.map(function (d) {
89
+ if (!d || !(0, _dayjs["default"])(d).isValid()) return '';
90
+ return (0, _dayjs["default"])(d).format(currentFormat);
91
+ })) || dateString;
92
+ onChange === null || onChange === void 0 || onChange(formattedValues, currentFormat);
93
+ };
94
+ return (0, _jsxRuntime.jsxs)("div", {
95
+ style: {
96
+ display: 'flex',
97
+ gap: 4
98
+ },
99
+ children: [(0, _jsxRuntime.jsx)(_pandora.Select, {
100
+ style: {
101
+ width: 120
102
+ },
103
+ value: currentFormat,
104
+ onChange: handleFormatChange,
105
+ children: DATE_FORMAT_OPTIONS.map(function (option) {
106
+ return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
107
+ value: option.value,
108
+ children: option.label
109
+ }, option.value);
110
+ })
111
+ }), (0, _jsxRuntime.jsx)(RangePicker, {
112
+ value: rangeValue,
113
+ onChange: handleRangeChange,
114
+ style: {
115
+ flex: 1
116
+ },
117
+ format: currentFormat,
118
+ showTime: showTime,
119
+ mode: getRangePickerMode()
120
+ })]
121
+ });
122
+ };
123
+ var DateFormatPicker = exports.DateFormatPicker = function DateFormatPicker(_ref2) {
124
+ var value = _ref2.value,
125
+ format = _ref2.format,
126
+ onChange = _ref2.onChange;
127
+ var _useState3 = (0, _react.useState)(format || DEFAULT_FORMAT),
128
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
129
+ currentFormat = _useState4[0],
130
+ setCurrentFormat = _useState4[1];
131
+ (0, _react.useEffect)(function () {
132
+ if (format) {
133
+ setCurrentFormat(format);
134
+ }
135
+ }, [format]);
136
+ var showTime = currentFormat.includes('HH:mm');
137
+ var isYearOnly = currentFormat === 'YYYY';
138
+ var isMonthOnly = currentFormat === 'YYYY-MM' || currentFormat === 'YYYY/MM';
139
+ var handleFormatChange = function handleFormatChange(newFormat) {
140
+ // 切换格式时,用新格式重新格式化当前值
141
+ if (value) {
142
+ var parsed = (0, _dayjs["default"])(value);
143
+ if (parsed.isValid()) {
144
+ onChange === null || onChange === void 0 || onChange(parsed.format(newFormat), newFormat);
145
+ }
146
+ }
147
+ setCurrentFormat(newFormat);
148
+ };
149
+ // 将字符串转为 dayjs 对象,使用宽松解析
150
+ var dateValue = function () {
151
+ if (!value) return undefined;
152
+ var parsed = (0, _dayjs["default"])(value, currentFormat, true);
153
+ if (parsed.isValid()) return parsed;
154
+ var looseParsed = (0, _dayjs["default"])(value, currentFormat);
155
+ if (looseParsed.isValid()) return looseParsed;
156
+ var anyParsed = (0, _dayjs["default"])(value);
157
+ return anyParsed.isValid() ? anyParsed : undefined;
158
+ }();
159
+ var handleDateChange = function handleDateChange(dateString) {
160
+ onChange === null || onChange === void 0 || onChange(dateString, currentFormat);
161
+ };
162
+ var handleYearChange = function handleYearChange(dateString) {
163
+ onChange === null || onChange === void 0 || onChange(dateString, currentFormat);
164
+ };
165
+ var handleMonthChange = function handleMonthChange(dateString) {
166
+ onChange === null || onChange === void 0 || onChange(dateString, currentFormat);
167
+ };
168
+ // 根据格式渲染不同的选择器
169
+ var renderPicker = function renderPicker() {
170
+ if (isYearOnly) {
171
+ return (0, _jsxRuntime.jsx)(YearPicker, {
172
+ value: dateValue,
173
+ onChange: handleYearChange,
174
+ style: {
175
+ flex: 1
176
+ }
177
+ });
178
+ }
179
+ if (isMonthOnly) {
180
+ return (0, _jsxRuntime.jsx)(MonthPicker, {
181
+ value: dateValue,
182
+ onChange: handleMonthChange,
183
+ style: {
184
+ flex: 1
185
+ },
186
+ format: currentFormat
187
+ });
188
+ }
189
+ return (0, _jsxRuntime.jsx)(_pandora.DatePicker, {
190
+ value: dateValue,
191
+ onChange: handleDateChange,
192
+ style: {
193
+ flex: 1
194
+ },
195
+ format: currentFormat,
196
+ showTime: showTime
197
+ });
198
+ };
199
+ return (0, _jsxRuntime.jsxs)("div", {
200
+ style: {
201
+ display: 'flex',
202
+ gap: 4
203
+ },
204
+ children: [(0, _jsxRuntime.jsx)(_pandora.Select, {
205
+ style: {
206
+ width: 120
207
+ },
208
+ value: currentFormat,
209
+ onChange: handleFormatChange,
210
+ children: DATE_FORMAT_OPTIONS.map(function (option) {
211
+ return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
212
+ value: option.value,
213
+ children: option.label
214
+ }, option.value);
215
+ })
216
+ }), renderPicker()]
217
+ });
218
+ };
@@ -0,0 +1,5 @@
1
+ export declare const DATE_FORMAT_OPTIONS: {
2
+ value: string;
3
+ label: string;
4
+ }[];
5
+ export declare const DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH:mm";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DEFAULT_DATE_FORMAT = exports.DATE_FORMAT_OPTIONS = void 0;
7
+ var DATE_FORMAT_OPTIONS = exports.DATE_FORMAT_OPTIONS = [{
8
+ value: 'YYYY-MM',
9
+ label: 'YYYY-MM'
10
+ }, {
11
+ value: 'YYYY-MM-DD',
12
+ label: 'YYYY-MM-DD'
13
+ }, {
14
+ value: 'YYYY-MM-DD HH:mm',
15
+ label: 'YYYY-MM-DD HH:mm'
16
+ }, {
17
+ value: 'YYYY/MM',
18
+ label: 'YYYY/MM'
19
+ }, {
20
+ value: 'YYYY/MM/DD',
21
+ label: 'YYYY/MM/DD'
22
+ }, {
23
+ value: 'YYYY/MM/DD HH:mm',
24
+ label: 'YYYY/MM/DD HH:mm'
25
+ }];
26
+ var DEFAULT_DATE_FORMAT = exports.DEFAULT_DATE_FORMAT = 'YYYY-MM-DD HH:mm';
@@ -27,12 +27,12 @@ var _useProvider = require("../../../hooks/use-provider");
27
27
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
28
28
  var _utils = require("../formula-list/utils");
29
29
  var _itemName = _interopRequireDefault(require("../../modules/components/item-name"));
30
+ var _dateFormatPicker = require("./date-format-picker");
30
31
  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); }
31
32
  /**
32
33
  * 关联模块 选择表字段
33
34
  */
34
35
 
35
- var RangePicker = _pandora.DatePicker.RangePicker;
36
36
  var NUMBER_LIST = ['等于', '不等于', '大于', '小于', '介于之间', '大于或等于', '小于或等于', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
37
37
  var STRING_LIST = ['等于', '不等于', '包含', '不包含', '为空', '不为空', '以...开始', '以...结束', '不以...开始', '不以...结束', 'In', 'Not In', '正则匹配'];
38
38
  var DATE_LIST = [
@@ -395,23 +395,21 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
395
395
  });
396
396
  }
397
397
  if (type === _enum.SQL_GROUP_TYPE.DATE) {
398
- return (0, _jsxRuntime.jsx)("div", {
399
- children: (0, _jsxRuntime.jsx)(RangePicker, {
400
- showTime: {
401
- format: 'HH:mm'
402
- },
403
- format: 'YYYY-MM-DD HH:mm',
404
- className: 'w_300',
405
- // @ts-ignore
406
- value: firstVal ? [(0, _dayjs["default"])(firstVal !== null && firstVal !== void 0 ? firstVal : undefined), (0, _dayjs["default"])(secondVal !== null && secondVal !== void 0 ? secondVal : undefined)] : [],
407
- onChange: function onChange(val) {
408
- // @ts-ignore
409
- val && setRhsVal([{
398
+ var _rhsVal$, _rhsVal$2;
399
+ var dateVal = ((_rhsVal$ = rhsVal[0]) === null || _rhsVal$ === void 0 ? void 0 : _rhsVal$.type) === _types.AtomsTypeEnum.INPUT_STRING_LIST ? rhsVal[0].val : undefined;
400
+ var dateFormat = ((_rhsVal$2 = rhsVal[0]) === null || _rhsVal$2 === void 0 ? void 0 : _rhsVal$2.type) === _types.AtomsTypeEnum.INPUT_STRING_LIST ? rhsVal[0].format : undefined;
401
+ return (0, _jsxRuntime.jsx)(_dateFormatPicker.DateRangeFormatPicker, {
402
+ value: dateVal,
403
+ format: dateFormat,
404
+ onChange: function onChange(val, format) {
405
+ if (val) {
406
+ setRhsVal([{
410
407
  type: _types.AtomsTypeEnum.INPUT_STRING_LIST,
411
- val: [(0, _dayjs["default"])(val[0]).format('YYYY-MM-DD HH:mm'), (0, _dayjs["default"])(val[1]).format('YYYY-MM-DD HH:mm')]
408
+ val: val,
409
+ format: format
412
410
  }]);
413
411
  }
414
- })
412
+ }
415
413
  });
416
414
  }
417
415
  } else if (conditionText === '当前') {
@@ -496,58 +494,50 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
496
494
  })]
497
495
  });
498
496
  } else if (~['早于', '晚于', '在'].indexOf(conditionText)) {
499
- return (0, _jsxRuntime.jsx)("div", {
500
- children: (0, _jsxRuntime.jsx)(_pandora.DatePicker, {
501
- showTime: {
502
- format: 'HH:mm'
503
- },
504
- format: 'YYYY-MM-DD HH:mm',
505
- className: 'w_300',
506
- value: firstVal ? (0, _dayjs["default"])(firstVal) : '',
507
- onChange: function onChange(val) {
508
- if (val) {
509
- setRhsVal([{
510
- type: _types.AtomsTypeEnum.INPUT_STRING,
511
- val: (0, _dayjs["default"])(val).format('YYYY-MM-DD HH:mm')
512
- }
513
- // {
514
- // type: AtomsTypeEnum.INPUT_STRING,
515
- // val: moment(val).format('YYYY-MM-DD HH:mm'),
516
- // },
517
- ]);
518
- } else {
519
- setRhsVal([{
520
- val: '',
521
- type: _types.AtomsTypeEnum.INPUT_STRING
522
- }]);
523
- // setVal([]);
524
- }
497
+ var _rhsVal$3, _rhsVal$4;
498
+ var _dateVal = ((_rhsVal$3 = rhsVal[0]) === null || _rhsVal$3 === void 0 ? void 0 : _rhsVal$3.type) === _types.AtomsTypeEnum.INPUT_STRING ? rhsVal[0].val : undefined;
499
+ var _dateFormat = ((_rhsVal$4 = rhsVal[0]) === null || _rhsVal$4 === void 0 ? void 0 : _rhsVal$4.type) === _types.AtomsTypeEnum.INPUT_STRING ? rhsVal[0].format : undefined;
500
+ return (0, _jsxRuntime.jsx)(_dateFormatPicker.DateFormatPicker, {
501
+ value: _dateVal,
502
+ format: _dateFormat,
503
+ onChange: function onChange(val, format) {
504
+ if (val) {
505
+ setRhsVal([{
506
+ type: _types.AtomsTypeEnum.INPUT_STRING,
507
+ val: val,
508
+ format: format
509
+ }]);
510
+ } else {
511
+ setRhsVal([{
512
+ val: '',
513
+ type: _types.AtomsTypeEnum.INPUT_STRING,
514
+ format: format
515
+ }]);
525
516
  }
526
- })
517
+ }
527
518
  });
528
519
  } else if (~['等于'].indexOf(conditionText) && type === _enum.SQL_GROUP_TYPE.DATE) {
529
- return (0, _jsxRuntime.jsx)("div", {
530
- children: (0, _jsxRuntime.jsx)(_pandora.DatePicker, {
531
- showTime: {
532
- format: 'HH:mm'
533
- },
534
- format: 'YYYY-MM-DD HH:mm',
535
- className: 'w_300',
536
- value: firstVal ? (0, _dayjs["default"])(firstVal) : '',
537
- onChange: function onChange(val) {
538
- if (val) {
539
- setRhsVal([{
540
- type: _types.AtomsTypeEnum.INPUT_STRING,
541
- val: (0, _dayjs["default"])(val).format('YYYY-MM-DD HH:mm')
542
- }]);
543
- } else {
544
- setRhsVal([{
545
- val: '',
546
- type: _types.AtomsTypeEnum.INPUT_STRING
547
- }]);
548
- }
520
+ var _rhsVal$5, _rhsVal$6;
521
+ var _dateVal2 = ((_rhsVal$5 = rhsVal[0]) === null || _rhsVal$5 === void 0 ? void 0 : _rhsVal$5.type) === _types.AtomsTypeEnum.INPUT_STRING ? rhsVal[0].val : undefined;
522
+ var _dateFormat2 = ((_rhsVal$6 = rhsVal[0]) === null || _rhsVal$6 === void 0 ? void 0 : _rhsVal$6.type) === _types.AtomsTypeEnum.INPUT_STRING ? rhsVal[0].format : undefined;
523
+ return (0, _jsxRuntime.jsx)(_dateFormatPicker.DateFormatPicker, {
524
+ value: _dateVal2,
525
+ format: _dateFormat2,
526
+ onChange: function onChange(val, format) {
527
+ if (val) {
528
+ setRhsVal([{
529
+ type: _types.AtomsTypeEnum.INPUT_STRING,
530
+ val: val,
531
+ format: format
532
+ }]);
533
+ } else {
534
+ setRhsVal([{
535
+ val: '',
536
+ type: _types.AtomsTypeEnum.INPUT_STRING,
537
+ format: format
538
+ }]);
549
539
  }
550
- })
540
+ }
551
541
  });
552
542
  } else if (~['In', 'Not In'].indexOf(conditionText)) {
553
543
  var options = firstVal ? firstVal.split(',') : [];
@@ -930,7 +920,8 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
930
920
  } else if (~['介于之间'].indexOf(_condition)) {
931
921
  setRhsVal([{
932
922
  val: ['', ''],
933
- type: _types.AtomsTypeEnum.INPUT_STRING_LIST
923
+ type: _types.AtomsTypeEnum.INPUT_STRING_LIST,
924
+ format: 'YYYY-MM-DD HH:mm'
934
925
  }]);
935
926
  } else if (~['当前'].indexOf(_condition)) {
936
927
  setRhsVal([{
@@ -940,7 +931,8 @@ var SelectFilterColumn = function SelectFilterColumn(_ref) {
940
931
  } else if (~['早于', '晚于', '在'].indexOf(_condition)) {
941
932
  setRhsVal([{
942
933
  val: (0, _dayjs["default"])().format('YYYY-MM-DD HH:mm'),
943
- type: _types.AtomsTypeEnum.INPUT_STRING
934
+ type: _types.AtomsTypeEnum.INPUT_STRING,
935
+ format: 'YYYY-MM-DD HH:mm'
944
936
  }]);
945
937
  } else {
946
938
  setRhsVal([{
@@ -355,11 +355,16 @@ var NextDom = function NextDom(props) {
355
355
  var handlePaste = function handlePaste() {
356
356
  var _store$metaList3;
357
357
  var index = (_store$metaList3 = store.metaList) === null || _store$metaList3 === void 0 || (_store$metaList3 = _store$metaList3[groupIndex]) === null || _store$metaList3 === void 0 || (_store$metaList3 = _store$metaList3.list) === null || _store$metaList3 === void 0 ? void 0 : _store$metaList3.indexOf(meta);
358
- store.addMeta('', index + 1, groupIndex, store.metabaseCopyModule);
359
- // 粘贴后重置
360
- store.setMetabaseCopyModule([]);
361
- store.setIsMetabaseCopy(false);
362
- _storage["default"]._metabaseCopyModule = [];
358
+ var success = store.addMeta('', index + 1, groupIndex, store.metabaseCopyModule, function (conflictingAlias) {
359
+ // 冲突提示
360
+ _pandora.Toast.warning("".concat(conflictingAlias, " \u7684 table1 \u4E0E\u7C98\u8D34\u4F4D\u7F6E\u76F8\u90BB\u9879\u51B2\u7A81\uFF0C\u8BF7\u8C03\u6574\u540E\u518D\u7C98\u8D34"));
361
+ });
362
+ // 仅在成功时重置
363
+ if (success) {
364
+ store.setMetabaseCopyModule([]);
365
+ store.setIsMetabaseCopy(false);
366
+ _storage["default"]._metabaseCopyModule = [];
367
+ }
363
368
  };
364
369
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
365
370
  children: [store.metabaseCopyModule && store.metabaseCopyModule.length > 0 && isShowAdd && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {