@strapi/content-manager 0.0.0-experimental.826f263c58b6886b849d3f03b81f7a530bc51c91 → 0.0.0-experimental.8f5736f39974781dca58cef1d1dea9d54580fbf1

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.
Files changed (134) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs → ComponentConfigurationPage-DfFSZQxe.mjs} +3 -3
  3. package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs.map → ComponentConfigurationPage-DfFSZQxe.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js → ComponentConfigurationPage-FqfsxQ1j.js} +3 -3
  5. package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js.map → ComponentConfigurationPage-FqfsxQ1j.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js → EditConfigurationPage-Cn0e8t3I.js} +3 -3
  7. package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js.map → EditConfigurationPage-Cn0e8t3I.js.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs → EditConfigurationPage-DdPNAbl3.mjs} +3 -3
  9. package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs.map → EditConfigurationPage-DdPNAbl3.mjs.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-DvaV7U9b.mjs → EditViewPage-B82x_x1b.mjs} +69 -48
  11. package/dist/_chunks/EditViewPage-B82x_x1b.mjs.map +1 -0
  12. package/dist/_chunks/{EditViewPage-CoQEnFlC.js → EditViewPage-DlxEHhUt.js} +68 -47
  13. package/dist/_chunks/EditViewPage-DlxEHhUt.js.map +1 -0
  14. package/dist/_chunks/{Field-ZdrmmQ4Y.js → Field-COL25JiC.js} +581 -229
  15. package/dist/_chunks/Field-COL25JiC.js.map +1 -0
  16. package/dist/_chunks/{Field-Cz_J9551.mjs → Field-DufHXW17.mjs} +579 -227
  17. package/dist/_chunks/Field-DufHXW17.mjs.map +1 -0
  18. package/dist/_chunks/{Form-Bpig5rch.js → Form-BssUwrTO.js} +52 -34
  19. package/dist/_chunks/Form-BssUwrTO.js.map +1 -0
  20. package/dist/_chunks/{Form-Dxmihyw8.mjs → Form-u_kAOhwB.mjs} +54 -36
  21. package/dist/_chunks/Form-u_kAOhwB.mjs.map +1 -0
  22. package/dist/_chunks/{History-BfX6XmZK.js → History-C9t9UqpO.js} +157 -40
  23. package/dist/_chunks/History-C9t9UqpO.js.map +1 -0
  24. package/dist/_chunks/{History-BZP8n7KT.mjs → History-DRwA3oMM.mjs} +158 -41
  25. package/dist/_chunks/History-DRwA3oMM.mjs.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-B3CXj8PY.js → ListConfigurationPage-BXYPohh-.js} +57 -46
  27. package/dist/_chunks/ListConfigurationPage-BXYPohh-.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-DxKuVkKz.mjs → ListConfigurationPage-BxfQJzPk.mjs} +58 -48
  29. package/dist/_chunks/ListConfigurationPage-BxfQJzPk.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-D5D3tVPq.mjs → ListViewPage-CELx2ysp.mjs} +103 -102
  31. package/dist/_chunks/ListViewPage-CELx2ysp.mjs.map +1 -0
  32. package/dist/_chunks/{ListViewPage-Bk9VO__I.js → ListViewPage-D2VD8Szg.js} +105 -104
  33. package/dist/_chunks/ListViewPage-D2VD8Szg.js.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js → NoContentTypePage-BV9IjJSM.js} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js.map → NoContentTypePage-BV9IjJSM.js.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs → NoContentTypePage-DtJ9jcfk.mjs} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs.map → NoContentTypePage-DtJ9jcfk.mjs.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs → NoPermissionsPage-DWleVYK7.mjs} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs.map → NoPermissionsPage-DWleVYK7.mjs.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js → NoPermissionsPage-Dp8NpF9I.js} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js.map → NoPermissionsPage-Dp8NpF9I.js.map} +1 -1
  42. package/dist/_chunks/{Relations-BOYZmuWy.mjs → Relations-BTcf5xaw.mjs} +33 -24
  43. package/dist/_chunks/Relations-BTcf5xaw.mjs.map +1 -0
  44. package/dist/_chunks/{Relations-B6B3A3mb.js → Relations-DR7EUgyC.js} +33 -24
  45. package/dist/_chunks/Relations-DR7EUgyC.js.map +1 -0
  46. package/dist/_chunks/{en-BN1bvFK7.js → en-Bm0D0IWz.js} +20 -15
  47. package/dist/_chunks/{en-BN1bvFK7.js.map → en-Bm0D0IWz.js.map} +1 -1
  48. package/dist/_chunks/{en-Dzv55oQw.mjs → en-DKV44jRb.mjs} +20 -15
  49. package/dist/_chunks/{en-Dzv55oQw.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  50. package/dist/_chunks/{index-DzN3kBgx.js → index-BdMf2lfT.js} +1030 -860
  51. package/dist/_chunks/index-BdMf2lfT.js.map +1 -0
  52. package/dist/_chunks/{index-VHviNMeW.mjs → index-wnqzm4Q8.mjs} +1062 -892
  53. package/dist/_chunks/index-wnqzm4Q8.mjs.map +1 -0
  54. package/dist/_chunks/{layout-CPn1PM6x.mjs → layout-2CfjL0T9.mjs} +41 -23
  55. package/dist/_chunks/layout-2CfjL0T9.mjs.map +1 -0
  56. package/dist/_chunks/{layout-b91XRlD2.js → layout-B2MyZU-_.js} +39 -21
  57. package/dist/_chunks/layout-B2MyZU-_.js.map +1 -0
  58. package/dist/_chunks/{relations-CA7IYmcP.js → relations-BH7JJGGe.js} +2 -2
  59. package/dist/_chunks/{relations-CA7IYmcP.js.map → relations-BH7JJGGe.js.map} +1 -1
  60. package/dist/_chunks/{relations-BsqxS6tR.mjs → relations-C0w0GcXi.mjs} +2 -2
  61. package/dist/_chunks/{relations-BsqxS6tR.mjs.map → relations-C0w0GcXi.mjs.map} +1 -1
  62. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  63. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  65. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  66. package/dist/admin/index.js +2 -1
  67. package/dist/admin/index.js.map +1 -1
  68. package/dist/admin/index.mjs +7 -6
  69. package/dist/admin/src/exports.d.ts +1 -1
  70. package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
  71. package/dist/admin/src/history/index.d.ts +3 -0
  72. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  73. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  74. package/dist/admin/src/index.d.ts +1 -0
  75. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
  76. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
  77. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  78. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  79. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  80. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
  81. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  82. package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
  83. package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
  84. package/dist/admin/src/services/api.d.ts +1 -1
  85. package/dist/admin/src/services/components.d.ts +2 -2
  86. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  87. package/dist/admin/src/services/documents.d.ts +19 -17
  88. package/dist/admin/src/services/init.d.ts +1 -1
  89. package/dist/admin/src/services/relations.d.ts +2 -2
  90. package/dist/admin/src/services/uid.d.ts +3 -3
  91. package/dist/admin/src/utils/validation.d.ts +4 -1
  92. package/dist/server/index.js +208 -120
  93. package/dist/server/index.js.map +1 -1
  94. package/dist/server/index.mjs +209 -121
  95. package/dist/server/index.mjs.map +1 -1
  96. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  97. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  98. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  99. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  100. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  101. package/dist/server/src/history/services/history.d.ts.map +1 -1
  102. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  103. package/dist/server/src/history/services/utils.d.ts +2 -1
  104. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  105. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  106. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  107. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  108. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  109. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  110. package/dist/shared/contracts/collection-types.d.ts +3 -1
  111. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  112. package/package.json +12 -12
  113. package/dist/_chunks/EditViewPage-CoQEnFlC.js.map +0 -1
  114. package/dist/_chunks/EditViewPage-DvaV7U9b.mjs.map +0 -1
  115. package/dist/_chunks/Field-Cz_J9551.mjs.map +0 -1
  116. package/dist/_chunks/Field-ZdrmmQ4Y.js.map +0 -1
  117. package/dist/_chunks/Form-Bpig5rch.js.map +0 -1
  118. package/dist/_chunks/Form-Dxmihyw8.mjs.map +0 -1
  119. package/dist/_chunks/History-BZP8n7KT.mjs.map +0 -1
  120. package/dist/_chunks/History-BfX6XmZK.js.map +0 -1
  121. package/dist/_chunks/ListConfigurationPage-B3CXj8PY.js.map +0 -1
  122. package/dist/_chunks/ListConfigurationPage-DxKuVkKz.mjs.map +0 -1
  123. package/dist/_chunks/ListViewPage-Bk9VO__I.js.map +0 -1
  124. package/dist/_chunks/ListViewPage-D5D3tVPq.mjs.map +0 -1
  125. package/dist/_chunks/Relations-B6B3A3mb.js.map +0 -1
  126. package/dist/_chunks/Relations-BOYZmuWy.mjs.map +0 -1
  127. package/dist/_chunks/index-DzN3kBgx.js.map +0 -1
  128. package/dist/_chunks/index-VHviNMeW.mjs.map +0 -1
  129. package/dist/_chunks/layout-CPn1PM6x.mjs.map +0 -1
  130. package/dist/_chunks/layout-b91XRlD2.js.map +0 -1
  131. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  132. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  133. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  134. package/strapi-server.js +0 -3
@@ -1,17 +1,17 @@
1
- import { ClockCounterClockwise, CrossCircle, More, WarningCircle, ListPlus, Pencil, Trash, Check, CheckCircle, ChevronRight, Duplicate, Feather } from "@strapi/icons";
1
+ import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
2
2
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import { useStrapiApp, useQueryParams, createContext, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useTracking, useForm, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
4
- import { stringify } from "qs";
5
- import { useIntl } from "react-intl";
6
- import { useNavigate, useParams, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
3
+ import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
7
4
  import * as React from "react";
8
5
  import { lazy } from "react";
9
- import { Menu, VisuallyHidden, Flex, Typography, Dialog, DialogBody, DialogFooter, Button, ModalLayout, ModalHeader, ModalBody, Box, Radio, Status, SingleSelect, SingleSelectOption, ModalFooter, Loader, IconButton, Tooltip, LinkButton } from "@strapi/design-system";
10
- import { styled } from "styled-components";
6
+ import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
7
+ import { useIntl } from "react-intl";
8
+ import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
11
9
  import * as yup from "yup";
12
10
  import { ValidationError } from "yup";
13
11
  import pipe from "lodash/fp/pipe";
14
12
  import { intervalToDuration, isPast } from "date-fns";
13
+ import { styled } from "styled-components";
14
+ import { stringify } from "qs";
15
15
  import { createSlice, combineReducers } from "@reduxjs/toolkit";
16
16
  const __variableDynamicImportRuntimeHelper = (glob, path) => {
17
17
  const v = glob[path];
@@ -49,42 +49,6 @@ const useInjectionZone = (area) => {
49
49
  const [page, position] = area.split(".");
50
50
  return contentManagerPlugin.getInjectedComponents(page, position);
51
51
  };
52
- const HistoryAction = ({ model, document }) => {
53
- const { formatMessage } = useIntl();
54
- const [{ query }] = useQueryParams();
55
- const navigate = useNavigate();
56
- const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
57
- if (!window.strapi.features.isEnabled("cms-content-history")) {
58
- return null;
59
- }
60
- return {
61
- icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
62
- label: formatMessage({
63
- id: "content-manager.history.document-action",
64
- defaultMessage: "Content History"
65
- }),
66
- onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
67
- disabled: (
68
- /**
69
- * The user is creating a new document.
70
- * It hasn't been saved yet, so there's no history to go to
71
- */
72
- !document || /**
73
- * The document has been created but the current dimension has never been saved.
74
- * For example, the user is creating a new locale in an existing document,
75
- * so there's no history for the document in that locale
76
- */
77
- !document.id || /**
78
- * History is only available for content types created by the user.
79
- * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
80
- * which start with `admin::` or `plugin::`
81
- */
82
- !model.startsWith("api::")
83
- ),
84
- position: "header"
85
- };
86
- };
87
- HistoryAction.type = "history";
88
52
  const ID = "id";
89
53
  const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
90
54
  const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
@@ -136,6 +100,7 @@ const DocumentRBAC = ({ children, permissions }) => {
136
100
  if (!slug) {
137
101
  throw new Error("Cannot find the slug param in the URL");
138
102
  }
103
+ const [{ rawQuery }] = useQueryParams();
139
104
  const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
140
105
  const contentTypePermissions = React.useMemo(() => {
141
106
  const contentTypePermissions2 = userPermissions.filter(
@@ -146,7 +111,14 @@ const DocumentRBAC = ({ children, permissions }) => {
146
111
  return { ...acc, [action]: [permission] };
147
112
  }, {});
148
113
  }, [slug, userPermissions]);
149
- const { isLoading, allowedActions } = useRBAC(contentTypePermissions, permissions ?? void 0);
114
+ const { isLoading, allowedActions } = useRBAC(
115
+ contentTypePermissions,
116
+ permissions ?? void 0,
117
+ // TODO: useRBAC context should be typed and built differently
118
+ // We are passing raw query as context to the hook so that it can
119
+ // rely on the locale provided from DocumentRBAC for its permission calculations.
120
+ rawQuery
121
+ );
150
122
  const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
151
123
  const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
152
124
  const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
@@ -194,10 +166,12 @@ const contentManagerApi = adminApi.enhanceEndpoints({
194
166
  "Document",
195
167
  "InitialData",
196
168
  "HistoryVersion",
197
- "Relations"
169
+ "Relations",
170
+ "UidAvailability"
198
171
  ]
199
172
  });
200
173
  const documentApi = contentManagerApi.injectEndpoints({
174
+ overrideExisting: true,
201
175
  endpoints: (builder) => ({
202
176
  autoCloneDocument: builder.mutation({
203
177
  query: ({ model, sourceId, query }) => ({
@@ -207,7 +181,12 @@ const documentApi = contentManagerApi.injectEndpoints({
207
181
  params: query
208
182
  }
209
183
  }),
210
- invalidatesTags: (_result, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
184
+ invalidatesTags: (_result, error, { model }) => {
185
+ if (error) {
186
+ return [];
187
+ }
188
+ return [{ type: "Document", id: `${model}_LIST` }];
189
+ }
211
190
  }),
212
191
  cloneDocument: builder.mutation({
213
192
  query: ({ model, sourceId, data, params }) => ({
@@ -218,7 +197,10 @@ const documentApi = contentManagerApi.injectEndpoints({
218
197
  params
219
198
  }
220
199
  }),
221
- invalidatesTags: (_result, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
200
+ invalidatesTags: (_result, _error, { model }) => [
201
+ { type: "Document", id: `${model}_LIST` },
202
+ { type: "UidAvailability", id: model }
203
+ ]
222
204
  }),
223
205
  /**
224
206
  * Creates a new collection-type document. This should ONLY be used for collection-types.
@@ -235,7 +217,8 @@ const documentApi = contentManagerApi.injectEndpoints({
235
217
  }),
236
218
  invalidatesTags: (result, _error, { model }) => [
237
219
  { type: "Document", id: `${model}_LIST` },
238
- "Relations"
220
+ "Relations",
221
+ { type: "UidAvailability", id: model }
239
222
  ]
240
223
  }),
241
224
  deleteDocument: builder.mutation({
@@ -276,7 +259,8 @@ const documentApi = contentManagerApi.injectEndpoints({
276
259
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
277
260
  },
278
261
  { type: "Document", id: `${model}_LIST` },
279
- "Relations"
262
+ "Relations",
263
+ { type: "UidAvailability", id: model }
280
264
  ];
281
265
  }
282
266
  }),
@@ -294,6 +278,7 @@ const documentApi = contentManagerApi.injectEndpoints({
294
278
  }),
295
279
  providesTags: (result, _error, arg) => {
296
280
  return [
281
+ { type: "Document", id: `ALL_LIST` },
297
282
  { type: "Document", id: `${arg.model}_LIST` },
298
283
  ...result?.results.map(({ documentId }) => ({
299
284
  type: "Document",
@@ -332,6 +317,11 @@ const documentApi = contentManagerApi.injectEndpoints({
332
317
  {
333
318
  type: "Document",
334
319
  id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
320
+ },
321
+ // Make it easy to invalidate all individual documents queries for a model
322
+ {
323
+ type: "Document",
324
+ id: `${model}_ALL_ITEMS`
335
325
  }
336
326
  ];
337
327
  }
@@ -395,8 +385,21 @@ const documentApi = contentManagerApi.injectEndpoints({
395
385
  type: "Document",
396
386
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
397
387
  },
398
- "Relations"
388
+ "Relations",
389
+ { type: "UidAvailability", id: model }
399
390
  ];
391
+ },
392
+ async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
393
+ const patchResult = dispatch(
394
+ documentApi.util.updateQueryData("getDocument", patch, (draft) => {
395
+ Object.assign(draft.data, data);
396
+ })
397
+ );
398
+ try {
399
+ await queryFulfilled;
400
+ } catch {
401
+ patchResult.undo();
402
+ }
400
403
  }
401
404
  }),
402
405
  unpublishDocument: builder.mutation({
@@ -466,20 +469,39 @@ const buildValidParams = (query) => {
466
469
  const isBaseQueryError = (error) => {
467
470
  return error.name !== void 0;
468
471
  };
469
- const createYupSchema = (attributes = {}, components = {}) => {
472
+ const arrayValidator = (attribute, options) => ({
473
+ message: translatedErrors.required,
474
+ test(value) {
475
+ if (options.status === "draft") {
476
+ return true;
477
+ }
478
+ if (!attribute.required) {
479
+ return true;
480
+ }
481
+ if (!value) {
482
+ return false;
483
+ }
484
+ if (Array.isArray(value) && value.length === 0) {
485
+ return false;
486
+ }
487
+ return true;
488
+ }
489
+ });
490
+ const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
470
491
  const createModelSchema = (attributes2) => yup.object().shape(
471
492
  Object.entries(attributes2).reduce((acc, [name, attribute]) => {
472
493
  if (DOCUMENT_META_FIELDS.includes(name)) {
473
494
  return acc;
474
495
  }
475
496
  const validations = [
497
+ addNullableValidation,
476
498
  addRequiredValidation,
477
499
  addMinLengthValidation,
478
500
  addMaxLengthValidation,
479
501
  addMinValidation,
480
502
  addMaxValidation,
481
503
  addRegexValidation
482
- ].map((fn) => fn(attribute));
504
+ ].map((fn) => fn(attribute, options));
483
505
  const transformSchema = pipe(...validations);
484
506
  switch (attribute.type) {
485
507
  case "component": {
@@ -489,12 +511,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
489
511
  ...acc,
490
512
  [name]: transformSchema(
491
513
  yup.array().of(createModelSchema(attributes3).nullable(false))
492
- )
514
+ ).test(arrayValidator(attribute, options))
493
515
  };
494
516
  } else {
495
517
  return {
496
518
  ...acc,
497
- [name]: transformSchema(createModelSchema(attributes3))
519
+ [name]: transformSchema(createModelSchema(attributes3).nullable())
498
520
  };
499
521
  }
500
522
  }
@@ -516,7 +538,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
516
538
  }
517
539
  )
518
540
  )
519
- )
541
+ ).test(arrayValidator(attribute, options))
520
542
  };
521
543
  case "relation":
522
544
  return {
@@ -528,7 +550,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
528
550
  } else if (Array.isArray(value)) {
529
551
  return yup.array().of(
530
552
  yup.object().shape({
531
- id: yup.string().required()
553
+ id: yup.number().required()
532
554
  })
533
555
  );
534
556
  } else if (typeof value === "object") {
@@ -580,6 +602,14 @@ const createAttributeSchema = (attribute) => {
580
602
  if (!value || typeof value === "string" && value.length === 0) {
581
603
  return true;
582
604
  }
605
+ if (typeof value === "object") {
606
+ try {
607
+ JSON.stringify(value);
608
+ return true;
609
+ } catch (err) {
610
+ return false;
611
+ }
612
+ }
583
613
  try {
584
614
  JSON.parse(value);
585
615
  return true;
@@ -598,13 +628,7 @@ const createAttributeSchema = (attribute) => {
598
628
  return yup.mixed();
599
629
  }
600
630
  };
601
- const addRequiredValidation = (attribute) => (schema) => {
602
- if (attribute.required) {
603
- return schema.required({
604
- id: translatedErrors.required.id,
605
- defaultMessage: "This field is required."
606
- });
607
- }
631
+ const nullableSchema = (schema) => {
608
632
  return schema?.nullable ? schema.nullable() : (
609
633
  // In some cases '.nullable' will not be available on the schema.
610
634
  // e.g. when the schema has been built using yup.lazy (e.g. for relations).
@@ -612,7 +636,22 @@ const addRequiredValidation = (attribute) => (schema) => {
612
636
  schema
613
637
  );
614
638
  };
615
- const addMinLengthValidation = (attribute) => (schema) => {
639
+ const addNullableValidation = () => (schema) => {
640
+ return nullableSchema(schema);
641
+ };
642
+ const addRequiredValidation = (attribute, options) => (schema) => {
643
+ if (options.status === "draft" || !attribute.required) {
644
+ return schema;
645
+ }
646
+ if (attribute.required && "required" in schema) {
647
+ return schema.required(translatedErrors.required);
648
+ }
649
+ return schema;
650
+ };
651
+ const addMinLengthValidation = (attribute, options) => (schema) => {
652
+ if (options.status === "draft") {
653
+ return schema;
654
+ }
616
655
  if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
617
656
  return schema.min(attribute.minLength, {
618
657
  ...translatedErrors.minLength,
@@ -634,10 +673,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
634
673
  }
635
674
  return schema;
636
675
  };
637
- const addMinValidation = (attribute) => (schema) => {
638
- if ("min" in attribute) {
676
+ const addMinValidation = (attribute, options) => (schema) => {
677
+ if (options.status === "draft") {
678
+ return schema;
679
+ }
680
+ if ("min" in attribute && "min" in schema) {
639
681
  const min = toInteger(attribute.min);
640
- if ("min" in schema && min) {
682
+ if (min) {
641
683
  return schema.min(min, {
642
684
  ...translatedErrors.min,
643
685
  values: {
@@ -755,16 +797,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
755
797
  }, {});
756
798
  return componentsByKey;
757
799
  };
758
- const useDocument = (args, opts) => {
800
+ const HOOKS = {
801
+ /**
802
+ * Hook that allows to mutate the displayed headers of the list view table
803
+ * @constant
804
+ * @type {string}
805
+ */
806
+ INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
807
+ /**
808
+ * Hook that allows to mutate the CM's collection types links pre-set filters
809
+ * @constant
810
+ * @type {string}
811
+ */
812
+ MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
813
+ /**
814
+ * Hook that allows to mutate the CM's edit view layout
815
+ * @constant
816
+ * @type {string}
817
+ */
818
+ MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
819
+ /**
820
+ * Hook that allows to mutate the CM's single types links pre-set filters
821
+ * @constant
822
+ * @type {string}
823
+ */
824
+ MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
825
+ };
826
+ const contentTypesApi = contentManagerApi.injectEndpoints({
827
+ endpoints: (builder) => ({
828
+ getContentTypeConfiguration: builder.query({
829
+ query: (uid) => ({
830
+ url: `/content-manager/content-types/${uid}/configuration`,
831
+ method: "GET"
832
+ }),
833
+ transformResponse: (response) => response.data,
834
+ providesTags: (_result, _error, uid) => [
835
+ { type: "ContentTypesConfiguration", id: uid },
836
+ { type: "ContentTypeSettings", id: "LIST" }
837
+ ]
838
+ }),
839
+ getAllContentTypeSettings: builder.query({
840
+ query: () => "/content-manager/content-types-settings",
841
+ transformResponse: (response) => response.data,
842
+ providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
843
+ }),
844
+ updateContentTypeConfiguration: builder.mutation({
845
+ query: ({ uid, ...body }) => ({
846
+ url: `/content-manager/content-types/${uid}/configuration`,
847
+ method: "PUT",
848
+ data: body
849
+ }),
850
+ transformResponse: (response) => response.data,
851
+ invalidatesTags: (_result, _error, { uid }) => [
852
+ { type: "ContentTypesConfiguration", id: uid },
853
+ { type: "ContentTypeSettings", id: "LIST" },
854
+ // Is this necessary?
855
+ { type: "InitialData" }
856
+ ]
857
+ })
858
+ })
859
+ });
860
+ const {
861
+ useGetContentTypeConfigurationQuery,
862
+ useGetAllContentTypeSettingsQuery,
863
+ useUpdateContentTypeConfigurationMutation
864
+ } = contentTypesApi;
865
+ const checkIfAttributeIsDisplayable = (attribute) => {
866
+ const { type } = attribute;
867
+ if (type === "relation") {
868
+ return !attribute.relation.toLowerCase().includes("morph");
869
+ }
870
+ return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
871
+ };
872
+ const getMainField = (attribute, mainFieldName, { schemas, components }) => {
873
+ if (!mainFieldName) {
874
+ return void 0;
875
+ }
876
+ const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
877
+ // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
878
+ schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
879
+ );
880
+ return {
881
+ name: mainFieldName,
882
+ type: mainFieldType ?? "string"
883
+ };
884
+ };
885
+ const DEFAULT_SETTINGS = {
886
+ bulkable: false,
887
+ filterable: false,
888
+ searchable: false,
889
+ pagination: false,
890
+ defaultSortBy: "",
891
+ defaultSortOrder: "asc",
892
+ mainField: "id",
893
+ pageSize: 10
894
+ };
895
+ const useDocumentLayout = (model) => {
896
+ const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
897
+ const [{ query }] = useQueryParams();
898
+ const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
759
899
  const { toggleNotification } = useNotification();
760
900
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
901
+ const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
761
902
  const {
762
- currentData: data,
763
- isLoading: isLoadingDocument,
764
- isFetching: isFetchingDocument,
765
- error
766
- } = useGetDocumentQuery(args, opts);
767
- const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
903
+ data,
904
+ isLoading: isLoadingConfigs,
905
+ error,
906
+ isFetching: isFetchingConfigs
907
+ } = useGetContentTypeConfigurationQuery(model);
908
+ const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
768
909
  React.useEffect(() => {
769
910
  if (error) {
770
911
  toggleNotification({
@@ -772,62 +913,318 @@ const useDocument = (args, opts) => {
772
913
  message: formatAPIError(error)
773
914
  });
774
915
  }
775
- }, [toggleNotification, error, formatAPIError, args.collectionType]);
776
- const validationSchema = React.useMemo(() => {
777
- if (!schema) {
778
- return null;
779
- }
780
- return createYupSchema(schema.attributes, components);
781
- }, [schema, components]);
782
- const validate = React.useCallback(
783
- (document) => {
784
- if (!validationSchema) {
785
- throw new Error(
786
- "There is no validation schema generated, this is likely due to the schema not being loaded yet."
787
- );
788
- }
789
- try {
790
- validationSchema.validateSync(document, { abortEarly: false, strict: true });
791
- return null;
792
- } catch (error2) {
793
- if (error2 instanceof ValidationError) {
794
- return getYupValidationErrors(error2);
795
- }
796
- throw error2;
797
- }
916
+ }, [error, formatAPIError, toggleNotification]);
917
+ const editLayout = React.useMemo(
918
+ () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
919
+ layout: [],
920
+ components: {},
921
+ metadatas: {},
922
+ options: {},
923
+ settings: DEFAULT_SETTINGS
798
924
  },
799
- [validationSchema]
925
+ [data, isLoading, schemas, schema, components]
926
+ );
927
+ const listLayout = React.useMemo(() => {
928
+ return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
929
+ layout: [],
930
+ metadatas: {},
931
+ options: {},
932
+ settings: DEFAULT_SETTINGS
933
+ };
934
+ }, [data, isLoading, schemas, schema, components]);
935
+ const { layout: edit } = React.useMemo(
936
+ () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
937
+ layout: editLayout,
938
+ query
939
+ }),
940
+ [editLayout, query, runHookWaterfall]
800
941
  );
801
- const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
802
942
  return {
803
- components,
804
- document: data?.data,
805
- meta: data?.meta,
943
+ error,
806
944
  isLoading,
807
- schema,
808
- validate
945
+ edit,
946
+ list: listLayout
809
947
  };
810
948
  };
811
- const useDoc = () => {
812
- const { id, slug, collectionType, origin } = useParams();
813
- const [{ query }] = useQueryParams();
814
- const params = React.useMemo(() => buildValidParams(query), [query]);
815
- if (!collectionType) {
816
- throw new Error("Could not find collectionType in url params");
817
- }
818
- if (!slug) {
819
- throw new Error("Could not find model in url params");
820
- }
949
+ const useDocLayout = () => {
950
+ const { model } = useDoc();
951
+ return useDocumentLayout(model);
952
+ };
953
+ const formatEditLayout = (data, {
954
+ schemas,
955
+ schema,
956
+ components
957
+ }) => {
958
+ let currentPanelIndex = 0;
959
+ const panelledEditAttributes = convertEditLayoutToFieldLayouts(
960
+ data.contentType.layouts.edit,
961
+ schema?.attributes,
962
+ data.contentType.metadatas,
963
+ { configurations: data.components, schemas: components },
964
+ schemas
965
+ ).reduce((panels, row) => {
966
+ if (row.some((field) => field.type === "dynamiczone")) {
967
+ panels.push([row]);
968
+ currentPanelIndex += 2;
969
+ } else {
970
+ if (!panels[currentPanelIndex]) {
971
+ panels.push([]);
972
+ }
973
+ panels[currentPanelIndex].push(row);
974
+ }
975
+ return panels;
976
+ }, []);
977
+ const componentEditAttributes = Object.entries(data.components).reduce(
978
+ (acc, [uid, configuration]) => {
979
+ acc[uid] = {
980
+ layout: convertEditLayoutToFieldLayouts(
981
+ configuration.layouts.edit,
982
+ components[uid].attributes,
983
+ configuration.metadatas,
984
+ { configurations: data.components, schemas: components }
985
+ ),
986
+ settings: {
987
+ ...configuration.settings,
988
+ icon: components[uid].info.icon,
989
+ displayName: components[uid].info.displayName
990
+ }
991
+ };
992
+ return acc;
993
+ },
994
+ {}
995
+ );
996
+ const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
997
+ (acc, [attribute, metadata]) => {
998
+ return {
999
+ ...acc,
1000
+ [attribute]: metadata.edit
1001
+ };
1002
+ },
1003
+ {}
1004
+ );
1005
+ return {
1006
+ layout: panelledEditAttributes,
1007
+ components: componentEditAttributes,
1008
+ metadatas: editMetadatas,
1009
+ settings: {
1010
+ ...data.contentType.settings,
1011
+ displayName: schema?.info.displayName
1012
+ },
1013
+ options: {
1014
+ ...schema?.options,
1015
+ ...schema?.pluginOptions,
1016
+ ...data.contentType.options
1017
+ }
1018
+ };
1019
+ };
1020
+ const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
1021
+ return rows.map(
1022
+ (row) => row.map((field) => {
1023
+ const attribute = attributes[field.name];
1024
+ if (!attribute) {
1025
+ return null;
1026
+ }
1027
+ const { edit: metadata } = metadatas[field.name];
1028
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1029
+ return {
1030
+ attribute,
1031
+ disabled: !metadata.editable,
1032
+ hint: metadata.description,
1033
+ label: metadata.label ?? "",
1034
+ name: field.name,
1035
+ // @ts-expect-error – mainField does exist on the metadata for a relation.
1036
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1037
+ schemas,
1038
+ components: components?.schemas ?? {}
1039
+ }),
1040
+ placeholder: metadata.placeholder ?? "",
1041
+ required: attribute.required ?? false,
1042
+ size: field.size,
1043
+ unique: "unique" in attribute ? attribute.unique : false,
1044
+ visible: metadata.visible ?? true,
1045
+ type: attribute.type
1046
+ };
1047
+ }).filter((field) => field !== null)
1048
+ );
1049
+ };
1050
+ const formatListLayout = (data, {
1051
+ schemas,
1052
+ schema,
1053
+ components
1054
+ }) => {
1055
+ const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
1056
+ (acc, [attribute, metadata]) => {
1057
+ return {
1058
+ ...acc,
1059
+ [attribute]: metadata.list
1060
+ };
1061
+ },
1062
+ {}
1063
+ );
1064
+ const listAttributes = convertListLayoutToFieldLayouts(
1065
+ data.contentType.layouts.list,
1066
+ schema?.attributes,
1067
+ listMetadatas,
1068
+ { configurations: data.components, schemas: components },
1069
+ schemas
1070
+ );
1071
+ return {
1072
+ layout: listAttributes,
1073
+ settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
1074
+ metadatas: listMetadatas,
1075
+ options: {
1076
+ ...schema?.options,
1077
+ ...schema?.pluginOptions,
1078
+ ...data.contentType.options
1079
+ }
1080
+ };
1081
+ };
1082
+ const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
1083
+ return columns.map((name) => {
1084
+ const attribute = attributes[name];
1085
+ if (!attribute) {
1086
+ return null;
1087
+ }
1088
+ const metadata = metadatas[name];
1089
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1090
+ return {
1091
+ attribute,
1092
+ label: metadata.label ?? "",
1093
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1094
+ schemas,
1095
+ components: components?.schemas ?? {}
1096
+ }),
1097
+ name,
1098
+ searchable: metadata.searchable ?? true,
1099
+ sortable: metadata.sortable ?? true
1100
+ };
1101
+ }).filter((field) => field !== null);
1102
+ };
1103
+ const useDocument = (args, opts) => {
1104
+ const { toggleNotification } = useNotification();
1105
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1106
+ const {
1107
+ currentData: data,
1108
+ isLoading: isLoadingDocument,
1109
+ isFetching: isFetchingDocument,
1110
+ error
1111
+ } = useGetDocumentQuery(args, {
1112
+ ...opts,
1113
+ skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
1114
+ });
1115
+ const {
1116
+ components,
1117
+ schema,
1118
+ schemas,
1119
+ isLoading: isLoadingSchema
1120
+ } = useContentTypeSchema(args.model);
1121
+ React.useEffect(() => {
1122
+ if (error) {
1123
+ toggleNotification({
1124
+ type: "danger",
1125
+ message: formatAPIError(error)
1126
+ });
1127
+ }
1128
+ }, [toggleNotification, error, formatAPIError, args.collectionType]);
1129
+ const validationSchema = React.useMemo(() => {
1130
+ if (!schema) {
1131
+ return null;
1132
+ }
1133
+ return createYupSchema(schema.attributes, components);
1134
+ }, [schema, components]);
1135
+ const validate = React.useCallback(
1136
+ (document) => {
1137
+ if (!validationSchema) {
1138
+ throw new Error(
1139
+ "There is no validation schema generated, this is likely due to the schema not being loaded yet."
1140
+ );
1141
+ }
1142
+ try {
1143
+ validationSchema.validateSync(document, { abortEarly: false, strict: true });
1144
+ return null;
1145
+ } catch (error2) {
1146
+ if (error2 instanceof ValidationError) {
1147
+ return getYupValidationErrors(error2);
1148
+ }
1149
+ throw error2;
1150
+ }
1151
+ },
1152
+ [validationSchema]
1153
+ );
1154
+ const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
1155
+ const hasError = !!error;
1156
+ return {
1157
+ components,
1158
+ document: data?.data,
1159
+ meta: data?.meta,
1160
+ isLoading,
1161
+ hasError,
1162
+ schema,
1163
+ schemas,
1164
+ validate
1165
+ };
1166
+ };
1167
+ const useDoc = () => {
1168
+ const { id, slug, collectionType, origin } = useParams();
1169
+ const [{ query }] = useQueryParams();
1170
+ const params = React.useMemo(() => buildValidParams(query), [query]);
1171
+ if (!collectionType) {
1172
+ throw new Error("Could not find collectionType in url params");
1173
+ }
1174
+ if (!slug) {
1175
+ throw new Error("Could not find model in url params");
1176
+ }
1177
+ const document = useDocument(
1178
+ { documentId: origin || id, model: slug, collectionType, params },
1179
+ {
1180
+ skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
1181
+ }
1182
+ );
1183
+ const returnId = origin || id === "create" ? void 0 : id;
821
1184
  return {
822
1185
  collectionType,
823
1186
  model: slug,
824
- id: origin || id === "create" ? void 0 : id,
825
- ...useDocument(
826
- { documentId: origin || id, model: slug, collectionType, params },
827
- {
828
- skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
829
- }
830
- )
1187
+ id: returnId,
1188
+ ...document
1189
+ };
1190
+ };
1191
+ const useContentManagerContext = () => {
1192
+ const {
1193
+ collectionType,
1194
+ model,
1195
+ id,
1196
+ components,
1197
+ isLoading: isLoadingDoc,
1198
+ schema,
1199
+ schemas
1200
+ } = useDoc();
1201
+ const layout = useDocumentLayout(model);
1202
+ const form = useForm("useContentManagerContext", (state) => state);
1203
+ const isSingleType = collectionType === SINGLE_TYPES;
1204
+ const slug = model;
1205
+ const isCreatingEntry = id === "create";
1206
+ useContentTypeSchema();
1207
+ const isLoading = isLoadingDoc || layout.isLoading;
1208
+ const error = layout.error;
1209
+ return {
1210
+ error,
1211
+ isLoading,
1212
+ // Base metadata
1213
+ model,
1214
+ collectionType,
1215
+ id,
1216
+ slug,
1217
+ isCreatingEntry,
1218
+ isSingleType,
1219
+ hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
1220
+ // All schema infos
1221
+ components,
1222
+ contentType: schema,
1223
+ contentTypes: schemas,
1224
+ // Form state
1225
+ form,
1226
+ // layout infos
1227
+ layout
831
1228
  };
832
1229
  };
833
1230
  const prefixPluginTranslations = (trad, pluginId) => {
@@ -849,6 +1246,8 @@ const useDocumentActions = () => {
849
1246
  const { formatMessage } = useIntl();
850
1247
  const { trackUsage } = useTracking();
851
1248
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1249
+ const navigate = useNavigate();
1250
+ const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
852
1251
  const [deleteDocument] = useDeleteDocumentMutation();
853
1252
  const _delete = React.useCallback(
854
1253
  async ({ collectionType, model, documentId, params }, trackerProperty) => {
@@ -927,12 +1326,13 @@ const useDocumentActions = () => {
927
1326
  );
928
1327
  const [discardDocument] = useDiscardDocumentMutation();
929
1328
  const discard = React.useCallback(
930
- async ({ collectionType, model, documentId }) => {
1329
+ async ({ collectionType, model, documentId, params }) => {
931
1330
  try {
932
1331
  const res = await discardDocument({
933
1332
  collectionType,
934
1333
  model,
935
- documentId
1334
+ documentId,
1335
+ params
936
1336
  });
937
1337
  if ("error" in res) {
938
1338
  toggleNotification({
@@ -1162,6 +1562,7 @@ const useDocumentActions = () => {
1162
1562
  defaultMessage: "Saved document"
1163
1563
  })
1164
1564
  });
1565
+ setCurrentStep("contentManager.success");
1165
1566
  return res.data;
1166
1567
  } catch (err) {
1167
1568
  toggleNotification({
@@ -1183,7 +1584,6 @@ const useDocumentActions = () => {
1183
1584
  sourceId
1184
1585
  });
1185
1586
  if ("error" in res) {
1186
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1187
1587
  return { error: res.error };
1188
1588
  }
1189
1589
  toggleNotification({
@@ -1202,7 +1602,7 @@ const useDocumentActions = () => {
1202
1602
  throw err;
1203
1603
  }
1204
1604
  },
1205
- [autoCloneDocument, formatAPIError, formatMessage, toggleNotification]
1605
+ [autoCloneDocument, formatMessage, toggleNotification]
1206
1606
  );
1207
1607
  const [cloneDocument] = useCloneDocumentMutation();
1208
1608
  const clone = React.useCallback(
@@ -1228,6 +1628,7 @@ const useDocumentActions = () => {
1228
1628
  defaultMessage: "Cloned document"
1229
1629
  })
1230
1630
  });
1631
+ navigate(`../../${res.data.data.documentId}`, { relative: "path" });
1231
1632
  return res.data;
1232
1633
  } catch (err) {
1233
1634
  toggleNotification({
@@ -1238,7 +1639,7 @@ const useDocumentActions = () => {
1238
1639
  throw err;
1239
1640
  }
1240
1641
  },
1241
- [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
1642
+ [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
1242
1643
  );
1243
1644
  const [getDoc] = useLazyGetDocumentQuery();
1244
1645
  const getDocument = React.useCallback(
@@ -1264,7 +1665,7 @@ const useDocumentActions = () => {
1264
1665
  };
1265
1666
  };
1266
1667
  const ProtectedHistoryPage = lazy(
1267
- () => import("./History-BZP8n7KT.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1668
+ () => import("./History-DRwA3oMM.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1268
1669
  );
1269
1670
  const routes$1 = [
1270
1671
  {
@@ -1277,31 +1678,31 @@ const routes$1 = [
1277
1678
  }
1278
1679
  ];
1279
1680
  const ProtectedEditViewPage = lazy(
1280
- () => import("./EditViewPage-DvaV7U9b.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1681
+ () => import("./EditViewPage-B82x_x1b.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1281
1682
  );
1282
1683
  const ProtectedListViewPage = lazy(
1283
- () => import("./ListViewPage-D5D3tVPq.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1684
+ () => import("./ListViewPage-CELx2ysp.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1284
1685
  );
1285
1686
  const ProtectedListConfiguration = lazy(
1286
- () => import("./ListConfigurationPage-DxKuVkKz.mjs").then((mod) => ({
1687
+ () => import("./ListConfigurationPage-BxfQJzPk.mjs").then((mod) => ({
1287
1688
  default: mod.ProtectedListConfiguration
1288
1689
  }))
1289
1690
  );
1290
1691
  const ProtectedEditConfigurationPage = lazy(
1291
- () => import("./EditConfigurationPage-DmCIb4kD.mjs").then((mod) => ({
1692
+ () => import("./EditConfigurationPage-DdPNAbl3.mjs").then((mod) => ({
1292
1693
  default: mod.ProtectedEditConfigurationPage
1293
1694
  }))
1294
1695
  );
1295
1696
  const ProtectedComponentConfigurationPage = lazy(
1296
- () => import("./ComponentConfigurationPage-CR5XdR33.mjs").then((mod) => ({
1697
+ () => import("./ComponentConfigurationPage-DfFSZQxe.mjs").then((mod) => ({
1297
1698
  default: mod.ProtectedComponentConfigurationPage
1298
1699
  }))
1299
1700
  );
1300
1701
  const NoPermissions = lazy(
1301
- () => import("./NoPermissionsPage-OyoME_Tf.mjs").then((mod) => ({ default: mod.NoPermissions }))
1702
+ () => import("./NoPermissionsPage-DWleVYK7.mjs").then((mod) => ({ default: mod.NoPermissions }))
1302
1703
  );
1303
1704
  const NoContentType = lazy(
1304
- () => import("./NoContentTypePage-DnMeuQCj.mjs").then((mod) => ({ default: mod.NoContentType }))
1705
+ () => import("./NoContentTypePage-DtJ9jcfk.mjs").then((mod) => ({ default: mod.NoContentType }))
1305
1706
  );
1306
1707
  const CollectionTypePages = () => {
1307
1708
  const { collectionType } = useParams();
@@ -1415,12 +1816,14 @@ const DocumentActionButton = (action) => {
1415
1816
  /* @__PURE__ */ jsx(
1416
1817
  Button,
1417
1818
  {
1418
- flex: 1,
1819
+ flex: "auto",
1419
1820
  startIcon: action.icon,
1420
1821
  disabled: action.disabled,
1421
1822
  onClick: handleClick(action),
1422
1823
  justifyContent: "center",
1423
1824
  variant: action.variant || "default",
1825
+ paddingTop: "7px",
1826
+ paddingBottom: "7px",
1424
1827
  children: action.label
1425
1828
  }
1426
1829
  ),
@@ -1428,7 +1831,7 @@ const DocumentActionButton = (action) => {
1428
1831
  DocumentActionConfirmDialog,
1429
1832
  {
1430
1833
  ...action.dialog,
1431
- variant: action.variant,
1834
+ variant: action.dialog?.variant ?? action.variant,
1432
1835
  isOpen: dialogId === action.id,
1433
1836
  onClose: handleClose
1434
1837
  }
@@ -1485,9 +1888,9 @@ const DocumentActionsMenu = ({
1485
1888
  disabled: isDisabled,
1486
1889
  size: "S",
1487
1890
  endIcon: null,
1488
- paddingTop: "7px",
1489
- paddingLeft: "9px",
1490
- paddingRight: "9px",
1891
+ paddingTop: "4px",
1892
+ paddingLeft: "7px",
1893
+ paddingRight: "7px",
1491
1894
  variant,
1492
1895
  children: [
1493
1896
  /* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
@@ -1498,7 +1901,7 @@ const DocumentActionsMenu = ({
1498
1901
  ]
1499
1902
  }
1500
1903
  ),
1501
- /* @__PURE__ */ jsxs(Menu.Content, { top: "4px", maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1904
+ /* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1502
1905
  actions2.map((action) => {
1503
1906
  return /* @__PURE__ */ jsx(
1504
1907
  Menu.Item,
@@ -1507,10 +1910,25 @@ const DocumentActionsMenu = ({
1507
1910
  onSelect: handleClick(action),
1508
1911
  display: "block",
1509
1912
  children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
1510
- /* @__PURE__ */ jsxs(Flex, { color: convertActionVariantToColor(action.variant), gap: 2, tag: "span", children: [
1511
- action.icon,
1512
- action.label
1513
- ] }),
1913
+ /* @__PURE__ */ jsxs(
1914
+ Flex,
1915
+ {
1916
+ color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
1917
+ gap: 2,
1918
+ tag: "span",
1919
+ children: [
1920
+ /* @__PURE__ */ jsx(
1921
+ Flex,
1922
+ {
1923
+ tag: "span",
1924
+ color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
1925
+ children: action.icon
1926
+ }
1927
+ ),
1928
+ action.label
1929
+ ]
1930
+ }
1931
+ ),
1514
1932
  action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
1515
1933
  Flex,
1516
1934
  {
@@ -1569,15 +1987,27 @@ const convertActionVariantToColor = (variant = "secondary") => {
1569
1987
  return "primary600";
1570
1988
  }
1571
1989
  };
1572
- const DocumentActionConfirmDialog = ({
1573
- onClose,
1574
- onCancel,
1575
- onConfirm,
1576
- title,
1577
- content,
1578
- isOpen,
1579
- variant = "secondary"
1580
- }) => {
1990
+ const convertActionVariantToIconColor = (variant = "secondary") => {
1991
+ switch (variant) {
1992
+ case "danger":
1993
+ return "danger600";
1994
+ case "secondary":
1995
+ return "neutral500";
1996
+ case "success":
1997
+ return "success600";
1998
+ default:
1999
+ return "primary600";
2000
+ }
2001
+ };
2002
+ const DocumentActionConfirmDialog = ({
2003
+ onClose,
2004
+ onCancel,
2005
+ onConfirm,
2006
+ title,
2007
+ content,
2008
+ isOpen,
2009
+ variant = "secondary"
2010
+ }) => {
1581
2011
  const { formatMessage } = useIntl();
1582
2012
  const handleClose = async () => {
1583
2013
  if (onCancel) {
@@ -1591,22 +2021,20 @@ const DocumentActionConfirmDialog = ({
1591
2021
  }
1592
2022
  onClose();
1593
2023
  };
1594
- return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
1595
- /* @__PURE__ */ jsx(DialogBody, { children: content }),
1596
- /* @__PURE__ */ jsx(
1597
- DialogFooter,
1598
- {
1599
- startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
1600
- id: "app.components.Button.cancel",
1601
- defaultMessage: "Cancel"
1602
- }) }),
1603
- endAction: /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, children: formatMessage({
1604
- id: "app.components.Button.confirm",
1605
- defaultMessage: "Confirm"
1606
- }) })
1607
- }
1608
- )
1609
- ] });
2024
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2025
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2026
+ /* @__PURE__ */ jsx(Dialog.Body, { children: content }),
2027
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
2028
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
2029
+ id: "app.components.Button.cancel",
2030
+ defaultMessage: "Cancel"
2031
+ }) }) }),
2032
+ /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
2033
+ id: "app.components.Button.confirm",
2034
+ defaultMessage: "Confirm"
2035
+ }) })
2036
+ ] })
2037
+ ] }) });
1610
2038
  };
1611
2039
  const DocumentActionModal = ({
1612
2040
  isOpen,
@@ -1616,34 +2044,17 @@ const DocumentActionModal = ({
1616
2044
  content: Content,
1617
2045
  onModalClose
1618
2046
  }) => {
1619
- const id = React.useId();
1620
- if (!isOpen) {
1621
- return null;
1622
- }
1623
2047
  const handleClose = () => {
1624
2048
  if (onClose) {
1625
2049
  onClose();
1626
2050
  }
1627
2051
  onModalClose();
1628
2052
  };
1629
- return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
1630
- /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id, children: title }) }),
1631
- /* @__PURE__ */ jsx(ModalBody, { children: typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content }),
1632
- /* @__PURE__ */ jsx(
1633
- Box,
1634
- {
1635
- paddingTop: 4,
1636
- paddingBottom: 4,
1637
- paddingLeft: 5,
1638
- paddingRight: 5,
1639
- borderWidth: "1px 0 0 0",
1640
- borderStyle: "solid",
1641
- borderColor: "neutral150",
1642
- background: "neutral100",
1643
- children: typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
1644
- }
1645
- )
1646
- ] });
2053
+ return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
2054
+ /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
2055
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
2056
+ typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
2057
+ ] }) });
1647
2058
  };
1648
2059
  const PublishAction$1 = ({
1649
2060
  activeTab,
@@ -1657,13 +2068,17 @@ const PublishAction$1 = ({
1657
2068
  const navigate = useNavigate();
1658
2069
  const { toggleNotification } = useNotification();
1659
2070
  const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
2071
+ const isListView = useMatch(LIST_PATH) !== null;
1660
2072
  const isCloning = useMatch(CLONE_PATH) !== null;
1661
2073
  const { formatMessage } = useIntl();
1662
- const { canPublish, canCreate, canUpdate } = useDocumentRBAC(
1663
- "PublishAction",
1664
- ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
1665
- );
2074
+ const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
1666
2075
  const { publish } = useDocumentActions();
2076
+ const [
2077
+ countDraftRelations,
2078
+ { isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
2079
+ ] = useLazyGetDraftRelationCountQuery();
2080
+ const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
2081
+ const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
1667
2082
  const [{ query, rawQuery }] = useQueryParams();
1668
2083
  const params = React.useMemo(() => buildValidParams(query), [query]);
1669
2084
  const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
@@ -1672,10 +2087,105 @@ const PublishAction$1 = ({
1672
2087
  const validate = useForm("PublishAction", (state) => state.validate);
1673
2088
  const setErrors = useForm("PublishAction", (state) => state.setErrors);
1674
2089
  const formValues = useForm("PublishAction", ({ values }) => values);
2090
+ React.useEffect(() => {
2091
+ if (isErrorDraftRelations) {
2092
+ toggleNotification({
2093
+ type: "danger",
2094
+ message: formatMessage({
2095
+ id: getTranslation("error.records.fetch-draft-relatons"),
2096
+ defaultMessage: "An error occurred while fetching draft relations on this document."
2097
+ })
2098
+ });
2099
+ }
2100
+ }, [isErrorDraftRelations, toggleNotification, formatMessage]);
2101
+ React.useEffect(() => {
2102
+ const localDraftRelations = /* @__PURE__ */ new Set();
2103
+ const extractDraftRelations = (data) => {
2104
+ const relations = data.connect || [];
2105
+ relations.forEach((relation) => {
2106
+ if (relation.status === "draft") {
2107
+ localDraftRelations.add(relation.id);
2108
+ }
2109
+ });
2110
+ };
2111
+ const traverseAndExtract = (data) => {
2112
+ Object.entries(data).forEach(([key, value]) => {
2113
+ if (key === "connect" && Array.isArray(value)) {
2114
+ extractDraftRelations({ connect: value });
2115
+ } else if (typeof value === "object" && value !== null) {
2116
+ traverseAndExtract(value);
2117
+ }
2118
+ });
2119
+ };
2120
+ if (!documentId || modified) {
2121
+ traverseAndExtract(formValues);
2122
+ setLocalCountOfDraftRelations(localDraftRelations.size);
2123
+ }
2124
+ }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
2125
+ React.useEffect(() => {
2126
+ if (!document || !document.documentId || isListView) {
2127
+ return;
2128
+ }
2129
+ const fetchDraftRelationsCount = async () => {
2130
+ const { data, error } = await countDraftRelations({
2131
+ collectionType,
2132
+ model,
2133
+ documentId,
2134
+ params
2135
+ });
2136
+ if (error) {
2137
+ throw error;
2138
+ }
2139
+ if (data) {
2140
+ setServerCountOfDraftRelations(data.data);
2141
+ }
2142
+ };
2143
+ fetchDraftRelationsCount();
2144
+ }, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
1675
2145
  const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
1676
2146
  if (!schema?.options?.draftAndPublish) {
1677
2147
  return null;
1678
2148
  }
2149
+ const performPublish = async () => {
2150
+ setSubmitting(true);
2151
+ try {
2152
+ const { errors } = await validate(true, {
2153
+ status: "published"
2154
+ });
2155
+ if (errors) {
2156
+ toggleNotification({
2157
+ type: "danger",
2158
+ message: formatMessage({
2159
+ id: "content-manager.validation.error",
2160
+ defaultMessage: "There are validation errors in your document. Please fix them before saving."
2161
+ })
2162
+ });
2163
+ return;
2164
+ }
2165
+ const res = await publish(
2166
+ {
2167
+ collectionType,
2168
+ model,
2169
+ documentId,
2170
+ params
2171
+ },
2172
+ formValues
2173
+ );
2174
+ if ("data" in res && collectionType !== SINGLE_TYPES) {
2175
+ navigate({
2176
+ pathname: `../${collectionType}/${model}/${res.data.documentId}`,
2177
+ search: rawQuery
2178
+ });
2179
+ } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2180
+ setErrors(formatValidationErrors(res.error));
2181
+ }
2182
+ } finally {
2183
+ setSubmitting(false);
2184
+ }
2185
+ };
2186
+ const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
2187
+ const enableDraftRelationsCount = false;
2188
+ const hasDraftRelations = enableDraftRelationsCount;
1679
2189
  return {
1680
2190
  /**
1681
2191
  * Disabled when:
@@ -1685,49 +2195,36 @@ const PublishAction$1 = ({
1685
2195
  * - the document is already published & not modified
1686
2196
  * - the document is being created & not modified
1687
2197
  * - the user doesn't have the permission to publish
1688
- * - the user doesn't have the permission to create a new document
1689
- * - the user doesn't have the permission to update the document
1690
2198
  */
1691
- disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish || Boolean(!document?.documentId && !canCreate || document?.documentId && !canUpdate),
2199
+ disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
1692
2200
  label: formatMessage({
1693
2201
  id: "app.utils.publish",
1694
2202
  defaultMessage: "Publish"
1695
2203
  }),
1696
2204
  onClick: async () => {
1697
- setSubmitting(true);
1698
- try {
1699
- const { errors } = await validate();
1700
- if (errors) {
1701
- toggleNotification({
1702
- type: "danger",
1703
- message: formatMessage({
1704
- id: "content-manager.validation.error",
1705
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
1706
- })
1707
- });
1708
- return;
1709
- }
1710
- const res = await publish(
1711
- {
1712
- collectionType,
1713
- model,
1714
- documentId,
1715
- params
1716
- },
1717
- formValues
1718
- );
1719
- if ("data" in res && collectionType !== SINGLE_TYPES) {
1720
- navigate({
1721
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1722
- search: rawQuery
1723
- });
1724
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1725
- setErrors(formatValidationErrors(res.error));
2205
+ await performPublish();
2206
+ },
2207
+ dialog: hasDraftRelations ? {
2208
+ type: "dialog",
2209
+ variant: "danger",
2210
+ footer: null,
2211
+ title: formatMessage({
2212
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
2213
+ defaultMessage: "Confirmation"
2214
+ }),
2215
+ content: formatMessage(
2216
+ {
2217
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
2218
+ defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
2219
+ },
2220
+ {
2221
+ count: totalDraftRelations
1726
2222
  }
1727
- } finally {
1728
- setSubmitting(false);
2223
+ ),
2224
+ onConfirm: async () => {
2225
+ await performPublish();
1729
2226
  }
1730
- }
2227
+ } : void 0
1731
2228
  };
1732
2229
  };
1733
2230
  PublishAction$1.type = "publish";
@@ -1743,10 +2240,6 @@ const UpdateAction = ({
1743
2240
  const cloneMatch = useMatch(CLONE_PATH);
1744
2241
  const isCloning = cloneMatch !== null;
1745
2242
  const { formatMessage } = useIntl();
1746
- const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
1747
- canCreate: canCreate2,
1748
- canUpdate: canUpdate2
1749
- }));
1750
2243
  const { create, update, clone } = useDocumentActions();
1751
2244
  const [{ query, rawQuery }] = useQueryParams();
1752
2245
  const params = React.useMemo(() => buildValidParams(query), [query]);
@@ -1763,10 +2256,8 @@ const UpdateAction = ({
1763
2256
  * - the form is submitting
1764
2257
  * - the document is not modified & we're not cloning (you can save a clone entity straight away)
1765
2258
  * - the active tab is the published tab
1766
- * - the user doesn't have the permission to create a new document
1767
- * - the user doesn't have the permission to update the document
1768
2259
  */
1769
- disabled: isSubmitting || !modified && !isCloning || activeTab === "published" || Boolean(!documentId && !canCreate || documentId && !canUpdate),
2260
+ disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
1770
2261
  label: formatMessage({
1771
2262
  id: "content-manager.containers.Edit.save",
1772
2263
  defaultMessage: "Save"
@@ -1774,7 +2265,9 @@ const UpdateAction = ({
1774
2265
  onClick: async () => {
1775
2266
  setSubmitting(true);
1776
2267
  try {
1777
- const { errors } = await validate();
2268
+ const { errors } = await validate(true, {
2269
+ status: "draft"
2270
+ });
1778
2271
  if (errors) {
1779
2272
  toggleNotification({
1780
2273
  type: "danger",
@@ -1795,10 +2288,13 @@ const UpdateAction = ({
1795
2288
  document
1796
2289
  );
1797
2290
  if ("data" in res) {
1798
- navigate({
1799
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1800
- search: rawQuery
1801
- });
2291
+ navigate(
2292
+ {
2293
+ pathname: `../${res.data.documentId}`,
2294
+ search: rawQuery
2295
+ },
2296
+ { relative: "path" }
2297
+ );
1802
2298
  } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1803
2299
  setErrors(formatValidationErrors(res.error));
1804
2300
  }
@@ -1826,10 +2322,13 @@ const UpdateAction = ({
1826
2322
  document
1827
2323
  );
1828
2324
  if ("data" in res && collectionType !== SINGLE_TYPES) {
1829
- navigate({
1830
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1831
- search: rawQuery
1832
- });
2325
+ navigate(
2326
+ {
2327
+ pathname: `../${res.data.documentId}`,
2328
+ search: rawQuery
2329
+ },
2330
+ { replace: true, relative: "path" }
2331
+ );
1833
2332
  } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1834
2333
  setErrors(formatValidationErrors(res.error));
1835
2334
  }
@@ -1861,10 +2360,8 @@ const UnpublishAction$1 = ({
1861
2360
  const { toggleNotification } = useNotification();
1862
2361
  const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
1863
2362
  const isDocumentModified = document?.status === "modified";
1864
- const handleChange = (e) => {
1865
- if ("value" in e.target) {
1866
- setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
1867
- }
2363
+ const handleChange = (value) => {
2364
+ setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
1868
2365
  };
1869
2366
  if (!schema?.options?.draftAndPublish) {
1870
2367
  return null;
@@ -1875,7 +2372,7 @@ const UnpublishAction$1 = ({
1875
2372
  id: "app.utils.unpublish",
1876
2373
  defaultMessage: "Unpublish"
1877
2374
  }),
1878
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2375
+ icon: /* @__PURE__ */ jsx(Cross, {}),
1879
2376
  onClick: async () => {
1880
2377
  if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
1881
2378
  if (!documentId) {
@@ -1914,40 +2411,24 @@ const UnpublishAction$1 = ({
1914
2411
  }) })
1915
2412
  ] }),
1916
2413
  /* @__PURE__ */ jsxs(
1917
- Flex,
2414
+ Radio.Group,
1918
2415
  {
1919
- onChange: handleChange,
1920
- direction: "column",
1921
- alignItems: "flex-start",
1922
- tag: "fieldset",
1923
- borderWidth: 0,
1924
- gap: 3,
2416
+ defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
2417
+ name: "discard-options",
2418
+ "aria-label": formatMessage({
2419
+ id: "content-manager.actions.unpublish.dialog.radio-label",
2420
+ defaultMessage: "Choose an option to unpublish the document."
2421
+ }),
2422
+ onValueChange: handleChange,
1925
2423
  children: [
1926
- /* @__PURE__ */ jsx(VisuallyHidden, { tag: "legend" }),
1927
- /* @__PURE__ */ jsx(
1928
- Radio,
1929
- {
1930
- checked: shouldKeepDraft,
1931
- value: UNPUBLISH_DRAFT_OPTIONS.KEEP,
1932
- name: "discard-options",
1933
- children: formatMessage({
1934
- id: "content-manager.actions.unpublish.dialog.option.keep-draft",
1935
- defaultMessage: "Keep draft"
1936
- })
1937
- }
1938
- ),
1939
- /* @__PURE__ */ jsx(
1940
- Radio,
1941
- {
1942
- checked: !shouldKeepDraft,
1943
- value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
1944
- name: "discard-options",
1945
- children: formatMessage({
1946
- id: "content-manager.actions.unpublish.dialog.option.replace-draft",
1947
- defaultMessage: "Replace draft"
1948
- })
1949
- }
1950
- )
2424
+ /* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
2425
+ id: "content-manager.actions.unpublish.dialog.option.keep-draft",
2426
+ defaultMessage: "Keep draft"
2427
+ }) }),
2428
+ /* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
2429
+ id: "content-manager.actions.unpublish.dialog.option.replace-draft",
2430
+ defaultMessage: "Replace draft"
2431
+ }) })
1951
2432
  ]
1952
2433
  }
1953
2434
  )
@@ -2003,7 +2484,7 @@ const DiscardAction = ({
2003
2484
  id: "content-manager.actions.discard.label",
2004
2485
  defaultMessage: "Discard changes"
2005
2486
  }),
2006
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2487
+ icon: /* @__PURE__ */ jsx(Cross, {}),
2007
2488
  position: ["panel", "table-row"],
2008
2489
  variant: "danger",
2009
2490
  dialog: {
@@ -2031,11 +2512,6 @@ const DiscardAction = ({
2031
2512
  };
2032
2513
  };
2033
2514
  DiscardAction.type = "discard";
2034
- const StyledCrossCircle = styled(CrossCircle)`
2035
- path {
2036
- fill: currentColor;
2037
- }
2038
- `;
2039
2515
  const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
2040
2516
  const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
2041
2517
  const RelativeTime = React.forwardRef(
@@ -2083,7 +2559,7 @@ const getDisplayName = ({
2083
2559
  };
2084
2560
  const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2085
2561
  const DocumentStatus = ({ status = "draft", ...restProps }) => {
2086
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
2562
+ const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
2087
2563
  return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
2088
2564
  };
2089
2565
  const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
@@ -2093,23 +2569,13 @@ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
2093
2569
  id: "content-manager.containers.edit.title.new",
2094
2570
  defaultMessage: "Create an entry"
2095
2571
  }) : documentTitle;
2096
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 8, paddingBottom: 4, gap: 3, children: [
2572
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
2097
2573
  /* @__PURE__ */ jsx(BackButton, {}),
2098
- /* @__PURE__ */ jsxs(
2099
- Flex,
2100
- {
2101
- width: "100%",
2102
- justifyContent: "space-between",
2103
- paddingTop: 1,
2104
- gap: "80px",
2105
- alignItems: "flex-start",
2106
- children: [
2107
- /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
2108
- /* @__PURE__ */ jsx(HeaderToolbar, {})
2109
- ]
2110
- }
2111
- ),
2112
- status ? /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
2574
+ /* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
2575
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
2576
+ /* @__PURE__ */ jsx(HeaderToolbar, {})
2577
+ ] }),
2578
+ status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
2113
2579
  ] });
2114
2580
  };
2115
2581
  const HeaderToolbar = () => {
@@ -2192,12 +2658,12 @@ const Information = ({ activeTab }) => {
2192
2658
  isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
2193
2659
  label: formatMessage({
2194
2660
  id: "content-manager.containers.edit.information.last-published.label",
2195
- defaultMessage: "Last published"
2661
+ defaultMessage: "Published"
2196
2662
  }),
2197
2663
  value: formatMessage(
2198
2664
  {
2199
2665
  id: "content-manager.containers.edit.information.last-published.value",
2200
- defaultMessage: `Published {time}{isAnonymous, select, true {} other { by {author}}}`
2666
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2201
2667
  },
2202
2668
  {
2203
2669
  time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
@@ -2210,12 +2676,12 @@ const Information = ({ activeTab }) => {
2210
2676
  isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
2211
2677
  label: formatMessage({
2212
2678
  id: "content-manager.containers.edit.information.last-draft.label",
2213
- defaultMessage: "Last draft"
2679
+ defaultMessage: "Updated"
2214
2680
  }),
2215
2681
  value: formatMessage(
2216
2682
  {
2217
2683
  id: "content-manager.containers.edit.information.last-draft.value",
2218
- defaultMessage: `Modified {time}{isAnonymous, select, true {} other { by {author}}}`
2684
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2219
2685
  },
2220
2686
  {
2221
2687
  time: /* @__PURE__ */ jsx(
@@ -2233,12 +2699,12 @@ const Information = ({ activeTab }) => {
2233
2699
  isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
2234
2700
  label: formatMessage({
2235
2701
  id: "content-manager.containers.edit.information.document.label",
2236
- defaultMessage: "Document"
2702
+ defaultMessage: "Created"
2237
2703
  }),
2238
2704
  value: formatMessage(
2239
2705
  {
2240
2706
  id: "content-manager.containers.edit.information.document.value",
2241
- defaultMessage: `Created {time}{isAnonymous, select, true {} other { by {author}}}`
2707
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2242
2708
  },
2243
2709
  {
2244
2710
  time: /* @__PURE__ */ jsx(
@@ -2276,25 +2742,77 @@ const Information = ({ activeTab }) => {
2276
2742
  );
2277
2743
  };
2278
2744
  const HeaderActions = ({ actions: actions2 }) => {
2279
- return /* @__PURE__ */ jsx(Flex, { children: actions2.map((action) => {
2280
- if ("options" in action) {
2745
+ const [dialogId, setDialogId] = React.useState(null);
2746
+ const handleClick = (action) => async (e) => {
2747
+ if (!("options" in action)) {
2748
+ const { onClick = () => false, dialog, id } = action;
2749
+ const muteDialog = await onClick(e);
2750
+ if (dialog && !muteDialog) {
2751
+ e.preventDefault();
2752
+ setDialogId(id);
2753
+ }
2754
+ }
2755
+ };
2756
+ const handleClose = () => {
2757
+ setDialogId(null);
2758
+ };
2759
+ return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
2760
+ if (action.options) {
2281
2761
  return /* @__PURE__ */ jsx(
2282
2762
  SingleSelect,
2283
2763
  {
2284
2764
  size: "S",
2285
- disabled: action.disabled,
2286
- "aria-label": action.label,
2287
2765
  onChange: action.onSelect,
2288
- value: action.value,
2766
+ "aria-label": action.label,
2767
+ ...action,
2289
2768
  children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
2290
2769
  },
2291
2770
  action.id
2292
2771
  );
2293
2772
  } else {
2294
- return null;
2773
+ if (action.type === "icon") {
2774
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2775
+ /* @__PURE__ */ jsx(
2776
+ IconButton,
2777
+ {
2778
+ disabled: action.disabled,
2779
+ label: action.label,
2780
+ size: "S",
2781
+ onClick: handleClick(action),
2782
+ children: action.icon
2783
+ }
2784
+ ),
2785
+ action.dialog ? /* @__PURE__ */ jsx(
2786
+ HeaderActionDialog,
2787
+ {
2788
+ ...action.dialog,
2789
+ isOpen: dialogId === action.id,
2790
+ onClose: handleClose
2791
+ }
2792
+ ) : null
2793
+ ] }, action.id);
2794
+ }
2295
2795
  }
2296
2796
  }) });
2297
2797
  };
2798
+ const HeaderActionDialog = ({
2799
+ onClose,
2800
+ onCancel,
2801
+ title,
2802
+ content: Content,
2803
+ isOpen
2804
+ }) => {
2805
+ const handleClose = async () => {
2806
+ if (onCancel) {
2807
+ await onCancel();
2808
+ }
2809
+ onClose();
2810
+ };
2811
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2812
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2813
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
2814
+ ] }) });
2815
+ };
2298
2816
  const ConfigureTheViewAction = ({ collectionType, model }) => {
2299
2817
  const navigate = useNavigate();
2300
2818
  const { formatMessage } = useIntl();
@@ -2335,12 +2853,16 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2335
2853
  const { delete: deleteAction } = useDocumentActions();
2336
2854
  const { toggleNotification } = useNotification();
2337
2855
  const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
2856
+ const isLocalized = document?.locale != null;
2338
2857
  return {
2339
2858
  disabled: !canDelete || !document,
2340
- label: formatMessage({
2341
- id: "content-manager.actions.delete.label",
2342
- defaultMessage: "Delete document"
2343
- }),
2859
+ label: formatMessage(
2860
+ {
2861
+ id: "content-manager.actions.delete.label",
2862
+ defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
2863
+ },
2864
+ { isLocalized }
2865
+ ),
2344
2866
  icon: /* @__PURE__ */ jsx(Trash, {}),
2345
2867
  dialog: {
2346
2868
  type: "dialog",
@@ -2430,7 +2952,7 @@ const ActionsPanel = () => {
2430
2952
  return {
2431
2953
  title: formatMessage({
2432
2954
  id: "content-manager.containers.edit.panels.default.title",
2433
- defaultMessage: "Document"
2955
+ defaultMessage: "Entry"
2434
2956
  }),
2435
2957
  content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
2436
2958
  };
@@ -2439,360 +2961,58 @@ ActionsPanel.type = "actions";
2439
2961
  const ActionsPanelContent = () => {
2440
2962
  const isCloning = useMatch(CLONE_PATH) !== null;
2441
2963
  const [
2442
- {
2443
- query: { status = "draft" }
2444
- }
2445
- ] = useQueryParams();
2446
- const { model, id, document, meta, collectionType } = useDoc();
2447
- const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
2448
- const props = {
2449
- activeTab: status,
2450
- model,
2451
- documentId: id,
2452
- document: isCloning ? void 0 : document,
2453
- meta: isCloning ? void 0 : meta,
2454
- collectionType
2455
- };
2456
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
2457
- /* @__PURE__ */ jsx(
2458
- DescriptionComponentRenderer,
2459
- {
2460
- props,
2461
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
2462
- children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
2463
- }
2464
- ),
2465
- /* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
2466
- ] });
2467
- };
2468
- const Panel = React.forwardRef(({ children, title }, ref) => {
2469
- return /* @__PURE__ */ jsxs(
2470
- Flex,
2471
- {
2472
- ref,
2473
- tag: "aside",
2474
- "aria-labelledby": "additional-information",
2475
- background: "neutral0",
2476
- borderColor: "neutral150",
2477
- hasRadius: true,
2478
- paddingBottom: 4,
2479
- paddingLeft: 4,
2480
- paddingRight: 4,
2481
- paddingTop: 4,
2482
- shadow: "tableShadow",
2483
- gap: 3,
2484
- direction: "column",
2485
- justifyContent: "stretch",
2486
- alignItems: "flex-start",
2487
- children: [
2488
- /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
2489
- children
2490
- ]
2491
- }
2492
- );
2493
- });
2494
- const HOOKS = {
2495
- /**
2496
- * Hook that allows to mutate the displayed headers of the list view table
2497
- * @constant
2498
- * @type {string}
2499
- */
2500
- INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
2501
- /**
2502
- * Hook that allows to mutate the CM's collection types links pre-set filters
2503
- * @constant
2504
- * @type {string}
2505
- */
2506
- MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
2507
- /**
2508
- * Hook that allows to mutate the CM's edit view layout
2509
- * @constant
2510
- * @type {string}
2511
- */
2512
- MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
2513
- /**
2514
- * Hook that allows to mutate the CM's single types links pre-set filters
2515
- * @constant
2516
- * @type {string}
2517
- */
2518
- MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
2519
- };
2520
- const contentTypesApi = contentManagerApi.injectEndpoints({
2521
- endpoints: (builder) => ({
2522
- getContentTypeConfiguration: builder.query({
2523
- query: (uid) => ({
2524
- url: `/content-manager/content-types/${uid}/configuration`,
2525
- method: "GET"
2526
- }),
2527
- transformResponse: (response) => response.data,
2528
- providesTags: (_result, _error, uid) => [
2529
- { type: "ContentTypesConfiguration", id: uid },
2530
- { type: "ContentTypeSettings", id: "LIST" }
2531
- ]
2532
- }),
2533
- getAllContentTypeSettings: builder.query({
2534
- query: () => "/content-manager/content-types-settings",
2535
- transformResponse: (response) => response.data,
2536
- providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
2537
- }),
2538
- updateContentTypeConfiguration: builder.mutation({
2539
- query: ({ uid, ...body }) => ({
2540
- url: `/content-manager/content-types/${uid}/configuration`,
2541
- method: "PUT",
2542
- data: body
2543
- }),
2544
- transformResponse: (response) => response.data,
2545
- invalidatesTags: (_result, _error, { uid }) => [
2546
- { type: "ContentTypesConfiguration", id: uid },
2547
- { type: "ContentTypeSettings", id: "LIST" },
2548
- // Is this necessary?
2549
- { type: "InitialData" }
2550
- ]
2551
- })
2552
- })
2553
- });
2554
- const {
2555
- useGetContentTypeConfigurationQuery,
2556
- useGetAllContentTypeSettingsQuery,
2557
- useUpdateContentTypeConfigurationMutation
2558
- } = contentTypesApi;
2559
- const checkIfAttributeIsDisplayable = (attribute) => {
2560
- const { type } = attribute;
2561
- if (type === "relation") {
2562
- return !attribute.relation.toLowerCase().includes("morph");
2563
- }
2564
- return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
2565
- };
2566
- const getMainField = (attribute, mainFieldName, { schemas, components }) => {
2567
- if (!mainFieldName) {
2568
- return void 0;
2569
- }
2570
- const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
2571
- // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
2572
- schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
2573
- );
2574
- return {
2575
- name: mainFieldName,
2576
- type: mainFieldType ?? "string"
2577
- };
2578
- };
2579
- const DEFAULT_SETTINGS = {
2580
- bulkable: false,
2581
- filterable: false,
2582
- searchable: false,
2583
- pagination: false,
2584
- defaultSortBy: "",
2585
- defaultSortOrder: "asc",
2586
- mainField: "id",
2587
- pageSize: 10
2588
- };
2589
- const useDocumentLayout = (model) => {
2590
- const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
2591
- const [{ query }] = useQueryParams();
2592
- const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
2593
- const { toggleNotification } = useNotification();
2594
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
2595
- const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
2596
- const {
2597
- data,
2598
- isLoading: isLoadingConfigs,
2599
- error,
2600
- isFetching: isFetchingConfigs
2601
- } = useGetContentTypeConfigurationQuery(model);
2602
- const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
2603
- React.useEffect(() => {
2604
- if (error) {
2605
- toggleNotification({
2606
- type: "danger",
2607
- message: formatAPIError(error)
2608
- });
2609
- }
2610
- }, [error, formatAPIError, toggleNotification]);
2611
- const editLayout = React.useMemo(
2612
- () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
2613
- layout: [],
2614
- components: {},
2615
- metadatas: {},
2616
- options: {},
2617
- settings: DEFAULT_SETTINGS
2618
- },
2619
- [data, isLoading, schemas, schema, components]
2620
- );
2621
- const listLayout = React.useMemo(() => {
2622
- return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
2623
- layout: [],
2624
- metadatas: {},
2625
- options: {},
2626
- settings: DEFAULT_SETTINGS
2627
- };
2628
- }, [data, isLoading, schemas, schema, components]);
2629
- const { layout: edit } = React.useMemo(
2630
- () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
2631
- layout: editLayout,
2632
- query
2633
- }),
2634
- [editLayout, query, runHookWaterfall]
2635
- );
2636
- return {
2637
- error,
2638
- isLoading,
2639
- edit,
2640
- list: listLayout
2641
- };
2642
- };
2643
- const useDocLayout = () => {
2644
- const { model } = useDoc();
2645
- return useDocumentLayout(model);
2646
- };
2647
- const formatEditLayout = (data, {
2648
- schemas,
2649
- schema,
2650
- components
2651
- }) => {
2652
- let currentPanelIndex = 0;
2653
- const panelledEditAttributes = convertEditLayoutToFieldLayouts(
2654
- data.contentType.layouts.edit,
2655
- schema?.attributes,
2656
- data.contentType.metadatas,
2657
- { configurations: data.components, schemas: components },
2658
- schemas
2659
- ).reduce((panels, row) => {
2660
- if (row.some((field) => field.type === "dynamiczone")) {
2661
- panels.push([row]);
2662
- currentPanelIndex += 2;
2663
- } else {
2664
- if (!panels[currentPanelIndex]) {
2665
- panels.push([]);
2666
- }
2667
- panels[currentPanelIndex].push(row);
2668
- }
2669
- return panels;
2670
- }, []);
2671
- const componentEditAttributes = Object.entries(data.components).reduce(
2672
- (acc, [uid, configuration]) => {
2673
- acc[uid] = {
2674
- layout: convertEditLayoutToFieldLayouts(
2675
- configuration.layouts.edit,
2676
- components[uid].attributes,
2677
- configuration.metadatas
2678
- ),
2679
- settings: {
2680
- ...configuration.settings,
2681
- icon: components[uid].info.icon,
2682
- displayName: components[uid].info.displayName
2683
- }
2684
- };
2685
- return acc;
2686
- },
2687
- {}
2688
- );
2689
- const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
2690
- (acc, [attribute, metadata]) => {
2691
- return {
2692
- ...acc,
2693
- [attribute]: metadata.edit
2694
- };
2695
- },
2696
- {}
2697
- );
2698
- return {
2699
- layout: panelledEditAttributes,
2700
- components: componentEditAttributes,
2701
- metadatas: editMetadatas,
2702
- settings: {
2703
- ...data.contentType.settings,
2704
- displayName: schema?.info.displayName
2705
- },
2706
- options: {
2707
- ...schema?.options,
2708
- ...schema?.pluginOptions,
2709
- ...data.contentType.options
2710
- }
2711
- };
2712
- };
2713
- const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
2714
- return rows.map(
2715
- (row) => row.map((field) => {
2716
- const attribute = attributes[field.name];
2717
- if (!attribute) {
2718
- return null;
2719
- }
2720
- const { edit: metadata } = metadatas[field.name];
2721
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
2722
- return {
2723
- attribute,
2724
- disabled: !metadata.editable,
2725
- hint: metadata.description,
2726
- label: metadata.label ?? "",
2727
- name: field.name,
2728
- // @ts-expect-error – mainField does exist on the metadata for a relation.
2729
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
2730
- schemas,
2731
- components: components?.schemas ?? {}
2732
- }),
2733
- placeholder: metadata.placeholder ?? "",
2734
- required: attribute.required ?? false,
2735
- size: field.size,
2736
- unique: "unique" in attribute ? attribute.unique : false,
2737
- visible: metadata.visible ?? true,
2738
- type: attribute.type
2739
- };
2740
- }).filter((field) => field !== null)
2741
- );
2742
- };
2743
- const formatListLayout = (data, {
2744
- schemas,
2745
- schema,
2746
- components
2747
- }) => {
2748
- const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
2749
- (acc, [attribute, metadata]) => {
2750
- return {
2751
- ...acc,
2752
- [attribute]: metadata.list
2753
- };
2754
- },
2755
- {}
2756
- );
2757
- const listAttributes = convertListLayoutToFieldLayouts(
2758
- data.contentType.layouts.list,
2759
- schema?.attributes,
2760
- listMetadatas,
2761
- { configurations: data.components, schemas: components },
2762
- schemas
2763
- );
2764
- return {
2765
- layout: listAttributes,
2766
- settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
2767
- metadatas: listMetadatas,
2768
- options: {
2769
- ...schema?.options,
2770
- ...schema?.pluginOptions,
2771
- ...data.contentType.options
2964
+ {
2965
+ query: { status = "draft" }
2772
2966
  }
2967
+ ] = useQueryParams();
2968
+ const { model, id, document, meta, collectionType } = useDoc();
2969
+ const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
2970
+ const props = {
2971
+ activeTab: status,
2972
+ model,
2973
+ documentId: id,
2974
+ document: isCloning ? void 0 : document,
2975
+ meta: isCloning ? void 0 : meta,
2976
+ collectionType
2773
2977
  };
2978
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
2979
+ /* @__PURE__ */ jsx(
2980
+ DescriptionComponentRenderer,
2981
+ {
2982
+ props,
2983
+ descriptions: plugins["content-manager"].apis.getDocumentActions(),
2984
+ children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
2985
+ }
2986
+ ),
2987
+ /* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
2988
+ ] });
2774
2989
  };
2775
- const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
2776
- return columns.map((name) => {
2777
- const attribute = attributes[name];
2778
- if (!attribute) {
2779
- return null;
2990
+ const Panel = React.forwardRef(({ children, title }, ref) => {
2991
+ return /* @__PURE__ */ jsxs(
2992
+ Flex,
2993
+ {
2994
+ ref,
2995
+ tag: "aside",
2996
+ "aria-labelledby": "additional-information",
2997
+ background: "neutral0",
2998
+ borderColor: "neutral150",
2999
+ hasRadius: true,
3000
+ paddingBottom: 4,
3001
+ paddingLeft: 4,
3002
+ paddingRight: 4,
3003
+ paddingTop: 4,
3004
+ shadow: "tableShadow",
3005
+ gap: 3,
3006
+ direction: "column",
3007
+ justifyContent: "stretch",
3008
+ alignItems: "flex-start",
3009
+ children: [
3010
+ /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
3011
+ children
3012
+ ]
2780
3013
  }
2781
- const metadata = metadatas[name];
2782
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
2783
- return {
2784
- attribute,
2785
- label: metadata.label ?? "",
2786
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
2787
- schemas,
2788
- components: components?.schemas ?? {}
2789
- }),
2790
- name,
2791
- searchable: metadata.searchable ?? true,
2792
- sortable: metadata.sortable ?? true
2793
- };
2794
- }).filter((field) => field !== null);
2795
- };
3014
+ );
3015
+ });
2796
3016
  const ConfirmBulkActionDialog = ({
2797
3017
  onToggleDialog,
2798
3018
  isOpen = false,
@@ -2800,30 +3020,23 @@ const ConfirmBulkActionDialog = ({
2800
3020
  endAction
2801
3021
  }) => {
2802
3022
  const { formatMessage } = useIntl();
2803
- return /* @__PURE__ */ jsxs(
2804
- Dialog,
2805
- {
2806
- onClose: onToggleDialog,
2807
- title: formatMessage({
2808
- id: "app.components.ConfirmDialog.title",
2809
- defaultMessage: "Confirmation"
2810
- }),
2811
- isOpen,
2812
- children: [
2813
- /* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: dialogBody }) }),
2814
- /* @__PURE__ */ jsx(
2815
- DialogFooter,
2816
- {
2817
- startAction: /* @__PURE__ */ jsx(Button, { onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
2818
- id: "app.components.Button.cancel",
2819
- defaultMessage: "Cancel"
2820
- }) }),
2821
- endAction
2822
- }
2823
- )
2824
- ]
2825
- }
2826
- );
3023
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
3024
+ /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
3025
+ id: "app.components.ConfirmDialog.title",
3026
+ defaultMessage: "Confirmation"
3027
+ }) }),
3028
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3029
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3030
+ dialogBody
3031
+ ] }) }),
3032
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
3033
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
3034
+ id: "app.components.Button.cancel",
3035
+ defaultMessage: "Cancel"
3036
+ }) }) }),
3037
+ endAction
3038
+ ] })
3039
+ ] }) });
2827
3040
  };
2828
3041
  const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
2829
3042
  const ConfirmDialogPublishAll = ({
@@ -2838,6 +3051,7 @@ const ConfirmDialogPublishAll = ({
2838
3051
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
2839
3052
  const { model, schema } = useDoc();
2840
3053
  const [{ query }] = useQueryParams();
3054
+ const enableDraftRelationsCount = false;
2841
3055
  const {
2842
3056
  data: countDraftRelations = 0,
2843
3057
  isLoading,
@@ -2849,7 +3063,7 @@ const ConfirmDialogPublishAll = ({
2849
3063
  locale: query?.plugins?.i18n?.locale
2850
3064
  },
2851
3065
  {
2852
- skip: selectedEntries.length === 0
3066
+ skip: !enableDraftRelationsCount
2853
3067
  }
2854
3068
  );
2855
3069
  React.useEffect(() => {
@@ -2928,16 +3142,30 @@ const formatErrorMessages = (errors, parentKey, formatMessage) => {
2928
3142
  )
2929
3143
  );
2930
3144
  } else {
2931
- messages.push(...formatErrorMessages(value, currentKey, formatMessage));
3145
+ messages.push(
3146
+ ...formatErrorMessages(
3147
+ // @ts-expect-error TODO: check why value is not compatible with FormErrors
3148
+ value,
3149
+ currentKey,
3150
+ formatMessage
3151
+ )
3152
+ );
2932
3153
  }
3154
+ } else {
3155
+ messages.push(
3156
+ formatMessage(
3157
+ {
3158
+ id: `${value}.withField`,
3159
+ defaultMessage: value
3160
+ },
3161
+ { field: currentKey }
3162
+ )
3163
+ );
2933
3164
  }
2934
3165
  });
2935
3166
  return messages;
2936
3167
  };
2937
- const EntryValidationText = ({
2938
- validationErrors,
2939
- isPublished = false
2940
- }) => {
3168
+ const EntryValidationText = ({ validationErrors, status }) => {
2941
3169
  const { formatMessage } = useIntl();
2942
3170
  if (validationErrors) {
2943
3171
  const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
@@ -2948,7 +3176,7 @@ const EntryValidationText = ({
2948
3176
  /* @__PURE__ */ jsx(Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
2949
3177
  ] });
2950
3178
  }
2951
- if (isPublished) {
3179
+ if (status === "published") {
2952
3180
  return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
2953
3181
  /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
2954
3182
  /* @__PURE__ */ jsx(Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
@@ -2957,6 +3185,15 @@ const EntryValidationText = ({
2957
3185
  }) })
2958
3186
  ] });
2959
3187
  }
3188
+ if (status === "modified") {
3189
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3190
+ /* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
3191
+ /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3192
+ id: "content-manager.bulk-publish.modified",
3193
+ defaultMessage: "Ready to publish changes"
3194
+ }) })
3195
+ ] });
3196
+ }
2960
3197
  return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
2961
3198
  /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
2962
3199
  /* @__PURE__ */ jsx(Typography, { children: formatMessage({
@@ -3008,10 +3245,10 @@ const SelectedEntriesTableContent = ({
3008
3245
  EntryValidationText,
3009
3246
  {
3010
3247
  validationErrors: validationErrors[row.documentId],
3011
- isPublished: row.status === "published"
3248
+ status: row.status
3012
3249
  }
3013
3250
  ) }),
3014
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
3251
+ /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3015
3252
  IconButton,
3016
3253
  {
3017
3254
  tag: Link,
@@ -3034,9 +3271,10 @@ const SelectedEntriesTableContent = ({
3034
3271
  ),
3035
3272
  target: "_blank",
3036
3273
  marginLeft: "auto",
3037
- children: /* @__PURE__ */ jsx(Pencil, {})
3274
+ variant: "ghost",
3275
+ children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
3038
3276
  }
3039
- ) })
3277
+ ) }) })
3040
3278
  ] }, row.id)) })
3041
3279
  ] });
3042
3280
  };
@@ -3073,7 +3311,13 @@ const SelectedEntriesModalContent = ({
3073
3311
  );
3074
3312
  const { rows, validationErrors } = React.useMemo(() => {
3075
3313
  if (data.length > 0 && schema) {
3076
- const validate = createYupSchema(schema.attributes, components);
3314
+ const validate = createYupSchema(
3315
+ schema.attributes,
3316
+ components,
3317
+ // Since this is the "Publish" action, the validation
3318
+ // schema must enforce the rules for published entities
3319
+ { status: "published" }
3320
+ );
3077
3321
  const validationErrors2 = {};
3078
3322
  const rows2 = data.map((entry) => {
3079
3323
  try {
@@ -3149,7 +3393,7 @@ const SelectedEntriesModalContent = ({
3149
3393
  );
3150
3394
  };
3151
3395
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3152
- /* @__PURE__ */ jsxs(ModalBody, { children: [
3396
+ /* @__PURE__ */ jsxs(Modal.Body, { children: [
3153
3397
  /* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
3154
3398
  /* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
3155
3399
  SelectedEntriesTableContent,
@@ -3161,27 +3405,24 @@ const SelectedEntriesModalContent = ({
3161
3405
  }
3162
3406
  ) })
3163
3407
  ] }),
3164
- /* @__PURE__ */ jsx(
3165
- ModalFooter,
3166
- {
3167
- startActions: /* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
3168
- id: "app.components.Button.cancel",
3169
- defaultMessage: "Cancel"
3170
- }) }),
3171
- endActions: /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3172
- /* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
3173
- /* @__PURE__ */ jsx(
3174
- Button,
3175
- {
3176
- onClick: toggleDialog,
3177
- disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
3178
- loading: isSubmittingForm,
3179
- children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
3180
- }
3181
- )
3182
- ] })
3183
- }
3184
- ),
3408
+ /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3409
+ /* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
3410
+ id: "app.components.Button.cancel",
3411
+ defaultMessage: "Cancel"
3412
+ }) }),
3413
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3414
+ /* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
3415
+ /* @__PURE__ */ jsx(
3416
+ Button,
3417
+ {
3418
+ onClick: toggleDialog,
3419
+ disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
3420
+ loading: isSubmittingForm,
3421
+ children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
3422
+ }
3423
+ )
3424
+ ] })
3425
+ ] }),
3185
3426
  /* @__PURE__ */ jsx(
3186
3427
  ConfirmDialogPublishAll,
3187
3428
  {
@@ -3246,143 +3487,10 @@ const BulkActionsRenderer = () => {
3246
3487
  documents: selectedRows
3247
3488
  },
3248
3489
  descriptions: plugins["content-manager"].apis.getBulkActions(),
3249
- children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(BulkActionAction, { ...action }, action.id))
3490
+ children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
3250
3491
  }
3251
3492
  ) });
3252
3493
  };
3253
- const BulkActionAction = (action) => {
3254
- const [dialogId, setDialogId] = React.useState(null);
3255
- const { toggleNotification } = useNotification();
3256
- const handleClick = (action2) => (e) => {
3257
- const { onClick, dialog, id } = action2;
3258
- if (onClick) {
3259
- onClick(e);
3260
- }
3261
- if (dialog) {
3262
- switch (dialog.type) {
3263
- case "notification":
3264
- toggleNotification({
3265
- title: dialog.title,
3266
- message: dialog.content,
3267
- type: dialog.status,
3268
- timeout: dialog.timeout,
3269
- onClose: dialog.onClose
3270
- });
3271
- break;
3272
- case "dialog":
3273
- case "modal": {
3274
- e.preventDefault();
3275
- setDialogId(id);
3276
- }
3277
- }
3278
- }
3279
- };
3280
- const handleClose = () => {
3281
- setDialogId(null);
3282
- if (action.dialog?.type === "modal" && action.dialog?.onClose) {
3283
- action.dialog.onClose();
3284
- }
3285
- };
3286
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3287
- /* @__PURE__ */ jsx(
3288
- Button,
3289
- {
3290
- disabled: action.disabled,
3291
- startIcon: action.icon,
3292
- variant: action.variant,
3293
- onClick: handleClick(action),
3294
- children: action.label
3295
- }
3296
- ),
3297
- action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
3298
- BulkActionConfirmDialog,
3299
- {
3300
- ...action.dialog,
3301
- variant: action.variant,
3302
- isOpen: dialogId === action.id,
3303
- onClose: handleClose
3304
- }
3305
- ) : null,
3306
- action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
3307
- BulkActionModal,
3308
- {
3309
- ...action.dialog,
3310
- onModalClose: handleClose,
3311
- isOpen: dialogId === action.id
3312
- }
3313
- ) : null
3314
- ] });
3315
- };
3316
- const BulkActionConfirmDialog = ({
3317
- onClose,
3318
- onCancel,
3319
- onConfirm,
3320
- title,
3321
- content,
3322
- confirmButton,
3323
- isOpen,
3324
- variant = "secondary"
3325
- }) => {
3326
- const { formatMessage } = useIntl();
3327
- const handleClose = async () => {
3328
- if (onCancel) {
3329
- await onCancel();
3330
- }
3331
- onClose();
3332
- };
3333
- const handleConfirm = async () => {
3334
- if (onConfirm) {
3335
- await onConfirm();
3336
- }
3337
- onClose();
3338
- };
3339
- return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
3340
- /* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: content }),
3341
- /* @__PURE__ */ jsx(
3342
- DialogFooter,
3343
- {
3344
- startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
3345
- id: "app.components.Button.cancel",
3346
- defaultMessage: "Cancel"
3347
- }) }),
3348
- endAction: /* @__PURE__ */ jsx(
3349
- Button,
3350
- {
3351
- onClick: handleConfirm,
3352
- variant: variant === "danger-light" ? variant : "secondary",
3353
- startIcon: variant === "danger-light" ? /* @__PURE__ */ jsx(Trash, {}) : /* @__PURE__ */ jsx(Check, {}),
3354
- children: confirmButton ? confirmButton : formatMessage({
3355
- id: "app.components.Button.confirm",
3356
- defaultMessage: "Confirm"
3357
- })
3358
- }
3359
- )
3360
- }
3361
- )
3362
- ] });
3363
- };
3364
- const BulkActionModal = ({
3365
- isOpen,
3366
- title,
3367
- onClose,
3368
- content: Content,
3369
- onModalClose
3370
- }) => {
3371
- const id = React.useId();
3372
- if (!isOpen) {
3373
- return null;
3374
- }
3375
- const handleClose = () => {
3376
- if (onClose) {
3377
- onClose();
3378
- }
3379
- onModalClose();
3380
- };
3381
- return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
3382
- /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id, children: title }) }),
3383
- /* @__PURE__ */ jsx(Content, { onClose: handleClose })
3384
- ] });
3385
- };
3386
3494
  const DeleteAction = ({ documents, model }) => {
3387
3495
  const { formatMessage } = useIntl();
3388
3496
  const { schema: contentType } = useDoc();
@@ -3415,6 +3523,7 @@ const DeleteAction = ({ documents, model }) => {
3415
3523
  defaultMessage: "Confirmation"
3416
3524
  }),
3417
3525
  content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3526
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3418
3527
  /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3419
3528
  id: "popUpWarning.bodyMessage.contentType.delete.all",
3420
3529
  defaultMessage: "Are you sure you want to delete these entries?"
@@ -3451,7 +3560,7 @@ const UnpublishAction = ({ documents, model }) => {
3451
3560
  selectRow([]);
3452
3561
  }
3453
3562
  };
3454
- const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published");
3563
+ const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
3455
3564
  if (!showUnpublishButton)
3456
3565
  return null;
3457
3566
  return {
@@ -3464,6 +3573,7 @@ const UnpublishAction = ({ documents, model }) => {
3464
3573
  defaultMessage: "Confirmation"
3465
3574
  }),
3466
3575
  content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3576
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3467
3577
  /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3468
3578
  id: "popUpWarning.bodyMessage.contentType.unpublish.all",
3469
3579
  defaultMessage: "Are you sure you want to unpublish these entries?"
@@ -3557,7 +3667,7 @@ const TableActions = ({ document }) => {
3557
3667
  DescriptionComponentRenderer,
3558
3668
  {
3559
3669
  props,
3560
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
3670
+ descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
3561
3671
  children: (actions2) => {
3562
3672
  const tableRowActions = actions2.filter((action) => {
3563
3673
  const positions = Array.isArray(action.position) ? action.position : [action.position];
@@ -3668,7 +3778,7 @@ const CloneAction = ({ model, documentId }) => {
3668
3778
  }),
3669
3779
  content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
3670
3780
  footer: ({ onClose }) => {
3671
- return /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
3781
+ return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3672
3782
  /* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
3673
3783
  id: "cancel",
3674
3784
  defaultMessage: "Cancel"
@@ -3709,8 +3819,7 @@ class ContentManagerPlugin {
3709
3819
  documentActions = [
3710
3820
  ...DEFAULT_ACTIONS,
3711
3821
  ...DEFAULT_TABLE_ROW_ACTIONS,
3712
- ...DEFAULT_HEADER_ACTIONS,
3713
- HistoryAction
3822
+ ...DEFAULT_HEADER_ACTIONS
3714
3823
  ];
3715
3824
  editViewSidePanels = [ActionsPanel];
3716
3825
  headerActions = [];
@@ -3799,6 +3908,52 @@ const getPrintableType = (value) => {
3799
3908
  }
3800
3909
  return nativeType;
3801
3910
  };
3911
+ const HistoryAction = ({ model, document }) => {
3912
+ const { formatMessage } = useIntl();
3913
+ const [{ query }] = useQueryParams();
3914
+ const navigate = useNavigate();
3915
+ const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
3916
+ if (!window.strapi.features.isEnabled("cms-content-history")) {
3917
+ return null;
3918
+ }
3919
+ return {
3920
+ icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
3921
+ label: formatMessage({
3922
+ id: "content-manager.history.document-action",
3923
+ defaultMessage: "Content History"
3924
+ }),
3925
+ onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
3926
+ disabled: (
3927
+ /**
3928
+ * The user is creating a new document.
3929
+ * It hasn't been saved yet, so there's no history to go to
3930
+ */
3931
+ !document || /**
3932
+ * The document has been created but the current dimension has never been saved.
3933
+ * For example, the user is creating a new locale in an existing document,
3934
+ * so there's no history for the document in that locale
3935
+ */
3936
+ !document.id || /**
3937
+ * History is only available for content types created by the user.
3938
+ * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
3939
+ * which start with `admin::` or `plugin::`
3940
+ */
3941
+ !model.startsWith("api::")
3942
+ ),
3943
+ position: "header"
3944
+ };
3945
+ };
3946
+ HistoryAction.type = "history";
3947
+ const historyAdmin = {
3948
+ bootstrap(app) {
3949
+ const { addDocumentAction } = app.getPlugin("content-manager").apis;
3950
+ addDocumentAction((actions2) => {
3951
+ const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
3952
+ actions2.splice(indexOfDeleteAction, 0, HistoryAction);
3953
+ return actions2;
3954
+ });
3955
+ }
3956
+ };
3802
3957
  const initialState = {
3803
3958
  collectionTypeLinks: [],
3804
3959
  components: [],
@@ -3849,15 +4004,29 @@ const index = {
3849
4004
  defaultMessage: "Content Manager"
3850
4005
  },
3851
4006
  permissions: [],
3852
- Component: () => import("./layout-CPn1PM6x.mjs").then((mod) => ({ default: mod.Layout })),
3853
4007
  position: 1
3854
4008
  });
4009
+ app.router.addRoute({
4010
+ path: "content-manager/*",
4011
+ lazy: async () => {
4012
+ const { Layout } = await import("./layout-2CfjL0T9.mjs");
4013
+ return {
4014
+ Component: Layout
4015
+ };
4016
+ },
4017
+ children: routes
4018
+ });
3855
4019
  app.registerPlugin(cm.config);
3856
4020
  },
4021
+ bootstrap(app) {
4022
+ if (typeof historyAdmin.bootstrap === "function") {
4023
+ historyAdmin.bootstrap(app);
4024
+ }
4025
+ },
3857
4026
  async registerTrads({ locales }) {
3858
4027
  const importedTrads = await Promise.all(
3859
4028
  locales.map((locale) => {
3860
- return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-Dzv55oQw.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
4029
+ return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-DKV44jRb.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
3861
4030
  return {
3862
4031
  data: prefixPluginTranslations(data, PLUGIN_ID),
3863
4032
  locale
@@ -3885,36 +4054,37 @@ export {
3885
4054
  InjectionZone as I,
3886
4055
  useDocument as J,
3887
4056
  index as K,
3888
- useDocumentActions as L,
4057
+ useContentManagerContext as L,
4058
+ useDocumentActions as M,
3889
4059
  Panels as P,
3890
4060
  RelativeTime as R,
3891
4061
  SINGLE_TYPES as S,
3892
4062
  TableActions as T,
3893
- useGetAllContentTypeSettingsQuery as a,
3894
- useDoc as b,
3895
- buildValidParams as c,
3896
- contentManagerApi as d,
3897
- useDocumentRBAC as e,
3898
- useDocumentLayout as f,
4063
+ useGetInitialDataQuery as a,
4064
+ useGetAllContentTypeSettingsQuery as b,
4065
+ useDoc as c,
4066
+ buildValidParams as d,
4067
+ contentManagerApi as e,
4068
+ useDocumentRBAC as f,
3899
4069
  getTranslation as g,
3900
- createYupSchema as h,
3901
- Header as i,
3902
- PERMISSIONS as j,
3903
- DocumentRBAC as k,
3904
- DOCUMENT_META_FIELDS as l,
3905
- useDocLayout as m,
3906
- useContentTypeSchema as n,
3907
- useGetContentTypeConfigurationQuery as o,
3908
- CREATOR_FIELDS as p,
3909
- getMainField as q,
3910
- routes as r,
4070
+ useDocumentLayout as h,
4071
+ createYupSchema as i,
4072
+ Header as j,
4073
+ PERMISSIONS as k,
4074
+ DocumentRBAC as l,
4075
+ DOCUMENT_META_FIELDS as m,
4076
+ CLONE_PATH as n,
4077
+ useDocLayout as o,
4078
+ useGetContentTypeConfigurationQuery as p,
4079
+ CREATOR_FIELDS as q,
4080
+ getMainField as r,
3911
4081
  setInitialData as s,
3912
4082
  getDisplayName as t,
3913
- useGetInitialDataQuery as u,
4083
+ useContentTypeSchema as u,
3914
4084
  checkIfAttributeIsDisplayable as v,
3915
4085
  useGetAllDocumentsQuery as w,
3916
4086
  convertListLayoutToFieldLayouts as x,
3917
4087
  capitalise as y,
3918
4088
  useUpdateContentTypeConfigurationMutation as z
3919
4089
  };
3920
- //# sourceMappingURL=index-VHviNMeW.mjs.map
4090
+ //# sourceMappingURL=index-wnqzm4Q8.mjs.map