awing-library 2.1.161-dev → 2.1.163-dev

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.
@@ -53,10 +53,11 @@ var Customer = function (props) {
53
53
  // noBorder
54
54
  label: t('Common.View'), callback: function (value) {
55
55
  var _a, _b;
56
- return changeQueryInput('time', {
57
- startDate: (0, Helpers_1.getStartOfDay)((_a = value === null || value === void 0 ? void 0 : value.startDate) === null || _a === void 0 ? void 0 : _a.toDate()),
58
- endDate: (0, Helpers_1.getStartOfDay)((_b = value === null || value === void 0 ? void 0 : value.endDate) === null || _b === void 0 ? void 0 : _b.toDate()),
59
- });
56
+ Object.values(value).filter(Boolean).length > 1 &&
57
+ changeQueryInput('time', {
58
+ startDate: (0, Helpers_1.getStartOfDay)((_a = value === null || value === void 0 ? void 0 : value.startDate) === null || _a === void 0 ? void 0 : _a.toDate()),
59
+ endDate: (0, Helpers_1.getStartOfDay)((_b = value === null || value === void 0 ? void 0 : value.endDate) === null || _b === void 0 ? void 0 : _b.toDate()),
60
+ });
60
61
  }, initialStartDate: (0, moment_1.default)(queryInput.time.startDate), initialEndDate: (0, moment_1.default)(queryInput.time.endDate), isShowCalendarInfo: true, variant: "outlined", textFieldProps: {
61
62
  fullWidth: true,
62
63
  sx: {
@@ -125,7 +125,7 @@ function SubCampaignDetail(props) {
125
125
  ? subCampaign.bonusAmount < 0
126
126
  ? translationText.notNegative
127
127
  : translationText.helperText
128
- : '' }) }), service.attributesGetByObjectTypeCode ? ((0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, style: { padding: 8 }, children: (0, jsx_runtime_1.jsx)(material_1.TextField, { id: "billingUnit", required: true, select: true, variant: "standard", fullWidth: true, label: translationText.BillingUnit, value: String(subCampaign.billingUnit), onChange: function (e) {
128
+ : '' }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, style: { padding: 8 }, children: (0, jsx_runtime_1.jsx)(material_1.TextField, { id: "billingUnit", required: true, select: true, variant: "standard", fullWidth: true, label: translationText.BillingUnit, value: String(subCampaign.billingUnit), onChange: function (e) {
129
129
  onSubCampaignChange(function (pre) { return (__assign(__assign({}, pre), { billingUnit: Number(e.target.value) })); });
130
130
  }, error: subValid.billingUnit !== undefined &&
131
131
  !subValid.billingUnit, helperText: subValid.billingUnit !== undefined &&
@@ -133,7 +133,7 @@ function SubCampaignDetail(props) {
133
133
  ? translationText.helperText
134
134
  : '', children: Object.values(Enum_2.AnalyticType)
135
135
  .filter(function (item) { return !isNaN(Number(item)); })
136
- .map(function (type) { return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: type, children: t("Campaign.BillingUnit.".concat((0, lodash_1.capitalize)((0, lodash_1.camelCase)(Enum_2.AnalyticType[type])))) }, type)); }) }) })) : null] })), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, style: { padding: 8 }, children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { control: (0, jsx_runtime_1.jsx)(material_1.Checkbox, { checked: subCampaign.isReserved, onChange: function (e) {
136
+ .map(function (type) { return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: type, children: t("Campaign.BillingUnit.".concat((0, lodash_1.capitalize)((0, lodash_1.camelCase)(Enum_2.AnalyticType[type])))) }, type)); }) }) })] })), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, style: { padding: 8 }, children: (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { control: (0, jsx_runtime_1.jsx)(material_1.Checkbox, { checked: subCampaign.isReserved, onChange: function (e) {
137
137
  e.persist();
138
138
  onSubCampaignChange(function (pre) { return (__assign(__assign({}, pre), { isReserved: e.target.checked })); });
139
139
  }, name: "isReserved", color: "primary" }), label: translationText.reserved, style: { marginTop: 6 } }) })] })] }));
@@ -122,9 +122,7 @@ var ViewContent = function (_a) {
122
122
  setScriptAutoField(res.template.autoField || '');
123
123
  };
124
124
  // eslint-disable-next-line react-hooks/exhaustive-deps
125
- var setChanged = react_1.default.useCallback((0, lodash_1.debounce)(function () {
126
- onChange(['isChanged'], true);
127
- }, 300), []);
125
+ var setChanged = function () { onChange(['isChanged'], true); };
128
126
  var handleOnChange = function (fieldPath, templateDatasUpdated) {
129
127
  var _a;
130
128
  var keys = fieldPath.split('.');
@@ -1,6 +1,6 @@
1
+ import { ITemplateType } from '../../../../ACM-AXN/Template/Types';
1
2
  import React from 'react';
2
3
  import { ViewModel } from '../../Types';
3
- import { ITemplateType } from '../../../../ACM-AXN/Template/Types';
4
4
  interface ViewInfoProps {
5
5
  templateTypes: ITemplateType[];
6
6
  onChange: (keys: string[], value: unknown) => void;
@@ -10,47 +10,24 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
15
  };
39
16
  Object.defineProperty(exports, "__esModule", { value: true });
40
17
  var jsx_runtime_1 = require("react/jsx-runtime");
41
- var react_1 = __importStar(require("react"));
42
- var AWING_1 = require("../../../../AWING");
43
- var react_i18next_1 = require("react-i18next");
44
- var Context_1 = __importDefault(require("../../Context"));
18
+ var Constant_1 = require("../../../../ACM-AXN/Common/Constant");
19
+ var Constant_2 = require("../../../../ACM-AXN/Page/Constant");
45
20
  var lodash_1 = require("lodash");
46
- var enums_1 = require("../../enums");
47
- var Utils_1 = require("../Utils");
48
- var Constant_1 = require("../../../../ACM-AXN/Page/Constant");
21
+ var react_1 = __importDefault(require("react"));
22
+ var react_i18next_1 = require("react-i18next");
49
23
  var react_router_dom_1 = require("react-router-dom");
50
24
  var recoil_1 = require("recoil");
51
- var Recoil_1 = require("../Recoil");
52
- var Constant_2 = require("../../../../ACM-AXN/Common/Constant");
25
+ var AWING_1 = require("../../../../AWING");
26
+ var Context_1 = __importDefault(require("../../Context"));
27
+ var enums_1 = require("../../enums");
53
28
  var ListenTemplate_1 = require("../ListenTemplate");
29
+ var Recoil_1 = require("../Recoil");
30
+ var Utils_1 = require("../Utils");
54
31
  var ViewInfo = function (_a) {
55
32
  var templateTypes = _a.templateTypes, onChange = _a.onChange, viewInfoData = _a.viewInfoData, viewNumber = _a.viewNumber;
56
33
  var pageId = (0, react_router_dom_1.useParams)().pageId;
@@ -64,14 +41,6 @@ var ViewInfo = function (_a) {
64
41
  var _d = react_1.default.useState([]), templates = _d[0], setTemplates = _d[1];
65
42
  var _e = react_1.default.useState(false), loadingTemplate = _e[0], setLoadingTemplate = _e[1];
66
43
  var defaultDirectory = react_1.default.useMemo(function () { return directories.find(function (item) { return item.parentDirectoryId === '99'; }); }, [directories]);
67
- (0, react_1.useEffect)(function () {
68
- var savedDirectoryId = JSON.parse(localStorage.getItem(Constant_1.PAGE_LOGIN_DIRECTORY_SELECTED) || '{}')[Array.isArray(domainId) ? 'awingPge' : domainId];
69
- if (savedDirectoryId && !pageId && !isMounted) {
70
- setIsMounted(true);
71
- handleChangeForm({ directoryId: savedDirectoryId }, true, 'directoryId');
72
- }
73
- // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, []);
75
44
  var overWriteOnChange = function (keys, value) {
76
45
  if (keys.includes('templateId')) {
77
46
  setDeprecated(false);
@@ -84,7 +53,7 @@ var ViewInfo = function (_a) {
84
53
  return;
85
54
  if (['templateTypeId', 'directoryId'].includes(keyUpdate)) {
86
55
  if (keyUpdate === 'directoryId') {
87
- localStorage.setItem(Constant_1.PAGE_LOGIN_DIRECTORY_SELECTED, JSON.stringify((_a = {}, _a[Array.isArray(domainId) ? 'awingPge' : domainId] = obj[keyUpdate], _a)));
56
+ localStorage.setItem(Constant_2.PAGE_LOGIN_DIRECTORY_SELECTED, JSON.stringify((_a = {}, _a[Array.isArray(domainId) ? 'awingPge' : domainId] = obj[keyUpdate], _a)));
88
57
  }
89
58
  overWriteOnChange(['templateId'], '');
90
59
  }
@@ -93,6 +62,14 @@ var ViewInfo = function (_a) {
93
62
  },
94
63
  // eslint-disable-next-line react-hooks/exhaustive-deps
95
64
  []);
65
+ react_1.default.useEffect(function () {
66
+ var savedDirectoryId = JSON.parse(localStorage.getItem(Constant_2.PAGE_LOGIN_DIRECTORY_SELECTED) || '{}')[Array.isArray(domainId) ? 'awingPge' : domainId];
67
+ if (savedDirectoryId && !pageId && !isMounted) {
68
+ setIsMounted(true);
69
+ handleChangeForm({ directoryId: savedDirectoryId }, true, 'directoryId');
70
+ }
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps
72
+ }, []);
96
73
  react_1.default.useEffect(function () {
97
74
  var fieldsRequireStatus = !(0, Utils_1.getFieldsValid)(viewInfoData.viewDatas).includes(false);
98
75
  onChange(['fieldsRequireStatus'], fieldsRequireStatus);
@@ -127,7 +104,7 @@ var ViewInfo = function (_a) {
127
104
  setTemplates(res.filter(function (x) { return !x.isDeprecated; }).concat(viewDeprecate ? [viewDeprecate] : []));
128
105
  })
129
106
  .finally(function () { return setLoadingTemplate(false); });
130
- }, Constant_2.Constants.DEBOUNCE_TIME_300), []);
107
+ }, Constant_1.Constants.DEBOUNCE_TIME_300), []);
131
108
  var templateOptions = react_1.default.useMemo(function () {
132
109
  var result = [];
133
110
  if (viewInfoData.templateTypeId) {
@@ -119,21 +119,23 @@ var TabView = function (_a) {
119
119
  }));
120
120
  };
121
121
  var onChange = function (keys, value) {
122
+ // console.log("keys", keys, "value", value, views, activeViewIndex)
122
123
  if (keys.includes('activeViewIndex')) {
123
124
  setActiveViewIndex(Number(value));
124
125
  return;
125
126
  }
126
- setView((0, immer_1.produce)(function (draf) {
127
- (0, Helpers_1.setObject)(draf, keys, value);
127
+ setView((0, immer_1.produce)(function (draft) {
128
+ if (draft.views.length < Number(keys[1] || 0) + 1)
129
+ return;
130
+ (0, Helpers_1.setObject)(draft, keys, value);
128
131
  }));
129
132
  };
130
133
  var handleChange = function (key) {
131
134
  if (key === void 0) { key = []; }
132
135
  return (0, Utils_1.composeKey)(onChange, (0, Utils_1.concatKey)(key));
133
136
  };
134
- var handleChangeView = react_1.default.useMemo(function () { return handleChange(['views', String(activeViewIndex)]); },
135
137
  // eslint-disable-next-line react-hooks/exhaustive-deps
136
- [activeViewIndex]);
138
+ var handleChangeView = react_1.default.useMemo(function () { return handleChange(['views', String(activeViewIndex)]); }, [activeViewIndex]);
137
139
  return ((0, jsx_runtime_1.jsx)(ViewList_1.default, { isDisableTabHeader: false, activeViewIndex: activeViewIndex, viewCount: views.length, onChangeView: handleChange(), addView: addPageView, deleteView: deletePageView, children: (0, jsx_runtime_1.jsx)(Panel_1.default, { value: activeViewIndex, index: activeViewIndex, children: views.map(function (view, index) { return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: activeViewIndex === index && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ViewInfo_1.default, { onChange: handleChangeView, templateTypes: templateTypes, viewInfoData: view, viewNumber: index + 1 }), (0, jsx_runtime_1.jsx)(ViewContent_1.default, { viewInfoData: view, pageId: page.pageId, viewNumber: index, onChange: handleChangeView, isCreate: Boolean(isCreate) })] })) }, index)); }) }) }));
138
140
  };
139
141
  exports.default = TabView;
@@ -0,0 +1,18 @@
1
+ /// <reference types="lodash" />
2
+ import { Configs, FieldInfo } from "../../../../../ACM-AXN/ViewTemplate/interface";
3
+ export declare const getValidationParams: (templateDatas: FieldInfo[], pagePath: string, configs: Configs) => {
4
+ fieldValue: any;
5
+ id?: string | undefined;
6
+ defaultValue?: string | undefined;
7
+ fieldName: string;
8
+ fieldType: "object" | "color" | "html" | "textarea" | "video" | "image" | "list" | "checkbox" | "url" | "textfield" | "textfield_number" | "dropdownlist" | "checkboxlist";
9
+ isRequired: boolean;
10
+ labelName?: string | undefined;
11
+ pageId?: string | undefined;
12
+ templateId?: string | undefined;
13
+ viewNumber?: number | undefined;
14
+ childrens?: FieldInfo[] | undefined;
15
+ }[][];
16
+ export declare const runValidate: import("lodash").DebouncedFunc<(scriptValidate: string, fields: FieldInfo[], pagePath: string, notifyError: (errorMessage: string) => void, changeViewValidStatus: (status: boolean) => void, changeViewValidProcess: (processValue: number) => void, configs: Configs) => void>;
17
+ export declare const getAutoFieldParams: (templateDatas: FieldInfo[], fieldPath: string, pagePath: string, configs: Configs) => any[];
18
+ export declare const runAutoField: import("lodash").DebouncedFunc<(scriptAutoField: string, fields: FieldInfo[], fieldPath: string, pagePath: string, updateNewValue: (needUpdateFieldPath: string, newValue: any) => void, configs: Configs) => void>;
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.runAutoField = exports.getAutoFieldParams = exports.runValidate = exports.getValidationParams = void 0;
18
+ var Enum_1 = require("../../../../../ACM-AXN/ViewTemplate/Enum");
19
+ var common_1 = require("../../../../../ACM-AXN/ViewTemplate/common");
20
+ var constant_1 = require("../../../../../ACM-AXN/ViewTemplate/constant");
21
+ var validation_1 = require("../../../../../AWING/ultis/validation");
22
+ var i18n_1 = __importDefault(require("../../../../../i18n"));
23
+ var lodash_1 = require("lodash");
24
+ var getValidationParams = function (templateDatas, pagePath, configs) {
25
+ var fields = templateDatas.map(function (dt) {
26
+ // Convert all video, image link
27
+ var fieldValue = dt.fieldValue;
28
+ if ([
29
+ Enum_1.TYPE_FIELD_TEMPLATE.IMAGE,
30
+ Enum_1.TYPE_FIELD_TEMPLATE.VIDEO,
31
+ Enum_1.TYPE_FIELD_TEMPLATE.OBJECT,
32
+ Enum_1.TYPE_FIELD_TEMPLATE.LIST,
33
+ ].includes(dt.fieldType)) {
34
+ var jsonValue = JSON.stringify(fieldValue);
35
+ if (jsonValue.includes(constant_1.ACM_TEMPLATE_PATH)) {
36
+ jsonValue = jsonValue.replaceAll('/' + constant_1.ACM_TEMPLATE_PATH, "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(dt.templateId));
37
+ }
38
+ if (jsonValue.includes(configs.FILE_RELATIVE_PATH || '')) {
39
+ jsonValue = jsonValue.replaceAll(configs.FILE_RELATIVE_PATH || '', pagePath);
40
+ }
41
+ fieldValue = JSON.parse(jsonValue);
42
+ }
43
+ return __assign(__assign({}, dt), { fieldValue: fieldValue });
44
+ });
45
+ return [fields];
46
+ };
47
+ exports.getValidationParams = getValidationParams;
48
+ var nomalValidate = function (parmas) {
49
+ return new Promise(function (resolve, reject) {
50
+ var result = [];
51
+ parmas.flatMap(function (f) { return f; }).forEach(function (field) {
52
+ var errorObj = {
53
+ code: Enum_1.VALID_TEMPLATE_CODE.ERROR,
54
+ fieldName: field.labelName || field.fieldName,
55
+ errorMessage: i18n_1.default.t('Common.InvalidData'),
56
+ };
57
+ if (field.fieldValue)
58
+ switch (field.fieldType) {
59
+ case Enum_1.TYPE_FIELD_TEMPLATE.COLOR: {
60
+ if (!(0, validation_1.colorValid)(field.fieldValue)) {
61
+ result.push(errorObj);
62
+ }
63
+ break;
64
+ }
65
+ case Enum_1.TYPE_FIELD_TEMPLATE.URL: {
66
+ if (!(0, validation_1.urlValid)(field.fieldValue)) {
67
+ result.push(errorObj);
68
+ }
69
+ break;
70
+ }
71
+ default:
72
+ break;
73
+ }
74
+ });
75
+ resolve(result);
76
+ });
77
+ };
78
+ exports.runValidate = (0, lodash_1.debounce)(function (scriptValidate, fields, pagePath, notifyError, changeViewValidStatus, changeViewValidProcess, configs) {
79
+ changeViewValidProcess(Enum_1.VALIDATE_PROCESS_CODE.VALIDATING);
80
+ Promise.all([
81
+ scriptValidate
82
+ ? (0, common_1.runScript)((0, exports.getValidationParams)(fields, pagePath, configs), scriptValidate)
83
+ : Promise.resolve([]),
84
+ nomalValidate((0, exports.getValidationParams)(fields, pagePath, configs)),
85
+ ]).then(function (_a) {
86
+ var resultScript = _a[0], resultNormal = _a[1];
87
+ var result = Array.from(resultNormal).concat(resultScript);
88
+ if (result) {
89
+ var fieldsError_1 = [];
90
+ var newAnswer = result.map(function (validInfo) {
91
+ var _a;
92
+ if (validInfo.code === Enum_1.VALID_TEMPLATE_CODE.SUCCESS) {
93
+ return true;
94
+ }
95
+ else {
96
+ var displayName = ((_a = fields.find(function (dt) {
97
+ return validInfo.fieldName === dt.fieldName;
98
+ })) === null || _a === void 0 ? void 0 : _a.labelName) || validInfo.fieldName;
99
+ fieldsError_1.push("".concat(displayName).concat(validInfo.errorMessage
100
+ ? ": ".concat(validInfo.errorMessage)
101
+ : ''));
102
+ return false;
103
+ }
104
+ });
105
+ if (fieldsError_1.length > 0) {
106
+ notifyError(fieldsError_1.toString());
107
+ }
108
+ changeViewValidStatus(newAnswer.length === 0 || !newAnswer.includes(false));
109
+ }
110
+ changeViewValidProcess(Enum_1.VALIDATE_PROCESS_CODE.VALIDATED);
111
+ });
112
+ }, constant_1.DELAY_TIME_RUN_SCRIPT);
113
+ var getAutoFieldParams = function (templateDatas, fieldPath, pagePath, configs) {
114
+ var fields = templateDatas.map(function (dt) {
115
+ // Convert all video, image link
116
+ var fieldValue = dt.fieldValue;
117
+ if ([
118
+ Enum_1.TYPE_FIELD_TEMPLATE.IMAGE,
119
+ Enum_1.TYPE_FIELD_TEMPLATE.VIDEO,
120
+ Enum_1.TYPE_FIELD_TEMPLATE.OBJECT,
121
+ Enum_1.TYPE_FIELD_TEMPLATE.LIST,
122
+ ].includes(dt.fieldType)) {
123
+ var jsonValue = JSON.stringify(fieldValue);
124
+ if (jsonValue.includes(constant_1.ACM_TEMPLATE_PATH)) {
125
+ jsonValue = jsonValue.replaceAll('/' + constant_1.ACM_TEMPLATE_PATH, "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(dt.templateId));
126
+ }
127
+ if (jsonValue.includes(configs.FILE_RELATIVE_PATH || '')) {
128
+ jsonValue = jsonValue.replaceAll(configs.FILE_RELATIVE_PATH || '', pagePath);
129
+ }
130
+ fieldValue = JSON.parse(jsonValue);
131
+ }
132
+ return __assign(__assign({}, dt), { fieldValue: fieldValue });
133
+ });
134
+ var keys = fieldPath.split('.');
135
+ var fieldChange = fields[Number(keys[1])];
136
+ return [fields, __assign(__assign({}, fieldChange), { changePath: fieldPath })];
137
+ };
138
+ exports.getAutoFieldParams = getAutoFieldParams;
139
+ exports.runAutoField = (0, lodash_1.debounce)(function (scriptAutoField, fields, fieldPath, pagePath, updateNewValue, configs) {
140
+ if (scriptAutoField) {
141
+ (0, common_1.runScript)((0, exports.getAutoFieldParams)(fields, fieldPath, pagePath, configs), scriptAutoField).then(function (result) {
142
+ if (result) {
143
+ result === null || result === void 0 ? void 0 : result.map(function (r) {
144
+ var _a;
145
+ var idx = fields.findIndex(function (f) { return f.fieldName === r.fieldName; });
146
+ if ([
147
+ Enum_1.TYPE_FIELD_TEMPLATE.IMAGE,
148
+ Enum_1.TYPE_FIELD_TEMPLATE.VIDEO,
149
+ Enum_1.TYPE_FIELD_TEMPLATE.OBJECT,
150
+ Enum_1.TYPE_FIELD_TEMPLATE.LIST,
151
+ ].includes(fields[idx].fieldType)) {
152
+ var jsonValue = JSON.stringify(r.newValue);
153
+ if (jsonValue.includes(pagePath)) {
154
+ jsonValue = jsonValue.replaceAll(pagePath, configs.FILE_RELATIVE_PATH || '');
155
+ }
156
+ if (configs.TEMPLATE_FILE_PATH &&
157
+ jsonValue.includes(configs.TEMPLATE_FILE_PATH)) {
158
+ var templatePath = "".concat(configs.TEMPLATE_FILE_PATH, "/").concat((_a = fields === null || fields === void 0 ? void 0 : fields[0]) === null || _a === void 0 ? void 0 : _a.templateId);
159
+ jsonValue = jsonValue.replaceAll(templatePath, "\"/".concat(constant_1.ACM_TEMPLATE_PATH));
160
+ }
161
+ r.newValue = JSON.parse(jsonValue);
162
+ }
163
+ var needUpdateFieldPath = "templateDatas.".concat(idx, ".fieldValue");
164
+ updateNewValue(needUpdateFieldPath, r.newValue);
165
+ return r;
166
+ });
167
+ }
168
+ });
169
+ }
170
+ }, constant_1.DELAY_TIME_RUN_SCRIPT);
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
38
  };
@@ -17,16 +40,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
40
  var jsx_runtime_1 = require("react/jsx-runtime");
18
41
  var material_1 = require("@mui/material");
19
42
  var styles_1 = require("@mui/styles");
43
+ var AWING_1 = require("../../../../../AWING");
44
+ var validation_1 = require("../../../../../AWING/ultis/validation");
45
+ var react_1 = __importStar(require("react"));
46
+ var react_i18next_1 = require("react-i18next");
47
+ var Enum_1 = require("../../../Enum");
20
48
  var ImageField_1 = __importDefault(require("./ImageField"));
21
- var VideoField_1 = __importDefault(require("./VideoField"));
22
49
  var MonacoEditor_1 = __importDefault(require("./MonacoEditor"));
23
- var common_1 = require("../../../common");
24
- var constant_1 = require("../../../constant");
25
- var Enum_1 = require("../../../Enum");
26
- var react_1 = require("react");
27
- var react_i18next_1 = require("react-i18next");
28
- var validation_1 = require("../../../../../AWING/ultis/validation");
29
- var debounce = require('lodash/debounce');
50
+ var Utils_1 = require("./Utils");
51
+ var VideoField_1 = __importDefault(require("./VideoField"));
30
52
  var useStyles = (0, styles_1.makeStyles)(function (theme) { return ({
31
53
  paper: {
32
54
  padding: '16px',
@@ -98,8 +120,8 @@ function BasicField(props) {
98
120
  if (scriptValidate) {
99
121
  onChangeValidateProcess(Enum_1.VALIDATE_PROCESS_CODE.NOT_VALIDATE);
100
122
  }
101
- runValidate(scriptValidate || '', fields, pagePath, onNotifyError, onChangeViewValid, onChangeValidateProcess, configs);
102
- runAutoField(scriptAutoField || '', fields, fieldPath, pagePath, function (needUpdateFieldPath, newValue) {
123
+ (0, Utils_1.runValidate)(scriptValidate || '', fields, pagePath, onNotifyError, onChangeViewValid, onChangeValidateProcess, configs);
124
+ (0, Utils_1.runAutoField)(scriptAutoField || '', fields, fieldPath, pagePath, function (needUpdateFieldPath, newValue) {
103
125
  setFormValue(needUpdateFieldPath, newValue);
104
126
  onChange(needUpdateFieldPath);
105
127
  }, configs);
@@ -107,11 +129,15 @@ function BasicField(props) {
107
129
  var renderField = function () {
108
130
  // const isError = !!getValueByPath(/*errors*/ {}, fieldPath)
109
131
  var isError = errors.includes(fieldPath);
110
- var field = register(fieldPath, __assign({ required: isRequired }, fieldType === Enum_1.TYPE_FIELD_TEMPLATE.URL && {
111
- onValidate: function (value) { return (0, validation_1.urlValid)(value); }
132
+ var field = register(fieldPath, __assign(__assign({ required: isRequired }, fieldType === Enum_1.TYPE_FIELD_TEMPLATE.URL && {
133
+ onValidate: validation_1.urlValid
134
+ }), fieldType === Enum_1.TYPE_FIELD_TEMPLATE.COLOR && {
135
+ onValidate: validation_1.colorValid
112
136
  }));
137
+ // onChangeViewValid(isError)
113
138
  switch (fieldType) {
114
139
  case Enum_1.TYPE_FIELD_TEMPLATE.TEXT_FIELD_NUMBER:
140
+ return renderNumberField(field, isError);
115
141
  case Enum_1.TYPE_FIELD_TEMPLATE.TEXT_FIELD:
116
142
  case Enum_1.TYPE_FIELD_TEMPLATE.URL:
117
143
  return renderTextField(field, isError);
@@ -133,10 +159,16 @@ function BasicField(props) {
133
159
  return null;
134
160
  }
135
161
  };
162
+ var renderNumberField = react_1.default.useCallback(function (field, isError) {
163
+ return ((0, jsx_runtime_1.jsx)(AWING_1.NumberFormat, __assign({}, field, { inputProps: { min: 0 }, className: classes.text, required: isRequired, min: 0, fullWidth: true, variant: "standard", label: labelName || fieldName, onChange: function (e) {
164
+ var newValue = Number(e.target.value);
165
+ console.log('newValue', newValue);
166
+ handleChange(newValue);
167
+ }, error: isError, helperText: isError ? t('Common.Required') : '' })));
168
+ // eslint-disable-next-line react-hooks/exhaustive-deps
169
+ }, [classes, fieldName, isRequired, labelName, t]);
136
170
  var renderTextField = function (field, isError) {
137
- return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, field, { className: classes.text, required: isRequired, fullWidth: true, inputProps: fieldType === Enum_1.TYPE_FIELD_TEMPLATE.TEXT_FIELD_NUMBER
138
- ? { type: 'number' }
139
- : {} }, (fieldType === Enum_1.TYPE_FIELD_TEMPLATE.TEXTAREA
171
+ return ((0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, field, { className: classes.text, required: isRequired, fullWidth: true }, (fieldType === Enum_1.TYPE_FIELD_TEMPLATE.TEXTAREA
140
172
  ? { multiline: true, rows: 4 }
141
173
  : {}), { variant: "standard", label: labelName || fieldName, onChange: function (e) {
142
174
  handleChange(e.target.value);
@@ -212,116 +244,3 @@ function BasicField(props) {
212
244
  return renderField();
213
245
  }
214
246
  exports.default = BasicField;
215
- var getValidationParams = function (templateDatas, pagePath, configs) {
216
- var fields = templateDatas.map(function (dt) {
217
- // Convert all video, image link
218
- var fieldValue = dt.fieldValue;
219
- if ([
220
- Enum_1.TYPE_FIELD_TEMPLATE.IMAGE,
221
- Enum_1.TYPE_FIELD_TEMPLATE.VIDEO,
222
- Enum_1.TYPE_FIELD_TEMPLATE.OBJECT,
223
- Enum_1.TYPE_FIELD_TEMPLATE.LIST,
224
- ].includes(dt.fieldType)) {
225
- var jsonValue = JSON.stringify(fieldValue);
226
- if (jsonValue.includes(constant_1.ACM_TEMPLATE_PATH)) {
227
- jsonValue = jsonValue.replaceAll('/' + constant_1.ACM_TEMPLATE_PATH, "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(dt.templateId));
228
- }
229
- if (jsonValue.includes(configs.FILE_RELATIVE_PATH || '')) {
230
- jsonValue = jsonValue.replaceAll(configs.FILE_RELATIVE_PATH || '', pagePath);
231
- }
232
- fieldValue = JSON.parse(jsonValue);
233
- }
234
- return __assign(__assign({}, dt), { fieldValue: fieldValue });
235
- });
236
- return [fields];
237
- };
238
- var runValidate = debounce(function (scriptValidate, fields, pagePath, notifyError, changeViewValidStatus, changeViewValidProcess, configs) {
239
- if (scriptValidate) {
240
- changeViewValidProcess(Enum_1.VALIDATE_PROCESS_CODE.VALIDATING);
241
- var params = getValidationParams(fields, pagePath, configs);
242
- (0, common_1.runScript)(
243
- // getValidationParams(fields, pagePath, configs),
244
- params, scriptValidate).then(function (result) {
245
- if (result) {
246
- var fieldsError_1 = [];
247
- var newAnswer = result.map(function (validInfo) {
248
- var _a;
249
- if (validInfo.code === Enum_1.VALID_TEMPLATE_CODE.SUCCESS) {
250
- return true;
251
- }
252
- else {
253
- var displayName = ((_a = fields.find(function (dt) {
254
- return validInfo.fieldName === dt.fieldName;
255
- })) === null || _a === void 0 ? void 0 : _a.labelName) || validInfo.fieldName;
256
- fieldsError_1.push("".concat(displayName).concat(validInfo.errorMessage
257
- ? ": ".concat(validInfo.errorMessage)
258
- : ''));
259
- return false;
260
- }
261
- });
262
- if (fieldsError_1.length > 0) {
263
- notifyError(fieldsError_1.toString());
264
- }
265
- changeViewValidStatus(newAnswer.length === 0 || !newAnswer.includes(false));
266
- }
267
- changeViewValidProcess(Enum_1.VALIDATE_PROCESS_CODE.VALIDATED);
268
- });
269
- }
270
- }, constant_1.DELAY_TIME_RUN_SCRIPT);
271
- var getAutoFieldParams = function (templateDatas, fieldPath, pagePath, configs) {
272
- var fields = templateDatas.map(function (dt) {
273
- // Convert all video, image link
274
- var fieldValue = dt.fieldValue;
275
- if ([
276
- Enum_1.TYPE_FIELD_TEMPLATE.IMAGE,
277
- Enum_1.TYPE_FIELD_TEMPLATE.VIDEO,
278
- Enum_1.TYPE_FIELD_TEMPLATE.OBJECT,
279
- Enum_1.TYPE_FIELD_TEMPLATE.LIST,
280
- ].includes(dt.fieldType)) {
281
- var jsonValue = JSON.stringify(fieldValue);
282
- if (jsonValue.includes(constant_1.ACM_TEMPLATE_PATH)) {
283
- jsonValue = jsonValue.replaceAll('/' + constant_1.ACM_TEMPLATE_PATH, "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(dt.templateId));
284
- }
285
- if (jsonValue.includes(configs.FILE_RELATIVE_PATH || '')) {
286
- jsonValue = jsonValue.replaceAll(configs.FILE_RELATIVE_PATH || '', pagePath);
287
- }
288
- fieldValue = JSON.parse(jsonValue);
289
- }
290
- return __assign(__assign({}, dt), { fieldValue: fieldValue });
291
- });
292
- var keys = fieldPath.split('.');
293
- var fieldChange = fields[Number(keys[1])];
294
- return [fields, __assign(__assign({}, fieldChange), { changePath: fieldPath })];
295
- };
296
- var runAutoField = debounce(function (scriptAutoField, fields, fieldPath, pagePath, updateNewValue, configs) {
297
- if (scriptAutoField) {
298
- (0, common_1.runScript)(getAutoFieldParams(fields, fieldPath, pagePath, configs), scriptAutoField).then(function (result) {
299
- if (result) {
300
- result === null || result === void 0 ? void 0 : result.map(function (r) {
301
- var _a;
302
- var idx = fields.findIndex(function (f) { return f.fieldName === r.fieldName; });
303
- if ([
304
- Enum_1.TYPE_FIELD_TEMPLATE.IMAGE,
305
- Enum_1.TYPE_FIELD_TEMPLATE.VIDEO,
306
- Enum_1.TYPE_FIELD_TEMPLATE.OBJECT,
307
- Enum_1.TYPE_FIELD_TEMPLATE.LIST,
308
- ].includes(fields[idx].fieldType)) {
309
- var jsonValue = JSON.stringify(r.newValue);
310
- if (jsonValue.includes(pagePath)) {
311
- jsonValue = jsonValue.replaceAll(pagePath, configs.FILE_RELATIVE_PATH || '');
312
- }
313
- if (configs.TEMPLATE_FILE_PATH &&
314
- jsonValue.includes(configs.TEMPLATE_FILE_PATH)) {
315
- var templatePath = "".concat(configs.TEMPLATE_FILE_PATH, "/").concat((_a = fields === null || fields === void 0 ? void 0 : fields[0]) === null || _a === void 0 ? void 0 : _a.templateId);
316
- jsonValue = jsonValue.replaceAll(templatePath, "\"/".concat(constant_1.ACM_TEMPLATE_PATH));
317
- }
318
- r.newValue = JSON.parse(jsonValue);
319
- }
320
- var needUpdateFieldPath = "templateDatas.".concat(idx, ".fieldValue");
321
- updateNewValue(needUpdateFieldPath, r.newValue);
322
- return r;
323
- });
324
- }
325
- });
326
- }
327
- }, constant_1.DELAY_TIME_RUN_SCRIPT);
@@ -93,7 +93,13 @@ function ViewTemplate(_a) {
93
93
  cursor: "pointer",
94
94
  }, onClick: function () {
95
95
  setAdvanceOptionExpand(!advanceOptionExpand);
96
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { style: { fontWeight: "bold" }, children: t("ViewTemplate.AdvanceOption") }), (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: advanceOptionExpand ? ((0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {})) : ((0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {})) })] }), advanceOptionExpand && ((0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, children: [fields && advanceFields.length > 0 && renderFields(fields, true), (0, jsx_runtime_1.jsx)(Event_1.default, __assign({}, props))] }))] })] }), enablePreview && ((0, jsx_runtime_1.jsxs)(material_1.Grid, { item: true, xs: 4, children: [(0, jsx_runtime_1.jsx)(Preview_1.default, { domainId: domainId || "", validStatus: validStatus, configs: CONFIGS, pagePath: pagePath, templateDatas: templateDatas }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", children: t("ViewTemplate.PreviewLoadingNote") })] }))] }));
96
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { style: { fontWeight: "bold" }, children: t("ViewTemplate.AdvanceOption") }), (0, jsx_runtime_1.jsx)(material_1.IconButton, { children: advanceOptionExpand ? ((0, jsx_runtime_1.jsx)(icons_material_1.ExpandLess, {})) : ((0, jsx_runtime_1.jsx)(icons_material_1.ExpandMore, {})) })] }), (0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, sx: {
97
+ transition: "all 3s",
98
+ }, style: advanceOptionExpand ? {
99
+ display: "block",
100
+ } : {
101
+ display: "none",
102
+ }, children: [fields && advanceFields.length > 0 && renderFields(fields, true), (0, jsx_runtime_1.jsx)(Event_1.default, __assign({}, props))] })] })] }), enablePreview && ((0, jsx_runtime_1.jsxs)(material_1.Grid, { item: true, xs: 4, children: [(0, jsx_runtime_1.jsx)(Preview_1.default, { domainId: domainId || "", validStatus: validStatus, configs: CONFIGS, pagePath: pagePath, templateDatas: templateDatas }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", children: t("ViewTemplate.PreviewLoadingNote") })] }))] }));
97
103
  }
98
104
  exports.default = ViewTemplate;
99
105
  var getChilds = function (fields, fieldInfo) {
@@ -53,7 +53,8 @@ var useForm = function (props) {
53
53
  var _updateFieldArray = function (name, value) {
54
54
  (0, set_1.default)(_formControl.current, name, value);
55
55
  };
56
- var getValues = function (fieldNames) {
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ var getValues = react_1.default.useCallback(function (fieldNames) {
57
58
  var data = (0, convertToArrayPayload_1.default)(fieldNames).map(function (fieldName) {
58
59
  return (0, cloneProxy_1.default)((0, get_1.default)(_formControl.current, fieldName));
59
60
  });
@@ -61,7 +62,7 @@ var useForm = function (props) {
61
62
  return data;
62
63
  if (data.length && data.length === 1)
63
64
  return data[0];
64
- };
65
+ }, []);
65
66
  var register = function (fieldPath, options) {
66
67
  var isRequired = options === null || options === void 0 ? void 0 : options.required;
67
68
  var onValidate = options === null || options === void 0 ? void 0 : options.onValidate;
@@ -1,3 +1,5 @@
1
1
  import { TextFieldProps } from '@mui/material';
2
- export declare const NumberFormat: (props: TextFieldProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const NumberFormat: (props: TextFieldProps & {
3
+ min?: number;
4
+ }) => import("react/jsx-runtime").JSX.Element;
3
5
  export default NumberFormat;
@@ -32,7 +32,7 @@ var helper_1 = require("../helper");
32
32
  var Context_1 = __importDefault(require("../../Context"));
33
33
  var react_1 = require("react");
34
34
  var NumberFormat = function (props) {
35
- var value = props.value, onChange = props.onChange, other = __rest(props, ["value", "onChange"]);
35
+ var value = props.value, onChange = props.onChange, min = props.min, other = __rest(props, ["value", "onChange", "min"]);
36
36
  var i18next = (0, react_1.useContext)(Context_1.default).i18next;
37
37
  var handleChange = function (event) {
38
38
  var el = event.target;
@@ -65,7 +65,7 @@ var NumberFormat = function (props) {
65
65
  .replace(new RegExp(escapeRegExp(decimalSeparator), 'g'), ''));
66
66
  }
67
67
  //add negation back
68
- if (hasNegation)
68
+ if (hasNegation && min !== 0)
69
69
  num = '-' + num;
70
70
  return num;
71
71
  }
@@ -10,6 +10,7 @@ export declare function dateRangeValid(value: (Date | null | undefined)[] | null
10
10
  export declare function emailValid(value: string | null | undefined): boolean;
11
11
  export declare function numberOnlyValid(value: string | null | undefined): boolean;
12
12
  export declare function urlValid(value: string | null | undefined): boolean;
13
+ export declare function colorValid(value: string | null | undefined): boolean;
13
14
  export declare function passwordValid(value: string | null | undefined): boolean;
14
15
  export declare function containsOnlyDigits(str: string): boolean;
15
16
  export declare function logicExpressionValid(value: string | null | undefined): boolean;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.textValidation = exports.logicExpressionValid = exports.containsOnlyDigits = exports.passwordValid = exports.urlValid = exports.numberOnlyValid = exports.emailValid = exports.dateRangeValid = exports.dateValid = exports.notNullValid = exports.stringNullableValid = exports.stringNotNullValid = exports.numberNotNullValid = exports.numberPercentageNotNullValid = exports.positiveNumberNotNullValid = exports.arrayIsNotEmptyValid = void 0;
6
+ exports.textValidation = exports.logicExpressionValid = exports.containsOnlyDigits = exports.passwordValid = exports.colorValid = exports.urlValid = exports.numberOnlyValid = exports.emailValid = exports.dateRangeValid = exports.dateValid = exports.notNullValid = exports.stringNullableValid = exports.stringNotNullValid = exports.numberNotNullValid = exports.numberPercentageNotNullValid = exports.positiveNumberNotNullValid = exports.arrayIsNotEmptyValid = void 0;
7
7
  /* eslint-disable no-useless-escape */
8
8
  var i18n_1 = __importDefault(require("../../i18n"));
9
9
  var lodash_1 = __importDefault(require("lodash"));
@@ -69,6 +69,11 @@ function urlValid(value) {
69
69
  }
70
70
  }
71
71
  exports.urlValid = urlValid;
72
+ function colorValid(value) {
73
+ var re = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
74
+ return value !== undefined && value !== null && re.test('#' + value);
75
+ }
76
+ exports.colorValid = colorValid;
72
77
  function passwordValid(value) {
73
78
  var re = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/;
74
79
  return value === undefined && value === null && re.test(value);
@@ -78,7 +78,6 @@ var Drawer = function (props) {
78
78
  .then(function (state) {
79
79
  setTimeout(function () {
80
80
  snackbar('success');
81
- console.log('success');
82
81
  }, 700);
83
82
  closeDrawer((typeof state === 'string' && state) ? state : CloseAction.Reload);
84
83
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.161-dev",
3
+ "version": "2.1.163-dev",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",