@compill/admin 1.0.56 → 1.0.58
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/index.cjs.js +16 -166
- package/index.esm.js +16 -167
- package/package.json +1 -1
- package/src/index.d.ts +8 -7
- package/src/lib/layout/ButtonBar.d.ts +4 -2
- package/src/lib/modal/ItemEditDialog.d.ts +0 -33
package/index.cjs.js
CHANGED
@@ -179,7 +179,7 @@ function ButtonBar(_a) {
|
|
179
179
|
children: children
|
180
180
|
}));
|
181
181
|
}
|
182
|
-
|
182
|
+
const ButtonBarButton = /*#__PURE__*/React__default["default"].forwardRef(function (_a, ref) {
|
183
183
|
var {
|
184
184
|
icon,
|
185
185
|
children
|
@@ -196,11 +196,12 @@ function ButtonBarButton(_a) {
|
|
196
196
|
corners: "square",
|
197
197
|
gap: "2"
|
198
198
|
}, props, {
|
199
|
+
ref: ref,
|
199
200
|
children: [icon && jsxRuntime.jsx(ui.Icon, {
|
200
201
|
path: icon
|
201
202
|
}), children]
|
202
203
|
}));
|
203
|
-
}
|
204
|
+
});
|
204
205
|
function ButtonBarDialogButton(_a) {
|
205
206
|
var {
|
206
207
|
icon,
|
@@ -1939,8 +1940,8 @@ function TableMassActions({
|
|
1939
1940
|
});
|
1940
1941
|
}
|
1941
1942
|
|
1942
|
-
const defaultErrorMsg$
|
1943
|
-
function nonNullValues
|
1943
|
+
const defaultErrorMsg$1 = "Oops, something went wrong...";
|
1944
|
+
function nonNullValues(data) {
|
1944
1945
|
var _a;
|
1945
1946
|
if (data) {
|
1946
1947
|
const nonNullData = Object.assign({}, data);
|
@@ -1949,7 +1950,7 @@ function nonNullValues$1(data) {
|
|
1949
1950
|
}
|
1950
1951
|
return data;
|
1951
1952
|
}
|
1952
|
-
function ItemEditDialog
|
1953
|
+
function ItemEditDialog(_a) {
|
1953
1954
|
var _b, _c, _d, _e;
|
1954
1955
|
var {
|
1955
1956
|
initialValues,
|
@@ -1960,9 +1961,9 @@ function ItemEditDialog$1(_a) {
|
|
1960
1961
|
querySaveOptions,
|
1961
1962
|
onSuccess,
|
1962
1963
|
onFetchError,
|
1963
|
-
fetchErrorMsg = defaultErrorMsg$
|
1964
|
+
fetchErrorMsg = defaultErrorMsg$1,
|
1964
1965
|
onSaveError,
|
1965
|
-
saveErrorMsg = defaultErrorMsg$
|
1966
|
+
saveErrorMsg = defaultErrorMsg$1,
|
1966
1967
|
fetchToFormData,
|
1967
1968
|
formToQueryData,
|
1968
1969
|
invalidateQueriesOnSuccess = true,
|
@@ -2050,7 +2051,7 @@ function ItemEditDialog$1(_a) {
|
|
2050
2051
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2051
2052
|
, Object.assign({
|
2052
2053
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2053
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues
|
2054
|
+
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = nonNullValues(initialValues(data))) !== null && _e !== void 0 ? _e : {},
|
2054
2055
|
onSubmit: saveItem
|
2055
2056
|
}, formikProps, {
|
2056
2057
|
children: ({
|
@@ -2119,7 +2120,7 @@ function QueryWrapperDialog({
|
|
2119
2120
|
}, [data, fn, transformFn]);
|
2120
2121
|
if (isFetching) return null;
|
2121
2122
|
// @ts-ignore
|
2122
|
-
return jsxRuntime.jsx(ItemEditDialog
|
2123
|
+
return jsxRuntime.jsx(ItemEditDialog, Object.assign({}, config(transformedData), {
|
2123
2124
|
queryId: queryId,
|
2124
2125
|
invalidateQueryKey: invalidateQueryKey,
|
2125
2126
|
show: true,
|
@@ -2157,7 +2158,7 @@ function MultiQueryWrapperDialog({
|
|
2157
2158
|
// if (isFetching)
|
2158
2159
|
// return null
|
2159
2160
|
// @ts-ignore
|
2160
|
-
return jsxRuntime.jsx(ItemEditDialog
|
2161
|
+
return jsxRuntime.jsx(ItemEditDialog, Object.assign({
|
2161
2162
|
isPreloading: isFetching
|
2162
2163
|
}, config(...transformedData), {
|
2163
2164
|
queryId: queryId,
|
@@ -2174,7 +2175,7 @@ function DialogRenderer({
|
|
2174
2175
|
queryId
|
2175
2176
|
}) {
|
2176
2177
|
const props = __rest$1(config, ["type"]);
|
2177
|
-
if (config.type === "dialog") return jsxRuntime.jsx(ItemEditDialog
|
2178
|
+
if (config.type === "dialog") return jsxRuntime.jsx(ItemEditDialog, Object.assign({}, props, {
|
2178
2179
|
queryId: queryId,
|
2179
2180
|
invalidateQueryKey: invalidateQueryKey,
|
2180
2181
|
show: true,
|
@@ -3049,7 +3050,7 @@ function LeftPanel({
|
|
3049
3050
|
});
|
3050
3051
|
}
|
3051
3052
|
|
3052
|
-
const defaultErrorMsg
|
3053
|
+
const defaultErrorMsg = "Oops, something went wrong...";
|
3053
3054
|
function AttachDialog(_a) {
|
3054
3055
|
var {
|
3055
3056
|
queryId,
|
@@ -3065,9 +3066,9 @@ function AttachDialog(_a) {
|
|
3065
3066
|
itemLabel,
|
3066
3067
|
onSuccess,
|
3067
3068
|
onFetchError,
|
3068
|
-
fetchErrorMsg = defaultErrorMsg
|
3069
|
+
fetchErrorMsg = defaultErrorMsg,
|
3069
3070
|
onSaveError,
|
3070
|
-
saveErrorMsg = defaultErrorMsg
|
3071
|
+
saveErrorMsg = defaultErrorMsg,
|
3071
3072
|
invalidateQueriesOnSuccess = true,
|
3072
3073
|
retryText = "Retry",
|
3073
3074
|
cancelLabel = "Cancel",
|
@@ -3294,158 +3295,6 @@ function FormActionDialog(_a) {
|
|
3294
3295
|
}));
|
3295
3296
|
}
|
3296
3297
|
|
3297
|
-
const defaultErrorMsg = "Oops, something went wrong...";
|
3298
|
-
function nonNullValues(data) {
|
3299
|
-
var _a;
|
3300
|
-
if (data) {
|
3301
|
-
const nonNullData = Object.assign({}, data);
|
3302
|
-
for (const key in data) nonNullData[key] = (_a = nonNullData[key]) !== null && _a !== void 0 ? _a : "";
|
3303
|
-
return nonNullData;
|
3304
|
-
}
|
3305
|
-
return data;
|
3306
|
-
}
|
3307
|
-
function ItemEditDialog(_a) {
|
3308
|
-
var _b, _c, _d, _e;
|
3309
|
-
var {
|
3310
|
-
initialValues,
|
3311
|
-
itemLabel,
|
3312
|
-
queryId = "",
|
3313
|
-
queryKey,
|
3314
|
-
queryFetchFn,
|
3315
|
-
queryFetchOptions,
|
3316
|
-
querySaveFn,
|
3317
|
-
querySaveOptions,
|
3318
|
-
onSuccess,
|
3319
|
-
onFetchError,
|
3320
|
-
fetchErrorMsg = defaultErrorMsg,
|
3321
|
-
onSaveError,
|
3322
|
-
saveErrorMsg = defaultErrorMsg,
|
3323
|
-
fetchToFormData,
|
3324
|
-
formToQueryData,
|
3325
|
-
invalidateQueriesOnSuccess = true,
|
3326
|
-
invalidateQueryKey,
|
3327
|
-
retryText = "Retry",
|
3328
|
-
cancelLabel = "Cancel",
|
3329
|
-
saveLabel,
|
3330
|
-
size = "lg",
|
3331
|
-
title,
|
3332
|
-
form: form$1,
|
3333
|
-
show,
|
3334
|
-
onClose,
|
3335
|
-
formikProps
|
3336
|
-
} = _a,
|
3337
|
-
props = __rest$1(_a, ["initialValues", "itemLabel", "queryId", "queryKey", "queryFetchFn", "queryFetchOptions", "querySaveFn", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
|
3338
|
-
const {
|
3339
|
-
isInitialLoading,
|
3340
|
-
isFetching,
|
3341
|
-
data,
|
3342
|
-
isError,
|
3343
|
-
error /*, error*/,
|
3344
|
-
refetch
|
3345
|
-
} = api.useApiQuery(queryKey, queryFetchFn, queryId, Object.assign({
|
3346
|
-
enabled: !( /*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
|
3347
|
-
onError: onFetchError
|
3348
|
-
}, queryFetchOptions));
|
3349
|
-
// const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
|
3350
|
-
// const [showTab, setShowTab] = React.useState(true);
|
3351
|
-
const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(querySaveFn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : queryKey, querySaveOptions) : api.useApiMutation(querySaveFn, queryKey, queryId, querySaveOptions);
|
3352
|
-
const retry = React__default["default"].useCallback(() => refetch(), [refetch]);
|
3353
|
-
const saveItem = React__default["default"].useCallback((item, actions) => {
|
3354
|
-
// Clear mutation error if any
|
3355
|
-
mutation.reset();
|
3356
|
-
const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
|
3357
|
-
mutation.mutateAsync(formItem).then(response => {
|
3358
|
-
var _a;
|
3359
|
-
if (onSuccess) onSuccess(formItem, response);else reactToastify.toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
|
3360
|
-
// closing delete modal
|
3361
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
3362
|
-
}).catch(error => {
|
3363
|
-
var _a;
|
3364
|
-
console.error("on error", error);
|
3365
|
-
if (onSaveError) onSaveError(item);else reactToastify.toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
|
3366
|
-
actions.setSubmitting(false);
|
3367
|
-
});
|
3368
|
-
}, [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
3369
|
-
// const switchTab = React.useCallback((tab: string) =>
|
3370
|
-
// {
|
3371
|
-
// setActiveTab(tab);
|
3372
|
-
// setShowTab(false);
|
3373
|
-
// setTimeout(function ()
|
3374
|
-
// {
|
3375
|
-
// setActiveTab(tab);
|
3376
|
-
// setShowTab(true);
|
3377
|
-
// }, 150);
|
3378
|
-
// }, [setActiveTab])
|
3379
|
-
return jsxRuntime.jsxs(ui.Modal, Object.assign({
|
3380
|
-
size: size,
|
3381
|
-
show: show,
|
3382
|
-
onClose: onClose,
|
3383
|
-
scheme: "light",
|
3384
|
-
transition: true
|
3385
|
-
}, props, {
|
3386
|
-
children: [jsxRuntime.jsxs(ui.Modal.Header, {
|
3387
|
-
children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_c = (_b = data === null || data === void 0 ? void 0 : data["name"]) !== null && _b !== void 0 ? _b : data === null || data === void 0 ? void 0 : data["title"]) !== null && _c !== void 0 ? _c : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form$1) && jsxRuntime.jsx(jsxRuntime.Fragment, {})
|
3388
|
-
// <ul className="nav nav-bold nav-pills">
|
3389
|
-
// {form.map(item =>
|
3390
|
-
// <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
|
3391
|
-
// <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
|
3392
|
-
// </li>
|
3393
|
-
// )}
|
3394
|
-
// </ul>
|
3395
|
-
]
|
3396
|
-
}), isInitialLoading && jsxRuntime.jsx(ui.Modal.Body, {
|
3397
|
-
children: jsxRuntime.jsx(components.QueryLoadingState, {
|
3398
|
-
minW: "72"
|
3399
|
-
})
|
3400
|
-
}), isError && jsxRuntime.jsx(ui.Modal.Body, {
|
3401
|
-
children: jsxRuntime.jsx(components.RetryOnError, {
|
3402
|
-
label: `${fetchErrorMsg} ${error}`,
|
3403
|
-
onClick: retry
|
3404
|
-
})
|
3405
|
-
}), !isInitialLoading && !isError && jsxRuntime.jsx(jsxRuntime.Fragment, {
|
3406
|
-
children: jsxRuntime.jsx(formik.Formik, Object.assign({
|
3407
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = (_d = nonNullValues(data)) !== null && _d !== void 0 ? _d : initialValues) !== null && _e !== void 0 ? _e : {},
|
3408
|
-
onSubmit: saveItem
|
3409
|
-
}, formikProps, {
|
3410
|
-
children: ({
|
3411
|
-
setFieldValue,
|
3412
|
-
dirty,
|
3413
|
-
handleSubmit,
|
3414
|
-
isValid,
|
3415
|
-
values
|
3416
|
-
}) => jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
3417
|
-
children: [jsxRuntime.jsx(ui.Modal.Body, {
|
3418
|
-
pb: "6",
|
3419
|
-
children: jsxRuntime.jsxs(formik.Form, {
|
3420
|
-
children: [/*#__PURE__*/React__default["default"].isValidElement(form$1) && form$1, Array.isArray(form$1) && jsxRuntime.jsx(form.FormRenderer, {
|
3421
|
-
form: form$1
|
3422
|
-
}), react.isFunction(form$1) && jsxRuntime.jsx(form.FormRenderer, {
|
3423
|
-
form: form$1(data !== null && data !== void 0 ? data : values)
|
3424
|
-
})]
|
3425
|
-
})
|
3426
|
-
}), jsxRuntime.jsxs(ui.Modal.Footer, {
|
3427
|
-
dflex: true,
|
3428
|
-
placeContent: "end",
|
3429
|
-
spaceX: "3",
|
3430
|
-
children: [jsxRuntime.jsx(ui.Button, {
|
3431
|
-
disabled: mutation.isLoading,
|
3432
|
-
onClick: onClose,
|
3433
|
-
variant: "borderless",
|
3434
|
-
me: "2",
|
3435
|
-
children: cancelLabel
|
3436
|
-
}), jsxRuntime.jsx(ui.Button, {
|
3437
|
-
type: "submit",
|
3438
|
-
disabled: !dirty || mutation.isLoading /* || !isValid*/,
|
3439
|
-
onClick: () => handleSubmit(),
|
3440
|
-
children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
|
3441
|
-
})]
|
3442
|
-
})]
|
3443
|
-
})
|
3444
|
-
}))
|
3445
|
-
}), mutation.isLoading && jsxRuntime.jsx(components.ModalLoadingOverlay, {})]
|
3446
|
-
}));
|
3447
|
-
}
|
3448
|
-
|
3449
3298
|
function PageSectionTitle(_a) {
|
3450
3299
|
var {
|
3451
3300
|
children
|
@@ -3695,6 +3544,7 @@ exports.ButtonBarDialogButton = ButtonBarDialogButton;
|
|
3695
3544
|
exports.DialogButton = DialogButton;
|
3696
3545
|
exports.FormActionDialog = FormActionDialog;
|
3697
3546
|
exports.InvalidateButton = InvalidateButton;
|
3547
|
+
exports.ItemDeleteDialog = ItemDeleteDialog;
|
3698
3548
|
exports.ItemEditDialog = ItemEditDialog;
|
3699
3549
|
exports.NavigateButton = NavigateButton;
|
3700
3550
|
exports.OrderCell = OrderCell;
|
package/index.esm.js
CHANGED
@@ -170,7 +170,7 @@ function ButtonBar(_a) {
|
|
170
170
|
children: children
|
171
171
|
}));
|
172
172
|
}
|
173
|
-
|
173
|
+
const ButtonBarButton = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
174
174
|
var {
|
175
175
|
icon,
|
176
176
|
children
|
@@ -187,11 +187,12 @@ function ButtonBarButton(_a) {
|
|
187
187
|
corners: "square",
|
188
188
|
gap: "2"
|
189
189
|
}, props, {
|
190
|
+
ref: ref,
|
190
191
|
children: [icon && jsx(Icon, {
|
191
192
|
path: icon
|
192
193
|
}), children]
|
193
194
|
}));
|
194
|
-
}
|
195
|
+
});
|
195
196
|
function ButtonBarDialogButton(_a) {
|
196
197
|
var {
|
197
198
|
icon,
|
@@ -1930,8 +1931,8 @@ function TableMassActions({
|
|
1930
1931
|
});
|
1931
1932
|
}
|
1932
1933
|
|
1933
|
-
const defaultErrorMsg$
|
1934
|
-
function nonNullValues
|
1934
|
+
const defaultErrorMsg$1 = "Oops, something went wrong...";
|
1935
|
+
function nonNullValues(data) {
|
1935
1936
|
var _a;
|
1936
1937
|
if (data) {
|
1937
1938
|
const nonNullData = Object.assign({}, data);
|
@@ -1940,7 +1941,7 @@ function nonNullValues$1(data) {
|
|
1940
1941
|
}
|
1941
1942
|
return data;
|
1942
1943
|
}
|
1943
|
-
function ItemEditDialog
|
1944
|
+
function ItemEditDialog(_a) {
|
1944
1945
|
var _b, _c, _d, _e;
|
1945
1946
|
var {
|
1946
1947
|
initialValues,
|
@@ -1951,9 +1952,9 @@ function ItemEditDialog$1(_a) {
|
|
1951
1952
|
querySaveOptions,
|
1952
1953
|
onSuccess,
|
1953
1954
|
onFetchError,
|
1954
|
-
fetchErrorMsg = defaultErrorMsg$
|
1955
|
+
fetchErrorMsg = defaultErrorMsg$1,
|
1955
1956
|
onSaveError,
|
1956
|
-
saveErrorMsg = defaultErrorMsg$
|
1957
|
+
saveErrorMsg = defaultErrorMsg$1,
|
1957
1958
|
fetchToFormData,
|
1958
1959
|
formToQueryData,
|
1959
1960
|
invalidateQueriesOnSuccess = true,
|
@@ -2041,7 +2042,7 @@ function ItemEditDialog$1(_a) {
|
|
2041
2042
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2042
2043
|
, Object.assign({
|
2043
2044
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2044
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues
|
2045
|
+
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = nonNullValues(initialValues(data))) !== null && _e !== void 0 ? _e : {},
|
2045
2046
|
onSubmit: saveItem
|
2046
2047
|
}, formikProps, {
|
2047
2048
|
children: ({
|
@@ -2110,7 +2111,7 @@ function QueryWrapperDialog({
|
|
2110
2111
|
}, [data, fn, transformFn]);
|
2111
2112
|
if (isFetching) return null;
|
2112
2113
|
// @ts-ignore
|
2113
|
-
return jsx(ItemEditDialog
|
2114
|
+
return jsx(ItemEditDialog, Object.assign({}, config(transformedData), {
|
2114
2115
|
queryId: queryId,
|
2115
2116
|
invalidateQueryKey: invalidateQueryKey,
|
2116
2117
|
show: true,
|
@@ -2148,7 +2149,7 @@ function MultiQueryWrapperDialog({
|
|
2148
2149
|
// if (isFetching)
|
2149
2150
|
// return null
|
2150
2151
|
// @ts-ignore
|
2151
|
-
return jsx(ItemEditDialog
|
2152
|
+
return jsx(ItemEditDialog, Object.assign({
|
2152
2153
|
isPreloading: isFetching
|
2153
2154
|
}, config(...transformedData), {
|
2154
2155
|
queryId: queryId,
|
@@ -2165,7 +2166,7 @@ function DialogRenderer({
|
|
2165
2166
|
queryId
|
2166
2167
|
}) {
|
2167
2168
|
const props = __rest$1(config, ["type"]);
|
2168
|
-
if (config.type === "dialog") return jsx(ItemEditDialog
|
2169
|
+
if (config.type === "dialog") return jsx(ItemEditDialog, Object.assign({}, props, {
|
2169
2170
|
queryId: queryId,
|
2170
2171
|
invalidateQueryKey: invalidateQueryKey,
|
2171
2172
|
show: true,
|
@@ -3040,7 +3041,7 @@ function LeftPanel({
|
|
3040
3041
|
});
|
3041
3042
|
}
|
3042
3043
|
|
3043
|
-
const defaultErrorMsg
|
3044
|
+
const defaultErrorMsg = "Oops, something went wrong...";
|
3044
3045
|
function AttachDialog(_a) {
|
3045
3046
|
var {
|
3046
3047
|
queryId,
|
@@ -3056,9 +3057,9 @@ function AttachDialog(_a) {
|
|
3056
3057
|
itemLabel,
|
3057
3058
|
onSuccess,
|
3058
3059
|
onFetchError,
|
3059
|
-
fetchErrorMsg = defaultErrorMsg
|
3060
|
+
fetchErrorMsg = defaultErrorMsg,
|
3060
3061
|
onSaveError,
|
3061
|
-
saveErrorMsg = defaultErrorMsg
|
3062
|
+
saveErrorMsg = defaultErrorMsg,
|
3062
3063
|
invalidateQueriesOnSuccess = true,
|
3063
3064
|
retryText = "Retry",
|
3064
3065
|
cancelLabel = "Cancel",
|
@@ -3285,158 +3286,6 @@ function FormActionDialog(_a) {
|
|
3285
3286
|
}));
|
3286
3287
|
}
|
3287
3288
|
|
3288
|
-
const defaultErrorMsg = "Oops, something went wrong...";
|
3289
|
-
function nonNullValues(data) {
|
3290
|
-
var _a;
|
3291
|
-
if (data) {
|
3292
|
-
const nonNullData = Object.assign({}, data);
|
3293
|
-
for (const key in data) nonNullData[key] = (_a = nonNullData[key]) !== null && _a !== void 0 ? _a : "";
|
3294
|
-
return nonNullData;
|
3295
|
-
}
|
3296
|
-
return data;
|
3297
|
-
}
|
3298
|
-
function ItemEditDialog(_a) {
|
3299
|
-
var _b, _c, _d, _e;
|
3300
|
-
var {
|
3301
|
-
initialValues,
|
3302
|
-
itemLabel,
|
3303
|
-
queryId = "",
|
3304
|
-
queryKey,
|
3305
|
-
queryFetchFn,
|
3306
|
-
queryFetchOptions,
|
3307
|
-
querySaveFn,
|
3308
|
-
querySaveOptions,
|
3309
|
-
onSuccess,
|
3310
|
-
onFetchError,
|
3311
|
-
fetchErrorMsg = defaultErrorMsg,
|
3312
|
-
onSaveError,
|
3313
|
-
saveErrorMsg = defaultErrorMsg,
|
3314
|
-
fetchToFormData,
|
3315
|
-
formToQueryData,
|
3316
|
-
invalidateQueriesOnSuccess = true,
|
3317
|
-
invalidateQueryKey,
|
3318
|
-
retryText = "Retry",
|
3319
|
-
cancelLabel = "Cancel",
|
3320
|
-
saveLabel,
|
3321
|
-
size = "lg",
|
3322
|
-
title,
|
3323
|
-
form,
|
3324
|
-
show,
|
3325
|
-
onClose,
|
3326
|
-
formikProps
|
3327
|
-
} = _a,
|
3328
|
-
props = __rest$1(_a, ["initialValues", "itemLabel", "queryId", "queryKey", "queryFetchFn", "queryFetchOptions", "querySaveFn", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
|
3329
|
-
const {
|
3330
|
-
isInitialLoading,
|
3331
|
-
isFetching,
|
3332
|
-
data,
|
3333
|
-
isError,
|
3334
|
-
error /*, error*/,
|
3335
|
-
refetch
|
3336
|
-
} = useApiQuery(queryKey, queryFetchFn, queryId, Object.assign({
|
3337
|
-
enabled: !( /*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
|
3338
|
-
onError: onFetchError
|
3339
|
-
}, queryFetchOptions));
|
3340
|
-
// const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
|
3341
|
-
// const [showTab, setShowTab] = React.useState(true);
|
3342
|
-
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(querySaveFn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : queryKey, querySaveOptions) : useApiMutation(querySaveFn, queryKey, queryId, querySaveOptions);
|
3343
|
-
const retry = React.useCallback(() => refetch(), [refetch]);
|
3344
|
-
const saveItem = React.useCallback((item, actions) => {
|
3345
|
-
// Clear mutation error if any
|
3346
|
-
mutation.reset();
|
3347
|
-
const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
|
3348
|
-
mutation.mutateAsync(formItem).then(response => {
|
3349
|
-
var _a;
|
3350
|
-
if (onSuccess) onSuccess(formItem, response);else toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
|
3351
|
-
// closing delete modal
|
3352
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
3353
|
-
}).catch(error => {
|
3354
|
-
var _a;
|
3355
|
-
console.error("on error", error);
|
3356
|
-
if (onSaveError) onSaveError(item);else toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
|
3357
|
-
actions.setSubmitting(false);
|
3358
|
-
});
|
3359
|
-
}, [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
3360
|
-
// const switchTab = React.useCallback((tab: string) =>
|
3361
|
-
// {
|
3362
|
-
// setActiveTab(tab);
|
3363
|
-
// setShowTab(false);
|
3364
|
-
// setTimeout(function ()
|
3365
|
-
// {
|
3366
|
-
// setActiveTab(tab);
|
3367
|
-
// setShowTab(true);
|
3368
|
-
// }, 150);
|
3369
|
-
// }, [setActiveTab])
|
3370
|
-
return jsxs(Modal, Object.assign({
|
3371
|
-
size: size,
|
3372
|
-
show: show,
|
3373
|
-
onClose: onClose,
|
3374
|
-
scheme: "light",
|
3375
|
-
transition: true
|
3376
|
-
}, props, {
|
3377
|
-
children: [jsxs(Modal.Header, {
|
3378
|
-
children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_c = (_b = data === null || data === void 0 ? void 0 : data["name"]) !== null && _b !== void 0 ? _b : data === null || data === void 0 ? void 0 : data["title"]) !== null && _c !== void 0 ? _c : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form) && jsx(Fragment, {})
|
3379
|
-
// <ul className="nav nav-bold nav-pills">
|
3380
|
-
// {form.map(item =>
|
3381
|
-
// <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
|
3382
|
-
// <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
|
3383
|
-
// </li>
|
3384
|
-
// )}
|
3385
|
-
// </ul>
|
3386
|
-
]
|
3387
|
-
}), isInitialLoading && jsx(Modal.Body, {
|
3388
|
-
children: jsx(QueryLoadingState, {
|
3389
|
-
minW: "72"
|
3390
|
-
})
|
3391
|
-
}), isError && jsx(Modal.Body, {
|
3392
|
-
children: jsx(RetryOnError, {
|
3393
|
-
label: `${fetchErrorMsg} ${error}`,
|
3394
|
-
onClick: retry
|
3395
|
-
})
|
3396
|
-
}), !isInitialLoading && !isError && jsx(Fragment, {
|
3397
|
-
children: jsx(Formik, Object.assign({
|
3398
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = (_d = nonNullValues(data)) !== null && _d !== void 0 ? _d : initialValues) !== null && _e !== void 0 ? _e : {},
|
3399
|
-
onSubmit: saveItem
|
3400
|
-
}, formikProps, {
|
3401
|
-
children: ({
|
3402
|
-
setFieldValue,
|
3403
|
-
dirty,
|
3404
|
-
handleSubmit,
|
3405
|
-
isValid,
|
3406
|
-
values
|
3407
|
-
}) => jsxs(Fragment, {
|
3408
|
-
children: [jsx(Modal.Body, {
|
3409
|
-
pb: "6",
|
3410
|
-
children: jsxs(Form, {
|
3411
|
-
children: [/*#__PURE__*/React.isValidElement(form) && form, Array.isArray(form) && jsx(FormRenderer, {
|
3412
|
-
form: form
|
3413
|
-
}), isFunction(form) && jsx(FormRenderer, {
|
3414
|
-
form: form(data !== null && data !== void 0 ? data : values)
|
3415
|
-
})]
|
3416
|
-
})
|
3417
|
-
}), jsxs(Modal.Footer, {
|
3418
|
-
dflex: true,
|
3419
|
-
placeContent: "end",
|
3420
|
-
spaceX: "3",
|
3421
|
-
children: [jsx(Button, {
|
3422
|
-
disabled: mutation.isLoading,
|
3423
|
-
onClick: onClose,
|
3424
|
-
variant: "borderless",
|
3425
|
-
me: "2",
|
3426
|
-
children: cancelLabel
|
3427
|
-
}), jsx(Button, {
|
3428
|
-
type: "submit",
|
3429
|
-
disabled: !dirty || mutation.isLoading /* || !isValid*/,
|
3430
|
-
onClick: () => handleSubmit(),
|
3431
|
-
children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
|
3432
|
-
})]
|
3433
|
-
})]
|
3434
|
-
})
|
3435
|
-
}))
|
3436
|
-
}), mutation.isLoading && jsx(ModalLoadingOverlay, {})]
|
3437
|
-
}));
|
3438
|
-
}
|
3439
|
-
|
3440
3289
|
function PageSectionTitle(_a) {
|
3441
3290
|
var {
|
3442
3291
|
children
|
@@ -3677,4 +3526,4 @@ function TableRowPublishPostButton(_a) {
|
|
3677
3526
|
}, props));
|
3678
3527
|
}
|
3679
3528
|
|
3680
|
-
export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, DialogButton, FormActionDialog, InvalidateButton, ItemEditDialog, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
|
3529
|
+
export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, DialogButton, FormActionDialog, InvalidateButton, ItemDeleteDialog, ItemEditDialog, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
@@ -7,21 +7,22 @@ export * from "./lib/buttons/PublishButton";
|
|
7
7
|
export * from "./lib/buttons/UpdateButton";
|
8
8
|
export * from "./lib/buttons/ViewButton";
|
9
9
|
export * from "./lib/cells/OrderCell";
|
10
|
-
export * from "./lib/json/
|
11
|
-
export * from "./lib/json/
|
12
|
-
export * from "./lib/json/
|
13
|
-
export * from "./lib/json/types/TabbedView";
|
10
|
+
export * from "./lib/json/ScreenRenderer";
|
11
|
+
export * from "./lib/json/dialog/ItemEditDialog";
|
12
|
+
export * from "./lib/json/dialog/ItemDeleteDialog";
|
14
13
|
export * from "./lib/json/types/DetailsView";
|
14
|
+
export * from "./lib/json/types/EditItemDialog";
|
15
|
+
export * from "./lib/json/types/MultiQueryWrapper";
|
15
16
|
export * from "./lib/json/types/QueryWrapper";
|
16
17
|
export * from "./lib/json/types/QueryWrapperDialog";
|
17
|
-
export * from "./lib/json/types/
|
18
|
-
export * from "./lib/json/
|
18
|
+
export * from "./lib/json/types/ScreenConfig";
|
19
|
+
export * from "./lib/json/types/TabbedView";
|
20
|
+
export * from "./lib/json/types/TableView";
|
19
21
|
export * from "./lib/layout/AdminLayout";
|
20
22
|
export * from "./lib/layout/ButtonBar";
|
21
23
|
export { MenuConfig } from "./lib/layout/Menu";
|
22
24
|
export * from "./lib/modal/AttachDialog";
|
23
25
|
export * from "./lib/modal/FormActionDialog";
|
24
|
-
export * from "./lib/modal/ItemEditDialog";
|
25
26
|
export * from "./lib/page/PageContainer";
|
26
27
|
export * from "./lib/page/PageContentEditor";
|
27
28
|
export * from "./lib/page/PageMain";
|
@@ -1,12 +1,14 @@
|
|
1
|
-
/// <reference types="react" />
|
2
1
|
import { DialogButtonProps } from "../buttons/DialogButton";
|
3
2
|
import { ParentComponent, SoperioComponent } from "@soperio/react";
|
4
3
|
import { ButtonProps } from "@valerya/ui";
|
4
|
+
import React from "react";
|
5
5
|
export declare function ButtonBar({ children, ...props }: ParentComponent & SoperioComponent): JSX.Element;
|
6
6
|
export type ButtonBarButtonProps = {
|
7
7
|
icon?: string;
|
8
8
|
} & ButtonProps;
|
9
|
-
export declare
|
9
|
+
export declare const ButtonBarButton: React.ForwardRefExoticComponent<{
|
10
|
+
icon?: string | undefined;
|
11
|
+
} & ButtonProps & React.RefAttributes<HTMLDivElement>>;
|
10
12
|
export type ButtonBarDialogButtonProps = {
|
11
13
|
icon?: string;
|
12
14
|
} & DialogButtonProps;
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import { FormRendererConfig } from "@compill/form";
|
2
|
-
import { UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
3
|
-
import { ModalProps } from "@valerya/ui";
|
4
|
-
import { FormikConfig } from "formik";
|
5
|
-
import React from "react";
|
6
|
-
export interface ItemEditDialogProps<TFormData extends {} = any, TResultData extends {} = any> extends Omit<ModalProps, "id" | "children" | "title" | "position"> {
|
7
|
-
itemLabel?: string;
|
8
|
-
queryId?: string;
|
9
|
-
queryKey: string[];
|
10
|
-
initialValues?: any;
|
11
|
-
queryFetchFn: (...args: any[]) => Promise<TResultData>;
|
12
|
-
queryFetchOptions?: UseQueryOptions;
|
13
|
-
querySaveFn: (item: TFormData) => Promise<TResultData>;
|
14
|
-
querySaveOptions?: UseMutationOptions<TResultData, unknown, TFormData>;
|
15
|
-
onSuccess?: (item: TResultData, response: any) => void;
|
16
|
-
onFetchError?: () => void;
|
17
|
-
fetchErrorMsg?: string;
|
18
|
-
onSaveError?: (item: TFormData) => void;
|
19
|
-
saveErrorMsg?: string;
|
20
|
-
fetchToFormData?: (item: TResultData) => TFormData;
|
21
|
-
formToQueryData?: (TFormData: any) => Partial<TResultData>;
|
22
|
-
invalidateQueriesOnSuccess?: boolean;
|
23
|
-
invalidateQueryKey?: string[];
|
24
|
-
retryText?: string;
|
25
|
-
cancelLabel?: string;
|
26
|
-
saveLabel?: string;
|
27
|
-
title?: ((item?: TResultData) => string);
|
28
|
-
formikProps: Omit<FormikConfig<any>, "initialValues" | "onSubmit">;
|
29
|
-
form: React.ReactNode | FormRendererConfig | ((item: TResultData) => FormRendererConfig);
|
30
|
-
show: boolean;
|
31
|
-
onClose: () => void;
|
32
|
-
}
|
33
|
-
export declare function ItemEditDialog<TFormData extends {}, TResultData extends {}>({ initialValues, itemLabel, queryId, queryKey, queryFetchFn, queryFetchOptions, querySaveFn, querySaveOptions, onSuccess, onFetchError, fetchErrorMsg, onSaveError, saveErrorMsg, fetchToFormData, formToQueryData, invalidateQueriesOnSuccess, invalidateQueryKey, retryText, cancelLabel, saveLabel, size, title, form, show, onClose, formikProps, ...props }: ItemEditDialogProps<TFormData, TResultData>): JSX.Element;
|