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