@compill/admin 1.0.49 → 1.0.50
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 +997 -966
- package/index.esm.js +995 -964
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/lib/buttons/InvalidateButton.d.ts +2 -2
- package/src/lib/json/table/RefreshButton.d.ts +4 -0
- package/src/lib/layout/ButtonBar.d.ts +8 -0
- package/src/lib/layout/PageTitleBar.d.ts +7 -0
package/index.esm.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { jsx, jsxs, Fragment } from '@soperio/jsx-runtime';
|
2
|
-
import { Icon, Button, IconButton, Container, Tile, Popover,
|
2
|
+
import { Icon, Button, IconButton, Container, Tile, Popover, Collapse, Modal, Checkbox, Badge } from '@valerya/ui';
|
3
3
|
import Link from 'next/link';
|
4
4
|
import React, { useRef, useCallback, useContext as useContext$2, useLayoutEffect, useEffect, createContext } from 'react';
|
5
5
|
import { INVALIDATE_API } from '@compill/admin-api';
|
@@ -152,6 +152,41 @@ function DialogButton(_a) {
|
|
152
152
|
});
|
153
153
|
}
|
154
154
|
|
155
|
+
function ButtonBar(_a) {
|
156
|
+
var {
|
157
|
+
children
|
158
|
+
} = _a,
|
159
|
+
props = __rest$1(_a, ["children"]);
|
160
|
+
return jsx("div", Object.assign({
|
161
|
+
dflex: true,
|
162
|
+
border: "1px",
|
163
|
+
borderColor: "zinc-200",
|
164
|
+
divideX: "1px",
|
165
|
+
divideColor: "zinc-200",
|
166
|
+
rounded: "lg",
|
167
|
+
overflow: "hidden"
|
168
|
+
}, props, {
|
169
|
+
children: children
|
170
|
+
}));
|
171
|
+
}
|
172
|
+
function ButtonBarButton(_a) {
|
173
|
+
var {
|
174
|
+
icon,
|
175
|
+
children
|
176
|
+
} = _a,
|
177
|
+
props = __rest$1(_a, ["icon", "children"]);
|
178
|
+
return jsxs(Button, Object.assign({
|
179
|
+
scheme: "dark",
|
180
|
+
size: "sm",
|
181
|
+
aspectRatio: icon && !children ? "square" : undefined,
|
182
|
+
variant: "borderless"
|
183
|
+
}, props, {
|
184
|
+
children: [icon && jsx(Icon, {
|
185
|
+
path: icon
|
186
|
+
}), children]
|
187
|
+
}));
|
188
|
+
}
|
189
|
+
|
155
190
|
function InvalidateButton(_a) {
|
156
191
|
var {
|
157
192
|
pathOrPermalink
|
@@ -162,12 +197,7 @@ function InvalidateButton(_a) {
|
|
162
197
|
const invalidate = useMutate(mutation, {
|
163
198
|
successMsg: "Page successfully invalidated"
|
164
199
|
});
|
165
|
-
return jsx(
|
166
|
-
scheme: "dark",
|
167
|
-
variant: "glass",
|
168
|
-
size: "md",
|
169
|
-
corners: "square",
|
170
|
-
aspectRatio: "square",
|
200
|
+
return jsx(ButtonBarButton, Object.assign({
|
171
201
|
title: "Regenerate",
|
172
202
|
disabled: mutation.isLoading,
|
173
203
|
onClick: invalidate,
|
@@ -1459,1004 +1489,1023 @@ function TableTopBar(_a) {
|
|
1459
1489
|
}));
|
1460
1490
|
}
|
1461
1491
|
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
return data;
|
1492
|
+
function compareValues(a, b, order) {
|
1493
|
+
if (a < b) {
|
1494
|
+
return order === 'asc' ? -1 : 1;
|
1495
|
+
}
|
1496
|
+
if (a > b) {
|
1497
|
+
return order === 'asc' ? 1 : -1;
|
1498
|
+
}
|
1499
|
+
return 0;
|
1471
1500
|
}
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
invalidateQueriesOnSuccess = true,
|
1489
|
-
invalidateQueryKey,
|
1490
|
-
retryText = "Retry",
|
1491
|
-
cancelLabel = "Cancel",
|
1492
|
-
saveLabel,
|
1493
|
-
size = "lg",
|
1494
|
-
title,
|
1495
|
-
form,
|
1496
|
-
show,
|
1497
|
-
onClose,
|
1498
|
-
formikProps
|
1499
|
-
} = _a,
|
1500
|
-
props = __rest$1(_a, ["initialValues", "itemLabel", "queryId", "api", "queryFetchOptions", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
|
1501
|
-
const {
|
1502
|
-
isInitialLoading,
|
1503
|
-
isFetching,
|
1504
|
-
data,
|
1505
|
-
isError,
|
1506
|
-
error /*, error*/,
|
1507
|
-
refetch
|
1508
|
-
} = useApiQuery(api.queryKey, api.get, queryId, Object.assign({
|
1509
|
-
enabled: !( /*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
|
1510
|
-
onError: onFetchError
|
1511
|
-
}, queryFetchOptions));
|
1512
|
-
// const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
|
1513
|
-
// const [showTab, setShowTab] = React.useState(true);
|
1514
|
-
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(api.upsert, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey, querySaveOptions) : useApiMutation(api.upsert, api.queryKey, queryId, querySaveOptions);
|
1515
|
-
const retry = React.useCallback(() => refetch(), [refetch]);
|
1516
|
-
const saveItem = React.useCallback((item, actions) => __awaiter(this, void 0, void 0, function* () {
|
1517
|
-
// Clear mutation error if any
|
1518
|
-
mutation.reset();
|
1519
|
-
const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
|
1520
|
-
yield mutation.mutateAsync(formItem).then(response => {
|
1521
|
-
var _a;
|
1522
|
-
if (onSuccess) onSuccess(formItem, response);else toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
|
1523
|
-
// closing delete modal
|
1524
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
1525
|
-
}).catch(error => {
|
1526
|
-
var _a;
|
1527
|
-
console.error("on error", error);
|
1528
|
-
if (onSaveError) onSaveError(item);else toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
|
1529
|
-
actions.setSubmitting(false);
|
1501
|
+
|
1502
|
+
function orderBy(arr, criteria, orders) {
|
1503
|
+
return arr.slice().sort((a, b) => {
|
1504
|
+
const ordersLength = orders.length;
|
1505
|
+
for (let i = 0; i < criteria.length; i++) {
|
1506
|
+
const order = ordersLength > i ? orders[i] : orders[ordersLength - 1];
|
1507
|
+
const criterion = criteria[i];
|
1508
|
+
const criterionIsFunction = typeof criterion === 'function';
|
1509
|
+
const valueA = criterionIsFunction ? criterion(a) : a[criterion];
|
1510
|
+
const valueB = criterionIsFunction ? criterion(b) : b[criterion];
|
1511
|
+
const result = compareValues(valueA, valueB, order);
|
1512
|
+
if (result !== 0) {
|
1513
|
+
return result;
|
1514
|
+
}
|
1515
|
+
}
|
1516
|
+
return 0;
|
1530
1517
|
});
|
1531
|
-
}), [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
1532
|
-
// const switchTab = React.useCallback((tab: string) =>
|
1533
|
-
// {
|
1534
|
-
// setActiveTab(tab);
|
1535
|
-
// setShowTab(false);
|
1536
|
-
// setTimeout(function ()
|
1537
|
-
// {
|
1538
|
-
// setActiveTab(tab);
|
1539
|
-
// setShowTab(true);
|
1540
|
-
// }, 150);
|
1541
|
-
// }, [setActiveTab])
|
1542
|
-
return jsxs(Modal, Object.assign({
|
1543
|
-
size: size,
|
1544
|
-
show: show,
|
1545
|
-
onClose: onClose,
|
1546
|
-
scheme: "light",
|
1547
|
-
transition: true
|
1548
|
-
}, props, {
|
1549
|
-
children: [jsxs(Modal.Header, {
|
1550
|
-
children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_d = (_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 : data === null || data === void 0 ? void 0 : data["name"]) !== null && _d !== void 0 ? _d : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form) && jsx(Fragment, {})
|
1551
|
-
// <ul className="nav nav-bold nav-pills">
|
1552
|
-
// {form.map(item =>
|
1553
|
-
// <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
|
1554
|
-
// <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
|
1555
|
-
// </li>
|
1556
|
-
// )}
|
1557
|
-
// </ul>
|
1558
|
-
]
|
1559
|
-
}), isInitialLoading && jsx(Modal.Body, {
|
1560
|
-
children: jsx(QueryLoadingState, {
|
1561
|
-
minW: "72"
|
1562
|
-
})
|
1563
|
-
}), isError && jsx(Modal.Body, {
|
1564
|
-
children: jsx(RetryOnError, {
|
1565
|
-
label: `${fetchErrorMsg} ${error}`,
|
1566
|
-
onClick: retry
|
1567
|
-
})
|
1568
|
-
}), !isInitialLoading && !isError && jsx(Fragment, {
|
1569
|
-
children: jsx(Formik
|
1570
|
-
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
1571
|
-
, Object.assign({
|
1572
|
-
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
1573
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues$1(data)) : (_e = nonNullValues$1(initialValues(data))) !== null && _e !== void 0 ? _e : {},
|
1574
|
-
onSubmit: saveItem
|
1575
|
-
}, formikProps, {
|
1576
|
-
children: ({
|
1577
|
-
setFieldValue,
|
1578
|
-
dirty,
|
1579
|
-
handleSubmit,
|
1580
|
-
isValid,
|
1581
|
-
values
|
1582
|
-
}) => jsxs(Fragment, {
|
1583
|
-
children: [jsx(Modal.Body, {
|
1584
|
-
pb: "6",
|
1585
|
-
children: jsxs(Form, {
|
1586
|
-
children: [/*#__PURE__*/React.isValidElement(form) && form, Array.isArray(form) && jsx(FormRenderer, {
|
1587
|
-
form: form
|
1588
|
-
}), isFunction(form) && jsx(FormRenderer, {
|
1589
|
-
form: form(data !== null && data !== void 0 ? data : values)
|
1590
|
-
})]
|
1591
|
-
})
|
1592
|
-
}), jsxs(Modal.Footer, {
|
1593
|
-
dflex: true,
|
1594
|
-
placeContent: "end",
|
1595
|
-
spaceX: "3",
|
1596
|
-
children: [jsx(Button, {
|
1597
|
-
disabled: mutation.isLoading,
|
1598
|
-
onClick: onClose,
|
1599
|
-
variant: "borderless",
|
1600
|
-
me: "2",
|
1601
|
-
children: cancelLabel
|
1602
|
-
}), jsx(Button, {
|
1603
|
-
type: "submit",
|
1604
|
-
disabled: !dirty || mutation.isLoading /* || !isValid*/,
|
1605
|
-
onClick: () => handleSubmit(),
|
1606
|
-
children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
|
1607
|
-
})]
|
1608
|
-
})]
|
1609
|
-
})
|
1610
|
-
}))
|
1611
|
-
}), mutation.isLoading && jsx(ModalLoadingOverlay, {})]
|
1612
|
-
}));
|
1613
1518
|
}
|
1614
1519
|
|
1615
|
-
function
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
}
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
retryOnMount: false,
|
1629
|
-
refetchOnMount: false,
|
1630
|
-
refetchOnWindowFocus: false
|
1631
|
-
});
|
1632
|
-
const transformedData = React.useMemo(() => {
|
1633
|
-
if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
|
1634
|
-
if (!transformFn) console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
|
1635
|
-
// @ts-ignore
|
1636
|
-
return transformFn === null || transformFn === void 0 ? void 0 : transformFn(data);
|
1520
|
+
function sortBy(arr, criteria) {
|
1521
|
+
return orderBy(arr, criteria, ['asc']);
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
function noop() { }
|
1525
|
+
|
1526
|
+
function getSymbols(object) {
|
1527
|
+
return Object.getOwnPropertySymbols(object).filter(symbol => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
1528
|
+
}
|
1529
|
+
|
1530
|
+
function getTag(value) {
|
1531
|
+
if (value == null) {
|
1532
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
1637
1533
|
}
|
1638
|
-
return
|
1639
|
-
}, [data, fn, transformFn]);
|
1640
|
-
if (isFetching) return null;
|
1641
|
-
// @ts-ignore
|
1642
|
-
return jsx(ItemEditDialog$1, Object.assign({}, config(transformedData), {
|
1643
|
-
queryId: queryId,
|
1644
|
-
invalidateQueryKey: invalidateQueryKey,
|
1645
|
-
show: true,
|
1646
|
-
onClose: onClose
|
1647
|
-
}));
|
1534
|
+
return Object.prototype.toString.call(value);
|
1648
1535
|
}
|
1649
1536
|
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1537
|
+
const regexpTag = '[object RegExp]';
|
1538
|
+
const stringTag = '[object String]';
|
1539
|
+
const numberTag = '[object Number]';
|
1540
|
+
const booleanTag = '[object Boolean]';
|
1541
|
+
const argumentsTag = '[object Arguments]';
|
1542
|
+
const symbolTag = '[object Symbol]';
|
1543
|
+
const dateTag = '[object Date]';
|
1544
|
+
const mapTag = '[object Map]';
|
1545
|
+
const setTag = '[object Set]';
|
1546
|
+
const arrayTag = '[object Array]';
|
1547
|
+
const functionTag = '[object Function]';
|
1548
|
+
const arrayBufferTag = '[object ArrayBuffer]';
|
1549
|
+
const objectTag = '[object Object]';
|
1550
|
+
const errorTag = '[object Error]';
|
1551
|
+
const dataViewTag = '[object DataView]';
|
1552
|
+
const uint8ArrayTag = '[object Uint8Array]';
|
1553
|
+
const uint8ClampedArrayTag = '[object Uint8ClampedArray]';
|
1554
|
+
const uint16ArrayTag = '[object Uint16Array]';
|
1555
|
+
const uint32ArrayTag = '[object Uint32Array]';
|
1556
|
+
const bigUint64ArrayTag = '[object BigUint64Array]';
|
1557
|
+
const int8ArrayTag = '[object Int8Array]';
|
1558
|
+
const int16ArrayTag = '[object Int16Array]';
|
1559
|
+
const int32ArrayTag = '[object Int32Array]';
|
1560
|
+
const bigInt64ArrayTag = '[object BigInt64Array]';
|
1561
|
+
const float32ArrayTag = '[object Float32Array]';
|
1562
|
+
const float64ArrayTag = '[object Float64Array]';
|
1563
|
+
|
1564
|
+
function isPlainObject(value) {
|
1565
|
+
if (!value || typeof value !== 'object') {
|
1566
|
+
return false;
|
1667
1567
|
}
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
// So instead, add a isPreloading and isPreloadingError to ItemEditDialog to handle the cases
|
1677
|
-
// if (isFetching)
|
1678
|
-
// return null
|
1679
|
-
// @ts-ignore
|
1680
|
-
return jsx(ItemEditDialog$1, Object.assign({
|
1681
|
-
isPreloading: isFetching
|
1682
|
-
}, config(...transformedData), {
|
1683
|
-
queryId: queryId,
|
1684
|
-
invalidateQueryKey: invalidateQueryKey,
|
1685
|
-
show: true,
|
1686
|
-
onClose: onClose
|
1687
|
-
}));
|
1568
|
+
const proto = Object.getPrototypeOf(value);
|
1569
|
+
const hasObjectPrototype = proto === null ||
|
1570
|
+
proto === Object.prototype ||
|
1571
|
+
Object.getPrototypeOf(proto) === null;
|
1572
|
+
if (!hasObjectPrototype) {
|
1573
|
+
return false;
|
1574
|
+
}
|
1575
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
1688
1576
|
}
|
1689
1577
|
|
1690
|
-
function
|
1691
|
-
|
1692
|
-
onClose,
|
1693
|
-
invalidateQueryKey,
|
1694
|
-
queryId
|
1695
|
-
}) {
|
1696
|
-
const props = __rest$1(config, ["type"]);
|
1697
|
-
if (config.type === "dialog") return jsx(ItemEditDialog$1, Object.assign({}, props, {
|
1698
|
-
queryId: queryId,
|
1699
|
-
invalidateQueryKey: invalidateQueryKey,
|
1700
|
-
show: true,
|
1701
|
-
onClose: onClose
|
1702
|
-
}));
|
1703
|
-
if (config.type === "query") return jsx(QueryWrapperDialog, Object.assign({}, props, {
|
1704
|
-
queryId: queryId,
|
1705
|
-
invalidateQueryKey: invalidateQueryKey,
|
1706
|
-
onClose: onClose
|
1707
|
-
}));
|
1708
|
-
if (config.type === "multiQuery") return jsx(MultiQueryWrapperDialog, Object.assign({}, props, {
|
1709
|
-
queryId: queryId,
|
1710
|
-
invalidateQueryKey: invalidateQueryKey,
|
1711
|
-
onClose: onClose
|
1712
|
-
}));
|
1713
|
-
return null;
|
1578
|
+
function eq(value, other) {
|
1579
|
+
return value === other || (Number.isNaN(value) && Number.isNaN(other));
|
1714
1580
|
}
|
1715
1581
|
|
1716
|
-
function
|
1717
|
-
|
1718
|
-
itemLabel,
|
1719
|
-
queryId = "",
|
1720
|
-
api,
|
1721
|
-
invalidateQueriesOnSuccess = true,
|
1722
|
-
invalidateQueryKey,
|
1723
|
-
size = "lg",
|
1724
|
-
show,
|
1725
|
-
onClose
|
1726
|
-
} = _a,
|
1727
|
-
props = __rest$1(_a, ["itemLabel", "queryId", "api", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "show", "onClose"]);
|
1728
|
-
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(api.delete, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey) : useApiMutation(api.upsert, api.queryKey);
|
1729
|
-
const mutate = useMutate(mutation, {
|
1730
|
-
onSuccess: () => onClose === null || onClose === void 0 ? void 0 : onClose()
|
1731
|
-
});
|
1732
|
-
const handleDelete = React.useCallback(() => mutate(queryId), [mutate, queryId]);
|
1733
|
-
return jsxs(Modal, Object.assign({
|
1734
|
-
size: size,
|
1735
|
-
show: show,
|
1736
|
-
onClose: onClose,
|
1737
|
-
scheme: "danger",
|
1738
|
-
variant: "glass",
|
1739
|
-
transition: true
|
1740
|
-
}, props, {
|
1741
|
-
children: [jsx(Modal.Header, {
|
1742
|
-
children: `Delete ${itemLabel}`
|
1743
|
-
}), jsxs(Modal.Body, {
|
1744
|
-
pb: "6",
|
1745
|
-
children: ["Do you really want to delete ", itemLabel, "?"]
|
1746
|
-
}), jsxs(Modal.Footer, {
|
1747
|
-
dflex: true,
|
1748
|
-
placeContent: "end",
|
1749
|
-
spaceX: "3",
|
1750
|
-
children: [jsx(Button, {
|
1751
|
-
disabled: mutation.isLoading,
|
1752
|
-
onClick: onClose,
|
1753
|
-
variant: "borderless",
|
1754
|
-
scheme: "secondary",
|
1755
|
-
me: "2",
|
1756
|
-
children: "Cancel"
|
1757
|
-
}), jsx(Button, {
|
1758
|
-
scheme: "danger",
|
1759
|
-
disabled: mutation.isLoading,
|
1760
|
-
onClick: handleDelete,
|
1761
|
-
children: "Delete"
|
1762
|
-
})]
|
1763
|
-
}), mutation.isLoading && jsx(ModalLoadingOverlay, {})]
|
1764
|
-
}));
|
1582
|
+
function isEqualWith(a, b, areValuesEqual) {
|
1583
|
+
return isEqualWithImpl(a, b, undefined, undefined, undefined, undefined, areValuesEqual);
|
1765
1584
|
}
|
1766
|
-
|
1767
|
-
const
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
}
|
1790
|
-
case "edit":
|
1791
|
-
{
|
1792
|
-
if (editView.type == "customDialog") {
|
1793
|
-
setDialog(editView.render({
|
1794
|
-
show: true,
|
1795
|
-
onClose: onCloseDialog
|
1796
|
-
}));
|
1797
|
-
} else {
|
1798
|
-
setDialog(jsx(DialogRenderer, {
|
1799
|
-
onClose: onCloseDialog,
|
1800
|
-
config: editView,
|
1801
|
-
queryId: item.id,
|
1802
|
-
invalidateQueryKey: queryKey
|
1803
|
-
}));
|
1804
|
-
}
|
1805
|
-
break;
|
1806
|
-
}
|
1807
|
-
case "delete":
|
1808
|
-
{
|
1809
|
-
setDialog(jsx(ItemDeleteDialog, Object.assign({
|
1810
|
-
show: true,
|
1811
|
-
onClose: onCloseDialog,
|
1812
|
-
queryId: item.id,
|
1813
|
-
invalidateQueryKey: queryKey
|
1814
|
-
}, deleteItem, {
|
1815
|
-
itemLabel: runIfFn(deleteItem.itemLabel, item)
|
1816
|
-
})));
|
1817
|
-
// TODO
|
1818
|
-
// const { initialValues, ...props } = editItem!!
|
1819
|
-
// setDialog(<ItemEditDialog {...props} initialValues={runIfFn(initialValues, item)} show queryId={item?.id} onClose={onCloseDialog} />)
|
1820
|
-
break;
|
1585
|
+
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
|
1586
|
+
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
|
1587
|
+
if (result !== undefined) {
|
1588
|
+
return result;
|
1589
|
+
}
|
1590
|
+
if (typeof a === typeof b) {
|
1591
|
+
switch (typeof a) {
|
1592
|
+
case 'bigint':
|
1593
|
+
case 'string':
|
1594
|
+
case 'boolean':
|
1595
|
+
case 'symbol':
|
1596
|
+
case 'undefined': {
|
1597
|
+
return a === b;
|
1598
|
+
}
|
1599
|
+
case 'number': {
|
1600
|
+
return a === b || Object.is(a, b);
|
1601
|
+
}
|
1602
|
+
case 'function': {
|
1603
|
+
return a === b;
|
1604
|
+
}
|
1605
|
+
case 'object': {
|
1606
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
1607
|
+
}
|
1821
1608
|
}
|
1822
1609
|
}
|
1823
|
-
|
1824
|
-
const Provider = provider;
|
1825
|
-
const value = {
|
1826
|
-
dialog,
|
1827
|
-
onAction
|
1828
|
-
};
|
1829
|
-
return jsx(Provider, {
|
1830
|
-
value: value,
|
1831
|
-
children: children
|
1832
|
-
});
|
1610
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
1833
1611
|
}
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1612
|
+
function areObjectsEqual(a, b, stack, areValuesEqual) {
|
1613
|
+
if (Object.is(a, b)) {
|
1614
|
+
return true;
|
1615
|
+
}
|
1616
|
+
let aTag = getTag(a);
|
1617
|
+
let bTag = getTag(b);
|
1618
|
+
if (aTag === argumentsTag) {
|
1619
|
+
aTag = objectTag;
|
1620
|
+
}
|
1621
|
+
if (bTag === argumentsTag) {
|
1622
|
+
bTag = objectTag;
|
1623
|
+
}
|
1624
|
+
if (aTag !== bTag) {
|
1625
|
+
return false;
|
1626
|
+
}
|
1627
|
+
switch (aTag) {
|
1628
|
+
case stringTag:
|
1629
|
+
return a.toString() === b.toString();
|
1630
|
+
case numberTag: {
|
1631
|
+
const x = a.valueOf();
|
1632
|
+
const y = b.valueOf();
|
1633
|
+
return eq(x, y);
|
1634
|
+
}
|
1635
|
+
case booleanTag:
|
1636
|
+
case dateTag:
|
1637
|
+
case symbolTag:
|
1638
|
+
return Object.is(a.valueOf(), b.valueOf());
|
1639
|
+
case regexpTag: {
|
1640
|
+
return a.source === b.source && a.flags === b.flags;
|
1641
|
+
}
|
1642
|
+
case functionTag: {
|
1643
|
+
return a === b;
|
1644
|
+
}
|
1645
|
+
}
|
1646
|
+
stack = stack ?? new Map();
|
1647
|
+
const aStack = stack.get(a);
|
1648
|
+
const bStack = stack.get(b);
|
1649
|
+
if (aStack != null && bStack != null) {
|
1650
|
+
return aStack === b;
|
1651
|
+
}
|
1652
|
+
stack.set(a, b);
|
1653
|
+
stack.set(b, a);
|
1654
|
+
try {
|
1655
|
+
switch (aTag) {
|
1656
|
+
case mapTag: {
|
1657
|
+
if (a.size !== b.size) {
|
1658
|
+
return false;
|
1659
|
+
}
|
1660
|
+
for (const [key, value] of a.entries()) {
|
1661
|
+
if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) {
|
1662
|
+
return false;
|
1663
|
+
}
|
1664
|
+
}
|
1665
|
+
return true;
|
1666
|
+
}
|
1667
|
+
case setTag: {
|
1668
|
+
if (a.size !== b.size) {
|
1669
|
+
return false;
|
1670
|
+
}
|
1671
|
+
const aValues = Array.from(a.values());
|
1672
|
+
const bValues = Array.from(b.values());
|
1673
|
+
for (let i = 0; i < aValues.length; i++) {
|
1674
|
+
const aValue = aValues[i];
|
1675
|
+
const index = bValues.findIndex(bValue => {
|
1676
|
+
return isEqualWithImpl(aValue, bValue, undefined, a, b, stack, areValuesEqual);
|
1677
|
+
});
|
1678
|
+
if (index === -1) {
|
1679
|
+
return false;
|
1680
|
+
}
|
1681
|
+
bValues.splice(index, 1);
|
1682
|
+
}
|
1683
|
+
return true;
|
1684
|
+
}
|
1685
|
+
case arrayTag:
|
1686
|
+
case uint8ArrayTag:
|
1687
|
+
case uint8ClampedArrayTag:
|
1688
|
+
case uint16ArrayTag:
|
1689
|
+
case uint32ArrayTag:
|
1690
|
+
case bigUint64ArrayTag:
|
1691
|
+
case int8ArrayTag:
|
1692
|
+
case int16ArrayTag:
|
1693
|
+
case int32ArrayTag:
|
1694
|
+
case bigInt64ArrayTag:
|
1695
|
+
case float32ArrayTag:
|
1696
|
+
case float64ArrayTag: {
|
1697
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
1698
|
+
return false;
|
1699
|
+
}
|
1700
|
+
if (a.length !== b.length) {
|
1701
|
+
return false;
|
1702
|
+
}
|
1703
|
+
for (let i = 0; i < a.length; i++) {
|
1704
|
+
if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) {
|
1705
|
+
return false;
|
1706
|
+
}
|
1707
|
+
}
|
1708
|
+
return true;
|
1709
|
+
}
|
1710
|
+
case arrayBufferTag: {
|
1711
|
+
if (a.byteLength !== b.byteLength) {
|
1712
|
+
return false;
|
1713
|
+
}
|
1714
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
1715
|
+
}
|
1716
|
+
case dataViewTag: {
|
1717
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
1718
|
+
return false;
|
1719
|
+
}
|
1720
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
1721
|
+
}
|
1722
|
+
case errorTag: {
|
1723
|
+
return a.name === b.name && a.message === b.message;
|
1724
|
+
}
|
1725
|
+
case objectTag: {
|
1726
|
+
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) ||
|
1727
|
+
(isPlainObject(a) && isPlainObject(b));
|
1728
|
+
if (!areEqualInstances) {
|
1729
|
+
return false;
|
1730
|
+
}
|
1731
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
1732
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
1733
|
+
if (aKeys.length !== bKeys.length) {
|
1734
|
+
return false;
|
1735
|
+
}
|
1736
|
+
for (let i = 0; i < aKeys.length; i++) {
|
1737
|
+
const propKey = aKeys[i];
|
1738
|
+
const aProp = a[propKey];
|
1739
|
+
if (!Object.hasOwn(b, propKey)) {
|
1740
|
+
return false;
|
1741
|
+
}
|
1742
|
+
const bProp = b[propKey];
|
1743
|
+
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) {
|
1744
|
+
return false;
|
1745
|
+
}
|
1746
|
+
}
|
1747
|
+
return true;
|
1748
|
+
}
|
1749
|
+
default: {
|
1750
|
+
return false;
|
1751
|
+
}
|
1752
|
+
}
|
1753
|
+
}
|
1754
|
+
finally {
|
1755
|
+
stack.delete(a);
|
1756
|
+
stack.delete(b);
|
1757
|
+
}
|
1900
1758
|
}
|
1901
1759
|
|
1902
|
-
function
|
1903
|
-
|
1904
|
-
id,
|
1905
|
-
api,
|
1906
|
-
status,
|
1907
|
-
invalidateQueryKey
|
1908
|
-
} = _a,
|
1909
|
-
props = __rest$1(_a, ["id", "api", "status", "invalidateQueryKey"]);
|
1910
|
-
const isDraft = status == "draft";
|
1911
|
-
const mutation = useInvalidateParentMutation(isDraft ? api.publish : api.unpublish, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey, {
|
1912
|
-
networkMode: "always"
|
1913
|
-
});
|
1914
|
-
const publish = React.useCallback(event => {
|
1915
|
-
event === null || event === void 0 ? void 0 : event.preventDefault();
|
1916
|
-
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
1917
|
-
mutation.reset();
|
1918
|
-
mutation.mutateAsync(id).then(() => toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => toast.error(`Error: ${error}`));
|
1919
|
-
}, [mutation, id]);
|
1920
|
-
return jsx(Button, Object.assign({
|
1921
|
-
variant: "borderless",
|
1922
|
-
corners: "square",
|
1923
|
-
scheme: "dark",
|
1924
|
-
onClick: publish
|
1925
|
-
}, props, {
|
1926
|
-
children: jsx(Icon, {
|
1927
|
-
path: isDraft ? mdiPublish : mdiPublishOff,
|
1928
|
-
size: "sm"
|
1929
|
-
})
|
1930
|
-
}));
|
1760
|
+
function isEqual(a, b) {
|
1761
|
+
return isEqualWith(a, b, noop);
|
1931
1762
|
}
|
1932
1763
|
|
1933
|
-
function
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
queryKey
|
1764
|
+
function TableFilters({
|
1765
|
+
form,
|
1766
|
+
initialValues,
|
1767
|
+
schema,
|
1768
|
+
processInput
|
1939
1769
|
}) {
|
1940
|
-
const
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1770
|
+
const {
|
1771
|
+
showFilters
|
1772
|
+
} = useContext$1();
|
1773
|
+
const {
|
1774
|
+
getFilters,
|
1775
|
+
setFilters
|
1776
|
+
} = useTableContext();
|
1777
|
+
const handleSubmit = React.useCallback((values, actions) => {
|
1778
|
+
var _a;
|
1779
|
+
const params = (_a = processInput === null || processInput === void 0 ? void 0 : processInput(values)) !== null && _a !== void 0 ? _a : values;
|
1780
|
+
if (!isEqual(params, getFilters())) setFilters(params);
|
1781
|
+
// setFilters(processInput?.(values) ?? values)
|
1782
|
+
actions.setSubmitting(false);
|
1783
|
+
}, [setFilters, processInput]);
|
1784
|
+
const handleReset = React.useCallback(resetForm => {
|
1785
|
+
setFilters(initialValues);
|
1786
|
+
resetForm();
|
1787
|
+
}, [setFilters, initialValues]);
|
1788
|
+
React.useEffect(() => setFilters(initialValues), []);
|
1789
|
+
return jsx(Collapse, {
|
1790
|
+
in: showFilters,
|
1791
|
+
style: {
|
1792
|
+
overflow: showFilters ? "initial" : "hidden"
|
1793
|
+
},
|
1794
|
+
children: jsx("div", {
|
1795
|
+
p: "8",
|
1796
|
+
borderT: "px",
|
1797
|
+
borderB: "px",
|
1798
|
+
borderColor: "slate-100",
|
1799
|
+
children: jsx(FormProvider, {
|
1800
|
+
initialValues: mergeInitialFormValues(getFilters(), initialValues),
|
1801
|
+
onSubmit: handleSubmit,
|
1802
|
+
validationSchema: schema,
|
1803
|
+
enableReinitialize: true,
|
1804
|
+
children: props => jsxs("div", {
|
1805
|
+
dflex: true,
|
1806
|
+
gap: "3",
|
1807
|
+
placeContent: "start",
|
1808
|
+
children: [jsx(FormRenderer, {
|
1809
|
+
flexRow: true,
|
1810
|
+
w: "auto",
|
1811
|
+
form: form
|
1812
|
+
}), jsx(Buttons, {
|
1813
|
+
handleReset: () => handleReset(props.resetForm)
|
1814
|
+
})]
|
1961
1815
|
})
|
1962
|
-
})
|
1963
|
-
}
|
1816
|
+
})
|
1817
|
+
})
|
1964
1818
|
});
|
1965
1819
|
}
|
1966
|
-
function
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
props = __rest$1(_a, ["onClick"]);
|
1971
|
-
const handleClick = React.useCallback(event => {
|
1972
|
-
event === null || event === void 0 ? void 0 : event.preventDefault();
|
1973
|
-
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
1974
|
-
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
1975
|
-
}, [onClick]);
|
1976
|
-
return jsx(Button, Object.assign({
|
1820
|
+
function Buttons({
|
1821
|
+
handleReset
|
1822
|
+
}) {
|
1823
|
+
return jsxs("div", {
|
1977
1824
|
dflex: true,
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
}
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
"delete": "dark",
|
2002
|
-
"publish": "dark",
|
2003
|
-
"custom": "dark"
|
2004
|
-
};
|
2005
|
-
|
2006
|
-
function useTableProps(api, table, rowActions) {
|
2007
|
-
const navigate = useNavigate();
|
2008
|
-
const openLink = useOpenLink();
|
2009
|
-
const {
|
2010
|
-
onAction
|
2011
|
-
} = useContext();
|
2012
|
-
const {
|
2013
|
-
onRowClick,
|
2014
|
-
columns: c
|
2015
|
-
} = table,
|
2016
|
-
props = __rest$1(table, ["onRowClick", "columns"]);
|
2017
|
-
const onRowClickHandler = React.useCallback(item => {
|
2018
|
-
if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) === "navigate") navigate(runIfFn(onRowClick.path, item));else if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) == "link") openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${runIfFn(onRowClick.path, item)}`);
|
2019
|
-
}, [navigate, onRowClick]);
|
2020
|
-
const columns = React.useMemo(() => {
|
2021
|
-
const columns = table.columns.concat([]);
|
2022
|
-
if (rowActions) {
|
2023
|
-
columns.push(createColumnHelper().display({
|
2024
|
-
id: "actions",
|
2025
|
-
header: "Actions",
|
2026
|
-
cell: props => jsx(TableRowActionsView, {
|
2027
|
-
row: props.row,
|
2028
|
-
onAction: onAction,
|
2029
|
-
rowActions: rowActions,
|
2030
|
-
api: api,
|
2031
|
-
queryKey: api.queryKey
|
2032
|
-
})
|
2033
|
-
}));
|
2034
|
-
}
|
2035
|
-
return columns;
|
2036
|
-
}, [table]);
|
2037
|
-
const tableProps = Object.assign({}, props);
|
2038
|
-
tableProps.columns = columns;
|
2039
|
-
tableProps.onRowClick = onRowClickHandler;
|
2040
|
-
tableProps.queryKey = api.queryKey;
|
2041
|
-
tableProps.queryFn = api.search;
|
2042
|
-
return tableProps;
|
1825
|
+
gap: "3",
|
1826
|
+
children: [jsxs("div", {
|
1827
|
+
dflex: true,
|
1828
|
+
flexCol: true,
|
1829
|
+
children: [jsx(FieldLabel, {
|
1830
|
+
name: "",
|
1831
|
+
label: "\u00A0"
|
1832
|
+
}), jsx(SubmitButton, {
|
1833
|
+
children: "Filter"
|
1834
|
+
})]
|
1835
|
+
}), jsxs("div", {
|
1836
|
+
dflex: true,
|
1837
|
+
flexCol: true,
|
1838
|
+
children: [jsx(FieldLabel, {
|
1839
|
+
name: "",
|
1840
|
+
label: "\u00A0"
|
1841
|
+
}), jsx(Button, {
|
1842
|
+
scheme: "neutral",
|
1843
|
+
onClick: handleReset,
|
1844
|
+
children: "Reset"
|
1845
|
+
})]
|
1846
|
+
})]
|
1847
|
+
});
|
2043
1848
|
}
|
2044
1849
|
|
2045
|
-
function
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
1850
|
+
function ActionButton$1({
|
1851
|
+
label,
|
1852
|
+
buttonProps,
|
1853
|
+
icon,
|
1854
|
+
queryKey,
|
1855
|
+
queryFn,
|
1856
|
+
successMsg,
|
1857
|
+
errorMsg,
|
1858
|
+
invalidateParent
|
1859
|
+
}) {
|
1860
|
+
const mutation = invalidateParent ? useInvalidateParentMutation(queryFn, queryKey) : useApiMutation(queryFn, queryKey);
|
1861
|
+
const mutate = useMutate(mutation, {
|
1862
|
+
successMsg,
|
1863
|
+
errorMsg
|
1864
|
+
});
|
1865
|
+
return jsxs(Button, Object.assign({
|
1866
|
+
display: "flex",
|
1867
|
+
alignItems: "center",
|
1868
|
+
gap: "3"
|
1869
|
+
}, buttonProps, {
|
1870
|
+
onClick: mutate,
|
1871
|
+
disabled: mutation.isLoading,
|
1872
|
+
children: [icon && jsx(Icon, {
|
1873
|
+
path: icon
|
1874
|
+
}), label]
|
1875
|
+
}));
|
2053
1876
|
}
|
2054
1877
|
|
2055
|
-
function
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
1878
|
+
function TableMassActions({
|
1879
|
+
actions
|
1880
|
+
}) {
|
1881
|
+
const {
|
1882
|
+
ids
|
1883
|
+
} = useTableContext();
|
1884
|
+
const showMassActions = ids && ids.length > 0;
|
1885
|
+
return jsx(Collapse, {
|
1886
|
+
in: showMassActions,
|
1887
|
+
style: {
|
1888
|
+
overflow: showMassActions ? "initial" : "hidden"
|
1889
|
+
},
|
1890
|
+
children: jsx("div", {
|
1891
|
+
dflex: true,
|
1892
|
+
gap: "3",
|
1893
|
+
flexWrap: true,
|
1894
|
+
alignItems: "center",
|
1895
|
+
px: "8",
|
1896
|
+
pt: "5",
|
1897
|
+
children: actions.map((action, index) => jsx("div", {
|
1898
|
+
children: action.type == "button" && !action.showConfirmationDialog && jsx(ActionButton$1, {
|
1899
|
+
label: action.label,
|
1900
|
+
queryFn: action.queryFn,
|
1901
|
+
queryKey: action.queryKey,
|
1902
|
+
buttonProps: action.buttonProps
|
1903
|
+
})
|
1904
|
+
}, index))
|
1905
|
+
})
|
1906
|
+
});
|
2071
1907
|
}
|
2072
1908
|
|
2073
|
-
|
2074
|
-
|
1909
|
+
const defaultErrorMsg$2 = "Oops, something went wrong...";
|
1910
|
+
function nonNullValues$1(data) {
|
1911
|
+
var _a;
|
1912
|
+
if (data) {
|
1913
|
+
const nonNullData = Object.assign({}, data);
|
1914
|
+
for (const key in data) nonNullData[key] = (_a = nonNullData[key]) !== null && _a !== void 0 ? _a : "";
|
1915
|
+
return nonNullData;
|
1916
|
+
}
|
1917
|
+
return data;
|
2075
1918
|
}
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
1919
|
+
function ItemEditDialog$1(_a) {
|
1920
|
+
var _b, _c, _d, _e;
|
1921
|
+
var {
|
1922
|
+
initialValues,
|
1923
|
+
itemLabel,
|
1924
|
+
queryId = "",
|
1925
|
+
api,
|
1926
|
+
queryFetchOptions,
|
1927
|
+
querySaveOptions,
|
1928
|
+
onSuccess,
|
1929
|
+
onFetchError,
|
1930
|
+
fetchErrorMsg = defaultErrorMsg$2,
|
1931
|
+
onSaveError,
|
1932
|
+
saveErrorMsg = defaultErrorMsg$2,
|
1933
|
+
fetchToFormData,
|
1934
|
+
formToQueryData,
|
1935
|
+
invalidateQueriesOnSuccess = true,
|
1936
|
+
invalidateQueryKey,
|
1937
|
+
retryText = "Retry",
|
1938
|
+
cancelLabel = "Cancel",
|
1939
|
+
saveLabel,
|
1940
|
+
size = "lg",
|
1941
|
+
title,
|
1942
|
+
form,
|
1943
|
+
show,
|
1944
|
+
onClose,
|
1945
|
+
formikProps
|
1946
|
+
} = _a,
|
1947
|
+
props = __rest$1(_a, ["initialValues", "itemLabel", "queryId", "api", "queryFetchOptions", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
|
1948
|
+
const {
|
1949
|
+
isInitialLoading,
|
1950
|
+
isFetching,
|
1951
|
+
data,
|
1952
|
+
isError,
|
1953
|
+
error /*, error*/,
|
1954
|
+
refetch
|
1955
|
+
} = useApiQuery(api.queryKey, api.get, queryId, Object.assign({
|
1956
|
+
enabled: !( /*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
|
1957
|
+
onError: onFetchError
|
1958
|
+
}, queryFetchOptions));
|
1959
|
+
// const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
|
1960
|
+
// const [showTab, setShowTab] = React.useState(true);
|
1961
|
+
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(api.upsert, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey, querySaveOptions) : useApiMutation(api.upsert, api.queryKey, queryId, querySaveOptions);
|
1962
|
+
const retry = React.useCallback(() => refetch(), [refetch]);
|
1963
|
+
const saveItem = React.useCallback((item, actions) => __awaiter(this, void 0, void 0, function* () {
|
1964
|
+
// Clear mutation error if any
|
1965
|
+
mutation.reset();
|
1966
|
+
const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
|
1967
|
+
yield mutation.mutateAsync(formItem).then(response => {
|
1968
|
+
var _a;
|
1969
|
+
if (onSuccess) onSuccess(formItem, response);else toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
|
1970
|
+
// closing delete modal
|
1971
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
1972
|
+
}).catch(error => {
|
1973
|
+
var _a;
|
1974
|
+
console.error("on error", error);
|
1975
|
+
if (onSaveError) onSaveError(item);else toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
|
1976
|
+
actions.setSubmitting(false);
|
1977
|
+
});
|
1978
|
+
}), [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
1979
|
+
// const switchTab = React.useCallback((tab: string) =>
|
1980
|
+
// {
|
1981
|
+
// setActiveTab(tab);
|
1982
|
+
// setShowTab(false);
|
1983
|
+
// setTimeout(function ()
|
1984
|
+
// {
|
1985
|
+
// setActiveTab(tab);
|
1986
|
+
// setShowTab(true);
|
1987
|
+
// }, 150);
|
1988
|
+
// }, [setActiveTab])
|
1989
|
+
return jsxs(Modal, Object.assign({
|
1990
|
+
size: size,
|
1991
|
+
show: show,
|
1992
|
+
onClose: onClose,
|
1993
|
+
scheme: "light",
|
1994
|
+
transition: true
|
1995
|
+
}, props, {
|
1996
|
+
children: [jsxs(Modal.Header, {
|
1997
|
+
children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_d = (_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 : data === null || data === void 0 ? void 0 : data["name"]) !== null && _d !== void 0 ? _d : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form) && jsx(Fragment, {})
|
1998
|
+
// <ul className="nav nav-bold nav-pills">
|
1999
|
+
// {form.map(item =>
|
2000
|
+
// <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
|
2001
|
+
// <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
|
2002
|
+
// </li>
|
2003
|
+
// )}
|
2004
|
+
// </ul>
|
2005
|
+
]
|
2006
|
+
}), isInitialLoading && jsx(Modal.Body, {
|
2007
|
+
children: jsx(QueryLoadingState, {
|
2008
|
+
minW: "72"
|
2009
|
+
})
|
2010
|
+
}), isError && jsx(Modal.Body, {
|
2011
|
+
children: jsx(RetryOnError, {
|
2012
|
+
label: `${fetchErrorMsg} ${error}`,
|
2013
|
+
onClick: retry
|
2014
|
+
})
|
2015
|
+
}), !isInitialLoading && !isError && jsx(Fragment, {
|
2016
|
+
children: jsx(Formik
|
2017
|
+
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2018
|
+
, Object.assign({
|
2019
|
+
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2020
|
+
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues$1(data)) : (_e = nonNullValues$1(initialValues(data))) !== null && _e !== void 0 ? _e : {},
|
2021
|
+
onSubmit: saveItem
|
2022
|
+
}, formikProps, {
|
2023
|
+
children: ({
|
2024
|
+
setFieldValue,
|
2025
|
+
dirty,
|
2026
|
+
handleSubmit,
|
2027
|
+
isValid,
|
2028
|
+
values
|
2029
|
+
}) => jsxs(Fragment, {
|
2030
|
+
children: [jsx(Modal.Body, {
|
2031
|
+
pb: "6",
|
2032
|
+
children: jsxs(Form, {
|
2033
|
+
children: [/*#__PURE__*/React.isValidElement(form) && form, Array.isArray(form) && jsx(FormRenderer, {
|
2034
|
+
form: form
|
2035
|
+
}), isFunction(form) && jsx(FormRenderer, {
|
2036
|
+
form: form(data !== null && data !== void 0 ? data : values)
|
2037
|
+
})]
|
2038
|
+
})
|
2039
|
+
}), jsxs(Modal.Footer, {
|
2040
|
+
dflex: true,
|
2041
|
+
placeContent: "end",
|
2042
|
+
spaceX: "3",
|
2043
|
+
children: [jsx(Button, {
|
2044
|
+
disabled: mutation.isLoading,
|
2045
|
+
onClick: onClose,
|
2046
|
+
variant: "borderless",
|
2047
|
+
me: "2",
|
2048
|
+
children: cancelLabel
|
2049
|
+
}), jsx(Button, {
|
2050
|
+
type: "submit",
|
2051
|
+
disabled: !dirty || mutation.isLoading /* || !isValid*/,
|
2052
|
+
onClick: () => handleSubmit(),
|
2053
|
+
children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
|
2054
|
+
})]
|
2055
|
+
})]
|
2056
|
+
})
|
2057
|
+
}))
|
2058
|
+
}), mutation.isLoading && jsx(ModalLoadingOverlay, {})]
|
2059
|
+
}));
|
2081
2060
|
}
|
2082
2061
|
|
2083
|
-
function
|
2084
|
-
|
2085
|
-
|
2062
|
+
function QueryWrapperDialog({
|
2063
|
+
api,
|
2064
|
+
fn,
|
2065
|
+
transformFn,
|
2066
|
+
config,
|
2067
|
+
onClose,
|
2068
|
+
queryId,
|
2069
|
+
invalidateQueryKey
|
2070
|
+
}) {
|
2071
|
+
const {
|
2072
|
+
data,
|
2073
|
+
isFetching
|
2074
|
+
} = useApiQuery(api.queryKey, fn === "get" || fn === "getTransformed" ? api.get : api.getAll, undefined, {
|
2075
|
+
retryOnMount: false,
|
2076
|
+
refetchOnMount: false,
|
2077
|
+
refetchOnWindowFocus: false
|
2078
|
+
});
|
2079
|
+
const transformedData = React.useMemo(() => {
|
2080
|
+
if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
|
2081
|
+
if (!transformFn) console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
|
2082
|
+
// @ts-ignore
|
2083
|
+
return transformFn === null || transformFn === void 0 ? void 0 : transformFn(data);
|
2086
2084
|
}
|
2087
|
-
return
|
2085
|
+
return data;
|
2086
|
+
}, [data, fn, transformFn]);
|
2087
|
+
if (isFetching) return null;
|
2088
|
+
// @ts-ignore
|
2089
|
+
return jsx(ItemEditDialog$1, Object.assign({}, config(transformedData), {
|
2090
|
+
queryId: queryId,
|
2091
|
+
invalidateQueryKey: invalidateQueryKey,
|
2092
|
+
show: true,
|
2093
|
+
onClose: onClose
|
2094
|
+
}));
|
2088
2095
|
}
|
2089
2096
|
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
const
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
const uint16ArrayTag = '[object Uint16Array]';
|
2108
|
-
const uint32ArrayTag = '[object Uint32Array]';
|
2109
|
-
const bigUint64ArrayTag = '[object BigUint64Array]';
|
2110
|
-
const int8ArrayTag = '[object Int8Array]';
|
2111
|
-
const int16ArrayTag = '[object Int16Array]';
|
2112
|
-
const int32ArrayTag = '[object Int32Array]';
|
2113
|
-
const bigInt64ArrayTag = '[object BigInt64Array]';
|
2114
|
-
const float32ArrayTag = '[object Float32Array]';
|
2115
|
-
const float64ArrayTag = '[object Float64Array]';
|
2116
|
-
|
2117
|
-
function isPlainObject(value) {
|
2118
|
-
if (!value || typeof value !== 'object') {
|
2119
|
-
return false;
|
2120
|
-
}
|
2121
|
-
const proto = Object.getPrototypeOf(value);
|
2122
|
-
const hasObjectPrototype = proto === null ||
|
2123
|
-
proto === Object.prototype ||
|
2124
|
-
Object.getPrototypeOf(proto) === null;
|
2125
|
-
if (!hasObjectPrototype) {
|
2126
|
-
return false;
|
2097
|
+
function MultiQueryWrapperDialog({
|
2098
|
+
queries,
|
2099
|
+
config,
|
2100
|
+
onClose,
|
2101
|
+
queryId,
|
2102
|
+
invalidateQueryKey
|
2103
|
+
}) {
|
2104
|
+
const {
|
2105
|
+
data,
|
2106
|
+
isFetching,
|
2107
|
+
isError
|
2108
|
+
} = useApiQueries(queries.map(q => ({
|
2109
|
+
queryKey: q.api.queryKey,
|
2110
|
+
queryFn: q.fn == "get" ? q.api.get : q.api.getAll,
|
2111
|
+
queryOptions: {
|
2112
|
+
cacheTime: q.cache === false ? 0 : undefined,
|
2113
|
+
staleTime: q.cache === false ? 0 : undefined
|
2127
2114
|
}
|
2128
|
-
|
2115
|
+
})));
|
2116
|
+
const transformedData = React.useMemo(() => {
|
2117
|
+
return data === null || data === void 0 ? void 0 : data.map((d, index) => {
|
2118
|
+
var _a, _b;
|
2119
|
+
return queries[index].transformFn ? (_b = (_a = queries[index]) === null || _a === void 0 ? void 0 : _a.transformFn) === null || _b === void 0 ? void 0 : _b.call(_a, d) : d;
|
2120
|
+
});
|
2121
|
+
}, [data, queries]);
|
2122
|
+
// TODO This is not really good
|
2123
|
+
// So instead, add a isPreloading and isPreloadingError to ItemEditDialog to handle the cases
|
2124
|
+
// if (isFetching)
|
2125
|
+
// return null
|
2126
|
+
// @ts-ignore
|
2127
|
+
return jsx(ItemEditDialog$1, Object.assign({
|
2128
|
+
isPreloading: isFetching
|
2129
|
+
}, config(...transformedData), {
|
2130
|
+
queryId: queryId,
|
2131
|
+
invalidateQueryKey: invalidateQueryKey,
|
2132
|
+
show: true,
|
2133
|
+
onClose: onClose
|
2134
|
+
}));
|
2129
2135
|
}
|
2130
2136
|
|
2131
|
-
function
|
2132
|
-
|
2137
|
+
function DialogRenderer({
|
2138
|
+
config,
|
2139
|
+
onClose,
|
2140
|
+
invalidateQueryKey,
|
2141
|
+
queryId
|
2142
|
+
}) {
|
2143
|
+
const props = __rest$1(config, ["type"]);
|
2144
|
+
if (config.type === "dialog") return jsx(ItemEditDialog$1, Object.assign({}, props, {
|
2145
|
+
queryId: queryId,
|
2146
|
+
invalidateQueryKey: invalidateQueryKey,
|
2147
|
+
show: true,
|
2148
|
+
onClose: onClose
|
2149
|
+
}));
|
2150
|
+
if (config.type === "query") return jsx(QueryWrapperDialog, Object.assign({}, props, {
|
2151
|
+
queryId: queryId,
|
2152
|
+
invalidateQueryKey: invalidateQueryKey,
|
2153
|
+
onClose: onClose
|
2154
|
+
}));
|
2155
|
+
if (config.type === "multiQuery") return jsx(MultiQueryWrapperDialog, Object.assign({}, props, {
|
2156
|
+
queryId: queryId,
|
2157
|
+
invalidateQueryKey: invalidateQueryKey,
|
2158
|
+
onClose: onClose
|
2159
|
+
}));
|
2160
|
+
return null;
|
2133
2161
|
}
|
2134
2162
|
|
2135
|
-
function
|
2136
|
-
|
2163
|
+
function RefreshButton({
|
2164
|
+
queryKey
|
2165
|
+
}) {
|
2166
|
+
const invalidate = useInvalidateQuery(queryKey);
|
2167
|
+
useHotkeys('ctrl+r', () => invalidate(), {
|
2168
|
+
preventDefault: true
|
2169
|
+
}, [invalidate]);
|
2170
|
+
return jsx(ButtonBarButton, {
|
2171
|
+
scheme: "dark",
|
2172
|
+
size: "sm",
|
2173
|
+
aspectRatio: "square",
|
2174
|
+
variant: "borderless",
|
2175
|
+
onClick: invalidate,
|
2176
|
+
children: jsx(Icon, {
|
2177
|
+
path: mdiRefresh
|
2178
|
+
})
|
2179
|
+
});
|
2137
2180
|
}
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2181
|
+
|
2182
|
+
function ItemDeleteDialog(_a) {
|
2183
|
+
var {
|
2184
|
+
itemLabel,
|
2185
|
+
queryId = "",
|
2186
|
+
api,
|
2187
|
+
invalidateQueriesOnSuccess = true,
|
2188
|
+
invalidateQueryKey,
|
2189
|
+
size = "lg",
|
2190
|
+
show,
|
2191
|
+
onClose
|
2192
|
+
} = _a,
|
2193
|
+
props = __rest$1(_a, ["itemLabel", "queryId", "api", "invalidateQueriesOnSuccess", "invalidateQueryKey", "size", "show", "onClose"]);
|
2194
|
+
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(api.delete, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey) : useApiMutation(api.upsert, api.queryKey);
|
2195
|
+
const mutate = useMutate(mutation, {
|
2196
|
+
onSuccess: () => onClose === null || onClose === void 0 ? void 0 : onClose()
|
2197
|
+
});
|
2198
|
+
const handleDelete = React.useCallback(() => mutate(queryId), [mutate, queryId]);
|
2199
|
+
return jsxs(Modal, Object.assign({
|
2200
|
+
size: size,
|
2201
|
+
show: show,
|
2202
|
+
onClose: onClose,
|
2203
|
+
scheme: "danger",
|
2204
|
+
variant: "glass",
|
2205
|
+
transition: true
|
2206
|
+
}, props, {
|
2207
|
+
children: [jsx(Modal.Header, {
|
2208
|
+
children: `Delete ${itemLabel}`
|
2209
|
+
}), jsxs(Modal.Body, {
|
2210
|
+
pb: "6",
|
2211
|
+
children: ["Do you really want to delete ", itemLabel, "?"]
|
2212
|
+
}), jsxs(Modal.Footer, {
|
2213
|
+
dflex: true,
|
2214
|
+
placeContent: "end",
|
2215
|
+
spaceX: "3",
|
2216
|
+
children: [jsx(Button, {
|
2217
|
+
disabled: mutation.isLoading,
|
2218
|
+
onClick: onClose,
|
2219
|
+
variant: "borderless",
|
2220
|
+
scheme: "secondary",
|
2221
|
+
me: "2",
|
2222
|
+
children: "Cancel"
|
2223
|
+
}), jsx(Button, {
|
2224
|
+
scheme: "danger",
|
2225
|
+
disabled: mutation.isLoading,
|
2226
|
+
onClick: handleDelete,
|
2227
|
+
children: "Delete"
|
2228
|
+
})]
|
2229
|
+
}), mutation.isLoading && jsx(ModalLoadingOverlay, {})]
|
2230
|
+
}));
|
2164
2231
|
}
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
case numberTag: {
|
2184
|
-
const x = a.valueOf();
|
2185
|
-
const y = b.valueOf();
|
2186
|
-
return eq(x, y);
|
2232
|
+
|
2233
|
+
const [provider, useContext] = createContext$1();
|
2234
|
+
function TableViewProvider({
|
2235
|
+
editView,
|
2236
|
+
deleteItem,
|
2237
|
+
queryKey,
|
2238
|
+
children
|
2239
|
+
}) {
|
2240
|
+
const openLink = useOpenLink();
|
2241
|
+
const navigate = useNavigate();
|
2242
|
+
const [dialog, setDialog] = React.useState(null);
|
2243
|
+
const onCloseDialog = React.useCallback(() => setDialog(null), [setDialog]);
|
2244
|
+
const onAction = React.useCallback((action, item) => {
|
2245
|
+
switch (action.type) {
|
2246
|
+
case "view":
|
2247
|
+
{
|
2248
|
+
navigate(runIfFn(action.path, item));
|
2249
|
+
break;
|
2187
2250
|
}
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
case regexpTag: {
|
2193
|
-
return a.source === b.source && a.flags === b.flags;
|
2251
|
+
case "link":
|
2252
|
+
{
|
2253
|
+
openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${runIfFn(action.path, item)}`);
|
2254
|
+
break;
|
2194
2255
|
}
|
2195
|
-
|
2196
|
-
|
2256
|
+
case "edit":
|
2257
|
+
{
|
2258
|
+
if (editView.type == "customDialog") {
|
2259
|
+
setDialog(editView.render({
|
2260
|
+
show: true,
|
2261
|
+
onClose: onCloseDialog
|
2262
|
+
}));
|
2263
|
+
} else {
|
2264
|
+
setDialog(jsx(DialogRenderer, {
|
2265
|
+
onClose: onCloseDialog,
|
2266
|
+
config: editView,
|
2267
|
+
queryId: item.id,
|
2268
|
+
invalidateQueryKey: queryKey
|
2269
|
+
}));
|
2270
|
+
}
|
2271
|
+
break;
|
2197
2272
|
}
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
}
|
2213
|
-
for (const [key, value] of a.entries()) {
|
2214
|
-
if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) {
|
2215
|
-
return false;
|
2216
|
-
}
|
2217
|
-
}
|
2218
|
-
return true;
|
2219
|
-
}
|
2220
|
-
case setTag: {
|
2221
|
-
if (a.size !== b.size) {
|
2222
|
-
return false;
|
2223
|
-
}
|
2224
|
-
const aValues = Array.from(a.values());
|
2225
|
-
const bValues = Array.from(b.values());
|
2226
|
-
for (let i = 0; i < aValues.length; i++) {
|
2227
|
-
const aValue = aValues[i];
|
2228
|
-
const index = bValues.findIndex(bValue => {
|
2229
|
-
return isEqualWithImpl(aValue, bValue, undefined, a, b, stack, areValuesEqual);
|
2230
|
-
});
|
2231
|
-
if (index === -1) {
|
2232
|
-
return false;
|
2233
|
-
}
|
2234
|
-
bValues.splice(index, 1);
|
2235
|
-
}
|
2236
|
-
return true;
|
2237
|
-
}
|
2238
|
-
case arrayTag:
|
2239
|
-
case uint8ArrayTag:
|
2240
|
-
case uint8ClampedArrayTag:
|
2241
|
-
case uint16ArrayTag:
|
2242
|
-
case uint32ArrayTag:
|
2243
|
-
case bigUint64ArrayTag:
|
2244
|
-
case int8ArrayTag:
|
2245
|
-
case int16ArrayTag:
|
2246
|
-
case int32ArrayTag:
|
2247
|
-
case bigInt64ArrayTag:
|
2248
|
-
case float32ArrayTag:
|
2249
|
-
case float64ArrayTag: {
|
2250
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(a) !== Buffer.isBuffer(b)) {
|
2251
|
-
return false;
|
2252
|
-
}
|
2253
|
-
if (a.length !== b.length) {
|
2254
|
-
return false;
|
2255
|
-
}
|
2256
|
-
for (let i = 0; i < a.length; i++) {
|
2257
|
-
if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) {
|
2258
|
-
return false;
|
2259
|
-
}
|
2260
|
-
}
|
2261
|
-
return true;
|
2262
|
-
}
|
2263
|
-
case arrayBufferTag: {
|
2264
|
-
if (a.byteLength !== b.byteLength) {
|
2265
|
-
return false;
|
2266
|
-
}
|
2267
|
-
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
2268
|
-
}
|
2269
|
-
case dataViewTag: {
|
2270
|
-
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) {
|
2271
|
-
return false;
|
2272
|
-
}
|
2273
|
-
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
2274
|
-
}
|
2275
|
-
case errorTag: {
|
2276
|
-
return a.name === b.name && a.message === b.message;
|
2277
|
-
}
|
2278
|
-
case objectTag: {
|
2279
|
-
const areEqualInstances = areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) ||
|
2280
|
-
(isPlainObject(a) && isPlainObject(b));
|
2281
|
-
if (!areEqualInstances) {
|
2282
|
-
return false;
|
2283
|
-
}
|
2284
|
-
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
2285
|
-
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
2286
|
-
if (aKeys.length !== bKeys.length) {
|
2287
|
-
return false;
|
2288
|
-
}
|
2289
|
-
for (let i = 0; i < aKeys.length; i++) {
|
2290
|
-
const propKey = aKeys[i];
|
2291
|
-
const aProp = a[propKey];
|
2292
|
-
if (!Object.hasOwn(b, propKey)) {
|
2293
|
-
return false;
|
2294
|
-
}
|
2295
|
-
const bProp = b[propKey];
|
2296
|
-
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) {
|
2297
|
-
return false;
|
2298
|
-
}
|
2299
|
-
}
|
2300
|
-
return true;
|
2301
|
-
}
|
2302
|
-
default: {
|
2303
|
-
return false;
|
2304
|
-
}
|
2273
|
+
case "delete":
|
2274
|
+
{
|
2275
|
+
setDialog(jsx(ItemDeleteDialog, Object.assign({
|
2276
|
+
show: true,
|
2277
|
+
onClose: onCloseDialog,
|
2278
|
+
queryId: item.id,
|
2279
|
+
invalidateQueryKey: queryKey
|
2280
|
+
}, deleteItem, {
|
2281
|
+
itemLabel: runIfFn(deleteItem.itemLabel, item)
|
2282
|
+
})));
|
2283
|
+
// TODO
|
2284
|
+
// const { initialValues, ...props } = editItem!!
|
2285
|
+
// setDialog(<ItemEditDialog {...props} initialValues={runIfFn(initialValues, item)} show queryId={item?.id} onClose={onCloseDialog} />)
|
2286
|
+
break;
|
2305
2287
|
}
|
2306
2288
|
}
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2289
|
+
}, [navigate, editView, deleteItem]);
|
2290
|
+
const Provider = provider;
|
2291
|
+
const value = {
|
2292
|
+
dialog,
|
2293
|
+
onAction
|
2294
|
+
};
|
2295
|
+
return jsx(Provider, {
|
2296
|
+
value: value,
|
2297
|
+
children: children
|
2298
|
+
});
|
2311
2299
|
}
|
2312
2300
|
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2301
|
+
/**
|
2302
|
+
* table-core
|
2303
|
+
*
|
2304
|
+
* Copyright (c) TanStack
|
2305
|
+
*
|
2306
|
+
* This source code is licensed under the MIT license found in the
|
2307
|
+
* LICENSE.md file in the root directory of this source tree.
|
2308
|
+
*
|
2309
|
+
* @license MIT
|
2310
|
+
*/
|
2311
|
+
// type Person = {
|
2312
|
+
// firstName: string
|
2313
|
+
// lastName: string
|
2314
|
+
// age: number
|
2315
|
+
// visits: number
|
2316
|
+
// status: string
|
2317
|
+
// progress: number
|
2318
|
+
// createdAt: Date
|
2319
|
+
// nested: {
|
2320
|
+
// foo: [
|
2321
|
+
// {
|
2322
|
+
// bar: 'bar'
|
2323
|
+
// }
|
2324
|
+
// ]
|
2325
|
+
// bar: { subBar: boolean }[]
|
2326
|
+
// baz: {
|
2327
|
+
// foo: 'foo'
|
2328
|
+
// bar: {
|
2329
|
+
// baz: 'baz'
|
2330
|
+
// }
|
2331
|
+
// }
|
2332
|
+
// }
|
2333
|
+
// }
|
2316
2334
|
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
style: {
|
2345
|
-
overflow: showFilters ? "initial" : "hidden"
|
2335
|
+
// const test: DeepKeys<Person> = 'nested.foo.0.bar'
|
2336
|
+
// const test2: DeepKeys<Person> = 'nested.bar'
|
2337
|
+
|
2338
|
+
// const helper = createColumnHelper<Person>()
|
2339
|
+
|
2340
|
+
// helper.accessor('nested.foo', {
|
2341
|
+
// cell: info => info.getValue(),
|
2342
|
+
// })
|
2343
|
+
|
2344
|
+
// helper.accessor('nested.foo.0.bar', {
|
2345
|
+
// cell: info => info.getValue(),
|
2346
|
+
// })
|
2347
|
+
|
2348
|
+
// helper.accessor('nested.bar', {
|
2349
|
+
// cell: info => info.getValue(),
|
2350
|
+
// })
|
2351
|
+
|
2352
|
+
function createColumnHelper() {
|
2353
|
+
return {
|
2354
|
+
accessor: (accessor, column) => {
|
2355
|
+
return typeof accessor === 'function' ? {
|
2356
|
+
...column,
|
2357
|
+
accessorFn: accessor
|
2358
|
+
} : {
|
2359
|
+
...column,
|
2360
|
+
accessorKey: accessor
|
2361
|
+
};
|
2346
2362
|
},
|
2347
|
-
|
2348
|
-
|
2349
|
-
|
2350
|
-
|
2351
|
-
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
w: "auto",
|
2364
|
-
form: form
|
2365
|
-
}), jsx(Buttons, {
|
2366
|
-
handleReset: () => handleReset(props.resetForm)
|
2367
|
-
})]
|
2368
|
-
})
|
2369
|
-
})
|
2370
|
-
})
|
2363
|
+
display: column => column,
|
2364
|
+
group: column => column
|
2365
|
+
};
|
2366
|
+
}
|
2367
|
+
|
2368
|
+
function TableRowPublishPostButton$1(_a) {
|
2369
|
+
var {
|
2370
|
+
id,
|
2371
|
+
api,
|
2372
|
+
status,
|
2373
|
+
invalidateQueryKey
|
2374
|
+
} = _a,
|
2375
|
+
props = __rest$1(_a, ["id", "api", "status", "invalidateQueryKey"]);
|
2376
|
+
const isDraft = status == "draft";
|
2377
|
+
const mutation = useInvalidateParentMutation(isDraft ? api.publish : api.unpublish, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : api.queryKey, {
|
2378
|
+
networkMode: "always"
|
2371
2379
|
});
|
2380
|
+
const publish = React.useCallback(event => {
|
2381
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
2382
|
+
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
2383
|
+
mutation.reset();
|
2384
|
+
mutation.mutateAsync(id).then(() => toast.success(isDraft ? "Published!" : "Unpublished!")).catch(error => toast.error(`Error: ${error}`));
|
2385
|
+
}, [mutation, id]);
|
2386
|
+
return jsx(Button, Object.assign({
|
2387
|
+
variant: "borderless",
|
2388
|
+
corners: "square",
|
2389
|
+
scheme: "dark",
|
2390
|
+
onClick: publish
|
2391
|
+
}, props, {
|
2392
|
+
children: jsx(Icon, {
|
2393
|
+
path: isDraft ? mdiPublish : mdiPublishOff,
|
2394
|
+
size: "sm"
|
2395
|
+
})
|
2396
|
+
}));
|
2372
2397
|
}
|
2373
|
-
|
2374
|
-
|
2398
|
+
|
2399
|
+
function TableRowActionsView({
|
2400
|
+
row,
|
2401
|
+
onAction,
|
2402
|
+
rowActions,
|
2403
|
+
api,
|
2404
|
+
queryKey
|
2375
2405
|
}) {
|
2376
|
-
|
2406
|
+
const item = row.original;
|
2407
|
+
return jsx("div", {
|
2377
2408
|
dflex: true,
|
2378
|
-
|
2379
|
-
|
2380
|
-
|
2381
|
-
|
2382
|
-
|
2383
|
-
|
2384
|
-
|
2385
|
-
|
2386
|
-
|
2387
|
-
|
2388
|
-
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2395
|
-
|
2396
|
-
|
2397
|
-
children: "Reset"
|
2409
|
+
w: "full",
|
2410
|
+
alignItems: "stretch",
|
2411
|
+
placeContent: "end",
|
2412
|
+
h: "full",
|
2413
|
+
children: rowActions === null || rowActions === void 0 ? void 0 : rowActions.map((action, index) => jsxs(React.Fragment, {
|
2414
|
+
children: [action.type === "publish" && jsx(TableRowPublishPostButton$1, {
|
2415
|
+
id: item.id,
|
2416
|
+
api: api,
|
2417
|
+
status: item.status,
|
2418
|
+
invalidateQueryKey: queryKey
|
2419
|
+
}), action.type == "custom" && jsx(Fragment, {
|
2420
|
+
children: action.component(item, queryKey, action.icon, action.label)
|
2421
|
+
}), !["publish", "custom"].includes(action.type) && jsx(ActionButton, {
|
2422
|
+
onClick: () => onAction(action, item),
|
2423
|
+
scheme: schemes$1[action.type],
|
2424
|
+
children: jsx(Icon, {
|
2425
|
+
path: icons[action.type],
|
2426
|
+
size: "sm"
|
2427
|
+
})
|
2398
2428
|
})]
|
2399
|
-
})
|
2429
|
+
}, index))
|
2400
2430
|
});
|
2401
2431
|
}
|
2402
|
-
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2410
|
-
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2424
|
-
disabled: mutation.isLoading,
|
2425
|
-
children: [icon && jsx(Icon, {
|
2426
|
-
path: icon
|
2427
|
-
}), label]
|
2428
|
-
}));
|
2432
|
+
function ActionButton(_a) {
|
2433
|
+
var {
|
2434
|
+
onClick
|
2435
|
+
} = _a,
|
2436
|
+
props = __rest$1(_a, ["onClick"]);
|
2437
|
+
const handleClick = React.useCallback(event => {
|
2438
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
2439
|
+
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
2440
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
2441
|
+
}, [onClick]);
|
2442
|
+
return jsx(Button, Object.assign({
|
2443
|
+
dflex: true,
|
2444
|
+
alignContent: "center",
|
2445
|
+
placeContent: "center",
|
2446
|
+
py: "2.5",
|
2447
|
+
px: "3",
|
2448
|
+
h: "full",
|
2449
|
+
size: "lg",
|
2450
|
+
variant: "borderless",
|
2451
|
+
corners: "default",
|
2452
|
+
onClick: handleClick
|
2453
|
+
}, props));
|
2429
2454
|
}
|
2455
|
+
const icons = {
|
2456
|
+
"link": mdiOpenInNew,
|
2457
|
+
"view": mdiEye,
|
2458
|
+
"edit": mdiPencil,
|
2459
|
+
"delete": mdiDelete,
|
2460
|
+
"publish": mdiDelete,
|
2461
|
+
"custom": ""
|
2462
|
+
};
|
2463
|
+
const schemes$1 = {
|
2464
|
+
"link": "dark",
|
2465
|
+
"view": "dark",
|
2466
|
+
"edit": "dark",
|
2467
|
+
"delete": "dark",
|
2468
|
+
"publish": "dark",
|
2469
|
+
"custom": "dark"
|
2470
|
+
};
|
2430
2471
|
|
2431
|
-
function
|
2432
|
-
|
2433
|
-
|
2472
|
+
function useTableProps(api, table, rowActions) {
|
2473
|
+
const navigate = useNavigate();
|
2474
|
+
const openLink = useOpenLink();
|
2434
2475
|
const {
|
2435
|
-
|
2436
|
-
} =
|
2437
|
-
const
|
2438
|
-
|
2439
|
-
|
2440
|
-
|
2441
|
-
|
2442
|
-
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
2448
|
-
|
2449
|
-
|
2450
|
-
|
2451
|
-
|
2452
|
-
|
2453
|
-
|
2454
|
-
|
2455
|
-
|
2476
|
+
onAction
|
2477
|
+
} = useContext();
|
2478
|
+
const {
|
2479
|
+
onRowClick,
|
2480
|
+
columns: c
|
2481
|
+
} = table,
|
2482
|
+
props = __rest$1(table, ["onRowClick", "columns"]);
|
2483
|
+
const onRowClickHandler = React.useCallback(item => {
|
2484
|
+
if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) === "navigate") navigate(runIfFn(onRowClick.path, item));else if ((onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick.type) == "link") openLink(`${process.env["NEXT_PUBLIC_WEBSITE_URL"]}/${runIfFn(onRowClick.path, item)}`);
|
2485
|
+
}, [navigate, onRowClick]);
|
2486
|
+
const columns = React.useMemo(() => {
|
2487
|
+
const columns = table.columns.concat([]);
|
2488
|
+
if (rowActions) {
|
2489
|
+
columns.push(createColumnHelper().display({
|
2490
|
+
id: "actions",
|
2491
|
+
header: "Actions",
|
2492
|
+
cell: props => jsx(TableRowActionsView, {
|
2493
|
+
row: props.row,
|
2494
|
+
onAction: onAction,
|
2495
|
+
rowActions: rowActions,
|
2496
|
+
api: api,
|
2497
|
+
queryKey: api.queryKey
|
2456
2498
|
})
|
2457
|
-
}
|
2458
|
-
}
|
2459
|
-
|
2499
|
+
}));
|
2500
|
+
}
|
2501
|
+
return columns;
|
2502
|
+
}, [table]);
|
2503
|
+
const tableProps = Object.assign({}, props);
|
2504
|
+
tableProps.columns = columns;
|
2505
|
+
tableProps.onRowClick = onRowClickHandler;
|
2506
|
+
tableProps.queryKey = api.queryKey;
|
2507
|
+
tableProps.queryFn = api.search;
|
2508
|
+
return tableProps;
|
2460
2509
|
}
|
2461
2510
|
|
2462
2511
|
function useId(queryField) {
|
@@ -2519,7 +2568,7 @@ function TT({
|
|
2519
2568
|
breadcrumbs: breadcrumbs
|
2520
2569
|
}), jsx(TableTopBar, {
|
2521
2570
|
title: title,
|
2522
|
-
children: jsx(
|
2571
|
+
children: jsx(TableButtonBar, {
|
2523
2572
|
buttonBar: buttonBar,
|
2524
2573
|
createView: createView,
|
2525
2574
|
editView: editView,
|
@@ -2549,7 +2598,7 @@ function TT({
|
|
2549
2598
|
})]
|
2550
2599
|
});
|
2551
2600
|
}
|
2552
|
-
function
|
2601
|
+
function TableButtonBar({
|
2553
2602
|
buttonBar,
|
2554
2603
|
queryKey,
|
2555
2604
|
createView,
|
@@ -2557,10 +2606,6 @@ function ButtonBar({
|
|
2557
2606
|
api,
|
2558
2607
|
children
|
2559
2608
|
}) {
|
2560
|
-
const invalidate = useInvalidateQuery(queryKey);
|
2561
|
-
useHotkeys('ctrl+r', () => invalidate(), {
|
2562
|
-
preventDefault: true
|
2563
|
-
}, [invalidate]);
|
2564
2609
|
const createDialog = React.useCallback(onClose => {
|
2565
2610
|
const view = createView !== null && createView !== void 0 ? createView : editView;
|
2566
2611
|
if (view.type == "customDialog") return view.render({
|
@@ -2572,23 +2617,9 @@ function ButtonBar({
|
|
2572
2617
|
invalidateQueryKey: api.queryKey
|
2573
2618
|
});
|
2574
2619
|
}, [editView, api]);
|
2575
|
-
return jsxs(
|
2576
|
-
|
2577
|
-
|
2578
|
-
borderColor: "zinc-200",
|
2579
|
-
divideX: "1px",
|
2580
|
-
divideColor: "zinc-200",
|
2581
|
-
rounded: "lg",
|
2582
|
-
overflow: "hidden",
|
2583
|
-
children: [jsx(Button, {
|
2584
|
-
scheme: "dark",
|
2585
|
-
size: "sm",
|
2586
|
-
aspectRatio: "square",
|
2587
|
-
variant: "borderless",
|
2588
|
-
onClick: invalidate,
|
2589
|
-
children: jsx(Icon, {
|
2590
|
-
path: mdiRefresh
|
2591
|
-
})
|
2620
|
+
return jsxs(ButtonBar, {
|
2621
|
+
children: [jsx(RefreshButton, {
|
2622
|
+
queryKey: queryKey
|
2592
2623
|
}), buttonBar && buttonBar.map((button, index) => jsxs(React.Fragment, {
|
2593
2624
|
children: [button.type === "create" && editView && jsx(TableCreateButton, {
|
2594
2625
|
buildDialog: createDialog
|