@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
@@ -2,15 +2,16 @@
|
|
2
2
|
const Icons = require("@strapi/icons");
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
4
4
|
const strapiAdmin = require("@strapi/admin/strapi-admin");
|
5
|
-
const qs = require("qs");
|
6
|
-
const reactIntl = require("react-intl");
|
7
|
-
const reactRouterDom = require("react-router-dom");
|
8
5
|
const React = require("react");
|
9
6
|
const designSystem = require("@strapi/design-system");
|
10
|
-
const
|
7
|
+
const mapValues = require("lodash/fp/mapValues");
|
8
|
+
const reactIntl = require("react-intl");
|
9
|
+
const reactRouterDom = require("react-router-dom");
|
11
10
|
const yup = require("yup");
|
12
11
|
const pipe = require("lodash/fp/pipe");
|
13
12
|
const dateFns = require("date-fns");
|
13
|
+
const styledComponents = require("styled-components");
|
14
|
+
const qs = require("qs");
|
14
15
|
const toolkit = require("@reduxjs/toolkit");
|
15
16
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
16
17
|
function _interopNamespace(e) {
|
@@ -32,6 +33,7 @@ function _interopNamespace(e) {
|
|
32
33
|
return Object.freeze(n);
|
33
34
|
}
|
34
35
|
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
36
|
+
const mapValues__default = /* @__PURE__ */ _interopDefault(mapValues);
|
35
37
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
36
38
|
const pipe__default = /* @__PURE__ */ _interopDefault(pipe);
|
37
39
|
const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
@@ -70,42 +72,6 @@ const useInjectionZone = (area) => {
|
|
70
72
|
const [page, position] = area.split(".");
|
71
73
|
return contentManagerPlugin.getInjectedComponents(page, position);
|
72
74
|
};
|
73
|
-
const HistoryAction = ({ model, document }) => {
|
74
|
-
const { formatMessage } = reactIntl.useIntl();
|
75
|
-
const [{ query }] = strapiAdmin.useQueryParams();
|
76
|
-
const navigate = reactRouterDom.useNavigate();
|
77
|
-
const pluginsQueryParams = qs.stringify({ plugins: query.plugins }, { encode: false });
|
78
|
-
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
79
|
-
return null;
|
80
|
-
}
|
81
|
-
return {
|
82
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.ClockCounterClockwise, {}),
|
83
|
-
label: formatMessage({
|
84
|
-
id: "content-manager.history.document-action",
|
85
|
-
defaultMessage: "Content History"
|
86
|
-
}),
|
87
|
-
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
88
|
-
disabled: (
|
89
|
-
/**
|
90
|
-
* The user is creating a new document.
|
91
|
-
* It hasn't been saved yet, so there's no history to go to
|
92
|
-
*/
|
93
|
-
!document || /**
|
94
|
-
* The document has been created but the current dimension has never been saved.
|
95
|
-
* For example, the user is creating a new locale in an existing document,
|
96
|
-
* so there's no history for the document in that locale
|
97
|
-
*/
|
98
|
-
!document.id || /**
|
99
|
-
* History is only available for content types created by the user.
|
100
|
-
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
101
|
-
* which start with `admin::` or `plugin::`
|
102
|
-
*/
|
103
|
-
!model.startsWith("api::")
|
104
|
-
),
|
105
|
-
position: "header"
|
106
|
-
};
|
107
|
-
};
|
108
|
-
HistoryAction.type = "history";
|
109
75
|
const ID = "id";
|
110
76
|
const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
|
111
77
|
const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
|
@@ -157,6 +123,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
157
123
|
if (!slug) {
|
158
124
|
throw new Error("Cannot find the slug param in the URL");
|
159
125
|
}
|
126
|
+
const [{ rawQuery }] = strapiAdmin.useQueryParams();
|
160
127
|
const userPermissions = strapiAdmin.useAuth("DocumentRBAC", (state) => state.permissions);
|
161
128
|
const contentTypePermissions = React__namespace.useMemo(() => {
|
162
129
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -167,7 +134,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
167
134
|
return { ...acc, [action]: [permission] };
|
168
135
|
}, {});
|
169
136
|
}, [slug, userPermissions]);
|
170
|
-
const { isLoading, allowedActions } = strapiAdmin.useRBAC(
|
137
|
+
const { isLoading, allowedActions } = strapiAdmin.useRBAC(
|
138
|
+
contentTypePermissions,
|
139
|
+
permissions ?? void 0,
|
140
|
+
// TODO: useRBAC context should be typed and built differently
|
141
|
+
// We are passing raw query as context to the hook so that it can
|
142
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
143
|
+
rawQuery
|
144
|
+
);
|
171
145
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
172
146
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
173
147
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -215,10 +189,12 @@ const contentManagerApi = strapiAdmin.adminApi.enhanceEndpoints({
|
|
215
189
|
"Document",
|
216
190
|
"InitialData",
|
217
191
|
"HistoryVersion",
|
218
|
-
"Relations"
|
192
|
+
"Relations",
|
193
|
+
"UidAvailability"
|
219
194
|
]
|
220
195
|
});
|
221
196
|
const documentApi = contentManagerApi.injectEndpoints({
|
197
|
+
overrideExisting: true,
|
222
198
|
endpoints: (builder) => ({
|
223
199
|
autoCloneDocument: builder.mutation({
|
224
200
|
query: ({ model, sourceId, query }) => ({
|
@@ -228,7 +204,12 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
228
204
|
params: query
|
229
205
|
}
|
230
206
|
}),
|
231
|
-
invalidatesTags: (_result,
|
207
|
+
invalidatesTags: (_result, error, { model }) => {
|
208
|
+
if (error) {
|
209
|
+
return [];
|
210
|
+
}
|
211
|
+
return [{ type: "Document", id: `${model}_LIST` }];
|
212
|
+
}
|
232
213
|
}),
|
233
214
|
cloneDocument: builder.mutation({
|
234
215
|
query: ({ model, sourceId, data, params }) => ({
|
@@ -239,7 +220,10 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
239
220
|
params
|
240
221
|
}
|
241
222
|
}),
|
242
|
-
invalidatesTags: (_result, _error, { model }) => [
|
223
|
+
invalidatesTags: (_result, _error, { model }) => [
|
224
|
+
{ type: "Document", id: `${model}_LIST` },
|
225
|
+
{ type: "UidAvailability", id: model }
|
226
|
+
]
|
243
227
|
}),
|
244
228
|
/**
|
245
229
|
* Creates a new collection-type document. This should ONLY be used for collection-types.
|
@@ -256,7 +240,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
256
240
|
}),
|
257
241
|
invalidatesTags: (result, _error, { model }) => [
|
258
242
|
{ type: "Document", id: `${model}_LIST` },
|
259
|
-
"Relations"
|
243
|
+
"Relations",
|
244
|
+
{ type: "UidAvailability", id: model }
|
260
245
|
]
|
261
246
|
}),
|
262
247
|
deleteDocument: builder.mutation({
|
@@ -297,7 +282,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
297
282
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
298
283
|
},
|
299
284
|
{ type: "Document", id: `${model}_LIST` },
|
300
|
-
"Relations"
|
285
|
+
"Relations",
|
286
|
+
{ type: "UidAvailability", id: model }
|
301
287
|
];
|
302
288
|
}
|
303
289
|
}),
|
@@ -315,6 +301,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
315
301
|
}),
|
316
302
|
providesTags: (result, _error, arg) => {
|
317
303
|
return [
|
304
|
+
{ type: "Document", id: `ALL_LIST` },
|
318
305
|
{ type: "Document", id: `${arg.model}_LIST` },
|
319
306
|
...result?.results.map(({ documentId }) => ({
|
320
307
|
type: "Document",
|
@@ -353,6 +340,11 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
353
340
|
{
|
354
341
|
type: "Document",
|
355
342
|
id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
|
343
|
+
},
|
344
|
+
// Make it easy to invalidate all individual documents queries for a model
|
345
|
+
{
|
346
|
+
type: "Document",
|
347
|
+
id: `${model}_ALL_ITEMS`
|
356
348
|
}
|
357
349
|
];
|
358
350
|
}
|
@@ -416,8 +408,21 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
416
408
|
type: "Document",
|
417
409
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
418
410
|
},
|
419
|
-
"Relations"
|
411
|
+
"Relations",
|
412
|
+
{ type: "UidAvailability", id: model }
|
420
413
|
];
|
414
|
+
},
|
415
|
+
async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
|
416
|
+
const patchResult = dispatch(
|
417
|
+
documentApi.util.updateQueryData("getDocument", patch, (draft) => {
|
418
|
+
Object.assign(draft.data, data);
|
419
|
+
})
|
420
|
+
);
|
421
|
+
try {
|
422
|
+
await queryFulfilled;
|
423
|
+
} catch {
|
424
|
+
patchResult.undo();
|
425
|
+
}
|
421
426
|
}
|
422
427
|
}),
|
423
428
|
unpublishDocument: builder.mutation({
|
@@ -487,20 +492,39 @@ const buildValidParams = (query) => {
|
|
487
492
|
const isBaseQueryError = (error) => {
|
488
493
|
return error.name !== void 0;
|
489
494
|
};
|
490
|
-
const
|
495
|
+
const arrayValidator = (attribute, options) => ({
|
496
|
+
message: strapiAdmin.translatedErrors.required,
|
497
|
+
test(value) {
|
498
|
+
if (options.status === "draft") {
|
499
|
+
return true;
|
500
|
+
}
|
501
|
+
if (!attribute.required) {
|
502
|
+
return true;
|
503
|
+
}
|
504
|
+
if (!value) {
|
505
|
+
return false;
|
506
|
+
}
|
507
|
+
if (Array.isArray(value) && value.length === 0) {
|
508
|
+
return false;
|
509
|
+
}
|
510
|
+
return true;
|
511
|
+
}
|
512
|
+
});
|
513
|
+
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
491
514
|
const createModelSchema = (attributes2) => yup__namespace.object().shape(
|
492
515
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
493
516
|
if (DOCUMENT_META_FIELDS.includes(name)) {
|
494
517
|
return acc;
|
495
518
|
}
|
496
519
|
const validations = [
|
520
|
+
addNullableValidation,
|
497
521
|
addRequiredValidation,
|
498
522
|
addMinLengthValidation,
|
499
523
|
addMaxLengthValidation,
|
500
524
|
addMinValidation,
|
501
525
|
addMaxValidation,
|
502
526
|
addRegexValidation
|
503
|
-
].map((fn) => fn(attribute));
|
527
|
+
].map((fn) => fn(attribute, options));
|
504
528
|
const transformSchema = pipe__default.default(...validations);
|
505
529
|
switch (attribute.type) {
|
506
530
|
case "component": {
|
@@ -510,12 +534,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
510
534
|
...acc,
|
511
535
|
[name]: transformSchema(
|
512
536
|
yup__namespace.array().of(createModelSchema(attributes3).nullable(false))
|
513
|
-
)
|
537
|
+
).test(arrayValidator(attribute, options))
|
514
538
|
};
|
515
539
|
} else {
|
516
540
|
return {
|
517
541
|
...acc,
|
518
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
542
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
519
543
|
};
|
520
544
|
}
|
521
545
|
}
|
@@ -537,7 +561,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
537
561
|
}
|
538
562
|
)
|
539
563
|
)
|
540
|
-
)
|
564
|
+
).test(arrayValidator(attribute, options))
|
541
565
|
};
|
542
566
|
case "relation":
|
543
567
|
return {
|
@@ -549,7 +573,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
549
573
|
} else if (Array.isArray(value)) {
|
550
574
|
return yup__namespace.array().of(
|
551
575
|
yup__namespace.object().shape({
|
552
|
-
id: yup__namespace.
|
576
|
+
id: yup__namespace.number().required()
|
553
577
|
})
|
554
578
|
);
|
555
579
|
} else if (typeof value === "object") {
|
@@ -601,6 +625,14 @@ const createAttributeSchema = (attribute) => {
|
|
601
625
|
if (!value || typeof value === "string" && value.length === 0) {
|
602
626
|
return true;
|
603
627
|
}
|
628
|
+
if (typeof value === "object") {
|
629
|
+
try {
|
630
|
+
JSON.stringify(value);
|
631
|
+
return true;
|
632
|
+
} catch (err) {
|
633
|
+
return false;
|
634
|
+
}
|
635
|
+
}
|
604
636
|
try {
|
605
637
|
JSON.parse(value);
|
606
638
|
return true;
|
@@ -619,13 +651,7 @@ const createAttributeSchema = (attribute) => {
|
|
619
651
|
return yup__namespace.mixed();
|
620
652
|
}
|
621
653
|
};
|
622
|
-
const
|
623
|
-
if (attribute.required) {
|
624
|
-
return schema.required({
|
625
|
-
id: strapiAdmin.translatedErrors.required.id,
|
626
|
-
defaultMessage: "This field is required."
|
627
|
-
});
|
628
|
-
}
|
654
|
+
const nullableSchema = (schema) => {
|
629
655
|
return schema?.nullable ? schema.nullable() : (
|
630
656
|
// In some cases '.nullable' will not be available on the schema.
|
631
657
|
// e.g. when the schema has been built using yup.lazy (e.g. for relations).
|
@@ -633,7 +659,22 @@ const addRequiredValidation = (attribute) => (schema) => {
|
|
633
659
|
schema
|
634
660
|
);
|
635
661
|
};
|
636
|
-
const
|
662
|
+
const addNullableValidation = () => (schema) => {
|
663
|
+
return nullableSchema(schema);
|
664
|
+
};
|
665
|
+
const addRequiredValidation = (attribute, options) => (schema) => {
|
666
|
+
if (options.status === "draft" || !attribute.required) {
|
667
|
+
return schema;
|
668
|
+
}
|
669
|
+
if (attribute.required && "required" in schema) {
|
670
|
+
return schema.required(strapiAdmin.translatedErrors.required);
|
671
|
+
}
|
672
|
+
return schema;
|
673
|
+
};
|
674
|
+
const addMinLengthValidation = (attribute, options) => (schema) => {
|
675
|
+
if (options.status === "draft") {
|
676
|
+
return schema;
|
677
|
+
}
|
637
678
|
if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
|
638
679
|
return schema.min(attribute.minLength, {
|
639
680
|
...strapiAdmin.translatedErrors.minLength,
|
@@ -655,10 +696,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
655
696
|
}
|
656
697
|
return schema;
|
657
698
|
};
|
658
|
-
const addMinValidation = (attribute) => (schema) => {
|
659
|
-
if ("
|
699
|
+
const addMinValidation = (attribute, options) => (schema) => {
|
700
|
+
if (options.status === "draft") {
|
701
|
+
return schema;
|
702
|
+
}
|
703
|
+
if ("min" in attribute && "min" in schema) {
|
660
704
|
const min = toInteger(attribute.min);
|
661
|
-
if (
|
705
|
+
if (min) {
|
662
706
|
return schema.min(min, {
|
663
707
|
...strapiAdmin.translatedErrors.min,
|
664
708
|
values: {
|
@@ -776,16 +820,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
776
820
|
}, {});
|
777
821
|
return componentsByKey;
|
778
822
|
};
|
779
|
-
const
|
823
|
+
const HOOKS = {
|
824
|
+
/**
|
825
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
826
|
+
* @constant
|
827
|
+
* @type {string}
|
828
|
+
*/
|
829
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
830
|
+
/**
|
831
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
832
|
+
* @constant
|
833
|
+
* @type {string}
|
834
|
+
*/
|
835
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
836
|
+
/**
|
837
|
+
* Hook that allows to mutate the CM's edit view layout
|
838
|
+
* @constant
|
839
|
+
* @type {string}
|
840
|
+
*/
|
841
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
842
|
+
/**
|
843
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
844
|
+
* @constant
|
845
|
+
* @type {string}
|
846
|
+
*/
|
847
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
848
|
+
};
|
849
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
850
|
+
endpoints: (builder) => ({
|
851
|
+
getContentTypeConfiguration: builder.query({
|
852
|
+
query: (uid) => ({
|
853
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
854
|
+
method: "GET"
|
855
|
+
}),
|
856
|
+
transformResponse: (response) => response.data,
|
857
|
+
providesTags: (_result, _error, uid) => [
|
858
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
859
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
860
|
+
]
|
861
|
+
}),
|
862
|
+
getAllContentTypeSettings: builder.query({
|
863
|
+
query: () => "/content-manager/content-types-settings",
|
864
|
+
transformResponse: (response) => response.data,
|
865
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
866
|
+
}),
|
867
|
+
updateContentTypeConfiguration: builder.mutation({
|
868
|
+
query: ({ uid, ...body }) => ({
|
869
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
870
|
+
method: "PUT",
|
871
|
+
data: body
|
872
|
+
}),
|
873
|
+
transformResponse: (response) => response.data,
|
874
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
875
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
876
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
877
|
+
// Is this necessary?
|
878
|
+
{ type: "InitialData" }
|
879
|
+
]
|
880
|
+
})
|
881
|
+
})
|
882
|
+
});
|
883
|
+
const {
|
884
|
+
useGetContentTypeConfigurationQuery,
|
885
|
+
useGetAllContentTypeSettingsQuery,
|
886
|
+
useUpdateContentTypeConfigurationMutation
|
887
|
+
} = contentTypesApi;
|
888
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
889
|
+
const { type } = attribute;
|
890
|
+
if (type === "relation") {
|
891
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
892
|
+
}
|
893
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
894
|
+
};
|
895
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
896
|
+
if (!mainFieldName) {
|
897
|
+
return void 0;
|
898
|
+
}
|
899
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
900
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
901
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
902
|
+
);
|
903
|
+
return {
|
904
|
+
name: mainFieldName,
|
905
|
+
type: mainFieldType ?? "string"
|
906
|
+
};
|
907
|
+
};
|
908
|
+
const DEFAULT_SETTINGS = {
|
909
|
+
bulkable: false,
|
910
|
+
filterable: false,
|
911
|
+
searchable: false,
|
912
|
+
pagination: false,
|
913
|
+
defaultSortBy: "",
|
914
|
+
defaultSortOrder: "asc",
|
915
|
+
mainField: "id",
|
916
|
+
pageSize: 10
|
917
|
+
};
|
918
|
+
const useDocumentLayout = (model) => {
|
919
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
920
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
921
|
+
const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
780
922
|
const { toggleNotification } = strapiAdmin.useNotification();
|
781
923
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
924
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
782
925
|
const {
|
783
|
-
|
784
|
-
isLoading:
|
785
|
-
|
786
|
-
|
787
|
-
} =
|
788
|
-
const
|
926
|
+
data,
|
927
|
+
isLoading: isLoadingConfigs,
|
928
|
+
error,
|
929
|
+
isFetching: isFetchingConfigs
|
930
|
+
} = useGetContentTypeConfigurationQuery(model);
|
931
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
789
932
|
React__namespace.useEffect(() => {
|
790
933
|
if (error) {
|
791
934
|
toggleNotification({
|
@@ -793,62 +936,318 @@ const useDocument = (args, opts) => {
|
|
793
936
|
message: formatAPIError(error)
|
794
937
|
});
|
795
938
|
}
|
796
|
-
}, [
|
797
|
-
const
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
(document) => {
|
805
|
-
if (!validationSchema) {
|
806
|
-
throw new Error(
|
807
|
-
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
808
|
-
);
|
809
|
-
}
|
810
|
-
try {
|
811
|
-
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
812
|
-
return null;
|
813
|
-
} catch (error2) {
|
814
|
-
if (error2 instanceof yup.ValidationError) {
|
815
|
-
return strapiAdmin.getYupValidationErrors(error2);
|
816
|
-
}
|
817
|
-
throw error2;
|
818
|
-
}
|
939
|
+
}, [error, formatAPIError, toggleNotification]);
|
940
|
+
const editLayout = React__namespace.useMemo(
|
941
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
942
|
+
layout: [],
|
943
|
+
components: {},
|
944
|
+
metadatas: {},
|
945
|
+
options: {},
|
946
|
+
settings: DEFAULT_SETTINGS
|
819
947
|
},
|
820
|
-
[
|
948
|
+
[data, isLoading, schemas, schema, components]
|
949
|
+
);
|
950
|
+
const listLayout = React__namespace.useMemo(() => {
|
951
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
952
|
+
layout: [],
|
953
|
+
metadatas: {},
|
954
|
+
options: {},
|
955
|
+
settings: DEFAULT_SETTINGS
|
956
|
+
};
|
957
|
+
}, [data, isLoading, schemas, schema, components]);
|
958
|
+
const { layout: edit } = React__namespace.useMemo(
|
959
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
960
|
+
layout: editLayout,
|
961
|
+
query
|
962
|
+
}),
|
963
|
+
[editLayout, query, runHookWaterfall]
|
821
964
|
);
|
822
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
823
965
|
return {
|
824
|
-
|
825
|
-
document: data?.data,
|
826
|
-
meta: data?.meta,
|
966
|
+
error,
|
827
967
|
isLoading,
|
828
|
-
|
829
|
-
|
968
|
+
edit,
|
969
|
+
list: listLayout
|
830
970
|
};
|
831
971
|
};
|
832
|
-
const
|
833
|
-
const {
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
972
|
+
const useDocLayout = () => {
|
973
|
+
const { model } = useDoc();
|
974
|
+
return useDocumentLayout(model);
|
975
|
+
};
|
976
|
+
const formatEditLayout = (data, {
|
977
|
+
schemas,
|
978
|
+
schema,
|
979
|
+
components
|
980
|
+
}) => {
|
981
|
+
let currentPanelIndex = 0;
|
982
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
983
|
+
data.contentType.layouts.edit,
|
984
|
+
schema?.attributes,
|
985
|
+
data.contentType.metadatas,
|
986
|
+
{ configurations: data.components, schemas: components },
|
987
|
+
schemas
|
988
|
+
).reduce((panels, row) => {
|
989
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
990
|
+
panels.push([row]);
|
991
|
+
currentPanelIndex += 2;
|
992
|
+
} else {
|
993
|
+
if (!panels[currentPanelIndex]) {
|
994
|
+
panels.push([]);
|
995
|
+
}
|
996
|
+
panels[currentPanelIndex].push(row);
|
997
|
+
}
|
998
|
+
return panels;
|
999
|
+
}, []);
|
1000
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
1001
|
+
(acc, [uid, configuration]) => {
|
1002
|
+
acc[uid] = {
|
1003
|
+
layout: convertEditLayoutToFieldLayouts(
|
1004
|
+
configuration.layouts.edit,
|
1005
|
+
components[uid].attributes,
|
1006
|
+
configuration.metadatas,
|
1007
|
+
{ configurations: data.components, schemas: components }
|
1008
|
+
),
|
1009
|
+
settings: {
|
1010
|
+
...configuration.settings,
|
1011
|
+
icon: components[uid].info.icon,
|
1012
|
+
displayName: components[uid].info.displayName
|
1013
|
+
}
|
1014
|
+
};
|
1015
|
+
return acc;
|
1016
|
+
},
|
1017
|
+
{}
|
1018
|
+
);
|
1019
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1020
|
+
(acc, [attribute, metadata]) => {
|
1021
|
+
return {
|
1022
|
+
...acc,
|
1023
|
+
[attribute]: metadata.edit
|
1024
|
+
};
|
1025
|
+
},
|
1026
|
+
{}
|
1027
|
+
);
|
1028
|
+
return {
|
1029
|
+
layout: panelledEditAttributes,
|
1030
|
+
components: componentEditAttributes,
|
1031
|
+
metadatas: editMetadatas,
|
1032
|
+
settings: {
|
1033
|
+
...data.contentType.settings,
|
1034
|
+
displayName: schema?.info.displayName
|
1035
|
+
},
|
1036
|
+
options: {
|
1037
|
+
...schema?.options,
|
1038
|
+
...schema?.pluginOptions,
|
1039
|
+
...data.contentType.options
|
1040
|
+
}
|
1041
|
+
};
|
1042
|
+
};
|
1043
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1044
|
+
return rows.map(
|
1045
|
+
(row) => row.map((field) => {
|
1046
|
+
const attribute = attributes[field.name];
|
1047
|
+
if (!attribute) {
|
1048
|
+
return null;
|
1049
|
+
}
|
1050
|
+
const { edit: metadata } = metadatas[field.name];
|
1051
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1052
|
+
return {
|
1053
|
+
attribute,
|
1054
|
+
disabled: !metadata.editable,
|
1055
|
+
hint: metadata.description,
|
1056
|
+
label: metadata.label ?? "",
|
1057
|
+
name: field.name,
|
1058
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1059
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1060
|
+
schemas,
|
1061
|
+
components: components?.schemas ?? {}
|
1062
|
+
}),
|
1063
|
+
placeholder: metadata.placeholder ?? "",
|
1064
|
+
required: attribute.required ?? false,
|
1065
|
+
size: field.size,
|
1066
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1067
|
+
visible: metadata.visible ?? true,
|
1068
|
+
type: attribute.type
|
1069
|
+
};
|
1070
|
+
}).filter((field) => field !== null)
|
1071
|
+
);
|
1072
|
+
};
|
1073
|
+
const formatListLayout = (data, {
|
1074
|
+
schemas,
|
1075
|
+
schema,
|
1076
|
+
components
|
1077
|
+
}) => {
|
1078
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1079
|
+
(acc, [attribute, metadata]) => {
|
1080
|
+
return {
|
1081
|
+
...acc,
|
1082
|
+
[attribute]: metadata.list
|
1083
|
+
};
|
1084
|
+
},
|
1085
|
+
{}
|
1086
|
+
);
|
1087
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1088
|
+
data.contentType.layouts.list,
|
1089
|
+
schema?.attributes,
|
1090
|
+
listMetadatas,
|
1091
|
+
{ configurations: data.components, schemas: components },
|
1092
|
+
schemas
|
1093
|
+
);
|
1094
|
+
return {
|
1095
|
+
layout: listAttributes,
|
1096
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1097
|
+
metadatas: listMetadatas,
|
1098
|
+
options: {
|
1099
|
+
...schema?.options,
|
1100
|
+
...schema?.pluginOptions,
|
1101
|
+
...data.contentType.options
|
1102
|
+
}
|
1103
|
+
};
|
1104
|
+
};
|
1105
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1106
|
+
return columns.map((name) => {
|
1107
|
+
const attribute = attributes[name];
|
1108
|
+
if (!attribute) {
|
1109
|
+
return null;
|
1110
|
+
}
|
1111
|
+
const metadata = metadatas[name];
|
1112
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1113
|
+
return {
|
1114
|
+
attribute,
|
1115
|
+
label: metadata.label ?? "",
|
1116
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1117
|
+
schemas,
|
1118
|
+
components: components?.schemas ?? {}
|
1119
|
+
}),
|
1120
|
+
name,
|
1121
|
+
searchable: metadata.searchable ?? true,
|
1122
|
+
sortable: metadata.sortable ?? true
|
1123
|
+
};
|
1124
|
+
}).filter((field) => field !== null);
|
1125
|
+
};
|
1126
|
+
const useDocument = (args, opts) => {
|
1127
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1128
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1129
|
+
const {
|
1130
|
+
currentData: data,
|
1131
|
+
isLoading: isLoadingDocument,
|
1132
|
+
isFetching: isFetchingDocument,
|
1133
|
+
error
|
1134
|
+
} = useGetDocumentQuery(args, {
|
1135
|
+
...opts,
|
1136
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1137
|
+
});
|
1138
|
+
const {
|
1139
|
+
components,
|
1140
|
+
schema,
|
1141
|
+
schemas,
|
1142
|
+
isLoading: isLoadingSchema
|
1143
|
+
} = useContentTypeSchema(args.model);
|
1144
|
+
React__namespace.useEffect(() => {
|
1145
|
+
if (error) {
|
1146
|
+
toggleNotification({
|
1147
|
+
type: "danger",
|
1148
|
+
message: formatAPIError(error)
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1152
|
+
const validationSchema = React__namespace.useMemo(() => {
|
1153
|
+
if (!schema) {
|
1154
|
+
return null;
|
1155
|
+
}
|
1156
|
+
return createYupSchema(schema.attributes, components);
|
1157
|
+
}, [schema, components]);
|
1158
|
+
const validate = React__namespace.useCallback(
|
1159
|
+
(document) => {
|
1160
|
+
if (!validationSchema) {
|
1161
|
+
throw new Error(
|
1162
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1163
|
+
);
|
1164
|
+
}
|
1165
|
+
try {
|
1166
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1167
|
+
return null;
|
1168
|
+
} catch (error2) {
|
1169
|
+
if (error2 instanceof yup.ValidationError) {
|
1170
|
+
return strapiAdmin.getYupValidationErrors(error2);
|
1171
|
+
}
|
1172
|
+
throw error2;
|
1173
|
+
}
|
1174
|
+
},
|
1175
|
+
[validationSchema]
|
1176
|
+
);
|
1177
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1178
|
+
const hasError = !!error;
|
1179
|
+
return {
|
1180
|
+
components,
|
1181
|
+
document: data?.data,
|
1182
|
+
meta: data?.meta,
|
1183
|
+
isLoading,
|
1184
|
+
hasError,
|
1185
|
+
schema,
|
1186
|
+
schemas,
|
1187
|
+
validate
|
1188
|
+
};
|
1189
|
+
};
|
1190
|
+
const useDoc = () => {
|
1191
|
+
const { id, slug, collectionType, origin } = reactRouterDom.useParams();
|
1192
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
1193
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1194
|
+
if (!collectionType) {
|
1195
|
+
throw new Error("Could not find collectionType in url params");
|
1196
|
+
}
|
1197
|
+
if (!slug) {
|
840
1198
|
throw new Error("Could not find model in url params");
|
841
1199
|
}
|
1200
|
+
const document = useDocument(
|
1201
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1202
|
+
{
|
1203
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1204
|
+
}
|
1205
|
+
);
|
1206
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
842
1207
|
return {
|
843
1208
|
collectionType,
|
844
1209
|
model: slug,
|
845
|
-
id:
|
846
|
-
...
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
1210
|
+
id: returnId,
|
1211
|
+
...document
|
1212
|
+
};
|
1213
|
+
};
|
1214
|
+
const useContentManagerContext = () => {
|
1215
|
+
const {
|
1216
|
+
collectionType,
|
1217
|
+
model,
|
1218
|
+
id,
|
1219
|
+
components,
|
1220
|
+
isLoading: isLoadingDoc,
|
1221
|
+
schema,
|
1222
|
+
schemas
|
1223
|
+
} = useDoc();
|
1224
|
+
const layout = useDocumentLayout(model);
|
1225
|
+
const form = strapiAdmin.useForm("useContentManagerContext", (state) => state);
|
1226
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1227
|
+
const slug = model;
|
1228
|
+
const isCreatingEntry = id === "create";
|
1229
|
+
useContentTypeSchema();
|
1230
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1231
|
+
const error = layout.error;
|
1232
|
+
return {
|
1233
|
+
error,
|
1234
|
+
isLoading,
|
1235
|
+
// Base metadata
|
1236
|
+
model,
|
1237
|
+
collectionType,
|
1238
|
+
id,
|
1239
|
+
slug,
|
1240
|
+
isCreatingEntry,
|
1241
|
+
isSingleType,
|
1242
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1243
|
+
// All schema infos
|
1244
|
+
components,
|
1245
|
+
contentType: schema,
|
1246
|
+
contentTypes: schemas,
|
1247
|
+
// Form state
|
1248
|
+
form,
|
1249
|
+
// layout infos
|
1250
|
+
layout
|
852
1251
|
};
|
853
1252
|
};
|
854
1253
|
const prefixPluginTranslations = (trad, pluginId) => {
|
@@ -870,6 +1269,8 @@ const useDocumentActions = () => {
|
|
870
1269
|
const { formatMessage } = reactIntl.useIntl();
|
871
1270
|
const { trackUsage } = strapiAdmin.useTracking();
|
872
1271
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1272
|
+
const navigate = reactRouterDom.useNavigate();
|
1273
|
+
const setCurrentStep = strapiAdmin.useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
873
1274
|
const [deleteDocument] = useDeleteDocumentMutation();
|
874
1275
|
const _delete = React__namespace.useCallback(
|
875
1276
|
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
@@ -948,12 +1349,13 @@ const useDocumentActions = () => {
|
|
948
1349
|
);
|
949
1350
|
const [discardDocument] = useDiscardDocumentMutation();
|
950
1351
|
const discard = React__namespace.useCallback(
|
951
|
-
async ({ collectionType, model, documentId }) => {
|
1352
|
+
async ({ collectionType, model, documentId, params }) => {
|
952
1353
|
try {
|
953
1354
|
const res = await discardDocument({
|
954
1355
|
collectionType,
|
955
1356
|
model,
|
956
|
-
documentId
|
1357
|
+
documentId,
|
1358
|
+
params
|
957
1359
|
});
|
958
1360
|
if ("error" in res) {
|
959
1361
|
toggleNotification({
|
@@ -1183,6 +1585,7 @@ const useDocumentActions = () => {
|
|
1183
1585
|
defaultMessage: "Saved document"
|
1184
1586
|
})
|
1185
1587
|
});
|
1588
|
+
setCurrentStep("contentManager.success");
|
1186
1589
|
return res.data;
|
1187
1590
|
} catch (err) {
|
1188
1591
|
toggleNotification({
|
@@ -1204,7 +1607,6 @@ const useDocumentActions = () => {
|
|
1204
1607
|
sourceId
|
1205
1608
|
});
|
1206
1609
|
if ("error" in res) {
|
1207
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1208
1610
|
return { error: res.error };
|
1209
1611
|
}
|
1210
1612
|
toggleNotification({
|
@@ -1223,7 +1625,7 @@ const useDocumentActions = () => {
|
|
1223
1625
|
throw err;
|
1224
1626
|
}
|
1225
1627
|
},
|
1226
|
-
[autoCloneDocument,
|
1628
|
+
[autoCloneDocument, formatMessage, toggleNotification]
|
1227
1629
|
);
|
1228
1630
|
const [cloneDocument] = useCloneDocumentMutation();
|
1229
1631
|
const clone = React__namespace.useCallback(
|
@@ -1249,6 +1651,7 @@ const useDocumentActions = () => {
|
|
1249
1651
|
defaultMessage: "Cloned document"
|
1250
1652
|
})
|
1251
1653
|
});
|
1654
|
+
navigate(`../../${res.data.data.documentId}`, { relative: "path" });
|
1252
1655
|
return res.data;
|
1253
1656
|
} catch (err) {
|
1254
1657
|
toggleNotification({
|
@@ -1259,7 +1662,7 @@ const useDocumentActions = () => {
|
|
1259
1662
|
throw err;
|
1260
1663
|
}
|
1261
1664
|
},
|
1262
|
-
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
|
1665
|
+
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
|
1263
1666
|
);
|
1264
1667
|
const [getDoc] = useLazyGetDocumentQuery();
|
1265
1668
|
const getDocument = React__namespace.useCallback(
|
@@ -1285,7 +1688,7 @@ const useDocumentActions = () => {
|
|
1285
1688
|
};
|
1286
1689
|
};
|
1287
1690
|
const ProtectedHistoryPage = React.lazy(
|
1288
|
-
() => Promise.resolve().then(() => require("./History-
|
1691
|
+
() => Promise.resolve().then(() => require("./History-Bw9vfT1k.js")).then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1289
1692
|
);
|
1290
1693
|
const routes$1 = [
|
1291
1694
|
{
|
@@ -1298,31 +1701,31 @@ const routes$1 = [
|
|
1298
1701
|
}
|
1299
1702
|
];
|
1300
1703
|
const ProtectedEditViewPage = React.lazy(
|
1301
|
-
() => Promise.resolve().then(() => require("./EditViewPage-
|
1704
|
+
() => Promise.resolve().then(() => require("./EditViewPage-BvcMXaP2.js")).then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1302
1705
|
);
|
1303
1706
|
const ProtectedListViewPage = React.lazy(
|
1304
|
-
() => Promise.resolve().then(() => require("./ListViewPage-
|
1707
|
+
() => Promise.resolve().then(() => require("./ListViewPage-MZu-8OKX.js")).then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1305
1708
|
);
|
1306
1709
|
const ProtectedListConfiguration = React.lazy(
|
1307
|
-
() => Promise.resolve().then(() => require("./ListConfigurationPage-
|
1710
|
+
() => Promise.resolve().then(() => require("./ListConfigurationPage-DBVqF5fc.js")).then((mod) => ({
|
1308
1711
|
default: mod.ProtectedListConfiguration
|
1309
1712
|
}))
|
1310
1713
|
);
|
1311
1714
|
const ProtectedEditConfigurationPage = React.lazy(
|
1312
|
-
() => Promise.resolve().then(() => require("./EditConfigurationPage-
|
1715
|
+
() => Promise.resolve().then(() => require("./EditConfigurationPage-Bcbi6r5y.js")).then((mod) => ({
|
1313
1716
|
default: mod.ProtectedEditConfigurationPage
|
1314
1717
|
}))
|
1315
1718
|
);
|
1316
1719
|
const ProtectedComponentConfigurationPage = React.lazy(
|
1317
|
-
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-
|
1720
|
+
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-CzDn8Uxh.js")).then((mod) => ({
|
1318
1721
|
default: mod.ProtectedComponentConfigurationPage
|
1319
1722
|
}))
|
1320
1723
|
);
|
1321
1724
|
const NoPermissions = React.lazy(
|
1322
|
-
() => Promise.resolve().then(() => require("./NoPermissionsPage-
|
1725
|
+
() => Promise.resolve().then(() => require("./NoPermissionsPage-COs61PpB.js")).then((mod) => ({ default: mod.NoPermissions }))
|
1323
1726
|
);
|
1324
1727
|
const NoContentType = React.lazy(
|
1325
|
-
() => Promise.resolve().then(() => require("./NoContentTypePage-
|
1728
|
+
() => Promise.resolve().then(() => require("./NoContentTypePage-C9lRMTCa.js")).then((mod) => ({ default: mod.NoContentType }))
|
1326
1729
|
);
|
1327
1730
|
const CollectionTypePages = () => {
|
1328
1731
|
const { collectionType } = reactRouterDom.useParams();
|
@@ -1436,12 +1839,14 @@ const DocumentActionButton = (action) => {
|
|
1436
1839
|
/* @__PURE__ */ jsxRuntime.jsx(
|
1437
1840
|
designSystem.Button,
|
1438
1841
|
{
|
1439
|
-
flex:
|
1842
|
+
flex: "auto",
|
1440
1843
|
startIcon: action.icon,
|
1441
1844
|
disabled: action.disabled,
|
1442
1845
|
onClick: handleClick(action),
|
1443
1846
|
justifyContent: "center",
|
1444
1847
|
variant: action.variant || "default",
|
1848
|
+
paddingTop: "7px",
|
1849
|
+
paddingBottom: "7px",
|
1445
1850
|
children: action.label
|
1446
1851
|
}
|
1447
1852
|
),
|
@@ -1449,7 +1854,7 @@ const DocumentActionButton = (action) => {
|
|
1449
1854
|
DocumentActionConfirmDialog,
|
1450
1855
|
{
|
1451
1856
|
...action.dialog,
|
1452
|
-
variant: action.variant,
|
1857
|
+
variant: action.dialog?.variant ?? action.variant,
|
1453
1858
|
isOpen: dialogId === action.id,
|
1454
1859
|
onClose: handleClose
|
1455
1860
|
}
|
@@ -1506,9 +1911,9 @@ const DocumentActionsMenu = ({
|
|
1506
1911
|
disabled: isDisabled,
|
1507
1912
|
size: "S",
|
1508
1913
|
endIcon: null,
|
1509
|
-
paddingTop: "
|
1510
|
-
paddingLeft: "
|
1511
|
-
paddingRight: "
|
1914
|
+
paddingTop: "4px",
|
1915
|
+
paddingLeft: "7px",
|
1916
|
+
paddingRight: "7px",
|
1512
1917
|
variant,
|
1513
1918
|
children: [
|
1514
1919
|
/* @__PURE__ */ jsxRuntime.jsx(Icons.More, { "aria-hidden": true, focusable: false }),
|
@@ -1519,7 +1924,7 @@ const DocumentActionsMenu = ({
|
|
1519
1924
|
]
|
1520
1925
|
}
|
1521
1926
|
),
|
1522
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, {
|
1927
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1523
1928
|
actions2.map((action) => {
|
1524
1929
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
1525
1930
|
designSystem.Menu.Item,
|
@@ -1528,10 +1933,25 @@ const DocumentActionsMenu = ({
|
|
1528
1933
|
onSelect: handleClick(action),
|
1529
1934
|
display: "block",
|
1530
1935
|
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", gap: 4, children: [
|
1531
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1936
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
1937
|
+
designSystem.Flex,
|
1938
|
+
{
|
1939
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1940
|
+
gap: 2,
|
1941
|
+
tag: "span",
|
1942
|
+
children: [
|
1943
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
1944
|
+
designSystem.Flex,
|
1945
|
+
{
|
1946
|
+
tag: "span",
|
1947
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1948
|
+
children: action.icon
|
1949
|
+
}
|
1950
|
+
),
|
1951
|
+
action.label
|
1952
|
+
]
|
1953
|
+
}
|
1954
|
+
),
|
1535
1955
|
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsxRuntime.jsx(
|
1536
1956
|
designSystem.Flex,
|
1537
1957
|
{
|
@@ -1590,6 +2010,18 @@ const convertActionVariantToColor = (variant = "secondary") => {
|
|
1590
2010
|
return "primary600";
|
1591
2011
|
}
|
1592
2012
|
};
|
2013
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
2014
|
+
switch (variant) {
|
2015
|
+
case "danger":
|
2016
|
+
return "danger600";
|
2017
|
+
case "secondary":
|
2018
|
+
return "neutral500";
|
2019
|
+
case "success":
|
2020
|
+
return "success600";
|
2021
|
+
default:
|
2022
|
+
return "primary600";
|
2023
|
+
}
|
2024
|
+
};
|
1593
2025
|
const DocumentActionConfirmDialog = ({
|
1594
2026
|
onClose,
|
1595
2027
|
onCancel,
|
@@ -1612,22 +2044,20 @@ const DocumentActionConfirmDialog = ({
|
|
1612
2044
|
}
|
1613
2045
|
onClose();
|
1614
2046
|
};
|
1615
|
-
return /* @__PURE__ */ jsxRuntime.
|
1616
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.
|
1617
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
1618
|
-
|
1619
|
-
{
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
)
|
1630
|
-
] });
|
2047
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
2048
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
|
2049
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: content }),
|
2050
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
|
2051
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
2052
|
+
id: "app.components.Button.cancel",
|
2053
|
+
defaultMessage: "Cancel"
|
2054
|
+
}) }) }),
|
2055
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
2056
|
+
id: "app.components.Button.confirm",
|
2057
|
+
defaultMessage: "Confirm"
|
2058
|
+
}) })
|
2059
|
+
] })
|
2060
|
+
] }) });
|
1631
2061
|
};
|
1632
2062
|
const DocumentActionModal = ({
|
1633
2063
|
isOpen,
|
@@ -1637,36 +2067,31 @@ const DocumentActionModal = ({
|
|
1637
2067
|
content: Content,
|
1638
2068
|
onModalClose
|
1639
2069
|
}) => {
|
1640
|
-
const id = React__namespace.useId();
|
1641
|
-
if (!isOpen) {
|
1642
|
-
return null;
|
1643
|
-
}
|
1644
2070
|
const handleClose = () => {
|
1645
2071
|
if (onClose) {
|
1646
2072
|
onClose();
|
1647
2073
|
}
|
1648
2074
|
onModalClose();
|
1649
2075
|
};
|
1650
|
-
return /* @__PURE__ */ jsxRuntime.
|
1651
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.
|
1652
|
-
|
1653
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
] });
|
2076
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
|
2077
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
|
2078
|
+
typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: Content }),
|
2079
|
+
typeof Footer === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Footer, { onClose: handleClose }) : Footer
|
2080
|
+
] }) });
|
2081
|
+
};
|
2082
|
+
const transformData = (data) => {
|
2083
|
+
if (Array.isArray(data)) {
|
2084
|
+
return data.map(transformData);
|
2085
|
+
}
|
2086
|
+
if (typeof data === "object" && data !== null) {
|
2087
|
+
if ("apiData" in data) {
|
2088
|
+
return data.apiData;
|
2089
|
+
}
|
2090
|
+
return mapValues__default.default(transformData)(data);
|
2091
|
+
}
|
2092
|
+
return data;
|
1668
2093
|
};
|
1669
|
-
const PublishAction = ({
|
2094
|
+
const PublishAction$1 = ({
|
1670
2095
|
activeTab,
|
1671
2096
|
documentId,
|
1672
2097
|
model,
|
@@ -1678,13 +2103,17 @@ const PublishAction = ({
|
|
1678
2103
|
const navigate = reactRouterDom.useNavigate();
|
1679
2104
|
const { toggleNotification } = strapiAdmin.useNotification();
|
1680
2105
|
const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
|
2106
|
+
const isListView = reactRouterDom.useMatch(LIST_PATH) !== null;
|
1681
2107
|
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
1682
2108
|
const { formatMessage } = reactIntl.useIntl();
|
1683
|
-
const { canPublish
|
1684
|
-
"PublishAction",
|
1685
|
-
({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
|
1686
|
-
);
|
2109
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1687
2110
|
const { publish } = useDocumentActions();
|
2111
|
+
const [
|
2112
|
+
countDraftRelations,
|
2113
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2114
|
+
] = useLazyGetDraftRelationCountQuery();
|
2115
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React__namespace.useState(0);
|
2116
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React__namespace.useState(0);
|
1688
2117
|
const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
|
1689
2118
|
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1690
2119
|
const modified = strapiAdmin.useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
@@ -1693,10 +2122,105 @@ const PublishAction = ({
|
|
1693
2122
|
const validate = strapiAdmin.useForm("PublishAction", (state) => state.validate);
|
1694
2123
|
const setErrors = strapiAdmin.useForm("PublishAction", (state) => state.setErrors);
|
1695
2124
|
const formValues = strapiAdmin.useForm("PublishAction", ({ values }) => values);
|
2125
|
+
React__namespace.useEffect(() => {
|
2126
|
+
if (isErrorDraftRelations) {
|
2127
|
+
toggleNotification({
|
2128
|
+
type: "danger",
|
2129
|
+
message: formatMessage({
|
2130
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2131
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2132
|
+
})
|
2133
|
+
});
|
2134
|
+
}
|
2135
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2136
|
+
React__namespace.useEffect(() => {
|
2137
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2138
|
+
const extractDraftRelations = (data) => {
|
2139
|
+
const relations = data.connect || [];
|
2140
|
+
relations.forEach((relation) => {
|
2141
|
+
if (relation.status === "draft") {
|
2142
|
+
localDraftRelations.add(relation.id);
|
2143
|
+
}
|
2144
|
+
});
|
2145
|
+
};
|
2146
|
+
const traverseAndExtract = (data) => {
|
2147
|
+
Object.entries(data).forEach(([key, value]) => {
|
2148
|
+
if (key === "connect" && Array.isArray(value)) {
|
2149
|
+
extractDraftRelations({ connect: value });
|
2150
|
+
} else if (typeof value === "object" && value !== null) {
|
2151
|
+
traverseAndExtract(value);
|
2152
|
+
}
|
2153
|
+
});
|
2154
|
+
};
|
2155
|
+
if (!documentId || modified) {
|
2156
|
+
traverseAndExtract(formValues);
|
2157
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2158
|
+
}
|
2159
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2160
|
+
React__namespace.useEffect(() => {
|
2161
|
+
if (!document || !document.documentId || isListView) {
|
2162
|
+
return;
|
2163
|
+
}
|
2164
|
+
const fetchDraftRelationsCount = async () => {
|
2165
|
+
const { data, error } = await countDraftRelations({
|
2166
|
+
collectionType,
|
2167
|
+
model,
|
2168
|
+
documentId,
|
2169
|
+
params
|
2170
|
+
});
|
2171
|
+
if (error) {
|
2172
|
+
throw error;
|
2173
|
+
}
|
2174
|
+
if (data) {
|
2175
|
+
setServerCountOfDraftRelations(data.data);
|
2176
|
+
}
|
2177
|
+
};
|
2178
|
+
fetchDraftRelationsCount();
|
2179
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
1696
2180
|
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1697
2181
|
if (!schema?.options?.draftAndPublish) {
|
1698
2182
|
return null;
|
1699
2183
|
}
|
2184
|
+
const performPublish = async () => {
|
2185
|
+
setSubmitting(true);
|
2186
|
+
try {
|
2187
|
+
const { errors } = await validate(true, {
|
2188
|
+
status: "published"
|
2189
|
+
});
|
2190
|
+
if (errors) {
|
2191
|
+
toggleNotification({
|
2192
|
+
type: "danger",
|
2193
|
+
message: formatMessage({
|
2194
|
+
id: "content-manager.validation.error",
|
2195
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2196
|
+
})
|
2197
|
+
});
|
2198
|
+
return;
|
2199
|
+
}
|
2200
|
+
const res = await publish(
|
2201
|
+
{
|
2202
|
+
collectionType,
|
2203
|
+
model,
|
2204
|
+
documentId,
|
2205
|
+
params
|
2206
|
+
},
|
2207
|
+
transformData(formValues)
|
2208
|
+
);
|
2209
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2210
|
+
navigate({
|
2211
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2212
|
+
search: rawQuery
|
2213
|
+
});
|
2214
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2215
|
+
setErrors(formatValidationErrors(res.error));
|
2216
|
+
}
|
2217
|
+
} finally {
|
2218
|
+
setSubmitting(false);
|
2219
|
+
}
|
2220
|
+
};
|
2221
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2222
|
+
const enableDraftRelationsCount = false;
|
2223
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
1700
2224
|
return {
|
1701
2225
|
/**
|
1702
2226
|
* Disabled when:
|
@@ -1706,52 +2230,39 @@ const PublishAction = ({
|
|
1706
2230
|
* - the document is already published & not modified
|
1707
2231
|
* - the document is being created & not modified
|
1708
2232
|
* - the user doesn't have the permission to publish
|
1709
|
-
* - the user doesn't have the permission to create a new document
|
1710
|
-
* - the user doesn't have the permission to update the document
|
1711
2233
|
*/
|
1712
|
-
disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish
|
2234
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1713
2235
|
label: formatMessage({
|
1714
2236
|
id: "app.utils.publish",
|
1715
2237
|
defaultMessage: "Publish"
|
1716
2238
|
}),
|
1717
2239
|
onClick: async () => {
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
documentId,
|
1736
|
-
params
|
1737
|
-
},
|
1738
|
-
formValues
|
1739
|
-
);
|
1740
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1741
|
-
navigate({
|
1742
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1743
|
-
search: rawQuery
|
1744
|
-
});
|
1745
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1746
|
-
setErrors(formatValidationErrors(res.error));
|
2240
|
+
await performPublish();
|
2241
|
+
},
|
2242
|
+
dialog: hasDraftRelations ? {
|
2243
|
+
type: "dialog",
|
2244
|
+
variant: "danger",
|
2245
|
+
footer: null,
|
2246
|
+
title: formatMessage({
|
2247
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2248
|
+
defaultMessage: "Confirmation"
|
2249
|
+
}),
|
2250
|
+
content: formatMessage(
|
2251
|
+
{
|
2252
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2253
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2254
|
+
},
|
2255
|
+
{
|
2256
|
+
count: totalDraftRelations
|
1747
2257
|
}
|
1748
|
-
|
1749
|
-
|
2258
|
+
),
|
2259
|
+
onConfirm: async () => {
|
2260
|
+
await performPublish();
|
1750
2261
|
}
|
1751
|
-
}
|
2262
|
+
} : void 0
|
1752
2263
|
};
|
1753
2264
|
};
|
1754
|
-
PublishAction.type = "publish";
|
2265
|
+
PublishAction$1.type = "publish";
|
1755
2266
|
const UpdateAction = ({
|
1756
2267
|
activeTab,
|
1757
2268
|
documentId,
|
@@ -1764,10 +2275,6 @@ const UpdateAction = ({
|
|
1764
2275
|
const cloneMatch = reactRouterDom.useMatch(CLONE_PATH);
|
1765
2276
|
const isCloning = cloneMatch !== null;
|
1766
2277
|
const { formatMessage } = reactIntl.useIntl();
|
1767
|
-
const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
|
1768
|
-
canCreate: canCreate2,
|
1769
|
-
canUpdate: canUpdate2
|
1770
|
-
}));
|
1771
2278
|
const { create, update, clone } = useDocumentActions();
|
1772
2279
|
const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
|
1773
2280
|
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
@@ -1784,10 +2291,8 @@ const UpdateAction = ({
|
|
1784
2291
|
* - the form is submitting
|
1785
2292
|
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
1786
2293
|
* - the active tab is the published tab
|
1787
|
-
* - the user doesn't have the permission to create a new document
|
1788
|
-
* - the user doesn't have the permission to update the document
|
1789
2294
|
*/
|
1790
|
-
disabled: isSubmitting || !modified && !isCloning || activeTab === "published"
|
2295
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
1791
2296
|
label: formatMessage({
|
1792
2297
|
id: "content-manager.containers.Edit.save",
|
1793
2298
|
defaultMessage: "Save"
|
@@ -1795,7 +2300,9 @@ const UpdateAction = ({
|
|
1795
2300
|
onClick: async () => {
|
1796
2301
|
setSubmitting(true);
|
1797
2302
|
try {
|
1798
|
-
const { errors } = await validate(
|
2303
|
+
const { errors } = await validate(true, {
|
2304
|
+
status: "draft"
|
2305
|
+
});
|
1799
2306
|
if (errors) {
|
1800
2307
|
toggleNotification({
|
1801
2308
|
type: "danger",
|
@@ -1813,13 +2320,16 @@ const UpdateAction = ({
|
|
1813
2320
|
documentId: cloneMatch.params.origin,
|
1814
2321
|
params
|
1815
2322
|
},
|
1816
|
-
document
|
2323
|
+
transformData(document)
|
1817
2324
|
);
|
1818
2325
|
if ("data" in res) {
|
1819
|
-
navigate(
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
2326
|
+
navigate(
|
2327
|
+
{
|
2328
|
+
pathname: `../${res.data.documentId}`,
|
2329
|
+
search: rawQuery
|
2330
|
+
},
|
2331
|
+
{ relative: "path" }
|
2332
|
+
);
|
1823
2333
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1824
2334
|
setErrors(formatValidationErrors(res.error));
|
1825
2335
|
}
|
@@ -1831,7 +2341,7 @@ const UpdateAction = ({
|
|
1831
2341
|
documentId,
|
1832
2342
|
params
|
1833
2343
|
},
|
1834
|
-
document
|
2344
|
+
transformData(document)
|
1835
2345
|
);
|
1836
2346
|
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1837
2347
|
setErrors(formatValidationErrors(res.error));
|
@@ -1844,13 +2354,16 @@ const UpdateAction = ({
|
|
1844
2354
|
model,
|
1845
2355
|
params
|
1846
2356
|
},
|
1847
|
-
document
|
2357
|
+
transformData(document)
|
1848
2358
|
);
|
1849
2359
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1850
|
-
navigate(
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
2360
|
+
navigate(
|
2361
|
+
{
|
2362
|
+
pathname: `../${res.data.documentId}`,
|
2363
|
+
search: rawQuery
|
2364
|
+
},
|
2365
|
+
{ replace: true, relative: "path" }
|
2366
|
+
);
|
1854
2367
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1855
2368
|
setErrors(formatValidationErrors(res.error));
|
1856
2369
|
}
|
@@ -1882,10 +2395,8 @@ const UnpublishAction$1 = ({
|
|
1882
2395
|
const { toggleNotification } = strapiAdmin.useNotification();
|
1883
2396
|
const [shouldKeepDraft, setShouldKeepDraft] = React__namespace.useState(true);
|
1884
2397
|
const isDocumentModified = document?.status === "modified";
|
1885
|
-
const handleChange = (
|
1886
|
-
|
1887
|
-
setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1888
|
-
}
|
2398
|
+
const handleChange = (value) => {
|
2399
|
+
setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1889
2400
|
};
|
1890
2401
|
if (!schema?.options?.draftAndPublish) {
|
1891
2402
|
return null;
|
@@ -1896,7 +2407,7 @@ const UnpublishAction$1 = ({
|
|
1896
2407
|
id: "app.utils.unpublish",
|
1897
2408
|
defaultMessage: "Unpublish"
|
1898
2409
|
}),
|
1899
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(
|
2410
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {}),
|
1900
2411
|
onClick: async () => {
|
1901
2412
|
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
1902
2413
|
if (!documentId) {
|
@@ -1935,40 +2446,24 @@ const UnpublishAction$1 = ({
|
|
1935
2446
|
}) })
|
1936
2447
|
] }),
|
1937
2448
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
1938
|
-
designSystem.
|
2449
|
+
designSystem.Radio.Group,
|
1939
2450
|
{
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
2451
|
+
defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
|
2452
|
+
name: "discard-options",
|
2453
|
+
"aria-label": formatMessage({
|
2454
|
+
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2455
|
+
defaultMessage: "Choose an option to unpublish the document."
|
2456
|
+
}),
|
2457
|
+
onValueChange: handleChange,
|
1946
2458
|
children: [
|
1947
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
1956
|
-
defaultMessage: "Keep draft"
|
1957
|
-
})
|
1958
|
-
}
|
1959
|
-
),
|
1960
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
1961
|
-
designSystem.Radio,
|
1962
|
-
{
|
1963
|
-
checked: !shouldKeepDraft,
|
1964
|
-
value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
|
1965
|
-
name: "discard-options",
|
1966
|
-
children: formatMessage({
|
1967
|
-
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
1968
|
-
defaultMessage: "Replace draft"
|
1969
|
-
})
|
1970
|
-
}
|
1971
|
-
)
|
2459
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2460
|
+
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2461
|
+
defaultMessage: "Keep draft"
|
2462
|
+
}) }),
|
2463
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2464
|
+
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2465
|
+
defaultMessage: "Replace draft"
|
2466
|
+
}) })
|
1972
2467
|
]
|
1973
2468
|
}
|
1974
2469
|
)
|
@@ -2024,7 +2519,7 @@ const DiscardAction = ({
|
|
2024
2519
|
id: "content-manager.actions.discard.label",
|
2025
2520
|
defaultMessage: "Discard changes"
|
2026
2521
|
}),
|
2027
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(
|
2522
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {}),
|
2028
2523
|
position: ["panel", "table-row"],
|
2029
2524
|
variant: "danger",
|
2030
2525
|
dialog: {
|
@@ -2052,12 +2547,7 @@ const DiscardAction = ({
|
|
2052
2547
|
};
|
2053
2548
|
};
|
2054
2549
|
DiscardAction.type = "discard";
|
2055
|
-
const
|
2056
|
-
path {
|
2057
|
-
fill: currentColor;
|
2058
|
-
}
|
2059
|
-
`;
|
2060
|
-
const DEFAULT_ACTIONS = [PublishAction, UpdateAction, UnpublishAction$1, DiscardAction];
|
2550
|
+
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2061
2551
|
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2062
2552
|
const RelativeTime = React__namespace.forwardRef(
|
2063
2553
|
({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
|
@@ -2104,7 +2594,7 @@ const getDisplayName = ({
|
|
2104
2594
|
};
|
2105
2595
|
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2106
2596
|
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2107
|
-
const statusVariant = status === "draft" ? "
|
2597
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2108
2598
|
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2109
2599
|
};
|
2110
2600
|
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
@@ -2114,23 +2604,13 @@ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
|
2114
2604
|
id: "content-manager.containers.edit.title.new",
|
2115
2605
|
defaultMessage: "Create an entry"
|
2116
2606
|
}) : documentTitle;
|
2117
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", paddingTop:
|
2607
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2118
2608
|
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.BackButton, {}),
|
2119
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
2120
|
-
designSystem.
|
2121
|
-
{
|
2122
|
-
|
2123
|
-
|
2124
|
-
paddingTop: 1,
|
2125
|
-
gap: "80px",
|
2126
|
-
alignItems: "flex-start",
|
2127
|
-
children: [
|
2128
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: title }),
|
2129
|
-
/* @__PURE__ */ jsxRuntime.jsx(HeaderToolbar, {})
|
2130
|
-
]
|
2131
|
-
}
|
2132
|
-
),
|
2133
|
-
status ? /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
|
2609
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2610
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: title }),
|
2611
|
+
/* @__PURE__ */ jsxRuntime.jsx(HeaderToolbar, {})
|
2612
|
+
] }),
|
2613
|
+
status ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2134
2614
|
] });
|
2135
2615
|
};
|
2136
2616
|
const HeaderToolbar = () => {
|
@@ -2213,12 +2693,12 @@ const Information = ({ activeTab }) => {
|
|
2213
2693
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2214
2694
|
label: formatMessage({
|
2215
2695
|
id: "content-manager.containers.edit.information.last-published.label",
|
2216
|
-
defaultMessage: "
|
2696
|
+
defaultMessage: "Published"
|
2217
2697
|
}),
|
2218
2698
|
value: formatMessage(
|
2219
2699
|
{
|
2220
2700
|
id: "content-manager.containers.edit.information.last-published.value",
|
2221
|
-
defaultMessage: `
|
2701
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2222
2702
|
},
|
2223
2703
|
{
|
2224
2704
|
time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2231,12 +2711,12 @@ const Information = ({ activeTab }) => {
|
|
2231
2711
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2232
2712
|
label: formatMessage({
|
2233
2713
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2234
|
-
defaultMessage: "
|
2714
|
+
defaultMessage: "Updated"
|
2235
2715
|
}),
|
2236
2716
|
value: formatMessage(
|
2237
2717
|
{
|
2238
2718
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2239
|
-
defaultMessage: `
|
2719
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2240
2720
|
},
|
2241
2721
|
{
|
2242
2722
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2254,12 +2734,12 @@ const Information = ({ activeTab }) => {
|
|
2254
2734
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2255
2735
|
label: formatMessage({
|
2256
2736
|
id: "content-manager.containers.edit.information.document.label",
|
2257
|
-
defaultMessage: "
|
2737
|
+
defaultMessage: "Created"
|
2258
2738
|
}),
|
2259
2739
|
value: formatMessage(
|
2260
2740
|
{
|
2261
2741
|
id: "content-manager.containers.edit.information.document.value",
|
2262
|
-
defaultMessage: `
|
2742
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2263
2743
|
},
|
2264
2744
|
{
|
2265
2745
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2297,25 +2777,77 @@ const Information = ({ activeTab }) => {
|
|
2297
2777
|
);
|
2298
2778
|
};
|
2299
2779
|
const HeaderActions = ({ actions: actions2 }) => {
|
2300
|
-
|
2301
|
-
|
2780
|
+
const [dialogId, setDialogId] = React__namespace.useState(null);
|
2781
|
+
const handleClick = (action) => async (e) => {
|
2782
|
+
if (!("options" in action)) {
|
2783
|
+
const { onClick = () => false, dialog, id } = action;
|
2784
|
+
const muteDialog = await onClick(e);
|
2785
|
+
if (dialog && !muteDialog) {
|
2786
|
+
e.preventDefault();
|
2787
|
+
setDialogId(id);
|
2788
|
+
}
|
2789
|
+
}
|
2790
|
+
};
|
2791
|
+
const handleClose = () => {
|
2792
|
+
setDialogId(null);
|
2793
|
+
};
|
2794
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 1, children: actions2.map((action) => {
|
2795
|
+
if (action.options) {
|
2302
2796
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
2303
2797
|
designSystem.SingleSelect,
|
2304
2798
|
{
|
2305
2799
|
size: "S",
|
2306
|
-
disabled: action.disabled,
|
2307
|
-
"aria-label": action.label,
|
2308
2800
|
onChange: action.onSelect,
|
2309
|
-
|
2801
|
+
"aria-label": action.label,
|
2802
|
+
...action,
|
2310
2803
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
|
2311
2804
|
},
|
2312
2805
|
action.id
|
2313
2806
|
);
|
2314
2807
|
} else {
|
2315
|
-
|
2808
|
+
if (action.type === "icon") {
|
2809
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
|
2810
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
2811
|
+
designSystem.IconButton,
|
2812
|
+
{
|
2813
|
+
disabled: action.disabled,
|
2814
|
+
label: action.label,
|
2815
|
+
size: "S",
|
2816
|
+
onClick: handleClick(action),
|
2817
|
+
children: action.icon
|
2818
|
+
}
|
2819
|
+
),
|
2820
|
+
action.dialog ? /* @__PURE__ */ jsxRuntime.jsx(
|
2821
|
+
HeaderActionDialog,
|
2822
|
+
{
|
2823
|
+
...action.dialog,
|
2824
|
+
isOpen: dialogId === action.id,
|
2825
|
+
onClose: handleClose
|
2826
|
+
}
|
2827
|
+
) : null
|
2828
|
+
] }, action.id);
|
2829
|
+
}
|
2316
2830
|
}
|
2317
2831
|
}) });
|
2318
2832
|
};
|
2833
|
+
const HeaderActionDialog = ({
|
2834
|
+
onClose,
|
2835
|
+
onCancel,
|
2836
|
+
title,
|
2837
|
+
content: Content,
|
2838
|
+
isOpen
|
2839
|
+
}) => {
|
2840
|
+
const handleClose = async () => {
|
2841
|
+
if (onCancel) {
|
2842
|
+
await onCancel();
|
2843
|
+
}
|
2844
|
+
onClose();
|
2845
|
+
};
|
2846
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
2847
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
|
2848
|
+
typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : Content
|
2849
|
+
] }) });
|
2850
|
+
};
|
2319
2851
|
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
2320
2852
|
const navigate = reactRouterDom.useNavigate();
|
2321
2853
|
const { formatMessage } = reactIntl.useIntl();
|
@@ -2356,12 +2888,16 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2356
2888
|
const { delete: deleteAction } = useDocumentActions();
|
2357
2889
|
const { toggleNotification } = strapiAdmin.useNotification();
|
2358
2890
|
const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
|
2891
|
+
const isLocalized = document?.locale != null;
|
2359
2892
|
return {
|
2360
2893
|
disabled: !canDelete || !document,
|
2361
|
-
label: formatMessage(
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2894
|
+
label: formatMessage(
|
2895
|
+
{
|
2896
|
+
id: "content-manager.actions.delete.label",
|
2897
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2898
|
+
},
|
2899
|
+
{ isLocalized }
|
2900
|
+
),
|
2365
2901
|
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
|
2366
2902
|
dialog: {
|
2367
2903
|
type: "dialog",
|
@@ -2451,7 +2987,7 @@ const ActionsPanel = () => {
|
|
2451
2987
|
return {
|
2452
2988
|
title: formatMessage({
|
2453
2989
|
id: "content-manager.containers.edit.panels.default.title",
|
2454
|
-
defaultMessage: "
|
2990
|
+
defaultMessage: "Entry"
|
2455
2991
|
}),
|
2456
2992
|
content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
|
2457
2993
|
};
|
@@ -2512,155 +3048,483 @@ const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
|
|
2512
3048
|
}
|
2513
3049
|
);
|
2514
3050
|
});
|
2515
|
-
const
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2519
|
-
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2524
|
-
|
2525
|
-
|
2526
|
-
|
2527
|
-
|
2528
|
-
|
2529
|
-
|
2530
|
-
|
2531
|
-
|
2532
|
-
|
2533
|
-
|
2534
|
-
|
2535
|
-
|
2536
|
-
|
2537
|
-
|
2538
|
-
|
2539
|
-
}
|
2540
|
-
if (dialog) {
|
2541
|
-
switch (dialog.type) {
|
2542
|
-
case "notification":
|
2543
|
-
toggleNotification({
|
2544
|
-
title: dialog.title,
|
2545
|
-
message: dialog.content,
|
2546
|
-
type: dialog.status,
|
2547
|
-
timeout: dialog.timeout,
|
2548
|
-
onClose: dialog.onClose
|
2549
|
-
});
|
2550
|
-
break;
|
2551
|
-
case "dialog":
|
2552
|
-
case "modal": {
|
2553
|
-
e.preventDefault();
|
2554
|
-
setDialogId(id);
|
2555
|
-
}
|
2556
|
-
}
|
2557
|
-
}
|
2558
|
-
};
|
2559
|
-
const handleClose = () => {
|
2560
|
-
setDialogId(null);
|
2561
|
-
if (action.dialog?.type === "modal" && action.dialog?.onClose) {
|
2562
|
-
action.dialog.onClose();
|
2563
|
-
}
|
2564
|
-
};
|
2565
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
2566
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
2567
|
-
designSystem.Button,
|
2568
|
-
{
|
2569
|
-
disabled: action.disabled,
|
2570
|
-
startIcon: action.icon,
|
2571
|
-
variant: action.variant,
|
2572
|
-
onClick: handleClick(action),
|
2573
|
-
children: action.label
|
2574
|
-
}
|
2575
|
-
),
|
2576
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
|
2577
|
-
BulkActionConfirmDialog,
|
2578
|
-
{
|
2579
|
-
...action.dialog,
|
2580
|
-
variant: action.variant,
|
2581
|
-
isOpen: dialogId === action.id,
|
2582
|
-
onClose: handleClose
|
2583
|
-
}
|
2584
|
-
) : null,
|
2585
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
|
2586
|
-
BulkActionModal,
|
2587
|
-
{
|
2588
|
-
...action.dialog,
|
2589
|
-
onModalClose: handleClose,
|
2590
|
-
isOpen: dialogId === action.id
|
2591
|
-
}
|
2592
|
-
) : null
|
2593
|
-
] });
|
3051
|
+
const ConfirmBulkActionDialog = ({
|
3052
|
+
onToggleDialog,
|
3053
|
+
isOpen = false,
|
3054
|
+
dialogBody,
|
3055
|
+
endAction
|
3056
|
+
}) => {
|
3057
|
+
const { formatMessage } = reactIntl.useIntl();
|
3058
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
3059
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: formatMessage({
|
3060
|
+
id: "app.components.ConfirmDialog.title",
|
3061
|
+
defaultMessage: "Confirmation"
|
3062
|
+
}) }),
|
3063
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3064
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3065
|
+
dialogBody
|
3066
|
+
] }) }),
|
3067
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
|
3068
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
|
3069
|
+
id: "app.components.Button.cancel",
|
3070
|
+
defaultMessage: "Cancel"
|
3071
|
+
}) }) }),
|
3072
|
+
endAction
|
3073
|
+
] })
|
3074
|
+
] }) });
|
2594
3075
|
};
|
2595
|
-
const
|
2596
|
-
|
2597
|
-
onCancel,
|
2598
|
-
onConfirm,
|
2599
|
-
title,
|
2600
|
-
content,
|
2601
|
-
confirmButton,
|
3076
|
+
const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", children: chunks });
|
3077
|
+
const ConfirmDialogPublishAll = ({
|
2602
3078
|
isOpen,
|
2603
|
-
|
3079
|
+
onToggleDialog,
|
3080
|
+
isConfirmButtonLoading = false,
|
3081
|
+
onConfirm
|
2604
3082
|
}) => {
|
2605
3083
|
const { formatMessage } = reactIntl.useIntl();
|
2606
|
-
const
|
2607
|
-
|
2608
|
-
|
3084
|
+
const selectedEntries = strapiAdmin.useTable("ConfirmDialogPublishAll", (state) => state.selectedRows);
|
3085
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
3086
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler(getTranslation);
|
3087
|
+
const { model, schema } = useDoc();
|
3088
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
3089
|
+
const enableDraftRelationsCount = false;
|
3090
|
+
const {
|
3091
|
+
data: countDraftRelations = 0,
|
3092
|
+
isLoading,
|
3093
|
+
error
|
3094
|
+
} = useGetManyDraftRelationCountQuery(
|
3095
|
+
{
|
3096
|
+
model,
|
3097
|
+
documentIds: selectedEntries.map((entry) => entry.documentId),
|
3098
|
+
locale: query?.plugins?.i18n?.locale
|
3099
|
+
},
|
3100
|
+
{
|
3101
|
+
skip: !enableDraftRelationsCount
|
2609
3102
|
}
|
2610
|
-
|
2611
|
-
|
2612
|
-
|
2613
|
-
|
2614
|
-
await onConfirm();
|
3103
|
+
);
|
3104
|
+
React__namespace.useEffect(() => {
|
3105
|
+
if (error) {
|
3106
|
+
toggleNotification({ type: "danger", message: formatAPIError(error) });
|
2615
3107
|
}
|
2616
|
-
|
2617
|
-
|
2618
|
-
|
2619
|
-
|
2620
|
-
|
2621
|
-
|
2622
|
-
|
2623
|
-
|
2624
|
-
|
2625
|
-
|
3108
|
+
}, [error, formatAPIError, toggleNotification]);
|
3109
|
+
if (error) {
|
3110
|
+
return null;
|
3111
|
+
}
|
3112
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
3113
|
+
ConfirmBulkActionDialog,
|
3114
|
+
{
|
3115
|
+
isOpen: isOpen && !isLoading,
|
3116
|
+
onToggleDialog,
|
3117
|
+
dialogBody: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
3118
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { id: "confirm-description", textAlign: "center", children: [
|
3119
|
+
countDraftRelations > 0 && formatMessage(
|
3120
|
+
{
|
3121
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
3122
|
+
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. "
|
3123
|
+
},
|
3124
|
+
{
|
3125
|
+
b: BoldChunk$1,
|
3126
|
+
count: countDraftRelations,
|
3127
|
+
entities: selectedEntries.length
|
3128
|
+
}
|
3129
|
+
),
|
3130
|
+
formatMessage({
|
3131
|
+
id: getTranslation("popUpWarning.bodyMessage.contentType.publish.all"),
|
3132
|
+
defaultMessage: "Are you sure you want to publish these entries?"
|
3133
|
+
})
|
3134
|
+
] }),
|
3135
|
+
schema?.pluginOptions && "i18n" in schema.pluginOptions && schema?.pluginOptions.i18n && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", textAlign: "center", children: formatMessage(
|
3136
|
+
{
|
3137
|
+
id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
|
3138
|
+
defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
|
3139
|
+
},
|
3140
|
+
{
|
3141
|
+
em: Emphasis
|
3142
|
+
}
|
3143
|
+
) })
|
3144
|
+
] }),
|
3145
|
+
endAction: /* @__PURE__ */ jsxRuntime.jsx(
|
3146
|
+
designSystem.Button,
|
3147
|
+
{
|
3148
|
+
onClick: onConfirm,
|
3149
|
+
variant: "secondary",
|
3150
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Check, {}),
|
3151
|
+
loading: isConfirmButtonLoading,
|
3152
|
+
children: formatMessage({
|
3153
|
+
id: "app.utils.publish",
|
3154
|
+
defaultMessage: "Publish"
|
3155
|
+
})
|
3156
|
+
}
|
3157
|
+
)
|
3158
|
+
}
|
3159
|
+
);
|
3160
|
+
};
|
3161
|
+
const TypographyMaxWidth = styledComponents.styled(designSystem.Typography)`
|
3162
|
+
max-width: 300px;
|
3163
|
+
`;
|
3164
|
+
const formatErrorMessages = (errors, parentKey, formatMessage) => {
|
3165
|
+
const messages = [];
|
3166
|
+
Object.entries(errors).forEach(([key, value]) => {
|
3167
|
+
const currentKey = parentKey ? `${parentKey}.${key}` : key;
|
3168
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
3169
|
+
if ("id" in value && "defaultMessage" in value) {
|
3170
|
+
messages.push(
|
3171
|
+
formatMessage(
|
3172
|
+
{
|
3173
|
+
id: `${value.id}.withField`,
|
3174
|
+
defaultMessage: value.defaultMessage
|
3175
|
+
},
|
3176
|
+
{ field: currentKey }
|
3177
|
+
)
|
3178
|
+
);
|
3179
|
+
} else {
|
3180
|
+
messages.push(
|
3181
|
+
...formatErrorMessages(
|
3182
|
+
// @ts-expect-error TODO: check why value is not compatible with FormErrors
|
3183
|
+
value,
|
3184
|
+
currentKey,
|
3185
|
+
formatMessage
|
3186
|
+
)
|
3187
|
+
);
|
3188
|
+
}
|
3189
|
+
} else {
|
3190
|
+
messages.push(
|
3191
|
+
formatMessage(
|
3192
|
+
{
|
3193
|
+
id: `${value}.withField`,
|
3194
|
+
defaultMessage: value
|
3195
|
+
},
|
3196
|
+
{ field: currentKey }
|
3197
|
+
)
|
3198
|
+
);
|
3199
|
+
}
|
3200
|
+
});
|
3201
|
+
return messages;
|
3202
|
+
};
|
3203
|
+
const EntryValidationText = ({ validationErrors, status }) => {
|
3204
|
+
const { formatMessage } = reactIntl.useIntl();
|
3205
|
+
if (validationErrors) {
|
3206
|
+
const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
|
3207
|
+
" "
|
3208
|
+
);
|
3209
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
3210
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.CrossCircle, { fill: "danger600" }),
|
3211
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsxRuntime.jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
|
3212
|
+
] });
|
3213
|
+
}
|
3214
|
+
if (status === "published") {
|
3215
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
3216
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.CheckCircle, { fill: "success600" }),
|
3217
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
|
3218
|
+
id: "content-manager.bulk-publish.already-published",
|
3219
|
+
defaultMessage: "Already Published"
|
3220
|
+
}) })
|
3221
|
+
] });
|
3222
|
+
}
|
3223
|
+
if (status === "modified") {
|
3224
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
3225
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.ArrowsCounterClockwise, { fill: "alternative600" }),
|
3226
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: formatMessage({
|
3227
|
+
id: "content-manager.bulk-publish.modified",
|
3228
|
+
defaultMessage: "Ready to publish changes"
|
3229
|
+
}) })
|
3230
|
+
] });
|
3231
|
+
}
|
3232
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
3233
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.CheckCircle, { fill: "success600" }),
|
3234
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: formatMessage({
|
3235
|
+
id: "app.utils.ready-to-publish",
|
3236
|
+
defaultMessage: "Ready to publish"
|
3237
|
+
}) })
|
3238
|
+
] });
|
3239
|
+
};
|
3240
|
+
const TABLE_HEADERS = [
|
3241
|
+
{ name: "id", label: "id" },
|
3242
|
+
{ name: "name", label: "name" },
|
3243
|
+
{ name: "status", label: "status" },
|
3244
|
+
{ name: "publicationStatus", label: "Publication status" }
|
3245
|
+
];
|
3246
|
+
const SelectedEntriesTableContent = ({
|
3247
|
+
isPublishing,
|
3248
|
+
rowsToDisplay = [],
|
3249
|
+
entriesToPublish = [],
|
3250
|
+
validationErrors = {}
|
3251
|
+
}) => {
|
3252
|
+
const { pathname } = reactRouterDom.useLocation();
|
3253
|
+
const { formatMessage } = reactIntl.useIntl();
|
3254
|
+
const {
|
3255
|
+
list: {
|
3256
|
+
settings: { mainField }
|
3257
|
+
}
|
3258
|
+
} = useDocLayout();
|
3259
|
+
const shouldDisplayMainField = mainField != null && mainField !== "id";
|
3260
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Table.Content, { children: [
|
3261
|
+
/* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Table.Head, { children: [
|
3262
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.HeaderCheckboxCell, {}),
|
3263
|
+
TABLE_HEADERS.filter((head) => head.name !== "name" || shouldDisplayMainField).map(
|
3264
|
+
(head) => /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.HeaderCell, { ...head }, head.name)
|
3265
|
+
)
|
3266
|
+
] }),
|
3267
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Loading, {}),
|
3268
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Body, { children: rowsToDisplay.map((row, index2) => /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Table.Row, { children: [
|
3269
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.CheckboxCell, { id: row.id }),
|
3270
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: row.id }) }),
|
3271
|
+
shouldDisplayMainField && /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: row[mainField] }) }),
|
3272
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: row.status, maxWidth: "min-content" }) }),
|
3273
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: isPublishing && entriesToPublish.includes(row.documentId) ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
3274
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: formatMessage({
|
3275
|
+
id: "content-manager.success.record.publishing",
|
3276
|
+
defaultMessage: "Publishing..."
|
2626
3277
|
}) }),
|
2627
|
-
|
3278
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true })
|
3279
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
3280
|
+
EntryValidationText,
|
3281
|
+
{
|
3282
|
+
validationErrors: validationErrors[row.documentId],
|
3283
|
+
status: row.status
|
3284
|
+
}
|
3285
|
+
) }),
|
3286
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
3287
|
+
designSystem.IconButton,
|
3288
|
+
{
|
3289
|
+
tag: reactRouterDom.Link,
|
3290
|
+
to: {
|
3291
|
+
pathname: `${pathname}/${row.documentId}`,
|
3292
|
+
search: row.locale && `?plugins[i18n][locale]=${row.locale}`
|
3293
|
+
},
|
3294
|
+
state: { from: pathname },
|
3295
|
+
label: formatMessage(
|
3296
|
+
{ id: "app.component.HelperPluginTable.edit", defaultMessage: "Edit {target}" },
|
3297
|
+
{
|
3298
|
+
target: formatMessage(
|
3299
|
+
{
|
3300
|
+
id: "content-manager.components.ListViewHelperPluginTable.row-line",
|
3301
|
+
defaultMessage: "item line {number}"
|
3302
|
+
},
|
3303
|
+
{ number: index2 + 1 }
|
3304
|
+
)
|
3305
|
+
}
|
3306
|
+
),
|
3307
|
+
target: "_blank",
|
3308
|
+
marginLeft: "auto",
|
3309
|
+
variant: "ghost",
|
3310
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, { width: "1.6rem", height: "1.6rem" })
|
3311
|
+
}
|
3312
|
+
) }) })
|
3313
|
+
] }, row.id)) })
|
3314
|
+
] });
|
3315
|
+
};
|
3316
|
+
const BoldChunk = (chunks) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", children: chunks });
|
3317
|
+
const SelectedEntriesModalContent = ({
|
3318
|
+
listViewSelectedEntries,
|
3319
|
+
toggleModal,
|
3320
|
+
setListViewSelectedDocuments,
|
3321
|
+
model
|
3322
|
+
}) => {
|
3323
|
+
const { formatMessage } = reactIntl.useIntl();
|
3324
|
+
const { schema, components } = useContentTypeSchema(model);
|
3325
|
+
const documentIds = listViewSelectedEntries.map(({ documentId }) => documentId);
|
3326
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
3327
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
3328
|
+
const { data, isLoading, isFetching, refetch } = useGetAllDocumentsQuery(
|
3329
|
+
{
|
3330
|
+
model,
|
3331
|
+
params: {
|
3332
|
+
page: "1",
|
3333
|
+
pageSize: documentIds.length.toString(),
|
3334
|
+
sort: query.sort,
|
3335
|
+
filters: {
|
3336
|
+
documentId: {
|
3337
|
+
$in: documentIds
|
3338
|
+
}
|
3339
|
+
},
|
3340
|
+
locale: query.plugins?.i18n?.locale
|
3341
|
+
}
|
3342
|
+
},
|
3343
|
+
{
|
3344
|
+
selectFromResult: ({ data: data2, ...restRes }) => ({ data: data2?.results ?? [], ...restRes })
|
3345
|
+
}
|
3346
|
+
);
|
3347
|
+
const { rows, validationErrors } = React__namespace.useMemo(() => {
|
3348
|
+
if (data.length > 0 && schema) {
|
3349
|
+
const validate = createYupSchema(
|
3350
|
+
schema.attributes,
|
3351
|
+
components,
|
3352
|
+
// Since this is the "Publish" action, the validation
|
3353
|
+
// schema must enforce the rules for published entities
|
3354
|
+
{ status: "published" }
|
3355
|
+
);
|
3356
|
+
const validationErrors2 = {};
|
3357
|
+
const rows2 = data.map((entry) => {
|
3358
|
+
try {
|
3359
|
+
validate.validateSync(entry, { abortEarly: false });
|
3360
|
+
return entry;
|
3361
|
+
} catch (e) {
|
3362
|
+
if (e instanceof yup.ValidationError) {
|
3363
|
+
validationErrors2[entry.documentId] = strapiAdmin.getYupValidationErrors(e);
|
3364
|
+
}
|
3365
|
+
return entry;
|
3366
|
+
}
|
3367
|
+
});
|
3368
|
+
return { rows: rows2, validationErrors: validationErrors2 };
|
3369
|
+
}
|
3370
|
+
return {
|
3371
|
+
rows: [],
|
3372
|
+
validationErrors: {}
|
3373
|
+
};
|
3374
|
+
}, [components, data, schema]);
|
3375
|
+
const [publishedCount, setPublishedCount] = React__namespace.useState(0);
|
3376
|
+
const [isDialogOpen, setIsDialogOpen] = React__namespace.useState(false);
|
3377
|
+
const { publishMany: bulkPublishAction } = useDocumentActions();
|
3378
|
+
const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation();
|
3379
|
+
const selectedRows = strapiAdmin.useTable("publishAction", (state) => state.selectedRows);
|
3380
|
+
const selectedEntries = rows.filter(
|
3381
|
+
(entry) => selectedRows.some((selectedEntry) => selectedEntry.documentId === entry.documentId)
|
3382
|
+
);
|
3383
|
+
const entriesToPublish = selectedEntries.filter((entry) => !validationErrors[entry.documentId]).map((entry) => entry.documentId);
|
3384
|
+
const selectedEntriesWithErrorsCount = selectedEntries.filter(
|
3385
|
+
({ documentId }) => validationErrors[documentId]
|
3386
|
+
).length;
|
3387
|
+
const selectedEntriesPublished = selectedEntries.filter(
|
3388
|
+
({ status }) => status === "published"
|
3389
|
+
).length;
|
3390
|
+
const selectedEntriesWithNoErrorsCount = selectedEntries.length - selectedEntriesWithErrorsCount - selectedEntriesPublished;
|
3391
|
+
const toggleDialog = () => setIsDialogOpen((prev) => !prev);
|
3392
|
+
const handleConfirmBulkPublish = async () => {
|
3393
|
+
toggleDialog();
|
3394
|
+
const res = await bulkPublishAction({ model, documentIds: entriesToPublish, params });
|
3395
|
+
if (!("error" in res)) {
|
3396
|
+
setPublishedCount(res.count);
|
3397
|
+
const unpublishedEntries = rows.filter((row) => {
|
3398
|
+
return !entriesToPublish.includes(row.documentId);
|
3399
|
+
});
|
3400
|
+
setListViewSelectedDocuments(unpublishedEntries);
|
3401
|
+
}
|
3402
|
+
};
|
3403
|
+
const getFormattedCountMessage = () => {
|
3404
|
+
if (publishedCount) {
|
3405
|
+
return formatMessage(
|
3406
|
+
{
|
3407
|
+
id: getTranslation("containers.list.selectedEntriesModal.publishedCount"),
|
3408
|
+
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."
|
3409
|
+
},
|
3410
|
+
{
|
3411
|
+
publishedCount,
|
3412
|
+
withErrorsCount: selectedEntriesWithErrorsCount,
|
3413
|
+
b: BoldChunk
|
3414
|
+
}
|
3415
|
+
);
|
3416
|
+
}
|
3417
|
+
return formatMessage(
|
3418
|
+
{
|
3419
|
+
id: getTranslation("containers.list.selectedEntriesModal.selectedCount"),
|
3420
|
+
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."
|
3421
|
+
},
|
3422
|
+
{
|
3423
|
+
readyToPublishCount: selectedEntriesWithNoErrorsCount,
|
3424
|
+
withErrorsCount: selectedEntriesWithErrorsCount,
|
3425
|
+
alreadyPublishedCount: selectedEntriesPublished,
|
3426
|
+
b: BoldChunk
|
3427
|
+
}
|
3428
|
+
);
|
3429
|
+
};
|
3430
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
3431
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Body, { children: [
|
3432
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: getFormattedCountMessage() }),
|
3433
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 5, children: /* @__PURE__ */ jsxRuntime.jsx(
|
3434
|
+
SelectedEntriesTableContent,
|
3435
|
+
{
|
3436
|
+
isPublishing: isSubmittingForm,
|
3437
|
+
rowsToDisplay: rows,
|
3438
|
+
entriesToPublish,
|
3439
|
+
validationErrors
|
3440
|
+
}
|
3441
|
+
) })
|
3442
|
+
] }),
|
3443
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
|
3444
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
|
3445
|
+
id: "app.components.Button.cancel",
|
3446
|
+
defaultMessage: "Cancel"
|
3447
|
+
}) }),
|
3448
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
3449
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
|
3450
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
2628
3451
|
designSystem.Button,
|
2629
3452
|
{
|
2630
|
-
onClick:
|
2631
|
-
|
2632
|
-
|
2633
|
-
children:
|
2634
|
-
id: "app.components.Button.confirm",
|
2635
|
-
defaultMessage: "Confirm"
|
2636
|
-
})
|
3453
|
+
onClick: toggleDialog,
|
3454
|
+
disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
|
3455
|
+
loading: isSubmittingForm,
|
3456
|
+
children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
|
2637
3457
|
}
|
2638
3458
|
)
|
3459
|
+
] })
|
3460
|
+
] }),
|
3461
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
3462
|
+
ConfirmDialogPublishAll,
|
3463
|
+
{
|
3464
|
+
isOpen: isDialogOpen,
|
3465
|
+
onToggleDialog: toggleDialog,
|
3466
|
+
isConfirmButtonLoading: isSubmittingForm,
|
3467
|
+
onConfirm: handleConfirmBulkPublish
|
2639
3468
|
}
|
2640
3469
|
)
|
2641
3470
|
] });
|
2642
3471
|
};
|
2643
|
-
const
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
2649
|
-
|
2650
|
-
|
2651
|
-
if (!
|
3472
|
+
const PublishAction = ({ documents, model }) => {
|
3473
|
+
const { formatMessage } = reactIntl.useIntl();
|
3474
|
+
const hasPublishPermission = useDocumentRBAC("unpublishAction", (state) => state.canPublish);
|
3475
|
+
const showPublishButton = hasPublishPermission && documents.some(({ status }) => status !== "published");
|
3476
|
+
const setListViewSelectedDocuments = strapiAdmin.useTable("publishAction", (state) => state.selectRow);
|
3477
|
+
const refetchList = () => {
|
3478
|
+
contentManagerApi.util.invalidateTags([{ type: "Document", id: `${model}_LIST` }]);
|
3479
|
+
};
|
3480
|
+
if (!showPublishButton)
|
2652
3481
|
return null;
|
2653
|
-
|
2654
|
-
|
2655
|
-
|
2656
|
-
|
3482
|
+
return {
|
3483
|
+
actionType: "publish",
|
3484
|
+
variant: "tertiary",
|
3485
|
+
label: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" }),
|
3486
|
+
dialog: {
|
3487
|
+
type: "modal",
|
3488
|
+
title: formatMessage({
|
3489
|
+
id: getTranslation("containers.ListPage.selectedEntriesModal.title"),
|
3490
|
+
defaultMessage: "Publish entries"
|
3491
|
+
}),
|
3492
|
+
content: ({ onClose }) => {
|
3493
|
+
return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Root, { rows: documents, defaultSelectedRows: documents, headers: TABLE_HEADERS, children: /* @__PURE__ */ jsxRuntime.jsx(
|
3494
|
+
SelectedEntriesModalContent,
|
3495
|
+
{
|
3496
|
+
listViewSelectedEntries: documents,
|
3497
|
+
toggleModal: () => {
|
3498
|
+
onClose();
|
3499
|
+
refetchList();
|
3500
|
+
},
|
3501
|
+
setListViewSelectedDocuments,
|
3502
|
+
model
|
3503
|
+
}
|
3504
|
+
) });
|
3505
|
+
},
|
3506
|
+
onClose: () => {
|
3507
|
+
refetchList();
|
3508
|
+
}
|
2657
3509
|
}
|
2658
|
-
onModalClose();
|
2659
3510
|
};
|
2660
|
-
|
2661
|
-
|
2662
|
-
|
2663
|
-
|
3511
|
+
};
|
3512
|
+
const BulkActionsRenderer = () => {
|
3513
|
+
const plugins = strapiAdmin.useStrapiApp("BulkActionsRenderer", (state) => state.plugins);
|
3514
|
+
const { model, collectionType } = useDoc();
|
3515
|
+
const { selectedRows } = strapiAdmin.useTable("BulkActionsRenderer", (state) => state);
|
3516
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
3517
|
+
strapiAdmin.DescriptionComponentRenderer,
|
3518
|
+
{
|
3519
|
+
props: {
|
3520
|
+
model,
|
3521
|
+
collectionType,
|
3522
|
+
documents: selectedRows
|
3523
|
+
},
|
3524
|
+
descriptions: plugins["content-manager"].apis.getBulkActions(),
|
3525
|
+
children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActionButton, { ...action }, action.id))
|
3526
|
+
}
|
3527
|
+
) });
|
2664
3528
|
};
|
2665
3529
|
const DeleteAction = ({ documents, model }) => {
|
2666
3530
|
const { formatMessage } = reactIntl.useIntl();
|
@@ -2694,6 +3558,7 @@ const DeleteAction = ({ documents, model }) => {
|
|
2694
3558
|
defaultMessage: "Confirmation"
|
2695
3559
|
}),
|
2696
3560
|
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3561
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
2697
3562
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
2698
3563
|
id: "popUpWarning.bodyMessage.contentType.delete.all",
|
2699
3564
|
defaultMessage: "Are you sure you want to delete these entries?"
|
@@ -2730,7 +3595,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
2730
3595
|
selectRow([]);
|
2731
3596
|
}
|
2732
3597
|
};
|
2733
|
-
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published");
|
3598
|
+
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
|
2734
3599
|
if (!showUnpublishButton)
|
2735
3600
|
return null;
|
2736
3601
|
return {
|
@@ -2743,6 +3608,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
2743
3608
|
defaultMessage: "Confirmation"
|
2744
3609
|
}),
|
2745
3610
|
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3611
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
2746
3612
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
2747
3613
|
id: "popUpWarning.bodyMessage.contentType.unpublish.all",
|
2748
3614
|
defaultMessage: "Are you sure you want to unpublish these entries?"
|
@@ -2767,7 +3633,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
2767
3633
|
};
|
2768
3634
|
UnpublishAction.type = "unpublish";
|
2769
3635
|
const Emphasis = (chunks) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
|
2770
|
-
const DEFAULT_BULK_ACTIONS = [UnpublishAction, DeleteAction];
|
3636
|
+
const DEFAULT_BULK_ACTIONS = [PublishAction, UnpublishAction, DeleteAction];
|
2771
3637
|
const AutoCloneFailureModalBody = ({ prohibitedFields }) => {
|
2772
3638
|
const { formatMessage } = reactIntl.useIntl();
|
2773
3639
|
const getDefaultErrorMessage = (reason) => {
|
@@ -2836,7 +3702,7 @@ const TableActions = ({ document }) => {
|
|
2836
3702
|
strapiAdmin.DescriptionComponentRenderer,
|
2837
3703
|
{
|
2838
3704
|
props,
|
2839
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3705
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
|
2840
3706
|
children: (actions2) => {
|
2841
3707
|
const tableRowActions = actions2.filter((action) => {
|
2842
3708
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -2947,7 +3813,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
2947
3813
|
}),
|
2948
3814
|
content: /* @__PURE__ */ jsxRuntime.jsx(AutoCloneFailureModalBody, { prohibitedFields }),
|
2949
3815
|
footer: ({ onClose }) => {
|
2950
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.
|
3816
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
|
2951
3817
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
|
2952
3818
|
id: "cancel",
|
2953
3819
|
defaultMessage: "Cancel"
|
@@ -2988,8 +3854,7 @@ class ContentManagerPlugin {
|
|
2988
3854
|
documentActions = [
|
2989
3855
|
...DEFAULT_ACTIONS,
|
2990
3856
|
...DEFAULT_TABLE_ROW_ACTIONS,
|
2991
|
-
...DEFAULT_HEADER_ACTIONS
|
2992
|
-
HistoryAction
|
3857
|
+
...DEFAULT_HEADER_ACTIONS
|
2993
3858
|
];
|
2994
3859
|
editViewSidePanels = [ActionsPanel];
|
2995
3860
|
headerActions = [];
|
@@ -3078,6 +3943,52 @@ const getPrintableType = (value) => {
|
|
3078
3943
|
}
|
3079
3944
|
return nativeType;
|
3080
3945
|
};
|
3946
|
+
const HistoryAction = ({ model, document }) => {
|
3947
|
+
const { formatMessage } = reactIntl.useIntl();
|
3948
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
3949
|
+
const navigate = reactRouterDom.useNavigate();
|
3950
|
+
const pluginsQueryParams = qs.stringify({ plugins: query.plugins }, { encode: false });
|
3951
|
+
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
3952
|
+
return null;
|
3953
|
+
}
|
3954
|
+
return {
|
3955
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.ClockCounterClockwise, {}),
|
3956
|
+
label: formatMessage({
|
3957
|
+
id: "content-manager.history.document-action",
|
3958
|
+
defaultMessage: "Content History"
|
3959
|
+
}),
|
3960
|
+
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
3961
|
+
disabled: (
|
3962
|
+
/**
|
3963
|
+
* The user is creating a new document.
|
3964
|
+
* It hasn't been saved yet, so there's no history to go to
|
3965
|
+
*/
|
3966
|
+
!document || /**
|
3967
|
+
* The document has been created but the current dimension has never been saved.
|
3968
|
+
* For example, the user is creating a new locale in an existing document,
|
3969
|
+
* so there's no history for the document in that locale
|
3970
|
+
*/
|
3971
|
+
!document.id || /**
|
3972
|
+
* History is only available for content types created by the user.
|
3973
|
+
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
3974
|
+
* which start with `admin::` or `plugin::`
|
3975
|
+
*/
|
3976
|
+
!model.startsWith("api::")
|
3977
|
+
),
|
3978
|
+
position: "header"
|
3979
|
+
};
|
3980
|
+
};
|
3981
|
+
HistoryAction.type = "history";
|
3982
|
+
const historyAdmin = {
|
3983
|
+
bootstrap(app) {
|
3984
|
+
const { addDocumentAction } = app.getPlugin("content-manager").apis;
|
3985
|
+
addDocumentAction((actions2) => {
|
3986
|
+
const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
|
3987
|
+
actions2.splice(indexOfDeleteAction, 0, HistoryAction);
|
3988
|
+
return actions2;
|
3989
|
+
});
|
3990
|
+
}
|
3991
|
+
};
|
3081
3992
|
const initialState = {
|
3082
3993
|
collectionTypeLinks: [],
|
3083
3994
|
components: [],
|
@@ -3114,308 +4025,6 @@ const { setInitialData } = actions;
|
|
3114
4025
|
const reducer = toolkit.combineReducers({
|
3115
4026
|
app: reducer$1
|
3116
4027
|
});
|
3117
|
-
const HOOKS = {
|
3118
|
-
/**
|
3119
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
3120
|
-
* @constant
|
3121
|
-
* @type {string}
|
3122
|
-
*/
|
3123
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
3124
|
-
/**
|
3125
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
3126
|
-
* @constant
|
3127
|
-
* @type {string}
|
3128
|
-
*/
|
3129
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
3130
|
-
/**
|
3131
|
-
* Hook that allows to mutate the CM's edit view layout
|
3132
|
-
* @constant
|
3133
|
-
* @type {string}
|
3134
|
-
*/
|
3135
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
3136
|
-
/**
|
3137
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
3138
|
-
* @constant
|
3139
|
-
* @type {string}
|
3140
|
-
*/
|
3141
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
3142
|
-
};
|
3143
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
3144
|
-
endpoints: (builder) => ({
|
3145
|
-
getContentTypeConfiguration: builder.query({
|
3146
|
-
query: (uid) => ({
|
3147
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
3148
|
-
method: "GET"
|
3149
|
-
}),
|
3150
|
-
transformResponse: (response) => response.data,
|
3151
|
-
providesTags: (_result, _error, uid) => [
|
3152
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
3153
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
3154
|
-
]
|
3155
|
-
}),
|
3156
|
-
getAllContentTypeSettings: builder.query({
|
3157
|
-
query: () => "/content-manager/content-types-settings",
|
3158
|
-
transformResponse: (response) => response.data,
|
3159
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
3160
|
-
}),
|
3161
|
-
updateContentTypeConfiguration: builder.mutation({
|
3162
|
-
query: ({ uid, ...body }) => ({
|
3163
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
3164
|
-
method: "PUT",
|
3165
|
-
data: body
|
3166
|
-
}),
|
3167
|
-
transformResponse: (response) => response.data,
|
3168
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
3169
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
3170
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
3171
|
-
// Is this necessary?
|
3172
|
-
{ type: "InitialData" }
|
3173
|
-
]
|
3174
|
-
})
|
3175
|
-
})
|
3176
|
-
});
|
3177
|
-
const {
|
3178
|
-
useGetContentTypeConfigurationQuery,
|
3179
|
-
useGetAllContentTypeSettingsQuery,
|
3180
|
-
useUpdateContentTypeConfigurationMutation
|
3181
|
-
} = contentTypesApi;
|
3182
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
3183
|
-
const { type } = attribute;
|
3184
|
-
if (type === "relation") {
|
3185
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
3186
|
-
}
|
3187
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
3188
|
-
};
|
3189
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
3190
|
-
if (!mainFieldName) {
|
3191
|
-
return void 0;
|
3192
|
-
}
|
3193
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
3194
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
3195
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
3196
|
-
);
|
3197
|
-
return {
|
3198
|
-
name: mainFieldName,
|
3199
|
-
type: mainFieldType ?? "string"
|
3200
|
-
};
|
3201
|
-
};
|
3202
|
-
const DEFAULT_SETTINGS = {
|
3203
|
-
bulkable: false,
|
3204
|
-
filterable: false,
|
3205
|
-
searchable: false,
|
3206
|
-
pagination: false,
|
3207
|
-
defaultSortBy: "",
|
3208
|
-
defaultSortOrder: "asc",
|
3209
|
-
mainField: "id",
|
3210
|
-
pageSize: 10
|
3211
|
-
};
|
3212
|
-
const useDocumentLayout = (model) => {
|
3213
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
3214
|
-
const [{ query }] = strapiAdmin.useQueryParams();
|
3215
|
-
const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
3216
|
-
const { toggleNotification } = strapiAdmin.useNotification();
|
3217
|
-
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
3218
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
3219
|
-
const {
|
3220
|
-
data,
|
3221
|
-
isLoading: isLoadingConfigs,
|
3222
|
-
error,
|
3223
|
-
isFetching: isFetchingConfigs
|
3224
|
-
} = useGetContentTypeConfigurationQuery(model);
|
3225
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
3226
|
-
React__namespace.useEffect(() => {
|
3227
|
-
if (error) {
|
3228
|
-
toggleNotification({
|
3229
|
-
type: "danger",
|
3230
|
-
message: formatAPIError(error)
|
3231
|
-
});
|
3232
|
-
}
|
3233
|
-
}, [error, formatAPIError, toggleNotification]);
|
3234
|
-
const editLayout = React__namespace.useMemo(
|
3235
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
3236
|
-
layout: [],
|
3237
|
-
components: {},
|
3238
|
-
metadatas: {},
|
3239
|
-
options: {},
|
3240
|
-
settings: DEFAULT_SETTINGS
|
3241
|
-
},
|
3242
|
-
[data, isLoading, schemas, schema, components]
|
3243
|
-
);
|
3244
|
-
const listLayout = React__namespace.useMemo(() => {
|
3245
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
3246
|
-
layout: [],
|
3247
|
-
metadatas: {},
|
3248
|
-
options: {},
|
3249
|
-
settings: DEFAULT_SETTINGS
|
3250
|
-
};
|
3251
|
-
}, [data, isLoading, schemas, schema, components]);
|
3252
|
-
const { layout: edit } = React__namespace.useMemo(
|
3253
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
3254
|
-
layout: editLayout,
|
3255
|
-
query
|
3256
|
-
}),
|
3257
|
-
[editLayout, query, runHookWaterfall]
|
3258
|
-
);
|
3259
|
-
return {
|
3260
|
-
error,
|
3261
|
-
isLoading,
|
3262
|
-
edit,
|
3263
|
-
list: listLayout
|
3264
|
-
};
|
3265
|
-
};
|
3266
|
-
const useDocLayout = () => {
|
3267
|
-
const { model } = useDoc();
|
3268
|
-
return useDocumentLayout(model);
|
3269
|
-
};
|
3270
|
-
const formatEditLayout = (data, {
|
3271
|
-
schemas,
|
3272
|
-
schema,
|
3273
|
-
components
|
3274
|
-
}) => {
|
3275
|
-
let currentPanelIndex = 0;
|
3276
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
3277
|
-
data.contentType.layouts.edit,
|
3278
|
-
schema?.attributes,
|
3279
|
-
data.contentType.metadatas,
|
3280
|
-
{ configurations: data.components, schemas: components },
|
3281
|
-
schemas
|
3282
|
-
).reduce((panels, row) => {
|
3283
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
3284
|
-
panels.push([row]);
|
3285
|
-
currentPanelIndex += 2;
|
3286
|
-
} else {
|
3287
|
-
if (!panels[currentPanelIndex]) {
|
3288
|
-
panels.push([]);
|
3289
|
-
}
|
3290
|
-
panels[currentPanelIndex].push(row);
|
3291
|
-
}
|
3292
|
-
return panels;
|
3293
|
-
}, []);
|
3294
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
3295
|
-
(acc, [uid, configuration]) => {
|
3296
|
-
acc[uid] = {
|
3297
|
-
layout: convertEditLayoutToFieldLayouts(
|
3298
|
-
configuration.layouts.edit,
|
3299
|
-
components[uid].attributes,
|
3300
|
-
configuration.metadatas
|
3301
|
-
),
|
3302
|
-
settings: {
|
3303
|
-
...configuration.settings,
|
3304
|
-
icon: components[uid].info.icon,
|
3305
|
-
displayName: components[uid].info.displayName
|
3306
|
-
}
|
3307
|
-
};
|
3308
|
-
return acc;
|
3309
|
-
},
|
3310
|
-
{}
|
3311
|
-
);
|
3312
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
3313
|
-
(acc, [attribute, metadata]) => {
|
3314
|
-
return {
|
3315
|
-
...acc,
|
3316
|
-
[attribute]: metadata.edit
|
3317
|
-
};
|
3318
|
-
},
|
3319
|
-
{}
|
3320
|
-
);
|
3321
|
-
return {
|
3322
|
-
layout: panelledEditAttributes,
|
3323
|
-
components: componentEditAttributes,
|
3324
|
-
metadatas: editMetadatas,
|
3325
|
-
settings: {
|
3326
|
-
...data.contentType.settings,
|
3327
|
-
displayName: schema?.info.displayName
|
3328
|
-
},
|
3329
|
-
options: {
|
3330
|
-
...schema?.options,
|
3331
|
-
...schema?.pluginOptions,
|
3332
|
-
...data.contentType.options
|
3333
|
-
}
|
3334
|
-
};
|
3335
|
-
};
|
3336
|
-
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
3337
|
-
return rows.map(
|
3338
|
-
(row) => row.map((field) => {
|
3339
|
-
const attribute = attributes[field.name];
|
3340
|
-
if (!attribute) {
|
3341
|
-
return null;
|
3342
|
-
}
|
3343
|
-
const { edit: metadata } = metadatas[field.name];
|
3344
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
3345
|
-
return {
|
3346
|
-
attribute,
|
3347
|
-
disabled: !metadata.editable,
|
3348
|
-
hint: metadata.description,
|
3349
|
-
label: metadata.label ?? "",
|
3350
|
-
name: field.name,
|
3351
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
3352
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
3353
|
-
schemas,
|
3354
|
-
components: components?.schemas ?? {}
|
3355
|
-
}),
|
3356
|
-
placeholder: metadata.placeholder ?? "",
|
3357
|
-
required: attribute.required ?? false,
|
3358
|
-
size: field.size,
|
3359
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
3360
|
-
visible: metadata.visible ?? true,
|
3361
|
-
type: attribute.type
|
3362
|
-
};
|
3363
|
-
}).filter((field) => field !== null)
|
3364
|
-
);
|
3365
|
-
};
|
3366
|
-
const formatListLayout = (data, {
|
3367
|
-
schemas,
|
3368
|
-
schema,
|
3369
|
-
components
|
3370
|
-
}) => {
|
3371
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
3372
|
-
(acc, [attribute, metadata]) => {
|
3373
|
-
return {
|
3374
|
-
...acc,
|
3375
|
-
[attribute]: metadata.list
|
3376
|
-
};
|
3377
|
-
},
|
3378
|
-
{}
|
3379
|
-
);
|
3380
|
-
const listAttributes = convertListLayoutToFieldLayouts(
|
3381
|
-
data.contentType.layouts.list,
|
3382
|
-
schema?.attributes,
|
3383
|
-
listMetadatas,
|
3384
|
-
{ configurations: data.components, schemas: components },
|
3385
|
-
schemas
|
3386
|
-
);
|
3387
|
-
return {
|
3388
|
-
layout: listAttributes,
|
3389
|
-
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
3390
|
-
metadatas: listMetadatas,
|
3391
|
-
options: {
|
3392
|
-
...schema?.options,
|
3393
|
-
...schema?.pluginOptions,
|
3394
|
-
...data.contentType.options
|
3395
|
-
}
|
3396
|
-
};
|
3397
|
-
};
|
3398
|
-
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
3399
|
-
return columns.map((name) => {
|
3400
|
-
const attribute = attributes[name];
|
3401
|
-
if (!attribute) {
|
3402
|
-
return null;
|
3403
|
-
}
|
3404
|
-
const metadata = metadatas[name];
|
3405
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
3406
|
-
return {
|
3407
|
-
attribute,
|
3408
|
-
label: metadata.label ?? "",
|
3409
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
3410
|
-
schemas,
|
3411
|
-
components: components?.schemas ?? {}
|
3412
|
-
}),
|
3413
|
-
name,
|
3414
|
-
searchable: metadata.searchable ?? true,
|
3415
|
-
sortable: metadata.sortable ?? true
|
3416
|
-
};
|
3417
|
-
}).filter((field) => field !== null);
|
3418
|
-
};
|
3419
4028
|
const index = {
|
3420
4029
|
register(app) {
|
3421
4030
|
const cm = new ContentManagerPlugin();
|
@@ -3430,15 +4039,29 @@ const index = {
|
|
3430
4039
|
defaultMessage: "Content Manager"
|
3431
4040
|
},
|
3432
4041
|
permissions: [],
|
3433
|
-
Component: () => Promise.resolve().then(() => require("./layout-ni_L9kT1.js")).then((mod) => ({ default: mod.Layout })),
|
3434
4042
|
position: 1
|
3435
4043
|
});
|
4044
|
+
app.router.addRoute({
|
4045
|
+
path: "content-manager/*",
|
4046
|
+
lazy: async () => {
|
4047
|
+
const { Layout } = await Promise.resolve().then(() => require("./layout-Euka-kfv.js"));
|
4048
|
+
return {
|
4049
|
+
Component: Layout
|
4050
|
+
};
|
4051
|
+
},
|
4052
|
+
children: routes
|
4053
|
+
});
|
3436
4054
|
app.registerPlugin(cm.config);
|
3437
4055
|
},
|
4056
|
+
bootstrap(app) {
|
4057
|
+
if (typeof historyAdmin.bootstrap === "function") {
|
4058
|
+
historyAdmin.bootstrap(app);
|
4059
|
+
}
|
4060
|
+
},
|
3438
4061
|
async registerTrads({ locales }) {
|
3439
4062
|
const importedTrads = await Promise.all(
|
3440
4063
|
locales.map((locale) => {
|
3441
|
-
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => Promise.resolve().then(() => require("./ar-BUUWXIYu.js")), "./translations/ca.json": () => Promise.resolve().then(() => require("./ca-Cmk45QO6.js")), "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-CkJy6B2v.js")), "./translations/de.json": () => Promise.resolve().then(() => require("./de-CCEmbAah.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-
|
4064
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => Promise.resolve().then(() => require("./ar-BUUWXIYu.js")), "./translations/ca.json": () => Promise.resolve().then(() => require("./ca-Cmk45QO6.js")), "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-CkJy6B2v.js")), "./translations/de.json": () => Promise.resolve().then(() => require("./de-CCEmbAah.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-Bm0D0IWz.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-EUonQTon.js")), "./translations/eu.json": () => Promise.resolve().then(() => require("./eu-VDH-3ovk.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-B7kGGg3E.js")), "./translations/gu.json": () => Promise.resolve().then(() => require("./gu-BRmF601H.js")), "./translations/hi.json": () => Promise.resolve().then(() => require("./hi-CCJBptSq.js")), "./translations/hu.json": () => Promise.resolve().then(() => require("./hu-sNV_yLYy.js")), "./translations/id.json": () => Promise.resolve().then(() => require("./id-B5Ser98A.js")), "./translations/it.json": () => Promise.resolve().then(() => require("./it-DkBIs7vD.js")), "./translations/ja.json": () => Promise.resolve().then(() => require("./ja-CcFe8diO.js")), "./translations/ko.json": () => Promise.resolve().then(() => require("./ko-woFZPmLk.js")), "./translations/ml.json": () => Promise.resolve().then(() => require("./ml-C2W8N8k1.js")), "./translations/ms.json": () => Promise.resolve().then(() => require("./ms-BuFotyP_.js")), "./translations/nl.json": () => Promise.resolve().then(() => require("./nl-bbEOHChV.js")), "./translations/pl.json": () => Promise.resolve().then(() => require("./pl-uzwG-hk7.js")), "./translations/pt-BR.json": () => Promise.resolve().then(() => require("./pt-BR-BiOz37D9.js")), "./translations/pt.json": () => Promise.resolve().then(() => require("./pt-CeXQuq50.js")), "./translations/ru.json": () => Promise.resolve().then(() => require("./ru-BT3ybNny.js")), "./translations/sa.json": () => Promise.resolve().then(() => require("./sa-CcvkYInH.js")), "./translations/sk.json": () => Promise.resolve().then(() => require("./sk-CvY09Xjv.js")), "./translations/sv.json": () => Promise.resolve().then(() => require("./sv-MYDuzgvT.js")), "./translations/th.json": () => Promise.resolve().then(() => require("./th-D9_GfAjc.js")), "./translations/tr.json": () => Promise.resolve().then(() => require("./tr-D9UH-O_R.js")), "./translations/uk.json": () => Promise.resolve().then(() => require("./uk-C8EiqJY7.js")), "./translations/vi.json": () => Promise.resolve().then(() => require("./vi-CJlYDheJ.js")), "./translations/zh-Hans.json": () => Promise.resolve().then(() => require("./zh-Hans-9kOncHGw.js")), "./translations/zh.json": () => Promise.resolve().then(() => require("./zh-CQQfszqR.js")) }), `./translations/${locale}.json`).then(({ default: data }) => {
|
3442
4065
|
return {
|
3443
4066
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3444
4067
|
locale
|
@@ -3456,6 +4079,7 @@ const index = {
|
|
3456
4079
|
};
|
3457
4080
|
exports.ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD = ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD;
|
3458
4081
|
exports.BulkActionsRenderer = BulkActionsRenderer;
|
4082
|
+
exports.CLONE_PATH = CLONE_PATH;
|
3459
4083
|
exports.COLLECTION_TYPES = COLLECTION_TYPES;
|
3460
4084
|
exports.CREATOR_FIELDS = CREATOR_FIELDS;
|
3461
4085
|
exports.DEFAULT_SETTINGS = DEFAULT_SETTINGS;
|
@@ -3482,8 +4106,8 @@ exports.getDisplayName = getDisplayName;
|
|
3482
4106
|
exports.getMainField = getMainField;
|
3483
4107
|
exports.getTranslation = getTranslation;
|
3484
4108
|
exports.index = index;
|
3485
|
-
exports.routes = routes;
|
3486
4109
|
exports.setInitialData = setInitialData;
|
4110
|
+
exports.useContentManagerContext = useContentManagerContext;
|
3487
4111
|
exports.useContentTypeSchema = useContentTypeSchema;
|
3488
4112
|
exports.useDoc = useDoc;
|
3489
4113
|
exports.useDocLayout = useDocLayout;
|
@@ -3496,4 +4120,4 @@ exports.useGetAllDocumentsQuery = useGetAllDocumentsQuery;
|
|
3496
4120
|
exports.useGetContentTypeConfigurationQuery = useGetContentTypeConfigurationQuery;
|
3497
4121
|
exports.useGetInitialDataQuery = useGetInitialDataQuery;
|
3498
4122
|
exports.useUpdateContentTypeConfigurationMutation = useUpdateContentTypeConfigurationMutation;
|
3499
|
-
//# sourceMappingURL=index-
|
4123
|
+
//# sourceMappingURL=index-oDq3VO9j.js.map
|