@strapi/content-manager 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.f8a68bc03b751aa0a66c4dcfaf83553c9b6adf2b
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/LICENSE +18 -3
- package/dist/_chunks/{ComponentConfigurationPage-CuWgXugY.mjs → ComponentConfigurationPage-B2g3icXu.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CuWgXugY.mjs.map → ComponentConfigurationPage-B2g3icXu.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-by0e_kNd.js → ComponentConfigurationPage-CzDn8Uxh.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-by0e_kNd.js.map → ComponentConfigurationPage-CzDn8Uxh.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CqBeCPGH.js → EditConfigurationPage-Bcbi6r5y.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CqBeCPGH.js.map → EditConfigurationPage-Bcbi6r5y.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DbI4KMyz.mjs → EditConfigurationPage-DSA1zONV.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DbI4KMyz.mjs.map → EditConfigurationPage-DSA1zONV.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-ChgloMyO.js → EditViewPage-BvcMXaP2.js} +68 -47
- package/dist/_chunks/EditViewPage-BvcMXaP2.js.map +1 -0
- package/dist/_chunks/{EditViewPage-dFPBya9U.mjs → EditViewPage-Ca2EmJpb.mjs} +69 -48
- package/dist/_chunks/EditViewPage-Ca2EmJpb.mjs.map +1 -0
- package/dist/_chunks/{Field-C1nUKcdS.mjs → Field-BEYkgCZ0.mjs} +579 -227
- package/dist/_chunks/Field-BEYkgCZ0.mjs.map +1 -0
- package/dist/_chunks/{Field-dLk-vgLL.js → Field-CmaWxdpf.js} +581 -229
- package/dist/_chunks/Field-CmaWxdpf.js.map +1 -0
- package/dist/_chunks/{Form-DOlpi7Js.mjs → Form-BJVbU6w4.mjs} +54 -36
- package/dist/_chunks/Form-BJVbU6w4.mjs.map +1 -0
- package/dist/_chunks/{Form-CbXtmHC_.js → Form-DAUpPBVM.js} +52 -34
- package/dist/_chunks/Form-DAUpPBVM.js.map +1 -0
- package/dist/_chunks/{History-BjDfohBr.js → History-Bw9vfT1k.js} +158 -40
- package/dist/_chunks/History-Bw9vfT1k.js.map +1 -0
- package/dist/_chunks/{History-BFNUAiGc.mjs → History-M6Pk9CoY.mjs} +159 -41
- package/dist/_chunks/History-M6Pk9CoY.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DDi0KqFm.mjs → ListConfigurationPage-D7ior2zq.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-D7ior2zq.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-IQBgWTaa.js → ListConfigurationPage-DBVqF5fc.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-DBVqF5fc.js.map +1 -0
- package/dist/_chunks/{ListViewPage-BPjljUsH.mjs → ListViewPage-BH37wONY.mjs} +116 -103
- package/dist/_chunks/ListViewPage-BH37wONY.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-CZYGqlvF.js → ListViewPage-MZu-8OKX.js} +117 -104
- package/dist/_chunks/ListViewPage-MZu-8OKX.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BOAI6VZ1.js → NoContentTypePage-C9lRMTCa.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BOAI6VZ1.js.map → NoContentTypePage-C9lRMTCa.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DaWw67K-.mjs → NoContentTypePage-DRp7Aem_.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DaWw67K-.mjs.map → NoContentTypePage-DRp7Aem_.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-cYEtLc_e.js → NoPermissionsPage-COs61PpB.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-cYEtLc_e.js.map → NoPermissionsPage-COs61PpB.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CZrJH00p.mjs → NoPermissionsPage-CzhRt5CA.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CZrJH00p.mjs.map → NoPermissionsPage-CzhRt5CA.mjs.map} +1 -1
- package/dist/_chunks/{Relations-DTowyge2.mjs → Relations-68XxIzPI.mjs} +51 -30
- package/dist/_chunks/Relations-68XxIzPI.mjs.map +1 -0
- package/dist/_chunks/{Relations-DU6B7irU.js → Relations-CsGlulU_.js} +51 -30
- package/dist/_chunks/Relations-CsGlulU_.js.map +1 -0
- package/dist/_chunks/{en-DTULi5-d.js → en-Bm0D0IWz.js} +21 -15
- package/dist/_chunks/{en-DTULi5-d.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-GCOTL6jR.mjs → en-DKV44jRb.mjs} +21 -15
- package/dist/_chunks/{en-GCOTL6jR.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-BaGHmIir.mjs → index-CsfwpRfc.mjs} +1406 -783
- package/dist/_chunks/index-CsfwpRfc.mjs.map +1 -0
- package/dist/_chunks/{index-CCJeB7Rw.js → index-oDq3VO9j.js} +1382 -758
- package/dist/_chunks/index-oDq3VO9j.js.map +1 -0
- package/dist/_chunks/{layout-BinjszSQ.mjs → layout-C5uSVTqi.mjs} +41 -23
- package/dist/_chunks/layout-C5uSVTqi.mjs.map +1 -0
- package/dist/_chunks/{layout-ni_L9kT1.js → layout-Euka-kfv.js} +39 -21
- package/dist/_chunks/layout-Euka-kfv.js.map +1 -0
- package/dist/_chunks/{relations-c91ji5eR.mjs → relations-BpHVgFuV.mjs} +2 -2
- package/dist/_chunks/{relations-c91ji5eR.mjs.map → relations-BpHVgFuV.mjs.map} +1 -1
- package/dist/_chunks/{relations-CeJAJc5I.js → relations-DG7kmxa0.js} +2 -2
- package/dist/_chunks/{relations-CeJAJc5I.js.map → relations-DG7kmxa0.js.map} +1 -1
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +7 -6
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
- package/dist/admin/src/history/index.d.ts +3 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/hooks/useDocumentActions.d.ts +1 -1
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
- package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
- package/dist/admin/src/pages/ListView/components/BulkActions/PublishAction.d.ts +14 -0
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +222 -127
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +223 -128
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/single-types.d.ts.map +1 -1
- package/dist/server/src/controllers/uid.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +2 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +12 -12
- package/dist/_chunks/EditViewPage-ChgloMyO.js.map +0 -1
- package/dist/_chunks/EditViewPage-dFPBya9U.mjs.map +0 -1
- package/dist/_chunks/Field-C1nUKcdS.mjs.map +0 -1
- package/dist/_chunks/Field-dLk-vgLL.js.map +0 -1
- package/dist/_chunks/Form-CbXtmHC_.js.map +0 -1
- package/dist/_chunks/Form-DOlpi7Js.mjs.map +0 -1
- package/dist/_chunks/History-BFNUAiGc.mjs.map +0 -1
- package/dist/_chunks/History-BjDfohBr.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DDi0KqFm.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-IQBgWTaa.js.map +0 -1
- package/dist/_chunks/ListViewPage-BPjljUsH.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CZYGqlvF.js.map +0 -1
- package/dist/_chunks/Relations-DTowyge2.mjs.map +0 -1
- package/dist/_chunks/Relations-DU6B7irU.js.map +0 -1
- package/dist/_chunks/index-BaGHmIir.mjs.map +0 -1
- package/dist/_chunks/index-CCJeB7Rw.js.map +0 -1
- package/dist/_chunks/layout-BinjszSQ.mjs.map +0 -1
- package/dist/_chunks/layout-ni_L9kT1.js.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
@@ -1,17 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
|
2
2
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
3
|
-
import { useStrapiApp,
|
4
|
-
import { stringify } from "qs";
|
5
|
-
import { useIntl } from "react-intl";
|
6
|
-
import { useNavigate, useParams, Navigate, useMatch, NavLink } from "react-router-dom";
|
3
|
+
import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
|
7
4
|
import * as React from "react";
|
8
5
|
import { lazy } from "react";
|
9
|
-
import { Menu, VisuallyHidden, Flex, Typography, Dialog,
|
10
|
-
import
|
6
|
+
import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
|
7
|
+
import mapValues from "lodash/fp/mapValues";
|
8
|
+
import { useIntl } from "react-intl";
|
9
|
+
import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
|
11
10
|
import * as yup from "yup";
|
12
11
|
import { ValidationError } from "yup";
|
13
12
|
import pipe from "lodash/fp/pipe";
|
14
13
|
import { intervalToDuration, isPast } from "date-fns";
|
14
|
+
import { styled } from "styled-components";
|
15
|
+
import { stringify } from "qs";
|
15
16
|
import { createSlice, combineReducers } from "@reduxjs/toolkit";
|
16
17
|
const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
17
18
|
const v = glob[path];
|
@@ -49,42 +50,6 @@ const useInjectionZone = (area) => {
|
|
49
50
|
const [page, position] = area.split(".");
|
50
51
|
return contentManagerPlugin.getInjectedComponents(page, position);
|
51
52
|
};
|
52
|
-
const HistoryAction = ({ model, document }) => {
|
53
|
-
const { formatMessage } = useIntl();
|
54
|
-
const [{ query }] = useQueryParams();
|
55
|
-
const navigate = useNavigate();
|
56
|
-
const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
|
57
|
-
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
58
|
-
return null;
|
59
|
-
}
|
60
|
-
return {
|
61
|
-
icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
|
62
|
-
label: formatMessage({
|
63
|
-
id: "content-manager.history.document-action",
|
64
|
-
defaultMessage: "Content History"
|
65
|
-
}),
|
66
|
-
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
67
|
-
disabled: (
|
68
|
-
/**
|
69
|
-
* The user is creating a new document.
|
70
|
-
* It hasn't been saved yet, so there's no history to go to
|
71
|
-
*/
|
72
|
-
!document || /**
|
73
|
-
* The document has been created but the current dimension has never been saved.
|
74
|
-
* For example, the user is creating a new locale in an existing document,
|
75
|
-
* so there's no history for the document in that locale
|
76
|
-
*/
|
77
|
-
!document.id || /**
|
78
|
-
* History is only available for content types created by the user.
|
79
|
-
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
80
|
-
* which start with `admin::` or `plugin::`
|
81
|
-
*/
|
82
|
-
!model.startsWith("api::")
|
83
|
-
),
|
84
|
-
position: "header"
|
85
|
-
};
|
86
|
-
};
|
87
|
-
HistoryAction.type = "history";
|
88
53
|
const ID = "id";
|
89
54
|
const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
|
90
55
|
const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
|
@@ -136,6 +101,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
136
101
|
if (!slug) {
|
137
102
|
throw new Error("Cannot find the slug param in the URL");
|
138
103
|
}
|
104
|
+
const [{ rawQuery }] = useQueryParams();
|
139
105
|
const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
|
140
106
|
const contentTypePermissions = React.useMemo(() => {
|
141
107
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -146,7 +112,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
146
112
|
return { ...acc, [action]: [permission] };
|
147
113
|
}, {});
|
148
114
|
}, [slug, userPermissions]);
|
149
|
-
const { isLoading, allowedActions } = useRBAC(
|
115
|
+
const { isLoading, allowedActions } = useRBAC(
|
116
|
+
contentTypePermissions,
|
117
|
+
permissions ?? void 0,
|
118
|
+
// TODO: useRBAC context should be typed and built differently
|
119
|
+
// We are passing raw query as context to the hook so that it can
|
120
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
121
|
+
rawQuery
|
122
|
+
);
|
150
123
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
151
124
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
152
125
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -194,10 +167,12 @@ const contentManagerApi = adminApi.enhanceEndpoints({
|
|
194
167
|
"Document",
|
195
168
|
"InitialData",
|
196
169
|
"HistoryVersion",
|
197
|
-
"Relations"
|
170
|
+
"Relations",
|
171
|
+
"UidAvailability"
|
198
172
|
]
|
199
173
|
});
|
200
174
|
const documentApi = contentManagerApi.injectEndpoints({
|
175
|
+
overrideExisting: true,
|
201
176
|
endpoints: (builder) => ({
|
202
177
|
autoCloneDocument: builder.mutation({
|
203
178
|
query: ({ model, sourceId, query }) => ({
|
@@ -207,7 +182,12 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
207
182
|
params: query
|
208
183
|
}
|
209
184
|
}),
|
210
|
-
invalidatesTags: (_result,
|
185
|
+
invalidatesTags: (_result, error, { model }) => {
|
186
|
+
if (error) {
|
187
|
+
return [];
|
188
|
+
}
|
189
|
+
return [{ type: "Document", id: `${model}_LIST` }];
|
190
|
+
}
|
211
191
|
}),
|
212
192
|
cloneDocument: builder.mutation({
|
213
193
|
query: ({ model, sourceId, data, params }) => ({
|
@@ -218,7 +198,10 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
218
198
|
params
|
219
199
|
}
|
220
200
|
}),
|
221
|
-
invalidatesTags: (_result, _error, { model }) => [
|
201
|
+
invalidatesTags: (_result, _error, { model }) => [
|
202
|
+
{ type: "Document", id: `${model}_LIST` },
|
203
|
+
{ type: "UidAvailability", id: model }
|
204
|
+
]
|
222
205
|
}),
|
223
206
|
/**
|
224
207
|
* Creates a new collection-type document. This should ONLY be used for collection-types.
|
@@ -235,7 +218,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
235
218
|
}),
|
236
219
|
invalidatesTags: (result, _error, { model }) => [
|
237
220
|
{ type: "Document", id: `${model}_LIST` },
|
238
|
-
"Relations"
|
221
|
+
"Relations",
|
222
|
+
{ type: "UidAvailability", id: model }
|
239
223
|
]
|
240
224
|
}),
|
241
225
|
deleteDocument: builder.mutation({
|
@@ -276,7 +260,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
276
260
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
277
261
|
},
|
278
262
|
{ type: "Document", id: `${model}_LIST` },
|
279
|
-
"Relations"
|
263
|
+
"Relations",
|
264
|
+
{ type: "UidAvailability", id: model }
|
280
265
|
];
|
281
266
|
}
|
282
267
|
}),
|
@@ -294,6 +279,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
294
279
|
}),
|
295
280
|
providesTags: (result, _error, arg) => {
|
296
281
|
return [
|
282
|
+
{ type: "Document", id: `ALL_LIST` },
|
297
283
|
{ type: "Document", id: `${arg.model}_LIST` },
|
298
284
|
...result?.results.map(({ documentId }) => ({
|
299
285
|
type: "Document",
|
@@ -332,6 +318,11 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
332
318
|
{
|
333
319
|
type: "Document",
|
334
320
|
id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
|
321
|
+
},
|
322
|
+
// Make it easy to invalidate all individual documents queries for a model
|
323
|
+
{
|
324
|
+
type: "Document",
|
325
|
+
id: `${model}_ALL_ITEMS`
|
335
326
|
}
|
336
327
|
];
|
337
328
|
}
|
@@ -395,8 +386,21 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
395
386
|
type: "Document",
|
396
387
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
397
388
|
},
|
398
|
-
"Relations"
|
389
|
+
"Relations",
|
390
|
+
{ type: "UidAvailability", id: model }
|
399
391
|
];
|
392
|
+
},
|
393
|
+
async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
|
394
|
+
const patchResult = dispatch(
|
395
|
+
documentApi.util.updateQueryData("getDocument", patch, (draft) => {
|
396
|
+
Object.assign(draft.data, data);
|
397
|
+
})
|
398
|
+
);
|
399
|
+
try {
|
400
|
+
await queryFulfilled;
|
401
|
+
} catch {
|
402
|
+
patchResult.undo();
|
403
|
+
}
|
400
404
|
}
|
401
405
|
}),
|
402
406
|
unpublishDocument: builder.mutation({
|
@@ -466,20 +470,39 @@ const buildValidParams = (query) => {
|
|
466
470
|
const isBaseQueryError = (error) => {
|
467
471
|
return error.name !== void 0;
|
468
472
|
};
|
469
|
-
const
|
473
|
+
const arrayValidator = (attribute, options) => ({
|
474
|
+
message: translatedErrors.required,
|
475
|
+
test(value) {
|
476
|
+
if (options.status === "draft") {
|
477
|
+
return true;
|
478
|
+
}
|
479
|
+
if (!attribute.required) {
|
480
|
+
return true;
|
481
|
+
}
|
482
|
+
if (!value) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
if (Array.isArray(value) && value.length === 0) {
|
486
|
+
return false;
|
487
|
+
}
|
488
|
+
return true;
|
489
|
+
}
|
490
|
+
});
|
491
|
+
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
470
492
|
const createModelSchema = (attributes2) => yup.object().shape(
|
471
493
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
472
494
|
if (DOCUMENT_META_FIELDS.includes(name)) {
|
473
495
|
return acc;
|
474
496
|
}
|
475
497
|
const validations = [
|
498
|
+
addNullableValidation,
|
476
499
|
addRequiredValidation,
|
477
500
|
addMinLengthValidation,
|
478
501
|
addMaxLengthValidation,
|
479
502
|
addMinValidation,
|
480
503
|
addMaxValidation,
|
481
504
|
addRegexValidation
|
482
|
-
].map((fn) => fn(attribute));
|
505
|
+
].map((fn) => fn(attribute, options));
|
483
506
|
const transformSchema = pipe(...validations);
|
484
507
|
switch (attribute.type) {
|
485
508
|
case "component": {
|
@@ -489,12 +512,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
489
512
|
...acc,
|
490
513
|
[name]: transformSchema(
|
491
514
|
yup.array().of(createModelSchema(attributes3).nullable(false))
|
492
|
-
)
|
515
|
+
).test(arrayValidator(attribute, options))
|
493
516
|
};
|
494
517
|
} else {
|
495
518
|
return {
|
496
519
|
...acc,
|
497
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
520
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
498
521
|
};
|
499
522
|
}
|
500
523
|
}
|
@@ -516,7 +539,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
516
539
|
}
|
517
540
|
)
|
518
541
|
)
|
519
|
-
)
|
542
|
+
).test(arrayValidator(attribute, options))
|
520
543
|
};
|
521
544
|
case "relation":
|
522
545
|
return {
|
@@ -528,7 +551,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
528
551
|
} else if (Array.isArray(value)) {
|
529
552
|
return yup.array().of(
|
530
553
|
yup.object().shape({
|
531
|
-
id: yup.
|
554
|
+
id: yup.number().required()
|
532
555
|
})
|
533
556
|
);
|
534
557
|
} else if (typeof value === "object") {
|
@@ -580,6 +603,14 @@ const createAttributeSchema = (attribute) => {
|
|
580
603
|
if (!value || typeof value === "string" && value.length === 0) {
|
581
604
|
return true;
|
582
605
|
}
|
606
|
+
if (typeof value === "object") {
|
607
|
+
try {
|
608
|
+
JSON.stringify(value);
|
609
|
+
return true;
|
610
|
+
} catch (err) {
|
611
|
+
return false;
|
612
|
+
}
|
613
|
+
}
|
583
614
|
try {
|
584
615
|
JSON.parse(value);
|
585
616
|
return true;
|
@@ -598,13 +629,7 @@ const createAttributeSchema = (attribute) => {
|
|
598
629
|
return yup.mixed();
|
599
630
|
}
|
600
631
|
};
|
601
|
-
const
|
602
|
-
if (attribute.required) {
|
603
|
-
return schema.required({
|
604
|
-
id: translatedErrors.required.id,
|
605
|
-
defaultMessage: "This field is required."
|
606
|
-
});
|
607
|
-
}
|
632
|
+
const nullableSchema = (schema) => {
|
608
633
|
return schema?.nullable ? schema.nullable() : (
|
609
634
|
// In some cases '.nullable' will not be available on the schema.
|
610
635
|
// e.g. when the schema has been built using yup.lazy (e.g. for relations).
|
@@ -612,7 +637,22 @@ const addRequiredValidation = (attribute) => (schema) => {
|
|
612
637
|
schema
|
613
638
|
);
|
614
639
|
};
|
615
|
-
const
|
640
|
+
const addNullableValidation = () => (schema) => {
|
641
|
+
return nullableSchema(schema);
|
642
|
+
};
|
643
|
+
const addRequiredValidation = (attribute, options) => (schema) => {
|
644
|
+
if (options.status === "draft" || !attribute.required) {
|
645
|
+
return schema;
|
646
|
+
}
|
647
|
+
if (attribute.required && "required" in schema) {
|
648
|
+
return schema.required(translatedErrors.required);
|
649
|
+
}
|
650
|
+
return schema;
|
651
|
+
};
|
652
|
+
const addMinLengthValidation = (attribute, options) => (schema) => {
|
653
|
+
if (options.status === "draft") {
|
654
|
+
return schema;
|
655
|
+
}
|
616
656
|
if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
|
617
657
|
return schema.min(attribute.minLength, {
|
618
658
|
...translatedErrors.minLength,
|
@@ -634,10 +674,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
634
674
|
}
|
635
675
|
return schema;
|
636
676
|
};
|
637
|
-
const addMinValidation = (attribute) => (schema) => {
|
638
|
-
if ("
|
677
|
+
const addMinValidation = (attribute, options) => (schema) => {
|
678
|
+
if (options.status === "draft") {
|
679
|
+
return schema;
|
680
|
+
}
|
681
|
+
if ("min" in attribute && "min" in schema) {
|
639
682
|
const min = toInteger(attribute.min);
|
640
|
-
if (
|
683
|
+
if (min) {
|
641
684
|
return schema.min(min, {
|
642
685
|
...translatedErrors.min,
|
643
686
|
values: {
|
@@ -755,16 +798,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
755
798
|
}, {});
|
756
799
|
return componentsByKey;
|
757
800
|
};
|
758
|
-
const
|
801
|
+
const HOOKS = {
|
802
|
+
/**
|
803
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
804
|
+
* @constant
|
805
|
+
* @type {string}
|
806
|
+
*/
|
807
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
808
|
+
/**
|
809
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
810
|
+
* @constant
|
811
|
+
* @type {string}
|
812
|
+
*/
|
813
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
814
|
+
/**
|
815
|
+
* Hook that allows to mutate the CM's edit view layout
|
816
|
+
* @constant
|
817
|
+
* @type {string}
|
818
|
+
*/
|
819
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
820
|
+
/**
|
821
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
822
|
+
* @constant
|
823
|
+
* @type {string}
|
824
|
+
*/
|
825
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
826
|
+
};
|
827
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
828
|
+
endpoints: (builder) => ({
|
829
|
+
getContentTypeConfiguration: builder.query({
|
830
|
+
query: (uid) => ({
|
831
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
832
|
+
method: "GET"
|
833
|
+
}),
|
834
|
+
transformResponse: (response) => response.data,
|
835
|
+
providesTags: (_result, _error, uid) => [
|
836
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
837
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
838
|
+
]
|
839
|
+
}),
|
840
|
+
getAllContentTypeSettings: builder.query({
|
841
|
+
query: () => "/content-manager/content-types-settings",
|
842
|
+
transformResponse: (response) => response.data,
|
843
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
844
|
+
}),
|
845
|
+
updateContentTypeConfiguration: builder.mutation({
|
846
|
+
query: ({ uid, ...body }) => ({
|
847
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
848
|
+
method: "PUT",
|
849
|
+
data: body
|
850
|
+
}),
|
851
|
+
transformResponse: (response) => response.data,
|
852
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
853
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
854
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
855
|
+
// Is this necessary?
|
856
|
+
{ type: "InitialData" }
|
857
|
+
]
|
858
|
+
})
|
859
|
+
})
|
860
|
+
});
|
861
|
+
const {
|
862
|
+
useGetContentTypeConfigurationQuery,
|
863
|
+
useGetAllContentTypeSettingsQuery,
|
864
|
+
useUpdateContentTypeConfigurationMutation
|
865
|
+
} = contentTypesApi;
|
866
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
867
|
+
const { type } = attribute;
|
868
|
+
if (type === "relation") {
|
869
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
870
|
+
}
|
871
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
872
|
+
};
|
873
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
874
|
+
if (!mainFieldName) {
|
875
|
+
return void 0;
|
876
|
+
}
|
877
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
878
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
879
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
880
|
+
);
|
881
|
+
return {
|
882
|
+
name: mainFieldName,
|
883
|
+
type: mainFieldType ?? "string"
|
884
|
+
};
|
885
|
+
};
|
886
|
+
const DEFAULT_SETTINGS = {
|
887
|
+
bulkable: false,
|
888
|
+
filterable: false,
|
889
|
+
searchable: false,
|
890
|
+
pagination: false,
|
891
|
+
defaultSortBy: "",
|
892
|
+
defaultSortOrder: "asc",
|
893
|
+
mainField: "id",
|
894
|
+
pageSize: 10
|
895
|
+
};
|
896
|
+
const useDocumentLayout = (model) => {
|
897
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
898
|
+
const [{ query }] = useQueryParams();
|
899
|
+
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
759
900
|
const { toggleNotification } = useNotification();
|
760
901
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
902
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
761
903
|
const {
|
762
|
-
|
763
|
-
isLoading:
|
764
|
-
|
765
|
-
|
766
|
-
} =
|
767
|
-
const
|
904
|
+
data,
|
905
|
+
isLoading: isLoadingConfigs,
|
906
|
+
error,
|
907
|
+
isFetching: isFetchingConfigs
|
908
|
+
} = useGetContentTypeConfigurationQuery(model);
|
909
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
768
910
|
React.useEffect(() => {
|
769
911
|
if (error) {
|
770
912
|
toggleNotification({
|
@@ -772,62 +914,318 @@ const useDocument = (args, opts) => {
|
|
772
914
|
message: formatAPIError(error)
|
773
915
|
});
|
774
916
|
}
|
775
|
-
}, [
|
776
|
-
const
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
(document) => {
|
784
|
-
if (!validationSchema) {
|
785
|
-
throw new Error(
|
786
|
-
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
787
|
-
);
|
788
|
-
}
|
789
|
-
try {
|
790
|
-
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
791
|
-
return null;
|
792
|
-
} catch (error2) {
|
793
|
-
if (error2 instanceof ValidationError) {
|
794
|
-
return getYupValidationErrors(error2);
|
795
|
-
}
|
796
|
-
throw error2;
|
797
|
-
}
|
917
|
+
}, [error, formatAPIError, toggleNotification]);
|
918
|
+
const editLayout = React.useMemo(
|
919
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
920
|
+
layout: [],
|
921
|
+
components: {},
|
922
|
+
metadatas: {},
|
923
|
+
options: {},
|
924
|
+
settings: DEFAULT_SETTINGS
|
798
925
|
},
|
799
|
-
[
|
926
|
+
[data, isLoading, schemas, schema, components]
|
927
|
+
);
|
928
|
+
const listLayout = React.useMemo(() => {
|
929
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
930
|
+
layout: [],
|
931
|
+
metadatas: {},
|
932
|
+
options: {},
|
933
|
+
settings: DEFAULT_SETTINGS
|
934
|
+
};
|
935
|
+
}, [data, isLoading, schemas, schema, components]);
|
936
|
+
const { layout: edit } = React.useMemo(
|
937
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
938
|
+
layout: editLayout,
|
939
|
+
query
|
940
|
+
}),
|
941
|
+
[editLayout, query, runHookWaterfall]
|
800
942
|
);
|
801
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
802
943
|
return {
|
803
|
-
|
804
|
-
document: data?.data,
|
805
|
-
meta: data?.meta,
|
944
|
+
error,
|
806
945
|
isLoading,
|
807
|
-
|
808
|
-
|
946
|
+
edit,
|
947
|
+
list: listLayout
|
809
948
|
};
|
810
949
|
};
|
811
|
-
const
|
812
|
-
const {
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
950
|
+
const useDocLayout = () => {
|
951
|
+
const { model } = useDoc();
|
952
|
+
return useDocumentLayout(model);
|
953
|
+
};
|
954
|
+
const formatEditLayout = (data, {
|
955
|
+
schemas,
|
956
|
+
schema,
|
957
|
+
components
|
958
|
+
}) => {
|
959
|
+
let currentPanelIndex = 0;
|
960
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
961
|
+
data.contentType.layouts.edit,
|
962
|
+
schema?.attributes,
|
963
|
+
data.contentType.metadatas,
|
964
|
+
{ configurations: data.components, schemas: components },
|
965
|
+
schemas
|
966
|
+
).reduce((panels, row) => {
|
967
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
968
|
+
panels.push([row]);
|
969
|
+
currentPanelIndex += 2;
|
970
|
+
} else {
|
971
|
+
if (!panels[currentPanelIndex]) {
|
972
|
+
panels.push([]);
|
973
|
+
}
|
974
|
+
panels[currentPanelIndex].push(row);
|
975
|
+
}
|
976
|
+
return panels;
|
977
|
+
}, []);
|
978
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
979
|
+
(acc, [uid, configuration]) => {
|
980
|
+
acc[uid] = {
|
981
|
+
layout: convertEditLayoutToFieldLayouts(
|
982
|
+
configuration.layouts.edit,
|
983
|
+
components[uid].attributes,
|
984
|
+
configuration.metadatas,
|
985
|
+
{ configurations: data.components, schemas: components }
|
986
|
+
),
|
987
|
+
settings: {
|
988
|
+
...configuration.settings,
|
989
|
+
icon: components[uid].info.icon,
|
990
|
+
displayName: components[uid].info.displayName
|
991
|
+
}
|
992
|
+
};
|
993
|
+
return acc;
|
994
|
+
},
|
995
|
+
{}
|
996
|
+
);
|
997
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
998
|
+
(acc, [attribute, metadata]) => {
|
999
|
+
return {
|
1000
|
+
...acc,
|
1001
|
+
[attribute]: metadata.edit
|
1002
|
+
};
|
1003
|
+
},
|
1004
|
+
{}
|
1005
|
+
);
|
1006
|
+
return {
|
1007
|
+
layout: panelledEditAttributes,
|
1008
|
+
components: componentEditAttributes,
|
1009
|
+
metadatas: editMetadatas,
|
1010
|
+
settings: {
|
1011
|
+
...data.contentType.settings,
|
1012
|
+
displayName: schema?.info.displayName
|
1013
|
+
},
|
1014
|
+
options: {
|
1015
|
+
...schema?.options,
|
1016
|
+
...schema?.pluginOptions,
|
1017
|
+
...data.contentType.options
|
1018
|
+
}
|
1019
|
+
};
|
1020
|
+
};
|
1021
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1022
|
+
return rows.map(
|
1023
|
+
(row) => row.map((field) => {
|
1024
|
+
const attribute = attributes[field.name];
|
1025
|
+
if (!attribute) {
|
1026
|
+
return null;
|
1027
|
+
}
|
1028
|
+
const { edit: metadata } = metadatas[field.name];
|
1029
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1030
|
+
return {
|
1031
|
+
attribute,
|
1032
|
+
disabled: !metadata.editable,
|
1033
|
+
hint: metadata.description,
|
1034
|
+
label: metadata.label ?? "",
|
1035
|
+
name: field.name,
|
1036
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1037
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1038
|
+
schemas,
|
1039
|
+
components: components?.schemas ?? {}
|
1040
|
+
}),
|
1041
|
+
placeholder: metadata.placeholder ?? "",
|
1042
|
+
required: attribute.required ?? false,
|
1043
|
+
size: field.size,
|
1044
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1045
|
+
visible: metadata.visible ?? true,
|
1046
|
+
type: attribute.type
|
1047
|
+
};
|
1048
|
+
}).filter((field) => field !== null)
|
1049
|
+
);
|
1050
|
+
};
|
1051
|
+
const formatListLayout = (data, {
|
1052
|
+
schemas,
|
1053
|
+
schema,
|
1054
|
+
components
|
1055
|
+
}) => {
|
1056
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1057
|
+
(acc, [attribute, metadata]) => {
|
1058
|
+
return {
|
1059
|
+
...acc,
|
1060
|
+
[attribute]: metadata.list
|
1061
|
+
};
|
1062
|
+
},
|
1063
|
+
{}
|
1064
|
+
);
|
1065
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1066
|
+
data.contentType.layouts.list,
|
1067
|
+
schema?.attributes,
|
1068
|
+
listMetadatas,
|
1069
|
+
{ configurations: data.components, schemas: components },
|
1070
|
+
schemas
|
1071
|
+
);
|
1072
|
+
return {
|
1073
|
+
layout: listAttributes,
|
1074
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1075
|
+
metadatas: listMetadatas,
|
1076
|
+
options: {
|
1077
|
+
...schema?.options,
|
1078
|
+
...schema?.pluginOptions,
|
1079
|
+
...data.contentType.options
|
1080
|
+
}
|
1081
|
+
};
|
1082
|
+
};
|
1083
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1084
|
+
return columns.map((name) => {
|
1085
|
+
const attribute = attributes[name];
|
1086
|
+
if (!attribute) {
|
1087
|
+
return null;
|
1088
|
+
}
|
1089
|
+
const metadata = metadatas[name];
|
1090
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1091
|
+
return {
|
1092
|
+
attribute,
|
1093
|
+
label: metadata.label ?? "",
|
1094
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1095
|
+
schemas,
|
1096
|
+
components: components?.schemas ?? {}
|
1097
|
+
}),
|
1098
|
+
name,
|
1099
|
+
searchable: metadata.searchable ?? true,
|
1100
|
+
sortable: metadata.sortable ?? true
|
1101
|
+
};
|
1102
|
+
}).filter((field) => field !== null);
|
1103
|
+
};
|
1104
|
+
const useDocument = (args, opts) => {
|
1105
|
+
const { toggleNotification } = useNotification();
|
1106
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1107
|
+
const {
|
1108
|
+
currentData: data,
|
1109
|
+
isLoading: isLoadingDocument,
|
1110
|
+
isFetching: isFetchingDocument,
|
1111
|
+
error
|
1112
|
+
} = useGetDocumentQuery(args, {
|
1113
|
+
...opts,
|
1114
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1115
|
+
});
|
1116
|
+
const {
|
1117
|
+
components,
|
1118
|
+
schema,
|
1119
|
+
schemas,
|
1120
|
+
isLoading: isLoadingSchema
|
1121
|
+
} = useContentTypeSchema(args.model);
|
1122
|
+
React.useEffect(() => {
|
1123
|
+
if (error) {
|
1124
|
+
toggleNotification({
|
1125
|
+
type: "danger",
|
1126
|
+
message: formatAPIError(error)
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1130
|
+
const validationSchema = React.useMemo(() => {
|
1131
|
+
if (!schema) {
|
1132
|
+
return null;
|
1133
|
+
}
|
1134
|
+
return createYupSchema(schema.attributes, components);
|
1135
|
+
}, [schema, components]);
|
1136
|
+
const validate = React.useCallback(
|
1137
|
+
(document) => {
|
1138
|
+
if (!validationSchema) {
|
1139
|
+
throw new Error(
|
1140
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1141
|
+
);
|
1142
|
+
}
|
1143
|
+
try {
|
1144
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1145
|
+
return null;
|
1146
|
+
} catch (error2) {
|
1147
|
+
if (error2 instanceof ValidationError) {
|
1148
|
+
return getYupValidationErrors(error2);
|
1149
|
+
}
|
1150
|
+
throw error2;
|
1151
|
+
}
|
1152
|
+
},
|
1153
|
+
[validationSchema]
|
1154
|
+
);
|
1155
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1156
|
+
const hasError = !!error;
|
1157
|
+
return {
|
1158
|
+
components,
|
1159
|
+
document: data?.data,
|
1160
|
+
meta: data?.meta,
|
1161
|
+
isLoading,
|
1162
|
+
hasError,
|
1163
|
+
schema,
|
1164
|
+
schemas,
|
1165
|
+
validate
|
1166
|
+
};
|
1167
|
+
};
|
1168
|
+
const useDoc = () => {
|
1169
|
+
const { id, slug, collectionType, origin } = useParams();
|
1170
|
+
const [{ query }] = useQueryParams();
|
1171
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1172
|
+
if (!collectionType) {
|
1173
|
+
throw new Error("Could not find collectionType in url params");
|
1174
|
+
}
|
1175
|
+
if (!slug) {
|
1176
|
+
throw new Error("Could not find model in url params");
|
1177
|
+
}
|
1178
|
+
const document = useDocument(
|
1179
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1180
|
+
{
|
1181
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1182
|
+
}
|
1183
|
+
);
|
1184
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
821
1185
|
return {
|
822
1186
|
collectionType,
|
823
1187
|
model: slug,
|
824
|
-
id:
|
825
|
-
...
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
1188
|
+
id: returnId,
|
1189
|
+
...document
|
1190
|
+
};
|
1191
|
+
};
|
1192
|
+
const useContentManagerContext = () => {
|
1193
|
+
const {
|
1194
|
+
collectionType,
|
1195
|
+
model,
|
1196
|
+
id,
|
1197
|
+
components,
|
1198
|
+
isLoading: isLoadingDoc,
|
1199
|
+
schema,
|
1200
|
+
schemas
|
1201
|
+
} = useDoc();
|
1202
|
+
const layout = useDocumentLayout(model);
|
1203
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1204
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1205
|
+
const slug = model;
|
1206
|
+
const isCreatingEntry = id === "create";
|
1207
|
+
useContentTypeSchema();
|
1208
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1209
|
+
const error = layout.error;
|
1210
|
+
return {
|
1211
|
+
error,
|
1212
|
+
isLoading,
|
1213
|
+
// Base metadata
|
1214
|
+
model,
|
1215
|
+
collectionType,
|
1216
|
+
id,
|
1217
|
+
slug,
|
1218
|
+
isCreatingEntry,
|
1219
|
+
isSingleType,
|
1220
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1221
|
+
// All schema infos
|
1222
|
+
components,
|
1223
|
+
contentType: schema,
|
1224
|
+
contentTypes: schemas,
|
1225
|
+
// Form state
|
1226
|
+
form,
|
1227
|
+
// layout infos
|
1228
|
+
layout
|
831
1229
|
};
|
832
1230
|
};
|
833
1231
|
const prefixPluginTranslations = (trad, pluginId) => {
|
@@ -849,6 +1247,8 @@ const useDocumentActions = () => {
|
|
849
1247
|
const { formatMessage } = useIntl();
|
850
1248
|
const { trackUsage } = useTracking();
|
851
1249
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1250
|
+
const navigate = useNavigate();
|
1251
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
852
1252
|
const [deleteDocument] = useDeleteDocumentMutation();
|
853
1253
|
const _delete = React.useCallback(
|
854
1254
|
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
@@ -927,12 +1327,13 @@ const useDocumentActions = () => {
|
|
927
1327
|
);
|
928
1328
|
const [discardDocument] = useDiscardDocumentMutation();
|
929
1329
|
const discard = React.useCallback(
|
930
|
-
async ({ collectionType, model, documentId }) => {
|
1330
|
+
async ({ collectionType, model, documentId, params }) => {
|
931
1331
|
try {
|
932
1332
|
const res = await discardDocument({
|
933
1333
|
collectionType,
|
934
1334
|
model,
|
935
|
-
documentId
|
1335
|
+
documentId,
|
1336
|
+
params
|
936
1337
|
});
|
937
1338
|
if ("error" in res) {
|
938
1339
|
toggleNotification({
|
@@ -1162,6 +1563,7 @@ const useDocumentActions = () => {
|
|
1162
1563
|
defaultMessage: "Saved document"
|
1163
1564
|
})
|
1164
1565
|
});
|
1566
|
+
setCurrentStep("contentManager.success");
|
1165
1567
|
return res.data;
|
1166
1568
|
} catch (err) {
|
1167
1569
|
toggleNotification({
|
@@ -1183,7 +1585,6 @@ const useDocumentActions = () => {
|
|
1183
1585
|
sourceId
|
1184
1586
|
});
|
1185
1587
|
if ("error" in res) {
|
1186
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1187
1588
|
return { error: res.error };
|
1188
1589
|
}
|
1189
1590
|
toggleNotification({
|
@@ -1202,7 +1603,7 @@ const useDocumentActions = () => {
|
|
1202
1603
|
throw err;
|
1203
1604
|
}
|
1204
1605
|
},
|
1205
|
-
[autoCloneDocument,
|
1606
|
+
[autoCloneDocument, formatMessage, toggleNotification]
|
1206
1607
|
);
|
1207
1608
|
const [cloneDocument] = useCloneDocumentMutation();
|
1208
1609
|
const clone = React.useCallback(
|
@@ -1228,6 +1629,7 @@ const useDocumentActions = () => {
|
|
1228
1629
|
defaultMessage: "Cloned document"
|
1229
1630
|
})
|
1230
1631
|
});
|
1632
|
+
navigate(`../../${res.data.data.documentId}`, { relative: "path" });
|
1231
1633
|
return res.data;
|
1232
1634
|
} catch (err) {
|
1233
1635
|
toggleNotification({
|
@@ -1238,7 +1640,7 @@ const useDocumentActions = () => {
|
|
1238
1640
|
throw err;
|
1239
1641
|
}
|
1240
1642
|
},
|
1241
|
-
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
|
1643
|
+
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
|
1242
1644
|
);
|
1243
1645
|
const [getDoc] = useLazyGetDocumentQuery();
|
1244
1646
|
const getDocument = React.useCallback(
|
@@ -1264,7 +1666,7 @@ const useDocumentActions = () => {
|
|
1264
1666
|
};
|
1265
1667
|
};
|
1266
1668
|
const ProtectedHistoryPage = lazy(
|
1267
|
-
() => import("./History-
|
1669
|
+
() => import("./History-M6Pk9CoY.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1268
1670
|
);
|
1269
1671
|
const routes$1 = [
|
1270
1672
|
{
|
@@ -1277,31 +1679,31 @@ const routes$1 = [
|
|
1277
1679
|
}
|
1278
1680
|
];
|
1279
1681
|
const ProtectedEditViewPage = lazy(
|
1280
|
-
() => import("./EditViewPage-
|
1682
|
+
() => import("./EditViewPage-Ca2EmJpb.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1281
1683
|
);
|
1282
1684
|
const ProtectedListViewPage = lazy(
|
1283
|
-
() => import("./ListViewPage-
|
1685
|
+
() => import("./ListViewPage-BH37wONY.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1284
1686
|
);
|
1285
1687
|
const ProtectedListConfiguration = lazy(
|
1286
|
-
() => import("./ListConfigurationPage-
|
1688
|
+
() => import("./ListConfigurationPage-D7ior2zq.mjs").then((mod) => ({
|
1287
1689
|
default: mod.ProtectedListConfiguration
|
1288
1690
|
}))
|
1289
1691
|
);
|
1290
1692
|
const ProtectedEditConfigurationPage = lazy(
|
1291
|
-
() => import("./EditConfigurationPage-
|
1693
|
+
() => import("./EditConfigurationPage-DSA1zONV.mjs").then((mod) => ({
|
1292
1694
|
default: mod.ProtectedEditConfigurationPage
|
1293
1695
|
}))
|
1294
1696
|
);
|
1295
1697
|
const ProtectedComponentConfigurationPage = lazy(
|
1296
|
-
() => import("./ComponentConfigurationPage-
|
1698
|
+
() => import("./ComponentConfigurationPage-B2g3icXu.mjs").then((mod) => ({
|
1297
1699
|
default: mod.ProtectedComponentConfigurationPage
|
1298
1700
|
}))
|
1299
1701
|
);
|
1300
1702
|
const NoPermissions = lazy(
|
1301
|
-
() => import("./NoPermissionsPage-
|
1703
|
+
() => import("./NoPermissionsPage-CzhRt5CA.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1302
1704
|
);
|
1303
1705
|
const NoContentType = lazy(
|
1304
|
-
() => import("./NoContentTypePage-
|
1706
|
+
() => import("./NoContentTypePage-DRp7Aem_.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1305
1707
|
);
|
1306
1708
|
const CollectionTypePages = () => {
|
1307
1709
|
const { collectionType } = useParams();
|
@@ -1415,12 +1817,14 @@ const DocumentActionButton = (action) => {
|
|
1415
1817
|
/* @__PURE__ */ jsx(
|
1416
1818
|
Button,
|
1417
1819
|
{
|
1418
|
-
flex:
|
1820
|
+
flex: "auto",
|
1419
1821
|
startIcon: action.icon,
|
1420
1822
|
disabled: action.disabled,
|
1421
1823
|
onClick: handleClick(action),
|
1422
1824
|
justifyContent: "center",
|
1423
1825
|
variant: action.variant || "default",
|
1826
|
+
paddingTop: "7px",
|
1827
|
+
paddingBottom: "7px",
|
1424
1828
|
children: action.label
|
1425
1829
|
}
|
1426
1830
|
),
|
@@ -1428,7 +1832,7 @@ const DocumentActionButton = (action) => {
|
|
1428
1832
|
DocumentActionConfirmDialog,
|
1429
1833
|
{
|
1430
1834
|
...action.dialog,
|
1431
|
-
variant: action.variant,
|
1835
|
+
variant: action.dialog?.variant ?? action.variant,
|
1432
1836
|
isOpen: dialogId === action.id,
|
1433
1837
|
onClose: handleClose
|
1434
1838
|
}
|
@@ -1485,9 +1889,9 @@ const DocumentActionsMenu = ({
|
|
1485
1889
|
disabled: isDisabled,
|
1486
1890
|
size: "S",
|
1487
1891
|
endIcon: null,
|
1488
|
-
paddingTop: "
|
1489
|
-
paddingLeft: "
|
1490
|
-
paddingRight: "
|
1892
|
+
paddingTop: "4px",
|
1893
|
+
paddingLeft: "7px",
|
1894
|
+
paddingRight: "7px",
|
1491
1895
|
variant,
|
1492
1896
|
children: [
|
1493
1897
|
/* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
|
@@ -1498,7 +1902,7 @@ const DocumentActionsMenu = ({
|
|
1498
1902
|
]
|
1499
1903
|
}
|
1500
1904
|
),
|
1501
|
-
/* @__PURE__ */ jsxs(Menu.Content, {
|
1905
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1502
1906
|
actions2.map((action) => {
|
1503
1907
|
return /* @__PURE__ */ jsx(
|
1504
1908
|
Menu.Item,
|
@@ -1507,10 +1911,25 @@ const DocumentActionsMenu = ({
|
|
1507
1911
|
onSelect: handleClick(action),
|
1508
1912
|
display: "block",
|
1509
1913
|
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
|
1510
|
-
/* @__PURE__ */ jsxs(
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1914
|
+
/* @__PURE__ */ jsxs(
|
1915
|
+
Flex,
|
1916
|
+
{
|
1917
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1918
|
+
gap: 2,
|
1919
|
+
tag: "span",
|
1920
|
+
children: [
|
1921
|
+
/* @__PURE__ */ jsx(
|
1922
|
+
Flex,
|
1923
|
+
{
|
1924
|
+
tag: "span",
|
1925
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1926
|
+
children: action.icon
|
1927
|
+
}
|
1928
|
+
),
|
1929
|
+
action.label
|
1930
|
+
]
|
1931
|
+
}
|
1932
|
+
),
|
1514
1933
|
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
|
1515
1934
|
Flex,
|
1516
1935
|
{
|
@@ -1569,15 +1988,27 @@ const convertActionVariantToColor = (variant = "secondary") => {
|
|
1569
1988
|
return "primary600";
|
1570
1989
|
}
|
1571
1990
|
};
|
1572
|
-
const
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1991
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
1992
|
+
switch (variant) {
|
1993
|
+
case "danger":
|
1994
|
+
return "danger600";
|
1995
|
+
case "secondary":
|
1996
|
+
return "neutral500";
|
1997
|
+
case "success":
|
1998
|
+
return "success600";
|
1999
|
+
default:
|
2000
|
+
return "primary600";
|
2001
|
+
}
|
2002
|
+
};
|
2003
|
+
const DocumentActionConfirmDialog = ({
|
2004
|
+
onClose,
|
2005
|
+
onCancel,
|
2006
|
+
onConfirm,
|
2007
|
+
title,
|
2008
|
+
content,
|
2009
|
+
isOpen,
|
2010
|
+
variant = "secondary"
|
2011
|
+
}) => {
|
1581
2012
|
const { formatMessage } = useIntl();
|
1582
2013
|
const handleClose = async () => {
|
1583
2014
|
if (onCancel) {
|
@@ -1591,22 +2022,20 @@ const DocumentActionConfirmDialog = ({
|
|
1591
2022
|
}
|
1592
2023
|
onClose();
|
1593
2024
|
};
|
1594
|
-
return /* @__PURE__ */
|
1595
|
-
/* @__PURE__ */ jsx(
|
1596
|
-
/* @__PURE__ */ jsx(
|
1597
|
-
|
1598
|
-
{
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
)
|
1609
|
-
] });
|
2025
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2026
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2027
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: content }),
|
2028
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
2029
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
2030
|
+
id: "app.components.Button.cancel",
|
2031
|
+
defaultMessage: "Cancel"
|
2032
|
+
}) }) }),
|
2033
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
2034
|
+
id: "app.components.Button.confirm",
|
2035
|
+
defaultMessage: "Confirm"
|
2036
|
+
}) })
|
2037
|
+
] })
|
2038
|
+
] }) });
|
1610
2039
|
};
|
1611
2040
|
const DocumentActionModal = ({
|
1612
2041
|
isOpen,
|
@@ -1616,36 +2045,31 @@ const DocumentActionModal = ({
|
|
1616
2045
|
content: Content,
|
1617
2046
|
onModalClose
|
1618
2047
|
}) => {
|
1619
|
-
const id = React.useId();
|
1620
|
-
if (!isOpen) {
|
1621
|
-
return null;
|
1622
|
-
}
|
1623
2048
|
const handleClose = () => {
|
1624
2049
|
if (onClose) {
|
1625
2050
|
onClose();
|
1626
2051
|
}
|
1627
2052
|
onModalClose();
|
1628
2053
|
};
|
1629
|
-
return /* @__PURE__ */
|
1630
|
-
/* @__PURE__ */ jsx(
|
1631
|
-
|
1632
|
-
/* @__PURE__ */ jsx(
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
] });
|
2054
|
+
return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
2055
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
|
2056
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
|
2057
|
+
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
2058
|
+
] }) });
|
2059
|
+
};
|
2060
|
+
const transformData = (data) => {
|
2061
|
+
if (Array.isArray(data)) {
|
2062
|
+
return data.map(transformData);
|
2063
|
+
}
|
2064
|
+
if (typeof data === "object" && data !== null) {
|
2065
|
+
if ("apiData" in data) {
|
2066
|
+
return data.apiData;
|
2067
|
+
}
|
2068
|
+
return mapValues(transformData)(data);
|
2069
|
+
}
|
2070
|
+
return data;
|
1647
2071
|
};
|
1648
|
-
const PublishAction = ({
|
2072
|
+
const PublishAction$1 = ({
|
1649
2073
|
activeTab,
|
1650
2074
|
documentId,
|
1651
2075
|
model,
|
@@ -1657,13 +2081,17 @@ const PublishAction = ({
|
|
1657
2081
|
const navigate = useNavigate();
|
1658
2082
|
const { toggleNotification } = useNotification();
|
1659
2083
|
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
2084
|
+
const isListView = useMatch(LIST_PATH) !== null;
|
1660
2085
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
1661
2086
|
const { formatMessage } = useIntl();
|
1662
|
-
const { canPublish
|
1663
|
-
"PublishAction",
|
1664
|
-
({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
|
1665
|
-
);
|
2087
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1666
2088
|
const { publish } = useDocumentActions();
|
2089
|
+
const [
|
2090
|
+
countDraftRelations,
|
2091
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2092
|
+
] = useLazyGetDraftRelationCountQuery();
|
2093
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
|
2094
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
|
1667
2095
|
const [{ query, rawQuery }] = useQueryParams();
|
1668
2096
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1669
2097
|
const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
@@ -1672,10 +2100,105 @@ const PublishAction = ({
|
|
1672
2100
|
const validate = useForm("PublishAction", (state) => state.validate);
|
1673
2101
|
const setErrors = useForm("PublishAction", (state) => state.setErrors);
|
1674
2102
|
const formValues = useForm("PublishAction", ({ values }) => values);
|
2103
|
+
React.useEffect(() => {
|
2104
|
+
if (isErrorDraftRelations) {
|
2105
|
+
toggleNotification({
|
2106
|
+
type: "danger",
|
2107
|
+
message: formatMessage({
|
2108
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2109
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2110
|
+
})
|
2111
|
+
});
|
2112
|
+
}
|
2113
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2114
|
+
React.useEffect(() => {
|
2115
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2116
|
+
const extractDraftRelations = (data) => {
|
2117
|
+
const relations = data.connect || [];
|
2118
|
+
relations.forEach((relation) => {
|
2119
|
+
if (relation.status === "draft") {
|
2120
|
+
localDraftRelations.add(relation.id);
|
2121
|
+
}
|
2122
|
+
});
|
2123
|
+
};
|
2124
|
+
const traverseAndExtract = (data) => {
|
2125
|
+
Object.entries(data).forEach(([key, value]) => {
|
2126
|
+
if (key === "connect" && Array.isArray(value)) {
|
2127
|
+
extractDraftRelations({ connect: value });
|
2128
|
+
} else if (typeof value === "object" && value !== null) {
|
2129
|
+
traverseAndExtract(value);
|
2130
|
+
}
|
2131
|
+
});
|
2132
|
+
};
|
2133
|
+
if (!documentId || modified) {
|
2134
|
+
traverseAndExtract(formValues);
|
2135
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2136
|
+
}
|
2137
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2138
|
+
React.useEffect(() => {
|
2139
|
+
if (!document || !document.documentId || isListView) {
|
2140
|
+
return;
|
2141
|
+
}
|
2142
|
+
const fetchDraftRelationsCount = async () => {
|
2143
|
+
const { data, error } = await countDraftRelations({
|
2144
|
+
collectionType,
|
2145
|
+
model,
|
2146
|
+
documentId,
|
2147
|
+
params
|
2148
|
+
});
|
2149
|
+
if (error) {
|
2150
|
+
throw error;
|
2151
|
+
}
|
2152
|
+
if (data) {
|
2153
|
+
setServerCountOfDraftRelations(data.data);
|
2154
|
+
}
|
2155
|
+
};
|
2156
|
+
fetchDraftRelationsCount();
|
2157
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
1675
2158
|
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1676
2159
|
if (!schema?.options?.draftAndPublish) {
|
1677
2160
|
return null;
|
1678
2161
|
}
|
2162
|
+
const performPublish = async () => {
|
2163
|
+
setSubmitting(true);
|
2164
|
+
try {
|
2165
|
+
const { errors } = await validate(true, {
|
2166
|
+
status: "published"
|
2167
|
+
});
|
2168
|
+
if (errors) {
|
2169
|
+
toggleNotification({
|
2170
|
+
type: "danger",
|
2171
|
+
message: formatMessage({
|
2172
|
+
id: "content-manager.validation.error",
|
2173
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2174
|
+
})
|
2175
|
+
});
|
2176
|
+
return;
|
2177
|
+
}
|
2178
|
+
const res = await publish(
|
2179
|
+
{
|
2180
|
+
collectionType,
|
2181
|
+
model,
|
2182
|
+
documentId,
|
2183
|
+
params
|
2184
|
+
},
|
2185
|
+
transformData(formValues)
|
2186
|
+
);
|
2187
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2188
|
+
navigate({
|
2189
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2190
|
+
search: rawQuery
|
2191
|
+
});
|
2192
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2193
|
+
setErrors(formatValidationErrors(res.error));
|
2194
|
+
}
|
2195
|
+
} finally {
|
2196
|
+
setSubmitting(false);
|
2197
|
+
}
|
2198
|
+
};
|
2199
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2200
|
+
const enableDraftRelationsCount = false;
|
2201
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
1679
2202
|
return {
|
1680
2203
|
/**
|
1681
2204
|
* Disabled when:
|
@@ -1685,52 +2208,39 @@ const PublishAction = ({
|
|
1685
2208
|
* - the document is already published & not modified
|
1686
2209
|
* - the document is being created & not modified
|
1687
2210
|
* - the user doesn't have the permission to publish
|
1688
|
-
* - the user doesn't have the permission to create a new document
|
1689
|
-
* - the user doesn't have the permission to update the document
|
1690
2211
|
*/
|
1691
|
-
disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish
|
2212
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1692
2213
|
label: formatMessage({
|
1693
2214
|
id: "app.utils.publish",
|
1694
2215
|
defaultMessage: "Publish"
|
1695
2216
|
}),
|
1696
2217
|
onClick: async () => {
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
documentId,
|
1715
|
-
params
|
1716
|
-
},
|
1717
|
-
formValues
|
1718
|
-
);
|
1719
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1720
|
-
navigate({
|
1721
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1722
|
-
search: rawQuery
|
1723
|
-
});
|
1724
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1725
|
-
setErrors(formatValidationErrors(res.error));
|
2218
|
+
await performPublish();
|
2219
|
+
},
|
2220
|
+
dialog: hasDraftRelations ? {
|
2221
|
+
type: "dialog",
|
2222
|
+
variant: "danger",
|
2223
|
+
footer: null,
|
2224
|
+
title: formatMessage({
|
2225
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2226
|
+
defaultMessage: "Confirmation"
|
2227
|
+
}),
|
2228
|
+
content: formatMessage(
|
2229
|
+
{
|
2230
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2231
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2232
|
+
},
|
2233
|
+
{
|
2234
|
+
count: totalDraftRelations
|
1726
2235
|
}
|
1727
|
-
|
1728
|
-
|
2236
|
+
),
|
2237
|
+
onConfirm: async () => {
|
2238
|
+
await performPublish();
|
1729
2239
|
}
|
1730
|
-
}
|
2240
|
+
} : void 0
|
1731
2241
|
};
|
1732
2242
|
};
|
1733
|
-
PublishAction.type = "publish";
|
2243
|
+
PublishAction$1.type = "publish";
|
1734
2244
|
const UpdateAction = ({
|
1735
2245
|
activeTab,
|
1736
2246
|
documentId,
|
@@ -1743,10 +2253,6 @@ const UpdateAction = ({
|
|
1743
2253
|
const cloneMatch = useMatch(CLONE_PATH);
|
1744
2254
|
const isCloning = cloneMatch !== null;
|
1745
2255
|
const { formatMessage } = useIntl();
|
1746
|
-
const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
|
1747
|
-
canCreate: canCreate2,
|
1748
|
-
canUpdate: canUpdate2
|
1749
|
-
}));
|
1750
2256
|
const { create, update, clone } = useDocumentActions();
|
1751
2257
|
const [{ query, rawQuery }] = useQueryParams();
|
1752
2258
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
@@ -1763,10 +2269,8 @@ const UpdateAction = ({
|
|
1763
2269
|
* - the form is submitting
|
1764
2270
|
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
1765
2271
|
* - the active tab is the published tab
|
1766
|
-
* - the user doesn't have the permission to create a new document
|
1767
|
-
* - the user doesn't have the permission to update the document
|
1768
2272
|
*/
|
1769
|
-
disabled: isSubmitting || !modified && !isCloning || activeTab === "published"
|
2273
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
1770
2274
|
label: formatMessage({
|
1771
2275
|
id: "content-manager.containers.Edit.save",
|
1772
2276
|
defaultMessage: "Save"
|
@@ -1774,7 +2278,9 @@ const UpdateAction = ({
|
|
1774
2278
|
onClick: async () => {
|
1775
2279
|
setSubmitting(true);
|
1776
2280
|
try {
|
1777
|
-
const { errors } = await validate(
|
2281
|
+
const { errors } = await validate(true, {
|
2282
|
+
status: "draft"
|
2283
|
+
});
|
1778
2284
|
if (errors) {
|
1779
2285
|
toggleNotification({
|
1780
2286
|
type: "danger",
|
@@ -1792,13 +2298,16 @@ const UpdateAction = ({
|
|
1792
2298
|
documentId: cloneMatch.params.origin,
|
1793
2299
|
params
|
1794
2300
|
},
|
1795
|
-
document
|
2301
|
+
transformData(document)
|
1796
2302
|
);
|
1797
2303
|
if ("data" in res) {
|
1798
|
-
navigate(
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
2304
|
+
navigate(
|
2305
|
+
{
|
2306
|
+
pathname: `../${res.data.documentId}`,
|
2307
|
+
search: rawQuery
|
2308
|
+
},
|
2309
|
+
{ relative: "path" }
|
2310
|
+
);
|
1802
2311
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1803
2312
|
setErrors(formatValidationErrors(res.error));
|
1804
2313
|
}
|
@@ -1810,7 +2319,7 @@ const UpdateAction = ({
|
|
1810
2319
|
documentId,
|
1811
2320
|
params
|
1812
2321
|
},
|
1813
|
-
document
|
2322
|
+
transformData(document)
|
1814
2323
|
);
|
1815
2324
|
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1816
2325
|
setErrors(formatValidationErrors(res.error));
|
@@ -1823,13 +2332,16 @@ const UpdateAction = ({
|
|
1823
2332
|
model,
|
1824
2333
|
params
|
1825
2334
|
},
|
1826
|
-
document
|
2335
|
+
transformData(document)
|
1827
2336
|
);
|
1828
2337
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1829
|
-
navigate(
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
2338
|
+
navigate(
|
2339
|
+
{
|
2340
|
+
pathname: `../${res.data.documentId}`,
|
2341
|
+
search: rawQuery
|
2342
|
+
},
|
2343
|
+
{ replace: true, relative: "path" }
|
2344
|
+
);
|
1833
2345
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1834
2346
|
setErrors(formatValidationErrors(res.error));
|
1835
2347
|
}
|
@@ -1861,10 +2373,8 @@ const UnpublishAction$1 = ({
|
|
1861
2373
|
const { toggleNotification } = useNotification();
|
1862
2374
|
const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
|
1863
2375
|
const isDocumentModified = document?.status === "modified";
|
1864
|
-
const handleChange = (
|
1865
|
-
|
1866
|
-
setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1867
|
-
}
|
2376
|
+
const handleChange = (value) => {
|
2377
|
+
setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1868
2378
|
};
|
1869
2379
|
if (!schema?.options?.draftAndPublish) {
|
1870
2380
|
return null;
|
@@ -1875,7 +2385,7 @@ const UnpublishAction$1 = ({
|
|
1875
2385
|
id: "app.utils.unpublish",
|
1876
2386
|
defaultMessage: "Unpublish"
|
1877
2387
|
}),
|
1878
|
-
icon: /* @__PURE__ */ jsx(
|
2388
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
1879
2389
|
onClick: async () => {
|
1880
2390
|
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
1881
2391
|
if (!documentId) {
|
@@ -1914,40 +2424,24 @@ const UnpublishAction$1 = ({
|
|
1914
2424
|
}) })
|
1915
2425
|
] }),
|
1916
2426
|
/* @__PURE__ */ jsxs(
|
1917
|
-
|
2427
|
+
Radio.Group,
|
1918
2428
|
{
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
2429
|
+
defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
|
2430
|
+
name: "discard-options",
|
2431
|
+
"aria-label": formatMessage({
|
2432
|
+
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2433
|
+
defaultMessage: "Choose an option to unpublish the document."
|
2434
|
+
}),
|
2435
|
+
onValueChange: handleChange,
|
1925
2436
|
children: [
|
1926
|
-
/* @__PURE__ */ jsx(
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
1935
|
-
defaultMessage: "Keep draft"
|
1936
|
-
})
|
1937
|
-
}
|
1938
|
-
),
|
1939
|
-
/* @__PURE__ */ jsx(
|
1940
|
-
Radio,
|
1941
|
-
{
|
1942
|
-
checked: !shouldKeepDraft,
|
1943
|
-
value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
|
1944
|
-
name: "discard-options",
|
1945
|
-
children: formatMessage({
|
1946
|
-
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
1947
|
-
defaultMessage: "Replace draft"
|
1948
|
-
})
|
1949
|
-
}
|
1950
|
-
)
|
2437
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2438
|
+
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2439
|
+
defaultMessage: "Keep draft"
|
2440
|
+
}) }),
|
2441
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2442
|
+
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2443
|
+
defaultMessage: "Replace draft"
|
2444
|
+
}) })
|
1951
2445
|
]
|
1952
2446
|
}
|
1953
2447
|
)
|
@@ -2003,7 +2497,7 @@ const DiscardAction = ({
|
|
2003
2497
|
id: "content-manager.actions.discard.label",
|
2004
2498
|
defaultMessage: "Discard changes"
|
2005
2499
|
}),
|
2006
|
-
icon: /* @__PURE__ */ jsx(
|
2500
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
2007
2501
|
position: ["panel", "table-row"],
|
2008
2502
|
variant: "danger",
|
2009
2503
|
dialog: {
|
@@ -2031,12 +2525,7 @@ const DiscardAction = ({
|
|
2031
2525
|
};
|
2032
2526
|
};
|
2033
2527
|
DiscardAction.type = "discard";
|
2034
|
-
const
|
2035
|
-
path {
|
2036
|
-
fill: currentColor;
|
2037
|
-
}
|
2038
|
-
`;
|
2039
|
-
const DEFAULT_ACTIONS = [PublishAction, UpdateAction, UnpublishAction$1, DiscardAction];
|
2528
|
+
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2040
2529
|
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2041
2530
|
const RelativeTime = React.forwardRef(
|
2042
2531
|
({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
|
@@ -2083,7 +2572,7 @@ const getDisplayName = ({
|
|
2083
2572
|
};
|
2084
2573
|
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2085
2574
|
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2086
|
-
const statusVariant = status === "draft" ? "
|
2575
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2087
2576
|
return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2088
2577
|
};
|
2089
2578
|
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
@@ -2093,23 +2582,13 @@ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
|
2093
2582
|
id: "content-manager.containers.edit.title.new",
|
2094
2583
|
defaultMessage: "Create an entry"
|
2095
2584
|
}) : documentTitle;
|
2096
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop:
|
2585
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2097
2586
|
/* @__PURE__ */ jsx(BackButton, {}),
|
2098
|
-
/* @__PURE__ */ jsxs(
|
2099
|
-
|
2100
|
-
{
|
2101
|
-
|
2102
|
-
|
2103
|
-
paddingTop: 1,
|
2104
|
-
gap: "80px",
|
2105
|
-
alignItems: "flex-start",
|
2106
|
-
children: [
|
2107
|
-
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2108
|
-
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2109
|
-
]
|
2110
|
-
}
|
2111
|
-
),
|
2112
|
-
status ? /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
|
2587
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2588
|
+
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2589
|
+
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2590
|
+
] }),
|
2591
|
+
status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2113
2592
|
] });
|
2114
2593
|
};
|
2115
2594
|
const HeaderToolbar = () => {
|
@@ -2192,12 +2671,12 @@ const Information = ({ activeTab }) => {
|
|
2192
2671
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2193
2672
|
label: formatMessage({
|
2194
2673
|
id: "content-manager.containers.edit.information.last-published.label",
|
2195
|
-
defaultMessage: "
|
2674
|
+
defaultMessage: "Published"
|
2196
2675
|
}),
|
2197
2676
|
value: formatMessage(
|
2198
2677
|
{
|
2199
2678
|
id: "content-manager.containers.edit.information.last-published.value",
|
2200
|
-
defaultMessage: `
|
2679
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2201
2680
|
},
|
2202
2681
|
{
|
2203
2682
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2210,12 +2689,12 @@ const Information = ({ activeTab }) => {
|
|
2210
2689
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2211
2690
|
label: formatMessage({
|
2212
2691
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2213
|
-
defaultMessage: "
|
2692
|
+
defaultMessage: "Updated"
|
2214
2693
|
}),
|
2215
2694
|
value: formatMessage(
|
2216
2695
|
{
|
2217
2696
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2218
|
-
defaultMessage: `
|
2697
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2219
2698
|
},
|
2220
2699
|
{
|
2221
2700
|
time: /* @__PURE__ */ jsx(
|
@@ -2233,12 +2712,12 @@ const Information = ({ activeTab }) => {
|
|
2233
2712
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2234
2713
|
label: formatMessage({
|
2235
2714
|
id: "content-manager.containers.edit.information.document.label",
|
2236
|
-
defaultMessage: "
|
2715
|
+
defaultMessage: "Created"
|
2237
2716
|
}),
|
2238
2717
|
value: formatMessage(
|
2239
2718
|
{
|
2240
2719
|
id: "content-manager.containers.edit.information.document.value",
|
2241
|
-
defaultMessage: `
|
2720
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2242
2721
|
},
|
2243
2722
|
{
|
2244
2723
|
time: /* @__PURE__ */ jsx(
|
@@ -2276,25 +2755,77 @@ const Information = ({ activeTab }) => {
|
|
2276
2755
|
);
|
2277
2756
|
};
|
2278
2757
|
const HeaderActions = ({ actions: actions2 }) => {
|
2279
|
-
|
2280
|
-
|
2758
|
+
const [dialogId, setDialogId] = React.useState(null);
|
2759
|
+
const handleClick = (action) => async (e) => {
|
2760
|
+
if (!("options" in action)) {
|
2761
|
+
const { onClick = () => false, dialog, id } = action;
|
2762
|
+
const muteDialog = await onClick(e);
|
2763
|
+
if (dialog && !muteDialog) {
|
2764
|
+
e.preventDefault();
|
2765
|
+
setDialogId(id);
|
2766
|
+
}
|
2767
|
+
}
|
2768
|
+
};
|
2769
|
+
const handleClose = () => {
|
2770
|
+
setDialogId(null);
|
2771
|
+
};
|
2772
|
+
return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
|
2773
|
+
if (action.options) {
|
2281
2774
|
return /* @__PURE__ */ jsx(
|
2282
2775
|
SingleSelect,
|
2283
2776
|
{
|
2284
2777
|
size: "S",
|
2285
|
-
disabled: action.disabled,
|
2286
|
-
"aria-label": action.label,
|
2287
2778
|
onChange: action.onSelect,
|
2288
|
-
|
2779
|
+
"aria-label": action.label,
|
2780
|
+
...action,
|
2289
2781
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2290
2782
|
},
|
2291
2783
|
action.id
|
2292
2784
|
);
|
2293
2785
|
} else {
|
2294
|
-
|
2786
|
+
if (action.type === "icon") {
|
2787
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
2788
|
+
/* @__PURE__ */ jsx(
|
2789
|
+
IconButton,
|
2790
|
+
{
|
2791
|
+
disabled: action.disabled,
|
2792
|
+
label: action.label,
|
2793
|
+
size: "S",
|
2794
|
+
onClick: handleClick(action),
|
2795
|
+
children: action.icon
|
2796
|
+
}
|
2797
|
+
),
|
2798
|
+
action.dialog ? /* @__PURE__ */ jsx(
|
2799
|
+
HeaderActionDialog,
|
2800
|
+
{
|
2801
|
+
...action.dialog,
|
2802
|
+
isOpen: dialogId === action.id,
|
2803
|
+
onClose: handleClose
|
2804
|
+
}
|
2805
|
+
) : null
|
2806
|
+
] }, action.id);
|
2807
|
+
}
|
2295
2808
|
}
|
2296
2809
|
}) });
|
2297
2810
|
};
|
2811
|
+
const HeaderActionDialog = ({
|
2812
|
+
onClose,
|
2813
|
+
onCancel,
|
2814
|
+
title,
|
2815
|
+
content: Content,
|
2816
|
+
isOpen
|
2817
|
+
}) => {
|
2818
|
+
const handleClose = async () => {
|
2819
|
+
if (onCancel) {
|
2820
|
+
await onCancel();
|
2821
|
+
}
|
2822
|
+
onClose();
|
2823
|
+
};
|
2824
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2825
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2826
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
|
2827
|
+
] }) });
|
2828
|
+
};
|
2298
2829
|
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
2299
2830
|
const navigate = useNavigate();
|
2300
2831
|
const { formatMessage } = useIntl();
|
@@ -2335,12 +2866,16 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2335
2866
|
const { delete: deleteAction } = useDocumentActions();
|
2336
2867
|
const { toggleNotification } = useNotification();
|
2337
2868
|
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2869
|
+
const isLocalized = document?.locale != null;
|
2338
2870
|
return {
|
2339
2871
|
disabled: !canDelete || !document,
|
2340
|
-
label: formatMessage(
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2872
|
+
label: formatMessage(
|
2873
|
+
{
|
2874
|
+
id: "content-manager.actions.delete.label",
|
2875
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2876
|
+
},
|
2877
|
+
{ isLocalized }
|
2878
|
+
),
|
2344
2879
|
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2345
2880
|
dialog: {
|
2346
2881
|
type: "dialog",
|
@@ -2430,7 +2965,7 @@ const ActionsPanel = () => {
|
|
2430
2965
|
return {
|
2431
2966
|
title: formatMessage({
|
2432
2967
|
id: "content-manager.containers.edit.panels.default.title",
|
2433
|
-
defaultMessage: "
|
2968
|
+
defaultMessage: "Entry"
|
2434
2969
|
}),
|
2435
2970
|
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2436
2971
|
};
|
@@ -2491,155 +3026,483 @@ const Panel = React.forwardRef(({ children, title }, ref) => {
|
|
2491
3026
|
}
|
2492
3027
|
);
|
2493
3028
|
});
|
2494
|
-
const
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
3029
|
+
const ConfirmBulkActionDialog = ({
|
3030
|
+
onToggleDialog,
|
3031
|
+
isOpen = false,
|
3032
|
+
dialogBody,
|
3033
|
+
endAction
|
3034
|
+
}) => {
|
3035
|
+
const { formatMessage } = useIntl();
|
3036
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
3037
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
|
3038
|
+
id: "app.components.ConfirmDialog.title",
|
3039
|
+
defaultMessage: "Confirmation"
|
3040
|
+
}) }),
|
3041
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3042
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3043
|
+
dialogBody
|
3044
|
+
] }) }),
|
3045
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
3046
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
|
3047
|
+
id: "app.components.Button.cancel",
|
3048
|
+
defaultMessage: "Cancel"
|
3049
|
+
}) }) }),
|
3050
|
+
endAction
|
3051
|
+
] })
|
3052
|
+
] }) });
|
2510
3053
|
};
|
2511
|
-
const
|
2512
|
-
|
3054
|
+
const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
|
3055
|
+
const ConfirmDialogPublishAll = ({
|
3056
|
+
isOpen,
|
3057
|
+
onToggleDialog,
|
3058
|
+
isConfirmButtonLoading = false,
|
3059
|
+
onConfirm
|
3060
|
+
}) => {
|
3061
|
+
const { formatMessage } = useIntl();
|
3062
|
+
const selectedEntries = useTable("ConfirmDialogPublishAll", (state) => state.selectedRows);
|
2513
3063
|
const { toggleNotification } = useNotification();
|
2514
|
-
const
|
2515
|
-
|
2516
|
-
|
2517
|
-
|
3064
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
|
3065
|
+
const { model, schema } = useDoc();
|
3066
|
+
const [{ query }] = useQueryParams();
|
3067
|
+
const enableDraftRelationsCount = false;
|
3068
|
+
const {
|
3069
|
+
data: countDraftRelations = 0,
|
3070
|
+
isLoading,
|
3071
|
+
error
|
3072
|
+
} = useGetManyDraftRelationCountQuery(
|
3073
|
+
{
|
3074
|
+
model,
|
3075
|
+
documentIds: selectedEntries.map((entry) => entry.documentId),
|
3076
|
+
locale: query?.plugins?.i18n?.locale
|
3077
|
+
},
|
3078
|
+
{
|
3079
|
+
skip: !enableDraftRelationsCount
|
2518
3080
|
}
|
2519
|
-
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
title: dialog.title,
|
2524
|
-
message: dialog.content,
|
2525
|
-
type: dialog.status,
|
2526
|
-
timeout: dialog.timeout,
|
2527
|
-
onClose: dialog.onClose
|
2528
|
-
});
|
2529
|
-
break;
|
2530
|
-
case "dialog":
|
2531
|
-
case "modal": {
|
2532
|
-
e.preventDefault();
|
2533
|
-
setDialogId(id);
|
2534
|
-
}
|
2535
|
-
}
|
3081
|
+
);
|
3082
|
+
React.useEffect(() => {
|
3083
|
+
if (error) {
|
3084
|
+
toggleNotification({ type: "danger", message: formatAPIError(error) });
|
2536
3085
|
}
|
2537
|
-
};
|
2538
|
-
|
2539
|
-
|
2540
|
-
|
2541
|
-
|
3086
|
+
}, [error, formatAPIError, toggleNotification]);
|
3087
|
+
if (error) {
|
3088
|
+
return null;
|
3089
|
+
}
|
3090
|
+
return /* @__PURE__ */ jsx(
|
3091
|
+
ConfirmBulkActionDialog,
|
3092
|
+
{
|
3093
|
+
isOpen: isOpen && !isLoading,
|
3094
|
+
onToggleDialog,
|
3095
|
+
dialogBody: /* @__PURE__ */ jsxs(Fragment, { children: [
|
3096
|
+
/* @__PURE__ */ jsxs(Typography, { id: "confirm-description", textAlign: "center", children: [
|
3097
|
+
countDraftRelations > 0 && formatMessage(
|
3098
|
+
{
|
3099
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
3100
|
+
defaultMessage: "<b>{count} {count, plural, one { relation } other { relations } } out of {entities} { entities, plural, one { entry } other { entries } } {count, plural, one { is } other { are } }</b> not published yet and might lead to unexpected behavior. "
|
3101
|
+
},
|
3102
|
+
{
|
3103
|
+
b: BoldChunk$1,
|
3104
|
+
count: countDraftRelations,
|
3105
|
+
entities: selectedEntries.length
|
3106
|
+
}
|
3107
|
+
),
|
3108
|
+
formatMessage({
|
3109
|
+
id: getTranslation("popUpWarning.bodyMessage.contentType.publish.all"),
|
3110
|
+
defaultMessage: "Are you sure you want to publish these entries?"
|
3111
|
+
})
|
3112
|
+
] }),
|
3113
|
+
schema?.pluginOptions && "i18n" in schema.pluginOptions && schema?.pluginOptions.i18n && /* @__PURE__ */ jsx(Typography, { textColor: "danger500", textAlign: "center", children: formatMessage(
|
3114
|
+
{
|
3115
|
+
id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
|
3116
|
+
defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
|
3117
|
+
},
|
3118
|
+
{
|
3119
|
+
em: Emphasis
|
3120
|
+
}
|
3121
|
+
) })
|
3122
|
+
] }),
|
3123
|
+
endAction: /* @__PURE__ */ jsx(
|
3124
|
+
Button,
|
3125
|
+
{
|
3126
|
+
onClick: onConfirm,
|
3127
|
+
variant: "secondary",
|
3128
|
+
startIcon: /* @__PURE__ */ jsx(Check, {}),
|
3129
|
+
loading: isConfirmButtonLoading,
|
3130
|
+
children: formatMessage({
|
3131
|
+
id: "app.utils.publish",
|
3132
|
+
defaultMessage: "Publish"
|
3133
|
+
})
|
3134
|
+
}
|
3135
|
+
)
|
2542
3136
|
}
|
2543
|
-
|
2544
|
-
|
2545
|
-
|
2546
|
-
|
2547
|
-
|
2548
|
-
|
2549
|
-
|
2550
|
-
|
2551
|
-
|
2552
|
-
|
2553
|
-
|
2554
|
-
|
2555
|
-
|
2556
|
-
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2564
|
-
|
2565
|
-
|
2566
|
-
|
2567
|
-
|
2568
|
-
|
2569
|
-
|
3137
|
+
);
|
3138
|
+
};
|
3139
|
+
const TypographyMaxWidth = styled(Typography)`
|
3140
|
+
max-width: 300px;
|
3141
|
+
`;
|
3142
|
+
const formatErrorMessages = (errors, parentKey, formatMessage) => {
|
3143
|
+
const messages = [];
|
3144
|
+
Object.entries(errors).forEach(([key, value]) => {
|
3145
|
+
const currentKey = parentKey ? `${parentKey}.${key}` : key;
|
3146
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
3147
|
+
if ("id" in value && "defaultMessage" in value) {
|
3148
|
+
messages.push(
|
3149
|
+
formatMessage(
|
3150
|
+
{
|
3151
|
+
id: `${value.id}.withField`,
|
3152
|
+
defaultMessage: value.defaultMessage
|
3153
|
+
},
|
3154
|
+
{ field: currentKey }
|
3155
|
+
)
|
3156
|
+
);
|
3157
|
+
} else {
|
3158
|
+
messages.push(
|
3159
|
+
...formatErrorMessages(
|
3160
|
+
// @ts-expect-error TODO: check why value is not compatible with FormErrors
|
3161
|
+
value,
|
3162
|
+
currentKey,
|
3163
|
+
formatMessage
|
3164
|
+
)
|
3165
|
+
);
|
2570
3166
|
}
|
2571
|
-
|
3167
|
+
} else {
|
3168
|
+
messages.push(
|
3169
|
+
formatMessage(
|
3170
|
+
{
|
3171
|
+
id: `${value}.withField`,
|
3172
|
+
defaultMessage: value
|
3173
|
+
},
|
3174
|
+
{ field: currentKey }
|
3175
|
+
)
|
3176
|
+
);
|
3177
|
+
}
|
3178
|
+
});
|
3179
|
+
return messages;
|
3180
|
+
};
|
3181
|
+
const EntryValidationText = ({ validationErrors, status }) => {
|
3182
|
+
const { formatMessage } = useIntl();
|
3183
|
+
if (validationErrors) {
|
3184
|
+
const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
|
3185
|
+
" "
|
3186
|
+
);
|
3187
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3188
|
+
/* @__PURE__ */ jsx(CrossCircle, { fill: "danger600" }),
|
3189
|
+
/* @__PURE__ */ jsx(Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
|
3190
|
+
] });
|
3191
|
+
}
|
3192
|
+
if (status === "published") {
|
3193
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3194
|
+
/* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
|
3195
|
+
/* @__PURE__ */ jsx(Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
|
3196
|
+
id: "content-manager.bulk-publish.already-published",
|
3197
|
+
defaultMessage: "Already Published"
|
3198
|
+
}) })
|
3199
|
+
] });
|
3200
|
+
}
|
3201
|
+
if (status === "modified") {
|
3202
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3203
|
+
/* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
|
3204
|
+
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
3205
|
+
id: "content-manager.bulk-publish.modified",
|
3206
|
+
defaultMessage: "Ready to publish changes"
|
3207
|
+
}) })
|
3208
|
+
] });
|
3209
|
+
}
|
3210
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3211
|
+
/* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
|
3212
|
+
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
3213
|
+
id: "app.utils.ready-to-publish",
|
3214
|
+
defaultMessage: "Ready to publish"
|
3215
|
+
}) })
|
2572
3216
|
] });
|
2573
3217
|
};
|
2574
|
-
const
|
2575
|
-
|
2576
|
-
|
2577
|
-
|
2578
|
-
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
3218
|
+
const TABLE_HEADERS = [
|
3219
|
+
{ name: "id", label: "id" },
|
3220
|
+
{ name: "name", label: "name" },
|
3221
|
+
{ name: "status", label: "status" },
|
3222
|
+
{ name: "publicationStatus", label: "Publication status" }
|
3223
|
+
];
|
3224
|
+
const SelectedEntriesTableContent = ({
|
3225
|
+
isPublishing,
|
3226
|
+
rowsToDisplay = [],
|
3227
|
+
entriesToPublish = [],
|
3228
|
+
validationErrors = {}
|
2583
3229
|
}) => {
|
3230
|
+
const { pathname } = useLocation();
|
2584
3231
|
const { formatMessage } = useIntl();
|
2585
|
-
const
|
2586
|
-
|
2587
|
-
|
3232
|
+
const {
|
3233
|
+
list: {
|
3234
|
+
settings: { mainField }
|
2588
3235
|
}
|
2589
|
-
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
3236
|
+
} = useDocLayout();
|
3237
|
+
const shouldDisplayMainField = mainField != null && mainField !== "id";
|
3238
|
+
return /* @__PURE__ */ jsxs(Table.Content, { children: [
|
3239
|
+
/* @__PURE__ */ jsxs(Table.Head, { children: [
|
3240
|
+
/* @__PURE__ */ jsx(Table.HeaderCheckboxCell, {}),
|
3241
|
+
TABLE_HEADERS.filter((head) => head.name !== "name" || shouldDisplayMainField).map(
|
3242
|
+
(head) => /* @__PURE__ */ jsx(Table.HeaderCell, { ...head }, head.name)
|
3243
|
+
)
|
3244
|
+
] }),
|
3245
|
+
/* @__PURE__ */ jsx(Table.Loading, {}),
|
3246
|
+
/* @__PURE__ */ jsx(Table.Body, { children: rowsToDisplay.map((row, index2) => /* @__PURE__ */ jsxs(Table.Row, { children: [
|
3247
|
+
/* @__PURE__ */ jsx(Table.CheckboxCell, { id: row.id }),
|
3248
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { children: row.id }) }),
|
3249
|
+
shouldDisplayMainField && /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { children: row[mainField] }) }),
|
3250
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(DocumentStatus, { status: row.status, maxWidth: "min-content" }) }),
|
3251
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: isPublishing && entriesToPublish.includes(row.documentId) ? /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3252
|
+
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
3253
|
+
id: "content-manager.success.record.publishing",
|
3254
|
+
defaultMessage: "Publishing..."
|
3255
|
+
}) }),
|
3256
|
+
/* @__PURE__ */ jsx(Loader, { small: true })
|
3257
|
+
] }) : /* @__PURE__ */ jsx(
|
3258
|
+
EntryValidationText,
|
3259
|
+
{
|
3260
|
+
validationErrors: validationErrors[row.documentId],
|
3261
|
+
status: row.status
|
3262
|
+
}
|
3263
|
+
) }),
|
3264
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
|
3265
|
+
IconButton,
|
3266
|
+
{
|
3267
|
+
tag: Link,
|
3268
|
+
to: {
|
3269
|
+
pathname: `${pathname}/${row.documentId}`,
|
3270
|
+
search: row.locale && `?plugins[i18n][locale]=${row.locale}`
|
3271
|
+
},
|
3272
|
+
state: { from: pathname },
|
3273
|
+
label: formatMessage(
|
3274
|
+
{ id: "app.component.HelperPluginTable.edit", defaultMessage: "Edit {target}" },
|
3275
|
+
{
|
3276
|
+
target: formatMessage(
|
3277
|
+
{
|
3278
|
+
id: "content-manager.components.ListViewHelperPluginTable.row-line",
|
3279
|
+
defaultMessage: "item line {number}"
|
3280
|
+
},
|
3281
|
+
{ number: index2 + 1 }
|
3282
|
+
)
|
3283
|
+
}
|
3284
|
+
),
|
3285
|
+
target: "_blank",
|
3286
|
+
marginLeft: "auto",
|
3287
|
+
variant: "ghost",
|
3288
|
+
children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
|
3289
|
+
}
|
3290
|
+
) }) })
|
3291
|
+
] }, row.id)) })
|
3292
|
+
] });
|
3293
|
+
};
|
3294
|
+
const BoldChunk = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
|
3295
|
+
const SelectedEntriesModalContent = ({
|
3296
|
+
listViewSelectedEntries,
|
3297
|
+
toggleModal,
|
3298
|
+
setListViewSelectedDocuments,
|
3299
|
+
model
|
3300
|
+
}) => {
|
3301
|
+
const { formatMessage } = useIntl();
|
3302
|
+
const { schema, components } = useContentTypeSchema(model);
|
3303
|
+
const documentIds = listViewSelectedEntries.map(({ documentId }) => documentId);
|
3304
|
+
const [{ query }] = useQueryParams();
|
3305
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
3306
|
+
const { data, isLoading, isFetching, refetch } = useGetAllDocumentsQuery(
|
3307
|
+
{
|
3308
|
+
model,
|
3309
|
+
params: {
|
3310
|
+
page: "1",
|
3311
|
+
pageSize: documentIds.length.toString(),
|
3312
|
+
sort: query.sort,
|
3313
|
+
filters: {
|
3314
|
+
documentId: {
|
3315
|
+
$in: documentIds
|
3316
|
+
}
|
3317
|
+
},
|
3318
|
+
locale: query.plugins?.i18n?.locale
|
3319
|
+
}
|
3320
|
+
},
|
3321
|
+
{
|
3322
|
+
selectFromResult: ({ data: data2, ...restRes }) => ({ data: data2?.results ?? [], ...restRes })
|
3323
|
+
}
|
3324
|
+
);
|
3325
|
+
const { rows, validationErrors } = React.useMemo(() => {
|
3326
|
+
if (data.length > 0 && schema) {
|
3327
|
+
const validate = createYupSchema(
|
3328
|
+
schema.attributes,
|
3329
|
+
components,
|
3330
|
+
// Since this is the "Publish" action, the validation
|
3331
|
+
// schema must enforce the rules for published entities
|
3332
|
+
{ status: "published" }
|
3333
|
+
);
|
3334
|
+
const validationErrors2 = {};
|
3335
|
+
const rows2 = data.map((entry) => {
|
3336
|
+
try {
|
3337
|
+
validate.validateSync(entry, { abortEarly: false });
|
3338
|
+
return entry;
|
3339
|
+
} catch (e) {
|
3340
|
+
if (e instanceof ValidationError) {
|
3341
|
+
validationErrors2[entry.documentId] = getYupValidationErrors(e);
|
3342
|
+
}
|
3343
|
+
return entry;
|
3344
|
+
}
|
3345
|
+
});
|
3346
|
+
return { rows: rows2, validationErrors: validationErrors2 };
|
3347
|
+
}
|
3348
|
+
return {
|
3349
|
+
rows: [],
|
3350
|
+
validationErrors: {}
|
3351
|
+
};
|
3352
|
+
}, [components, data, schema]);
|
3353
|
+
const [publishedCount, setPublishedCount] = React.useState(0);
|
3354
|
+
const [isDialogOpen, setIsDialogOpen] = React.useState(false);
|
3355
|
+
const { publishMany: bulkPublishAction } = useDocumentActions();
|
3356
|
+
const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation();
|
3357
|
+
const selectedRows = useTable("publishAction", (state) => state.selectedRows);
|
3358
|
+
const selectedEntries = rows.filter(
|
3359
|
+
(entry) => selectedRows.some((selectedEntry) => selectedEntry.documentId === entry.documentId)
|
3360
|
+
);
|
3361
|
+
const entriesToPublish = selectedEntries.filter((entry) => !validationErrors[entry.documentId]).map((entry) => entry.documentId);
|
3362
|
+
const selectedEntriesWithErrorsCount = selectedEntries.filter(
|
3363
|
+
({ documentId }) => validationErrors[documentId]
|
3364
|
+
).length;
|
3365
|
+
const selectedEntriesPublished = selectedEntries.filter(
|
3366
|
+
({ status }) => status === "published"
|
3367
|
+
).length;
|
3368
|
+
const selectedEntriesWithNoErrorsCount = selectedEntries.length - selectedEntriesWithErrorsCount - selectedEntriesPublished;
|
3369
|
+
const toggleDialog = () => setIsDialogOpen((prev) => !prev);
|
3370
|
+
const handleConfirmBulkPublish = async () => {
|
3371
|
+
toggleDialog();
|
3372
|
+
const res = await bulkPublishAction({ model, documentIds: entriesToPublish, params });
|
3373
|
+
if (!("error" in res)) {
|
3374
|
+
setPublishedCount(res.count);
|
3375
|
+
const unpublishedEntries = rows.filter((row) => {
|
3376
|
+
return !entriesToPublish.includes(row.documentId);
|
3377
|
+
});
|
3378
|
+
setListViewSelectedDocuments(unpublishedEntries);
|
2594
3379
|
}
|
2595
|
-
onClose();
|
2596
3380
|
};
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
2600
|
-
|
3381
|
+
const getFormattedCountMessage = () => {
|
3382
|
+
if (publishedCount) {
|
3383
|
+
return formatMessage(
|
3384
|
+
{
|
3385
|
+
id: getTranslation("containers.list.selectedEntriesModal.publishedCount"),
|
3386
|
+
defaultMessage: "<b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} published. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action."
|
3387
|
+
},
|
3388
|
+
{
|
3389
|
+
publishedCount,
|
3390
|
+
withErrorsCount: selectedEntriesWithErrorsCount,
|
3391
|
+
b: BoldChunk
|
3392
|
+
}
|
3393
|
+
);
|
3394
|
+
}
|
3395
|
+
return formatMessage(
|
2601
3396
|
{
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
3397
|
+
id: getTranslation("containers.list.selectedEntriesModal.selectedCount"),
|
3398
|
+
defaultMessage: "<b>{alreadyPublishedCount}</b> {alreadyPublishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{readyToPublishCount}</b> {readyToPublishCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action."
|
3399
|
+
},
|
3400
|
+
{
|
3401
|
+
readyToPublishCount: selectedEntriesWithNoErrorsCount,
|
3402
|
+
withErrorsCount: selectedEntriesWithErrorsCount,
|
3403
|
+
alreadyPublishedCount: selectedEntriesPublished,
|
3404
|
+
b: BoldChunk
|
3405
|
+
}
|
3406
|
+
);
|
3407
|
+
};
|
3408
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
3409
|
+
/* @__PURE__ */ jsxs(Modal.Body, { children: [
|
3410
|
+
/* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
|
3411
|
+
/* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
|
3412
|
+
SelectedEntriesTableContent,
|
3413
|
+
{
|
3414
|
+
isPublishing: isSubmittingForm,
|
3415
|
+
rowsToDisplay: rows,
|
3416
|
+
entriesToPublish,
|
3417
|
+
validationErrors
|
3418
|
+
}
|
3419
|
+
) })
|
3420
|
+
] }),
|
3421
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3422
|
+
/* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
|
3423
|
+
id: "app.components.Button.cancel",
|
3424
|
+
defaultMessage: "Cancel"
|
3425
|
+
}) }),
|
3426
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3427
|
+
/* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
|
3428
|
+
/* @__PURE__ */ jsx(
|
2607
3429
|
Button,
|
2608
3430
|
{
|
2609
|
-
onClick:
|
2610
|
-
|
2611
|
-
|
2612
|
-
children:
|
2613
|
-
id: "app.components.Button.confirm",
|
2614
|
-
defaultMessage: "Confirm"
|
2615
|
-
})
|
3431
|
+
onClick: toggleDialog,
|
3432
|
+
disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
|
3433
|
+
loading: isSubmittingForm,
|
3434
|
+
children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
|
2616
3435
|
}
|
2617
3436
|
)
|
3437
|
+
] })
|
3438
|
+
] }),
|
3439
|
+
/* @__PURE__ */ jsx(
|
3440
|
+
ConfirmDialogPublishAll,
|
3441
|
+
{
|
3442
|
+
isOpen: isDialogOpen,
|
3443
|
+
onToggleDialog: toggleDialog,
|
3444
|
+
isConfirmButtonLoading: isSubmittingForm,
|
3445
|
+
onConfirm: handleConfirmBulkPublish
|
2618
3446
|
}
|
2619
3447
|
)
|
2620
3448
|
] });
|
2621
3449
|
};
|
2622
|
-
const
|
2623
|
-
|
2624
|
-
|
2625
|
-
|
2626
|
-
|
2627
|
-
|
2628
|
-
|
2629
|
-
|
2630
|
-
if (!
|
3450
|
+
const PublishAction = ({ documents, model }) => {
|
3451
|
+
const { formatMessage } = useIntl();
|
3452
|
+
const hasPublishPermission = useDocumentRBAC("unpublishAction", (state) => state.canPublish);
|
3453
|
+
const showPublishButton = hasPublishPermission && documents.some(({ status }) => status !== "published");
|
3454
|
+
const setListViewSelectedDocuments = useTable("publishAction", (state) => state.selectRow);
|
3455
|
+
const refetchList = () => {
|
3456
|
+
contentManagerApi.util.invalidateTags([{ type: "Document", id: `${model}_LIST` }]);
|
3457
|
+
};
|
3458
|
+
if (!showPublishButton)
|
2631
3459
|
return null;
|
2632
|
-
|
2633
|
-
|
2634
|
-
|
2635
|
-
|
3460
|
+
return {
|
3461
|
+
actionType: "publish",
|
3462
|
+
variant: "tertiary",
|
3463
|
+
label: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" }),
|
3464
|
+
dialog: {
|
3465
|
+
type: "modal",
|
3466
|
+
title: formatMessage({
|
3467
|
+
id: getTranslation("containers.ListPage.selectedEntriesModal.title"),
|
3468
|
+
defaultMessage: "Publish entries"
|
3469
|
+
}),
|
3470
|
+
content: ({ onClose }) => {
|
3471
|
+
return /* @__PURE__ */ jsx(Table.Root, { rows: documents, defaultSelectedRows: documents, headers: TABLE_HEADERS, children: /* @__PURE__ */ jsx(
|
3472
|
+
SelectedEntriesModalContent,
|
3473
|
+
{
|
3474
|
+
listViewSelectedEntries: documents,
|
3475
|
+
toggleModal: () => {
|
3476
|
+
onClose();
|
3477
|
+
refetchList();
|
3478
|
+
},
|
3479
|
+
setListViewSelectedDocuments,
|
3480
|
+
model
|
3481
|
+
}
|
3482
|
+
) });
|
3483
|
+
},
|
3484
|
+
onClose: () => {
|
3485
|
+
refetchList();
|
3486
|
+
}
|
2636
3487
|
}
|
2637
|
-
onModalClose();
|
2638
3488
|
};
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2642
|
-
|
3489
|
+
};
|
3490
|
+
const BulkActionsRenderer = () => {
|
3491
|
+
const plugins = useStrapiApp("BulkActionsRenderer", (state) => state.plugins);
|
3492
|
+
const { model, collectionType } = useDoc();
|
3493
|
+
const { selectedRows } = useTable("BulkActionsRenderer", (state) => state);
|
3494
|
+
return /* @__PURE__ */ jsx(Flex, { gap: 2, children: /* @__PURE__ */ jsx(
|
3495
|
+
DescriptionComponentRenderer,
|
3496
|
+
{
|
3497
|
+
props: {
|
3498
|
+
model,
|
3499
|
+
collectionType,
|
3500
|
+
documents: selectedRows
|
3501
|
+
},
|
3502
|
+
descriptions: plugins["content-manager"].apis.getBulkActions(),
|
3503
|
+
children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
|
3504
|
+
}
|
3505
|
+
) });
|
2643
3506
|
};
|
2644
3507
|
const DeleteAction = ({ documents, model }) => {
|
2645
3508
|
const { formatMessage } = useIntl();
|
@@ -2673,6 +3536,7 @@ const DeleteAction = ({ documents, model }) => {
|
|
2673
3536
|
defaultMessage: "Confirmation"
|
2674
3537
|
}),
|
2675
3538
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3539
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
2676
3540
|
/* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
2677
3541
|
id: "popUpWarning.bodyMessage.contentType.delete.all",
|
2678
3542
|
defaultMessage: "Are you sure you want to delete these entries?"
|
@@ -2709,7 +3573,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
2709
3573
|
selectRow([]);
|
2710
3574
|
}
|
2711
3575
|
};
|
2712
|
-
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published");
|
3576
|
+
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
|
2713
3577
|
if (!showUnpublishButton)
|
2714
3578
|
return null;
|
2715
3579
|
return {
|
@@ -2722,6 +3586,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
2722
3586
|
defaultMessage: "Confirmation"
|
2723
3587
|
}),
|
2724
3588
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3589
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
2725
3590
|
/* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
2726
3591
|
id: "popUpWarning.bodyMessage.contentType.unpublish.all",
|
2727
3592
|
defaultMessage: "Are you sure you want to unpublish these entries?"
|
@@ -2746,7 +3611,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
2746
3611
|
};
|
2747
3612
|
UnpublishAction.type = "unpublish";
|
2748
3613
|
const Emphasis = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
|
2749
|
-
const DEFAULT_BULK_ACTIONS = [UnpublishAction, DeleteAction];
|
3614
|
+
const DEFAULT_BULK_ACTIONS = [PublishAction, UnpublishAction, DeleteAction];
|
2750
3615
|
const AutoCloneFailureModalBody = ({ prohibitedFields }) => {
|
2751
3616
|
const { formatMessage } = useIntl();
|
2752
3617
|
const getDefaultErrorMessage = (reason) => {
|
@@ -2815,7 +3680,7 @@ const TableActions = ({ document }) => {
|
|
2815
3680
|
DescriptionComponentRenderer,
|
2816
3681
|
{
|
2817
3682
|
props,
|
2818
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3683
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
|
2819
3684
|
children: (actions2) => {
|
2820
3685
|
const tableRowActions = actions2.filter((action) => {
|
2821
3686
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -2926,7 +3791,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
2926
3791
|
}),
|
2927
3792
|
content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
|
2928
3793
|
footer: ({ onClose }) => {
|
2929
|
-
return /* @__PURE__ */ jsxs(
|
3794
|
+
return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
2930
3795
|
/* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
|
2931
3796
|
id: "cancel",
|
2932
3797
|
defaultMessage: "Cancel"
|
@@ -2967,8 +3832,7 @@ class ContentManagerPlugin {
|
|
2967
3832
|
documentActions = [
|
2968
3833
|
...DEFAULT_ACTIONS,
|
2969
3834
|
...DEFAULT_TABLE_ROW_ACTIONS,
|
2970
|
-
...DEFAULT_HEADER_ACTIONS
|
2971
|
-
HistoryAction
|
3835
|
+
...DEFAULT_HEADER_ACTIONS
|
2972
3836
|
];
|
2973
3837
|
editViewSidePanels = [ActionsPanel];
|
2974
3838
|
headerActions = [];
|
@@ -3057,6 +3921,52 @@ const getPrintableType = (value) => {
|
|
3057
3921
|
}
|
3058
3922
|
return nativeType;
|
3059
3923
|
};
|
3924
|
+
const HistoryAction = ({ model, document }) => {
|
3925
|
+
const { formatMessage } = useIntl();
|
3926
|
+
const [{ query }] = useQueryParams();
|
3927
|
+
const navigate = useNavigate();
|
3928
|
+
const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
|
3929
|
+
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
3930
|
+
return null;
|
3931
|
+
}
|
3932
|
+
return {
|
3933
|
+
icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
|
3934
|
+
label: formatMessage({
|
3935
|
+
id: "content-manager.history.document-action",
|
3936
|
+
defaultMessage: "Content History"
|
3937
|
+
}),
|
3938
|
+
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
3939
|
+
disabled: (
|
3940
|
+
/**
|
3941
|
+
* The user is creating a new document.
|
3942
|
+
* It hasn't been saved yet, so there's no history to go to
|
3943
|
+
*/
|
3944
|
+
!document || /**
|
3945
|
+
* The document has been created but the current dimension has never been saved.
|
3946
|
+
* For example, the user is creating a new locale in an existing document,
|
3947
|
+
* so there's no history for the document in that locale
|
3948
|
+
*/
|
3949
|
+
!document.id || /**
|
3950
|
+
* History is only available for content types created by the user.
|
3951
|
+
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
3952
|
+
* which start with `admin::` or `plugin::`
|
3953
|
+
*/
|
3954
|
+
!model.startsWith("api::")
|
3955
|
+
),
|
3956
|
+
position: "header"
|
3957
|
+
};
|
3958
|
+
};
|
3959
|
+
HistoryAction.type = "history";
|
3960
|
+
const historyAdmin = {
|
3961
|
+
bootstrap(app) {
|
3962
|
+
const { addDocumentAction } = app.getPlugin("content-manager").apis;
|
3963
|
+
addDocumentAction((actions2) => {
|
3964
|
+
const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
|
3965
|
+
actions2.splice(indexOfDeleteAction, 0, HistoryAction);
|
3966
|
+
return actions2;
|
3967
|
+
});
|
3968
|
+
}
|
3969
|
+
};
|
3060
3970
|
const initialState = {
|
3061
3971
|
collectionTypeLinks: [],
|
3062
3972
|
components: [],
|
@@ -3093,308 +4003,6 @@ const { setInitialData } = actions;
|
|
3093
4003
|
const reducer = combineReducers({
|
3094
4004
|
app: reducer$1
|
3095
4005
|
});
|
3096
|
-
const HOOKS = {
|
3097
|
-
/**
|
3098
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
3099
|
-
* @constant
|
3100
|
-
* @type {string}
|
3101
|
-
*/
|
3102
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
3103
|
-
/**
|
3104
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
3105
|
-
* @constant
|
3106
|
-
* @type {string}
|
3107
|
-
*/
|
3108
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
3109
|
-
/**
|
3110
|
-
* Hook that allows to mutate the CM's edit view layout
|
3111
|
-
* @constant
|
3112
|
-
* @type {string}
|
3113
|
-
*/
|
3114
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
3115
|
-
/**
|
3116
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
3117
|
-
* @constant
|
3118
|
-
* @type {string}
|
3119
|
-
*/
|
3120
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
3121
|
-
};
|
3122
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
3123
|
-
endpoints: (builder) => ({
|
3124
|
-
getContentTypeConfiguration: builder.query({
|
3125
|
-
query: (uid) => ({
|
3126
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
3127
|
-
method: "GET"
|
3128
|
-
}),
|
3129
|
-
transformResponse: (response) => response.data,
|
3130
|
-
providesTags: (_result, _error, uid) => [
|
3131
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
3132
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
3133
|
-
]
|
3134
|
-
}),
|
3135
|
-
getAllContentTypeSettings: builder.query({
|
3136
|
-
query: () => "/content-manager/content-types-settings",
|
3137
|
-
transformResponse: (response) => response.data,
|
3138
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
3139
|
-
}),
|
3140
|
-
updateContentTypeConfiguration: builder.mutation({
|
3141
|
-
query: ({ uid, ...body }) => ({
|
3142
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
3143
|
-
method: "PUT",
|
3144
|
-
data: body
|
3145
|
-
}),
|
3146
|
-
transformResponse: (response) => response.data,
|
3147
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
3148
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
3149
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
3150
|
-
// Is this necessary?
|
3151
|
-
{ type: "InitialData" }
|
3152
|
-
]
|
3153
|
-
})
|
3154
|
-
})
|
3155
|
-
});
|
3156
|
-
const {
|
3157
|
-
useGetContentTypeConfigurationQuery,
|
3158
|
-
useGetAllContentTypeSettingsQuery,
|
3159
|
-
useUpdateContentTypeConfigurationMutation
|
3160
|
-
} = contentTypesApi;
|
3161
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
3162
|
-
const { type } = attribute;
|
3163
|
-
if (type === "relation") {
|
3164
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
3165
|
-
}
|
3166
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
3167
|
-
};
|
3168
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
3169
|
-
if (!mainFieldName) {
|
3170
|
-
return void 0;
|
3171
|
-
}
|
3172
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
3173
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
3174
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
3175
|
-
);
|
3176
|
-
return {
|
3177
|
-
name: mainFieldName,
|
3178
|
-
type: mainFieldType ?? "string"
|
3179
|
-
};
|
3180
|
-
};
|
3181
|
-
const DEFAULT_SETTINGS = {
|
3182
|
-
bulkable: false,
|
3183
|
-
filterable: false,
|
3184
|
-
searchable: false,
|
3185
|
-
pagination: false,
|
3186
|
-
defaultSortBy: "",
|
3187
|
-
defaultSortOrder: "asc",
|
3188
|
-
mainField: "id",
|
3189
|
-
pageSize: 10
|
3190
|
-
};
|
3191
|
-
const useDocumentLayout = (model) => {
|
3192
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
3193
|
-
const [{ query }] = useQueryParams();
|
3194
|
-
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
3195
|
-
const { toggleNotification } = useNotification();
|
3196
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
3197
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
3198
|
-
const {
|
3199
|
-
data,
|
3200
|
-
isLoading: isLoadingConfigs,
|
3201
|
-
error,
|
3202
|
-
isFetching: isFetchingConfigs
|
3203
|
-
} = useGetContentTypeConfigurationQuery(model);
|
3204
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
3205
|
-
React.useEffect(() => {
|
3206
|
-
if (error) {
|
3207
|
-
toggleNotification({
|
3208
|
-
type: "danger",
|
3209
|
-
message: formatAPIError(error)
|
3210
|
-
});
|
3211
|
-
}
|
3212
|
-
}, [error, formatAPIError, toggleNotification]);
|
3213
|
-
const editLayout = React.useMemo(
|
3214
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
3215
|
-
layout: [],
|
3216
|
-
components: {},
|
3217
|
-
metadatas: {},
|
3218
|
-
options: {},
|
3219
|
-
settings: DEFAULT_SETTINGS
|
3220
|
-
},
|
3221
|
-
[data, isLoading, schemas, schema, components]
|
3222
|
-
);
|
3223
|
-
const listLayout = React.useMemo(() => {
|
3224
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
3225
|
-
layout: [],
|
3226
|
-
metadatas: {},
|
3227
|
-
options: {},
|
3228
|
-
settings: DEFAULT_SETTINGS
|
3229
|
-
};
|
3230
|
-
}, [data, isLoading, schemas, schema, components]);
|
3231
|
-
const { layout: edit } = React.useMemo(
|
3232
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
3233
|
-
layout: editLayout,
|
3234
|
-
query
|
3235
|
-
}),
|
3236
|
-
[editLayout, query, runHookWaterfall]
|
3237
|
-
);
|
3238
|
-
return {
|
3239
|
-
error,
|
3240
|
-
isLoading,
|
3241
|
-
edit,
|
3242
|
-
list: listLayout
|
3243
|
-
};
|
3244
|
-
};
|
3245
|
-
const useDocLayout = () => {
|
3246
|
-
const { model } = useDoc();
|
3247
|
-
return useDocumentLayout(model);
|
3248
|
-
};
|
3249
|
-
const formatEditLayout = (data, {
|
3250
|
-
schemas,
|
3251
|
-
schema,
|
3252
|
-
components
|
3253
|
-
}) => {
|
3254
|
-
let currentPanelIndex = 0;
|
3255
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
3256
|
-
data.contentType.layouts.edit,
|
3257
|
-
schema?.attributes,
|
3258
|
-
data.contentType.metadatas,
|
3259
|
-
{ configurations: data.components, schemas: components },
|
3260
|
-
schemas
|
3261
|
-
).reduce((panels, row) => {
|
3262
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
3263
|
-
panels.push([row]);
|
3264
|
-
currentPanelIndex += 2;
|
3265
|
-
} else {
|
3266
|
-
if (!panels[currentPanelIndex]) {
|
3267
|
-
panels.push([]);
|
3268
|
-
}
|
3269
|
-
panels[currentPanelIndex].push(row);
|
3270
|
-
}
|
3271
|
-
return panels;
|
3272
|
-
}, []);
|
3273
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
3274
|
-
(acc, [uid, configuration]) => {
|
3275
|
-
acc[uid] = {
|
3276
|
-
layout: convertEditLayoutToFieldLayouts(
|
3277
|
-
configuration.layouts.edit,
|
3278
|
-
components[uid].attributes,
|
3279
|
-
configuration.metadatas
|
3280
|
-
),
|
3281
|
-
settings: {
|
3282
|
-
...configuration.settings,
|
3283
|
-
icon: components[uid].info.icon,
|
3284
|
-
displayName: components[uid].info.displayName
|
3285
|
-
}
|
3286
|
-
};
|
3287
|
-
return acc;
|
3288
|
-
},
|
3289
|
-
{}
|
3290
|
-
);
|
3291
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
3292
|
-
(acc, [attribute, metadata]) => {
|
3293
|
-
return {
|
3294
|
-
...acc,
|
3295
|
-
[attribute]: metadata.edit
|
3296
|
-
};
|
3297
|
-
},
|
3298
|
-
{}
|
3299
|
-
);
|
3300
|
-
return {
|
3301
|
-
layout: panelledEditAttributes,
|
3302
|
-
components: componentEditAttributes,
|
3303
|
-
metadatas: editMetadatas,
|
3304
|
-
settings: {
|
3305
|
-
...data.contentType.settings,
|
3306
|
-
displayName: schema?.info.displayName
|
3307
|
-
},
|
3308
|
-
options: {
|
3309
|
-
...schema?.options,
|
3310
|
-
...schema?.pluginOptions,
|
3311
|
-
...data.contentType.options
|
3312
|
-
}
|
3313
|
-
};
|
3314
|
-
};
|
3315
|
-
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
3316
|
-
return rows.map(
|
3317
|
-
(row) => row.map((field) => {
|
3318
|
-
const attribute = attributes[field.name];
|
3319
|
-
if (!attribute) {
|
3320
|
-
return null;
|
3321
|
-
}
|
3322
|
-
const { edit: metadata } = metadatas[field.name];
|
3323
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
3324
|
-
return {
|
3325
|
-
attribute,
|
3326
|
-
disabled: !metadata.editable,
|
3327
|
-
hint: metadata.description,
|
3328
|
-
label: metadata.label ?? "",
|
3329
|
-
name: field.name,
|
3330
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
3331
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
3332
|
-
schemas,
|
3333
|
-
components: components?.schemas ?? {}
|
3334
|
-
}),
|
3335
|
-
placeholder: metadata.placeholder ?? "",
|
3336
|
-
required: attribute.required ?? false,
|
3337
|
-
size: field.size,
|
3338
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
3339
|
-
visible: metadata.visible ?? true,
|
3340
|
-
type: attribute.type
|
3341
|
-
};
|
3342
|
-
}).filter((field) => field !== null)
|
3343
|
-
);
|
3344
|
-
};
|
3345
|
-
const formatListLayout = (data, {
|
3346
|
-
schemas,
|
3347
|
-
schema,
|
3348
|
-
components
|
3349
|
-
}) => {
|
3350
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
3351
|
-
(acc, [attribute, metadata]) => {
|
3352
|
-
return {
|
3353
|
-
...acc,
|
3354
|
-
[attribute]: metadata.list
|
3355
|
-
};
|
3356
|
-
},
|
3357
|
-
{}
|
3358
|
-
);
|
3359
|
-
const listAttributes = convertListLayoutToFieldLayouts(
|
3360
|
-
data.contentType.layouts.list,
|
3361
|
-
schema?.attributes,
|
3362
|
-
listMetadatas,
|
3363
|
-
{ configurations: data.components, schemas: components },
|
3364
|
-
schemas
|
3365
|
-
);
|
3366
|
-
return {
|
3367
|
-
layout: listAttributes,
|
3368
|
-
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
3369
|
-
metadatas: listMetadatas,
|
3370
|
-
options: {
|
3371
|
-
...schema?.options,
|
3372
|
-
...schema?.pluginOptions,
|
3373
|
-
...data.contentType.options
|
3374
|
-
}
|
3375
|
-
};
|
3376
|
-
};
|
3377
|
-
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
3378
|
-
return columns.map((name) => {
|
3379
|
-
const attribute = attributes[name];
|
3380
|
-
if (!attribute) {
|
3381
|
-
return null;
|
3382
|
-
}
|
3383
|
-
const metadata = metadatas[name];
|
3384
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
3385
|
-
return {
|
3386
|
-
attribute,
|
3387
|
-
label: metadata.label ?? "",
|
3388
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
3389
|
-
schemas,
|
3390
|
-
components: components?.schemas ?? {}
|
3391
|
-
}),
|
3392
|
-
name,
|
3393
|
-
searchable: metadata.searchable ?? true,
|
3394
|
-
sortable: metadata.sortable ?? true
|
3395
|
-
};
|
3396
|
-
}).filter((field) => field !== null);
|
3397
|
-
};
|
3398
4006
|
const index = {
|
3399
4007
|
register(app) {
|
3400
4008
|
const cm = new ContentManagerPlugin();
|
@@ -3409,15 +4017,29 @@ const index = {
|
|
3409
4017
|
defaultMessage: "Content Manager"
|
3410
4018
|
},
|
3411
4019
|
permissions: [],
|
3412
|
-
Component: () => import("./layout-BinjszSQ.mjs").then((mod) => ({ default: mod.Layout })),
|
3413
4020
|
position: 1
|
3414
4021
|
});
|
4022
|
+
app.router.addRoute({
|
4023
|
+
path: "content-manager/*",
|
4024
|
+
lazy: async () => {
|
4025
|
+
const { Layout } = await import("./layout-C5uSVTqi.mjs");
|
4026
|
+
return {
|
4027
|
+
Component: Layout
|
4028
|
+
};
|
4029
|
+
},
|
4030
|
+
children: routes
|
4031
|
+
});
|
3415
4032
|
app.registerPlugin(cm.config);
|
3416
4033
|
},
|
4034
|
+
bootstrap(app) {
|
4035
|
+
if (typeof historyAdmin.bootstrap === "function") {
|
4036
|
+
historyAdmin.bootstrap(app);
|
4037
|
+
}
|
4038
|
+
},
|
3417
4039
|
async registerTrads({ locales }) {
|
3418
4040
|
const importedTrads = await Promise.all(
|
3419
4041
|
locales.map((locale) => {
|
3420
|
-
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-
|
4042
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-DKV44jRb.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
|
3421
4043
|
return {
|
3422
4044
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3423
4045
|
locale
|
@@ -3445,36 +4067,37 @@ export {
|
|
3445
4067
|
InjectionZone as I,
|
3446
4068
|
useDocument as J,
|
3447
4069
|
index as K,
|
3448
|
-
|
4070
|
+
useContentManagerContext as L,
|
4071
|
+
useDocumentActions as M,
|
3449
4072
|
Panels as P,
|
3450
4073
|
RelativeTime as R,
|
3451
4074
|
SINGLE_TYPES as S,
|
3452
4075
|
TableActions as T,
|
3453
|
-
|
3454
|
-
|
3455
|
-
|
3456
|
-
|
3457
|
-
|
3458
|
-
|
4076
|
+
useGetInitialDataQuery as a,
|
4077
|
+
useGetAllContentTypeSettingsQuery as b,
|
4078
|
+
useDoc as c,
|
4079
|
+
buildValidParams as d,
|
4080
|
+
contentManagerApi as e,
|
4081
|
+
useDocumentRBAC as f,
|
3459
4082
|
getTranslation as g,
|
3460
|
-
|
3461
|
-
|
3462
|
-
|
3463
|
-
|
3464
|
-
|
3465
|
-
|
3466
|
-
|
3467
|
-
|
3468
|
-
|
3469
|
-
|
3470
|
-
|
4083
|
+
useDocumentLayout as h,
|
4084
|
+
createYupSchema as i,
|
4085
|
+
Header as j,
|
4086
|
+
PERMISSIONS as k,
|
4087
|
+
DocumentRBAC as l,
|
4088
|
+
DOCUMENT_META_FIELDS as m,
|
4089
|
+
CLONE_PATH as n,
|
4090
|
+
useDocLayout as o,
|
4091
|
+
useGetContentTypeConfigurationQuery as p,
|
4092
|
+
CREATOR_FIELDS as q,
|
4093
|
+
getMainField as r,
|
3471
4094
|
setInitialData as s,
|
3472
4095
|
getDisplayName as t,
|
3473
|
-
|
4096
|
+
useContentTypeSchema as u,
|
3474
4097
|
checkIfAttributeIsDisplayable as v,
|
3475
4098
|
useGetAllDocumentsQuery as w,
|
3476
4099
|
convertListLayoutToFieldLayouts as x,
|
3477
4100
|
capitalise as y,
|
3478
4101
|
useUpdateContentTypeConfigurationMutation as z
|
3479
4102
|
};
|
3480
|
-
//# sourceMappingURL=index-
|
4103
|
+
//# sourceMappingURL=index-CsfwpRfc.mjs.map
|