@steroidsjs/core 2.1.0-beta.26 → 2.1.0-beta.30
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/actions/modal.d.ts +1 -1
- package/components/SocialComponent.js +10 -8
- package/components/social/FacebookProvider.d.ts +1 -1
- package/components/social/FacebookProvider.js +5 -6
- package/components/social/GitlabProvider.d.ts +1 -1
- package/components/social/GitlabProvider.js +5 -5
- package/components/social/GoogleProvider.d.ts +1 -1
- package/components/social/GoogleProvider.js +2 -2
- package/components/social/SteamProvider.d.ts +1 -1
- package/components/social/SteamProvider.js +8 -9
- package/components/social/VkProvider.d.ts +1 -1
- package/components/social/VkProvider.js +8 -9
- package/hooks/useComponents.js +1 -2
- package/hooks/useDataProvider.d.ts +1 -0
- package/hooks/useDataProvider.js +2 -3
- package/hooks/useDataSelect.d.ts +3 -3
- package/hooks/useDataSelect.js +6 -3
- package/hooks/useFetch.js +3 -0
- package/hooks/useLayout.js +21 -12
- package/hooks/useList.d.ts +11 -1
- package/hooks/useList.js +8 -3
- package/package.json +1 -1
- package/reducers/form.d.ts +1 -0
- package/reducers/form.js +3 -1
- package/reducers/router.js +7 -3
- package/ui/content/Detail/Detail.d.ts +1 -1
- package/ui/crud/Crud/Crud.js +4 -2
- package/ui/crud/Crud/CrudContent.d.ts +5 -1
- package/ui/crud/Crud/CrudContent.js +5 -5
- package/ui/crud/index.d.ts +1 -0
- package/ui/form/AutoCompleteField/AutoCompleteField.d.ts +1 -6
- package/ui/form/BlankField/BlankField.d.ts +1 -6
- package/ui/form/CheckboxField/CheckboxField.d.ts +1 -6
- package/ui/form/CheckboxListField/CheckboxListField.d.ts +1 -6
- package/ui/form/DateField/DateField.d.ts +1 -7
- package/ui/form/DateRangeField/DateRangeField.d.ts +1 -7
- package/ui/form/DateRangeField/DateRangeField.js +2 -1
- package/ui/form/DateTimeField/DateTimeField.d.ts +1 -7
- package/ui/form/DateTimeRangeField/DateTimeRangeField.d.ts +1 -7
- package/ui/form/DropDownField/DropDownField.d.ts +1 -7
- package/ui/form/DropDownField/DropDownField.js +8 -5
- package/ui/form/Field/fieldWrapper.d.ts +4 -4
- package/ui/form/FieldList/FieldList.d.ts +1 -6
- package/ui/form/FileField/FileField.d.ts +1 -6
- package/ui/form/Form/Form.js +1 -1
- package/ui/form/HtmlField/HtmlField.d.ts +1 -7
- package/ui/form/ImageField/ImageField.d.ts +1 -7
- package/ui/form/InputField/InputField.d.ts +1 -6
- package/ui/form/NavField/NavField.d.ts +2 -8
- package/ui/form/NumberField/NumberField.d.ts +1 -6
- package/ui/form/PasswordField/PasswordField.d.ts +1 -6
- package/ui/form/RadioListField/RadioListField.d.ts +1 -6
- package/ui/form/RateField/RateField.d.ts +2 -8
- package/ui/form/ReCaptchaField/ReCaptchaField.d.ts +1 -7
- package/ui/form/SliderField/SliderField.d.ts +4 -11
- package/ui/form/SliderField/demo/marks.js +8 -10
- package/ui/form/SwitcherField/SwitcherField.d.ts +1 -7
- package/ui/form/TextField/TextField.d.ts +1 -6
- package/ui/form/TimeField/TimeField.d.ts +1 -7
- package/ui/form/index.d.ts +22 -132
- package/ui/list/Grid/Grid.js +3 -1
- package/ui/list/Grid/demo/inner-search-form.d.ts +1 -6
- package/ui/list/List/List.js +4 -6
- package/ui/list/PaginationSize/PaginationSize.d.ts +2 -2
- package/ui/nav/Router/Router.d.ts +5 -0
- package/ui/nav/Router/Router.js +0 -2
- package/components/social/index.d.ts +0 -13
- package/components/social/index.js +0 -17
package/actions/modal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IModalProps } from '
|
|
1
|
+
import { IModalProps } from '../ui/modal/Modal/Modal';
|
|
2
2
|
export declare const MODAL_OPEN = "@modal/open";
|
|
3
3
|
export declare const MODAL_MARK_CLOSING = "@modal/markClosing";
|
|
4
4
|
export declare const MODAL_CLOSE = "@modal/close";
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
var
|
|
6
|
+
var isFunction_1 = __importDefault(require("lodash-es/isFunction"));
|
|
7
7
|
/**
|
|
8
8
|
* Social Component
|
|
9
9
|
* Провайдер для социальных сетей. Обеспечивает вызов окна соц сети для oauth авторизации
|
|
@@ -17,11 +17,15 @@ var SocialComponent = /** @class */ (function () {
|
|
|
17
17
|
SocialComponent.prototype.init = function () {
|
|
18
18
|
var _this = this;
|
|
19
19
|
Object.keys(this.providers).forEach(function (name) {
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
_this.providers[name] = new social_1["default"][name](_this._components);
|
|
23
|
-
Object.assign(_this.providers[name], config);
|
|
20
|
+
if (isFunction_1["default"](_this.providers[name])) {
|
|
21
|
+
_this.providers[name] = { className: _this.providers[name] };
|
|
24
22
|
}
|
|
23
|
+
var ProviderClass = _this.providers[name].className;
|
|
24
|
+
delete _this.providers[name].className;
|
|
25
|
+
if (!ProviderClass) {
|
|
26
|
+
throw new Error('Not found class for social provider: ' + name);
|
|
27
|
+
}
|
|
28
|
+
_this.providers[name] = new ProviderClass(_this._components, _this.providers[name]);
|
|
25
29
|
});
|
|
26
30
|
Object.keys(this.providers).forEach(function (name) {
|
|
27
31
|
_this._initializing[name] = _this.providers[name].init();
|
|
@@ -32,9 +36,7 @@ var SocialComponent = /** @class */ (function () {
|
|
|
32
36
|
if (!this._initializing[socialName]) {
|
|
33
37
|
return Promise.reject();
|
|
34
38
|
}
|
|
35
|
-
return this._initializing[socialName].then(function () {
|
|
36
|
-
return _this.providers[socialName].start();
|
|
37
|
-
});
|
|
39
|
+
return this._initializing[socialName].then(function () { return _this.providers[socialName].start(); });
|
|
38
40
|
};
|
|
39
41
|
return SocialComponent;
|
|
40
42
|
}());
|
|
@@ -37,13 +37,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
exports.__esModule = true;
|
|
39
39
|
var FacebookProvider = /** @class */ (function () {
|
|
40
|
-
function FacebookProvider(components) {
|
|
40
|
+
function FacebookProvider(components, config) {
|
|
41
41
|
this._components = components;
|
|
42
|
-
this.clientId = '';
|
|
43
|
-
this.language =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this._components.locale.language.toUpperCase();
|
|
42
|
+
this.clientId = config.clientId || '';
|
|
43
|
+
this.language = this._components.locale.language
|
|
44
|
+
+ '_'
|
|
45
|
+
+ this._components.locale.language.toUpperCase();
|
|
47
46
|
}
|
|
48
47
|
FacebookProvider.prototype.init = function () {
|
|
49
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -37,10 +37,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
exports.__esModule = true;
|
|
39
39
|
var GitlabProvider = /** @class */ (function () {
|
|
40
|
-
function GitlabProvider(components) {
|
|
40
|
+
function GitlabProvider(components, config) {
|
|
41
41
|
this._components = components;
|
|
42
|
-
this.url = '';
|
|
43
|
-
this.redirectUrl = this._components.http.getUrl('/api/v1/auth/social/proxy');
|
|
42
|
+
this.url = config.url || '';
|
|
43
|
+
this.redirectUrl = config.redirectUrl || this._components.http.getUrl('/api/v1/auth/social/proxy');
|
|
44
44
|
}
|
|
45
45
|
GitlabProvider.prototype.init = function () {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -78,9 +78,9 @@ var GitlabProvider = /** @class */ (function () {
|
|
|
78
78
|
.join(','));
|
|
79
79
|
popup.onbeforeunload = function () { return reject(); };
|
|
80
80
|
// This is a handler which is used by child window to pass auth result
|
|
81
|
-
// @ts-ignore
|
|
82
81
|
window.authCallback = function (link) {
|
|
83
|
-
// link: http://127.0.0.1:9424/api/v1/auth/social/proxy
|
|
82
|
+
// link: http://127.0.0.1:9424/api/v1/auth/social/proxy
|
|
83
|
+
// ?provider=gitlab_kozhindev#access_token=7b87e3de0...5518198d885d&token_type=Bearer
|
|
84
84
|
var token = (/access_token=(\w+)/.exec(link) || [])[1];
|
|
85
85
|
if (token) {
|
|
86
86
|
resolve({ token: token });
|
|
@@ -37,9 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
exports.__esModule = true;
|
|
39
39
|
var GoogleProvider = /** @class */ (function () {
|
|
40
|
-
function GoogleProvider(components) {
|
|
40
|
+
function GoogleProvider(components, config) {
|
|
41
41
|
this._components = components;
|
|
42
|
-
this.clientId =
|
|
42
|
+
this.clientId = config.clientId;
|
|
43
43
|
}
|
|
44
44
|
GoogleProvider.prototype.init = function () {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -57,9 +57,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
57
57
|
exports.__esModule = true;
|
|
58
58
|
var queryString = __importStar(require("qs"));
|
|
59
59
|
var Vk = /** @class */ (function () {
|
|
60
|
-
function Vk(components) {
|
|
60
|
+
function Vk(components, config) {
|
|
61
61
|
this._components = components;
|
|
62
|
-
this.clientId =
|
|
62
|
+
this.clientId = config.clientId;
|
|
63
63
|
}
|
|
64
64
|
Vk.prototype.init = function () {
|
|
65
65
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -74,14 +74,14 @@ var Vk = /** @class */ (function () {
|
|
|
74
74
|
return __generator(this, function (_a) {
|
|
75
75
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
76
76
|
// Generate url
|
|
77
|
-
var url = 'https://steamcommunity.com/openid/login?'
|
|
78
|
-
queryString.stringify({
|
|
77
|
+
var url = 'https://steamcommunity.com/openid/login?'
|
|
78
|
+
+ queryString.stringify({
|
|
79
79
|
'openid.mode': 'checkid_setup',
|
|
80
80
|
'openid.ns': 'http://specs.openid.net/auth/2.0',
|
|
81
81
|
'openid.identity': 'http://specs.openid.net/auth/2.0/identifier_select',
|
|
82
82
|
'openid.claimed_id': 'http://specs.openid.net/auth/2.0/identifier_select',
|
|
83
83
|
'openid.return_to': _this._components.http.getUrl('/api/v1/auth/social/proxy'),
|
|
84
|
-
'openid.realm': location.origin
|
|
84
|
+
'openid.realm': window.location.origin
|
|
85
85
|
});
|
|
86
86
|
// Open popup auth window
|
|
87
87
|
var width = 900;
|
|
@@ -107,14 +107,13 @@ var Vk = /** @class */ (function () {
|
|
|
107
107
|
.join(','));
|
|
108
108
|
popup.onbeforeunload = function () { return reject(); };
|
|
109
109
|
// This is a handler which is used by child window to pass auth result
|
|
110
|
-
// @ts-ignore
|
|
111
110
|
window.authCallback = function (link) {
|
|
112
|
-
var
|
|
113
|
-
if (!
|
|
111
|
+
var query = queryString.parse(new URL(link).search);
|
|
112
|
+
if (!query['openid.mode']) {
|
|
114
113
|
reject();
|
|
115
114
|
}
|
|
116
115
|
else {
|
|
117
|
-
resolve(
|
|
116
|
+
resolve(query);
|
|
118
117
|
}
|
|
119
118
|
};
|
|
120
119
|
})];
|
|
@@ -57,10 +57,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
57
57
|
exports.__esModule = true;
|
|
58
58
|
var queryString = __importStar(require("qs"));
|
|
59
59
|
var VkProvider = /** @class */ (function () {
|
|
60
|
-
function VkProvider(components) {
|
|
60
|
+
function VkProvider(components, config) {
|
|
61
61
|
this._components = components;
|
|
62
|
-
this.clientId =
|
|
63
|
-
this.redirectUrl = this._components.http.getUrl('/api/v1/auth/social/proxy');
|
|
62
|
+
this.clientId = config.clientId;
|
|
63
|
+
this.redirectUrl = config.redirectUrl || this._components.http.getUrl('/api/v1/auth/social/proxy');
|
|
64
64
|
}
|
|
65
65
|
VkProvider.prototype.init = function () {
|
|
66
66
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -75,8 +75,8 @@ var VkProvider = /** @class */ (function () {
|
|
|
75
75
|
return __generator(this, function (_a) {
|
|
76
76
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
77
77
|
// Generate url
|
|
78
|
-
var url = 'https://oauth.vk.com/authorize/?'
|
|
79
|
-
queryString.stringify({
|
|
78
|
+
var url = 'https://oauth.vk.com/authorize/?'
|
|
79
|
+
+ queryString.stringify({
|
|
80
80
|
client_id: _this.clientId,
|
|
81
81
|
redirect_uri: _this.redirectUrl,
|
|
82
82
|
scope: 'offline,public_profile',
|
|
@@ -106,16 +106,15 @@ var VkProvider = /** @class */ (function () {
|
|
|
106
106
|
.join(','));
|
|
107
107
|
popup.onbeforeunload = function () { return reject(); };
|
|
108
108
|
// This is a handler which is used by child window to pass auth result
|
|
109
|
-
// @ts-ignore
|
|
110
109
|
window.authCallback = function (link) {
|
|
111
|
-
var
|
|
112
|
-
var error =
|
|
110
|
+
var query = new URL(link).searchParams;
|
|
111
|
+
var error = query.get('error');
|
|
113
112
|
if (error) {
|
|
114
113
|
reject(error);
|
|
115
114
|
}
|
|
116
115
|
else {
|
|
117
116
|
resolve({
|
|
118
|
-
token:
|
|
117
|
+
token: query.get('code')
|
|
119
118
|
});
|
|
120
119
|
}
|
|
121
120
|
};
|
package/hooks/useComponents.js
CHANGED
|
@@ -3,10 +3,9 @@ exports.__esModule = true;
|
|
|
3
3
|
var react_1 = require("react");
|
|
4
4
|
var ComponentsProvider_1 = require("../providers/ComponentsProvider");
|
|
5
5
|
function useComponents() {
|
|
6
|
-
var components = react_1.useContext(ComponentsProvider_1.ComponentsContext);
|
|
7
6
|
if (!process.env.IS_SSR) {
|
|
8
7
|
return window.SteroidsComponents;
|
|
9
8
|
}
|
|
10
|
-
return
|
|
9
|
+
return react_1.useContext(ComponentsProvider_1.ComponentsContext); // eslint-disable-line react-hooks/rules-of-hooks
|
|
11
10
|
}
|
|
12
11
|
exports["default"] = useComponents;
|
package/hooks/useDataProvider.js
CHANGED
|
@@ -54,11 +54,11 @@ var react_redux_1 = require("react-redux");
|
|
|
54
54
|
var isString_1 = __importDefault(require("lodash-es/isString"));
|
|
55
55
|
var isFunction_1 = __importDefault(require("lodash-es/isFunction"));
|
|
56
56
|
var react_1 = require("react");
|
|
57
|
+
var react_use_1 = require("react-use");
|
|
57
58
|
var data_1 = require("../utils/data");
|
|
58
59
|
var index_1 = require("./index");
|
|
59
60
|
var fields_1 = require("../reducers/fields");
|
|
60
61
|
var text_1 = require("../utils/text");
|
|
61
|
-
var react_use_1 = require("react-use");
|
|
62
62
|
var defaultProps = {
|
|
63
63
|
autoComplete: {
|
|
64
64
|
enable: false,
|
|
@@ -137,8 +137,7 @@ function useDataProvider(config) {
|
|
|
137
137
|
delayTimerRef.current = setTimeout(fetchRemote, autoComplete.delay);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
}, [autoComplete, components.api, components.http, config.autoFetch, config.dataProvider, config.query,
|
|
141
|
-
dataProvider, dataProvider.action, dataProvider.onSearch, sourceItems]);
|
|
140
|
+
}, [autoComplete, components.api, components.http, config.autoFetch, config.dataProvider, config.query, dataProvider, dataProvider.action, dataProvider.onSearch, prevQuery, sourceItems]);
|
|
142
141
|
return {
|
|
143
142
|
sourceItems: sourceItems,
|
|
144
143
|
items: items,
|
package/hooks/useDataSelect.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface IDataSelectConfig {
|
|
|
13
13
|
* Список с видимыми элементами
|
|
14
14
|
* @example [{id: 1, label: 'Krasnoyarsk'}, {id: 2, label: 'Moscow'}]
|
|
15
15
|
*/
|
|
16
|
-
items
|
|
16
|
+
items?: IDataSelectItem[];
|
|
17
17
|
/**
|
|
18
18
|
* Сделать активным первый элемент в списке
|
|
19
19
|
* @example true
|
|
@@ -23,7 +23,7 @@ export interface IDataSelectConfig {
|
|
|
23
23
|
* Список с идентификаторами выбранных элементов
|
|
24
24
|
* @example [1, 4]
|
|
25
25
|
*/
|
|
26
|
-
selectedIds
|
|
26
|
+
selectedIds?: any;
|
|
27
27
|
/**
|
|
28
28
|
* Первичный ключ для item
|
|
29
29
|
* @example id
|
|
@@ -32,7 +32,7 @@ export interface IDataSelectConfig {
|
|
|
32
32
|
/**
|
|
33
33
|
* Значение поля в форме
|
|
34
34
|
*/
|
|
35
|
-
inputValue
|
|
35
|
+
inputValue?: any;
|
|
36
36
|
/**
|
|
37
37
|
* Список со всеми элементами
|
|
38
38
|
*/
|
package/hooks/useDataSelect.js
CHANGED
|
@@ -34,7 +34,9 @@ function useDataSelect(config) {
|
|
|
34
34
|
}, [config.items, config.selectFirst, config.selectedIds, primaryKey, config.inputValue]);
|
|
35
35
|
var initialSelectedItems = react_1.useMemo(function () { return config.items.length > 0
|
|
36
36
|
&& initialSelectedIds.length > 0
|
|
37
|
-
? initialSelectedIds
|
|
37
|
+
? initialSelectedIds
|
|
38
|
+
.map(function (selectedId) { return config.items.find(function (item) { return item.id === selectedId; }); })
|
|
39
|
+
.filter(Boolean)
|
|
38
40
|
: []; }, [initialSelectedIds, config.items]);
|
|
39
41
|
// State
|
|
40
42
|
var _a = react_1.useState(false), isOpened = _a[0], setIsOpened = _a[1];
|
|
@@ -81,7 +83,7 @@ function useDataSelect(config) {
|
|
|
81
83
|
var hasChanges = false;
|
|
82
84
|
selectedIds.forEach(function (selectedId) {
|
|
83
85
|
var finedItem = config.items.find(function (item) { return item[primaryKey] === selectedId; });
|
|
84
|
-
if (!finedItem) {
|
|
86
|
+
if (!finedItem && config.sourceItems) {
|
|
85
87
|
finedItem = config.sourceItems.find(function (item) { return item[primaryKey] === selectedId; });
|
|
86
88
|
}
|
|
87
89
|
var selectedItem = selectedItems.find(function (item) { return item[primaryKey] === selectedId; });
|
|
@@ -112,7 +114,8 @@ function useDataSelect(config) {
|
|
|
112
114
|
? itemsForSelect.map(function (item) { return item[primaryKey]; }).filter(function (id) { return config.selectedIds.includes(id); })
|
|
113
115
|
: [];
|
|
114
116
|
selectedItems.forEach(function (selectedItem) {
|
|
115
|
-
if (!newSelectedIds.includes(selectedItem.id) && config.selectedIds
|
|
117
|
+
if (!newSelectedIds.includes(selectedItem.id) && config.selectedIds
|
|
118
|
+
&& config.selectedIds.includes(selectedItem.id)) {
|
|
116
119
|
newSelectedIds.push(selectedItem.id);
|
|
117
120
|
}
|
|
118
121
|
});
|
package/hooks/useFetch.js
CHANGED
|
@@ -60,6 +60,9 @@ var normalizeConfig = function (config) { return (config
|
|
|
60
60
|
? __assign({ id: null, url: '', method: 'get', params: {}, options: null, onFetch: null }, config) : null); };
|
|
61
61
|
exports.normalizeConfig = normalizeConfig;
|
|
62
62
|
var getConfigId = function (config) {
|
|
63
|
+
if (config === null) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
63
66
|
var result = trim_1["default"](config.id || config.url, '/');
|
|
64
67
|
if (!result) {
|
|
65
68
|
// eslint-disable-next-line no-console
|
package/hooks/useLayout.js
CHANGED
|
@@ -81,14 +81,18 @@ var runInitAction = function (initAction, components, dispatch) { return (initAc
|
|
|
81
81
|
exports.runInitAction = runInitAction;
|
|
82
82
|
function useLayout(initAction) {
|
|
83
83
|
if (initAction === void 0) { initAction = null; }
|
|
84
|
-
var _a = useSelector_1["default"](function (state) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
var _a = useSelector_1["default"](function (state) {
|
|
85
|
+
var routesMap = router_1.getRoutesMap(state);
|
|
86
|
+
return {
|
|
87
|
+
route: router_1.getRoute(state),
|
|
88
|
+
user: auth_1.getUser(state),
|
|
89
|
+
data: auth_1.getData(state),
|
|
90
|
+
isInitialized: auth_1.isInitialized(state),
|
|
91
|
+
initializeCounter: auth_1.getInitializeCounter(state),
|
|
92
|
+
redirectPageId: state.auth.redirectPageId,
|
|
93
|
+
loginRouteId: Object.keys(routesMap).find(function (name) { return routesMap[name].role === 'login'; })
|
|
94
|
+
};
|
|
95
|
+
}), route = _a.route, user = _a.user, data = _a.data, isInitialized = _a.isInitialized, initializeCounter = _a.initializeCounter, redirectPageId = _a.redirectPageId, loginRouteId = _a.loginRouteId;
|
|
92
96
|
var _b = react_1.useState(null), error = _b[0], setError = _b[1];
|
|
93
97
|
var dispatch = useDispatch_1["default"]();
|
|
94
98
|
var components = useComponents_1["default"]();
|
|
@@ -133,10 +137,15 @@ function useLayout(initAction) {
|
|
|
133
137
|
userRoles.push(null); // Guest
|
|
134
138
|
}
|
|
135
139
|
if (intersection_1["default"](pageRoles, userRoles).length === 0) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
if (loginRouteId && route.id !== loginRouteId) {
|
|
141
|
+
dispatch(router_2.goToRoute(loginRouteId));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
status = exports.STATUS_ACCESS_DENIED;
|
|
145
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
146
|
+
// eslint-disable-next-line no-console
|
|
147
|
+
console.log('Access denied. Page roles: ', pageRoles, 'User roles:', userRoles.join(), 'Route:', route);
|
|
148
|
+
}
|
|
140
149
|
}
|
|
141
150
|
}
|
|
142
151
|
}
|
package/hooks/useList.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IApiMethod } from '../components/ApiComponent';
|
|
1
2
|
import { IList } from '../actions/list';
|
|
2
3
|
import { ILayoutNamesProps } from '../ui/list/LayoutNames/LayoutNames';
|
|
3
4
|
import { IPaginationProps } from '../ui/list/Pagination/Pagination';
|
|
@@ -50,7 +51,7 @@ export interface IListConfig {
|
|
|
50
51
|
* Url, который вернет коллекцию элементов
|
|
51
52
|
* @example api/v1/articles
|
|
52
53
|
*/
|
|
53
|
-
action?: string;
|
|
54
|
+
action?: string | IApiMethod;
|
|
54
55
|
/**
|
|
55
56
|
* Тип HTTP запроса (GET | POST | PUT | DELETE)
|
|
56
57
|
* @example GET
|
|
@@ -128,6 +129,15 @@ export interface IListConfig {
|
|
|
128
129
|
* Элементы коллекции
|
|
129
130
|
*/
|
|
130
131
|
items?: Array<any>;
|
|
132
|
+
/**
|
|
133
|
+
* Начальные элементы. Используется для подгрузки нескольких списков в один запрос, при этом не отменяя пагинацию
|
|
134
|
+
* и последующие запросы на бекенд для 2-й и следующих страниц
|
|
135
|
+
*/
|
|
136
|
+
initialItems?: Array<any>;
|
|
137
|
+
/**
|
|
138
|
+
* Количество элементов всего в списке (для отрисовки пагинации), заданное вручную
|
|
139
|
+
*/
|
|
140
|
+
initialTotal?: number;
|
|
131
141
|
}
|
|
132
142
|
export interface IListOutput {
|
|
133
143
|
list: IList;
|
package/hooks/useList.js
CHANGED
|
@@ -193,6 +193,7 @@ function useList(config) {
|
|
|
193
193
|
scope: config.scope,
|
|
194
194
|
items: null,
|
|
195
195
|
sourceItems: config.items || null,
|
|
196
|
+
total: config.initialTotal,
|
|
196
197
|
isRemote: !config.items,
|
|
197
198
|
primaryKey: config.primaryKey || exports.defaultConfig.primaryKey,
|
|
198
199
|
formId: formId,
|
|
@@ -202,9 +203,13 @@ function useList(config) {
|
|
|
202
203
|
sortAttribute: sort.attribute || null,
|
|
203
204
|
layoutAttribute: layoutNamesProps.attribute || null
|
|
204
205
|
}),
|
|
205
|
-
list_2.listSetItems(config.listId, config.items),
|
|
206
|
-
list_2.listLazyFetch(config.listId),
|
|
207
206
|
];
|
|
207
|
+
if (config.initialItems || config.items) {
|
|
208
|
+
toDispatch.push(list_2.listSetItems(config.listId, config.initialItems || config.items));
|
|
209
|
+
}
|
|
210
|
+
if (!config.initialItems) {
|
|
211
|
+
toDispatch.push(list_2.listLazyFetch(config.listId));
|
|
212
|
+
}
|
|
208
213
|
dispatch(toDispatch);
|
|
209
214
|
}
|
|
210
215
|
});
|
|
@@ -215,7 +220,7 @@ function useList(config) {
|
|
|
215
220
|
}); });
|
|
216
221
|
var prevFormValues = react_use_1.usePrevious(formValues);
|
|
217
222
|
react_use_1.useUpdateEffect(function () {
|
|
218
|
-
if (!isEqual_1["default"](formValues, prevFormValues)) {
|
|
223
|
+
if (prevFormValues && !isEqual_1["default"](formValues, prevFormValues)) {
|
|
219
224
|
// Has changes (but not page) -> reset page
|
|
220
225
|
var attribute = paginationProps.attribute;
|
|
221
226
|
if ((prevFormValues === null || prevFormValues === void 0 ? void 0 : prevFormValues[attribute]) === formValues[attribute] && formValues[attribute] > 1) {
|
package/package.json
CHANGED
package/reducers/form.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare function reducerItem(state: any, action: any): any;
|
|
|
7
7
|
declare const _default: (state: {}, action: any) => any;
|
|
8
8
|
export default _default;
|
|
9
9
|
export declare const formSelector: (state: any, formId: any, selector: any) => any;
|
|
10
|
+
export declare const getFormValues: (state: any, formId: any) => any;
|
package/reducers/form.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
exports.__esModule = true;
|
|
17
|
-
exports.formSelector = exports.reducerItem = void 0;
|
|
17
|
+
exports.getFormValues = exports.formSelector = exports.reducerItem = void 0;
|
|
18
18
|
var get_1 = __importDefault(require("lodash-es/get"));
|
|
19
19
|
var cloneDeep_1 = __importDefault(require("lodash-es/cloneDeep"));
|
|
20
20
|
var dot_prop_immutable_1 = require("dot-prop-immutable");
|
|
@@ -66,3 +66,5 @@ exports["default"] = (function (state, action) {
|
|
|
66
66
|
});
|
|
67
67
|
var formSelector = function (state, formId, selector) { var _a; return selector(((_a = state.form) === null || _a === void 0 ? void 0 : _a[formId]) || {}); };
|
|
68
68
|
exports.formSelector = formSelector;
|
|
69
|
+
var getFormValues = function (state, formId) { var _a, _b; return ((_b = (_a = state.form) === null || _a === void 0 ? void 0 : _a[formId]) === null || _b === void 0 ? void 0 : _b.values) || null; };
|
|
70
|
+
exports.getFormValues = getFormValues;
|
package/reducers/router.js
CHANGED
|
@@ -40,6 +40,7 @@ var react_router_1 = require("react-router");
|
|
|
40
40
|
var queryString = __importStar(require("qs"));
|
|
41
41
|
var get_1 = __importDefault(require("lodash-es/get"));
|
|
42
42
|
var isEmpty_1 = __importDefault(require("lodash-es/isEmpty"));
|
|
43
|
+
var isEqual_1 = __importDefault(require("lodash-es/isEqual"));
|
|
43
44
|
var pick_1 = __importDefault(require("lodash-es/pick"));
|
|
44
45
|
var isArray_1 = __importDefault(require("lodash-es/isArray"));
|
|
45
46
|
var isObject_1 = __importDefault(require("lodash-es/isObject"));
|
|
@@ -157,9 +158,12 @@ var reducerMap = (_a = {},
|
|
|
157
158
|
activeIds: activeIds, match: getMatch(currentRoute, state) });
|
|
158
159
|
},
|
|
159
160
|
_a['@@router/LOCATION_CHANGE'] = function (state, action) {
|
|
160
|
-
var
|
|
161
|
-
var currentRoute =
|
|
162
|
-
|
|
161
|
+
var newActiveIds = Object.keys(state.routesMap).filter(function (id) { return checkIsActive(state, state.routesMap[id]); });
|
|
162
|
+
var currentRoute = newActiveIds.length > 0 ? state.routesMap[newActiveIds[0]] : null;
|
|
163
|
+
if (!isEqual_1["default"](newActiveIds, state.activeIds)) {
|
|
164
|
+
state.activeIds = newActiveIds;
|
|
165
|
+
}
|
|
166
|
+
return __assign(__assign({}, state), { match: getMatch(currentRoute, state) });
|
|
163
167
|
},
|
|
164
168
|
_a[router_1.ROUTER_SET_PARAMS] = function (state, action) { return (__assign(__assign({}, state), { params: __assign(__assign(__assign({}, state.params), state.location.query), action.params) })); },
|
|
165
169
|
_a);
|
|
@@ -74,7 +74,7 @@ export interface IDetailProps {
|
|
|
74
74
|
/**
|
|
75
75
|
* Дочерние компоненты
|
|
76
76
|
*/
|
|
77
|
-
children
|
|
77
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
78
78
|
[key: string]: any;
|
|
79
79
|
}
|
|
80
80
|
export interface IDetailItemOutputProps extends IDetailItemProps {
|
package/ui/crud/Crud/Crud.js
CHANGED
|
@@ -150,13 +150,15 @@ function Crud(props) {
|
|
|
150
150
|
model: props.model,
|
|
151
151
|
restUrl: props.restUrl,
|
|
152
152
|
restApi: props.restApi,
|
|
153
|
+
grid: props.grid,
|
|
154
|
+
form: props.form,
|
|
153
155
|
goToAction: goToAction,
|
|
154
156
|
items: items,
|
|
155
157
|
itemsToControls: itemsToControls,
|
|
156
158
|
record: record,
|
|
157
159
|
recordId: recordId
|
|
158
|
-
}); }, [crudId,
|
|
159
|
-
props.
|
|
160
|
+
}); }, [crudId, props.queryKey, props.primaryKey, props.model, props.restUrl, props.restApi, props.grid,
|
|
161
|
+
props.form, goToAction, items, itemsToControls, record, recordId]);
|
|
160
162
|
// Open modal on route change
|
|
161
163
|
react_1.useEffect(function () {
|
|
162
164
|
if (mode === MODE_MODAL && routeAction !== utils_1.CRUD_ACTION_INDEX) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { IGridProps } from '@steroidsjs/core/ui/list/Grid/Grid';
|
|
3
|
+
import { IFormProps } from '@steroidsjs/core/ui/form/Form/Form';
|
|
2
4
|
import { ICrudItem } from './Crud';
|
|
3
5
|
import { IApiRest } from '../../../components/ApiComponent';
|
|
4
6
|
export interface ICrudContentProps {
|
|
@@ -14,5 +16,7 @@ export interface ICrudContentProps {
|
|
|
14
16
|
record?: Record<string, unknown>;
|
|
15
17
|
recordId?: PrimaryKey;
|
|
16
18
|
action?: string;
|
|
19
|
+
grid?: IGridProps | React.ReactNode;
|
|
20
|
+
form?: IFormProps | React.ReactNode;
|
|
17
21
|
}
|
|
18
22
|
export default function CrudContent(props: ICrudContentProps): JSX.Element;
|
|
@@ -68,23 +68,23 @@ function CrudContent(props) {
|
|
|
68
68
|
ItemComponent = Grid_1["default"];
|
|
69
69
|
}
|
|
70
70
|
return (React.createElement(ItemComponent // Grid
|
|
71
|
-
, { key: props.crudId, listId: props.crudId, action: props.restApi ? props.restApi.index : props.restUrl, scope: ['model', 'permission'], primaryKey: props.primaryKey, model: props.model,
|
|
71
|
+
, __assign({ key: props.crudId, listId: props.crudId, action: props.restApi ? props.restApi.index : props.restUrl, scope: ['model', 'permission'], primaryKey: props.primaryKey, model: props.model,
|
|
72
72
|
//searchModel={props.searchModel}
|
|
73
73
|
controls: controlsGetter, columns: [props.primaryKey], pagination: {
|
|
74
74
|
loadMore: false
|
|
75
|
-
} }));
|
|
75
|
+
} }, props.grid)));
|
|
76
76
|
case utils_1.CRUD_ACTION_CREATE:
|
|
77
77
|
case utils_1.CRUD_ACTION_UPDATE:
|
|
78
78
|
if (!ItemComponent) {
|
|
79
79
|
ItemComponent = Form_1["default"];
|
|
80
80
|
}
|
|
81
|
-
if (props.action === utils_1.CRUD_ACTION_UPDATE && !props.record) {
|
|
81
|
+
if (props.action === utils_1.CRUD_ACTION_UPDATE && (props.restUrl || props.restApi) && !props.record) {
|
|
82
82
|
return null;
|
|
83
83
|
}
|
|
84
84
|
return (React.createElement(ItemComponent // Form
|
|
85
|
-
, { key: formId, formId: formId, action: props.restApi
|
|
85
|
+
, __assign({ key: formId, formId: formId, action: props.restApi
|
|
86
86
|
? (props.recordId ? props.restApi.update : props.restApi.create)
|
|
87
|
-
: [props.restUrl, props.recordId].filter(Boolean).join('/'), model: props.model, autoFocus: true, submitLabel: props.recordId ? __('Сохранить') : __('Добавить'), layout: 'horizontal', onComplete: onFormComplete, initialValues: formInitialValues }));
|
|
87
|
+
: [props.restUrl, props.recordId].filter(Boolean).join('/'), model: props.model, autoFocus: true, submitLabel: props.recordId ? __('Сохранить') : __('Добавить'), layout: 'horizontal', onComplete: onFormComplete }, props.form, { initialValues: formInitialValues })));
|
|
88
88
|
default:
|
|
89
89
|
if (ItemComponent) {
|
|
90
90
|
return (React.createElement(ItemComponent, __assign({ key: props.crudId + '_' + props.action }, props, crudItem.componentProps)));
|
package/ui/crud/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare const generateCrud: (routeId: string, props: ICrudGeneratorProps)
|
|
|
26
26
|
isNavVisible?: boolean;
|
|
27
27
|
models: string | string[];
|
|
28
28
|
enums: string | string[];
|
|
29
|
+
role?: string;
|
|
29
30
|
roles?: string[];
|
|
30
31
|
fetch?: import("../../hoc/fetch").IFetchHocConfigFunc;
|
|
31
32
|
items?: IRouteItem[] | {
|
|
@@ -35,10 +35,5 @@ export interface IAutoCompleteFieldViewProps extends Omit<IAutoCompleteFieldProp
|
|
|
35
35
|
onItemSelect: (id: PrimaryKey | any) => void;
|
|
36
36
|
onItemHover: (id: PrimaryKey | any) => void;
|
|
37
37
|
}
|
|
38
|
-
declare const _default:
|
|
39
|
-
(props: import("../../../ui/form/Field/fieldWrapper").IFieldWrapperInputProps): JSX.Element;
|
|
40
|
-
WrappedComponent: any;
|
|
41
|
-
displayName: any;
|
|
42
|
-
defaultProps: any;
|
|
43
|
-
};
|
|
38
|
+
declare const _default: import("../../../ui/form/Field/fieldWrapper").FieldWrapperComponent<IAutoCompleteFieldProps>;
|
|
44
39
|
export default _default;
|