@platox/pivot-table 0.0.35 → 0.0.37

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.
Files changed (123) hide show
  1. package/es/dashboard-workbench/components/add-module-btn/index.js +14 -5
  2. package/es/dashboard-workbench/components/add-module-btn/index.js.map +1 -1
  3. package/es/dashboard-workbench/components/add-module-modal/add-calendar-modal/custome-data.d.ts +3 -3
  4. package/es/dashboard-workbench/components/add-module-modal/add-calendar-modal/custome-data.js +3 -3
  5. package/es/dashboard-workbench/components/add-module-modal/add-calendar-modal/custome-data.js.map +1 -1
  6. package/es/dashboard-workbench/components/add-module-modal/add-calendar-modal/index.js +4 -4
  7. package/es/dashboard-workbench/components/add-module-modal/add-calendar-modal/index.js.map +1 -1
  8. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/CombinationChartOptionPicker.d.ts +18 -0
  9. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/CombinationChartOptionPicker.js +103 -0
  10. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/CombinationChartOptionPicker.js.map +1 -0
  11. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/GroupFieldConfigPicker.d.ts +14 -0
  12. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/GroupFieldConfigPicker.js +79 -0
  13. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/GroupFieldConfigPicker.js.map +1 -0
  14. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/index.module.less.js +11 -0
  15. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/components/index.module.less.js.map +1 -0
  16. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/config.d.ts +14 -0
  17. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/config.js +153 -0
  18. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/config.js.map +1 -0
  19. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/custome-data.d.ts +1 -21
  20. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/custome-data.js +132 -101
  21. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/custome-data.js.map +1 -1
  22. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/custome-styles.d.ts +0 -6
  23. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/custome-styles.js +2 -4
  24. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/custome-styles.js.map +1 -1
  25. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/index.js +4 -4
  26. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/index.js.map +1 -1
  27. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/index.module.less.js +7 -0
  28. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/index.module.less.js.map +1 -0
  29. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/interface.d.ts +62 -0
  30. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/interface.js +31 -0
  31. package/es/dashboard-workbench/components/add-module-modal/add-chart-modal/interface.js.map +1 -0
  32. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/custome-data.d.ts +3 -3
  33. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/custome-data.js +2 -2
  34. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/custome-data.js.map +1 -1
  35. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/custome-styles.js +16 -11
  36. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/custome-styles.js.map +1 -1
  37. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/index.js +4 -4
  38. package/es/dashboard-workbench/components/add-module-modal/add-statistics-modal/index.js.map +1 -1
  39. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/config.d.ts +30 -0
  40. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/config.js +132 -0
  41. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/config.js.map +1 -0
  42. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/debounce-select.js.map +1 -1
  43. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/index.d.ts +4 -12
  44. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/index.js +6 -200
  45. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/index.js.map +1 -1
  46. package/es/dashboard-workbench/components/add-module-modal/components/condition-modal/interface.d.ts +14 -0
  47. package/es/dashboard-workbench/components/global-filter-condition/ConditionRowItem.d.ts +9 -0
  48. package/es/dashboard-workbench/components/global-filter-condition/ConditionRowItem.js +90 -0
  49. package/es/dashboard-workbench/components/global-filter-condition/ConditionRowItem.js.map +1 -0
  50. package/es/dashboard-workbench/components/global-filter-condition/ConditionSymbolAndValuePicker.d.ts +15 -0
  51. package/es/dashboard-workbench/components/global-filter-condition/ConditionSymbolAndValuePicker.js +218 -0
  52. package/es/dashboard-workbench/components/global-filter-condition/ConditionSymbolAndValuePicker.js.map +1 -0
  53. package/es/dashboard-workbench/components/global-filter-condition/FieldPicker.d.ts +13 -0
  54. package/es/dashboard-workbench/components/global-filter-condition/FieldPicker.js +56 -0
  55. package/es/dashboard-workbench/components/global-filter-condition/FieldPicker.js.map +1 -0
  56. package/es/dashboard-workbench/components/global-filter-condition/index.d.ts +13 -0
  57. package/es/dashboard-workbench/components/global-filter-condition/index.js +311 -0
  58. package/es/dashboard-workbench/components/global-filter-condition/index.js.map +1 -0
  59. package/es/dashboard-workbench/components/global-filter-condition/index.module.less.js +8 -0
  60. package/es/dashboard-workbench/components/global-filter-condition/index.module.less.js.map +1 -0
  61. package/es/dashboard-workbench/components/global-filter-condition/interface.d.ts +9 -0
  62. package/es/dashboard-workbench/components/global-filter-condition/useContext.d.ts +13 -0
  63. package/es/dashboard-workbench/components/global-filter-condition/useContext.js +10 -0
  64. package/es/dashboard-workbench/components/global-filter-condition/useContext.js.map +1 -0
  65. package/es/dashboard-workbench/components/global-filter-condition/util.d.ts +1 -0
  66. package/es/dashboard-workbench/components/global-filter-condition/util.js +7 -0
  67. package/es/dashboard-workbench/components/global-filter-condition/util.js.map +1 -0
  68. package/es/dashboard-workbench/components/{ui/modal/editor-header.js → modal-editor-header/index.js} +4 -4
  69. package/es/dashboard-workbench/components/modal-editor-header/index.js.map +1 -0
  70. package/es/dashboard-workbench/components/modal-editor-header/index.module.less.js +9 -0
  71. package/es/dashboard-workbench/components/module-content/calendar-module/index.js +33 -19
  72. package/es/dashboard-workbench/components/module-content/calendar-module/index.js.map +1 -1
  73. package/es/dashboard-workbench/components/module-content/chart-module/Empty.js +1 -1
  74. package/es/dashboard-workbench/components/module-content/chart-module/Empty.js.map +1 -1
  75. package/es/dashboard-workbench/components/module-content/chart-module/base-chart/index.js +1 -1
  76. package/es/dashboard-workbench/components/module-content/chart-module/base-chart/index.js.map +1 -1
  77. package/es/dashboard-workbench/components/module-content/chart-module/index.d.ts +3 -4
  78. package/es/dashboard-workbench/components/module-content/chart-module/index.js +239 -158
  79. package/es/dashboard-workbench/components/module-content/chart-module/index.js.map +1 -1
  80. package/es/dashboard-workbench/components/module-content/chart-module/utils.d.ts +100 -2
  81. package/es/dashboard-workbench/components/module-content/chart-module/utils.js +66 -13
  82. package/es/dashboard-workbench/components/module-content/chart-module/utils.js.map +1 -1
  83. package/es/dashboard-workbench/components/module-content/index.js +3 -3
  84. package/es/dashboard-workbench/components/module-content/index.js.map +1 -1
  85. package/es/dashboard-workbench/components/module-content/statistics-module/index.d.ts +1 -1
  86. package/es/dashboard-workbench/components/module-content/statistics-module/index.js +17 -7
  87. package/es/dashboard-workbench/components/module-content/statistics-module/index.js.map +1 -1
  88. package/es/dashboard-workbench/components/module-content/text-module/editor/index.js +5 -5
  89. package/es/dashboard-workbench/components/module-content/text-module/editor/index.js.map +1 -1
  90. package/es/dashboard-workbench/components/module-content/utils.d.ts +2 -15
  91. package/es/dashboard-workbench/components/module-content/utils.js.map +1 -1
  92. package/es/dashboard-workbench/components/module-header/index.d.ts +1 -1
  93. package/es/dashboard-workbench/components/module-header/index.js +3 -3
  94. package/es/dashboard-workbench/components/module-header/index.js.map +1 -1
  95. package/es/dashboard-workbench/context.d.ts +21 -9
  96. package/es/dashboard-workbench/context.js +2 -9
  97. package/es/dashboard-workbench/context.js.map +1 -1
  98. package/es/dashboard-workbench/icon/icon-chart-combination.d.ts +3 -0
  99. package/es/dashboard-workbench/icon/icon-chart-combination.js +36 -0
  100. package/es/dashboard-workbench/icon/icon-chart-combination.js.map +1 -0
  101. package/es/dashboard-workbench/index.d.ts +2 -2
  102. package/es/dashboard-workbench/index.js +60 -30
  103. package/es/dashboard-workbench/index.js.map +1 -1
  104. package/es/dashboard-workbench/lang/en-US.d.ts +37 -0
  105. package/es/dashboard-workbench/lang/en-US.js +30 -3
  106. package/es/dashboard-workbench/lang/en-US.js.map +1 -1
  107. package/es/dashboard-workbench/lang/index.js +2 -2
  108. package/es/dashboard-workbench/lang/index.js.map +1 -1
  109. package/es/dashboard-workbench/lang/zh-CN.d.ts +37 -0
  110. package/es/dashboard-workbench/lang/zh-CN.js +30 -3
  111. package/es/dashboard-workbench/lang/zh-CN.js.map +1 -1
  112. package/es/dashboard-workbench/types.d.ts +18 -5
  113. package/es/dashboard-workbench/utils/index.d.ts +6 -4
  114. package/es/dashboard-workbench/utils/index.js +24 -3
  115. package/es/dashboard-workbench/utils/index.js.map +1 -1
  116. package/es/style.css +1 -1
  117. package/package.json +27 -24
  118. package/umd/pivot-table.umd.cjs +75 -75
  119. package/umd/style.css +1 -1
  120. package/es/dashboard-workbench/components/ui/modal/editor-header.js.map +0 -1
  121. package/es/dashboard-workbench/components/ui/modal/index.module.less.js +0 -9
  122. /package/es/dashboard-workbench/components/{ui/modal/editor-header.d.ts → modal-editor-header/index.d.ts} +0 -0
  123. /package/es/dashboard-workbench/components/{ui/modal → modal-editor-header}/index.module.less.js.map +0 -0
@@ -0,0 +1,218 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { Select, Input, InputNumber, DatePicker, Switch } from "antd";
4
+ import { useTranslation } from "react-i18next";
5
+ import { useControllableValue, useMemoizedFn } from "ahooks";
6
+ import dayjs from "dayjs";
7
+ import { useAppContext } from "../../context.js";
8
+ import { useConditionSymbolOptions } from "../add-module-modal/components/condition-modal/config.js";
9
+ import DebounceSelect from "../add-module-modal/components/condition-modal/debounce-select.js";
10
+ const ConditionSymbolAndValuePicker = (props) => {
11
+ var _a, _b, _c, _d;
12
+ const { style, className, field } = props;
13
+ const fieldType = field == null ? void 0 : field.type;
14
+ const { t } = useTranslation();
15
+ const { timeOptions, boolOptions, intOptions, stringOptions, rdateOptions, rdateOptions2 } = useConditionSymbolOptions();
16
+ const conditionOptions = {
17
+ int: intOptions,
18
+ timestamp: timeOptions,
19
+ string: stringOptions,
20
+ bool: boolOptions,
21
+ float: intOptions,
22
+ enum: stringOptions
23
+ };
24
+ const [value, setValue] = useControllableValue(props);
25
+ let symbolOptions = conditionOptions[fieldType] ?? [];
26
+ let symbolDisabled = !(props == null ? void 0 : props.field);
27
+ let symbolValue = value == null ? void 0 : value.condition;
28
+ let symbolOnChange = (v) => {
29
+ setValue({ ...value, condition: v });
30
+ };
31
+ const val = value == null ? void 0 : value.val;
32
+ const val2 = value == null ? void 0 : value.val2;
33
+ const rdate = value == null ? void 0 : value.rdate;
34
+ const enumDataApi = (_b = (_a = useAppContext()) == null ? void 0 : _a.service) == null ? void 0 : _b.enumDataApi;
35
+ const fieldMap = (_d = (_c = useAppContext()) == null ? void 0 : _c.globalData) == null ? void 0 : _d.fieldMap;
36
+ const { options: enumOptions, enumUrl } = useMemo(() => {
37
+ var _a2;
38
+ let options = [];
39
+ let enumUrl2 = void 0;
40
+ if ((field == null ? void 0 : field.type) === "enum") {
41
+ options = ((_a2 = field == null ? void 0 : field.enum) == null ? void 0 : _a2.map((item) => ({
42
+ label: (fieldMap == null ? void 0 : fieldMap[item.label]) ?? item.label,
43
+ value: item.value
44
+ }))) ?? [];
45
+ enumUrl2 = field == null ? void 0 : field.dynamic_call_enum_api;
46
+ }
47
+ return {
48
+ options,
49
+ enumUrl: enumUrl2
50
+ };
51
+ }, [field, fieldMap]);
52
+ const handleConditionValueChange = useMemoizedFn((key, v) => {
53
+ var _a2;
54
+ let _v = ((_a2 = v == null ? void 0 : v.target) == null ? void 0 : _a2.value) ?? v;
55
+ setValue({ ...value, [key]: _v });
56
+ });
57
+ const getVaildValue = (v, type, defaultValue) => {
58
+ let ret = defaultValue;
59
+ switch (type) {
60
+ case "number":
61
+ return typeof v === "number" ? v : ret;
62
+ case "dayjs":
63
+ return v instanceof dayjs ? v : ret;
64
+ case "boolean":
65
+ return typeof v === "boolean" ? v : ret;
66
+ case "string":
67
+ return typeof v === "string" ? v : ret;
68
+ default:
69
+ return v;
70
+ }
71
+ };
72
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
73
+ /* @__PURE__ */ jsx(
74
+ Select,
75
+ {
76
+ style: { width: "100px" },
77
+ disabled: symbolDisabled,
78
+ options: symbolOptions,
79
+ value: symbolValue,
80
+ onChange: symbolOnChange
81
+ }
82
+ ),
83
+ !fieldType && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Input, { style: { width: "100px" }, disabled: true }) }),
84
+ !!fieldType && /* @__PURE__ */ jsxs(Fragment, { children: [
85
+ ["int", "float"].includes(fieldType) && !["null", "notnull"].includes(symbolValue) ? /* @__PURE__ */ jsxs(Fragment, { children: [
86
+ /* @__PURE__ */ jsx(
87
+ InputNumber,
88
+ {
89
+ style: { width: "100px" },
90
+ placeholder: t("pleaseEnter"),
91
+ value: getVaildValue(val),
92
+ onChange: (v) => {
93
+ handleConditionValueChange("val", v);
94
+ }
95
+ }
96
+ ),
97
+ symbolValue === "contain" ? /* @__PURE__ */ jsx(
98
+ InputNumber,
99
+ {
100
+ style: { width: "100px", marginLeft: "5px" },
101
+ placeholder: t("pleaseEnter"),
102
+ value: getVaildValue(val2),
103
+ onChange: (v) => {
104
+ handleConditionValueChange("val2", v);
105
+ }
106
+ }
107
+ ) : null
108
+ ] }) : null,
109
+ fieldType === "timestamp" && !["null", "notnull"].includes(symbolValue) ? /* @__PURE__ */ jsxs(Fragment, { children: [
110
+ symbolValue === "=" || symbolValue === "<" || symbolValue === ">" ? /* @__PURE__ */ jsx(
111
+ Select,
112
+ {
113
+ showSearch: true,
114
+ optionFilterProp: "label",
115
+ style: { width: "150px" },
116
+ options: symbolValue === "=" ? rdateOptions : rdateOptions2,
117
+ value: getVaildValue(rdate),
118
+ onChange: (v) => {
119
+ handleConditionValueChange("rdate", v);
120
+ }
121
+ }
122
+ ) : null,
123
+ rdate === "exactdate" ? /* @__PURE__ */ jsx(
124
+ DatePicker,
125
+ {
126
+ style: { width: "150px" },
127
+ value: getVaildValue(val, "dayjs"),
128
+ onChange: (v) => {
129
+ handleConditionValueChange("val", v);
130
+ }
131
+ }
132
+ ) : null,
133
+ symbolValue === "contain" ? /* @__PURE__ */ jsx(
134
+ DatePicker,
135
+ {
136
+ style: { width: "150px", marginLeft: "5px" },
137
+ value: getVaildValue(val2, "dayjs"),
138
+ onChange: (v) => {
139
+ handleConditionValueChange("val2", v);
140
+ }
141
+ }
142
+ ) : null
143
+ ] }) : null,
144
+ ["string"].includes(fieldType) && !["null", "notnull"].includes(symbolValue) ? /* @__PURE__ */ jsxs(Fragment, { children: [
145
+ /* @__PURE__ */ jsx(
146
+ Input,
147
+ {
148
+ style: { width: "150px" },
149
+ placeholder: t("pleaseEnter"),
150
+ value: getVaildValue(val),
151
+ onChange: (v) => {
152
+ handleConditionValueChange("val", v);
153
+ }
154
+ }
155
+ ),
156
+ symbolValue === "contain" ? /* @__PURE__ */ jsx(
157
+ Input,
158
+ {
159
+ style: { width: "150px", marginLeft: "5px" },
160
+ placeholder: t("pleaseEnter"),
161
+ value: getVaildValue(val2, "dayjs"),
162
+ onChange: (v) => {
163
+ handleConditionValueChange("val2", v);
164
+ }
165
+ }
166
+ ) : null
167
+ ] }) : null,
168
+ ["bool"].includes(fieldType) ? /* @__PURE__ */ jsx(
169
+ Switch,
170
+ {
171
+ value: getVaildValue(val, "boolean"),
172
+ onChange: (v) => {
173
+ handleConditionValueChange("val", v);
174
+ }
175
+ }
176
+ ) : null,
177
+ ["enum"].includes(fieldType) && !["null", "notnull"].includes(symbolValue) ? /* @__PURE__ */ jsx(Fragment, { children: enumOptions && (enumOptions == null ? void 0 : enumOptions.length) > 0 ? /* @__PURE__ */ jsx(
178
+ Select,
179
+ {
180
+ showSearch: true,
181
+ optionFilterProp: "label",
182
+ style: { width: "150px" },
183
+ options: enumOptions,
184
+ value: getVaildValue(val),
185
+ onChange: (v) => {
186
+ handleConditionValueChange("val", v);
187
+ }
188
+ }
189
+ ) : enumUrl ? /* @__PURE__ */ jsx(
190
+ DebounceSelect,
191
+ {
192
+ style: { width: "150px" },
193
+ value: getVaildValue(val),
194
+ onChange: (v) => {
195
+ handleConditionValueChange("val", v);
196
+ },
197
+ fetchOptions: async (value2) => {
198
+ var _a2;
199
+ let dfUrl = enumUrl;
200
+ if (value2) {
201
+ dfUrl = `${dfUrl}?q=${value2}`;
202
+ }
203
+ return await ((_a2 = enumDataApi == null ? void 0 : enumDataApi(dfUrl)) == null ? void 0 : _a2.then((res) => {
204
+ var _a3;
205
+ return (_a3 = res.data) == null ? void 0 : _a3.list;
206
+ })) ?? [];
207
+ }
208
+ }
209
+ ) : null }) : null
210
+ ] })
211
+ ] });
212
+ };
213
+ ConditionSymbolAndValuePicker.displayName = "ConditionSymbolAndValuePicker";
214
+ export {
215
+ ConditionSymbolAndValuePicker,
216
+ ConditionSymbolAndValuePicker as default
217
+ };
218
+ //# sourceMappingURL=ConditionSymbolAndValuePicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConditionSymbolAndValuePicker.js","sources":["../../../../packages/dashboard-workbench/components/global-filter-condition/ConditionSymbolAndValuePicker.tsx"],"sourcesContent":["import { ChangeEventHandler, useEffect, useMemo, useState, type CSSProperties } from 'react'\nimport { DatePicker, Input, InputNumber, Select, Switch } from 'antd'\nimport { useTranslation } from 'react-i18next'\nimport { useControllableValue, useMemoizedFn } from 'ahooks'\nimport dayjs, { Dayjs } from 'dayjs'\nimport { useAppContext } from '../../context'\nimport { FieldItem } from '../../types'\nimport { useConditionSymbolOptions } from '../add-module-modal/components/condition-modal/config'\nimport DebounceSelect from '../add-module-modal/components/condition-modal/debounce-select'\nimport { ConditionListItemWrapper } from './interface'\n\nexport type ConditionSymbolAndValuePickerProps = {\n style?: CSSProperties\n className?: string\n\n field?: FieldItem\n\n value?: Omit<ConditionListItemWrapper, 'field'>\n onChange: (value: Omit<ConditionListItemWrapper, 'field'>) => void\n}\n\nexport const ConditionSymbolAndValuePicker = (props: ConditionSymbolAndValuePickerProps) => {\n const { style, className, field } = props\n const fieldType = field?.type\n\n const { t } = useTranslation()\n\n const { timeOptions, boolOptions, intOptions, stringOptions, rdateOptions, rdateOptions2 } =\n useConditionSymbolOptions()\n\n const conditionOptions = {\n int: intOptions,\n timestamp: timeOptions,\n string: stringOptions,\n bool: boolOptions,\n float: intOptions,\n enum: stringOptions,\n }\n\n const [value, setValue] = useControllableValue(props)\n\n /* ============================== symbol =============================== */\n let symbolOptions = conditionOptions[fieldType as keyof typeof conditionOptions] ?? []\n let symbolDisabled = !props?.field\n let symbolValue = value?.condition\n let symbolOnChange = (v: string) => {\n setValue({ ...value, condition: v })\n }\n\n /* ============================== condition value =============================== */\n const val = value?.val\n const val2 = value?.val2\n const rdate = value?.rdate\n\n const enumDataApi = useAppContext()?.service?.enumDataApi\n const fieldMap = useAppContext()?.globalData?.fieldMap\n const { options: enumOptions, enumUrl } = useMemo(() => {\n let options: {\n label: unknown\n value: unknown\n }[] = []\n let enumUrl: string | undefined = undefined\n\n if (field?.type === 'enum') {\n options =\n field?.enum?.map(item => ({\n label: fieldMap?.[item.label] ?? item.label,\n value: item.value,\n })) ?? []\n enumUrl = field?.dynamic_call_enum_api\n }\n return {\n options,\n enumUrl,\n }\n }, [field, fieldMap])\n\n const handleConditionValueChange = useMemoizedFn((key: 'val' | 'val2' | 'rdate', v: unknown) => {\n //@ts-ignore\n let _v = v?.target?.value ?? v\n\n setValue({ ...value, [key]: _v })\n })\n const getVaildValue = <T,>(\n v: unknown,\n type?: 'string' | 'number' | 'dayjs' | 'boolean',\n defaultValue?: T\n ) => {\n let ret = defaultValue\n\n switch (type) {\n case 'number':\n return (typeof v === 'number' ? v : ret) as T\n case 'dayjs':\n return (v instanceof dayjs ? v : ret) as T\n case 'boolean':\n return (typeof v === 'boolean' ? v : ret) as T\n case 'string':\n return (typeof v === 'string' ? v : ret) as T\n default:\n return v as T\n }\n }\n\n /* ============================== 默认值 =============================== */\n // useEffect(() => {\n // if (!!field?.value && !value?.condition) {\n // const initialValues: Omit<ConditionListItemWrapper, 'field'> = {\n // condition: '=',\n // val: '',\n // val2: '',\n // rdate: 'exactdate',\n // }\n // setValue({\n // ...initialValues,\n // })\n // }\n // }, [field?.value])\n\n return (\n <>\n <Select\n style={{ width: '100px' }}\n disabled={symbolDisabled}\n options={symbolOptions}\n value={symbolValue}\n onChange={symbolOnChange}\n />\n {!fieldType && (\n <>\n <Input style={{ width: '100px' }} disabled />\n </>\n )}\n\n {!!fieldType && (\n <>\n {['int', 'float'].includes(fieldType) && !['null', 'notnull'].includes(symbolValue) ? (\n <>\n <InputNumber\n style={{ width: '100px' }}\n placeholder={t('pleaseEnter')}\n value={getVaildValue(val)}\n onChange={v => {\n handleConditionValueChange('val', v)\n }}\n />\n {symbolValue === 'contain' ? (\n <InputNumber\n style={{ width: '100px', marginLeft: '5px' }}\n placeholder={t('pleaseEnter')}\n value={getVaildValue(val2)}\n onChange={v => {\n handleConditionValueChange('val2', v)\n }}\n />\n ) : null}\n </>\n ) : null}\n\n {fieldType === 'timestamp' && !['null', 'notnull'].includes(symbolValue) ? (\n <>\n {symbolValue === '=' || symbolValue === '<' || symbolValue === '>' ? (\n <Select\n showSearch\n optionFilterProp=\"label\"\n style={{ width: '150px' }}\n options={symbolValue === '=' ? rdateOptions : rdateOptions2}\n value={getVaildValue(rdate)}\n onChange={v => {\n handleConditionValueChange('rdate', v)\n }}\n />\n ) : null}\n\n {rdate === 'exactdate' ? (\n <DatePicker\n style={{ width: '150px' }}\n value={getVaildValue(val, 'dayjs')}\n onChange={v => {\n handleConditionValueChange('val', v)\n }}\n />\n ) : null}\n\n {symbolValue === 'contain' ? (\n <DatePicker\n style={{ width: '150px', marginLeft: '5px' }}\n value={getVaildValue(val2, 'dayjs')}\n onChange={v => {\n handleConditionValueChange('val2', v)\n }}\n />\n ) : null}\n </>\n ) : null}\n\n {['string'].includes(fieldType) && !['null', 'notnull'].includes(symbolValue) ? (\n <>\n <Input\n style={{ width: '150px' }}\n placeholder={t('pleaseEnter')}\n value={getVaildValue(val)}\n onChange={v => {\n handleConditionValueChange('val', v)\n }}\n />\n {symbolValue === 'contain' ? (\n <Input\n style={{ width: '150px', marginLeft: '5px' }}\n placeholder={t('pleaseEnter')}\n value={getVaildValue(val2, 'dayjs')}\n onChange={v => {\n handleConditionValueChange('val2', v)\n }}\n />\n ) : null}\n </>\n ) : null}\n\n {['bool'].includes(fieldType) ? (\n <Switch\n value={getVaildValue(val, 'boolean')}\n onChange={v => {\n handleConditionValueChange('val', v)\n }}\n />\n ) : null}\n\n {['enum'].includes(fieldType) && !['null', 'notnull'].includes(symbolValue) ? (\n <>\n {enumOptions && enumOptions?.length > 0 ? (\n <Select\n showSearch\n optionFilterProp=\"label\"\n style={{ width: '150px' }}\n options={enumOptions}\n value={getVaildValue(val)}\n onChange={v => {\n handleConditionValueChange('val', v)\n }}\n />\n ) : enumUrl ? (\n <DebounceSelect<{ label: string; value: string }>\n style={{ width: '150px' }}\n value={getVaildValue(val)}\n onChange={v => {\n handleConditionValueChange('val', v)\n }}\n fetchOptions={async value => {\n let dfUrl = enumUrl\n if (value) {\n dfUrl = `${dfUrl}?q=${value}`\n }\n return (await enumDataApi?.(dfUrl)?.then(res => res.data?.list)) ?? []\n }}\n />\n ) : null}\n </>\n ) : null}\n </>\n )}\n </>\n )\n}\n\nConditionSymbolAndValuePicker.displayName = 'ConditionSymbolAndValuePicker'\n\nexport default ConditionSymbolAndValuePicker\n"],"names":["enumUrl","_a","value"],"mappings":";;;;;;;;;AAqBa,MAAA,gCAAgC,CAAC,UAA8C;;AAC1F,QAAM,EAAE,OAAO,WAAW,MAAU,IAAA;AACpC,QAAM,YAAY,+BAAO;AAEnB,QAAA,EAAE,EAAE,IAAI,eAAe;AAEvB,QAAA,EAAE,aAAa,aAAa,YAAY,eAAe,cAAc,kBACzE,0BAA0B;AAE5B,QAAM,mBAAmB;AAAA,IACvB,KAAK;AAAA,IACL,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAEA,QAAM,CAAC,OAAO,QAAQ,IAAI,qBAAqB,KAAK;AAGpD,MAAI,gBAAgB,iBAAiB,SAA0C,KAAK,CAAC;AACjF,MAAA,iBAAiB,EAAC,+BAAO;AAC7B,MAAI,cAAc,+BAAO;AACrB,MAAA,iBAAiB,CAAC,MAAc;AAClC,aAAS,EAAE,GAAG,OAAO,WAAW,GAAG;AAAA,EACrC;AAGA,QAAM,MAAM,+BAAO;AACnB,QAAM,OAAO,+BAAO;AACpB,QAAM,QAAQ,+BAAO;AAEf,QAAA,eAAc,+BAAA,mBAAiB,YAAjB,mBAA0B;AACxC,QAAA,YAAW,+BAAA,mBAAiB,eAAjB,mBAA6B;AAC9C,QAAM,EAAE,SAAS,aAAa,QAAQ,IAAI,QAAQ,MAAM;;AACtD,QAAI,UAGE,CAAC;AACP,QAAIA,WAA8B;AAE9B,SAAA,+BAAO,UAAS,QAAQ;AAExB,kBAAAC,MAAA,+BAAO,SAAP,gBAAAA,IAAa,IAAI,CAAS,UAAA;AAAA,QACxB,QAAO,qCAAW,KAAK,WAAU,KAAK;AAAA,QACtC,OAAO,KAAK;AAAA,MACd,QAAO,CAAC;AACVD,iBAAU,+BAAO;AAAA,IAAA;AAEZ,WAA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,UAAA;AAAA,QACrC;AAAA,UAEA,UACF;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,OAAO,EAAE,OAAO,QAAQ;AAAA,UACxB,OAAO,cAAc,GAAG;AAAA,UACxB,UAAU,CAAK,MAAA;AACb,uCAA2B,OAAO,CAAC;AAAA,UACrC;AAAA,UACA,cAAc,OAAMC,WAAS;;AAC3B,gBAAI,QAAQ;AACZ,gBAAIA,QAAO;AACD,sBAAA,GAAG,KAAK,MAAMA,MAAK;AAAA,YAAA;AAErB,mBAAA,QAAMD,MAAA,2CAAc,WAAd,gBAAAA,IAAsB,KAAK;;AAAO,sBAAAA,MAAA,IAAI,SAAJ,gBAAAA,IAAU;AAAA,mBAAU,CAAC;AAAA,UAAA;AAAA,QACvE;AAAA,MAAA,IAEA,KACN,CAAA,IACE;AAAA,IAAA,EACN,CAAA;AAAA,EAAA,GAEJ;AAEJ;AAEA,8BAA8B,cAAc;"}
@@ -0,0 +1,13 @@
1
+ export type FiledPickerValue = {
2
+ dataSourceId: string;
3
+ field: string;
4
+ };
5
+ export type FieldPickerDataSourceItem = {
6
+ key: string;
7
+ label: string;
8
+ children: FieldPickerDataSourceItem[];
9
+ };
10
+ export declare const FieldPicker: (props: {
11
+ value?: FiledPickerValue;
12
+ onChange?: (value: FiledPickerValue) => void;
13
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,56 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { Dropdown, Select } from "antd";
4
+ import { useTranslation } from "react-i18next";
5
+ import { useControllableValue, useMemoizedFn } from "ahooks";
6
+ import { useContext } from "./useContext.js";
7
+ import { getMergeId } from "./util.js";
8
+ const FieldPicker = (props) => {
9
+ var _a, _b;
10
+ const { t } = useTranslation();
11
+ const { fieldPickerDataSource: dataSource, flattenFieldMap } = useContext();
12
+ const [value, onChange] = useControllableValue(props);
13
+ const handleClick = useMemoizedFn((props2) => {
14
+ const [mergeField, dataSourceId] = props2.keyPath;
15
+ let field = mergeField == null ? void 0 : mergeField.replace(`${dataSourceId}-`, "");
16
+ if (!!field) {
17
+ onChange({
18
+ dataSourceId,
19
+ field
20
+ });
21
+ }
22
+ });
23
+ const selectField = useMemo(() => {
24
+ {
25
+ let mergeField = getMergeId(value == null ? void 0 : value.dataSourceId, value == null ? void 0 : value.field);
26
+ let selectField2 = flattenFieldMap == null ? void 0 : flattenFieldMap.get(mergeField);
27
+ return selectField2;
28
+ }
29
+ }, [value, flattenFieldMap]);
30
+ return /* @__PURE__ */ jsx(
31
+ Dropdown,
32
+ {
33
+ trigger: ["click"],
34
+ menu: {
35
+ selectable: true,
36
+ selectedKeys: selectField ? [(_a = selectField == null ? void 0 : selectField.source) == null ? void 0 : _a.value, selectField == null ? void 0 : selectField.mergeId] : [],
37
+ items: dataSource,
38
+ onClick: handleClick
39
+ // getPopupContainer:(node)=>(node.parentNode??document.body) as HTMLElement
40
+ },
41
+ children: /* @__PURE__ */ jsx(
42
+ Select,
43
+ {
44
+ open: false,
45
+ placeholder: t("selectGroupField"),
46
+ style: { width: 200 },
47
+ value: ((_b = selectField == null ? void 0 : selectField.field) == null ? void 0 : _b.label) ?? void 0
48
+ }
49
+ )
50
+ }
51
+ );
52
+ };
53
+ export {
54
+ FieldPicker
55
+ };
56
+ //# sourceMappingURL=FieldPicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FieldPicker.js","sources":["../../../../packages/dashboard-workbench/components/global-filter-condition/FieldPicker.tsx"],"sourcesContent":["import React, { useMemo, useState } from 'react'\nimport { Button, Dropdown, MenuProps, Popover, Select } from 'antd'\nimport { ItemType, MenuItemGroupType, MenuItemType, SubMenuType } from 'antd/es/menu/interface'\nimport { useTranslation } from 'react-i18next'\nimport { useControllableValue, useMemoizedFn } from 'ahooks'\nimport { useContext } from './useContext'\nimport { getMergeId } from './util'\n\nexport type FiledPickerValue = {\n dataSourceId: string\n field: string\n}\n\nexport type FieldPickerDataSourceItem = {\n key: string\n label: string\n children: FieldPickerDataSourceItem[]\n}\n\nexport const FieldPicker = (props: {\n value?: FiledPickerValue\n onChange?: (value: FiledPickerValue) => void\n}) => {\n const { t } = useTranslation()\n const { fieldPickerDataSource: dataSource, flattenFieldMap } = useContext()\n\n const [value, onChange] = useControllableValue<FiledPickerValue>(props)\n\n const handleClick: MenuProps['onClick'] = useMemoizedFn(props => {\n const [mergeField, dataSourceId] = props.keyPath\n let field = mergeField?.replace(`${dataSourceId}-`, '')\n\n if (!!field) {\n onChange({\n dataSourceId: dataSourceId,\n field: field,\n })\n }\n })\n\n const selectField = useMemo(() => {\n {\n let mergeField = getMergeId(value?.dataSourceId, value?.field)\n let selectField = flattenFieldMap?.get(mergeField)\n return selectField\n }\n }, [value, flattenFieldMap])\n\n return (\n <Dropdown\n trigger={['click']}\n menu={{\n selectable: true,\n selectedKeys: selectField ? [selectField?.source?.value, selectField?.mergeId] : [],\n items: dataSource,\n onClick: handleClick,\n // getPopupContainer:(node)=>(node.parentNode??document.body) as HTMLElement\n }}\n >\n <Select\n open={false}\n placeholder={t('selectGroupField')}\n style={{ width: 200 }}\n value={selectField?.field?.label ?? undefined}\n />\n </Dropdown>\n )\n}\n"],"names":["props","selectField"],"mappings":";;;;;;;AAmBa,MAAA,cAAc,CAAC,UAGtB;;AACE,QAAA,EAAE,EAAE,IAAI,eAAe;AAC7B,QAAM,EAAE,uBAAuB,YAAY,gBAAA,IAAoB,WAAW;AAE1E,QAAM,CAAC,OAAO,QAAQ,IAAI,qBAAuC,KAAK;AAEhE,QAAA,cAAoC,cAAc,CAAAA,WAAS;AAC/D,UAAM,CAAC,YAAY,YAAY,IAAIA,OAAM;AACzC,QAAI,QAAQ,yCAAY,QAAQ,GAAG,YAAY,KAAK;AAEhD,QAAA,CAAC,CAAC,OAAO;AACF,eAAA;AAAA,QACP;AAAA,QACA;AAAA,MAAA,CACD;AAAA,IAAA;AAAA,EACH,CACD;AAEK,QAAA,cAAc,QAAQ,MAAM;AAChC;AACE,UAAI,aAAa,WAAW,+BAAO,cAAc,+BAAO,KAAK;AACzDC,UAAAA,eAAc,mDAAiB,IAAI;AAChCA,aAAAA;AAAAA,IAAA;AAAA,EACT,GACC,CAAC,OAAO,eAAe,CAAC;AAGzB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,SAAS,CAAC,OAAO;AAAA,MACjB,MAAM;AAAA,QACJ,YAAY;AAAA,QACZ,cAAc,cAAc,EAAC,gDAAa,WAAb,mBAAqB,OAAO,2CAAa,OAAO,IAAI,CAAC;AAAA,QAClF,OAAO;AAAA,QACP,SAAS;AAAA;AAAA,MAEX;AAAA,MAEA,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,MAAM;AAAA,UACN,aAAa,EAAE,kBAAkB;AAAA,UACjC,OAAO,EAAE,OAAO,IAAI;AAAA,UACpB,SAAO,gDAAa,UAAb,mBAAoB,UAAS;AAAA,QAAA;AAAA,MAAA;AAAA,IACtC;AAAA,EACF;AAEJ;"}
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ import { ConditionBlockWrapper } from './interface';
3
+ export interface GlobalFilterConditionProps {
4
+ className?: string;
5
+ style?: React.CSSProperties;
6
+ }
7
+ export declare const GlobalFilterCondition: React.FC<GlobalFilterConditionProps>;
8
+ export default GlobalFilterCondition;
9
+ export type PopoverContentProps = {
10
+ defaultValue?: ConditionBlockWrapper[];
11
+ onClose?: (isOk: boolean, data?: ConditionBlockWrapper[]) => void;
12
+ };
13
+ export declare const PopoverContent: (props: PopoverContentProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,311 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useMemo, useEffect } from "react";
3
+ import clsx from "clsx";
4
+ import { Popover, Button, Select } from "antd";
5
+ import { FilterOutlined, PlusOutlined } from "@ant-design/icons";
6
+ import { useTranslation } from "react-i18next";
7
+ import { useMemoizedFn } from "ahooks";
8
+ import { cloneDeep, isEqual } from "lodash-es";
9
+ import { useAppContext } from "../../context.js";
10
+ import { useConditionTypeOptions } from "../add-module-modal/components/condition-modal/config.js";
11
+ import { ConditionRowItem } from "./ConditionRowItem.js";
12
+ import styles from "./index.module.less.js";
13
+ import { Context, useContext } from "./useContext.js";
14
+ import { getMergeId } from "./util.js";
15
+ const componentName = "global-filter-condition";
16
+ const Empty = [];
17
+ const GlobalFilterCondition = (props) => {
18
+ const { className, style } = props;
19
+ const { t } = useTranslation();
20
+ const { globalFilterCondition, setGlobalFilterCondition } = useAppContext();
21
+ const [open, setOpen] = useState(false);
22
+ const { globalData } = useAppContext();
23
+ const { fieldPickerDataSource, flattenFieldMap } = useMemo(() => {
24
+ let flattenFieldMap2 = /* @__PURE__ */ new Map();
25
+ let fieldPickerDataSource2 = ((globalData == null ? void 0 : globalData.sourceData) || []).map((item) => {
26
+ let children = ((item == null ? void 0 : item.fields) || []).map((v) => {
27
+ let mergeId = getMergeId(item == null ? void 0 : item.value, v == null ? void 0 : v.value);
28
+ flattenFieldMap2.set(mergeId, {
29
+ field: v,
30
+ source: item,
31
+ mergeId
32
+ });
33
+ return {
34
+ key: mergeId,
35
+ label: v == null ? void 0 : v.label,
36
+ // 没有props 可以传到submenu里面 写在这里写死
37
+ style: {
38
+ minWidth: "160px"
39
+ }
40
+ };
41
+ });
42
+ return {
43
+ key: item == null ? void 0 : item.value,
44
+ label: item == null ? void 0 : item.label,
45
+ children
46
+ };
47
+ });
48
+ return {
49
+ fieldPickerDataSource: fieldPickerDataSource2,
50
+ flattenFieldMap: flattenFieldMap2
51
+ };
52
+ }, [globalData == null ? void 0 : globalData.sourceData]);
53
+ return /* @__PURE__ */ jsx(
54
+ Context.Provider,
55
+ {
56
+ value: {
57
+ fieldPickerDataSource,
58
+ flattenFieldMap
59
+ },
60
+ children: /* @__PURE__ */ jsx("div", { className: clsx(styles[`${componentName}`], className), style, children: /* @__PURE__ */ jsx(
61
+ Popover,
62
+ {
63
+ content: /* @__PURE__ */ jsx(
64
+ PopoverContent,
65
+ {
66
+ defaultValue: globalFilterCondition,
67
+ onClose: (isOk, data) => {
68
+ if (isOk) {
69
+ setGlobalFilterCondition(data);
70
+ }
71
+ setOpen(false);
72
+ }
73
+ }
74
+ ),
75
+ destroyTooltipOnHide: true,
76
+ placement: "bottomRight",
77
+ trigger: "click",
78
+ open,
79
+ onOpenChange: setOpen,
80
+ children: /* @__PURE__ */ jsxs(Button, { children: [
81
+ /* @__PURE__ */ jsx(FilterOutlined, {}),
82
+ t("filter"),
83
+ ((globalFilterCondition == null ? void 0 : globalFilterCondition.length) ?? 0) > 0 ? `(${globalFilterCondition == null ? void 0 : globalFilterCondition.length})` : ""
84
+ ] })
85
+ }
86
+ ) })
87
+ }
88
+ );
89
+ };
90
+ GlobalFilterCondition.displayName = "GlobalFilterCondition";
91
+ const PopoverContent = (props) => {
92
+ const { defaultValue } = props;
93
+ const { t } = useTranslation();
94
+ const fieldPickerDataSource = useContext().fieldPickerDataSource;
95
+ const conditionTypeOptions = useConditionTypeOptions();
96
+ const [value = Empty, setValue] = useState([]);
97
+ useEffect(() => {
98
+ if (defaultValue) {
99
+ setValue(cloneDeep(defaultValue));
100
+ }
101
+ }, [defaultValue]);
102
+ const [emptyBlockList, setEmptyBlockList] = useState([]);
103
+ const handleEmptyBlockListChange = (newItem) => {
104
+ if (newItem == null ? void 0 : newItem.field) {
105
+ setValue((prev) => {
106
+ let ret = [...prev];
107
+ let match = ret.find((item) => item.dataSourceId === newItem.dataSourceId);
108
+ if (match) {
109
+ match.conditionList.push(newItem);
110
+ return [...ret];
111
+ } else {
112
+ let newConditionBlockWrapper = {
113
+ dataSourceId: newItem.dataSourceId,
114
+ conditionType: "all",
115
+ conditionList: [newItem]
116
+ };
117
+ return [...ret, newConditionBlockWrapper];
118
+ }
119
+ });
120
+ }
121
+ };
122
+ const handleAddEmptyBlock = () => {
123
+ setEmptyBlockList([...emptyBlockList, {}]);
124
+ };
125
+ const hasChange = useMemo(() => {
126
+ return !isEqual(value, defaultValue);
127
+ }, [value, defaultValue]);
128
+ const handleSubmit = useMemoizedFn(() => {
129
+ var _a;
130
+ (_a = props == null ? void 0 : props.onClose) == null ? void 0 : _a.call(props, true, value);
131
+ });
132
+ return /* @__PURE__ */ jsxs("div", { className: clsx(styles[`${componentName}__popover`]), children: [
133
+ /* @__PURE__ */ jsx(
134
+ "div",
135
+ {
136
+ style: {
137
+ marginBottom: "10px"
138
+ },
139
+ children: t("setFilterCondition")
140
+ }
141
+ ),
142
+ value.map((item, index) => {
143
+ var _a;
144
+ let conditionList = item == null ? void 0 : item.conditionList;
145
+ let dataSourceName = (_a = fieldPickerDataSource == null ? void 0 : fieldPickerDataSource.find((v) => v.key === (item == null ? void 0 : item.dataSourceId))) == null ? void 0 : _a.label;
146
+ return /* @__PURE__ */ jsxs("div", { className: clsx(styles[`${componentName}__block`]), children: [
147
+ /* @__PURE__ */ jsxs(
148
+ "div",
149
+ {
150
+ style: {
151
+ marginBottom: "10px",
152
+ display: "flex",
153
+ justifyContent: "space-between"
154
+ },
155
+ children: [
156
+ /* @__PURE__ */ jsx("div", { children: dataSourceName }),
157
+ /* @__PURE__ */ jsxs(
158
+ "div",
159
+ {
160
+ style: {
161
+ display: "flex",
162
+ alignItems: "center",
163
+ gap: "5px"
164
+ },
165
+ children: [
166
+ t("conformTo"),
167
+ /* @__PURE__ */ jsx(
168
+ Select,
169
+ {
170
+ style: { width: "80px" },
171
+ options: conditionTypeOptions,
172
+ value: item == null ? void 0 : item.conditionType,
173
+ onChange: (v) => {
174
+ setValue((prev) => {
175
+ let ret = [...prev];
176
+ ret[index].conditionType = v;
177
+ return ret;
178
+ });
179
+ }
180
+ }
181
+ ),
182
+ t("addCondition")
183
+ ]
184
+ }
185
+ )
186
+ ]
187
+ }
188
+ ),
189
+ /* @__PURE__ */ jsx(
190
+ "div",
191
+ {
192
+ style: {
193
+ display: "flex",
194
+ flexDirection: "column",
195
+ gap: "10px"
196
+ },
197
+ children: conditionList.map((v, conditionIndex) => {
198
+ return /* @__PURE__ */ jsx(
199
+ ConditionRowItem,
200
+ {
201
+ value: v,
202
+ onChange: (newValue) => {
203
+ setValue((prev) => {
204
+ let ret = [...prev];
205
+ let prevItem = ret[index].conditionList[conditionIndex];
206
+ if ((prevItem == null ? void 0 : prevItem.dataSourceId) !== (newValue == null ? void 0 : newValue.dataSourceId)) {
207
+ ret[index].conditionList.splice(conditionIndex, 1);
208
+ if (ret[index].conditionList.length === 0) {
209
+ ret.splice(index, 1);
210
+ }
211
+ let newItem = newValue;
212
+ let match = ret.find((item2) => item2.dataSourceId === newItem.dataSourceId);
213
+ if (match) {
214
+ match.conditionList.push(newItem);
215
+ return [...ret];
216
+ } else {
217
+ let newConditionBlockWrapper = {
218
+ dataSourceId: newItem.dataSourceId,
219
+ conditionType: "all",
220
+ conditionList: [newItem]
221
+ };
222
+ return [...ret, newConditionBlockWrapper];
223
+ }
224
+ } else {
225
+ ret[index].conditionList[conditionIndex] = {
226
+ ...prevItem,
227
+ ...newValue
228
+ };
229
+ }
230
+ return ret;
231
+ });
232
+ },
233
+ onDelete: () => {
234
+ setValue((prev) => {
235
+ let ret = [...prev];
236
+ ret[index].conditionList.splice(conditionIndex, 1);
237
+ if (ret[index].conditionList.length === 0) {
238
+ ret.splice(index, 1);
239
+ }
240
+ return ret;
241
+ });
242
+ }
243
+ },
244
+ conditionIndex
245
+ );
246
+ })
247
+ }
248
+ )
249
+ ] }, item == null ? void 0 : item.dataSourceId);
250
+ }),
251
+ emptyBlockList.map((item, index) => {
252
+ return /* @__PURE__ */ jsx("div", { className: clsx(styles[`${componentName}__block`]), children: /* @__PURE__ */ jsx(
253
+ ConditionRowItem,
254
+ {
255
+ value: item,
256
+ onChange: (newValue) => {
257
+ handleEmptyBlockListChange(newValue);
258
+ },
259
+ onDelete: () => {
260
+ setEmptyBlockList((prev) => {
261
+ let ret = [...prev];
262
+ ret.splice(index, 1);
263
+ return ret;
264
+ });
265
+ }
266
+ }
267
+ ) }, index);
268
+ }),
269
+ /* @__PURE__ */ jsx(
270
+ Button,
271
+ {
272
+ type: "dashed",
273
+ block: true,
274
+ style: {
275
+ marginBottom: "10px"
276
+ },
277
+ icon: /* @__PURE__ */ jsx(PlusOutlined, {}),
278
+ onClick: () => {
279
+ handleAddEmptyBlock();
280
+ },
281
+ children: t("addCondition")
282
+ }
283
+ ),
284
+ /* @__PURE__ */ jsx(
285
+ "div",
286
+ {
287
+ style: {
288
+ display: "flex",
289
+ justifyContent: "flex-end"
290
+ },
291
+ children: /* @__PURE__ */ jsx(
292
+ Button,
293
+ {
294
+ type: "primary",
295
+ disabled: !hasChange,
296
+ onClick: () => {
297
+ handleSubmit();
298
+ },
299
+ children: t("confirm")
300
+ }
301
+ )
302
+ }
303
+ )
304
+ ] });
305
+ };
306
+ export {
307
+ GlobalFilterCondition,
308
+ PopoverContent,
309
+ GlobalFilterCondition as default
310
+ };
311
+ //# sourceMappingURL=index.js.map