awing-library 2.1.117-beta → 2.1.118-beta

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.
@@ -95,58 +95,59 @@ var CreateOrEdit = function (_a) {
95
95
  var pageChangedForm = (0, recoil_1.useRecoilValue)(Recoil_1.pageChangedFormState);
96
96
  var _e = (0, recoil_1.useRecoilState)(Recoil_1.pageRootState), pageRoot = _e[0], setPageRoot = _e[1];
97
97
  (0, react_1.useEffect)(function () {
98
- fetchDirectories();
99
- setPageRoot((0, immer_1.default)(function (draf) {
100
- draf.page.createdDate = (0, Helpers_1.convertDateTimeToTimestamp)(new Date());
101
- }));
102
- if (type === enums_1.PathType.CREATE) {
103
- service.pagesGenerateId().then(function (res) {
104
- setPageRoot((0, immer_1.default)(function (draf) {
105
- draf.page.pageId = res;
106
- draf.page.pageCode =
107
- pageCode === enums_1.PageCode.Lgn ? 'lgn' : 'wlc';
108
- }));
98
+ setLoading(true);
99
+ fetchDirectories().then(function (directories) { return __awaiter(void 0, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ if (!(type === enums_1.PathType.CREATE)) return [3 /*break*/, 2];
104
+ return [4 /*yield*/, service.pagesGenerateId().then(function (res) {
105
+ setPageRoot((0, immer_1.default)(function (draf) {
106
+ var _a;
107
+ draf.page.createdDate = (0, Helpers_1.convertDateTimeToTimestamp)(new Date());
108
+ draf.page.directoryId = ((_a = (0, lodash_1.minBy)(directories, 'level')) === null || _a === void 0 ? void 0 : _a.directoryId) || '';
109
+ draf.page.pageId = res;
110
+ draf.page.pageCode = pageCode === enums_1.PageCode.Lgn ? 'lgn' : 'wlc';
111
+ }));
112
+ })];
113
+ case 1:
114
+ _a.sent();
115
+ return [3 /*break*/, 4];
116
+ case 2: return [4 /*yield*/, service[type === enums_1.PathType.CLONE ? 'pagesClone' : 'pagesGet'](pageId).then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
117
+ var isDeprecated;
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0: return [4 /*yield*/, checkDeprecated(res.views.map(function (x) { return x.templateId; }))];
121
+ case 1:
122
+ isDeprecated = _a.sent();
123
+ setDeprecated(isDeprecated);
124
+ if (isDeprecated && type === enums_1.PathType.CLONE) {
125
+ na('..', { replace: true });
126
+ appHelper.snackbar('error', t('Page.DeprecatedTemplate'));
127
+ throw new Error(t('Page.DeprecatedTemplate'));
128
+ }
129
+ Utils_1.updateStateByPageModel.call({ setPageRoot: setPageRoot }, res);
130
+ return [2 /*return*/];
131
+ }
132
+ });
133
+ }); })];
134
+ case 3:
135
+ _a.sent();
136
+ _a.label = 4;
137
+ case 4:
138
+ setDirectories(directories);
139
+ return [2 /*return*/];
140
+ }
109
141
  });
110
- }
111
- else {
112
- setLoading(true);
113
- service[type === enums_1.PathType.CLONE ? 'pagesClone' : 'pagesGet'](pageId)
114
- .then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
115
- var isDeprecated;
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0: return [4 /*yield*/, checkDeprecated(res.views.map(function (x) { return x.templateId; }))];
119
- case 1:
120
- isDeprecated = _a.sent();
121
- setDeprecated(isDeprecated);
122
- if (isDeprecated && type === enums_1.PathType.CLONE) {
123
- na('..', { replace: true });
124
- appHelper.snackbar('error', t('Page.DeprecatedTemplate'));
125
- throw new Error(t('Page.DeprecatedTemplate'));
126
- }
127
- Utils_1.updateStateByPageModel.call({ setPageRoot: setPageRoot }, res);
128
- return [2 /*return*/];
129
- }
130
- });
131
- }); })
132
- .finally(function () { return setLoading(false); });
133
- }
142
+ }); }).finally(function () { return setLoading(false); });
134
143
  // eslint-disable-next-line react-hooks/exhaustive-deps
135
144
  }, []);
136
145
  var checkDeprecated = function (templateIds) {
137
146
  return Promise.all(templateIds.map(function (id) { return service.templatesGet(id); })).then(function (res) { return res.some(function (x) { return x.template.isDeprecated; }); });
138
147
  };
139
148
  var fetchDirectories = function () {
140
- service
141
- .directoriesGetByObjectTypeCode(Enum_1.DirectoryRoot[pageCode === enums_1.PageCode.Lgn ? 'PageLogin' : 'PageWelcome'])
142
- .then(function (res) {
143
- setDirectories(res);
144
- if (!pageRoot.page.directoryId && !pageRoot.page.pageId)
145
- setPageRoot((0, immer_1.default)(function (draf) {
146
- var _a;
147
- draf.page.directoryId = ((_a = (0, lodash_1.minBy)(res, 'level')) === null || _a === void 0 ? void 0 : _a.directoryId) || '';
148
- }));
149
- });
149
+ return service
150
+ .directoriesGetByObjectTypeCode(Enum_1.DirectoryRoot[pageCode === enums_1.PageCode.Lgn ? 'PageLogin' : 'PageWelcome']);
150
151
  };
151
152
  var handleSubmit = function () {
152
153
  if (isDeprecated) {
@@ -23,6 +23,9 @@ var Infomation = function (props) {
23
23
  var t = (0, react_i18next_1.useTranslation)().t;
24
24
  var _a = (0, recoil_1.useRecoilState)(Recoils_1.templateInfoState), templateInfo = _a[0], handleTemplateData = _a[1];
25
25
  var handleUpdate = (0, react_1.useCallback)(function (obj, formValid, fieldUpdate) {
26
+ if (fieldUpdate === 'pageCode') {
27
+ handleTemplateData(function (prev) { return (__assign(__assign({}, prev), { templateTypeId: null })); });
28
+ }
26
29
  if (fieldUpdate) {
27
30
  handleTemplateData(function (prev) { return (__assign(__assign({}, prev), obj)); });
28
31
  }
@@ -44,7 +47,9 @@ var Infomation = function (props) {
44
47
  type: 'select',
45
48
  label: t('Common.TypePage'),
46
49
  required: true,
47
- options: Object.values(enums_1.PageCode).filter(function (item) { return !isNaN(Number(item)); }).map(function (value) { return ({
50
+ options: Object.values(enums_1.PageCode)
51
+ .filter(function (item) { return !isNaN(Number(item)); })
52
+ .map(function (value) { return ({
48
53
  value: enums_1.PageCode[value].toLowerCase(),
49
54
  text: enums_1.PageCode[value],
50
55
  }); }),
@@ -54,7 +59,13 @@ var Infomation = function (props) {
54
59
  type: 'select',
55
60
  label: t('Common.TypeTemplate'),
56
61
  required: true,
57
- options: templateTypes.map(function (type) { return ({
62
+ options: templateTypes
63
+ .filter(function (type) {
64
+ var _a;
65
+ return !((_a = type.templateTypeCode) === null || _a === void 0 ? void 0 : _a.localeCompare(templateInfo.pageCode || 'lgn'));
66
+ })
67
+ .sort(function (a, b) { var _a; return ((_a = a.name) === null || _a === void 0 ? void 0 : _a.localeCompare((b === null || b === void 0 ? void 0 : b.name) || '')) || -1; })
68
+ .map(function (type) { return ({
58
69
  value: type.id,
59
70
  text: type.name,
60
71
  }); }),
@@ -15,6 +15,7 @@ export declare const OmitListType: {
15
15
  LIST: string;
16
16
  OBJECT: string;
17
17
  COLOR: string;
18
+ URL: string;
18
19
  };
19
20
  declare const _default: import("react").NamedExoticComponent<ParameterProps>;
20
21
  export default _default;
@@ -11,6 +11,7 @@ export declare const TYPE_FIELD_TEMPLATE: {
11
11
  LIST: string;
12
12
  OBJECT: string;
13
13
  COLOR: string;
14
+ URL: string;
14
15
  };
15
16
  export declare const PAGE_CODES: {
16
17
  PageCodeLogin: string;
@@ -14,6 +14,7 @@ exports.TYPE_FIELD_TEMPLATE = {
14
14
  LIST: "list",
15
15
  OBJECT: "object",
16
16
  COLOR: "color",
17
+ URL: "url",
17
18
  };
18
19
  exports.PAGE_CODES = {
19
20
  PageCodeLogin: "lgn",
@@ -25,6 +25,7 @@ var constant_1 = require("../../../constant");
25
25
  var Enum_1 = require("../../../Enum");
26
26
  var react_1 = require("react");
27
27
  var react_i18next_1 = require("react-i18next");
28
+ var validation_1 = require("../../../../../AWING/ultis/validation");
28
29
  var debounce = require('lodash/debounce');
29
30
  var useStyles = (0, styles_1.makeStyles)(function (theme) { return ({
30
31
  paper: {
@@ -101,11 +102,14 @@ function BasicField(props) {
101
102
  var renderField = function () {
102
103
  // const isError = !!getValueByPath(/*errors*/ {}, fieldPath)
103
104
  var isError = errors.includes(fieldPath);
104
- var field = register(fieldPath, { required: isRequired });
105
+ var field = register(fieldPath, __assign({ required: isRequired }, fieldType === Enum_1.TYPE_FIELD_TEMPLATE.URL && {
106
+ onValidate: function (value) { return (0, validation_1.urlValid)(value); }
107
+ }));
105
108
  switch (fieldType) {
106
109
  case Enum_1.TYPE_FIELD_TEMPLATE.TEXT_FIELD_NUMBER:
107
110
  return renderTextField(field, isError);
108
111
  case Enum_1.TYPE_FIELD_TEMPLATE.TEXT_FIELD:
112
+ case Enum_1.TYPE_FIELD_TEMPLATE.URL:
109
113
  return renderTextField(field, isError);
110
114
  case Enum_1.TYPE_FIELD_TEMPLATE.TEXTAREA:
111
115
  return renderTextField(field, isError);
@@ -164,7 +168,12 @@ function BasicField(props) {
164
168
  ? { multiline: true, rows: 4 }
165
169
  : {}), { variant: "standard", label: labelName || fieldName, onChange: function (e) {
166
170
  handleChange(e.target.value);
167
- }, error: isError, helperText: isError ? t('Common.Required') : '' })));
171
+ }, error: isError, helperText: isError
172
+ ? fieldType === Enum_1.TYPE_FIELD_TEMPLATE.URL &&
173
+ !(0, validation_1.urlValid)(field.value)
174
+ ? t('Common.InvalidData')
175
+ : t('Common.Required')
176
+ : '' })));
168
177
  };
169
178
  var renderDropdownListField = function (field, isError) {
170
179
  var opts = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.split('\\n');
@@ -58,11 +58,12 @@ var runScript = function (params, script) {
58
58
  };
59
59
  exports.runScript = runScript;
60
60
  var convertRelativeLink = function (link, pagePath, templateId, configs) {
61
- var isTemplatePath = link === null || link === void 0 ? void 0 : link.includes(constant_1.ACM_TEMPLATE_PATH);
61
+ var isTemplatePath = (link === null || link === void 0 ? void 0 : link.includes(constant_1.ACM_TEMPLATE_PATH)) || (link === null || link === void 0 ? void 0 : link.includes(constant_1.ACM_PAGE_PATH));
62
62
  if (isTemplatePath) {
63
63
  return "".concat(configs.TEMPLATE_FILE_PATH, "/").concat(templateId, "/").concat(link.split("/")[link.split("/").length - 1]);
64
64
  }
65
- return "".concat(pagePath, "/").concat(link.split("/")[link.split("/").length - 1]) || "";
65
+ return link;
66
+ // return `${pagePath}/${link.split("/")[link.split("/").length - 1]}` || "";
66
67
  };
67
68
  exports.convertRelativeLink = convertRelativeLink;
68
69
  var generateRandomInteger = function (max) {
@@ -1,2 +1,3 @@
1
1
  export declare const ACM_TEMPLATE_PATH = "{acmTemplatePath}";
2
+ export declare const ACM_PAGE_PATH = "{acmPagePath}";
2
3
  export declare const DELAY_TIME_RUN_SCRIPT = 1500;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DELAY_TIME_RUN_SCRIPT = exports.ACM_TEMPLATE_PATH = void 0;
3
+ exports.DELAY_TIME_RUN_SCRIPT = exports.ACM_PAGE_PATH = exports.ACM_TEMPLATE_PATH = void 0;
4
4
  exports.ACM_TEMPLATE_PATH = "{acmTemplatePath}";
5
+ exports.ACM_PAGE_PATH = "{acmPagePath}";
5
6
  exports.DELAY_TIME_RUN_SCRIPT = 1500;
@@ -11,7 +11,7 @@ export interface FieldInfo {
11
11
  id?: string;
12
12
  defaultValue?: string;
13
13
  fieldName: string;
14
- fieldType: "image" | "textfield" | "video" | "textfield_number" | "html" | "checkbox" | "textarea" | "dropdownlist" | "checkboxlist" | "list" | "object" | "color";
14
+ fieldType: "image" | "textfield" | "video" | "textfield_number" | "html" | "checkbox" | "textarea" | "dropdownlist" | "checkboxlist" | "list" | "object" | "color" | "url";
15
15
  fieldValue?: any;
16
16
  isRequired: boolean;
17
17
  labelName?: string;
@@ -1 +1,5 @@
1
1
  export type FieldValues = Record<string, any>;
2
+ export type FieldOptions = {
3
+ required: boolean;
4
+ onValidate: (value: any) => boolean;
5
+ };
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { FieldOptions } from './Utils/Types';
2
3
  export declare const useForm: (props: {
3
4
  defaultValue: Record<string, any>;
4
5
  }) => {
@@ -9,9 +10,7 @@ export declare const useForm: (props: {
9
10
  watch: boolean;
10
11
  };
11
12
  formValue: Record<string, any>;
12
- register: (fieldPath: string, options?: {
13
- required: boolean;
14
- }) => {
13
+ register: (fieldPath: string, options?: FieldOptions) => {
15
14
  required: boolean | undefined;
16
15
  name: string;
17
16
  value: any;
@@ -64,13 +64,14 @@ var useForm = function (props) {
64
64
  };
65
65
  var register = function (fieldPath, options) {
66
66
  var isRequired = options === null || options === void 0 ? void 0 : options.required;
67
+ var onValidate = options === null || options === void 0 ? void 0 : options.onValidate;
67
68
  return {
68
69
  required: isRequired,
69
70
  name: fieldPath,
70
71
  value: getValues(fieldPath),
71
72
  onBlur: function (e) {
72
- if (isRequired) {
73
- if (!getValues(fieldPath)) {
73
+ if (isRequired || onValidate) {
74
+ if (!getValues(fieldPath) || (onValidate && !onValidate(getValues(fieldPath)))) {
74
75
  _formError.current.push(fieldPath);
75
76
  }
76
77
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.117-beta",
3
+ "version": "2.1.118-beta",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",