react-hook-core 0.1.1 → 0.1.2
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.
- package/lib/components.js +17 -8
- package/lib/index.js +16 -17
- package/lib/useSearch.js +42 -32
- package/package.json +1 -1
- package/src/components.ts +76 -67
- package/src/index.ts +25 -0
- package/src/useSearch.ts +44 -35
package/lib/components.js
CHANGED
|
@@ -317,11 +317,6 @@ var BaseSearchComponent = (function (_super) {
|
|
|
317
317
|
_this.viewable = true;
|
|
318
318
|
_this.addable = true;
|
|
319
319
|
_this.editable = true;
|
|
320
|
-
_this.add = function (event) {
|
|
321
|
-
event.preventDefault();
|
|
322
|
-
var url = _this.props['props'].match.url + '/add';
|
|
323
|
-
_this.props.history.push(url);
|
|
324
|
-
};
|
|
325
320
|
_this.pageSizeOnClick = function () {
|
|
326
321
|
_this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
|
|
327
322
|
};
|
|
@@ -336,7 +331,6 @@ var BaseSearchComponent = (function (_super) {
|
|
|
336
331
|
_this.showMessage = _this.showMessage.bind(_this);
|
|
337
332
|
_this.toggleFilter = _this.toggleFilter.bind(_this);
|
|
338
333
|
_this.load = _this.load.bind(_this);
|
|
339
|
-
_this.add = _this.add.bind(_this);
|
|
340
334
|
_this.getSearchForm = _this.getSearchForm.bind(_this);
|
|
341
335
|
_this.setSearchForm = _this.setSearchForm.bind(_this);
|
|
342
336
|
_this.setFilter = _this.setFilter.bind(_this);
|
|
@@ -355,7 +349,8 @@ var BaseSearchComponent = (function (_super) {
|
|
|
355
349
|
_this.sort = _this.sort.bind(_this);
|
|
356
350
|
_this.showMore = _this.showMore.bind(_this);
|
|
357
351
|
_this.pageChanged = _this.pageChanged.bind(_this);
|
|
358
|
-
|
|
352
|
+
var currentUrl = window.location.host + window.location.pathname;
|
|
353
|
+
_this.url = removeUrlParams(currentUrl);
|
|
359
354
|
return _this;
|
|
360
355
|
}
|
|
361
356
|
BaseSearchComponent.prototype.getModelName = function () {
|
|
@@ -384,7 +379,10 @@ var BaseSearchComponent = (function (_super) {
|
|
|
384
379
|
return this.form;
|
|
385
380
|
};
|
|
386
381
|
BaseSearchComponent.prototype.setFilter = function (filter) {
|
|
387
|
-
this.
|
|
382
|
+
var modelName = this.getModelName();
|
|
383
|
+
var objSet = {};
|
|
384
|
+
objSet[modelName] = filter;
|
|
385
|
+
this.setState(objSet);
|
|
388
386
|
};
|
|
389
387
|
BaseSearchComponent.prototype.getCurrencyCode = function () {
|
|
390
388
|
return core_2.getCurrencyCode(this.form);
|
|
@@ -571,6 +569,11 @@ var SearchComponent = (function (_super) {
|
|
|
571
569
|
__extends(SearchComponent, _super);
|
|
572
570
|
function SearchComponent(props, sv, param, showMessage, showError, getLocale, uis, loading, listFormId) {
|
|
573
571
|
var _this = _super.call(this, props, input_1.getResource(param), input_1.getMsgFunc(param, showMessage), input_1.getLocaleFunc(param, getLocale), input_1.getUIService(param, uis), input_1.getLoadingFunc(param, loading), listFormId) || this;
|
|
572
|
+
_this.add = function (event) {
|
|
573
|
+
event.preventDefault();
|
|
574
|
+
var url = _this.url + '/add';
|
|
575
|
+
_this.props.history.push(url);
|
|
576
|
+
};
|
|
574
577
|
_this.autoSearch = input_1.getAutoSearch(param);
|
|
575
578
|
if (sv) {
|
|
576
579
|
if (typeof sv === 'function') {
|
|
@@ -584,6 +587,7 @@ var SearchComponent = (function (_super) {
|
|
|
584
587
|
}
|
|
585
588
|
}
|
|
586
589
|
}
|
|
590
|
+
_this.add = _this.add.bind(_this);
|
|
587
591
|
_this.call = _this.call.bind(_this);
|
|
588
592
|
_this.showError = input_1.getErrorFunc(param, showError);
|
|
589
593
|
_this.componentDidMount = _this.componentDidMount.bind(_this);
|
|
@@ -1254,3 +1258,8 @@ var DiffApprComponent = (function (_super) {
|
|
|
1254
1258
|
return DiffApprComponent;
|
|
1255
1259
|
}(BaseDiffApprComponent));
|
|
1256
1260
|
exports.DiffApprComponent = DiffApprComponent;
|
|
1261
|
+
function removeUrlParams(url) {
|
|
1262
|
+
var startParams = url.indexOf('?');
|
|
1263
|
+
return startParams !== -1 ? url.substring(0, startParams) : url;
|
|
1264
|
+
}
|
|
1265
|
+
exports.removeUrlParams = removeUrlParams;
|
package/lib/index.js
CHANGED
|
@@ -2,25 +2,24 @@
|
|
|
2
2
|
function __export(m) {
|
|
3
3
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
4
4
|
}
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var React = require("react");
|
|
7
|
-
__export(require("./formutil"));
|
|
8
|
-
__export(require("./util"));
|
|
9
|
-
__export(require("./core"));
|
|
10
|
-
__export(require("./state"));
|
|
11
|
-
__export(require("./edit"));
|
|
12
|
-
__export(require("./route"));
|
|
13
|
-
__export(require("./components"));
|
|
14
|
-
__export(require("./diff"));
|
|
15
|
-
__export(require("./router"));
|
|
16
|
-
__export(require("./merge"));
|
|
17
|
-
__export(require("./update"));
|
|
18
|
-
__export(require("./useView"));
|
|
19
|
-
__export(require("./useEdit"));
|
|
20
|
-
__export(require("./useSearch"));
|
|
21
|
-
__export(require("./useMessage"));
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });var React = require("react");__export(require("./formutil"));__export(require("./util"));__export(require("./core"));__export(require("./state"));__export(require("./edit"));__export(require("./route"));__export(require("./components"));__export(require("./diff"));__export(require("./router"));__export(require("./merge"));__export(require("./update"));__export(require("./useView"));__export(require("./useEdit"));__export(require("./useSearch"));__export(require("./useMessage"));
|
|
22
6
|
exports.withDefaultProps = function (Component) {
|
|
23
7
|
return function (props) {
|
|
24
8
|
return React.createElement(Component, { props: props, history: props.history });
|
|
25
9
|
};
|
|
26
10
|
};
|
|
11
|
+
exports.Loading = function (props) {
|
|
12
|
+
var loadingStyle = {
|
|
13
|
+
top: '30%',
|
|
14
|
+
backgroundColor: 'white',
|
|
15
|
+
border: 'none',
|
|
16
|
+
'WebkitBoxShadow': 'none',
|
|
17
|
+
'boxShadow': 'none'
|
|
18
|
+
};
|
|
19
|
+
if (props.error) {
|
|
20
|
+
return React.createElement("div", null, "Error Load Module!");
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return (React.createElement("div", { className: 'loader-wrapper' }, React.createElement("div", { className: 'loader-sign', style: loadingStyle }, React.createElement("div", { className: 'loader' }))));
|
|
24
|
+
}
|
|
25
|
+
};
|
package/lib/useSearch.js
CHANGED
|
@@ -71,9 +71,19 @@ function mergeParam(p) {
|
|
|
71
71
|
if (!p.pageMaxSize || p.pageMaxSize <= 0) {
|
|
72
72
|
p.pageMaxSize = 7;
|
|
73
73
|
}
|
|
74
|
+
return p;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return {
|
|
78
|
+
sequenceNo: 'sequenceNo',
|
|
79
|
+
pageSize: 20,
|
|
80
|
+
pageSizes: exports.pageSizes,
|
|
81
|
+
pageMaxSize: 7
|
|
82
|
+
};
|
|
74
83
|
}
|
|
75
84
|
}
|
|
76
85
|
exports.useSearch = function (refForm, initialState, search, p2, p) {
|
|
86
|
+
debugger;
|
|
77
87
|
var baseProps = exports.useCoreSearch(undefined, refForm, initialState, search, p2, p);
|
|
78
88
|
react_1.useEffect(function () {
|
|
79
89
|
var load = baseProps.load, setState = baseProps.setState, component = baseProps.component;
|
|
@@ -98,21 +108,21 @@ exports.useSearchOneProps = function (p) {
|
|
|
98
108
|
exports.useSearchOne = function (p) {
|
|
99
109
|
return exports.useCoreSearch(undefined, p.refForm, p.initialState, p.search, p, p);
|
|
100
110
|
};
|
|
101
|
-
exports.useCoreSearch = function (props, refForm, initialState, search,
|
|
102
|
-
mergeParam(
|
|
111
|
+
exports.useCoreSearch = function (props, refForm, initialState, search, p1, p2) {
|
|
112
|
+
var p = mergeParam(p2);
|
|
103
113
|
var _a = react_1.useState(), running = _a[0], setRunning = _a[1];
|
|
104
114
|
var _getModelName = function () {
|
|
105
|
-
return core_1.getName('filter',
|
|
115
|
+
return core_1.getName('filter', p && p.name ? p.name : undefined);
|
|
106
116
|
};
|
|
107
|
-
var getModelName = (
|
|
108
|
-
var baseProps = (props ? update_1.useUpdateWithProps(props, initialState, getModelName,
|
|
117
|
+
var getModelName = (p && p.getModelName ? p.getModelName : _getModelName);
|
|
118
|
+
var baseProps = (props ? update_1.useUpdateWithProps(props, initialState, getModelName, p1.getLocale, core_1.getRemoveError(p1), p ? p.prepareCustomData : undefined) : update_1.useUpdate(initialState, getModelName, p1.getLocale, core_1.getRemoveError(p1)));
|
|
109
119
|
var state = baseProps.state, setState = baseProps.setState;
|
|
110
120
|
var _b = [react_router_dom_1.useHistory(), react_router_dom_1.useRouteMatch()], history = _b[0], match = _b[1];
|
|
111
121
|
var _getCurrencyCode = function () {
|
|
112
122
|
return refForm && refForm.current ? refForm.current.getAttribute('currency-code') : null;
|
|
113
123
|
};
|
|
114
|
-
var getCurrencyCode =
|
|
115
|
-
var prepareCustomData = (
|
|
124
|
+
var getCurrencyCode = p && p.getCurrencyCode ? p.getCurrencyCode : _getCurrencyCode;
|
|
125
|
+
var prepareCustomData = (p && p.prepareCustomData ? p.prepareCustomData : prepareData);
|
|
116
126
|
var updateDateState = function (name, value) {
|
|
117
127
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
118
128
|
var modelName = getModelName();
|
|
@@ -126,7 +136,7 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
126
136
|
}
|
|
127
137
|
setState((_f = {}, _f[modelName] = __assign(__assign({}, currentState), (_g = {}, _g[name] = value, _g)), _f));
|
|
128
138
|
};
|
|
129
|
-
var _c = merge_1.useMergeState(
|
|
139
|
+
var _c = merge_1.useMergeState(p), component = _c[0], setComponent = _c[1];
|
|
130
140
|
var toggleFilter = function (event) {
|
|
131
141
|
setComponent({ hideFilter: !component.hideFilter });
|
|
132
142
|
};
|
|
@@ -140,23 +150,23 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
140
150
|
setComponent({ fields: fs, initFields: true });
|
|
141
151
|
return fs;
|
|
142
152
|
};
|
|
143
|
-
var getFields =
|
|
153
|
+
var getFields = p && p.getFields ? p.getFields : _getFields;
|
|
144
154
|
var getFilter = function (se) {
|
|
145
155
|
if (!se) {
|
|
146
156
|
se = component;
|
|
147
157
|
}
|
|
148
|
-
var keys =
|
|
158
|
+
var keys = p && p.keys ? p.keys : undefined;
|
|
149
159
|
if (!keys && typeof search !== 'function' && search.keys) {
|
|
150
160
|
keys = search.keys();
|
|
151
161
|
}
|
|
152
162
|
var n = getModelName();
|
|
153
|
-
var fs =
|
|
163
|
+
var fs = p && p.fields;
|
|
154
164
|
if (!fs || fs.length <= 0) {
|
|
155
165
|
fs = getFields();
|
|
156
166
|
}
|
|
157
|
-
var lc = (
|
|
167
|
+
var lc = (p1.getLocale ? p1.getLocale() : state_1.enLocale);
|
|
158
168
|
var cc = getCurrencyCode();
|
|
159
|
-
var obj3 = search_core_1.getModel(state, n, se, fs, se.excluding, keys, se.list, refForm.current, core_1.getDecodeFromForm(
|
|
169
|
+
var obj3 = search_core_1.getModel(state, n, se, fs, se.excluding, keys, se.list, refForm.current, core_1.getDecodeFromForm(p1), lc, cc);
|
|
160
170
|
return obj3;
|
|
161
171
|
};
|
|
162
172
|
var _setFilter = function (s) {
|
|
@@ -165,7 +175,7 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
165
175
|
objSet[n] = s;
|
|
166
176
|
setState(objSet);
|
|
167
177
|
};
|
|
168
|
-
var setFilter =
|
|
178
|
+
var setFilter = p && p.setFilter ? p.setFilter : _setFilter;
|
|
169
179
|
var _load = function (s, auto) {
|
|
170
180
|
var com = Object.assign({}, component);
|
|
171
181
|
var obj2 = search_core_1.initFilter(s, com);
|
|
@@ -178,9 +188,9 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
178
188
|
}, 0);
|
|
179
189
|
}
|
|
180
190
|
};
|
|
181
|
-
var load =
|
|
191
|
+
var load = p && p.load ? p.load : _load;
|
|
182
192
|
var doSearch = function (se, isFirstLoad) {
|
|
183
|
-
core_1.removeFormError(
|
|
193
|
+
core_1.removeFormError(p1, refForm.current);
|
|
184
194
|
var s = getFilter(se);
|
|
185
195
|
var isStillRunning = running;
|
|
186
196
|
validateSearch(s, function () {
|
|
@@ -188,11 +198,11 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
188
198
|
return;
|
|
189
199
|
}
|
|
190
200
|
setRunning(true);
|
|
191
|
-
core_1.showLoading(
|
|
192
|
-
if (
|
|
201
|
+
core_1.showLoading(p1.loading);
|
|
202
|
+
if (p && !p.ignoreUrlParam) {
|
|
193
203
|
search_core_1.addParametersIntoUrl(s, isFirstLoad);
|
|
194
204
|
}
|
|
195
|
-
var lc =
|
|
205
|
+
var lc = p1.getLocale ? p1.getLocale() : state_1.enLocale;
|
|
196
206
|
if (typeof search === 'function') {
|
|
197
207
|
exports.callSearch(s, search, showResults, searchError, lc, se.nextPageToken);
|
|
198
208
|
}
|
|
@@ -202,9 +212,9 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
202
212
|
});
|
|
203
213
|
};
|
|
204
214
|
var _validateSearch = function (se, callback) {
|
|
205
|
-
search_core_1.validate(se, callback, refForm.current, (
|
|
215
|
+
search_core_1.validate(se, callback, refForm.current, (p1.getLocale ? p1.getLocale() : undefined), core_1.getValidateForm(p1));
|
|
206
216
|
};
|
|
207
|
-
var validateSearch =
|
|
217
|
+
var validateSearch = p && p.validateSearch ? p.validateSearch : _validateSearch;
|
|
208
218
|
var pageSizeChanged = function (event) {
|
|
209
219
|
var size = parseInt(event.currentTarget.value, 10);
|
|
210
220
|
component.pageSize = size;
|
|
@@ -290,14 +300,14 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
290
300
|
};
|
|
291
301
|
var searchError = function (err) {
|
|
292
302
|
setComponent({ pageIndex: component.tmpPageIndex });
|
|
293
|
-
core_1.error(err,
|
|
303
|
+
core_1.error(err, p1.resource.value, p1.showError);
|
|
294
304
|
};
|
|
295
|
-
var appendList = (
|
|
296
|
-
var setList = (
|
|
305
|
+
var appendList = (p && p.appendList ? p.appendList : appendListOfState);
|
|
306
|
+
var setList = (p && p.setList ? p.setList : setListOfState);
|
|
297
307
|
var _showResults = function (s, sr, lc) {
|
|
298
308
|
var results = sr.list;
|
|
299
309
|
if (results && results.length > 0) {
|
|
300
|
-
search_core_1.formatResults(results, component.pageIndex, component.pageSize, component.initPageSize,
|
|
310
|
+
search_core_1.formatResults(results, component.pageIndex, component.pageSize, component.initPageSize, p ? p.sequenceNo : undefined, p ? p.format : undefined, lc);
|
|
301
311
|
}
|
|
302
312
|
var am = component.appendMode;
|
|
303
313
|
var pi = (s.page && s.page >= 1 ? s.page : 1);
|
|
@@ -320,18 +330,18 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
320
330
|
setList(results, setState);
|
|
321
331
|
setComponent({ tmpPageIndex: s.page });
|
|
322
332
|
if (s.limit) {
|
|
323
|
-
var m1 = search_core_1.buildMessage(
|
|
324
|
-
|
|
333
|
+
var m1 = search_core_1.buildMessage(p1.resource, s.page, s.limit, sr.list, sr.total);
|
|
334
|
+
p1.showMessage(m1);
|
|
325
335
|
}
|
|
326
336
|
}
|
|
327
337
|
setRunning(false);
|
|
328
|
-
core_1.hideLoading(
|
|
338
|
+
core_1.hideLoading(p1.loading);
|
|
329
339
|
if (component.triggerSearch) {
|
|
330
340
|
setComponent({ triggerSearch: false });
|
|
331
341
|
resetAndSearch();
|
|
332
342
|
}
|
|
333
343
|
};
|
|
334
|
-
var showResults = (
|
|
344
|
+
var showResults = (p && p.showResults ? p.showResults : _showResults);
|
|
335
345
|
var showMore = function (event) {
|
|
336
346
|
event.preventDefault();
|
|
337
347
|
var n = component.pageIndex ? component.pageIndex + 1 : 2;
|
|
@@ -354,8 +364,8 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
354
364
|
running: running,
|
|
355
365
|
setRunning: setRunning,
|
|
356
366
|
getCurrencyCode: getCurrencyCode,
|
|
357
|
-
updateDateState: updateDateState, resource:
|
|
358
|
-
component: component, showMessage:
|
|
367
|
+
updateDateState: updateDateState, resource: p1.resource.resource(), setComponent: setComponent,
|
|
368
|
+
component: component, showMessage: p1.showMessage, load: load,
|
|
359
369
|
add: add,
|
|
360
370
|
searchOnClick: searchOnClick,
|
|
361
371
|
sort: sort,
|
|
@@ -366,6 +376,6 @@ exports.useCoreSearch = function (props, refForm, initialState, search, p2, p1)
|
|
|
366
376
|
pageChanged: pageChanged,
|
|
367
377
|
pageSizeChanged: pageSizeChanged, clearKeyworkOnClick: clearQ, showResults: showResults,
|
|
368
378
|
getFields: getFields,
|
|
369
|
-
getModelName: getModelName, format:
|
|
379
|
+
getModelName: getModelName, format: p ? p.format : undefined
|
|
370
380
|
});
|
|
371
381
|
};
|
package/package.json
CHANGED
package/src/components.ts
CHANGED
|
@@ -47,27 +47,27 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
|
|
|
47
47
|
this.showModel = this.showModel.bind(this);
|
|
48
48
|
this.ref = React.createRef();
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
name?: string;
|
|
51
|
+
running?: boolean;
|
|
52
|
+
resourceService: ResourceService;
|
|
53
|
+
resource: StringMap;
|
|
54
|
+
loading?: LoadingService;
|
|
55
|
+
showError: (msg: string, title?: string, detail?: string, callback?: () => void) => void;
|
|
56
|
+
getLocale?: (profile?: string) => Locale;
|
|
57
|
+
loadData?: (id: ID, ctx?: any) => Promise<T>;
|
|
58
58
|
// protected service: ViewService<T, ID>;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
form?: HTMLFormElement;
|
|
60
|
+
ref: any;
|
|
61
|
+
keys?: string[];
|
|
62
|
+
metadata?: Attributes;
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
back(event: any) {
|
|
65
65
|
if (event) {
|
|
66
66
|
event.preventDefault();
|
|
67
67
|
}
|
|
68
68
|
this.props.history.goBack();
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
getModelName(): string {
|
|
71
71
|
if (this.name && this.name.length > 0) {
|
|
72
72
|
return this.name;
|
|
73
73
|
}
|
|
@@ -115,7 +115,7 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
handleNotFound(form?: HTMLFormElement): void {
|
|
119
119
|
const msg = message(this.resourceService.value, 'error_not_found', 'error');
|
|
120
120
|
if (form) {
|
|
121
121
|
readOnly(form);
|
|
@@ -135,7 +135,7 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
|
|
|
135
135
|
|
|
136
136
|
export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
137
137
|
constructor(props: P,
|
|
138
|
-
|
|
138
|
+
public getLocale?: () => Locale,
|
|
139
139
|
private removeErr?: (ctrl: HTMLInputElement) => void) {
|
|
140
140
|
super(props);
|
|
141
141
|
this.getModelName = this.getModelName.bind(this);
|
|
@@ -145,8 +145,8 @@ export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
|
145
145
|
this.updateDateState = this.updateDateState.bind(this);
|
|
146
146
|
this.prepareCustomData = this.prepareCustomData.bind(this);
|
|
147
147
|
}
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
running?: boolean;
|
|
149
|
+
form?: HTMLFormElement|null;
|
|
150
150
|
/*
|
|
151
151
|
protected handleSubmitForm(e) {
|
|
152
152
|
if (e.which === 13) {
|
|
@@ -163,7 +163,7 @@ export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
|
163
163
|
|
|
164
164
|
prepareCustomData(data: any) { }
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
updatePhoneState = (event: any) => {
|
|
167
167
|
const re = /^[0-9\b]+$/;
|
|
168
168
|
const target = event.currentTarget as HTMLInputElement;
|
|
169
169
|
const value = removePhoneFormat(target.value);
|
|
@@ -182,7 +182,7 @@ export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
updateDateState = (name: string, value: any) => {
|
|
186
186
|
const props: any = this.props;
|
|
187
187
|
const modelName = this.getModelName(this.form);
|
|
188
188
|
const state = (this.state as any)[modelName];
|
|
@@ -194,7 +194,7 @@ export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
|
194
194
|
this.setState(objSet);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
getModelName(f?: HTMLFormElement|null): string {
|
|
198
198
|
let f2 = f;
|
|
199
199
|
if (!f2) {
|
|
200
200
|
f2 = this.form;
|
|
@@ -207,7 +207,7 @@ export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
|
207
207
|
}
|
|
208
208
|
return 'model';
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
updateState = (e: any, callback?: () => void, lc?: Locale) => {
|
|
211
211
|
const ctrl = e.currentTarget as HTMLInputElement;
|
|
212
212
|
const modelName = this.getModelName(ctrl.form);
|
|
213
213
|
const l = localeOf(lc, this.getLocale);
|
|
@@ -226,7 +226,7 @@ export class BaseComponent<P, S> extends React.Component<P, S> {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
updateFlatState(e: any, callback?: () => void, lc?: Locale) {
|
|
230
230
|
const l = localeOf(lc, this.getLocale);
|
|
231
231
|
const objSet: any = buildFlatState(e, this.state, l);
|
|
232
232
|
if (objSet != null) {
|
|
@@ -255,7 +255,7 @@ export class MessageComponent<S extends MessageOnlyState, P> extends BaseCompone
|
|
|
255
255
|
ref: any;
|
|
256
256
|
name?: string;
|
|
257
257
|
alertClass = '';
|
|
258
|
-
|
|
258
|
+
getModelName(f?: HTMLFormElement|null): string {
|
|
259
259
|
if (this.name && this.name.length > 0) {
|
|
260
260
|
return this.name;
|
|
261
261
|
}
|
|
@@ -291,7 +291,7 @@ export class MessageComponent<S extends MessageOnlyState, P> extends BaseCompone
|
|
|
291
291
|
this.setState({ message: '' });
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
export class BaseSearchComponent<T, S extends Filter, P
|
|
294
|
+
export class BaseSearchComponent<T, S extends Filter, P, I extends SearchState<T, S>> extends BaseComponent<P, I> implements Searchable {
|
|
295
295
|
constructor(props: P,
|
|
296
296
|
protected resourceService: ResourceService,
|
|
297
297
|
protected showMessage: (msg: string) => void,
|
|
@@ -306,7 +306,6 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
306
306
|
|
|
307
307
|
this.toggleFilter = this.toggleFilter.bind(this);
|
|
308
308
|
this.load = this.load.bind(this);
|
|
309
|
-
this.add = this.add.bind(this);
|
|
310
309
|
this.getSearchForm = this.getSearchForm.bind(this);
|
|
311
310
|
this.setSearchForm = this.setSearchForm.bind(this);
|
|
312
311
|
|
|
@@ -329,7 +328,8 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
329
328
|
this.showMore = this.showMore.bind(this);
|
|
330
329
|
this.pageChanged = this.pageChanged.bind(this);
|
|
331
330
|
|
|
332
|
-
|
|
331
|
+
const currentUrl = window.location.host + window.location.pathname;
|
|
332
|
+
this.url = removeUrlParams(currentUrl);
|
|
333
333
|
/*
|
|
334
334
|
this.locationSearch = '';
|
|
335
335
|
const location = (props.location ? props.location : props['props'].location);
|
|
@@ -338,9 +338,10 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
338
338
|
}
|
|
339
339
|
*/
|
|
340
340
|
}
|
|
341
|
-
|
|
342
|
-
|
|
341
|
+
resource: StringMap;
|
|
342
|
+
url: string;
|
|
343
343
|
|
|
344
|
+
filter?: S;
|
|
344
345
|
// Pagination
|
|
345
346
|
initPageSize = 20;
|
|
346
347
|
pageSize = 20;
|
|
@@ -383,18 +384,13 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
383
384
|
approvable?: boolean;
|
|
384
385
|
deletable?: boolean;
|
|
385
386
|
|
|
386
|
-
|
|
387
|
+
getModelName(): string {
|
|
387
388
|
return 'filter';
|
|
388
389
|
}
|
|
389
390
|
|
|
390
391
|
toggleFilter(event: any): void {
|
|
391
392
|
this.hideFilter = !this.hideFilter;
|
|
392
393
|
}
|
|
393
|
-
protected add = (event: any) => {
|
|
394
|
-
event.preventDefault();
|
|
395
|
-
const url = (this.props as any)['props'].match.url + '/add';
|
|
396
|
-
this.props.history.push(url);
|
|
397
|
-
}
|
|
398
394
|
load(s: S, autoSearch: boolean): void {
|
|
399
395
|
const obj2 = initFilter(s, this);
|
|
400
396
|
this.setFilter(obj2);
|
|
@@ -406,20 +402,23 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
406
402
|
}
|
|
407
403
|
}
|
|
408
404
|
|
|
409
|
-
|
|
405
|
+
setSearchForm(form: HTMLFormElement): void {
|
|
410
406
|
this.form = form;
|
|
411
407
|
}
|
|
412
408
|
|
|
413
|
-
|
|
409
|
+
getSearchForm(): HTMLFormElement|undefined|null {
|
|
414
410
|
if (!this.form && this.listFormId) {
|
|
415
411
|
this.form = document.getElementById(this.listFormId) as HTMLFormElement;
|
|
416
412
|
}
|
|
417
413
|
return this.form;
|
|
418
414
|
}
|
|
419
415
|
setFilter(filter: S): void {
|
|
420
|
-
this.
|
|
416
|
+
const modelName = this.getModelName();
|
|
417
|
+
const objSet: any = {};
|
|
418
|
+
objSet[modelName] = filter;
|
|
419
|
+
this.setState(objSet);
|
|
421
420
|
}
|
|
422
|
-
|
|
421
|
+
getCurrencyCode(): string|undefined {
|
|
423
422
|
return getCurrencyCode(this.form);
|
|
424
423
|
}
|
|
425
424
|
getFilter(): S {
|
|
@@ -439,7 +438,7 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
439
438
|
const obj3 = getModel<T, S>(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
|
|
440
439
|
return obj3;
|
|
441
440
|
}
|
|
442
|
-
|
|
441
|
+
getFields(): string[]|undefined {
|
|
443
442
|
const fs = getFieldsFromForm(this.fields, this.initFields, this.form);
|
|
444
443
|
this.initFields = true;
|
|
445
444
|
return fs;
|
|
@@ -450,11 +449,11 @@ export class BaseSearchComponent<T, S extends Filter, P extends RouteComponentPr
|
|
|
450
449
|
this.pageSizeChanged(size);
|
|
451
450
|
}
|
|
452
451
|
*/
|
|
453
|
-
|
|
452
|
+
pageSizeOnClick = () => {
|
|
454
453
|
this.setState(prevState => ({ isPageSizeOpenDropDown: !(prevState as any).isPageSizeOpenDropDown } as any));
|
|
455
454
|
}
|
|
456
455
|
|
|
457
|
-
|
|
456
|
+
clearQ(): void {
|
|
458
457
|
const m = this.state.model;
|
|
459
458
|
if (m) {
|
|
460
459
|
m.q = '';
|
|
@@ -638,6 +637,7 @@ export class SearchComponent<T, S extends Filter, P extends RouteComponentProps,
|
|
|
638
637
|
}
|
|
639
638
|
}
|
|
640
639
|
}
|
|
640
|
+
this.add = this.add.bind(this);
|
|
641
641
|
this.call = this.call.bind(this);
|
|
642
642
|
this.showError = getErrorFunc(param, showError);
|
|
643
643
|
this.componentDidMount = this.componentDidMount.bind(this);
|
|
@@ -663,6 +663,11 @@ export class SearchComponent<T, S extends Filter, P extends RouteComponentProps,
|
|
|
663
663
|
const s: any = {};
|
|
664
664
|
return s;
|
|
665
665
|
}
|
|
666
|
+
add = (event: any) => {
|
|
667
|
+
event.preventDefault();
|
|
668
|
+
const url = this.url + '/add';
|
|
669
|
+
this.props.history.push(url);
|
|
670
|
+
}
|
|
666
671
|
call(se: S) {
|
|
667
672
|
this.running = true;
|
|
668
673
|
const s = clone(se);
|
|
@@ -766,25 +771,25 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
766
771
|
|
|
767
772
|
insertSuccessMsg: string;
|
|
768
773
|
updateSuccessMsg: string;
|
|
769
|
-
|
|
774
|
+
back(event: any) {
|
|
770
775
|
if (event) {
|
|
771
776
|
event.preventDefault();
|
|
772
777
|
}
|
|
773
778
|
this.props.history.goBack();
|
|
774
779
|
}
|
|
775
|
-
|
|
780
|
+
resetState(newMod: boolean, model: T, originalModel?: T) {
|
|
776
781
|
this.newMode = newMod;
|
|
777
782
|
this.orginalModel = originalModel;
|
|
778
783
|
this.showModel(model);
|
|
779
784
|
}
|
|
780
|
-
|
|
785
|
+
handleNotFound(form?: HTMLFormElement|null): void {
|
|
781
786
|
const msg = message(this.resourceService.value, 'error_not_found', 'error');
|
|
782
787
|
if (form) {
|
|
783
788
|
readOnly(form);
|
|
784
789
|
}
|
|
785
790
|
this.showError(msg.message, msg.title);
|
|
786
791
|
}
|
|
787
|
-
|
|
792
|
+
getModelName(f?: HTMLFormElement): string {
|
|
788
793
|
if (this.name && this.name.length > 0) {
|
|
789
794
|
return this.name;
|
|
790
795
|
}
|
|
@@ -807,7 +812,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
807
812
|
}
|
|
808
813
|
|
|
809
814
|
// end of: can be in ViewComponent
|
|
810
|
-
|
|
815
|
+
createModel(): T {
|
|
811
816
|
if (this.metadata) {
|
|
812
817
|
const obj = createModel2<T>(this.metadata);
|
|
813
818
|
return obj;
|
|
@@ -834,7 +839,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
834
839
|
}, 100);
|
|
835
840
|
}
|
|
836
841
|
}
|
|
837
|
-
|
|
842
|
+
saveOnClick = (event: any) => {
|
|
838
843
|
event.preventDefault();
|
|
839
844
|
(event as any).persist();
|
|
840
845
|
if (!this.form && event && event.target) {
|
|
@@ -881,7 +886,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
881
886
|
}
|
|
882
887
|
}
|
|
883
888
|
}
|
|
884
|
-
|
|
889
|
+
validate(obj: T, callback: (obj2?: T) => void) {
|
|
885
890
|
if (this.ui && this.form) {
|
|
886
891
|
const valid = this.ui.validateForm(this.form, localeOf(undefined, this.getLocale));
|
|
887
892
|
if (valid) {
|
|
@@ -892,10 +897,10 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
899
|
|
|
895
|
-
|
|
900
|
+
save(obj: T, dif?: T, isBack?: boolean) {
|
|
896
901
|
}
|
|
897
902
|
|
|
898
|
-
|
|
903
|
+
succeed(msg: string, isBack?: boolean, result?: ResultInfo<T>) {
|
|
899
904
|
if (result) {
|
|
900
905
|
const model = result.value;
|
|
901
906
|
this.newMode = false;
|
|
@@ -913,7 +918,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
913
918
|
this.back(null);
|
|
914
919
|
}
|
|
915
920
|
}
|
|
916
|
-
|
|
921
|
+
fail(result: ResultInfo<T>) {
|
|
917
922
|
const errors = result.errors;
|
|
918
923
|
const f = this.form;
|
|
919
924
|
const u = this.ui;
|
|
@@ -936,7 +941,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
936
941
|
}
|
|
937
942
|
}
|
|
938
943
|
|
|
939
|
-
|
|
944
|
+
postSave(res: number|string|ResultInfo<T>, backOnSave?: boolean) {
|
|
940
945
|
this.running = false;
|
|
941
946
|
hideLoading(this.loading);
|
|
942
947
|
const st = this.status;
|
|
@@ -972,7 +977,7 @@ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> ext
|
|
|
972
977
|
}
|
|
973
978
|
}
|
|
974
979
|
}
|
|
975
|
-
|
|
980
|
+
handleDuplicateKey(result?: ResultInfo<T>) {
|
|
976
981
|
const msg = message(this.resourceService.value, 'error_duplicate_key', 'error');
|
|
977
982
|
this.showError(msg.message, msg.title);
|
|
978
983
|
}
|
|
@@ -1012,7 +1017,7 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
|
|
|
1012
1017
|
this.componentDidMount = this.componentDidMount.bind(this);
|
|
1013
1018
|
this.ref = React.createRef();
|
|
1014
1019
|
}
|
|
1015
|
-
|
|
1020
|
+
ref: any;
|
|
1016
1021
|
componentDidMount() {
|
|
1017
1022
|
const k = (this.ui ? this.ui.registerEvents : undefined);
|
|
1018
1023
|
this.form = initForm(this.ref.current, k);
|
|
@@ -1073,7 +1078,7 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
|
|
|
1073
1078
|
}
|
|
1074
1079
|
}
|
|
1075
1080
|
}
|
|
1076
|
-
|
|
1081
|
+
save(obj: T, body?: T, isBack?: boolean) {
|
|
1077
1082
|
this.running = true;
|
|
1078
1083
|
showLoading(this.loading);
|
|
1079
1084
|
const isBackO = (isBack == null || isBack === undefined ? this.backOnSuccess : isBack);
|
|
@@ -1122,25 +1127,25 @@ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S exten
|
|
|
1122
1127
|
disabled: false
|
|
1123
1128
|
};
|
|
1124
1129
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
+
status: DiffStatusConfig;
|
|
1131
|
+
id?: ID;
|
|
1132
|
+
form?: HTMLFormElement;
|
|
1133
|
+
running?: boolean;
|
|
1134
|
+
resource: StringMap;
|
|
1130
1135
|
|
|
1131
|
-
|
|
1136
|
+
back(event: any) {
|
|
1132
1137
|
if (event) {
|
|
1133
1138
|
event.preventDefault();
|
|
1134
1139
|
}
|
|
1135
1140
|
this.props.history.goBack();
|
|
1136
1141
|
}
|
|
1137
1142
|
|
|
1138
|
-
|
|
1143
|
+
initModel(): T {
|
|
1139
1144
|
const x: any = {};
|
|
1140
1145
|
return x;
|
|
1141
1146
|
}
|
|
1142
1147
|
|
|
1143
|
-
|
|
1148
|
+
postApprove(s: number|string, err?: any) {
|
|
1144
1149
|
this.setState({ disabled: true });
|
|
1145
1150
|
const r = this.resourceService;
|
|
1146
1151
|
const st = this.status;
|
|
@@ -1156,7 +1161,7 @@ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S exten
|
|
|
1156
1161
|
}
|
|
1157
1162
|
}
|
|
1158
1163
|
|
|
1159
|
-
|
|
1164
|
+
postReject(status: number|string, err?: any) {
|
|
1160
1165
|
this.setState({ disabled: true });
|
|
1161
1166
|
const r = this.resourceService;
|
|
1162
1167
|
const st = this.status;
|
|
@@ -1211,7 +1216,7 @@ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S exten
|
|
|
1211
1216
|
}
|
|
1212
1217
|
}
|
|
1213
1218
|
|
|
1214
|
-
|
|
1219
|
+
handleNotFound() {
|
|
1215
1220
|
this.setState({ disabled: true });
|
|
1216
1221
|
const msg = message(this.resourceService.value, 'error_not_found', 'error');
|
|
1217
1222
|
this.showError(msg.message, msg.title);
|
|
@@ -1235,7 +1240,7 @@ export class DiffApprComponent<T, ID, P extends RouteComponentProps, S extends D
|
|
|
1235
1240
|
disabled: false,
|
|
1236
1241
|
};
|
|
1237
1242
|
}
|
|
1238
|
-
|
|
1243
|
+
ref: any;
|
|
1239
1244
|
|
|
1240
1245
|
componentDidMount() {
|
|
1241
1246
|
this.form = this.ref.current;
|
|
@@ -1317,3 +1322,7 @@ export class DiffApprComponent<T, ID, P extends RouteComponentProps, S extends D
|
|
|
1317
1322
|
}
|
|
1318
1323
|
}
|
|
1319
1324
|
}
|
|
1325
|
+
export function removeUrlParams(url: string): string {
|
|
1326
|
+
const startParams = url.indexOf('?');
|
|
1327
|
+
return startParams !== -1 ? url.substring(0, startParams) : url;
|
|
1328
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,3 +20,28 @@ export const withDefaultProps = (Component: any) => (props: RouteComponentProps)
|
|
|
20
20
|
// return <Component props={props} history={props.history} />;
|
|
21
21
|
return React.createElement(Component, { props, history: props.history });
|
|
22
22
|
};
|
|
23
|
+
export interface LoadingProps {
|
|
24
|
+
error?: any;
|
|
25
|
+
}
|
|
26
|
+
export const Loading = (props: LoadingProps) => {
|
|
27
|
+
const loadingStyle = {
|
|
28
|
+
top: '30%',
|
|
29
|
+
backgroundColor: 'white',
|
|
30
|
+
border: 'none',
|
|
31
|
+
'WebkitBoxShadow': 'none',
|
|
32
|
+
'boxShadow': 'none'
|
|
33
|
+
};
|
|
34
|
+
if (props.error) {
|
|
35
|
+
return React.createElement("div", null, "Error Load Module!");// return (<div>Error Load Module!</div>);
|
|
36
|
+
} else {
|
|
37
|
+
return (React.createElement("div", { className: 'loader-wrapper' }, React.createElement("div", { className: 'loader-sign', style: loadingStyle }, React.createElement("div", { className: 'loader' }))));
|
|
38
|
+
/*
|
|
39
|
+
return (
|
|
40
|
+
<div className='loader-wrapper'>
|
|
41
|
+
<div className='loader-sign' style={loadingStyle}>
|
|
42
|
+
<div className='loader' />
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
);*/
|
|
46
|
+
}
|
|
47
|
+
};
|
package/src/useSearch.ts
CHANGED
|
@@ -110,7 +110,7 @@ export interface SearchComponentState<T, S> extends Pagination, Sortable {
|
|
|
110
110
|
view?: string;
|
|
111
111
|
nextPageToken?: string;
|
|
112
112
|
keys?: string[];
|
|
113
|
-
|
|
113
|
+
filter?: S;
|
|
114
114
|
list?: T[];
|
|
115
115
|
|
|
116
116
|
format?: (obj: T, locale: Locale) => T;
|
|
@@ -133,7 +133,7 @@ export interface SearchComponentState<T, S> extends Pagination, Sortable {
|
|
|
133
133
|
}
|
|
134
134
|
export const pageSizes = [10, 20, 40, 60, 100, 200, 400, 800];
|
|
135
135
|
|
|
136
|
-
function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>):
|
|
136
|
+
function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>): SearchComponentParam<T, S> {
|
|
137
137
|
if (p) {
|
|
138
138
|
if (!p.sequenceNo) {
|
|
139
139
|
p.sequenceNo = 'sequenceNo';
|
|
@@ -147,6 +147,14 @@ function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>): void {
|
|
|
147
147
|
if (!p.pageMaxSize || p.pageMaxSize <= 0) {
|
|
148
148
|
p.pageMaxSize = 7;
|
|
149
149
|
}
|
|
150
|
+
return p;
|
|
151
|
+
} else {
|
|
152
|
+
return {
|
|
153
|
+
sequenceNo: 'sequenceNo',
|
|
154
|
+
pageSize: 20,
|
|
155
|
+
pageSizes,
|
|
156
|
+
pageMaxSize: 7
|
|
157
|
+
};
|
|
150
158
|
}
|
|
151
159
|
}
|
|
152
160
|
export const useSearch = <T, S extends Filter, ST extends SearchComponentState<T, S>>(
|
|
@@ -156,6 +164,7 @@ export const useSearch = <T, S extends Filter, ST extends SearchComponentState<T
|
|
|
156
164
|
p2: SearchParameter,
|
|
157
165
|
p?: InitSearchComponentParam<T, S, ST>,
|
|
158
166
|
) => {
|
|
167
|
+
debugger;
|
|
159
168
|
const baseProps = useCoreSearch(undefined, refForm, initialState, search, p2, p);
|
|
160
169
|
|
|
161
170
|
useEffect(() => {
|
|
@@ -185,28 +194,28 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
185
194
|
refForm: any,
|
|
186
195
|
initialState: ST,
|
|
187
196
|
search: ((s: S, limit?: number, offset?: number|string, fields?: string[]) => Promise<SearchResult<T>>) | SearchService<T, S>,
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
p1: SearchParameter,
|
|
198
|
+
p2?: SearchComponentParam<T, S>
|
|
190
199
|
) => {
|
|
191
|
-
mergeParam(
|
|
200
|
+
const p = mergeParam(p2);
|
|
192
201
|
const [running, setRunning] = useState<boolean>();
|
|
193
202
|
|
|
194
203
|
const _getModelName = (): string => {
|
|
195
|
-
return getName('filter',
|
|
204
|
+
return getName('filter', p && p.name ? p.name : undefined);
|
|
196
205
|
};
|
|
197
|
-
const getModelName = (
|
|
206
|
+
const getModelName = (p && p.getModelName ? p.getModelName : _getModelName);
|
|
198
207
|
|
|
199
208
|
// const setState2: <K extends keyof S, P>(st: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null), cb?: () => void) => void;
|
|
200
|
-
const baseProps = (props ? useUpdateWithProps<ST, P>(props, initialState, getModelName,
|
|
209
|
+
const baseProps = (props ? useUpdateWithProps<ST, P>(props, initialState, getModelName, p1.getLocale, getRemoveError(p1), p ? p.prepareCustomData : undefined) : useUpdate<ST>(initialState, getModelName, p1.getLocale, getRemoveError(p1)));
|
|
201
210
|
const { state, setState } = baseProps;
|
|
202
211
|
const [history, match] = [useHistory(), useRouteMatch()];
|
|
203
212
|
|
|
204
213
|
const _getCurrencyCode = (): string => {
|
|
205
214
|
return refForm && refForm.current ? refForm.current.getAttribute('currency-code') : null;
|
|
206
215
|
};
|
|
207
|
-
const getCurrencyCode =
|
|
216
|
+
const getCurrencyCode = p && p.getCurrencyCode ? p.getCurrencyCode : _getCurrencyCode;
|
|
208
217
|
|
|
209
|
-
const prepareCustomData = (
|
|
218
|
+
const prepareCustomData = (p && p.prepareCustomData ? p.prepareCustomData : prepareData);
|
|
210
219
|
const updateDateState = (name: string, value: any) => {
|
|
211
220
|
const modelName = getModelName();
|
|
212
221
|
const currentState = (state as any)[modelName];
|
|
@@ -220,7 +229,7 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
220
229
|
};
|
|
221
230
|
|
|
222
231
|
// const p = createSearchComponentState<T, S>(p1);
|
|
223
|
-
const [component, setComponent] = useMergeState<SearchComponentState<T, S>>(
|
|
232
|
+
const [component, setComponent] = useMergeState<SearchComponentState<T, S>>(p);
|
|
224
233
|
|
|
225
234
|
const toggleFilter = (event: any): void => {
|
|
226
235
|
setComponent({ hideFilter: !component.hideFilter });
|
|
@@ -237,24 +246,24 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
237
246
|
setComponent({ fields: fs, initFields: true });
|
|
238
247
|
return fs;
|
|
239
248
|
};
|
|
240
|
-
const getFields =
|
|
249
|
+
const getFields = p && p.getFields ? p.getFields : _getFields;
|
|
241
250
|
|
|
242
251
|
const getFilter = (se?: Searchable<T>): S => {
|
|
243
252
|
if (!se) {
|
|
244
253
|
se = component;
|
|
245
254
|
}
|
|
246
|
-
let keys =
|
|
255
|
+
let keys = p && p.keys ? p.keys : undefined;
|
|
247
256
|
if (!keys && typeof search !== 'function' && search.keys) {
|
|
248
257
|
keys = search.keys();
|
|
249
258
|
}
|
|
250
259
|
const n = getModelName();
|
|
251
|
-
let fs =
|
|
260
|
+
let fs = p && p.fields;
|
|
252
261
|
if (!fs || fs.length <= 0) {
|
|
253
262
|
fs = getFields();
|
|
254
263
|
}
|
|
255
|
-
const lc = (
|
|
264
|
+
const lc = (p1.getLocale ? p1.getLocale() : enLocale);
|
|
256
265
|
const cc = getCurrencyCode();
|
|
257
|
-
const obj3 = getModel<T, S>(state, n, se, fs, se.excluding, keys, se.list, refForm.current, getDecodeFromForm(
|
|
266
|
+
const obj3 = getModel<T, S>(state, n, se, fs, se.excluding, keys, se.list, refForm.current, getDecodeFromForm(p1), lc, cc);
|
|
258
267
|
return obj3;
|
|
259
268
|
};
|
|
260
269
|
const _setFilter = (s: S): void => {
|
|
@@ -264,7 +273,7 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
264
273
|
setState(objSet);
|
|
265
274
|
};
|
|
266
275
|
|
|
267
|
-
const setFilter =
|
|
276
|
+
const setFilter = p && p.setFilter ? p.setFilter : _setFilter;
|
|
268
277
|
|
|
269
278
|
const _load = (s: S, auto?: boolean): void => {
|
|
270
279
|
const com = Object.assign({}, component);
|
|
@@ -278,10 +287,10 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
278
287
|
}, 0);
|
|
279
288
|
}
|
|
280
289
|
};
|
|
281
|
-
const load =
|
|
290
|
+
const load = p && p.load ? p.load : _load;
|
|
282
291
|
|
|
283
292
|
const doSearch = (se: Searchable<T>, isFirstLoad?: boolean) => {
|
|
284
|
-
removeFormError(
|
|
293
|
+
removeFormError(p1, refForm.current);
|
|
285
294
|
const s = getFilter(se);
|
|
286
295
|
const isStillRunning = running;
|
|
287
296
|
validateSearch(s, () => {
|
|
@@ -289,11 +298,11 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
289
298
|
return;
|
|
290
299
|
}
|
|
291
300
|
setRunning(true);
|
|
292
|
-
showLoading(
|
|
293
|
-
if (
|
|
301
|
+
showLoading(p1.loading);
|
|
302
|
+
if (p && !p.ignoreUrlParam) {
|
|
294
303
|
addParametersIntoUrl(s, isFirstLoad);
|
|
295
304
|
}
|
|
296
|
-
const lc =
|
|
305
|
+
const lc = p1.getLocale ? p1.getLocale() : enLocale;
|
|
297
306
|
if (typeof search === 'function') {
|
|
298
307
|
callSearch<T, S>(s, search, showResults, searchError, lc, se.nextPageToken);
|
|
299
308
|
} else {
|
|
@@ -303,9 +312,9 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
303
312
|
};
|
|
304
313
|
|
|
305
314
|
const _validateSearch = (se: S, callback: () => void) => {
|
|
306
|
-
validate(se, callback, refForm.current, (
|
|
315
|
+
validate(se, callback, refForm.current, (p1.getLocale ? p1.getLocale() : undefined), getValidateForm(p1));
|
|
307
316
|
};
|
|
308
|
-
const validateSearch =
|
|
317
|
+
const validateSearch = p && p.validateSearch ? p.validateSearch : _validateSearch;
|
|
309
318
|
|
|
310
319
|
const pageSizeChanged = (event: any) => {
|
|
311
320
|
const size = parseInt(event.currentTarget.value, 10);
|
|
@@ -395,14 +404,14 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
395
404
|
|
|
396
405
|
const searchError = (err: any): void => {
|
|
397
406
|
setComponent({ pageIndex: component.tmpPageIndex });
|
|
398
|
-
error(err,
|
|
407
|
+
error(err, p1.resource.value, p1.showError);
|
|
399
408
|
};
|
|
400
|
-
const appendList = (
|
|
401
|
-
const setList = (
|
|
409
|
+
const appendList = (p && p.appendList ? p.appendList : appendListOfState);
|
|
410
|
+
const setList = (p && p.setList ? p.setList : setListOfState);
|
|
402
411
|
const _showResults = (s: S, sr: SearchResult<T>, lc: Locale) => {
|
|
403
412
|
const results = sr.list;
|
|
404
413
|
if (results && results.length > 0) {
|
|
405
|
-
formatResults(results, component.pageIndex, component.pageSize, component.initPageSize,
|
|
414
|
+
formatResults(results, component.pageIndex, component.pageSize, component.initPageSize, p ? p.sequenceNo : undefined, p ? p.format : undefined, lc);
|
|
406
415
|
}
|
|
407
416
|
const am = component.appendMode;
|
|
408
417
|
const pi = (s.page && s.page >= 1 ? s.page : 1);
|
|
@@ -423,18 +432,18 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
423
432
|
setList(results, setState as any);
|
|
424
433
|
setComponent({ tmpPageIndex: s.page });
|
|
425
434
|
if (s.limit) {
|
|
426
|
-
const m1 = buildMessage(
|
|
427
|
-
|
|
435
|
+
const m1 = buildMessage(p1.resource, s.page, s.limit, sr.list, sr.total);
|
|
436
|
+
p1.showMessage(m1);
|
|
428
437
|
}
|
|
429
438
|
}
|
|
430
439
|
setRunning(false);
|
|
431
|
-
hideLoading(
|
|
440
|
+
hideLoading(p1.loading);
|
|
432
441
|
if (component.triggerSearch) {
|
|
433
442
|
setComponent({ triggerSearch: false });
|
|
434
443
|
resetAndSearch();
|
|
435
444
|
}
|
|
436
445
|
};
|
|
437
|
-
const showResults = (
|
|
446
|
+
const showResults = (p && p.showResults ? p.showResults : _showResults);
|
|
438
447
|
|
|
439
448
|
const showMore = (event: any) => {
|
|
440
449
|
event.preventDefault();
|
|
@@ -462,10 +471,10 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
462
471
|
setRunning,
|
|
463
472
|
getCurrencyCode,
|
|
464
473
|
updateDateState,
|
|
465
|
-
resource:
|
|
474
|
+
resource: p1.resource.resource(),
|
|
466
475
|
setComponent,
|
|
467
476
|
component,
|
|
468
|
-
showMessage:
|
|
477
|
+
showMessage: p1.showMessage,
|
|
469
478
|
load,
|
|
470
479
|
add,
|
|
471
480
|
searchOnClick,
|
|
@@ -480,6 +489,6 @@ export const useCoreSearch = <T, S extends Filter, ST, P>(
|
|
|
480
489
|
showResults,
|
|
481
490
|
getFields,
|
|
482
491
|
getModelName,
|
|
483
|
-
format:
|
|
492
|
+
format: p ? p.format : undefined
|
|
484
493
|
};
|
|
485
494
|
};
|