@bluemarble/bm-components 1.4.2 → 1.6.0
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/dist/index.d.mts +121 -49
- package/dist/index.d.ts +121 -49
- package/dist/index.js +428 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +458 -208
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -255,7 +255,7 @@ var require_react_is_development = __commonJS({
|
|
|
255
255
|
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
256
256
|
var Element = REACT_ELEMENT_TYPE;
|
|
257
257
|
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
258
|
-
var
|
|
258
|
+
var Fragment3 = REACT_FRAGMENT_TYPE;
|
|
259
259
|
var Lazy = REACT_LAZY_TYPE;
|
|
260
260
|
var Memo = REACT_MEMO_TYPE;
|
|
261
261
|
var Portal = REACT_PORTAL_TYPE;
|
|
@@ -314,7 +314,7 @@ var require_react_is_development = __commonJS({
|
|
|
314
314
|
exports.ContextProvider = ContextProvider;
|
|
315
315
|
exports.Element = Element;
|
|
316
316
|
exports.ForwardRef = ForwardRef;
|
|
317
|
-
exports.Fragment =
|
|
317
|
+
exports.Fragment = Fragment3;
|
|
318
318
|
exports.Lazy = Lazy;
|
|
319
319
|
exports.Memo = Memo;
|
|
320
320
|
exports.Portal = Portal;
|
|
@@ -2404,7 +2404,7 @@ function createBox(options = {}) {
|
|
|
2404
2404
|
const BoxRoot = styled("div", {
|
|
2405
2405
|
shouldForwardProp: (prop) => prop !== "theme" && prop !== "sx" && prop !== "as"
|
|
2406
2406
|
})(styleFunctionSx_default);
|
|
2407
|
-
const
|
|
2407
|
+
const Box7 = /* @__PURE__ */ React3.forwardRef(function Box8(inProps, ref) {
|
|
2408
2408
|
const theme = useTheme_default(defaultTheme);
|
|
2409
2409
|
const _extendSxProp = extendSxProp(inProps), {
|
|
2410
2410
|
className,
|
|
@@ -2417,7 +2417,7 @@ function createBox(options = {}) {
|
|
|
2417
2417
|
theme: themeId ? theme[themeId] || theme : theme
|
|
2418
2418
|
}, other));
|
|
2419
2419
|
});
|
|
2420
|
-
return
|
|
2420
|
+
return Box7;
|
|
2421
2421
|
}
|
|
2422
2422
|
|
|
2423
2423
|
// node_modules/@mui/utils/generateUtilityClass/generateUtilityClass.js
|
|
@@ -3712,6 +3712,7 @@ var TabPanel = (props) => {
|
|
|
3712
3712
|
|
|
3713
3713
|
|
|
3714
3714
|
|
|
3715
|
+
|
|
3715
3716
|
// src/components/BaseGrid/Pagination/index.tsx
|
|
3716
3717
|
|
|
3717
3718
|
|
|
@@ -3817,7 +3818,6 @@ function BaseGrid({
|
|
|
3817
3818
|
tableBodyProps,
|
|
3818
3819
|
tableHeadProps,
|
|
3819
3820
|
tableProps,
|
|
3820
|
-
sortedDirection,
|
|
3821
3821
|
sortedBy,
|
|
3822
3822
|
onSortBy,
|
|
3823
3823
|
dense = true,
|
|
@@ -3825,6 +3825,8 @@ function BaseGrid({
|
|
|
3825
3825
|
bordered,
|
|
3826
3826
|
currentPage,
|
|
3827
3827
|
totalNumberOfPages,
|
|
3828
|
+
tableSortLabelProps,
|
|
3829
|
+
boxContainerProps,
|
|
3828
3830
|
onPageChange,
|
|
3829
3831
|
rowsPerPage,
|
|
3830
3832
|
setRowsPerPage,
|
|
@@ -3832,6 +3834,7 @@ function BaseGrid({
|
|
|
3832
3834
|
hideFooter,
|
|
3833
3835
|
prependColumn,
|
|
3834
3836
|
appendColumn,
|
|
3837
|
+
loadingColSpan,
|
|
3835
3838
|
isLoading
|
|
3836
3839
|
}) {
|
|
3837
3840
|
return /* @__PURE__ */ React2.default.createElement(
|
|
@@ -3840,34 +3843,52 @@ function BaseGrid({
|
|
|
3840
3843
|
sx: __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, styles.rowGap(dense)), styles.bordered(bordered)), styles.striped(striped)), styles.lastRowBorder(hideFooter)), paperProps == null ? void 0 : paperProps.sx)
|
|
3841
3844
|
}),
|
|
3842
3845
|
/* @__PURE__ */ React2.default.createElement(
|
|
3843
|
-
_material.
|
|
3844
|
-
__spreadProps(__spreadValues({
|
|
3845
|
-
|
|
3846
|
-
stickyHeader: true
|
|
3847
|
-
}, tableProps), {
|
|
3848
|
-
sx: __spreadValues({}, tableProps == null ? void 0 : tableProps.sx)
|
|
3846
|
+
_material.Box,
|
|
3847
|
+
__spreadProps(__spreadValues({}, boxContainerProps), {
|
|
3848
|
+
sx: __spreadValues({ overflowX: "auto" }, boxContainerProps == null ? void 0 : boxContainerProps.sx)
|
|
3849
3849
|
}),
|
|
3850
|
-
/* @__PURE__ */ React2.default.createElement(
|
|
3851
|
-
_material.
|
|
3852
|
-
{
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
},
|
|
3859
|
-
|
|
3860
|
-
|
|
3850
|
+
/* @__PURE__ */ React2.default.createElement(
|
|
3851
|
+
_material.Table,
|
|
3852
|
+
__spreadProps(__spreadValues({
|
|
3853
|
+
size: "small",
|
|
3854
|
+
stickyHeader: true
|
|
3855
|
+
}, tableProps), {
|
|
3856
|
+
sx: __spreadValues({}, tableProps == null ? void 0 : tableProps.sx)
|
|
3857
|
+
}),
|
|
3858
|
+
/* @__PURE__ */ React2.default.createElement(_material.TableHead, __spreadValues({}, tableHeadProps), /* @__PURE__ */ React2.default.createElement(_material.TableRow, null, prependColumn, columns.map((column) => {
|
|
3859
|
+
var _a;
|
|
3860
|
+
return /* @__PURE__ */ React2.default.createElement(
|
|
3861
|
+
_material.TableCell,
|
|
3862
|
+
{
|
|
3863
|
+
key: column.name,
|
|
3864
|
+
padding: dense ? "none" : "normal",
|
|
3865
|
+
sx: __spreadValues({
|
|
3866
|
+
pl: 2
|
|
3867
|
+
}, column == null ? void 0 : column.sx)
|
|
3868
|
+
},
|
|
3869
|
+
column.children ? column.children : /* @__PURE__ */ React2.default.createElement(
|
|
3870
|
+
_material.TableSortLabel,
|
|
3871
|
+
__spreadProps(__spreadValues({
|
|
3872
|
+
active: sortedBy.some((p) => p.prop === column.name),
|
|
3873
|
+
direction: ((_a = sortedBy.find((p) => p.prop === column.name)) == null ? void 0 : _a.direction) || "desc",
|
|
3874
|
+
onClick: () => onSortBy(column.name),
|
|
3875
|
+
disabled: column.canSort === false
|
|
3876
|
+
}, tableSortLabelProps), {
|
|
3877
|
+
sx: __spreadValues({}, tableSortLabelProps == null ? void 0 : tableSortLabelProps.sx)
|
|
3878
|
+
}),
|
|
3879
|
+
column.label
|
|
3880
|
+
)
|
|
3881
|
+
);
|
|
3882
|
+
}), appendColumn), isLoading && /* @__PURE__ */ React2.default.createElement(_material.TableRow, null, /* @__PURE__ */ React2.default.createElement(
|
|
3883
|
+
_material.TableCell,
|
|
3861
3884
|
{
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
onClick: () => onSortBy(column.name),
|
|
3865
|
-
disabled: column.canSort === false
|
|
3885
|
+
colSpan: loadingColSpan || columns.length,
|
|
3886
|
+
sx: { p: 0, border: "none" }
|
|
3866
3887
|
},
|
|
3867
|
-
|
|
3868
|
-
)
|
|
3869
|
-
|
|
3870
|
-
|
|
3888
|
+
/* @__PURE__ */ React2.default.createElement(_material.LinearProgress, null)
|
|
3889
|
+
))),
|
|
3890
|
+
/* @__PURE__ */ React2.default.createElement(_material.TableBody, __spreadValues({}, tableBodyProps), children)
|
|
3891
|
+
)
|
|
3871
3892
|
),
|
|
3872
3893
|
!hideFooter && /* @__PURE__ */ React2.default.createElement(
|
|
3873
3894
|
GridPagination,
|
|
@@ -3884,6 +3905,18 @@ function BaseGrid({
|
|
|
3884
3905
|
);
|
|
3885
3906
|
}
|
|
3886
3907
|
|
|
3908
|
+
// src/components/BaseGrid/BaseGridAutoRows.tsx
|
|
3909
|
+
|
|
3910
|
+
|
|
3911
|
+
|
|
3912
|
+
function BaseGridAutoRows({
|
|
3913
|
+
data,
|
|
3914
|
+
columns,
|
|
3915
|
+
rowKey
|
|
3916
|
+
}) {
|
|
3917
|
+
return /* @__PURE__ */ React2.default.createElement(_react.Fragment, null, data.map((row) => /* @__PURE__ */ React2.default.createElement(_material.TableRow, { key: row[rowKey] }, columns.map((column) => /* @__PURE__ */ React2.default.createElement(_material.TableCell, { key: column.name }, row[column.name])))));
|
|
3918
|
+
}
|
|
3919
|
+
|
|
3887
3920
|
// src/components/Modal/index.tsx
|
|
3888
3921
|
|
|
3889
3922
|
|
|
@@ -4113,14 +4146,17 @@ var AlertProvider = ({ children }) => {
|
|
|
4113
4146
|
const [severity, setSeverity] = _react.useState.call(void 0, "info");
|
|
4114
4147
|
const [message, setMessage] = _react.useState.call(void 0, "");
|
|
4115
4148
|
const [isVisible, setIsVisible] = _react.useState.call(void 0, false);
|
|
4116
|
-
const createAlert = (
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4149
|
+
const createAlert = _react.useCallback.call(void 0,
|
|
4150
|
+
(newMessage, severity2) => {
|
|
4151
|
+
setMessage(newMessage);
|
|
4152
|
+
setSeverity(severity2);
|
|
4153
|
+
setIsVisible(true);
|
|
4154
|
+
},
|
|
4155
|
+
[]
|
|
4156
|
+
);
|
|
4157
|
+
const onCloseToast = _react.useCallback.call(void 0, () => {
|
|
4122
4158
|
setIsVisible(false);
|
|
4123
|
-
}
|
|
4159
|
+
}, []);
|
|
4124
4160
|
return /* @__PURE__ */ React2.default.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React2.default.createElement(
|
|
4125
4161
|
Toast,
|
|
4126
4162
|
{
|
|
@@ -4141,13 +4177,13 @@ var useAlert = () => {
|
|
|
4141
4177
|
|
|
4142
4178
|
function useLoading() {
|
|
4143
4179
|
const [state, setState] = _react.useState.call(void 0, []);
|
|
4144
|
-
const isLoading = (prop) => state.includes(prop);
|
|
4145
|
-
const setLoading = (prop, remove) => {
|
|
4180
|
+
const isLoading = _react.useCallback.call(void 0, (prop) => state.includes(prop), [state]);
|
|
4181
|
+
const setLoading = _react.useCallback.call(void 0, (prop, remove) => {
|
|
4146
4182
|
if (remove)
|
|
4147
4183
|
setState((prevState) => prevState.filter((state2) => state2 !== prop));
|
|
4148
4184
|
else
|
|
4149
4185
|
setState((prevState) => [...prevState, prop]);
|
|
4150
|
-
};
|
|
4186
|
+
}, []);
|
|
4151
4187
|
return { isLoading, setLoading };
|
|
4152
4188
|
}
|
|
4153
4189
|
|
|
@@ -4167,59 +4203,68 @@ function useFormHelper() {
|
|
|
4167
4203
|
const { createAlert } = alertProps;
|
|
4168
4204
|
const { setLoading } = loadingProps;
|
|
4169
4205
|
const sourceRef = _react.useRef.call(void 0, new AbortController());
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4206
|
+
const onSubmitWrapper = _react.useCallback.call(void 0,
|
|
4207
|
+
(fn, { name }) => {
|
|
4208
|
+
return (fields, methods) => __async(this, null, function* () {
|
|
4209
|
+
const LOADING_NAME = name;
|
|
4210
|
+
setLoading(LOADING_NAME);
|
|
4211
|
+
try {
|
|
4212
|
+
yield fn(fields, methods);
|
|
4213
|
+
} catch (error) {
|
|
4214
|
+
errorHandler(error, methods.setErrors);
|
|
4215
|
+
} finally {
|
|
4216
|
+
setLoading(LOADING_NAME, true);
|
|
4217
|
+
}
|
|
4218
|
+
});
|
|
4219
|
+
},
|
|
4220
|
+
[setLoading]
|
|
4221
|
+
);
|
|
4222
|
+
const onRequestWrapper = _react.useCallback.call(void 0,
|
|
4223
|
+
(fn, { name }) => {
|
|
4224
|
+
return (...params) => __async(this, null, function* () {
|
|
4225
|
+
const LOADING_NAME = name;
|
|
4226
|
+
setLoading(LOADING_NAME);
|
|
4227
|
+
api.interceptors.request.use(
|
|
4228
|
+
(config) => {
|
|
4229
|
+
if (!config.signal && sourceRef.current && config.method === "get") {
|
|
4230
|
+
config.signal = sourceRef.current.signal;
|
|
4231
|
+
}
|
|
4232
|
+
return config;
|
|
4233
|
+
},
|
|
4234
|
+
(error) => {
|
|
4235
|
+
return Promise.reject(error);
|
|
4191
4236
|
}
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
return
|
|
4237
|
+
);
|
|
4238
|
+
try {
|
|
4239
|
+
const response = yield fn(...params);
|
|
4240
|
+
return response;
|
|
4241
|
+
} catch (error) {
|
|
4242
|
+
errorHandler(error);
|
|
4243
|
+
} finally {
|
|
4244
|
+
setLoading(LOADING_NAME, true);
|
|
4245
|
+
}
|
|
4246
|
+
});
|
|
4247
|
+
},
|
|
4248
|
+
[setLoading, api]
|
|
4249
|
+
);
|
|
4250
|
+
const errorHandler = _react.useCallback.call(void 0,
|
|
4251
|
+
(error, callback) => {
|
|
4252
|
+
if ((error == null ? void 0 : error.message) === "cancel.navigation")
|
|
4253
|
+
return;
|
|
4254
|
+
if (callback) {
|
|
4255
|
+
if (error.response.data.code === "invalid.body") {
|
|
4256
|
+
const errors = error.response.data.details.issues;
|
|
4257
|
+
const currentErrors = errors.reduce((acc, item) => {
|
|
4258
|
+
acc[item.path.join(".")] = item.message;
|
|
4259
|
+
return acc;
|
|
4260
|
+
}, {});
|
|
4261
|
+
callback(currentErrors);
|
|
4196
4262
|
}
|
|
4197
|
-
);
|
|
4198
|
-
try {
|
|
4199
|
-
const response = yield fn(...params);
|
|
4200
|
-
return response;
|
|
4201
|
-
} catch (error) {
|
|
4202
|
-
errorHandler(error);
|
|
4203
|
-
} finally {
|
|
4204
|
-
setLoading(LOADING_NAME, true);
|
|
4205
|
-
}
|
|
4206
|
-
});
|
|
4207
|
-
}
|
|
4208
|
-
function errorHandler(error, callback) {
|
|
4209
|
-
if ((error == null ? void 0 : error.message) === "cancel.navigation")
|
|
4210
|
-
return;
|
|
4211
|
-
if (callback) {
|
|
4212
|
-
if (error.response.data.code === "invalid.body") {
|
|
4213
|
-
const errors = error.response.data.details.issues;
|
|
4214
|
-
const currentErrors = errors.reduce((acc, item) => {
|
|
4215
|
-
acc[item.path.join(".")] = item.message;
|
|
4216
|
-
return acc;
|
|
4217
|
-
}, {});
|
|
4218
|
-
callback(currentErrors);
|
|
4219
4263
|
}
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4264
|
+
createAlert(formatErrorMessage(error), "error");
|
|
4265
|
+
},
|
|
4266
|
+
[formatErrorMessage, createAlert]
|
|
4267
|
+
);
|
|
4223
4268
|
_react.useEffect.call(void 0, () => {
|
|
4224
4269
|
return () => {
|
|
4225
4270
|
sourceRef.current.abort();
|
|
@@ -4567,7 +4612,7 @@ function getObjectValue(obj) {
|
|
|
4567
4612
|
// src/hooks/useFilter.ts
|
|
4568
4613
|
function useFilter() {
|
|
4569
4614
|
const [selectedFilters, setSelectedFilters] = _react.useState.call(void 0, []);
|
|
4570
|
-
const filterBy = (newFilter) => {
|
|
4615
|
+
const filterBy = _react.useCallback.call(void 0, (newFilter) => {
|
|
4571
4616
|
const propToCompare = (newFilter == null ? void 0 : newFilter.id) ? "id" : "prop";
|
|
4572
4617
|
function removeRepeatedFilters(filter) {
|
|
4573
4618
|
return filter[propToCompare] !== newFilter[propToCompare];
|
|
@@ -4576,13 +4621,16 @@ function useFilter() {
|
|
|
4576
4621
|
...filters.filter(removeRepeatedFilters),
|
|
4577
4622
|
newFilter
|
|
4578
4623
|
]);
|
|
4579
|
-
};
|
|
4580
|
-
const removeFilter = (
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4624
|
+
}, []);
|
|
4625
|
+
const removeFilter = _react.useCallback.call(void 0,
|
|
4626
|
+
(prop, isId) => {
|
|
4627
|
+
const propToCompare = isId ? "id" : "prop";
|
|
4628
|
+
setSelectedFilters(
|
|
4629
|
+
selectedFilters.filter((filter) => filter[propToCompare] !== prop)
|
|
4630
|
+
);
|
|
4631
|
+
},
|
|
4632
|
+
[selectedFilters]
|
|
4633
|
+
);
|
|
4586
4634
|
function clearAllFilters() {
|
|
4587
4635
|
setSelectedFilters([]);
|
|
4588
4636
|
}
|
|
@@ -4637,70 +4685,96 @@ function createFilter(filters) {
|
|
|
4637
4685
|
}
|
|
4638
4686
|
|
|
4639
4687
|
// src/hooks/useGrid.ts
|
|
4688
|
+
var _sortby = require('sort-by'); var _sortby2 = _interopRequireDefault(_sortby);
|
|
4640
4689
|
function useGrid({
|
|
4641
4690
|
columns,
|
|
4642
4691
|
filters = [],
|
|
4643
4692
|
search,
|
|
4644
|
-
rowsPerPageOptions = [30, 60, 100]
|
|
4693
|
+
rowsPerPageOptions = [30, 60, 100],
|
|
4694
|
+
defaultData: externalDefaultData,
|
|
4695
|
+
defaultCurrentPage,
|
|
4696
|
+
defaultSortedBy
|
|
4645
4697
|
}) {
|
|
4646
|
-
const [defaultData, setDefaultData] = _react.useState.call(void 0, []);
|
|
4647
|
-
const [sortedBy, setSortedBy] = _react.useState.call(void 0,
|
|
4648
|
-
|
|
4649
|
-
|
|
4698
|
+
const [defaultData, setDefaultData] = _react.useState.call(void 0, externalDefaultData || []);
|
|
4699
|
+
const [sortedBy, setSortedBy] = _react.useState.call(void 0,
|
|
4700
|
+
defaultSortedBy || []
|
|
4701
|
+
);
|
|
4702
|
+
const [currentPage, setCurrentPage] = _react.useState.call(void 0, defaultCurrentPage || 0);
|
|
4650
4703
|
const [rowsPerPage, setRowsPerPage] = _react.useState.call(void 0, rowsPerPageOptions[0]);
|
|
4651
|
-
const toggleSortedDirection = (
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4704
|
+
const toggleSortedDirection = _react.useCallback.call(void 0,
|
|
4705
|
+
(direction) => {
|
|
4706
|
+
if (direction === "asc")
|
|
4707
|
+
return "desc";
|
|
4708
|
+
return "asc";
|
|
4709
|
+
},
|
|
4710
|
+
[]
|
|
4711
|
+
);
|
|
4712
|
+
const setSort = _react.useCallback.call(void 0, (prop, direction) => {
|
|
4713
|
+
setSortedBy((prev) => [...prev, { prop, direction }]);
|
|
4714
|
+
}, []);
|
|
4715
|
+
const onSortBy = _react.useCallback.call(void 0,
|
|
4716
|
+
(prop) => {
|
|
4717
|
+
if (!prop)
|
|
4718
|
+
return;
|
|
4719
|
+
const currentSorted = sortedBy.find((p) => p.prop === prop);
|
|
4720
|
+
if (currentSorted) {
|
|
4721
|
+
if (currentSorted.direction === "asc") {
|
|
4722
|
+
setSortedBy((prev) => prev.filter((p) => p.prop !== prop));
|
|
4723
|
+
} else {
|
|
4724
|
+
setSortedBy((prev) => {
|
|
4725
|
+
const newArr = prev.map((p) => {
|
|
4726
|
+
if (p.prop !== prop)
|
|
4727
|
+
return p;
|
|
4728
|
+
return {
|
|
4729
|
+
prop: p.prop,
|
|
4730
|
+
direction: toggleSortedDirection(p.direction)
|
|
4731
|
+
};
|
|
4732
|
+
});
|
|
4733
|
+
return [...newArr].slice(0);
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
} else {
|
|
4737
|
+
setSortedBy((prev) => [...prev, { prop, direction: "desc" }]);
|
|
4738
|
+
}
|
|
4739
|
+
},
|
|
4740
|
+
[toggleSortedDirection, sortedBy]
|
|
4741
|
+
);
|
|
4742
|
+
const set = _react.useCallback.call(void 0, (data) => {
|
|
4676
4743
|
setDefaultData(data);
|
|
4677
|
-
};
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
const
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4744
|
+
}, []);
|
|
4745
|
+
const sortData = _react.useCallback.call(void 0,
|
|
4746
|
+
(data) => {
|
|
4747
|
+
if (sortedBy.length > 0) {
|
|
4748
|
+
const symbolDir = {
|
|
4749
|
+
asc: "",
|
|
4750
|
+
desc: "-"
|
|
4751
|
+
};
|
|
4752
|
+
const formattedKeys = sortedBy.map(
|
|
4753
|
+
({ prop, direction }) => `${symbolDir[direction]}${prop}`
|
|
4754
|
+
);
|
|
4755
|
+
return data.sort(_sortby2.default.call(void 0, ...formattedKeys));
|
|
4756
|
+
} else
|
|
4757
|
+
return data;
|
|
4758
|
+
},
|
|
4759
|
+
[sortedBy]
|
|
4760
|
+
);
|
|
4761
|
+
const onPageChange = _react.useCallback.call(void 0, (pageNumber) => {
|
|
4691
4762
|
if (pageNumber < 0)
|
|
4692
4763
|
return;
|
|
4693
4764
|
if (pageNumber > totalNumberOfPages)
|
|
4694
4765
|
return;
|
|
4695
4766
|
setCurrentPage(pageNumber);
|
|
4696
|
-
};
|
|
4697
|
-
const onChangeRowsPerPage = (
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4767
|
+
}, []);
|
|
4768
|
+
const onChangeRowsPerPage = _react.useCallback.call(void 0,
|
|
4769
|
+
(rows) => {
|
|
4770
|
+
let totalNumberOfPages2 = Math.round(filteredData.length / rows) - 1;
|
|
4771
|
+
totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
|
|
4772
|
+
if (currentPage > totalNumberOfPages2)
|
|
4773
|
+
setCurrentPage(totalNumberOfPages2);
|
|
4774
|
+
setRowsPerPage(rows);
|
|
4775
|
+
},
|
|
4776
|
+
[currentPage]
|
|
4777
|
+
);
|
|
4704
4778
|
const filteredData = _react.useMemo.call(void 0, () => {
|
|
4705
4779
|
let newData = defaultData.slice(0);
|
|
4706
4780
|
if (search && search.value !== "") {
|
|
@@ -4715,7 +4789,7 @@ function useGrid({
|
|
|
4715
4789
|
const startPage = currentPage * rowsPerPage;
|
|
4716
4790
|
const endPage = startPage + rowsPerPage;
|
|
4717
4791
|
return sortedData.slice(startPage, endPage);
|
|
4718
|
-
}, [
|
|
4792
|
+
}, [filteredData, currentPage, rowsPerPage, sortData]);
|
|
4719
4793
|
const totalNumberOfPages = Math.ceil(filteredData.length / rowsPerPage) - 1;
|
|
4720
4794
|
return {
|
|
4721
4795
|
data: displayData,
|
|
@@ -4723,7 +4797,6 @@ function useGrid({
|
|
|
4723
4797
|
onSortBy,
|
|
4724
4798
|
sortedBy,
|
|
4725
4799
|
defaultData,
|
|
4726
|
-
sortedDirection,
|
|
4727
4800
|
columns,
|
|
4728
4801
|
currentPage,
|
|
4729
4802
|
totalNumberOfPages: totalNumberOfPages < 0 ? 0 : totalNumberOfPages,
|
|
@@ -4769,6 +4842,180 @@ function createSearch(options) {
|
|
|
4769
4842
|
};
|
|
4770
4843
|
}
|
|
4771
4844
|
|
|
4845
|
+
// src/hooks/useAsyncGrid.ts
|
|
4846
|
+
|
|
4847
|
+
function useAsyncGrid({
|
|
4848
|
+
columns,
|
|
4849
|
+
filters = [],
|
|
4850
|
+
search,
|
|
4851
|
+
rowsPerPageOptions = [30, 60, 100],
|
|
4852
|
+
onRequest,
|
|
4853
|
+
axiosInstance,
|
|
4854
|
+
url,
|
|
4855
|
+
defaultData: externalDefaultData,
|
|
4856
|
+
defaultCurrentPage,
|
|
4857
|
+
defaultSortedBy
|
|
4858
|
+
}) {
|
|
4859
|
+
const [defaultData, setDefaultData] = _react.useState.call(void 0, externalDefaultData || []);
|
|
4860
|
+
const [sortedBy, setSortedBy] = _react.useState.call(void 0,
|
|
4861
|
+
defaultSortedBy || []
|
|
4862
|
+
);
|
|
4863
|
+
const [totalNumberOfItems, setTotalNumberOfItems] = _react.useState.call(void 0, 0);
|
|
4864
|
+
const [isLoading, setIsLoading] = _react.useState.call(void 0, false);
|
|
4865
|
+
const [currentPage, setCurrentPage] = _react.useState.call(void 0, defaultCurrentPage || 0);
|
|
4866
|
+
const [rowsPerPage, setRowsPerPage] = _react.useState.call(void 0, rowsPerPageOptions[0]);
|
|
4867
|
+
const totalNumberOfPages = Math.ceil(totalNumberOfItems / rowsPerPage) - 1;
|
|
4868
|
+
const toggleSortedDirection = _react.useCallback.call(void 0,
|
|
4869
|
+
(direction) => {
|
|
4870
|
+
if (direction === "asc")
|
|
4871
|
+
return "desc";
|
|
4872
|
+
return "asc";
|
|
4873
|
+
},
|
|
4874
|
+
[]
|
|
4875
|
+
);
|
|
4876
|
+
const setSort = _react.useCallback.call(void 0, (prop, direction) => {
|
|
4877
|
+
setSortedBy((prev) => [...prev, { prop, direction }]);
|
|
4878
|
+
}, []);
|
|
4879
|
+
const onSortBy = _react.useCallback.call(void 0,
|
|
4880
|
+
(prop) => __async(this, null, function* () {
|
|
4881
|
+
if (!prop)
|
|
4882
|
+
return;
|
|
4883
|
+
let finalArr = [];
|
|
4884
|
+
const currentSorted = sortedBy.find((p) => p.prop === prop);
|
|
4885
|
+
if (currentSorted) {
|
|
4886
|
+
if (currentSorted.direction === "asc") {
|
|
4887
|
+
finalArr = sortedBy.filter((p) => p.prop !== prop);
|
|
4888
|
+
} else {
|
|
4889
|
+
finalArr = sortedBy.map((p) => {
|
|
4890
|
+
if (p.prop !== prop)
|
|
4891
|
+
return p;
|
|
4892
|
+
return {
|
|
4893
|
+
prop: p.prop,
|
|
4894
|
+
direction: toggleSortedDirection(p.direction)
|
|
4895
|
+
};
|
|
4896
|
+
});
|
|
4897
|
+
}
|
|
4898
|
+
} else {
|
|
4899
|
+
finalArr = [...sortedBy, { prop, direction: "desc" }];
|
|
4900
|
+
}
|
|
4901
|
+
yield updateGridContent({
|
|
4902
|
+
page: currentPage,
|
|
4903
|
+
sortedBy: finalArr,
|
|
4904
|
+
rowsPerPage
|
|
4905
|
+
});
|
|
4906
|
+
}),
|
|
4907
|
+
[sortedBy, toggleSortedDirection, rowsPerPage, currentPage]
|
|
4908
|
+
);
|
|
4909
|
+
const set = _react.useCallback.call(void 0, (data) => {
|
|
4910
|
+
setDefaultData(data);
|
|
4911
|
+
}, []);
|
|
4912
|
+
const baseRequest = _react.useCallback.call(void 0,
|
|
4913
|
+
(_0) => __async(this, [_0], function* ({
|
|
4914
|
+
page,
|
|
4915
|
+
search: search2,
|
|
4916
|
+
filters: filters2,
|
|
4917
|
+
sortedBy: sortedBy2,
|
|
4918
|
+
rowsPerPage: rowsPerPage2
|
|
4919
|
+
}) {
|
|
4920
|
+
if (!axiosInstance)
|
|
4921
|
+
throw new Error("Axios instance not provided");
|
|
4922
|
+
try {
|
|
4923
|
+
const params = new URLSearchParams({
|
|
4924
|
+
page: String(page),
|
|
4925
|
+
rowsPerPage: String(rowsPerPage2),
|
|
4926
|
+
searchText: (search2 == null ? void 0 : search2.value) || "",
|
|
4927
|
+
sort: sortedBy2.map(({ prop, direction }) => `${prop}:${direction}`).join(","),
|
|
4928
|
+
filters: filters2.map(
|
|
4929
|
+
(filter) => `${filter.prop}:${filter.compareType}:${filter.value}`
|
|
4930
|
+
).join(",")
|
|
4931
|
+
});
|
|
4932
|
+
const pathWithParams = `${url}?${params.toString()}`;
|
|
4933
|
+
const { data } = yield axiosInstance.get(pathWithParams);
|
|
4934
|
+
setTotalNumberOfItems(data.totalNumberOfItems);
|
|
4935
|
+
return data.rows;
|
|
4936
|
+
} catch (_) {
|
|
4937
|
+
return [];
|
|
4938
|
+
}
|
|
4939
|
+
}),
|
|
4940
|
+
[axiosInstance, url]
|
|
4941
|
+
);
|
|
4942
|
+
const updateGridContent = _react.useCallback.call(void 0,
|
|
4943
|
+
(_0) => __async(this, [_0], function* ({
|
|
4944
|
+
page,
|
|
4945
|
+
sortedBy: sortedBy2,
|
|
4946
|
+
rowsPerPage: rowsPerPage2
|
|
4947
|
+
}) {
|
|
4948
|
+
setIsLoading(true);
|
|
4949
|
+
try {
|
|
4950
|
+
const props = {
|
|
4951
|
+
page,
|
|
4952
|
+
rowsPerPage: rowsPerPage2,
|
|
4953
|
+
sortedBy: sortedBy2,
|
|
4954
|
+
search,
|
|
4955
|
+
filters
|
|
4956
|
+
};
|
|
4957
|
+
const result = !onRequest ? yield baseRequest(props) : yield onRequest(props);
|
|
4958
|
+
setSortedBy(sortedBy2);
|
|
4959
|
+
setRowsPerPage(rowsPerPage2);
|
|
4960
|
+
set(result);
|
|
4961
|
+
setCurrentPage(page);
|
|
4962
|
+
} finally {
|
|
4963
|
+
setIsLoading(false);
|
|
4964
|
+
}
|
|
4965
|
+
}),
|
|
4966
|
+
[set, search, filters, onRequest, baseRequest]
|
|
4967
|
+
);
|
|
4968
|
+
const onPageChange = _react.useCallback.call(void 0,
|
|
4969
|
+
(pageNumber) => {
|
|
4970
|
+
if (pageNumber < 0)
|
|
4971
|
+
return;
|
|
4972
|
+
if (pageNumber > totalNumberOfPages)
|
|
4973
|
+
return;
|
|
4974
|
+
updateGridContent({ page: pageNumber, sortedBy, rowsPerPage });
|
|
4975
|
+
},
|
|
4976
|
+
[updateGridContent, totalNumberOfPages, sortedBy, rowsPerPage]
|
|
4977
|
+
);
|
|
4978
|
+
const onChangeRowsPerPage = _react.useCallback.call(void 0,
|
|
4979
|
+
(rows) => {
|
|
4980
|
+
let totalNumberOfPages2 = Math.round(totalNumberOfItems / rows) - 1;
|
|
4981
|
+
totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
|
|
4982
|
+
if (currentPage > totalNumberOfPages2)
|
|
4983
|
+
updateGridContent({
|
|
4984
|
+
page: totalNumberOfPages2,
|
|
4985
|
+
sortedBy,
|
|
4986
|
+
rowsPerPage: rows
|
|
4987
|
+
});
|
|
4988
|
+
updateGridContent({
|
|
4989
|
+
page: currentPage,
|
|
4990
|
+
sortedBy,
|
|
4991
|
+
rowsPerPage: rows
|
|
4992
|
+
});
|
|
4993
|
+
},
|
|
4994
|
+
[updateGridContent, totalNumberOfItems, sortedBy, currentPage]
|
|
4995
|
+
);
|
|
4996
|
+
const displayData = defaultData;
|
|
4997
|
+
_react.useEffect.call(void 0, () => {
|
|
4998
|
+
updateGridContent({ page: 0, sortedBy: [], rowsPerPage });
|
|
4999
|
+
}, [updateGridContent, rowsPerPage]);
|
|
5000
|
+
return {
|
|
5001
|
+
data: displayData,
|
|
5002
|
+
set,
|
|
5003
|
+
onSortBy,
|
|
5004
|
+
sortedBy,
|
|
5005
|
+
defaultData,
|
|
5006
|
+
columns,
|
|
5007
|
+
currentPage,
|
|
5008
|
+
totalNumberOfPages: totalNumberOfPages < 0 ? 0 : totalNumberOfPages,
|
|
5009
|
+
onPageChange,
|
|
5010
|
+
setRowsPerPage: onChangeRowsPerPage,
|
|
5011
|
+
rowsPerPageOptions,
|
|
5012
|
+
rowsPerPage,
|
|
5013
|
+
setSort,
|
|
5014
|
+
isLoading,
|
|
5015
|
+
setIsLoading
|
|
5016
|
+
};
|
|
5017
|
+
}
|
|
5018
|
+
|
|
4772
5019
|
// src/hooks/useEvent.ts
|
|
4773
5020
|
|
|
4774
5021
|
function useEvent(event, handler, passive = false) {
|
|
@@ -4800,31 +5047,32 @@ function CreateAuthProvider({
|
|
|
4800
5047
|
const [user, setUser] = _react.useState.call(void 0, );
|
|
4801
5048
|
const [status, setStatus] = _react.useState.call(void 0, "unauthenticated");
|
|
4802
5049
|
const { createAlert } = useAlert();
|
|
4803
|
-
const signIn = (
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
5050
|
+
const signIn = _react.useCallback.call(void 0,
|
|
5051
|
+
(_0) => __async(this, [_0], function* ({ email, password }) {
|
|
5052
|
+
setStatus("loading");
|
|
5053
|
+
try {
|
|
5054
|
+
const response = yield api.post("/auth/login", {
|
|
5055
|
+
email,
|
|
5056
|
+
password
|
|
5057
|
+
});
|
|
5058
|
+
const { token } = response.data;
|
|
5059
|
+
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
|
5060
|
+
const { data } = yield api.get("/auth/me");
|
|
5061
|
+
setUser(data);
|
|
5062
|
+
setStatus("autenticated");
|
|
5063
|
+
return true;
|
|
5064
|
+
} catch (error) {
|
|
5065
|
+
createAlert(error.response.data.error, "error");
|
|
5066
|
+
setStatus("unauthenticated");
|
|
5067
|
+
throw error;
|
|
5068
|
+
}
|
|
5069
|
+
}),
|
|
5070
|
+
[createAlert, api]
|
|
5071
|
+
);
|
|
5072
|
+
const ClientSignOut = _react.useCallback.call(void 0, () => __async(this, null, function* () {
|
|
5073
|
+
yield api.get("/auth/logout");
|
|
5074
|
+
setUser(void 0);
|
|
5075
|
+
}), [api]);
|
|
4828
5076
|
_react.useEffect.call(void 0, () => {
|
|
4829
5077
|
const token = _nookies.parseCookies.call(void 0, )[sessionTokenName];
|
|
4830
5078
|
if (token) {
|
|
@@ -4886,7 +5134,9 @@ function CreateAuthProvider({
|
|
|
4886
5134
|
|
|
4887
5135
|
|
|
4888
5136
|
|
|
4889
|
-
|
|
5137
|
+
|
|
5138
|
+
|
|
5139
|
+
exports.AlertContext = AlertContext; exports.AlertProvider = AlertProvider; exports.ApiHelper = ApiHelper; exports.AuthHelper = AuthHelper; exports.Autocomplete = Autocomplete2; exports.BaseGrid = BaseGrid; exports.BaseGridAutoRows = BaseGridAutoRows; exports.Checkbox = Checkbox; exports.CreateAuthProvider = CreateAuthProvider; exports.Dialog = Dialog; exports.EditableTableCell = EditableTableCell; exports.FormHelperContext = FormHelperContext; exports.FormHelperProvider = FormHelperProvider; exports.GetInputLabel = GetInputLabel; exports.Grid = Grid_default; exports.HttpError = HttpError; exports.Input = Input; exports.InputMask = InputMask2; exports.LargeButton = LargeButton; exports.Modal = Modal; exports.Radio = Radio; exports.Select = Select; exports.Switch = Switch; exports.TabPanel = TabPanel; exports.Td = Td; exports.Tr = Tr; exports.createAuthContext = createAuthContext; exports.createFilter = createFilter; exports.filterData = filterData; exports.getTabProps = getTabProps; exports.useAlert = useAlert; exports.useAsyncGrid = useAsyncGrid; exports.useEvent = useEvent; exports.useFilter = useFilter; exports.useFormHelper = useFormHelper; exports.useGrid = useGrid; exports.useLoading = useLoading;
|
|
4890
5140
|
/*! Bundled license information:
|
|
4891
5141
|
|
|
4892
5142
|
react-is/cjs/react-is.production.min.js:
|