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