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