@compill/admin 1.0.108 → 1.0.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2115 -0
- package/dist/index.d.ts +50 -565
- package/dist/index.js +605 -592
- package/dist/lib/SectionTitle.d.ts +2 -0
- package/dist/lib/breadcrumbs/BreadCrumbs.d.ts +15 -0
- package/dist/lib/buttons/DialogButton.d.ts +7 -0
- package/dist/lib/buttons/InvalidateButton.d.ts +6 -0
- package/dist/lib/buttons/NavigateButton.d.ts +4 -0
- package/dist/lib/buttons/PublishButton.d.ts +9 -0
- package/dist/lib/buttons/UpdateButton.d.ts +2 -0
- package/dist/lib/buttons/ViewButton.d.ts +5 -0
- package/dist/lib/cells/OrderCell.d.ts +11 -0
- package/dist/lib/json/DetailsView.d.ts +5 -0
- package/dist/lib/json/EditItemView.d.ts +2 -0
- package/dist/lib/json/MultiQueryWrapper.d.ts +5 -0
- package/dist/lib/json/QueryWrapper.d.ts +6 -0
- package/dist/lib/json/ScreenRenderer.d.ts +6 -0
- package/dist/lib/json/ScreenTopBar.d.ts +15 -0
- package/dist/lib/json/TabbedView.d.ts +3 -0
- package/dist/lib/json/buttons/ActionButton.d.ts +14 -0
- package/dist/lib/json/buttons/ConfirmationActionButton.d.ts +26 -0
- package/dist/lib/json/dialog/DialogRenderer.d.ts +11 -0
- package/dist/lib/json/dialog/ItemDeleteDialog.d.ts +17 -0
- package/dist/lib/json/dialog/ItemEditDialog.d.ts +32 -0
- package/dist/lib/json/dialog/MultiQueryWrapperDialog.d.ts +7 -0
- package/dist/lib/json/dialog/QueryWrapperDialog.d.ts +13 -0
- package/dist/lib/json/table/RefreshButton.d.ts +3 -0
- package/dist/lib/json/table/TableRowActionsView.d.ts +11 -0
- package/dist/lib/json/table/TableRowPublishPostButton.d.ts +8 -0
- package/dist/lib/json/table/TableView.d.ts +3 -0
- package/dist/lib/json/table/TableViewContext.d.ts +14 -0
- package/dist/lib/json/table/useTableProps.d.ts +3 -0
- package/dist/lib/json/types/DetailsView.d.ts +57 -0
- package/dist/lib/json/types/EditItemDialog.d.ts +4 -0
- package/dist/lib/json/types/MultiQueryWrapper.d.ts +18 -0
- package/dist/lib/json/types/MultiQueryWrapperDialog.d.ts +13 -0
- package/dist/lib/json/types/QueryWrapper.d.ts +27 -0
- package/dist/lib/json/types/QueryWrapperDialog.d.ts +22 -0
- package/dist/lib/json/types/ScreenConfig.d.ts +8 -0
- package/dist/lib/json/types/TabbedView.d.ts +22 -0
- package/dist/lib/json/types/TableView.d.ts +117 -0
- package/dist/lib/layout/AdminLayout.d.ts +13 -0
- package/dist/lib/layout/ButtonBar.d.ts +19 -0
- package/dist/lib/layout/Content.d.ts +9 -0
- package/dist/lib/layout/PageTitleBar.d.ts +6 -0
- package/dist/lib/layout/Sidebar.d.ts +20 -0
- package/dist/lib/layout/menu/Menu.d.ts +12 -0
- package/dist/lib/layout/menu/MenuButton.d.ts +6 -0
- package/dist/lib/layout/menu/MenuConfig.d.ts +13 -0
- package/dist/lib/layout/menu/MenuItem.d.ts +11 -0
- package/dist/lib/layout/menu/NextMenuItem.d.ts +11 -0
- package/dist/lib/layout/menu/SelectedIndicator.d.ts +3 -0
- package/dist/lib/layout/menu/UserBlock.d.ts +9 -0
- package/dist/lib/modal/AttachDialog.d.ts +30 -0
- package/dist/lib/modal/FormActionDialog.d.ts +23 -0
- package/dist/lib/page/PageContainer.d.ts +2 -0
- package/dist/lib/page/PageContentEditor.d.ts +4 -0
- package/dist/lib/page/PageMain.d.ts +2 -0
- package/dist/lib/page/PageQueryStateContainer.d.ts +21 -0
- package/dist/lib/page/PageSectionTitle.d.ts +2 -0
- package/dist/lib/page/PageSidebar.d.ts +2 -0
- package/dist/lib/page/PageSidebarSection.d.ts +4 -0
- package/dist/lib/page/PageStateContainer.d.ts +7 -0
- package/dist/lib/page/PageSubSectionTitle.d.ts +2 -0
- package/dist/lib/page/PageTitle.d.ts +2 -0
- package/dist/lib/page/PageTopBar.d.ts +13 -0
- package/dist/lib/status/StatusBadge.d.ts +4 -0
- package/dist/lib/table/TableColumnButton.d.ts +1 -0
- package/dist/lib/table/TableContainer.d.ts +10 -0
- package/dist/lib/table/TableContainerContext.d.ts +18 -0
- package/dist/lib/table/TableCreateButton.d.ts +4 -0
- package/dist/lib/table/TableFilterButton.d.ts +2 -0
- package/dist/lib/table/TableFilters.d.ts +9 -0
- package/dist/lib/table/TableMassActions.d.ts +6 -0
- package/dist/lib/table/TableRowActionBar.d.ts +10 -0
- package/dist/lib/table/TableRowActionButton.d.ts +4 -0
- package/dist/lib/table/TableRowActionDialogButton.d.ts +4 -0
- package/dist/lib/table/TableRowDeleteButton.d.ts +2 -0
- package/dist/lib/table/TableRowEditButton.d.ts +2 -0
- package/dist/lib/table/TableRowNavigateButton.d.ts +4 -0
- package/dist/lib/table/TableRowPublishPostButton.d.ts +8 -0
- package/dist/lib/table/TableRowViewButton.d.ts +4 -0
- package/dist/lib/table/TableTopBar.d.ts +8 -0
- package/package.json +17 -17
- package/dist/index.d.mts +0 -565
- package/dist/index.mjs +0 -2000
package/dist/index.js
CHANGED
|
@@ -1,67 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var Image = require('next/image');
|
|
29
|
-
var auth = require('@compill/auth');
|
|
30
|
-
|
|
31
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
32
|
-
|
|
33
|
-
var Link__default = /*#__PURE__*/_interopDefault(Link);
|
|
34
|
-
var React8__default = /*#__PURE__*/_interopDefault(React8);
|
|
35
|
-
var Image__default = /*#__PURE__*/_interopDefault(Image);
|
|
36
|
-
|
|
37
|
-
// src/lib/SectionTitle.tsx
|
|
1
|
+
import { jsx, jsxs, Fragment } from '@soperio/jsx-runtime';
|
|
2
|
+
import { useApiQuery, useApiMutation, useMutate, useInvalidateMutation, useInvalidateQuery, useInvalidateParentMutation, useApiQueries } from '@compill/api';
|
|
3
|
+
import { Shimmer, FlexCenter, QueryLoadingState, RetryOnError, TabContainer, ModalLoadingOverlay } from '@compill/components';
|
|
4
|
+
import { mdiCircleSmall, mdiDatabaseRefreshOutline, mdiPost, mdiEye, mdiEyeOff, mdiCloudUpload, mdiOpenInNew, mdiArrowUpBoldBox, mdiArrowDownBoldBox, mdiPlusThick, mdiFilter, mdiRefresh, mdiPublish, mdiPublishOff, mdiDelete, mdiPencil, mdiCog, mdiDotsVertical, mdiLogout, mdiArrowLeft } from '@mdi/js';
|
|
5
|
+
import { Icon, Button, Container, Tile, Popover, Collapse, Modal, Avatar, IconButton, Popup, Checkbox, Badge } from '@valerya/ui';
|
|
6
|
+
import Link from 'next/link';
|
|
7
|
+
import { useParams, useNavigate, Outlet, useLocation, useMatch, Link as Link$1 } from 'react-router-dom';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { INVALIDATE_API, API, useInvalidatePage } from '@compill/admin-api';
|
|
10
|
+
import { useFormikContext, Formik, Form } from 'formik';
|
|
11
|
+
import { toast } from 'react-toastify';
|
|
12
|
+
import { useHotkeys } from 'react-hotkeys-hook';
|
|
13
|
+
import { FormProvider, TextArea, FormRenderer, mergeInitialFormValues, FieldLabel, SubmitButton } from '@compill/form';
|
|
14
|
+
import { createContext, runIfFn, isFunction } from '@soperio/react';
|
|
15
|
+
import { FormEditor } from '@compill/form-editor';
|
|
16
|
+
import { ImageExtension } from '@compill/editor';
|
|
17
|
+
import { createPortal } from 'react-dom';
|
|
18
|
+
import { useRouter } from 'next/router';
|
|
19
|
+
import { TableContextProvider, useTableContext, Table } from '@compill/table';
|
|
20
|
+
import { isEqual, capitalize, sortBy } from 'es-toolkit';
|
|
21
|
+
import { useOpenLink, useBoolean } from '@compill/hooks';
|
|
22
|
+
import { AppEnv } from '@compill/env';
|
|
23
|
+
import { createColumnHelper } from '@tanstack/react-table';
|
|
24
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
25
|
+
import Image from 'next/image.js';
|
|
26
|
+
import { useSessionUser, useSessionLogout } from '@compill/auth';
|
|
27
|
+
|
|
38
28
|
function SectionTitle({ children, ...props }) {
|
|
39
|
-
return /* @__PURE__ */
|
|
29
|
+
return /* @__PURE__ */ jsx("h2", { textSize: "xl", fontWeight: "600", textColor: "slate-800", ...props, children });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isArray(value) {
|
|
33
|
+
return Array.isArray(value);
|
|
40
34
|
}
|
|
35
|
+
|
|
41
36
|
function Breadcrumbs({ breadcrumbs, ...props }) {
|
|
42
|
-
if (
|
|
43
|
-
return /* @__PURE__ */
|
|
37
|
+
if (isArray(breadcrumbs)) {
|
|
38
|
+
return /* @__PURE__ */ jsx("div", { dflex: true, alignItems: "center", trait: "typo.h5", ...props, children: breadcrumbs.map((b, index) => /* @__PURE__ */ jsx(BreadcrumbItem, { breadcrumb: b, showSeparator: index > 0 }, index)) });
|
|
44
39
|
}
|
|
45
|
-
return /* @__PURE__ */
|
|
40
|
+
return /* @__PURE__ */ jsx(QueryBreadcrumbs, { queryFn: breadcrumbs.queryFn, queryField: breadcrumbs.queryField, generate: breadcrumbs.generate });
|
|
46
41
|
}
|
|
47
42
|
function QueryBreadcrumbs({ queryFn, queryField, generate, ...props }) {
|
|
48
|
-
const params =
|
|
43
|
+
const params = useParams();
|
|
49
44
|
const id = queryField ? params[queryField] : void 0;
|
|
50
|
-
const { data, isLoading, isError } =
|
|
45
|
+
const { data, isLoading, isError } = useApiQuery([""], queryFn, id);
|
|
51
46
|
if (isLoading || isError) {
|
|
52
|
-
return /* @__PURE__ */
|
|
53
|
-
/* @__PURE__ */
|
|
54
|
-
/* @__PURE__ */
|
|
55
|
-
/* @__PURE__ */
|
|
47
|
+
return /* @__PURE__ */ jsxs("div", { dflex: true, alignItems: "center", children: [
|
|
48
|
+
/* @__PURE__ */ jsx(Shimmer, { h: "8", w: "24" }),
|
|
49
|
+
/* @__PURE__ */ jsx(Icon, { path: mdiCircleSmall, mx: "1" }),
|
|
50
|
+
/* @__PURE__ */ jsx(Shimmer, { h: "8", w: "20" })
|
|
56
51
|
] });
|
|
57
52
|
}
|
|
58
53
|
const breadcrumbs = generate(data);
|
|
59
|
-
return /* @__PURE__ */
|
|
54
|
+
return /* @__PURE__ */ jsx("div", { dflex: true, alignItems: "center", trait: "typo.h5", ...props, children: breadcrumbs.map((b, index) => /* @__PURE__ */ jsx(BreadcrumbItem, { breadcrumb: b, showSeparator: index > 0 }, index)) });
|
|
60
55
|
}
|
|
61
56
|
function BreadcrumbItem({ breadcrumb, showSeparator }) {
|
|
62
|
-
return /* @__PURE__ */
|
|
63
|
-
showSeparator && /* @__PURE__ */
|
|
64
|
-
/* @__PURE__ */
|
|
57
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
58
|
+
showSeparator && /* @__PURE__ */ jsx(Icon, { path: mdiCircleSmall, mx: "1" }),
|
|
59
|
+
/* @__PURE__ */ jsx(Link, { href: `/${breadcrumb.path || "#"}`, children: /* @__PURE__ */ jsx(
|
|
65
60
|
"span",
|
|
66
61
|
{
|
|
67
62
|
hover_textDecoration: breadcrumb.path ? "underline" : void 0,
|
|
@@ -71,28 +66,30 @@ function BreadcrumbItem({ breadcrumb, showSeparator }) {
|
|
|
71
66
|
) })
|
|
72
67
|
] });
|
|
73
68
|
}
|
|
69
|
+
|
|
74
70
|
function DialogButton({ buildDialog, ...props }) {
|
|
75
|
-
const [showDialog, setShowDialog] =
|
|
76
|
-
const onShowDialog =
|
|
71
|
+
const [showDialog, setShowDialog] = React.useState(false);
|
|
72
|
+
const onShowDialog = React.useCallback((event) => {
|
|
77
73
|
event?.preventDefault();
|
|
78
74
|
event?.stopPropagation();
|
|
79
75
|
setShowDialog(true);
|
|
80
76
|
}, [setShowDialog]);
|
|
81
|
-
const onCloseDialog =
|
|
77
|
+
const onCloseDialog = React.useCallback(() => {
|
|
82
78
|
setShowDialog(false);
|
|
83
79
|
}, [setShowDialog]);
|
|
84
|
-
return /* @__PURE__ */
|
|
85
|
-
/* @__PURE__ */
|
|
80
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
81
|
+
/* @__PURE__ */ jsx(Button, { onClick: onShowDialog, ...props }),
|
|
86
82
|
showDialog && buildDialog(onCloseDialog)
|
|
87
83
|
] });
|
|
88
84
|
}
|
|
85
|
+
|
|
89
86
|
function ButtonBar({ children, ...props }) {
|
|
90
|
-
return /* @__PURE__ */
|
|
87
|
+
return /* @__PURE__ */ jsx("div", { dflex: true, border: "1px", borderColor: "zinc-200", divideX: "1px", divideColor: "zinc-200", rounded: "lg", overflow: "hidden", ...props, children });
|
|
91
88
|
}
|
|
92
|
-
|
|
89
|
+
const ButtonBarButton = React.forwardRef(
|
|
93
90
|
function({ icon, children, ...props }, ref) {
|
|
94
|
-
return /* @__PURE__ */
|
|
95
|
-
|
|
91
|
+
return /* @__PURE__ */ jsxs(
|
|
92
|
+
Button,
|
|
96
93
|
{
|
|
97
94
|
scheme: "dark",
|
|
98
95
|
size: "sm",
|
|
@@ -106,19 +103,19 @@ var ButtonBarButton = React8__default.default.forwardRef(
|
|
|
106
103
|
...props,
|
|
107
104
|
ref,
|
|
108
105
|
children: [
|
|
109
|
-
icon && /* @__PURE__ */
|
|
106
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon }),
|
|
110
107
|
children
|
|
111
108
|
]
|
|
112
109
|
}
|
|
113
110
|
);
|
|
114
111
|
}
|
|
115
112
|
);
|
|
116
|
-
|
|
113
|
+
const ButtonBarSubmitButton = React.forwardRef(
|
|
117
114
|
function({ useDirty, disabled, icon, children, ...props }, ref) {
|
|
118
|
-
const { dirty, handleSubmit } =
|
|
119
|
-
const onSubmit =
|
|
120
|
-
return /* @__PURE__ */
|
|
121
|
-
|
|
115
|
+
const { dirty, handleSubmit } = useFormikContext() ?? { dirty: false, handleSubmit: void 0};
|
|
116
|
+
const onSubmit = React.useCallback(() => handleSubmit(), [handleSubmit]);
|
|
117
|
+
return /* @__PURE__ */ jsxs(
|
|
118
|
+
Button,
|
|
122
119
|
{
|
|
123
120
|
scheme: "dark",
|
|
124
121
|
size: "sm",
|
|
@@ -134,7 +131,7 @@ var ButtonBarSubmitButton = React8__default.default.forwardRef(
|
|
|
134
131
|
...props,
|
|
135
132
|
ref,
|
|
136
133
|
children: [
|
|
137
|
-
icon && /* @__PURE__ */
|
|
134
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon }),
|
|
138
135
|
children
|
|
139
136
|
]
|
|
140
137
|
}
|
|
@@ -142,7 +139,7 @@ var ButtonBarSubmitButton = React8__default.default.forwardRef(
|
|
|
142
139
|
}
|
|
143
140
|
);
|
|
144
141
|
function ButtonBarDialogButton({ icon, children, ...props }) {
|
|
145
|
-
return /* @__PURE__ */
|
|
142
|
+
return /* @__PURE__ */ jsxs(
|
|
146
143
|
DialogButton,
|
|
147
144
|
{
|
|
148
145
|
scheme: "dark",
|
|
@@ -156,112 +153,121 @@ function ButtonBarDialogButton({ icon, children, ...props }) {
|
|
|
156
153
|
gap: "2",
|
|
157
154
|
...props,
|
|
158
155
|
children: [
|
|
159
|
-
icon && /* @__PURE__ */
|
|
156
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon }),
|
|
160
157
|
children
|
|
161
158
|
]
|
|
162
159
|
}
|
|
163
160
|
);
|
|
164
161
|
}
|
|
162
|
+
|
|
165
163
|
function InvalidateButton({ pathOrPermalink, ...props }) {
|
|
166
|
-
const api
|
|
167
|
-
const mutation =
|
|
168
|
-
const invalidate =
|
|
169
|
-
return /* @__PURE__ */
|
|
164
|
+
const api = INVALIDATE_API.new(pathOrPermalink);
|
|
165
|
+
const mutation = useApiMutation(api.invalidate, api.queryKey);
|
|
166
|
+
const invalidate = useMutate(mutation, { successMsg: "Page successfully invalidated" });
|
|
167
|
+
return /* @__PURE__ */ jsx(
|
|
170
168
|
ButtonBarButton,
|
|
171
169
|
{
|
|
172
170
|
title: "Regenerate",
|
|
173
171
|
disabled: mutation.isLoading,
|
|
174
172
|
onClick: invalidate,
|
|
175
|
-
icon:
|
|
173
|
+
icon: mdiDatabaseRefreshOutline,
|
|
176
174
|
...props
|
|
177
175
|
}
|
|
178
176
|
);
|
|
179
177
|
}
|
|
178
|
+
|
|
180
179
|
function NavigateButton({ path, ...props }) {
|
|
181
|
-
const navigate =
|
|
182
|
-
const handleClick =
|
|
180
|
+
const navigate = useNavigate();
|
|
181
|
+
const handleClick = React.useCallback(() => {
|
|
183
182
|
navigate(path);
|
|
184
183
|
}, [navigate, path]);
|
|
185
|
-
return /* @__PURE__ */
|
|
184
|
+
return /* @__PURE__ */ jsx(Button, { type: "submit", scheme: "dark", variant: "glass", corners: "pill", w: "10", h: "10", onClick: handleClick, ...props, children: /* @__PURE__ */ jsx(Icon, { path: mdiPost }) });
|
|
186
185
|
}
|
|
186
|
+
|
|
187
187
|
function PublishButton({
|
|
188
188
|
status,
|
|
189
189
|
queryId,
|
|
190
|
-
api
|
|
190
|
+
api,
|
|
191
191
|
...props
|
|
192
192
|
}) {
|
|
193
193
|
const isDraft = status == "draft";
|
|
194
|
-
const mutation =
|
|
195
|
-
const publish =
|
|
194
|
+
const mutation = useInvalidateMutation(isDraft ? api.publish : api.unpublish, api.queryKey, queryId, { networkMode: "always" });
|
|
195
|
+
const publish = React.useCallback(() => {
|
|
196
196
|
mutation.reset();
|
|
197
|
-
mutation.mutateAsync(queryId).then(() =>
|
|
197
|
+
mutation.mutateAsync(queryId).then(() => toast.success(isDraft ? "Published!" : "Unpublished!")).catch((error) => toast.error(`Error: ${error}`));
|
|
198
198
|
}, [mutation, queryId]);
|
|
199
|
-
return /* @__PURE__ */
|
|
199
|
+
return /* @__PURE__ */ jsx(
|
|
200
200
|
ButtonBarButton,
|
|
201
201
|
{
|
|
202
202
|
disabled: mutation.isLoading,
|
|
203
203
|
onClick: publish,
|
|
204
|
-
icon: isDraft ?
|
|
204
|
+
icon: isDraft ? mdiEye : mdiEyeOff,
|
|
205
205
|
...props,
|
|
206
206
|
children: isDraft ? "Publish" : "Switch to draft"
|
|
207
207
|
}
|
|
208
208
|
);
|
|
209
209
|
}
|
|
210
|
+
|
|
210
211
|
function UpdateButton({ ...props }) {
|
|
211
|
-
const { dirty, handleSubmit } =
|
|
212
|
-
|
|
212
|
+
const { dirty, handleSubmit } = useFormikContext() ?? { dirty: false, handleSubmit: void 0};
|
|
213
|
+
useHotkeys("ctrl+s", () => {
|
|
213
214
|
if (dirty && !props.disabled) handleSubmit();
|
|
214
215
|
}, { preventDefault: true }, [dirty, props, handleSubmit]);
|
|
215
|
-
return /* @__PURE__ */
|
|
216
|
+
return /* @__PURE__ */ jsx(ButtonBarSubmitButton, { icon: mdiCloudUpload, ...props, children: "Update" });
|
|
216
217
|
}
|
|
218
|
+
|
|
217
219
|
function ViewButton({ label, path, icon, ...props }) {
|
|
218
|
-
const openPage =
|
|
220
|
+
const openPage = React.useCallback(() => {
|
|
219
221
|
window.open(path, "_blank");
|
|
220
222
|
}, [path]);
|
|
221
|
-
return /* @__PURE__ */
|
|
223
|
+
return /* @__PURE__ */ jsx(
|
|
222
224
|
ButtonBarButton,
|
|
223
225
|
{
|
|
224
226
|
onClick: openPage,
|
|
225
227
|
dflex: true,
|
|
226
228
|
alignItems: "center",
|
|
227
229
|
gap: "2",
|
|
228
|
-
icon: icon ||
|
|
230
|
+
icon: icon || mdiOpenInNew,
|
|
229
231
|
...props,
|
|
230
232
|
children: label
|
|
231
233
|
}
|
|
232
234
|
);
|
|
233
235
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const
|
|
236
|
+
|
|
237
|
+
function OrderCell({ api, postId, order }) {
|
|
238
|
+
const mutationDown = useInvalidateMutation(api.moveDown, api.queryKey);
|
|
239
|
+
const mutationUp = useInvalidateMutation(api.moveUp, api.queryKey);
|
|
240
|
+
const moveDown = React.useCallback((e) => {
|
|
238
241
|
e.stopPropagation();
|
|
239
242
|
mutationDown.mutateAsync(postId).catch((error) => {
|
|
240
|
-
|
|
243
|
+
toast.error(`Error: ${error}`);
|
|
241
244
|
});
|
|
242
245
|
}, [mutationDown, postId]);
|
|
243
|
-
const moveUp =
|
|
246
|
+
const moveUp = React.useCallback((e) => {
|
|
244
247
|
e.stopPropagation();
|
|
245
248
|
mutationUp.mutateAsync(postId).catch((error) => {
|
|
246
|
-
|
|
249
|
+
toast.error(`Error: ${error}`);
|
|
247
250
|
});
|
|
248
251
|
}, [mutationUp, postId]);
|
|
249
|
-
return /* @__PURE__ */
|
|
252
|
+
return /* @__PURE__ */ jsxs(FlexCenter, { placeContent: "start", numericFontVariant: "tabular-nums", children: [
|
|
250
253
|
order,
|
|
251
|
-
/* @__PURE__ */
|
|
252
|
-
/* @__PURE__ */
|
|
254
|
+
/* @__PURE__ */ jsx(Button, { ms: "3", variant: "borderless", scheme: "dark", onClick: moveUp, children: /* @__PURE__ */ jsx(Icon, { path: mdiArrowUpBoldBox }) }),
|
|
255
|
+
/* @__PURE__ */ jsx(Button, { variant: "borderless", scheme: "dark", onClick: moveDown, children: /* @__PURE__ */ jsx(Icon, { path: mdiArrowDownBoldBox }) })
|
|
253
256
|
] });
|
|
254
257
|
}
|
|
258
|
+
|
|
255
259
|
function PageContainer({ children, ...props }) {
|
|
256
|
-
return /* @__PURE__ */
|
|
260
|
+
return /* @__PURE__ */ jsx(Container, { center: true, dflex: true, flexCol: true, gap: "8", ...props, children });
|
|
257
261
|
}
|
|
262
|
+
|
|
258
263
|
function PageMain({ children, ...props }) {
|
|
259
|
-
return /* @__PURE__ */
|
|
264
|
+
return /* @__PURE__ */ jsx(Tile, { scheme: "light", p: "5", ...props, children });
|
|
260
265
|
}
|
|
266
|
+
|
|
261
267
|
function PageContentEditor({ name, ...props }) {
|
|
262
|
-
const extensions = [
|
|
263
|
-
return /* @__PURE__ */
|
|
264
|
-
|
|
268
|
+
const extensions = [ImageExtension];
|
|
269
|
+
return /* @__PURE__ */ jsx(PageMain, { h: "min", ...props, children: /* @__PURE__ */ jsx(
|
|
270
|
+
FormEditor,
|
|
265
271
|
{
|
|
266
272
|
minH: "128",
|
|
267
273
|
minW: "144",
|
|
@@ -272,73 +278,79 @@ function PageContentEditor({ name, ...props }) {
|
|
|
272
278
|
}
|
|
273
279
|
) });
|
|
274
280
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const
|
|
281
|
+
|
|
282
|
+
function PageQueryStateContainerInner({ queryId, api, apiFn, loadingStyles, errorStyles, children, ...props }) {
|
|
283
|
+
const { data, isLoading, isError } = apiFn == "getAll" ? useApiQuery(api.queryKey, api.getAll, props.apiParams) : useApiQuery(api.queryKey, api.get, queryId);
|
|
284
|
+
const invalidate = useInvalidateQuery(api.queryKey, queryId);
|
|
278
285
|
if (isLoading)
|
|
279
|
-
return /* @__PURE__ */
|
|
286
|
+
return /* @__PURE__ */ jsx(QueryLoadingState, { w: "full", h: "100%", ...loadingStyles });
|
|
280
287
|
if (isError)
|
|
281
|
-
return /* @__PURE__ */
|
|
282
|
-
return /* @__PURE__ */
|
|
288
|
+
return /* @__PURE__ */ jsx(RetryOnError, { p: "0", onClick: invalidate, ...errorStyles });
|
|
289
|
+
return /* @__PURE__ */ jsx(PageContainer, { ...props, children: apiFn == "get" ? children(data) : children(data) });
|
|
283
290
|
}
|
|
284
|
-
|
|
291
|
+
const PageQueryStateContainer = React.forwardRef(PageQueryStateContainerInner);
|
|
292
|
+
|
|
285
293
|
function PageSidebar({ children, ...props }) {
|
|
286
|
-
return /* @__PURE__ */
|
|
294
|
+
return /* @__PURE__ */ jsx("div", { w: "112", minW: "112", minH: "100%", gap: "8", dflex: true, flexCol: true, ...props, children });
|
|
287
295
|
}
|
|
296
|
+
|
|
288
297
|
function PageSectionTitle({ children, ...props }) {
|
|
289
|
-
return /* @__PURE__ */
|
|
298
|
+
return /* @__PURE__ */ jsx("div", { trait: "typo.h6", mb: "5", ...props, children });
|
|
290
299
|
}
|
|
300
|
+
|
|
291
301
|
function PageSidebarSection({ title, children, ...props }) {
|
|
292
|
-
return /* @__PURE__ */
|
|
293
|
-
title && /* @__PURE__ */
|
|
302
|
+
return /* @__PURE__ */ jsxs("div", { w: "full", ...props, children: [
|
|
303
|
+
title && /* @__PURE__ */ jsx(PageSectionTitle, { children: title }),
|
|
294
304
|
children
|
|
295
305
|
] });
|
|
296
306
|
}
|
|
307
|
+
|
|
297
308
|
function PageTitle({ children, ...props }) {
|
|
298
|
-
return /* @__PURE__ */
|
|
309
|
+
return /* @__PURE__ */ jsx("div", { trait: "typo.h5", ...props, children });
|
|
299
310
|
}
|
|
311
|
+
|
|
300
312
|
function PageTopBar({ title, breadcrumbs, children, ...props }) {
|
|
301
|
-
return /* @__PURE__ */
|
|
302
|
-
title && /* @__PURE__ */
|
|
303
|
-
breadcrumbs && /* @__PURE__ */
|
|
304
|
-
/* @__PURE__ */
|
|
313
|
+
return /* @__PURE__ */ jsxs(FlexCenter, { gap: "3", minH: "9", ...props, children: [
|
|
314
|
+
title && /* @__PURE__ */ jsx(PageTitle, { children: title }),
|
|
315
|
+
breadcrumbs && /* @__PURE__ */ jsx(Breadcrumbs, { breadcrumbs }),
|
|
316
|
+
/* @__PURE__ */ jsx("div", { flexGrow: true }),
|
|
305
317
|
children
|
|
306
318
|
] });
|
|
307
319
|
}
|
|
308
|
-
|
|
320
|
+
const [CP, usePageTabbedTopBarContext] = createContext();
|
|
309
321
|
function PageTabbedTopBarProvider({ children }) {
|
|
310
|
-
const [containerEl, setContainerEl] =
|
|
311
|
-
|
|
312
|
-
return /* @__PURE__ */
|
|
322
|
+
const [containerEl, setContainerEl] = React.useState(null);
|
|
323
|
+
React.createRef();
|
|
324
|
+
return /* @__PURE__ */ jsx(CP, { value: { containerEl, setContainerEl }, children });
|
|
313
325
|
}
|
|
314
326
|
function PageTabbedTopBar({ title, breadcrumbs, children, ...props }) {
|
|
315
|
-
const ref =
|
|
327
|
+
const ref = React.createRef();
|
|
316
328
|
const { setContainerEl } = usePageTabbedTopBarContext();
|
|
317
|
-
const [isSet, setIsSet] =
|
|
318
|
-
|
|
329
|
+
const [isSet, setIsSet] = React.useState(false);
|
|
330
|
+
React.useEffect(() => {
|
|
319
331
|
if (!isSet && ref.current) {
|
|
320
332
|
setContainerEl(ref.current);
|
|
321
333
|
setIsSet(true);
|
|
322
334
|
}
|
|
323
335
|
return () => setContainerEl(null);
|
|
324
336
|
}, []);
|
|
325
|
-
return /* @__PURE__ */
|
|
326
|
-
title && /* @__PURE__ */
|
|
327
|
-
breadcrumbs && /* @__PURE__ */
|
|
328
|
-
/* @__PURE__ */
|
|
329
|
-
/* @__PURE__ */
|
|
337
|
+
return /* @__PURE__ */ jsx(FlexCenter, { gap: "3", minH: "9", ...props, children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
338
|
+
title && /* @__PURE__ */ jsx(PageTitle, { children: title }),
|
|
339
|
+
breadcrumbs && /* @__PURE__ */ jsx(Breadcrumbs, { breadcrumbs }),
|
|
340
|
+
/* @__PURE__ */ jsx("div", { flexGrow: true }),
|
|
341
|
+
/* @__PURE__ */ jsx("div", { ref, dflex: true, flexRow: true, gap: "3" }),
|
|
330
342
|
children
|
|
331
343
|
] }) });
|
|
332
344
|
}
|
|
333
345
|
function PageTopBarToolbar({ trackingRef, children }) {
|
|
334
346
|
const { containerEl } = usePageTabbedTopBarContext();
|
|
335
|
-
const [visible, setVisible] =
|
|
336
|
-
const portal =
|
|
347
|
+
const [visible, setVisible] = React.useState(false);
|
|
348
|
+
const portal = React.useMemo(() => {
|
|
337
349
|
const node = containerEl;
|
|
338
350
|
return node;
|
|
339
351
|
}, [containerEl]);
|
|
340
352
|
const host = containerEl ?? (typeof window !== "undefined" ? document.body : void 0);
|
|
341
|
-
|
|
353
|
+
React.useLayoutEffect(() => {
|
|
342
354
|
if (!portal || !host)
|
|
343
355
|
return;
|
|
344
356
|
try {
|
|
@@ -355,10 +367,10 @@ function PageTopBarToolbar({ trackingRef, children }) {
|
|
|
355
367
|
}
|
|
356
368
|
};
|
|
357
369
|
}, [visible, portal, host]);
|
|
358
|
-
const callback =
|
|
370
|
+
const callback = React.useCallback((entries) => {
|
|
359
371
|
setVisible(entries[0].isVisible);
|
|
360
372
|
}, [children]);
|
|
361
|
-
|
|
373
|
+
React.useEffect(() => {
|
|
362
374
|
const opts = {
|
|
363
375
|
root: null,
|
|
364
376
|
rootMargin: "0px",
|
|
@@ -373,47 +385,49 @@ function PageTopBarToolbar({ trackingRef, children }) {
|
|
|
373
385
|
return () => observerScroll.disconnect();
|
|
374
386
|
}, [trackingRef, callback, children]);
|
|
375
387
|
if (host && portal)
|
|
376
|
-
return
|
|
388
|
+
return createPortal(children, portal);
|
|
377
389
|
return null;
|
|
378
390
|
}
|
|
391
|
+
|
|
379
392
|
function ScreenTopBar({ tabbed, breadcrumbs, api, item, isLoading, buttonBar, trackingRef }) {
|
|
380
|
-
return /* @__PURE__ */
|
|
381
|
-
tabbed && /* @__PURE__ */
|
|
382
|
-
!tabbed && /* @__PURE__ */
|
|
393
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
394
|
+
tabbed && /* @__PURE__ */ jsx(PageTopBarToolbar, { trackingRef, children: /* @__PURE__ */ jsx(Buttons$1, { api, item, isLoading, buttonBar }) }),
|
|
395
|
+
!tabbed && /* @__PURE__ */ jsx(PageTopBar, { breadcrumbs, children: /* @__PURE__ */ jsx(Buttons$1, { api, item, isLoading, buttonBar }) })
|
|
383
396
|
] });
|
|
384
397
|
}
|
|
385
|
-
function Buttons({ api, item, isLoading, buttonBar }) {
|
|
386
|
-
return /* @__PURE__ */
|
|
387
|
-
buttonBar && buttonBar.length > 0 && /* @__PURE__ */
|
|
388
|
-
button.type === "link" && /* @__PURE__ */
|
|
389
|
-
button.type === "invalidate" && /* @__PURE__ */
|
|
398
|
+
function Buttons$1({ api, item, isLoading, buttonBar }) {
|
|
399
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
400
|
+
buttonBar && buttonBar.length > 0 && /* @__PURE__ */ jsx(ButtonBar, { children: buttonBar.map((button, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
401
|
+
button.type === "link" && /* @__PURE__ */ jsx(ViewButton, { label: button.label, path: button.path, icon: button.icon }),
|
|
402
|
+
button.type === "invalidate" && /* @__PURE__ */ jsx(InvalidateButton, { pathOrPermalink: button.pathOrPermalink }),
|
|
390
403
|
button.type == "custom" && button.render(item)
|
|
391
404
|
] }, index)) }),
|
|
392
|
-
/* @__PURE__ */
|
|
393
|
-
api instanceof
|
|
394
|
-
/* @__PURE__ */
|
|
405
|
+
/* @__PURE__ */ jsxs(ButtonBar, { children: [
|
|
406
|
+
api instanceof API && /* @__PURE__ */ jsx(PublishButton, { api, queryId: item.id, status: item.status, disabled: isLoading }),
|
|
407
|
+
/* @__PURE__ */ jsx(UpdateButton, { disabled: isLoading })
|
|
395
408
|
] })
|
|
396
409
|
] });
|
|
397
410
|
}
|
|
411
|
+
|
|
398
412
|
function useQueryField(queryField, useNextRouter) {
|
|
399
413
|
if (useNextRouter) {
|
|
400
|
-
const router
|
|
401
|
-
return router
|
|
414
|
+
const router = useRouter();
|
|
415
|
+
return router.query[queryField];
|
|
402
416
|
}
|
|
403
|
-
const { [queryField]: id } =
|
|
417
|
+
const { [queryField]: id } = useParams();
|
|
404
418
|
return id;
|
|
405
419
|
}
|
|
406
420
|
function DetailsView({ queryField, api, useNextRouter, processInput, screen, tabbed, ...props }) {
|
|
407
421
|
const id = useQueryField(queryField, useNextRouter);
|
|
408
|
-
const ref =
|
|
409
|
-
return /* @__PURE__ */
|
|
422
|
+
const ref = React.useRef(null);
|
|
423
|
+
return /* @__PURE__ */ jsx(PageQueryStateContainer, { api, apiFn: "get", queryId: id, ref, p: "5", ...props, children: (item) => /* @__PURE__ */ jsx(Internal, { item, screen, api, tabbed, processInput, containerRef: ref }) });
|
|
410
424
|
}
|
|
411
|
-
function Internal({ item, screen, api
|
|
412
|
-
const pScreen =
|
|
425
|
+
function Internal({ item, screen, api, processInput, tabbed, containerRef }) {
|
|
426
|
+
const pScreen = runIfFn(screen, item);
|
|
413
427
|
const { breadcrumbs, schema, initialValues, header, sections, buttonBar, type, invalidateParentQueryKey, invalidatePage } = pScreen;
|
|
414
|
-
const mutation =
|
|
415
|
-
const invalidatePageFn =
|
|
416
|
-
const save =
|
|
428
|
+
const mutation = useInvalidateParentMutation(api.update, invalidateParentQueryKey ?? api.queryKey, { networkMode: "always" });
|
|
429
|
+
const invalidatePageFn = useInvalidatePage(invalidatePage || "");
|
|
430
|
+
const save = useMutate(mutation, {
|
|
417
431
|
processInput,
|
|
418
432
|
successMsg: (item2, values) => `${item2.title || item2.name} updated.`,
|
|
419
433
|
errorMsg: (error, item2) => `Error updating ${item2.title || item2.name}: ${error}`,
|
|
@@ -427,19 +441,19 @@ function Internal({ item, screen, api: api$1, processInput, tabbed, containerRef
|
|
|
427
441
|
editorMaxW = "calc(1280px - 28rem)";
|
|
428
442
|
else if (type == "section")
|
|
429
443
|
editorMaxW = "calc(1280px - 22rem)";
|
|
430
|
-
return /* @__PURE__ */
|
|
431
|
-
|
|
444
|
+
return /* @__PURE__ */ jsxs(
|
|
445
|
+
FormProvider,
|
|
432
446
|
{
|
|
433
|
-
initialValues:
|
|
447
|
+
initialValues: runIfFn(initialValues, item),
|
|
434
448
|
validationSchema: schema,
|
|
435
449
|
onSubmit: save,
|
|
436
450
|
enableReinitialize: true,
|
|
437
451
|
children: [
|
|
438
|
-
/* @__PURE__ */
|
|
452
|
+
/* @__PURE__ */ jsx(
|
|
439
453
|
ScreenTopBar,
|
|
440
454
|
{
|
|
441
455
|
tabbed,
|
|
442
|
-
api
|
|
456
|
+
api,
|
|
443
457
|
breadcrumbs,
|
|
444
458
|
buttonBar,
|
|
445
459
|
item,
|
|
@@ -447,15 +461,15 @@ function Internal({ item, screen, api: api$1, processInput, tabbed, containerRef
|
|
|
447
461
|
trackingRef: containerRef?.current
|
|
448
462
|
}
|
|
449
463
|
),
|
|
450
|
-
type == "form" && sections?.map((section, index) => /* @__PURE__ */
|
|
451
|
-
(pScreen.type == "post" || pScreen.type == "section") && /* @__PURE__ */
|
|
464
|
+
type == "form" && sections?.map((section, index) => /* @__PURE__ */ jsx(Section, { section, item }, index)),
|
|
465
|
+
(pScreen.type == "post" || pScreen.type == "section") && /* @__PURE__ */ jsx("div", { p: "5", bgColor: "slate-100", rounded: "lg", children: /* @__PURE__ */ jsxs(PageContainer, { w: editorMaxW ? "auto" : "full", size: "x2", id: "pagecontainer", children: [
|
|
452
466
|
header,
|
|
453
|
-
/* @__PURE__ */
|
|
454
|
-
/* @__PURE__ */
|
|
467
|
+
/* @__PURE__ */ jsxs("div", { dflex: true, gap: "5", children: [
|
|
468
|
+
/* @__PURE__ */ jsxs("div", { dflex: true, flexCol: true, gap: "8", flexGrow: true, children: [
|
|
455
469
|
pScreen.editor?.type != "textarea" && // TODO Find a way to make this editor shrink in width when resizing the window...
|
|
456
|
-
/* @__PURE__ */
|
|
457
|
-
pScreen.editor?.type == "textarea" && /* @__PURE__ */
|
|
458
|
-
|
|
470
|
+
/* @__PURE__ */ jsx(PageContentEditor, { name: "content", maxW: editorMaxW, minW: "144", shadow: true, rounded: "lg" }),
|
|
471
|
+
pScreen.editor?.type == "textarea" && /* @__PURE__ */ jsx(
|
|
472
|
+
TextArea,
|
|
459
473
|
{
|
|
460
474
|
name: pScreen.editor?.name,
|
|
461
475
|
maxW: editorMaxW,
|
|
@@ -472,7 +486,7 @@ function Internal({ item, screen, api: api$1, processInput, tabbed, containerRef
|
|
|
472
486
|
),
|
|
473
487
|
pScreen.editorFooter
|
|
474
488
|
] }),
|
|
475
|
-
/* @__PURE__ */
|
|
489
|
+
/* @__PURE__ */ jsx(PageSidebar, { children: sections?.map((section, index) => /* @__PURE__ */ jsx(Section, { section, item, cardStyle: true }, index)) })
|
|
476
490
|
] })
|
|
477
491
|
] }) })
|
|
478
492
|
]
|
|
@@ -488,21 +502,22 @@ function Section({ section, item, cardStyle }) {
|
|
|
488
502
|
textSize: "sm",
|
|
489
503
|
shadow: true
|
|
490
504
|
} : {};
|
|
491
|
-
return /* @__PURE__ */
|
|
505
|
+
return /* @__PURE__ */ jsx(PageSidebarSection, { title: section.title, ...style, children: /* @__PURE__ */ jsx(FormRenderer, { form: runIfFn(section.form, item) }) });
|
|
492
506
|
}
|
|
493
507
|
if (section.type === "custom")
|
|
494
|
-
return
|
|
508
|
+
return runIfFn(section.component, item);
|
|
495
509
|
return null;
|
|
496
510
|
}
|
|
511
|
+
|
|
497
512
|
function useApi(api, queryField) {
|
|
498
|
-
const params =
|
|
513
|
+
const params = useParams();
|
|
499
514
|
if (queryField === void 0)
|
|
500
515
|
return { id: void 0, api };
|
|
501
516
|
const { [queryField]: id } = params;
|
|
502
|
-
return { id, api:
|
|
517
|
+
return { id, api: runIfFn(api, id) };
|
|
503
518
|
}
|
|
504
519
|
function QueryWrapper({
|
|
505
|
-
api
|
|
520
|
+
api,
|
|
506
521
|
queryField,
|
|
507
522
|
fn,
|
|
508
523
|
transformFn,
|
|
@@ -510,9 +525,9 @@ function QueryWrapper({
|
|
|
510
525
|
tabbed,
|
|
511
526
|
...props
|
|
512
527
|
}) {
|
|
513
|
-
const { id, api: mApi } = useApi(api
|
|
514
|
-
const { data } =
|
|
515
|
-
const transformedData =
|
|
528
|
+
const { id, api: mApi } = useApi(api, queryField);
|
|
529
|
+
const { data } = useApiQuery(mApi.queryKey, fn === "get" || fn === "getTransformed" ? mApi.get : mApi.getAll, isFunction(api) ? void 0 : id);
|
|
530
|
+
const transformedData = React.useMemo(() => {
|
|
516
531
|
if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
|
|
517
532
|
if (!transformFn)
|
|
518
533
|
console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
|
|
@@ -522,11 +537,12 @@ function QueryWrapper({
|
|
|
522
537
|
}, [data]);
|
|
523
538
|
if (!data)
|
|
524
539
|
return null;
|
|
525
|
-
return /* @__PURE__ */
|
|
540
|
+
return /* @__PURE__ */ jsx(ScreenRenderer, { config: config(transformedData), tabbed, ...props });
|
|
526
541
|
}
|
|
542
|
+
|
|
527
543
|
function TabbedView({ queryField, api, screen, ...props }) {
|
|
528
|
-
const { [queryField]: id } =
|
|
529
|
-
return /* @__PURE__ */
|
|
544
|
+
const { [queryField]: id } = useParams();
|
|
545
|
+
return /* @__PURE__ */ jsx(
|
|
530
546
|
PageQueryStateContainer,
|
|
531
547
|
{
|
|
532
548
|
queryId: id,
|
|
@@ -534,18 +550,18 @@ function TabbedView({ queryField, api, screen, ...props }) {
|
|
|
534
550
|
apiFn: "get",
|
|
535
551
|
p: "5",
|
|
536
552
|
children: (city) => {
|
|
537
|
-
const { breadcrumbs, tabs } =
|
|
538
|
-
return /* @__PURE__ */
|
|
539
|
-
/* @__PURE__ */
|
|
540
|
-
/* @__PURE__ */
|
|
541
|
-
|
|
553
|
+
const { breadcrumbs, tabs } = runIfFn(screen, city);
|
|
554
|
+
return /* @__PURE__ */ jsxs(PageTabbedTopBarProvider, { children: [
|
|
555
|
+
/* @__PURE__ */ jsx(PageTabbedTopBar, { breadcrumbs, mb: "-3" }),
|
|
556
|
+
/* @__PURE__ */ jsx(
|
|
557
|
+
TabContainer,
|
|
542
558
|
{
|
|
543
559
|
tabs: tabs.map((tab) => tab.label),
|
|
544
560
|
saveKey: `tab-${id}`,
|
|
545
561
|
mt: "-3",
|
|
546
562
|
mb: "3",
|
|
547
563
|
id: "fff",
|
|
548
|
-
children: tabs.map((tab, index) => /* @__PURE__ */
|
|
564
|
+
children: tabs.map((tab, index) => /* @__PURE__ */ jsx(TabView, { tab }, index))
|
|
549
565
|
}
|
|
550
566
|
)
|
|
551
567
|
] });
|
|
@@ -558,18 +574,19 @@ function TabView({ tab }) {
|
|
|
558
574
|
throw new Error(`Screen config for tabbed view: one of your tabs does not have a component or config declared: ${tab.label}`);
|
|
559
575
|
if (tab.component)
|
|
560
576
|
return tab.component();
|
|
561
|
-
return /* @__PURE__ */
|
|
577
|
+
return /* @__PURE__ */ jsx(ScreenRenderer, { config: tab.config, tabbed: true, p: "0" });
|
|
562
578
|
}
|
|
563
|
-
|
|
579
|
+
|
|
580
|
+
const [provider$1, useContext$1] = createContext();
|
|
564
581
|
function getColId(column) {
|
|
565
582
|
return column.accessorKey ?? column.id;
|
|
566
583
|
}
|
|
567
584
|
function TableContainerContextProvider({ initialVisibleColumns, columns, children }) {
|
|
568
|
-
const [showFilters, setShowFilters] =
|
|
569
|
-
const [showMassActions, setShowMassActions] =
|
|
570
|
-
const [visibleColumnIds, setVisibleColumnIds] =
|
|
585
|
+
const [showFilters, setShowFilters] = React.useState(false);
|
|
586
|
+
const [showMassActions, setShowMassActions] = React.useState(false);
|
|
587
|
+
const [visibleColumnIds, setVisibleColumnIds] = React.useState(initialVisibleColumns ?? columns?.map((col) => getColId(col)) ?? []);
|
|
571
588
|
const filteredColumns = columns?.filter((col) => visibleColumnIds.includes(getColId(col))) ?? [];
|
|
572
|
-
const toggleColumnVisibility =
|
|
589
|
+
const toggleColumnVisibility = React.useCallback((id) => {
|
|
573
590
|
const index = visibleColumnIds.indexOf(id);
|
|
574
591
|
if (index > -1) {
|
|
575
592
|
const newIds = visibleColumnIds.concat();
|
|
@@ -579,10 +596,10 @@ function TableContainerContextProvider({ initialVisibleColumns, columns, childre
|
|
|
579
596
|
setVisibleColumnIds(visibleColumnIds.concat(id));
|
|
580
597
|
}
|
|
581
598
|
}, [visibleColumnIds, setVisibleColumnIds]);
|
|
582
|
-
const isColumnVisible =
|
|
599
|
+
const isColumnVisible = React.useCallback((id) => {
|
|
583
600
|
return visibleColumnIds.includes(id);
|
|
584
601
|
}, [visibleColumnIds]);
|
|
585
|
-
const Provider = provider;
|
|
602
|
+
const Provider = provider$1;
|
|
586
603
|
const value = {
|
|
587
604
|
showFilters,
|
|
588
605
|
setShowFilters,
|
|
@@ -593,29 +610,33 @@ function TableContainerContextProvider({ initialVisibleColumns, columns, childre
|
|
|
593
610
|
toggleColumnVisibility,
|
|
594
611
|
isColumnVisible
|
|
595
612
|
};
|
|
596
|
-
return /* @__PURE__ */
|
|
613
|
+
return /* @__PURE__ */ jsx(Provider, { value, children });
|
|
597
614
|
}
|
|
615
|
+
|
|
598
616
|
function TableContainer({ initialPageSize, initialVisibleColumns, columns, filtersMethod = "reactRouter", children, ...props }) {
|
|
599
|
-
return /* @__PURE__ */
|
|
617
|
+
return /* @__PURE__ */ jsx("div", { w: "full", dflex: true, flexCol: true, ...props, children: /* @__PURE__ */ jsx(TableContextProvider, { initialPageSize, filtersMethod, children: /* @__PURE__ */ jsx(TableContainerContextProvider, { columns, initialVisibleColumns, children }) }) });
|
|
600
618
|
}
|
|
619
|
+
|
|
601
620
|
function TableCreateButton({ icon, children, ...props }) {
|
|
602
|
-
return /* @__PURE__ */
|
|
603
|
-
/* @__PURE__ */
|
|
621
|
+
return /* @__PURE__ */ jsxs(ButtonBarDialogButton, { ...props, children: [
|
|
622
|
+
/* @__PURE__ */ jsx(Icon, { path: icon ?? mdiPlusThick }),
|
|
604
623
|
children
|
|
605
624
|
] });
|
|
606
625
|
}
|
|
626
|
+
|
|
607
627
|
function TableFilterButton({ ...props }) {
|
|
608
|
-
return /* @__PURE__ */
|
|
609
|
-
/* @__PURE__ */
|
|
610
|
-
/* @__PURE__ */
|
|
611
|
-
/* @__PURE__ */
|
|
612
|
-
/* @__PURE__ */
|
|
613
|
-
/* @__PURE__ */
|
|
628
|
+
return /* @__PURE__ */ jsxs(Popover, { side: "bottom-end", modal: true, children: [
|
|
629
|
+
/* @__PURE__ */ jsx(Button, { scheme: "dark", size: "sm", aspectRatio: "square", variant: "borderless", corners: "square", ...props, children: /* @__PURE__ */ jsx(Icon, { path: mdiFilter }) }),
|
|
630
|
+
/* @__PURE__ */ jsxs("div", { bgColor: "white", rounded: true, shadow: true, children: [
|
|
631
|
+
/* @__PURE__ */ jsx("div", { py: "3", hover_bgColor: "#ff0000", px: "5", hover_textColor: "white", children: "First Item" }),
|
|
632
|
+
/* @__PURE__ */ jsx("div", { py: "3", hover_bgColor: "#ff0000", px: "5", hover_textColor: "white", children: "Second Item" }),
|
|
633
|
+
/* @__PURE__ */ jsx("div", { py: "3", hover_bgColor: "#ff0000", px: "5", hover_textColor: "white", children: "Third Item" })
|
|
614
634
|
] })
|
|
615
635
|
] });
|
|
616
636
|
}
|
|
637
|
+
|
|
617
638
|
function TableTopBar({ title, breadcrumbs, children, ...props }) {
|
|
618
|
-
return /* @__PURE__ */
|
|
639
|
+
return /* @__PURE__ */ jsxs(
|
|
619
640
|
"div",
|
|
620
641
|
{
|
|
621
642
|
dflex: true,
|
|
@@ -625,57 +646,59 @@ function TableTopBar({ title, breadcrumbs, children, ...props }) {
|
|
|
625
646
|
p: "8",
|
|
626
647
|
...props,
|
|
627
648
|
children: [
|
|
628
|
-
/* @__PURE__ */
|
|
629
|
-
title && /* @__PURE__ */
|
|
630
|
-
breadcrumbs && /* @__PURE__ */
|
|
649
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
650
|
+
title && /* @__PURE__ */ jsx("h2", { textSize: "x2", fontWeight: "600", textColor: "#3f4254", textTransform: "capitalize", children: title }),
|
|
651
|
+
breadcrumbs && /* @__PURE__ */ jsx(Breadcrumbs, { breadcrumbs })
|
|
631
652
|
] }),
|
|
632
|
-
/* @__PURE__ */
|
|
653
|
+
/* @__PURE__ */ jsx("div", { flexGrow: true, children: "\xA0" }),
|
|
633
654
|
children
|
|
634
655
|
]
|
|
635
656
|
}
|
|
636
657
|
);
|
|
637
658
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
const {
|
|
641
|
-
const
|
|
659
|
+
|
|
660
|
+
function TableFilters({ form, initialValues, schema, processInput }) {
|
|
661
|
+
const { showFilters } = useContext$1();
|
|
662
|
+
const { getFilters, setFilters } = useTableContext();
|
|
663
|
+
const handleSubmit = React.useCallback((values, actions) => {
|
|
642
664
|
const params = processInput?.(values) ?? values;
|
|
643
|
-
if (!
|
|
665
|
+
if (!isEqual(params, getFilters()))
|
|
644
666
|
setFilters(params);
|
|
645
667
|
actions.setSubmitting(false);
|
|
646
668
|
}, [setFilters, processInput]);
|
|
647
|
-
const handleReset =
|
|
669
|
+
const handleReset = React.useCallback((resetForm) => {
|
|
648
670
|
setFilters(initialValues);
|
|
649
671
|
resetForm();
|
|
650
672
|
}, [setFilters, initialValues]);
|
|
651
|
-
|
|
652
|
-
return /* @__PURE__ */
|
|
653
|
-
|
|
673
|
+
React.useEffect(() => setFilters(initialValues), []);
|
|
674
|
+
return /* @__PURE__ */ jsx(Collapse, { in: showFilters, style: { overflow: showFilters ? "initial" : "hidden" }, children: /* @__PURE__ */ jsx("div", { p: "8", borderT: "px", borderB: "px", borderColor: "slate-100", children: /* @__PURE__ */ jsx(
|
|
675
|
+
FormProvider,
|
|
654
676
|
{
|
|
655
|
-
initialValues:
|
|
677
|
+
initialValues: mergeInitialFormValues(getFilters(), initialValues),
|
|
656
678
|
onSubmit: handleSubmit,
|
|
657
679
|
validationSchema: schema,
|
|
658
680
|
enableReinitialize: true,
|
|
659
|
-
children: (props) => /* @__PURE__ */
|
|
660
|
-
/* @__PURE__ */
|
|
661
|
-
/* @__PURE__ */
|
|
681
|
+
children: (props) => /* @__PURE__ */ jsxs("div", { dflex: true, gap: "3", placeContent: "start", children: [
|
|
682
|
+
/* @__PURE__ */ jsx(FormRenderer, { flexRow: true, w: "auto", form }),
|
|
683
|
+
/* @__PURE__ */ jsx(Buttons, { handleReset: () => handleReset(props.resetForm) })
|
|
662
684
|
] })
|
|
663
685
|
}
|
|
664
686
|
) }) });
|
|
665
687
|
}
|
|
666
|
-
function
|
|
667
|
-
return /* @__PURE__ */
|
|
668
|
-
/* @__PURE__ */
|
|
669
|
-
/* @__PURE__ */
|
|
670
|
-
/* @__PURE__ */
|
|
688
|
+
function Buttons({ handleReset }) {
|
|
689
|
+
return /* @__PURE__ */ jsxs("div", { dflex: true, gap: "3", children: [
|
|
690
|
+
/* @__PURE__ */ jsxs("div", { dflex: true, flexCol: true, children: [
|
|
691
|
+
/* @__PURE__ */ jsx(FieldLabel, { name: "", label: "\xA0" }),
|
|
692
|
+
/* @__PURE__ */ jsx(SubmitButton, { children: "Filter" })
|
|
671
693
|
] }),
|
|
672
|
-
/* @__PURE__ */
|
|
673
|
-
/* @__PURE__ */
|
|
674
|
-
/* @__PURE__ */
|
|
694
|
+
/* @__PURE__ */ jsxs("div", { dflex: true, flexCol: true, children: [
|
|
695
|
+
/* @__PURE__ */ jsx(FieldLabel, { name: "", label: "\xA0" }),
|
|
696
|
+
/* @__PURE__ */ jsx(Button, { scheme: "neutral", onClick: handleReset, children: "Reset" })
|
|
675
697
|
] })
|
|
676
698
|
] });
|
|
677
699
|
}
|
|
678
|
-
|
|
700
|
+
|
|
701
|
+
function ActionButton$1({
|
|
679
702
|
label,
|
|
680
703
|
buttonProps,
|
|
681
704
|
icon,
|
|
@@ -685,16 +708,16 @@ function ActionButton({
|
|
|
685
708
|
errorMsg,
|
|
686
709
|
invalidateParent
|
|
687
710
|
}) {
|
|
688
|
-
const mutation = invalidateParent ?
|
|
689
|
-
const mutate =
|
|
711
|
+
const mutation = invalidateParent ? useInvalidateParentMutation(queryFn, queryKey) : useApiMutation(queryFn, queryKey);
|
|
712
|
+
const mutate = useMutate(
|
|
690
713
|
mutation,
|
|
691
714
|
{
|
|
692
715
|
successMsg,
|
|
693
716
|
errorMsg
|
|
694
717
|
}
|
|
695
718
|
);
|
|
696
|
-
return /* @__PURE__ */
|
|
697
|
-
|
|
719
|
+
return /* @__PURE__ */ jsxs(
|
|
720
|
+
Button,
|
|
698
721
|
{
|
|
699
722
|
display: "flex",
|
|
700
723
|
alignItems: "center",
|
|
@@ -703,18 +726,20 @@ function ActionButton({
|
|
|
703
726
|
onClick: mutate,
|
|
704
727
|
disabled: mutation.isLoading,
|
|
705
728
|
children: [
|
|
706
|
-
icon && /* @__PURE__ */
|
|
729
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon }),
|
|
707
730
|
label
|
|
708
731
|
]
|
|
709
732
|
}
|
|
710
733
|
);
|
|
711
734
|
}
|
|
735
|
+
|
|
712
736
|
function TableMassActions({ actions }) {
|
|
713
|
-
const { ids } =
|
|
737
|
+
const { ids } = useTableContext();
|
|
714
738
|
const showMassActions = ids && ids.length > 0;
|
|
715
|
-
return /* @__PURE__ */
|
|
739
|
+
return /* @__PURE__ */ jsx(Collapse, { in: showMassActions, style: { overflow: showMassActions ? "initial" : "hidden" }, children: /* @__PURE__ */ jsx("div", { dflex: true, gap: "3", flexWrap: true, alignItems: "center", px: "8", pt: "5", children: actions.map((action, index) => /* @__PURE__ */ jsx("div", { children: action.type == "button" && !action.showConfirmationDialog && /* @__PURE__ */ jsx(ActionButton$1, { label: action.label, queryFn: action.queryFn, queryKey: action.queryKey, buttonProps: action.buttonProps }) }, index)) }) });
|
|
716
740
|
}
|
|
717
|
-
|
|
741
|
+
|
|
742
|
+
const defaultErrorMsg$1 = "Oops, something went wrong...";
|
|
718
743
|
function nonNullValues(data) {
|
|
719
744
|
if (data) {
|
|
720
745
|
const nonNullData = { ...data };
|
|
@@ -728,14 +753,14 @@ function ItemEditDialog({
|
|
|
728
753
|
initialValues,
|
|
729
754
|
itemLabel,
|
|
730
755
|
queryId = "",
|
|
731
|
-
api
|
|
756
|
+
api,
|
|
732
757
|
queryFetchOptions,
|
|
733
758
|
querySaveOptions,
|
|
734
759
|
onSuccess,
|
|
735
760
|
onFetchError,
|
|
736
|
-
fetchErrorMsg = defaultErrorMsg,
|
|
761
|
+
fetchErrorMsg = defaultErrorMsg$1,
|
|
737
762
|
onSaveError,
|
|
738
|
-
saveErrorMsg = defaultErrorMsg,
|
|
763
|
+
saveErrorMsg = defaultErrorMsg$1,
|
|
739
764
|
fetchToFormData,
|
|
740
765
|
formToQueryData,
|
|
741
766
|
invalidateQueriesOnSuccess = true,
|
|
@@ -745,41 +770,41 @@ function ItemEditDialog({
|
|
|
745
770
|
saveLabel,
|
|
746
771
|
size = "lg",
|
|
747
772
|
title,
|
|
748
|
-
form
|
|
773
|
+
form,
|
|
749
774
|
show,
|
|
750
775
|
onClose,
|
|
751
776
|
formikProps,
|
|
752
777
|
...props
|
|
753
778
|
}) {
|
|
754
|
-
const { isInitialLoading, isFetching, data, isError, error, refetch } =
|
|
779
|
+
const { isInitialLoading, isFetching, data, isError, error, refetch } = useApiQuery(api.queryKey, api.get, queryId, {
|
|
755
780
|
enabled: !/*queryId == 0 || */
|
|
756
781
|
(queryId == "" || queryId == null || queryId == void 0),
|
|
757
782
|
// means than this query is only enabled if the id is defined
|
|
758
783
|
onError: onFetchError,
|
|
759
784
|
...queryFetchOptions
|
|
760
785
|
});
|
|
761
|
-
const mutation = invalidateQueriesOnSuccess ?
|
|
762
|
-
const retry =
|
|
763
|
-
const saveItem =
|
|
786
|
+
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(api.upsert, invalidateQueryKey ?? api.queryKey, querySaveOptions) : useApiMutation(api.upsert, api.queryKey, queryId, querySaveOptions);
|
|
787
|
+
const retry = React.useCallback(() => refetch(), [refetch]);
|
|
788
|
+
const saveItem = React.useCallback(async (item, actions) => {
|
|
764
789
|
mutation.reset();
|
|
765
790
|
const formItem = formToQueryData ? formToQueryData(item) : { ...item };
|
|
766
791
|
await mutation.mutateAsync(formItem).then((response) => {
|
|
767
792
|
if (onSuccess)
|
|
768
793
|
onSuccess(formItem, response);
|
|
769
794
|
else
|
|
770
|
-
|
|
795
|
+
toast.success(`${title ? title(formItem) : formItem.name ?? formItem.title} ${queryId ? "saved" : "created"}`);
|
|
771
796
|
onClose?.();
|
|
772
797
|
}).catch((error2) => {
|
|
773
798
|
console.error("on error", error2);
|
|
774
799
|
if (onSaveError)
|
|
775
800
|
onSaveError(item);
|
|
776
801
|
else
|
|
777
|
-
|
|
802
|
+
toast.error(`Couldn't save ${title ? title(formItem) : formItem.name ?? formItem.title}`);
|
|
778
803
|
actions.setSubmitting(false);
|
|
779
804
|
});
|
|
780
805
|
}, [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
|
781
|
-
return /* @__PURE__ */
|
|
782
|
-
|
|
806
|
+
return /* @__PURE__ */ jsxs(
|
|
807
|
+
Modal,
|
|
783
808
|
{
|
|
784
809
|
size,
|
|
785
810
|
show,
|
|
@@ -788,28 +813,28 @@ function ItemEditDialog({
|
|
|
788
813
|
transition: true,
|
|
789
814
|
...props,
|
|
790
815
|
children: [
|
|
791
|
-
/* @__PURE__ */
|
|
816
|
+
/* @__PURE__ */ jsxs(Modal.Header, { children: [
|
|
792
817
|
!isInitialLoading && queryId && `Edit ${title ? title(data) : data?.["name"] ?? data?.["title"] ?? data?.["name"] ?? ""}`,
|
|
793
818
|
!queryId && `Create new ${itemLabel ?? "item"}`,
|
|
794
|
-
Array.isArray(form
|
|
819
|
+
Array.isArray(form) && /* @__PURE__ */ jsx(Fragment, {})
|
|
795
820
|
] }),
|
|
796
|
-
isInitialLoading && /* @__PURE__ */
|
|
797
|
-
isError && /* @__PURE__ */
|
|
798
|
-
!isInitialLoading && !isError && /* @__PURE__ */
|
|
799
|
-
|
|
821
|
+
isInitialLoading && /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(QueryLoadingState, { minW: "72" }) }),
|
|
822
|
+
isError && /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(RetryOnError, { label: `${fetchErrorMsg} ${error}`, onClick: retry }) }),
|
|
823
|
+
!isInitialLoading && !isError && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
824
|
+
Formik,
|
|
800
825
|
{
|
|
801
826
|
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(initialValues(data)) ?? {},
|
|
802
827
|
onSubmit: saveItem,
|
|
803
828
|
...formikProps,
|
|
804
|
-
children: ({ setFieldValue, dirty, handleSubmit, isValid, values }) => /* @__PURE__ */
|
|
805
|
-
/* @__PURE__ */
|
|
806
|
-
|
|
807
|
-
Array.isArray(form
|
|
808
|
-
|
|
829
|
+
children: ({ setFieldValue, dirty, handleSubmit, isValid, values }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
830
|
+
/* @__PURE__ */ jsx(Modal.Body, { pb: "6", children: /* @__PURE__ */ jsxs(Form, { children: [
|
|
831
|
+
React.isValidElement(form) && form,
|
|
832
|
+
Array.isArray(form) && /* @__PURE__ */ jsx(FormRenderer, { form }),
|
|
833
|
+
isFunction(form) && /* @__PURE__ */ jsx(FormRenderer, { form: form(data ?? values) })
|
|
809
834
|
] }) }),
|
|
810
|
-
/* @__PURE__ */
|
|
811
|
-
/* @__PURE__ */
|
|
812
|
-
|
|
835
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [
|
|
836
|
+
/* @__PURE__ */ jsx(
|
|
837
|
+
Button,
|
|
813
838
|
{
|
|
814
839
|
disabled: mutation.isLoading,
|
|
815
840
|
onClick: onClose,
|
|
@@ -818,8 +843,8 @@ function ItemEditDialog({
|
|
|
818
843
|
children: cancelLabel
|
|
819
844
|
}
|
|
820
845
|
),
|
|
821
|
-
/* @__PURE__ */
|
|
822
|
-
|
|
846
|
+
/* @__PURE__ */ jsx(
|
|
847
|
+
Button,
|
|
823
848
|
{
|
|
824
849
|
type: "submit",
|
|
825
850
|
disabled: !dirty || mutation.isLoading,
|
|
@@ -831,19 +856,20 @@ function ItemEditDialog({
|
|
|
831
856
|
] })
|
|
832
857
|
}
|
|
833
858
|
) }),
|
|
834
|
-
mutation.isLoading && /* @__PURE__ */
|
|
859
|
+
mutation.isLoading && /* @__PURE__ */ jsx(ModalLoadingOverlay, {})
|
|
835
860
|
]
|
|
836
861
|
}
|
|
837
862
|
);
|
|
838
863
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
864
|
+
|
|
865
|
+
function QueryWrapperDialog({ api, fn, transformFn, config, onClose, queryId, invalidateQueryKey }) {
|
|
866
|
+
const { data, isFetching } = useApiQuery(
|
|
867
|
+
api.queryKey,
|
|
868
|
+
fn === "get" || fn === "getTransformed" ? api.get : api.getAll,
|
|
843
869
|
void 0,
|
|
844
870
|
{ retryOnMount: false, refetchOnMount: false, refetchOnWindowFocus: false }
|
|
845
871
|
);
|
|
846
|
-
const transformedData =
|
|
872
|
+
const transformedData = React.useMemo(() => {
|
|
847
873
|
if (data && (fn === "getTransformed" || fn === "getAllTransformed")) {
|
|
848
874
|
if (!transformFn)
|
|
849
875
|
console.warn(`QueryWrapperDialog: you forgot to pass transformFn as parameter for fn ${fn}`);
|
|
@@ -853,10 +879,11 @@ function QueryWrapperDialog({ api: api$1, fn, transformFn, config, onClose, quer
|
|
|
853
879
|
}, [data, fn, transformFn]);
|
|
854
880
|
if (isFetching)
|
|
855
881
|
return null;
|
|
856
|
-
return /* @__PURE__ */
|
|
882
|
+
return /* @__PURE__ */ jsx(ItemEditDialog, { ...config(transformedData), queryId, invalidateQueryKey, show: true, onClose });
|
|
857
883
|
}
|
|
884
|
+
|
|
858
885
|
function MultiQueryWrapperDialog({ queries, config, onClose, queryId, invalidateQueryKey }) {
|
|
859
|
-
const { data, isFetching, isError } =
|
|
886
|
+
const { data, isFetching, isError } = useApiQueries(queries.map((q) => ({
|
|
860
887
|
queryKey: q.api.queryKey,
|
|
861
888
|
queryFn: q.fn == "get" ? q.api.get : q.api.getAll,
|
|
862
889
|
queryOptions: {
|
|
@@ -864,33 +891,36 @@ function MultiQueryWrapperDialog({ queries, config, onClose, queryId, invalidate
|
|
|
864
891
|
staleTime: q.cache === false ? 0 : void 0
|
|
865
892
|
}
|
|
866
893
|
})));
|
|
867
|
-
const transformedData =
|
|
894
|
+
const transformedData = React.useMemo(() => {
|
|
868
895
|
return data?.map((d, index) => queries[index]?.transformFn ? queries[index]?.transformFn?.(d) : d);
|
|
869
896
|
}, [data, queries]);
|
|
870
|
-
return /* @__PURE__ */
|
|
897
|
+
return /* @__PURE__ */ jsx(ItemEditDialog, { isPreloading: isFetching, ...config(...transformedData), queryId, invalidateQueryKey, show: true, onClose });
|
|
871
898
|
}
|
|
899
|
+
|
|
872
900
|
function DialogRenderer({ config, onClose, invalidateQueryKey, queryId }) {
|
|
873
901
|
const { type, ...props } = config;
|
|
874
902
|
if (config.type === "dialog")
|
|
875
|
-
return /* @__PURE__ */
|
|
903
|
+
return /* @__PURE__ */ jsx(ItemEditDialog, { ...props, queryId, invalidateQueryKey, show: true, onClose });
|
|
876
904
|
if (config.type === "query")
|
|
877
|
-
return /* @__PURE__ */
|
|
905
|
+
return /* @__PURE__ */ jsx(QueryWrapperDialog, { ...props, queryId, invalidateQueryKey, onClose });
|
|
878
906
|
if (config.type === "multiQuery")
|
|
879
|
-
return /* @__PURE__ */
|
|
907
|
+
return /* @__PURE__ */ jsx(MultiQueryWrapperDialog, { ...props, queryId, invalidateQueryKey, onClose });
|
|
880
908
|
return null;
|
|
881
909
|
}
|
|
910
|
+
|
|
882
911
|
function RefreshButton({ queryKey }) {
|
|
883
|
-
const invalidate =
|
|
884
|
-
|
|
885
|
-
return /* @__PURE__ */
|
|
912
|
+
const invalidate = useInvalidateQuery(queryKey);
|
|
913
|
+
useHotkeys("ctrl+r", () => invalidate(), { preventDefault: true }, [invalidate]);
|
|
914
|
+
return /* @__PURE__ */ jsx(ButtonBarButton, { scheme: "dark", size: "sm", aspectRatio: "square", variant: "borderless", onClick: invalidate, children: /* @__PURE__ */ jsx(Icon, { path: mdiRefresh }) });
|
|
886
915
|
}
|
|
916
|
+
|
|
887
917
|
function ItemDeleteDialog({
|
|
888
918
|
title,
|
|
889
919
|
actionButtonLabel,
|
|
890
920
|
closeActionButtonLabel = "Cancel",
|
|
891
921
|
itemLabel,
|
|
892
922
|
queryId = "",
|
|
893
|
-
api
|
|
923
|
+
api,
|
|
894
924
|
apiFn,
|
|
895
925
|
invalidateQueriesOnSuccess = true,
|
|
896
926
|
invalidateQueryKey,
|
|
@@ -902,15 +932,15 @@ function ItemDeleteDialog({
|
|
|
902
932
|
onSuccess,
|
|
903
933
|
...props
|
|
904
934
|
}) {
|
|
905
|
-
const fn = apiFn ? api
|
|
906
|
-
const mutation = invalidateQueriesOnSuccess ?
|
|
907
|
-
const mutate =
|
|
935
|
+
const fn = apiFn ? api[apiFn] : api.delete;
|
|
936
|
+
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(fn, invalidateQueryKey ?? api.queryKey) : useApiMutation(fn, api.queryKey);
|
|
937
|
+
const mutate = useMutate(mutation, { onSuccess: () => {
|
|
908
938
|
onClose?.();
|
|
909
939
|
onSuccess?.();
|
|
910
940
|
} });
|
|
911
|
-
const handleDelete =
|
|
912
|
-
return /* @__PURE__ */
|
|
913
|
-
|
|
941
|
+
const handleDelete = React.useCallback(() => mutate(queryId), [mutate, queryId]);
|
|
942
|
+
return /* @__PURE__ */ jsxs(
|
|
943
|
+
Modal,
|
|
914
944
|
{
|
|
915
945
|
size,
|
|
916
946
|
show,
|
|
@@ -920,14 +950,14 @@ function ItemDeleteDialog({
|
|
|
920
950
|
transition: true,
|
|
921
951
|
...props,
|
|
922
952
|
children: [
|
|
923
|
-
/* @__PURE__ */
|
|
924
|
-
/* @__PURE__ */
|
|
953
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: title || `Delete ${itemLabel}` }),
|
|
954
|
+
/* @__PURE__ */ jsxs(Modal.Body, { pb: "6", children: [
|
|
925
955
|
!msg && `Do you really want to delete ${itemLabel}?`,
|
|
926
|
-
msg &&
|
|
956
|
+
msg && runIfFn(msg, itemLabel)
|
|
927
957
|
] }),
|
|
928
|
-
/* @__PURE__ */
|
|
929
|
-
/* @__PURE__ */
|
|
930
|
-
|
|
958
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [
|
|
959
|
+
/* @__PURE__ */ jsx(
|
|
960
|
+
Button,
|
|
931
961
|
{
|
|
932
962
|
disabled: mutation.isPending,
|
|
933
963
|
onClick: onClose,
|
|
@@ -937,37 +967,38 @@ function ItemDeleteDialog({
|
|
|
937
967
|
children: closeActionButtonLabel
|
|
938
968
|
}
|
|
939
969
|
),
|
|
940
|
-
/* @__PURE__ */
|
|
970
|
+
/* @__PURE__ */ jsx(Button, { scheme: "danger", disabled: mutation.isPending, onClick: handleDelete, children: actionButtonLabel || "Delete" })
|
|
941
971
|
] }),
|
|
942
|
-
mutation.isPending && /* @__PURE__ */
|
|
972
|
+
mutation.isPending && /* @__PURE__ */ jsx(ModalLoadingOverlay, {})
|
|
943
973
|
]
|
|
944
974
|
}
|
|
945
975
|
);
|
|
946
976
|
}
|
|
947
|
-
|
|
977
|
+
|
|
978
|
+
const [provider, useContext] = createContext();
|
|
948
979
|
function TableViewProvider({ editView, deleteItem, queryKey, children }) {
|
|
949
|
-
const openLink =
|
|
950
|
-
const navigate =
|
|
951
|
-
const [dialog, setDialog] =
|
|
952
|
-
const onCloseDialog =
|
|
953
|
-
const onAction =
|
|
980
|
+
const openLink = useOpenLink();
|
|
981
|
+
const navigate = useNavigate();
|
|
982
|
+
const [dialog, setDialog] = React.useState(null);
|
|
983
|
+
const onCloseDialog = React.useCallback(() => setDialog(null), [setDialog]);
|
|
984
|
+
const onAction = React.useCallback((action, item) => {
|
|
954
985
|
switch (action.type) {
|
|
955
986
|
case "view": {
|
|
956
|
-
navigate(
|
|
987
|
+
navigate(runIfFn(action.path, item));
|
|
957
988
|
break;
|
|
958
989
|
}
|
|
959
990
|
case "link": {
|
|
960
|
-
openLink(`${
|
|
991
|
+
openLink(`${AppEnv.websiteUrl()}/${runIfFn(action.path, item)}`);
|
|
961
992
|
break;
|
|
962
993
|
}
|
|
963
994
|
case "edit": {
|
|
964
|
-
const editConfig =
|
|
995
|
+
const editConfig = runIfFn(editView, item);
|
|
965
996
|
if (editConfig) {
|
|
966
997
|
if (editConfig.type == "customDialog") {
|
|
967
998
|
setDialog(editConfig.render({ show: true, onClose: onCloseDialog }));
|
|
968
999
|
} else {
|
|
969
1000
|
setDialog(
|
|
970
|
-
/* @__PURE__ */
|
|
1001
|
+
/* @__PURE__ */ jsx(
|
|
971
1002
|
DialogRenderer,
|
|
972
1003
|
{
|
|
973
1004
|
onClose: onCloseDialog,
|
|
@@ -982,9 +1013,9 @@ function TableViewProvider({ editView, deleteItem, queryKey, children }) {
|
|
|
982
1013
|
break;
|
|
983
1014
|
}
|
|
984
1015
|
case "delete": {
|
|
985
|
-
const deleteConfig =
|
|
1016
|
+
const deleteConfig = runIfFn(deleteItem, item);
|
|
986
1017
|
setDialog(
|
|
987
|
-
/* @__PURE__ */
|
|
1018
|
+
/* @__PURE__ */ jsx(
|
|
988
1019
|
ItemDeleteDialog,
|
|
989
1020
|
{
|
|
990
1021
|
show: true,
|
|
@@ -993,7 +1024,7 @@ function TableViewProvider({ editView, deleteItem, queryKey, children }) {
|
|
|
993
1024
|
invalidateQueryKey: queryKey,
|
|
994
1025
|
msg: item.msg,
|
|
995
1026
|
...deleteConfig,
|
|
996
|
-
itemLabel:
|
|
1027
|
+
itemLabel: runIfFn(deleteConfig.itemLabel, item)
|
|
997
1028
|
}
|
|
998
1029
|
)
|
|
999
1030
|
);
|
|
@@ -1001,27 +1032,29 @@ function TableViewProvider({ editView, deleteItem, queryKey, children }) {
|
|
|
1001
1032
|
}
|
|
1002
1033
|
}
|
|
1003
1034
|
}, [navigate, editView, deleteItem]);
|
|
1004
|
-
const Provider =
|
|
1035
|
+
const Provider = provider;
|
|
1005
1036
|
const value = {
|
|
1006
1037
|
dialog,
|
|
1007
1038
|
onAction
|
|
1008
1039
|
};
|
|
1009
|
-
return /* @__PURE__ */
|
|
1040
|
+
return /* @__PURE__ */ jsx(Provider, { value, children });
|
|
1010
1041
|
}
|
|
1011
|
-
|
|
1042
|
+
|
|
1043
|
+
function TableRowPublishPostButton$1({ id, api, status, invalidateQueryKey, ...props }) {
|
|
1012
1044
|
const isDraft = status == "draft";
|
|
1013
|
-
const mutation =
|
|
1014
|
-
const publish =
|
|
1045
|
+
const mutation = useInvalidateParentMutation(isDraft ? api.publish : api.unpublish, invalidateQueryKey ?? api.queryKey, { networkMode: "always" });
|
|
1046
|
+
const publish = React.useCallback((event) => {
|
|
1015
1047
|
event?.preventDefault();
|
|
1016
1048
|
event?.stopPropagation();
|
|
1017
1049
|
mutation.reset();
|
|
1018
|
-
mutation.mutateAsync(id).then(() =>
|
|
1050
|
+
mutation.mutateAsync(id).then(() => toast.success(isDraft ? "Published!" : "Unpublished!")).catch((error) => toast.error(`Error: ${error}`));
|
|
1019
1051
|
}, [mutation, id]);
|
|
1020
|
-
return /* @__PURE__ */
|
|
1052
|
+
return /* @__PURE__ */ jsx(Button, { variant: "borderless", corners: "square", scheme: "dark", onClick: publish, ...props, children: /* @__PURE__ */ jsx(Icon, { path: isDraft ? mdiPublish : mdiPublishOff, size: "sm" }) });
|
|
1021
1053
|
}
|
|
1054
|
+
|
|
1022
1055
|
function TableRowActionButton({ icon, children, ...props }) {
|
|
1023
|
-
return /* @__PURE__ */
|
|
1024
|
-
|
|
1056
|
+
return /* @__PURE__ */ jsxs(
|
|
1057
|
+
Button,
|
|
1025
1058
|
{
|
|
1026
1059
|
dflex: true,
|
|
1027
1060
|
alignContent: "center",
|
|
@@ -1035,29 +1068,30 @@ function TableRowActionButton({ icon, children, ...props }) {
|
|
|
1035
1068
|
gap: "2",
|
|
1036
1069
|
...props,
|
|
1037
1070
|
children: [
|
|
1038
|
-
icon && /* @__PURE__ */
|
|
1071
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon, size: "sm" }),
|
|
1039
1072
|
children
|
|
1040
1073
|
]
|
|
1041
1074
|
}
|
|
1042
1075
|
);
|
|
1043
1076
|
}
|
|
1077
|
+
|
|
1044
1078
|
function TableRowActionsView({ row, onAction, rowActions, api, queryKey }) {
|
|
1045
1079
|
const item = row.original;
|
|
1046
|
-
return /* @__PURE__ */
|
|
1047
|
-
(action, index) => /* @__PURE__ */
|
|
1048
|
-
action.type === "publish" && /* @__PURE__ */
|
|
1049
|
-
action.type == "custom" && /* @__PURE__ */
|
|
1050
|
-
!["publish", "custom"].includes(action.type) && /* @__PURE__ */
|
|
1080
|
+
return /* @__PURE__ */ jsx("div", { dflex: true, w: "full", alignItems: "stretch", placeContent: "end", h: "full", children: runIfFn(rowActions, item)?.map(
|
|
1081
|
+
(action, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
1082
|
+
action.type === "publish" && /* @__PURE__ */ jsx(TableRowPublishPostButton$1, { id: item.id, api: action.api ?? api, status: item.status, invalidateQueryKey: queryKey }),
|
|
1083
|
+
action.type == "custom" && /* @__PURE__ */ jsx(Fragment, { children: action.component(item, queryKey, action.icon, action.label) }),
|
|
1084
|
+
!["publish", "custom"].includes(action.type) && /* @__PURE__ */ jsx(ActionButton, { onClick: () => onAction(action, item), scheme: schemes$1[action.type], children: /* @__PURE__ */ jsx(Icon, { path: icons[action.type], size: "sm" }) })
|
|
1051
1085
|
] }, index)
|
|
1052
1086
|
) });
|
|
1053
1087
|
}
|
|
1054
|
-
function
|
|
1055
|
-
const handleClick =
|
|
1088
|
+
function ActionButton({ onClick, ...props }) {
|
|
1089
|
+
const handleClick = React.useCallback((event) => {
|
|
1056
1090
|
event?.preventDefault();
|
|
1057
1091
|
event?.stopPropagation();
|
|
1058
1092
|
onClick?.(event);
|
|
1059
1093
|
}, [onClick]);
|
|
1060
|
-
return /* @__PURE__ */
|
|
1094
|
+
return /* @__PURE__ */ jsx(
|
|
1061
1095
|
TableRowActionButton,
|
|
1062
1096
|
{
|
|
1063
1097
|
onClick: handleClick,
|
|
@@ -1065,15 +1099,15 @@ function ActionButton2({ onClick, ...props }) {
|
|
|
1065
1099
|
}
|
|
1066
1100
|
);
|
|
1067
1101
|
}
|
|
1068
|
-
|
|
1069
|
-
"link":
|
|
1070
|
-
"view":
|
|
1071
|
-
"edit":
|
|
1072
|
-
"delete":
|
|
1073
|
-
"publish":
|
|
1102
|
+
const icons = {
|
|
1103
|
+
"link": mdiOpenInNew,
|
|
1104
|
+
"view": mdiEye,
|
|
1105
|
+
"edit": mdiPencil,
|
|
1106
|
+
"delete": mdiDelete,
|
|
1107
|
+
"publish": mdiDelete,
|
|
1074
1108
|
"custom": ""
|
|
1075
1109
|
};
|
|
1076
|
-
|
|
1110
|
+
const schemes$1 = {
|
|
1077
1111
|
"link": "dark",
|
|
1078
1112
|
"view": "dark",
|
|
1079
1113
|
"edit": "dark",
|
|
@@ -1081,40 +1115,41 @@ var schemes = {
|
|
|
1081
1115
|
"publish": "dark",
|
|
1082
1116
|
"custom": "dark"
|
|
1083
1117
|
};
|
|
1118
|
+
|
|
1084
1119
|
function useTableProps(api, table, rowActions, queryParams) {
|
|
1085
|
-
const navigate =
|
|
1086
|
-
const nextRouter =
|
|
1087
|
-
const openLink =
|
|
1088
|
-
const { onAction } =
|
|
1120
|
+
const navigate = useNavigate();
|
|
1121
|
+
const nextRouter = useRouter();
|
|
1122
|
+
const openLink = useOpenLink();
|
|
1123
|
+
const { onAction } = useContext();
|
|
1089
1124
|
const { onRowClick, columns: c, ...props } = table;
|
|
1090
|
-
const onRowClickHandler =
|
|
1091
|
-
const config =
|
|
1125
|
+
const onRowClickHandler = React.useCallback((item) => {
|
|
1126
|
+
const config = runIfFn(onRowClick, item);
|
|
1092
1127
|
if (config) {
|
|
1093
1128
|
switch (config.type) {
|
|
1094
1129
|
case "navigate": {
|
|
1095
|
-
navigate(
|
|
1130
|
+
navigate(runIfFn(config.path, item) ?? "");
|
|
1096
1131
|
break;
|
|
1097
1132
|
}
|
|
1098
1133
|
case "nextpush": {
|
|
1099
|
-
nextRouter.push(
|
|
1134
|
+
nextRouter.push(runIfFn(config.path, item));
|
|
1100
1135
|
break;
|
|
1101
1136
|
}
|
|
1102
1137
|
case "link": {
|
|
1103
|
-
openLink(`${
|
|
1138
|
+
openLink(`${AppEnv.websiteUrl()}/${runIfFn(config.path, item)}`);
|
|
1104
1139
|
break;
|
|
1105
1140
|
}
|
|
1106
1141
|
}
|
|
1107
1142
|
}
|
|
1108
1143
|
}, [navigate, onRowClick]);
|
|
1109
|
-
const columns =
|
|
1144
|
+
const columns = React.useMemo(() => {
|
|
1110
1145
|
const columns2 = table.columns.concat([]);
|
|
1111
1146
|
if (rowActions) {
|
|
1112
1147
|
columns2.push(
|
|
1113
|
-
|
|
1148
|
+
createColumnHelper().display(
|
|
1114
1149
|
{
|
|
1115
1150
|
id: "actions",
|
|
1116
1151
|
header: "Actions",
|
|
1117
|
-
cell: (props2) => /* @__PURE__ */
|
|
1152
|
+
cell: (props2) => /* @__PURE__ */ jsx(TableRowActionsView, { row: props2.row, onAction, rowActions, api, queryKey: api.queryKey })
|
|
1118
1153
|
}
|
|
1119
1154
|
)
|
|
1120
1155
|
);
|
|
@@ -1129,8 +1164,9 @@ function useTableProps(api, table, rowActions, queryParams) {
|
|
|
1129
1164
|
tableProps.queryFn = api.search;
|
|
1130
1165
|
return tableProps;
|
|
1131
1166
|
}
|
|
1167
|
+
|
|
1132
1168
|
function useId(queryField) {
|
|
1133
|
-
const params =
|
|
1169
|
+
const params = useParams();
|
|
1134
1170
|
if (queryField === void 0)
|
|
1135
1171
|
return void 0;
|
|
1136
1172
|
const { [queryField]: id } = params;
|
|
@@ -1138,16 +1174,16 @@ function useId(queryField) {
|
|
|
1138
1174
|
}
|
|
1139
1175
|
function TableView({ queryField, title, subtitle, screen, ...props }) {
|
|
1140
1176
|
const id = useId(queryField);
|
|
1141
|
-
const _screen =
|
|
1142
|
-
return /* @__PURE__ */
|
|
1177
|
+
const _screen = runIfFn(screen, id);
|
|
1178
|
+
return /* @__PURE__ */ jsx(PageContainer, { bgColor: "white", ...props, children: /* @__PURE__ */ jsx(TableContainer, { columns: _screen.table.columns, initialVisibleColumns: _screen.table.initialVisibleColumns, filtersMethod: _screen.table.filtersMethod, children: /* @__PURE__ */ jsx(TT, { id, title, subtitle, screen: _screen }) }) });
|
|
1143
1179
|
}
|
|
1144
1180
|
function TT({ id, title, subtitle, screen }) {
|
|
1145
|
-
const { setRowSelection } =
|
|
1146
|
-
const { api, table
|
|
1147
|
-
const tableApi =
|
|
1148
|
-
return /* @__PURE__ */
|
|
1149
|
-
/* @__PURE__ */
|
|
1150
|
-
filters && /* @__PURE__ */
|
|
1181
|
+
const { setRowSelection } = useTableContext();
|
|
1182
|
+
const { api, table, filters, massActions, buttonBar, rowActions, createView, editView, deleteItem, breadcrumbs } = screen;
|
|
1183
|
+
const tableApi = runIfFn(api, id ?? "");
|
|
1184
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1185
|
+
/* @__PURE__ */ jsx(TableTopBar, { title, breadcrumbs, children: /* @__PURE__ */ jsx(TableButtonBar, { buttonBar, createView, editView, api: tableApi, queryKey: tableApi.queryKey, children: filters && /* @__PURE__ */ jsx(TableFilterButton, {}) }) }),
|
|
1186
|
+
filters && /* @__PURE__ */ jsx(
|
|
1151
1187
|
TableFilters,
|
|
1152
1188
|
{
|
|
1153
1189
|
form: filters.form,
|
|
@@ -1156,28 +1192,28 @@ function TT({ id, title, subtitle, screen }) {
|
|
|
1156
1192
|
processInput: filters.processInput
|
|
1157
1193
|
}
|
|
1158
1194
|
),
|
|
1159
|
-
massActions && /* @__PURE__ */
|
|
1160
|
-
/* @__PURE__ */
|
|
1161
|
-
/* @__PURE__ */
|
|
1162
|
-
/* @__PURE__ */
|
|
1195
|
+
massActions && /* @__PURE__ */ jsx(TableMassActions, { actions: massActions.items }),
|
|
1196
|
+
/* @__PURE__ */ jsxs(TableViewProvider, { queryKey: tableApi.queryKey, editView, deleteItem, children: [
|
|
1197
|
+
/* @__PURE__ */ jsx(TableWrapper, { table: { ...table, onSelectionChange: setRowSelection }, rowActions, api: tableApi, subtitle, queryParams: screen.queryParams }),
|
|
1198
|
+
/* @__PURE__ */ jsx(TableDialogManager, {})
|
|
1163
1199
|
] })
|
|
1164
1200
|
] });
|
|
1165
1201
|
}
|
|
1166
1202
|
function TableButtonBar({ buttonBar, queryKey, createView, editView, api, children }) {
|
|
1167
|
-
const createDialogFn =
|
|
1203
|
+
const createDialogFn = React.useCallback((data) => {
|
|
1168
1204
|
return (onClose) => {
|
|
1169
|
-
const view =
|
|
1205
|
+
const view = runIfFn(createView, data) ?? runIfFn(editView, null);
|
|
1170
1206
|
if (view.type == "customDialog")
|
|
1171
1207
|
return view.render({ show: true, onClose });
|
|
1172
1208
|
else
|
|
1173
|
-
return /* @__PURE__ */
|
|
1209
|
+
return /* @__PURE__ */ jsx(DialogRenderer, { config: view, onClose, invalidateQueryKey: api.queryKey });
|
|
1174
1210
|
};
|
|
1175
1211
|
}, [createView, editView, api]);
|
|
1176
|
-
return /* @__PURE__ */
|
|
1177
|
-
/* @__PURE__ */
|
|
1212
|
+
return /* @__PURE__ */ jsxs(ButtonBar, { children: [
|
|
1213
|
+
/* @__PURE__ */ jsx(RefreshButton, { queryKey }),
|
|
1178
1214
|
buttonBar && buttonBar.map(
|
|
1179
|
-
(button, index) => /* @__PURE__ */
|
|
1180
|
-
button.type === "create" && editView && /* @__PURE__ */
|
|
1215
|
+
(button, index) => /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
1216
|
+
button.type === "create" && editView && /* @__PURE__ */ jsx(
|
|
1181
1217
|
TableCreateButton,
|
|
1182
1218
|
{
|
|
1183
1219
|
buildDialog: createDialogFn(button.data),
|
|
@@ -1185,33 +1221,34 @@ function TableButtonBar({ buttonBar, queryKey, createView, editView, api, childr
|
|
|
1185
1221
|
children: button.label
|
|
1186
1222
|
}
|
|
1187
1223
|
),
|
|
1188
|
-
button.type === "invalidate" && /* @__PURE__ */
|
|
1224
|
+
button.type === "invalidate" && /* @__PURE__ */ jsx(InvalidateButton, { pathOrPermalink: button.pathOrPermalink }),
|
|
1189
1225
|
button.type === "custom" && button.render()
|
|
1190
1226
|
] }, index)
|
|
1191
1227
|
),
|
|
1192
1228
|
children
|
|
1193
1229
|
] });
|
|
1194
1230
|
}
|
|
1195
|
-
function TableWrapper({ table
|
|
1196
|
-
const tableProps = useTableProps(api, table
|
|
1197
|
-
const _subtitle =
|
|
1231
|
+
function TableWrapper({ table, subtitle, rowActions, api, queryParams }) {
|
|
1232
|
+
const tableProps = useTableProps(api, table, rowActions, queryParams);
|
|
1233
|
+
const _subtitle = React.useMemo(() => {
|
|
1198
1234
|
if (!subtitle)
|
|
1199
1235
|
return void 0;
|
|
1200
1236
|
return (data) => {
|
|
1201
|
-
return /* @__PURE__ */
|
|
1237
|
+
return /* @__PURE__ */ jsx("div", { textSize: "lg", textColor: "#475569", fontWeight: "600", children: isFunction(subtitle) ? subtitle(data) : subtitle });
|
|
1202
1238
|
};
|
|
1203
1239
|
}, [subtitle]);
|
|
1204
|
-
return /* @__PURE__ */
|
|
1240
|
+
return /* @__PURE__ */ jsx(Table, { ...tableProps, p: "8", title: _subtitle });
|
|
1205
1241
|
}
|
|
1206
1242
|
function TableDialogManager() {
|
|
1207
|
-
const { dialog } =
|
|
1243
|
+
const { dialog } = useContext();
|
|
1208
1244
|
return dialog;
|
|
1209
1245
|
}
|
|
1246
|
+
|
|
1210
1247
|
function useQueries(queries) {
|
|
1211
|
-
const params =
|
|
1212
|
-
const { data, isFetching, isError } =
|
|
1248
|
+
const params = useParams();
|
|
1249
|
+
const { data, isFetching, isError } = useApiQueries(queries.map((q) => {
|
|
1213
1250
|
if (!q.queryField) {
|
|
1214
|
-
const api2 =
|
|
1251
|
+
const api2 = runIfFn(q.api);
|
|
1215
1252
|
return {
|
|
1216
1253
|
queryKey: api2.queryKey,
|
|
1217
1254
|
queryFn: q.fn == "get" ? api2.get : api2.getAll,
|
|
@@ -1219,11 +1256,11 @@ function useQueries(queries) {
|
|
|
1219
1256
|
};
|
|
1220
1257
|
}
|
|
1221
1258
|
const id = params[q.queryField];
|
|
1222
|
-
const api =
|
|
1259
|
+
const api = runIfFn(q.api, id);
|
|
1223
1260
|
return {
|
|
1224
1261
|
queryKey: api.queryKey,
|
|
1225
1262
|
queryFn: q.fn == "get" ? api.get : api.getAll,
|
|
1226
|
-
queryParam: q.fn == "getAll" ? q.params :
|
|
1263
|
+
queryParam: q.fn == "getAll" ? q.params : isFunction(q.api) ? void 0 : id
|
|
1227
1264
|
};
|
|
1228
1265
|
}));
|
|
1229
1266
|
let transformedData = void 0;
|
|
@@ -1233,17 +1270,17 @@ function useQueries(queries) {
|
|
|
1233
1270
|
return { data: transformedData, isFetching, isError };
|
|
1234
1271
|
}
|
|
1235
1272
|
function useInvalidate(queries) {
|
|
1236
|
-
const queryClient =
|
|
1237
|
-
const params =
|
|
1238
|
-
const invalidate =
|
|
1273
|
+
const queryClient = useQueryClient();
|
|
1274
|
+
const params = useParams();
|
|
1275
|
+
const invalidate = React.useCallback(
|
|
1239
1276
|
() => {
|
|
1240
1277
|
const queryKeys = [];
|
|
1241
1278
|
queries.forEach((q) => {
|
|
1242
|
-
if (!q.queryField || !
|
|
1279
|
+
if (!q.queryField || !isFunction(q.api)) {
|
|
1243
1280
|
queryKeys.push(q.api.queryKey);
|
|
1244
1281
|
} else {
|
|
1245
1282
|
const id = params[q.queryField];
|
|
1246
|
-
const api =
|
|
1283
|
+
const api = runIfFn(q.api, id);
|
|
1247
1284
|
queryKeys.push(api.queryKey);
|
|
1248
1285
|
}
|
|
1249
1286
|
});
|
|
@@ -1262,29 +1299,32 @@ function MultiQueryWrapper({
|
|
|
1262
1299
|
const { data, isFetching, isError } = useQueries(queries);
|
|
1263
1300
|
const invalidate = useInvalidate(queries);
|
|
1264
1301
|
if (isFetching)
|
|
1265
|
-
return /* @__PURE__ */
|
|
1302
|
+
return /* @__PURE__ */ jsx(QueryLoadingState, { w: "full", h: "100vh" });
|
|
1266
1303
|
if (isError || !data)
|
|
1267
|
-
return /* @__PURE__ */
|
|
1268
|
-
return /* @__PURE__ */
|
|
1304
|
+
return /* @__PURE__ */ jsx(RetryOnError, { p: "0", w: "full", h: "100vh", onClick: invalidate });
|
|
1305
|
+
return /* @__PURE__ */ jsx(ScreenRenderer, { config: config(...data), tabbed, ...props });
|
|
1269
1306
|
}
|
|
1307
|
+
|
|
1270
1308
|
function ScreenRenderer({ config, tabbed, ...props }) {
|
|
1271
1309
|
if (config.type === "table")
|
|
1272
|
-
return /* @__PURE__ */
|
|
1310
|
+
return /* @__PURE__ */ jsx(TableView, { ...config, ...props });
|
|
1273
1311
|
if (config.type === "tabbed")
|
|
1274
|
-
return /* @__PURE__ */
|
|
1312
|
+
return /* @__PURE__ */ jsx(TabbedView, { ...config, ...props });
|
|
1275
1313
|
if (config.type === "details")
|
|
1276
|
-
return /* @__PURE__ */
|
|
1314
|
+
return /* @__PURE__ */ jsx(DetailsView, { ...config, tabbed, ...props });
|
|
1277
1315
|
if (config.type === "query")
|
|
1278
|
-
return /* @__PURE__ */
|
|
1316
|
+
return /* @__PURE__ */ jsx(QueryWrapper, { ...config, tabbed, ...props });
|
|
1279
1317
|
if (config.type === "multiQuery")
|
|
1280
|
-
return /* @__PURE__ */
|
|
1281
|
-
return /* @__PURE__ */
|
|
1318
|
+
return /* @__PURE__ */ jsx(MultiQueryWrapper, { ...config, tabbed, ...props });
|
|
1319
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
1282
1320
|
}
|
|
1321
|
+
|
|
1283
1322
|
function Content({ ...props }) {
|
|
1284
|
-
return /* @__PURE__ */
|
|
1323
|
+
return /* @__PURE__ */ jsx("div", { w: "100%", h: "100%", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx(Outlet, {}) });
|
|
1285
1324
|
}
|
|
1325
|
+
|
|
1286
1326
|
function SelectedIndicator({ darkMode }) {
|
|
1287
|
-
return /* @__PURE__ */
|
|
1327
|
+
return /* @__PURE__ */ jsx(
|
|
1288
1328
|
"div",
|
|
1289
1329
|
{
|
|
1290
1330
|
position: "absolute",
|
|
@@ -1297,9 +1337,10 @@ function SelectedIndicator({ darkMode }) {
|
|
|
1297
1337
|
}
|
|
1298
1338
|
);
|
|
1299
1339
|
}
|
|
1340
|
+
|
|
1300
1341
|
function MenuButton({ depth, darkMode, icon, selected, children, ...props }) {
|
|
1301
|
-
return /* @__PURE__ */
|
|
1302
|
-
|
|
1342
|
+
return /* @__PURE__ */ jsxs(
|
|
1343
|
+
Button,
|
|
1303
1344
|
{
|
|
1304
1345
|
as: "li",
|
|
1305
1346
|
minH: "8",
|
|
@@ -1320,19 +1361,20 @@ function MenuButton({ depth, darkMode, icon, selected, children, ...props }) {
|
|
|
1320
1361
|
gap: "3",
|
|
1321
1362
|
...props,
|
|
1322
1363
|
children: [
|
|
1323
|
-
icon && /* @__PURE__ */
|
|
1364
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon, opacity: selected ? "100" : "60" }),
|
|
1324
1365
|
children
|
|
1325
1366
|
]
|
|
1326
1367
|
}
|
|
1327
1368
|
);
|
|
1328
1369
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1370
|
+
|
|
1371
|
+
function MenuItem$1({ icon, path, depth, darkMode, subMenu, ...props }) {
|
|
1372
|
+
const location = useLocation();
|
|
1331
1373
|
const selected = path == "/" ? location.pathname == "/" : location.pathname.startsWith(path.startsWith("/") ? path : `/${path}`);
|
|
1332
|
-
const match =
|
|
1333
|
-
return /* @__PURE__ */
|
|
1334
|
-
/* @__PURE__ */
|
|
1335
|
-
/* @__PURE__ */
|
|
1374
|
+
const match = useMatch("/" + path) != null;
|
|
1375
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1376
|
+
/* @__PURE__ */ jsxs(Link$1, { to: path, style: { position: "relative" }, children: [
|
|
1377
|
+
/* @__PURE__ */ jsx(
|
|
1336
1378
|
MenuButton,
|
|
1337
1379
|
{
|
|
1338
1380
|
depth,
|
|
@@ -1342,10 +1384,10 @@ function MenuItem({ icon, path, depth, darkMode, subMenu, ...props }) {
|
|
|
1342
1384
|
...props
|
|
1343
1385
|
}
|
|
1344
1386
|
),
|
|
1345
|
-
match && /* @__PURE__ */
|
|
1387
|
+
match && /* @__PURE__ */ jsx(SelectedIndicator, { darkMode })
|
|
1346
1388
|
] }),
|
|
1347
|
-
subMenu?.map((item, index) => /* @__PURE__ */
|
|
1348
|
-
MenuItem,
|
|
1389
|
+
subMenu?.map((item, index) => /* @__PURE__ */ jsx(
|
|
1390
|
+
MenuItem$1,
|
|
1349
1391
|
{
|
|
1350
1392
|
icon: item.icon,
|
|
1351
1393
|
path: item.path,
|
|
@@ -1358,13 +1400,14 @@ function MenuItem({ icon, path, depth, darkMode, subMenu, ...props }) {
|
|
|
1358
1400
|
))
|
|
1359
1401
|
] });
|
|
1360
1402
|
}
|
|
1403
|
+
|
|
1361
1404
|
function NextMenuItem({ icon, path, depth, darkMode, subMenu, ...props }) {
|
|
1362
|
-
const { pathname } =
|
|
1405
|
+
const { pathname } = useRouter();
|
|
1363
1406
|
const selected = path == "/" ? pathname == "/" : pathname.startsWith(path.startsWith("/") ? path : `/${path}`);
|
|
1364
1407
|
const match = path == "/" ? pathname == "/" : pathname == (path.startsWith("/") ? path : `/${path}`);
|
|
1365
|
-
return /* @__PURE__ */
|
|
1366
|
-
/* @__PURE__ */
|
|
1367
|
-
/* @__PURE__ */
|
|
1408
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1409
|
+
/* @__PURE__ */ jsxs(Link, { href: path, style: { position: "relative" }, children: [
|
|
1410
|
+
/* @__PURE__ */ jsx(
|
|
1368
1411
|
MenuButton,
|
|
1369
1412
|
{
|
|
1370
1413
|
depth,
|
|
@@ -1374,9 +1417,9 @@ function NextMenuItem({ icon, path, depth, darkMode, subMenu, ...props }) {
|
|
|
1374
1417
|
...props
|
|
1375
1418
|
}
|
|
1376
1419
|
),
|
|
1377
|
-
match && /* @__PURE__ */
|
|
1420
|
+
match && /* @__PURE__ */ jsx(SelectedIndicator, { darkMode })
|
|
1378
1421
|
] }),
|
|
1379
|
-
subMenu?.map((item, index) => /* @__PURE__ */
|
|
1422
|
+
subMenu?.map((item, index) => /* @__PURE__ */ jsx(
|
|
1380
1423
|
NextMenuItem,
|
|
1381
1424
|
{
|
|
1382
1425
|
icon: item.icon,
|
|
@@ -1390,13 +1433,14 @@ function NextMenuItem({ icon, path, depth, darkMode, subMenu, ...props }) {
|
|
|
1390
1433
|
))
|
|
1391
1434
|
] });
|
|
1392
1435
|
}
|
|
1436
|
+
|
|
1393
1437
|
function Menu({ darkMode, config, useNextRouter, ...props }) {
|
|
1394
|
-
const Comp = useNextRouter ? NextMenuItem : MenuItem;
|
|
1395
|
-
return /* @__PURE__ */
|
|
1438
|
+
const Comp = useNextRouter ? NextMenuItem : MenuItem$1;
|
|
1439
|
+
return /* @__PURE__ */ jsx("ul", { ...props, children: config.map((item, index) => {
|
|
1396
1440
|
if (item.type == "divider")
|
|
1397
|
-
return /* @__PURE__ */
|
|
1441
|
+
return /* @__PURE__ */ jsx(Divider, { title: item.label }, index);
|
|
1398
1442
|
if (item.type == "item") {
|
|
1399
|
-
return /* @__PURE__ */
|
|
1443
|
+
return /* @__PURE__ */ jsx(
|
|
1400
1444
|
Comp,
|
|
1401
1445
|
{
|
|
1402
1446
|
icon: item.icon,
|
|
@@ -1412,7 +1456,7 @@ function Menu({ darkMode, config, useNextRouter, ...props }) {
|
|
|
1412
1456
|
}) });
|
|
1413
1457
|
}
|
|
1414
1458
|
function Divider({ title }) {
|
|
1415
|
-
return /* @__PURE__ */
|
|
1459
|
+
return /* @__PURE__ */ jsx(
|
|
1416
1460
|
"div",
|
|
1417
1461
|
{
|
|
1418
1462
|
px: "2",
|
|
@@ -1427,13 +1471,14 @@ function Divider({ title }) {
|
|
|
1427
1471
|
}
|
|
1428
1472
|
);
|
|
1429
1473
|
}
|
|
1474
|
+
|
|
1430
1475
|
function UserBlock({ color, darkMode, menuConfig, path }) {
|
|
1431
|
-
const { isLoading, user } =
|
|
1432
|
-
const navigate =
|
|
1433
|
-
const handleClick =
|
|
1476
|
+
const { isLoading, user } = useSessionUser();
|
|
1477
|
+
const navigate = useNavigate();
|
|
1478
|
+
const handleClick = React.useCallback(() => navigate(path), [navigate, path]);
|
|
1434
1479
|
if (isLoading)
|
|
1435
1480
|
return null;
|
|
1436
|
-
return /* @__PURE__ */
|
|
1481
|
+
return /* @__PURE__ */ jsxs(
|
|
1437
1482
|
"div",
|
|
1438
1483
|
{
|
|
1439
1484
|
dflex: true,
|
|
@@ -1449,10 +1494,10 @@ function UserBlock({ color, darkMode, menuConfig, path }) {
|
|
|
1449
1494
|
textColor: darkMode ? "white" : "slate-800",
|
|
1450
1495
|
onClick: handleClick,
|
|
1451
1496
|
children: [
|
|
1452
|
-
/* @__PURE__ */
|
|
1453
|
-
/* @__PURE__ */
|
|
1454
|
-
/* @__PURE__ */
|
|
1455
|
-
|
|
1497
|
+
/* @__PURE__ */ jsx(Avatar, { size: "sm", src: user?.media?.url ?? "", name: `${user?.firstname} ${user?.lastname}` }),
|
|
1498
|
+
/* @__PURE__ */ jsx("span", { flexGrow: true, ms: "2", children: `${capitalize(user?.firstname || user?.lastname || "")}` }),
|
|
1499
|
+
/* @__PURE__ */ jsx(
|
|
1500
|
+
IconButton,
|
|
1456
1501
|
{
|
|
1457
1502
|
variant: "borderless",
|
|
1458
1503
|
corners: "pill",
|
|
@@ -1460,21 +1505,21 @@ function UserBlock({ color, darkMode, menuConfig, path }) {
|
|
|
1460
1505
|
textColor: darkMode ? "white" : "slate-800",
|
|
1461
1506
|
hover_textColor: darkMode ? "white" : "slate-800",
|
|
1462
1507
|
hover_bgColor: `${color}-${darkMode ? "900" : "200"}`,
|
|
1463
|
-
icon:
|
|
1508
|
+
icon: mdiCog,
|
|
1464
1509
|
onClick: handleClick
|
|
1465
1510
|
}
|
|
1466
1511
|
),
|
|
1467
|
-
/* @__PURE__ */
|
|
1512
|
+
/* @__PURE__ */ jsx(OverflowMenu, { color, darkMode, menuConfig })
|
|
1468
1513
|
]
|
|
1469
1514
|
}
|
|
1470
1515
|
);
|
|
1471
1516
|
}
|
|
1472
1517
|
function OverflowMenu({ color, darkMode, menuConfig }) {
|
|
1473
|
-
const [showPopup, setShowPopup] =
|
|
1474
|
-
const navigate =
|
|
1475
|
-
const logout =
|
|
1476
|
-
return /* @__PURE__ */
|
|
1477
|
-
|
|
1518
|
+
const [showPopup, setShowPopup] = React.useState(false);
|
|
1519
|
+
const navigate = useNavigate();
|
|
1520
|
+
const logout = useSessionLogout(false);
|
|
1521
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
|
|
1522
|
+
Popup,
|
|
1478
1523
|
{
|
|
1479
1524
|
show: showPopup,
|
|
1480
1525
|
position: "relative",
|
|
@@ -1486,10 +1531,10 @@ function OverflowMenu({ color, darkMode, menuConfig }) {
|
|
|
1486
1531
|
},
|
|
1487
1532
|
onHide: () => setShowPopup(false),
|
|
1488
1533
|
children: [
|
|
1489
|
-
/* @__PURE__ */
|
|
1490
|
-
|
|
1534
|
+
/* @__PURE__ */ jsx(
|
|
1535
|
+
IconButton,
|
|
1491
1536
|
{
|
|
1492
|
-
icon:
|
|
1537
|
+
icon: mdiDotsVertical,
|
|
1493
1538
|
variant: "borderless",
|
|
1494
1539
|
corners: "pill",
|
|
1495
1540
|
scheme: "dark",
|
|
@@ -1498,7 +1543,7 @@ function OverflowMenu({ color, darkMode, menuConfig }) {
|
|
|
1498
1543
|
hover_bgColor: `${color}-${darkMode ? "900" : "200"}`
|
|
1499
1544
|
}
|
|
1500
1545
|
),
|
|
1501
|
-
/* @__PURE__ */
|
|
1546
|
+
/* @__PURE__ */ jsxs(
|
|
1502
1547
|
"div",
|
|
1503
1548
|
{
|
|
1504
1549
|
bgColor: "white",
|
|
@@ -1514,11 +1559,11 @@ function OverflowMenu({ color, darkMode, menuConfig }) {
|
|
|
1514
1559
|
children: [
|
|
1515
1560
|
menuConfig && menuConfig.length > 0 && menuConfig.map((item, index) => {
|
|
1516
1561
|
if (item.type == "item") {
|
|
1517
|
-
return /* @__PURE__ */
|
|
1562
|
+
return /* @__PURE__ */ jsx(MenuItem, { icon: item.icon, onClick: () => navigate(item.path), children: item.label }, index);
|
|
1518
1563
|
}
|
|
1519
1564
|
return null;
|
|
1520
1565
|
}),
|
|
1521
|
-
/* @__PURE__ */
|
|
1566
|
+
/* @__PURE__ */ jsx(MenuItem, { icon: mdiLogout, onClick: logout, children: "Logout" })
|
|
1522
1567
|
]
|
|
1523
1568
|
}
|
|
1524
1569
|
)
|
|
@@ -1526,14 +1571,14 @@ function OverflowMenu({ color, darkMode, menuConfig }) {
|
|
|
1526
1571
|
}
|
|
1527
1572
|
) });
|
|
1528
1573
|
}
|
|
1529
|
-
function
|
|
1530
|
-
const handleClick =
|
|
1574
|
+
function MenuItem({ icon, onClick, children, ...props }) {
|
|
1575
|
+
const handleClick = React.useCallback((e) => {
|
|
1531
1576
|
e.preventDefault();
|
|
1532
1577
|
e.stopPropagation();
|
|
1533
1578
|
onClick?.(e);
|
|
1534
1579
|
}, []);
|
|
1535
|
-
return /* @__PURE__ */
|
|
1536
|
-
|
|
1580
|
+
return /* @__PURE__ */ jsxs(
|
|
1581
|
+
Button,
|
|
1537
1582
|
{
|
|
1538
1583
|
variant: "borderless",
|
|
1539
1584
|
scheme: "dark",
|
|
@@ -1548,14 +1593,15 @@ function MenuItem2({ icon, onClick, children, ...props }) {
|
|
|
1548
1593
|
textColor: "slate-700",
|
|
1549
1594
|
...props,
|
|
1550
1595
|
children: [
|
|
1551
|
-
icon && /* @__PURE__ */
|
|
1596
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon, size: "md" }),
|
|
1552
1597
|
children
|
|
1553
1598
|
]
|
|
1554
1599
|
}
|
|
1555
1600
|
);
|
|
1556
1601
|
}
|
|
1602
|
+
|
|
1557
1603
|
function Sidebar({ show, logo, title, menuConfig, userMenuConfig, userSettingsPath, color, darkMode, ...props }) {
|
|
1558
|
-
return /* @__PURE__ */
|
|
1604
|
+
return /* @__PURE__ */ jsxs(
|
|
1559
1605
|
"div",
|
|
1560
1606
|
{
|
|
1561
1607
|
dflex: true,
|
|
@@ -1567,8 +1613,8 @@ function Sidebar({ show, logo, title, menuConfig, userMenuConfig, userSettingsPa
|
|
|
1567
1613
|
textColor: darkMode ? "white" : "slate-800",
|
|
1568
1614
|
...props,
|
|
1569
1615
|
children: [
|
|
1570
|
-
/* @__PURE__ */
|
|
1571
|
-
|
|
1616
|
+
/* @__PURE__ */ jsxs(
|
|
1617
|
+
FlexCenter,
|
|
1572
1618
|
{
|
|
1573
1619
|
placeContent: "start",
|
|
1574
1620
|
p: "4",
|
|
@@ -1578,23 +1624,23 @@ function Sidebar({ show, logo, title, menuConfig, userMenuConfig, userSettingsPa
|
|
|
1578
1624
|
borderBColor: "slate-900",
|
|
1579
1625
|
borderOpacity: "5",
|
|
1580
1626
|
children: [
|
|
1581
|
-
logo ?? /* @__PURE__ */
|
|
1582
|
-
/* @__PURE__ */
|
|
1627
|
+
logo ?? /* @__PURE__ */ jsx(Logo, { width: 40, height: 40, darkMode }),
|
|
1628
|
+
/* @__PURE__ */ jsx("h1", { textSize: "md", children: title || AppEnv.appName() })
|
|
1583
1629
|
]
|
|
1584
1630
|
}
|
|
1585
1631
|
),
|
|
1586
|
-
/* @__PURE__ */
|
|
1587
|
-
/* @__PURE__ */
|
|
1632
|
+
/* @__PURE__ */ jsx(Menu, { overflowY: "auto", flexGrow: "1", p: "4", darkMode, config: menuConfig }),
|
|
1633
|
+
/* @__PURE__ */ jsx("div", { p: "2", children: /* @__PURE__ */ jsx(UserBlock, { darkMode, color, menuConfig: userMenuConfig, path: userSettingsPath }) })
|
|
1588
1634
|
]
|
|
1589
1635
|
}
|
|
1590
1636
|
);
|
|
1591
1637
|
}
|
|
1592
1638
|
function Logo({ width, height, darkMode, ...props }) {
|
|
1593
|
-
return /* @__PURE__ */
|
|
1594
|
-
|
|
1639
|
+
return /* @__PURE__ */ jsx("div", { ...props, children: /* @__PURE__ */ jsx(
|
|
1640
|
+
Image,
|
|
1595
1641
|
{
|
|
1596
1642
|
src: `/logo_${darkMode ? "light" : "dark"}.png`,
|
|
1597
|
-
alt:
|
|
1643
|
+
alt: AppEnv.appName() || "",
|
|
1598
1644
|
width,
|
|
1599
1645
|
height,
|
|
1600
1646
|
priority: true,
|
|
@@ -1602,8 +1648,9 @@ function Logo({ width, height, darkMode, ...props }) {
|
|
|
1602
1648
|
}
|
|
1603
1649
|
) });
|
|
1604
1650
|
}
|
|
1651
|
+
|
|
1605
1652
|
function AdminLayout({ color, darkMode, logo, title, menuConfig, userMenuConfig, userSettingsPath, ...props }) {
|
|
1606
|
-
return /* @__PURE__ */
|
|
1653
|
+
return /* @__PURE__ */ jsxs(
|
|
1607
1654
|
"div",
|
|
1608
1655
|
{
|
|
1609
1656
|
w: "full",
|
|
@@ -1613,7 +1660,7 @@ function AdminLayout({ color, darkMode, logo, title, menuConfig, userMenuConfig,
|
|
|
1613
1660
|
bgColor: `${color}-${darkMode ? "900" : "100"}`,
|
|
1614
1661
|
...props,
|
|
1615
1662
|
children: [
|
|
1616
|
-
/* @__PURE__ */
|
|
1663
|
+
/* @__PURE__ */ jsx(
|
|
1617
1664
|
LeftPanel,
|
|
1618
1665
|
{
|
|
1619
1666
|
color,
|
|
@@ -1625,15 +1672,15 @@ function AdminLayout({ color, darkMode, logo, title, menuConfig, userMenuConfig,
|
|
|
1625
1672
|
userSettingsPath
|
|
1626
1673
|
}
|
|
1627
1674
|
),
|
|
1628
|
-
/* @__PURE__ */
|
|
1675
|
+
/* @__PURE__ */ jsx("div", { w: "screen", py: "2", pe: "2", children: /* @__PURE__ */ jsx(Content, { bgColor: "white", rounded: "lg", shadow: true }) })
|
|
1629
1676
|
]
|
|
1630
1677
|
}
|
|
1631
1678
|
);
|
|
1632
1679
|
}
|
|
1633
1680
|
function LeftPanel({ color, darkMode, logo, title, menuConfig, userMenuConfig, userSettingsPath }) {
|
|
1634
|
-
const [isOpen, __, toggle] =
|
|
1635
|
-
|
|
1636
|
-
return /* @__PURE__ */
|
|
1681
|
+
const [isOpen, __, toggle] = useBoolean(true);
|
|
1682
|
+
useHotkeys("ctrl+t", () => toggle(), [toggle]);
|
|
1683
|
+
return /* @__PURE__ */ jsxs(
|
|
1637
1684
|
"div",
|
|
1638
1685
|
{
|
|
1639
1686
|
ms: isOpen ? "0" : "-14.5rem",
|
|
@@ -1641,7 +1688,7 @@ function LeftPanel({ color, darkMode, logo, title, menuConfig, userMenuConfig, u
|
|
|
1641
1688
|
duration: "500",
|
|
1642
1689
|
transform: true,
|
|
1643
1690
|
children: [
|
|
1644
|
-
/* @__PURE__ */
|
|
1691
|
+
/* @__PURE__ */ jsx(
|
|
1645
1692
|
Sidebar,
|
|
1646
1693
|
{
|
|
1647
1694
|
flexShrink: "0",
|
|
@@ -1654,10 +1701,10 @@ function LeftPanel({ color, darkMode, logo, title, menuConfig, userMenuConfig, u
|
|
|
1654
1701
|
userSettingsPath
|
|
1655
1702
|
}
|
|
1656
1703
|
),
|
|
1657
|
-
/* @__PURE__ */
|
|
1658
|
-
|
|
1704
|
+
/* @__PURE__ */ jsx(
|
|
1705
|
+
IconButton,
|
|
1659
1706
|
{
|
|
1660
|
-
icon:
|
|
1707
|
+
icon: mdiArrowLeft,
|
|
1661
1708
|
transition: "all",
|
|
1662
1709
|
duration: "500",
|
|
1663
1710
|
transform: true,
|
|
@@ -1675,7 +1722,8 @@ function LeftPanel({ color, darkMode, logo, title, menuConfig, userMenuConfig, u
|
|
|
1675
1722
|
}
|
|
1676
1723
|
);
|
|
1677
1724
|
}
|
|
1678
|
-
|
|
1725
|
+
|
|
1726
|
+
const defaultErrorMsg = "Oops, something went wrong...";
|
|
1679
1727
|
function AttachDialog({
|
|
1680
1728
|
queryId,
|
|
1681
1729
|
queryKey,
|
|
@@ -1690,9 +1738,9 @@ function AttachDialog({
|
|
|
1690
1738
|
itemLabel,
|
|
1691
1739
|
onSuccess,
|
|
1692
1740
|
onFetchError,
|
|
1693
|
-
fetchErrorMsg =
|
|
1741
|
+
fetchErrorMsg = defaultErrorMsg,
|
|
1694
1742
|
onSaveError,
|
|
1695
|
-
saveErrorMsg =
|
|
1743
|
+
saveErrorMsg = defaultErrorMsg,
|
|
1696
1744
|
invalidateQueriesOnSuccess = true,
|
|
1697
1745
|
retryText = "Retry",
|
|
1698
1746
|
cancelLabel = "Cancel",
|
|
@@ -1701,14 +1749,14 @@ function AttachDialog({
|
|
|
1701
1749
|
getItemName,
|
|
1702
1750
|
...props
|
|
1703
1751
|
}) {
|
|
1704
|
-
const queryClient =
|
|
1705
|
-
const { data: attached, isInitialLoading: fetchLoading, isError: fetchError, refetch, error } =
|
|
1706
|
-
const { data, isInitialLoading: fetchAllLoading, isError: fetchAllError, refetch: refetchAll, error: errorAll } =
|
|
1707
|
-
const [selectedResources, setSelectedResources] =
|
|
1752
|
+
const queryClient = useQueryClient();
|
|
1753
|
+
const { data: attached, isInitialLoading: fetchLoading, isError: fetchError, refetch, error } = useApiQuery(queryKey, queryFetchFn);
|
|
1754
|
+
const { data, isInitialLoading: fetchAllLoading, isError: fetchAllError, refetch: refetchAll, error: errorAll } = useApiQuery(queryFetchAllKey, queryFetchAllFn);
|
|
1755
|
+
const [selectedResources, setSelectedResources] = React.useState([]);
|
|
1708
1756
|
const isLoading = fetchLoading || fetchAllLoading;
|
|
1709
1757
|
const isError = fetchError || fetchAllError;
|
|
1710
|
-
const mutation =
|
|
1711
|
-
const handleClick =
|
|
1758
|
+
const mutation = useApiMutation(querySaveFn, queryKey, queryId);
|
|
1759
|
+
const handleClick = React.useCallback((event) => {
|
|
1712
1760
|
const id = event?.currentTarget.dataset.id ?? "";
|
|
1713
1761
|
const arr = selectedResources.concat([]);
|
|
1714
1762
|
const i = selectedResources.indexOf(id);
|
|
@@ -1718,19 +1766,19 @@ function AttachDialog({
|
|
|
1718
1766
|
arr.push(id);
|
|
1719
1767
|
setSelectedResources(arr);
|
|
1720
1768
|
}, [selectedResources, setSelectedResources]);
|
|
1721
|
-
const retry =
|
|
1769
|
+
const retry = React.useCallback(() => {
|
|
1722
1770
|
if (fetchError)
|
|
1723
1771
|
refetch();
|
|
1724
1772
|
if (fetchAllError)
|
|
1725
1773
|
refetchAll();
|
|
1726
1774
|
}, [refetch, refetchAll, fetchError, fetchAllError]);
|
|
1727
|
-
const saveItem =
|
|
1775
|
+
const saveItem = React.useCallback(() => {
|
|
1728
1776
|
mutation.reset();
|
|
1729
1777
|
mutation.mutateAsync({ resources: selectedResources }).then((response) => {
|
|
1730
1778
|
if (onSuccess)
|
|
1731
1779
|
onSuccess(response);
|
|
1732
1780
|
else
|
|
1733
|
-
|
|
1781
|
+
toast.success(`${itemLabel} saved`);
|
|
1734
1782
|
if (invalidateQueriesOnSuccess)
|
|
1735
1783
|
queryClient.invalidateQueries({ queryKey });
|
|
1736
1784
|
onClose?.();
|
|
@@ -1739,10 +1787,10 @@ function AttachDialog({
|
|
|
1739
1787
|
if (onSaveError)
|
|
1740
1788
|
onSaveError();
|
|
1741
1789
|
else
|
|
1742
|
-
|
|
1790
|
+
toast.error(`Error adding ${itemLabel}`);
|
|
1743
1791
|
});
|
|
1744
1792
|
}, [mutation, queryId, onSuccess, queryClient, onSaveError, onClose]);
|
|
1745
|
-
const resources =
|
|
1793
|
+
const resources = React.useMemo(() => {
|
|
1746
1794
|
let r = [];
|
|
1747
1795
|
if (attached && data) {
|
|
1748
1796
|
r = [].concat(data);
|
|
@@ -1751,12 +1799,12 @@ function AttachDialog({
|
|
|
1751
1799
|
r = r.map((item) => {
|
|
1752
1800
|
return { ...item, name: getItemName(item) };
|
|
1753
1801
|
});
|
|
1754
|
-
r =
|
|
1802
|
+
r = sortBy(r, ["name"]);
|
|
1755
1803
|
}
|
|
1756
1804
|
return r;
|
|
1757
1805
|
}, [attached, data]);
|
|
1758
|
-
return /* @__PURE__ */
|
|
1759
|
-
|
|
1806
|
+
return /* @__PURE__ */ jsxs(
|
|
1807
|
+
Modal,
|
|
1760
1808
|
{
|
|
1761
1809
|
size,
|
|
1762
1810
|
show,
|
|
@@ -1765,11 +1813,11 @@ function AttachDialog({
|
|
|
1765
1813
|
transition: true,
|
|
1766
1814
|
...props,
|
|
1767
1815
|
children: [
|
|
1768
|
-
/* @__PURE__ */
|
|
1769
|
-
isLoading && /* @__PURE__ */
|
|
1770
|
-
isError && /* @__PURE__ */
|
|
1771
|
-
!isLoading && !isError && /* @__PURE__ */
|
|
1772
|
-
/* @__PURE__ */
|
|
1816
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: `Add ${itemLabel}` }),
|
|
1817
|
+
isLoading && /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(QueryLoadingState, { minW: "72" }) }),
|
|
1818
|
+
isError && /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsx(RetryOnError, { label: `${fetchErrorMsg} ${error}`, onClick: retry }) }),
|
|
1819
|
+
!isLoading && !isError && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1820
|
+
/* @__PURE__ */ jsx(Modal.Body, { px: "0", pb: "6", maxH: "750px", overflow: "auto", children: /* @__PURE__ */ jsx("div", { dflex: true, flexCol: true, overflow: "auto", children: resources.map((item) => /* @__PURE__ */ jsx(
|
|
1773
1821
|
ListItem,
|
|
1774
1822
|
{
|
|
1775
1823
|
label: item.name,
|
|
@@ -1780,9 +1828,9 @@ function AttachDialog({
|
|
|
1780
1828
|
},
|
|
1781
1829
|
item.id
|
|
1782
1830
|
)) }) }),
|
|
1783
|
-
/* @__PURE__ */
|
|
1784
|
-
/* @__PURE__ */
|
|
1785
|
-
|
|
1831
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [
|
|
1832
|
+
/* @__PURE__ */ jsx(
|
|
1833
|
+
Button,
|
|
1786
1834
|
{
|
|
1787
1835
|
disabled: mutation.isLoading,
|
|
1788
1836
|
onClick: onClose,
|
|
@@ -1791,8 +1839,8 @@ function AttachDialog({
|
|
|
1791
1839
|
children: cancelLabel
|
|
1792
1840
|
}
|
|
1793
1841
|
),
|
|
1794
|
-
/* @__PURE__ */
|
|
1795
|
-
|
|
1842
|
+
/* @__PURE__ */ jsx(
|
|
1843
|
+
Button,
|
|
1796
1844
|
{
|
|
1797
1845
|
type: "submit",
|
|
1798
1846
|
disabled: selectedResources.length == 0 || mutation.isLoading,
|
|
@@ -1802,13 +1850,13 @@ function AttachDialog({
|
|
|
1802
1850
|
)
|
|
1803
1851
|
] })
|
|
1804
1852
|
] }),
|
|
1805
|
-
mutation.isLoading && /* @__PURE__ */
|
|
1853
|
+
mutation.isLoading && /* @__PURE__ */ jsx(ModalLoadingOverlay, {})
|
|
1806
1854
|
]
|
|
1807
1855
|
}
|
|
1808
1856
|
);
|
|
1809
1857
|
}
|
|
1810
1858
|
function ListItem({ label, value, checked, ...props }) {
|
|
1811
|
-
return /* @__PURE__ */
|
|
1859
|
+
return /* @__PURE__ */ jsxs(
|
|
1812
1860
|
"div",
|
|
1813
1861
|
{
|
|
1814
1862
|
dflex: true,
|
|
@@ -1819,12 +1867,13 @@ function ListItem({ label, value, checked, ...props }) {
|
|
|
1819
1867
|
cursor: "pointer",
|
|
1820
1868
|
...props,
|
|
1821
1869
|
children: [
|
|
1822
|
-
/* @__PURE__ */
|
|
1823
|
-
/* @__PURE__ */
|
|
1870
|
+
/* @__PURE__ */ jsx("span", { flexGrow: true, children: label }),
|
|
1871
|
+
/* @__PURE__ */ jsx(Checkbox, { name: `resources.${value}`, value, checked })
|
|
1824
1872
|
]
|
|
1825
1873
|
}
|
|
1826
1874
|
);
|
|
1827
1875
|
}
|
|
1876
|
+
|
|
1828
1877
|
function FormActionDialog({
|
|
1829
1878
|
initialValues,
|
|
1830
1879
|
itemLabel,
|
|
@@ -1844,14 +1893,14 @@ function FormActionDialog({
|
|
|
1844
1893
|
saveLabel = "Send",
|
|
1845
1894
|
size = "lg",
|
|
1846
1895
|
title,
|
|
1847
|
-
form
|
|
1896
|
+
form,
|
|
1848
1897
|
show,
|
|
1849
1898
|
onClose,
|
|
1850
1899
|
formikProps,
|
|
1851
1900
|
...props
|
|
1852
1901
|
}) {
|
|
1853
|
-
const mutation = invalidateQueriesOnSuccess ?
|
|
1854
|
-
const mutate =
|
|
1902
|
+
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(queryFn, queryKey, queryOptions) : useApiMutation(queryFn, queryKey, queryId, queryOptions);
|
|
1903
|
+
const mutate = useMutate(mutation, {
|
|
1855
1904
|
onSuccess,
|
|
1856
1905
|
successMsg,
|
|
1857
1906
|
showSuccessMsg,
|
|
@@ -1860,8 +1909,8 @@ function FormActionDialog({
|
|
|
1860
1909
|
showErrorMsg,
|
|
1861
1910
|
processInput
|
|
1862
1911
|
});
|
|
1863
|
-
return /* @__PURE__ */
|
|
1864
|
-
|
|
1912
|
+
return /* @__PURE__ */ jsxs(
|
|
1913
|
+
Modal,
|
|
1865
1914
|
{
|
|
1866
1915
|
size,
|
|
1867
1916
|
show,
|
|
@@ -1870,21 +1919,21 @@ function FormActionDialog({
|
|
|
1870
1919
|
transition: true,
|
|
1871
1920
|
...props,
|
|
1872
1921
|
children: [
|
|
1873
|
-
/* @__PURE__ */
|
|
1874
|
-
/* @__PURE__ */
|
|
1875
|
-
|
|
1922
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: title }),
|
|
1923
|
+
/* @__PURE__ */ jsxs(
|
|
1924
|
+
FormProvider,
|
|
1876
1925
|
{
|
|
1877
1926
|
initialValues: initialValues ?? {},
|
|
1878
1927
|
onSubmit: mutate,
|
|
1879
1928
|
...formikProps,
|
|
1880
1929
|
children: [
|
|
1881
|
-
/* @__PURE__ */
|
|
1882
|
-
|
|
1883
|
-
Array.isArray(form
|
|
1930
|
+
/* @__PURE__ */ jsxs(Modal.Body, { pb: "6", children: [
|
|
1931
|
+
React.isValidElement(form) && form,
|
|
1932
|
+
Array.isArray(form) && /* @__PURE__ */ jsx(FormRenderer, { form })
|
|
1884
1933
|
] }),
|
|
1885
|
-
/* @__PURE__ */
|
|
1886
|
-
/* @__PURE__ */
|
|
1887
|
-
|
|
1934
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { dflex: true, placeContent: "end", spaceX: "3", children: [
|
|
1935
|
+
/* @__PURE__ */ jsx(
|
|
1936
|
+
Button,
|
|
1888
1937
|
{
|
|
1889
1938
|
disabled: mutation.isLoading,
|
|
1890
1939
|
onClick: onClose,
|
|
@@ -1893,26 +1942,29 @@ function FormActionDialog({
|
|
|
1893
1942
|
children: cancelLabel
|
|
1894
1943
|
}
|
|
1895
1944
|
),
|
|
1896
|
-
/* @__PURE__ */
|
|
1945
|
+
/* @__PURE__ */ jsx(SubmitButton, { disabled: mutation.isLoading, children: saveLabel })
|
|
1897
1946
|
] })
|
|
1898
1947
|
]
|
|
1899
1948
|
}
|
|
1900
1949
|
),
|
|
1901
|
-
mutation.isLoading && /* @__PURE__ */
|
|
1950
|
+
mutation.isLoading && /* @__PURE__ */ jsx(ModalLoadingOverlay, {})
|
|
1902
1951
|
]
|
|
1903
1952
|
}
|
|
1904
1953
|
);
|
|
1905
1954
|
}
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1955
|
+
|
|
1956
|
+
const PageStateContainer = React.forwardRef(({ loading = false, children, ...props }, ref) => {
|
|
1957
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1958
|
+
loading && /* @__PURE__ */ jsx(QueryLoadingState, { w: "full", h: "100%" }),
|
|
1959
|
+
!loading && /* @__PURE__ */ jsx(Container, { ref, center: true, size: "x2", dflex: true, flexCol: true, gap: "8", ...props, children })
|
|
1910
1960
|
] });
|
|
1911
1961
|
});
|
|
1962
|
+
|
|
1912
1963
|
function PageSubSectionTitle({ children, ...props }) {
|
|
1913
|
-
return /* @__PURE__ */
|
|
1964
|
+
return /* @__PURE__ */ jsx("div", { trait: "typo.h6", mb: "3", ...props, children });
|
|
1914
1965
|
}
|
|
1915
|
-
|
|
1966
|
+
|
|
1967
|
+
const labels = {
|
|
1916
1968
|
draft: "Draft",
|
|
1917
1969
|
published: "Published",
|
|
1918
1970
|
pending: "Pending",
|
|
@@ -1920,7 +1972,7 @@ var labels = {
|
|
|
1920
1972
|
partially_approved: "Partially Approved",
|
|
1921
1973
|
rejected: "Rejected"
|
|
1922
1974
|
};
|
|
1923
|
-
|
|
1975
|
+
const schemes = {
|
|
1924
1976
|
draft: "warning",
|
|
1925
1977
|
published: "success",
|
|
1926
1978
|
pending: "secondary",
|
|
@@ -1929,27 +1981,30 @@ var schemes2 = {
|
|
|
1929
1981
|
rejected: "danger"
|
|
1930
1982
|
};
|
|
1931
1983
|
function StatusBadge({ status, ...props }) {
|
|
1932
|
-
return /* @__PURE__ */
|
|
1984
|
+
return /* @__PURE__ */ jsx(Badge, { size: "sm", variant: "glass", whiteSpace: "nowrap", rounded: "full", px: "3", scheme: schemes[status], ...props, children: labels[status] });
|
|
1933
1985
|
}
|
|
1986
|
+
|
|
1934
1987
|
function TableRowViewButton({ path, ...props }) {
|
|
1935
|
-
const openPage =
|
|
1988
|
+
const openPage = React.useCallback((event) => {
|
|
1936
1989
|
event?.preventDefault();
|
|
1937
1990
|
event?.stopPropagation();
|
|
1938
|
-
window.open(`${
|
|
1991
|
+
window.open(`${AppEnv.websiteUrl()}/${path}`, "_blank");
|
|
1939
1992
|
}, [path]);
|
|
1940
|
-
return /* @__PURE__ */
|
|
1993
|
+
return /* @__PURE__ */ jsx(TableRowActionButton, { icon: mdiOpenInNew, onClick: openPage, ...props });
|
|
1941
1994
|
}
|
|
1995
|
+
|
|
1942
1996
|
function TableRowNavigateButton({ path, ...props }) {
|
|
1943
|
-
const navigate =
|
|
1944
|
-
const handleClick =
|
|
1997
|
+
const navigate = useNavigate();
|
|
1998
|
+
const handleClick = React.useCallback((event) => {
|
|
1945
1999
|
event?.preventDefault();
|
|
1946
2000
|
event?.stopPropagation();
|
|
1947
2001
|
navigate(`${path}`);
|
|
1948
2002
|
}, [navigate, path]);
|
|
1949
|
-
return /* @__PURE__ */
|
|
2003
|
+
return /* @__PURE__ */ jsx(TableRowActionButton, { icon: mdiEye, onClick: handleClick, ...props });
|
|
1950
2004
|
}
|
|
2005
|
+
|
|
1951
2006
|
function TableRowActionDialogButton({ icon, children, ...props }) {
|
|
1952
|
-
return /* @__PURE__ */
|
|
2007
|
+
return /* @__PURE__ */ jsxs(
|
|
1953
2008
|
DialogButton,
|
|
1954
2009
|
{
|
|
1955
2010
|
dflex: true,
|
|
@@ -1964,18 +2019,21 @@ function TableRowActionDialogButton({ icon, children, ...props }) {
|
|
|
1964
2019
|
gap: "2",
|
|
1965
2020
|
...props,
|
|
1966
2021
|
children: [
|
|
1967
|
-
icon && /* @__PURE__ */
|
|
2022
|
+
icon && /* @__PURE__ */ jsx(Icon, { path: icon, size: "sm" }),
|
|
1968
2023
|
children
|
|
1969
2024
|
]
|
|
1970
2025
|
}
|
|
1971
2026
|
);
|
|
1972
2027
|
}
|
|
2028
|
+
|
|
1973
2029
|
function TableRowEditButton({ children, ...props }) {
|
|
1974
|
-
return /* @__PURE__ */
|
|
2030
|
+
return /* @__PURE__ */ jsx(TableRowActionDialogButton, { icon: mdiPencil, ...props, children });
|
|
1975
2031
|
}
|
|
2032
|
+
|
|
1976
2033
|
function TableRowDeleteButton({ children, ...props }) {
|
|
1977
|
-
return /* @__PURE__ */
|
|
2034
|
+
return /* @__PURE__ */ jsx(TableRowActionDialogButton, { icon: mdiDelete, ...props, children });
|
|
1978
2035
|
}
|
|
2036
|
+
|
|
1979
2037
|
function TableRowActionBar({
|
|
1980
2038
|
publishId,
|
|
1981
2039
|
viewPath,
|
|
@@ -1985,70 +2043,25 @@ function TableRowActionBar({
|
|
|
1985
2043
|
children,
|
|
1986
2044
|
...props
|
|
1987
2045
|
}) {
|
|
1988
|
-
return /* @__PURE__ */
|
|
1989
|
-
viewPath && /* @__PURE__ */
|
|
1990
|
-
navigatePath && /* @__PURE__ */
|
|
1991
|
-
editDialog && /* @__PURE__ */
|
|
1992
|
-
deleteDialog && /* @__PURE__ */
|
|
2046
|
+
return /* @__PURE__ */ jsxs("div", { dflex: true, spaceX: "1", placeContent: "end", ...props, children: [
|
|
2047
|
+
viewPath && /* @__PURE__ */ jsx(TableRowViewButton, { path: viewPath }),
|
|
2048
|
+
navigatePath && /* @__PURE__ */ jsx(TableRowNavigateButton, { path: navigatePath }),
|
|
2049
|
+
editDialog && /* @__PURE__ */ jsx(TableRowEditButton, { buildDialog: editDialog }),
|
|
2050
|
+
deleteDialog && /* @__PURE__ */ jsx(TableRowDeleteButton, { buildDialog: deleteDialog }),
|
|
1993
2051
|
children
|
|
1994
2052
|
] });
|
|
1995
2053
|
}
|
|
1996
|
-
|
|
2054
|
+
|
|
2055
|
+
function TableRowPublishPostButton({ id, api, status, invalidateQueryKey, ...props }) {
|
|
1997
2056
|
const isDraft = status == "draft";
|
|
1998
|
-
const mutation =
|
|
1999
|
-
const publish =
|
|
2057
|
+
const mutation = useInvalidateParentMutation(isDraft ? api.publish : api.unpublish, invalidateQueryKey ?? api.queryKey, { networkMode: "always" });
|
|
2058
|
+
const publish = React.useCallback((event) => {
|
|
2000
2059
|
event?.preventDefault();
|
|
2001
2060
|
event?.stopPropagation();
|
|
2002
2061
|
mutation.reset();
|
|
2003
|
-
mutation.mutateAsync(id).then(() =>
|
|
2062
|
+
mutation.mutateAsync(id).then(() => toast.success(isDraft ? "Published!" : "Unpublished!")).catch((error) => toast.error(`Error: ${error}`));
|
|
2004
2063
|
}, [mutation, id]);
|
|
2005
|
-
return /* @__PURE__ */
|
|
2006
|
-
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
exports.AttachDialog = AttachDialog;
|
|
2010
|
-
exports.Breadcrumbs = Breadcrumbs;
|
|
2011
|
-
exports.ButtonBar = ButtonBar;
|
|
2012
|
-
exports.ButtonBarButton = ButtonBarButton;
|
|
2013
|
-
exports.ButtonBarDialogButton = ButtonBarDialogButton;
|
|
2014
|
-
exports.ButtonBarSubmitButton = ButtonBarSubmitButton;
|
|
2015
|
-
exports.DialogButton = DialogButton;
|
|
2016
|
-
exports.FormActionDialog = FormActionDialog;
|
|
2017
|
-
exports.InvalidateButton = InvalidateButton;
|
|
2018
|
-
exports.ItemDeleteDialog = ItemDeleteDialog;
|
|
2019
|
-
exports.ItemEditDialog = ItemEditDialog;
|
|
2020
|
-
exports.Menu = Menu;
|
|
2021
|
-
exports.NavigateButton = NavigateButton;
|
|
2022
|
-
exports.OrderCell = OrderCell;
|
|
2023
|
-
exports.PageContainer = PageContainer;
|
|
2024
|
-
exports.PageContentEditor = PageContentEditor;
|
|
2025
|
-
exports.PageMain = PageMain;
|
|
2026
|
-
exports.PageQueryStateContainer = PageQueryStateContainer;
|
|
2027
|
-
exports.PageSectionTitle = PageSectionTitle;
|
|
2028
|
-
exports.PageSidebar = PageSidebar;
|
|
2029
|
-
exports.PageSidebarSection = PageSidebarSection;
|
|
2030
|
-
exports.PageStateContainer = PageStateContainer;
|
|
2031
|
-
exports.PageSubSectionTitle = PageSubSectionTitle;
|
|
2032
|
-
exports.PageTabbedTopBar = PageTabbedTopBar;
|
|
2033
|
-
exports.PageTabbedTopBarProvider = PageTabbedTopBarProvider;
|
|
2034
|
-
exports.PageTitle = PageTitle;
|
|
2035
|
-
exports.PageTopBar = PageTopBar;
|
|
2036
|
-
exports.PageTopBarToolbar = PageTopBarToolbar;
|
|
2037
|
-
exports.PublishButton = PublishButton;
|
|
2038
|
-
exports.ScreenRenderer = ScreenRenderer;
|
|
2039
|
-
exports.SectionTitle = SectionTitle;
|
|
2040
|
-
exports.StatusBadge = StatusBadge;
|
|
2041
|
-
exports.TableContainer = TableContainer;
|
|
2042
|
-
exports.TableCreateButton = TableCreateButton;
|
|
2043
|
-
exports.TableFilterButton = TableFilterButton;
|
|
2044
|
-
exports.TableRowActionBar = TableRowActionBar;
|
|
2045
|
-
exports.TableRowActionButton = TableRowActionButton;
|
|
2046
|
-
exports.TableRowActionDialogButton = TableRowActionDialogButton;
|
|
2047
|
-
exports.TableRowDeleteButton = TableRowDeleteButton;
|
|
2048
|
-
exports.TableRowEditButton = TableRowEditButton;
|
|
2049
|
-
exports.TableRowNavigateButton = TableRowNavigateButton;
|
|
2050
|
-
exports.TableRowPublishPostButton = TableRowPublishPostButton2;
|
|
2051
|
-
exports.TableRowViewButton = TableRowViewButton;
|
|
2052
|
-
exports.TableTopBar = TableTopBar;
|
|
2053
|
-
exports.UpdateButton = UpdateButton;
|
|
2054
|
-
exports.ViewButton = ViewButton;
|
|
2064
|
+
return /* @__PURE__ */ jsx(TableRowActionButton, { icon: isDraft ? mdiPublish : mdiPublishOff, onClick: publish, ...props });
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, ButtonBarSubmitButton, DialogButton, FormActionDialog, InvalidateButton, ItemDeleteDialog, ItemEditDialog, Menu, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
|