@steroidsjs/core 2.2.71 → 2.2.74
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/package.json +1 -1
- package/ui/crud/Crud/Crud.d.ts +2 -0
- package/ui/crud/Crud/Crud.js +2 -1
- package/ui/crud/Crud/utils.js +12 -5
- package/ui/form/DateField/useDateInputState.d.ts +9 -1
- package/ui/form/DateField/useDateInputState.js +3 -3
- package/ui/form/DateField/useDateTime.d.ts +1 -1
- package/ui/form/DateField/useDateTime.js +12 -4
- package/ui/form/DateTimeField/DateTimeField.js +6 -4
- package/ui/form/RadioListField/RadioListField.js +11 -4
- package/ui/form/TimeField/TimeField.js +4 -2
package/package.json
CHANGED
package/ui/crud/Crud/Crud.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface ICrudClickProps {
|
|
|
34
34
|
record?: Record<string, unknown>;
|
|
35
35
|
components: IComponents;
|
|
36
36
|
goToAction: (nextAction: string) => any;
|
|
37
|
+
errorHandler?: (error: any, dispatch: any) => void;
|
|
37
38
|
}
|
|
38
39
|
export interface ICrudProps {
|
|
39
40
|
crudId?: string;
|
|
@@ -56,6 +57,7 @@ export interface ICrudProps {
|
|
|
56
57
|
form?: IFormProps | React.ReactNode;
|
|
57
58
|
detail?: any;
|
|
58
59
|
crudView?: CustomView;
|
|
60
|
+
errorHandler?: (error: any, dispatch: any) => void;
|
|
59
61
|
[key: string]: any;
|
|
60
62
|
}
|
|
61
63
|
export interface ICrudChildrenProps extends ICrudProps, IConnectHocOutput, IComponentsHocOutput {
|
package/ui/crud/Crud/Crud.js
CHANGED
|
@@ -112,7 +112,8 @@ function Crud(props) {
|
|
|
112
112
|
recordId: recordId,
|
|
113
113
|
record: record,
|
|
114
114
|
components: components,
|
|
115
|
-
goToAction: goToAction
|
|
115
|
+
goToAction: goToAction,
|
|
116
|
+
errorHandler: props.errorHandler
|
|
116
117
|
}); }, [components, goToAction, props.crudId, props.mode, props.primaryKey, props.queryKey,
|
|
117
118
|
props.restApi, props.restUrl, record, recordId, routeAction, routeId, routeParams]);
|
|
118
119
|
// Handler for convert control item to props for button
|
package/ui/crud/Crud/utils.js
CHANGED
|
@@ -101,16 +101,23 @@ var normalizeItems = function (sourceItems, fromProps) {
|
|
|
101
101
|
return [4 /*yield*/, props.restApi["delete"](props.components.api, (_a = {}, _a[props.primaryKey] = props.recordId, _a))];
|
|
102
102
|
case 1:
|
|
103
103
|
_b.sent();
|
|
104
|
-
|
|
104
|
+
props.goToAction(exports.CRUD_ACTION_INDEX);
|
|
105
|
+
return [2 /*return*/];
|
|
105
106
|
case 2:
|
|
106
107
|
if (!props.restUrl) return [3 /*break*/, 4];
|
|
107
|
-
return [4 /*yield*/, props.components.http["delete"](props.restUrl + "/" + props.recordId)
|
|
108
|
+
return [4 /*yield*/, props.components.http["delete"](props.restUrl + "/" + props.recordId)
|
|
109
|
+
.then(function () { return props.goToAction(exports.CRUD_ACTION_INDEX); })["catch"](function (error) {
|
|
110
|
+
if (props.errorHandler) {
|
|
111
|
+
props.errorHandler(error, props.components.store.dispatch);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
})];
|
|
108
117
|
case 3:
|
|
109
118
|
_b.sent();
|
|
110
|
-
_b.label = 4;
|
|
111
|
-
case 4:
|
|
112
|
-
props.goToAction(exports.CRUD_ACTION_INDEX);
|
|
113
119
|
return [2 /*return*/];
|
|
120
|
+
case 4: throw new Error('Either restApi or restUrl must be set');
|
|
114
121
|
}
|
|
115
122
|
});
|
|
116
123
|
}); }
|
|
@@ -36,9 +36,17 @@ export interface IDateInputStateInput extends IFieldWrapperInputProps {
|
|
|
36
36
|
*/
|
|
37
37
|
valueFormat?: string;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Приводить значение даты к часовому поясу UTC
|
|
40
|
+
* (пример: с бэкенда приходит дата в какой-либо временной зоне (не UTC), но нужно отбразить ее
|
|
41
|
+
* в часовом поясе UTC. В этом случае dateInUTC = false, а useUTC = true)
|
|
40
42
|
*/
|
|
41
43
|
useUTC?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Задано ли значение даты в часовом поясе UTC
|
|
46
|
+
* (пример: с бэкенда приходит дата в UTC, но нужно отбразить ее в локальном времени.
|
|
47
|
+
* В этом случае dateInUTC = true, а useUTC = false)
|
|
48
|
+
*/
|
|
49
|
+
dateInUTC?: boolean;
|
|
42
50
|
}
|
|
43
51
|
export interface IDateInputStateOutput {
|
|
44
52
|
/**
|
|
@@ -23,7 +23,7 @@ function useDateInputState(props) {
|
|
|
23
23
|
var propsDisplayValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [
|
|
24
24
|
props.valueFormat,
|
|
25
25
|
props.displayFormat,
|
|
26
|
-
], props.displayFormat,
|
|
26
|
+
], props.displayFormat, props.useUTC, props.dateInUTC) || ''; }, [props.displayFormat, props.input.value, props.valueFormat]);
|
|
27
27
|
// Display value state
|
|
28
28
|
var _a = react_1.useState(propsDisplayValue), displayValue = _a[0], setDisplayValue = _a[1];
|
|
29
29
|
// Update display value on update props input value
|
|
@@ -41,7 +41,7 @@ function useDateInputState(props) {
|
|
|
41
41
|
var onDisplayValueChange = react_1.useCallback(function (value) {
|
|
42
42
|
value = value.replace(/[^0-9:. ]/g, '');
|
|
43
43
|
setDisplayValue(value);
|
|
44
|
-
var parsedValue = calendar_1.convertDate(value, props.displayFormat, props.valueFormat, props.useUTC);
|
|
44
|
+
var parsedValue = calendar_1.convertDate(value, props.displayFormat, props.valueFormat, props.useUTC, props.dateInUTC);
|
|
45
45
|
var newValue = parsedValue || !value ? parsedValue || null : false;
|
|
46
46
|
if (newValue && newValue !== props.input.value) {
|
|
47
47
|
props.input.onChange.call(null, newValue);
|
|
@@ -49,7 +49,7 @@ function useDateInputState(props) {
|
|
|
49
49
|
props.onChange.call(null, value);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
}, [props.displayFormat, props.input.onChange, props.input.value, props.onChange, props.valueFormat, props.useUTC]);
|
|
52
|
+
}, [props.displayFormat, props.input.onChange, props.input.value, props.onChange, props.valueFormat, props.useUTC, props.dateInUTC]);
|
|
53
53
|
// Dropdown opened state
|
|
54
54
|
var _b = react_1.useState(false), isOpened = _b[0], setIsOpened = _b[1];
|
|
55
55
|
// Focus/blur handlers
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IDateInputStateInput } from '../../form/DateField/useDateInputState';
|
|
2
|
-
interface IUseDateTimeProps extends Pick<IDateInputStateInput, 'displayFormat' | 'valueFormat' | 'input' | 'useUTC'> {
|
|
2
|
+
interface IUseDateTimeProps extends Pick<IDateInputStateInput, 'displayFormat' | 'valueFormat' | 'input' | 'useUTC' | 'dateInUTC'> {
|
|
3
3
|
dateTimeSeparator: string;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
@@ -13,16 +13,24 @@ var calendar_1 = require("../../../utils/calendar");
|
|
|
13
13
|
*/
|
|
14
14
|
function useDateTime(props) {
|
|
15
15
|
var _a = props.valueFormat.split(props.dateTimeSeparator), dateValueFormat = _a[0], timeValueFormat = _a[1];
|
|
16
|
-
var dateValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.valueFormat, props.displayFormat], dateValueFormat,
|
|
17
|
-
var timeValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.displayFormat, props.valueFormat], timeValueFormat,
|
|
16
|
+
var dateValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.valueFormat, props.displayFormat], dateValueFormat, props.useUTC, props.dateInUTC); }, [dateValueFormat, props.displayFormat, props.input.value, props.valueFormat]);
|
|
17
|
+
var timeValue = react_1.useMemo(function () { return calendar_1.convertDate(props.input.value, [props.displayFormat, props.valueFormat], timeValueFormat, props.useUTC, props.dateInUTC); }, [props.displayFormat, props.input.value, props.valueFormat, timeValueFormat]);
|
|
18
18
|
// Handler for calendar and time picker changes
|
|
19
19
|
var onDateSelect = react_1.useCallback(function (date) {
|
|
20
20
|
var result = date + props.dateTimeSeparator + (timeValue || '00:00');
|
|
21
|
-
props.input.onChange.call(null, calendar_1.convertDate(result, [props.valueFormat, 'YYYY-MM-DD HH:mm'], props.valueFormat,
|
|
21
|
+
props.input.onChange.call(null, calendar_1.convertDate(result, [props.valueFormat, 'YYYY-MM-DD HH:mm'], props.valueFormat,
|
|
22
|
+
// converting to UTC here depends on whether the date is stored in UTC
|
|
23
|
+
props.dateInUTC,
|
|
24
|
+
// whether the date provided from onSelect is in UTC or not depends on this flag
|
|
25
|
+
props.useUTC));
|
|
22
26
|
}, [props.dateTimeSeparator, props.input.onChange, props.valueFormat, timeValue]);
|
|
23
27
|
var onTimeSelect = react_1.useCallback(function (time) {
|
|
24
28
|
var result = (dateValue || moment_1["default"]().format(dateValueFormat)) + props.dateTimeSeparator + time;
|
|
25
|
-
props.input.onChange.call(null, calendar_1.convertDate(result, [props.valueFormat, 'YYYY-MM-DD HH:mm'], props.valueFormat,
|
|
29
|
+
props.input.onChange.call(null, calendar_1.convertDate(result, [props.valueFormat, 'YYYY-MM-DD HH:mm'], props.valueFormat,
|
|
30
|
+
// converting to UTC here depends on whether the date is stored in UTC
|
|
31
|
+
props.dateInUTC,
|
|
32
|
+
// whether the date provided from onSelect is in UTC or not depends on this flag
|
|
33
|
+
props.useUTC));
|
|
26
34
|
}, [dateValue, dateValueFormat, props.dateTimeSeparator, props.input.onChange, props.valueFormat]);
|
|
27
35
|
return {
|
|
28
36
|
dateValue: dateValue,
|
|
@@ -35,15 +35,16 @@ function DateTimeField(props) {
|
|
|
35
35
|
placeholder: props.placeholder,
|
|
36
36
|
valueFormat: props.valueFormat,
|
|
37
37
|
displayFormat: props.displayFormat,
|
|
38
|
-
useUTC: props.useUTC
|
|
38
|
+
useUTC: props.useUTC,
|
|
39
|
+
dateInUTC: props.dateInUTC
|
|
39
40
|
}), onClear = _a.onClear, onClose = _a.onClose, isOpened = _a.isOpened, inputProps = _a.inputProps;
|
|
40
|
-
console.log("DATETIME INPUT", inputProps);
|
|
41
41
|
var _b = useDateTime_1["default"]({
|
|
42
42
|
displayFormat: props.displayFormat,
|
|
43
43
|
dateTimeSeparator: DATE_TIME_SEPARATOR,
|
|
44
44
|
input: props.input,
|
|
45
45
|
valueFormat: props.valueFormat,
|
|
46
|
-
useUTC: props.useUTC
|
|
46
|
+
useUTC: props.useUTC,
|
|
47
|
+
dateInUTC: props.dateInUTC
|
|
47
48
|
}), dateValueFormat = _b.dateValueFormat, dateValue = _b.dateValue, timeValue = _b.timeValue, onDateSelect = _b.onDateSelect, onTimeSelect = _b.onTimeSelect;
|
|
48
49
|
// Calendar props
|
|
49
50
|
var calendarProps = react_1.useMemo(function () { return ({
|
|
@@ -72,6 +73,7 @@ DateTimeField.defaultProps = {
|
|
|
72
73
|
className: '',
|
|
73
74
|
displayFormat: 'DD.MM.YYYY' + DATE_TIME_SEPARATOR + 'HH:mm',
|
|
74
75
|
valueFormat: 'YYYY-MM-DD' + DATE_TIME_SEPARATOR + 'HH:mm',
|
|
75
|
-
useUTC: true
|
|
76
|
+
useUTC: true,
|
|
77
|
+
dateInUTC: false
|
|
76
78
|
};
|
|
77
79
|
exports["default"] = fieldWrapper_1["default"]('DateTimeField', DateTimeField);
|
|
@@ -17,15 +17,18 @@ exports.__esModule = true;
|
|
|
17
17
|
var react_1 = require("react");
|
|
18
18
|
var hooks_1 = require("../../../hooks");
|
|
19
19
|
var fieldWrapper_1 = __importDefault(require("../../form/Field/fieldWrapper"));
|
|
20
|
+
var react_use_1 = require("react-use");
|
|
21
|
+
var isEqual_1 = __importDefault(require("lodash-es/isEqual"));
|
|
20
22
|
function RadioListField(props) {
|
|
21
23
|
var components = hooks_1.useComponents();
|
|
24
|
+
var inputSelectedIds = react_1.useMemo(function () { return props.selectedIds || [].concat(props.input.value || []); }, [props.input.value, props.selectedIds]);
|
|
22
25
|
// Data provider
|
|
23
26
|
var items = hooks_1.useDataProvider({
|
|
24
27
|
items: props.items
|
|
25
28
|
}).items;
|
|
26
29
|
// Data select
|
|
27
30
|
var _a = hooks_1.useDataSelect({
|
|
28
|
-
selectedIds:
|
|
31
|
+
selectedIds: inputSelectedIds,
|
|
29
32
|
selectFirst: props.selectFirst,
|
|
30
33
|
primaryKey: props.primaryKey,
|
|
31
34
|
items: items,
|
|
@@ -36,10 +39,14 @@ function RadioListField(props) {
|
|
|
36
39
|
}, [setSelectedIds]);
|
|
37
40
|
var inputProps = react_1.useMemo(function () { return (__assign(__assign({}, props.inputProps), { type: 'radio', name: props.input.name, disabled: props.disabled, onChange: function (value) { return props.input.onChange(value); } })); }, [props.disabled, props.input, props.inputProps]);
|
|
38
41
|
// Sync with form
|
|
42
|
+
var prevSelectedIds = react_use_1.usePrevious(selectedIds);
|
|
39
43
|
react_1.useEffect(function () {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
if (!isEqual_1["default"](prevSelectedIds || [], selectedIds)) {
|
|
45
|
+
props.input.onChange.call(null, selectedIds[0]);
|
|
46
|
+
if (props.onChange) {
|
|
47
|
+
props.onChange.call(null, selectedIds[0]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
43
50
|
}, [props.input.onChange, selectedIds]);
|
|
44
51
|
return components.ui.renderView(props.view || 'form.RadioListFieldView', __assign(__assign({}, props), { items: items,
|
|
45
52
|
inputProps: inputProps,
|
|
@@ -29,7 +29,8 @@ function TimeField(props) {
|
|
|
29
29
|
placeholder: props.placeholder,
|
|
30
30
|
valueFormat: props.valueFormat,
|
|
31
31
|
displayFormat: props.displayFormat,
|
|
32
|
-
useUTC: props.useUTC
|
|
32
|
+
useUTC: props.useUTC,
|
|
33
|
+
dateInUTC: props.dateInUTC
|
|
33
34
|
}), onNow = _a.onNow, onClear = _a.onClear, onClose = _a.onClose, isOpened = _a.isOpened, inputProps = _a.inputProps;
|
|
34
35
|
var timePanelViewProps = react_1.useMemo(function () { return (__assign({ onNow: onNow,
|
|
35
36
|
onClose: onClose, value: inputProps.value, onSelect: inputProps.onChange }, props.timePanelViewProps)); }, [inputProps.onChange, inputProps.value, onClose, onNow, props.timePanelViewProps]);
|
|
@@ -49,6 +50,7 @@ TimeField.defaultProps = {
|
|
|
49
50
|
showRemove: true,
|
|
50
51
|
type: 'text',
|
|
51
52
|
valueFormat: 'HH:mm',
|
|
52
|
-
useUTC: true
|
|
53
|
+
useUTC: true,
|
|
54
|
+
dateInUTC: false
|
|
53
55
|
};
|
|
54
56
|
exports["default"] = fieldWrapper_1["default"]('TimeField', TimeField);
|