@strapi/content-manager 0.0.0-experimental.93a73ca8c7b85667fe8e46c0cb6627506570a02f → 0.0.0-experimental.953e1857bbad81a3c34f5d6511736c1bc8b91dcb

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 (179) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-KXSuLnQD.js → ComponentConfigurationPage-CpJNPBgk.js} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-KXSuLnQD.js.map → ComponentConfigurationPage-CpJNPBgk.js.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-B3yDbeU1.mjs → ComponentConfigurationPage-TYDPg5WG.mjs} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-B3yDbeU1.mjs.map → ComponentConfigurationPage-TYDPg5WG.mjs.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-BQ17--5R.js → EditConfigurationPage-CFDe6SA1.js} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-BQ17--5R.js.map → EditConfigurationPage-CFDe6SA1.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-D7PrLO8j.mjs → EditConfigurationPage-DqL8Pq5r.mjs} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-D7PrLO8j.mjs.map → EditConfigurationPage-DqL8Pq5r.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-B7VgwJaG.mjs → EditViewPage-RXrFLav2.mjs} +15 -5
  10. package/dist/_chunks/EditViewPage-RXrFLav2.mjs.map +1 -0
  11. package/dist/_chunks/{EditViewPage-BgjdnGz2.js → EditViewPage-khfP2CR3.js} +15 -5
  12. package/dist/_chunks/EditViewPage-khfP2CR3.js.map +1 -0
  13. package/dist/_chunks/{Field-tHCw4lGA.mjs → Field--rQeS6Zj.mjs} +99 -86
  14. package/dist/_chunks/Field--rQeS6Zj.mjs.map +1 -0
  15. package/dist/_chunks/{Field-CdK7ZLmv.js → Field-C1ftmTe9.js} +102 -89
  16. package/dist/_chunks/Field-C1ftmTe9.js.map +1 -0
  17. package/dist/_chunks/{Form-BJxdTv3Q.mjs → Form-COtGXyUE.mjs} +16 -8
  18. package/dist/_chunks/Form-COtGXyUE.mjs.map +1 -0
  19. package/dist/_chunks/{Form-C_0KTVvV.js → Form-CwdX5oLw.js} +16 -8
  20. package/dist/_chunks/Form-CwdX5oLw.js.map +1 -0
  21. package/dist/_chunks/{History-DR2txJLE.mjs → History-BevwkPO1.mjs} +38 -41
  22. package/dist/_chunks/History-BevwkPO1.mjs.map +1 -0
  23. package/dist/_chunks/{History-nuEzM5qm.js → History-DKS2aqqM.js} +37 -40
  24. package/dist/_chunks/History-DKS2aqqM.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-voFVtXu6.mjs → ListConfigurationPage-DNfZDtDA.mjs} +3 -3
  26. package/dist/_chunks/{ListConfigurationPage-voFVtXu6.mjs.map → ListConfigurationPage-DNfZDtDA.mjs.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-CnB86Psm.js → ListConfigurationPage-LSYSPZHH.js} +3 -3
  28. package/dist/_chunks/{ListConfigurationPage-CnB86Psm.js.map → ListConfigurationPage-LSYSPZHH.js.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-B_GaWgRH.mjs → ListViewPage-C1PyuYRS.mjs} +52 -37
  30. package/dist/_chunks/ListViewPage-C1PyuYRS.mjs.map +1 -0
  31. package/dist/_chunks/{ListViewPage-SXIXm-RM.js → ListViewPage-DlUpqLIo.js} +55 -40
  32. package/dist/_chunks/ListViewPage-DlUpqLIo.js.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-CYiGpsbj.mjs → NoContentTypePage-C9q744z1.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-CYiGpsbj.mjs.map → NoContentTypePage-C9q744z1.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-BzsQ3hLZ.js → NoContentTypePage-m8wt3sf6.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-BzsQ3hLZ.js.map → NoContentTypePage-m8wt3sf6.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-B5baIHal.mjs → NoPermissionsPage-8BM-LWta.mjs} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-B5baIHal.mjs.map → NoPermissionsPage-8BM-LWta.mjs.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-IGkId4C5.js → NoPermissionsPage-DLfPsA0Q.js} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-IGkId4C5.js.map → NoPermissionsPage-DLfPsA0Q.js.map} +1 -1
  41. package/dist/_chunks/{Relations-CIYDdKU-.mjs → Relations-D25xRcFy.mjs} +72 -36
  42. package/dist/_chunks/Relations-D25xRcFy.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-Dhuurpx2.js → Relations-OMriCP_L.js} +71 -35
  44. package/dist/_chunks/Relations-OMriCP_L.js.map +1 -0
  45. package/dist/_chunks/{en-uOUIxfcQ.js → en-Bdpa50w3.js} +18 -13
  46. package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bdpa50w3.js.map} +1 -1
  47. package/dist/_chunks/{en-BrCTWlZv.mjs → en-CZw4xdPY.mjs} +18 -13
  48. package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-CZw4xdPY.mjs.map} +1 -1
  49. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  50. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  51. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  52. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  53. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  54. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  55. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  56. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  57. package/dist/_chunks/{index-C9TJPyni.mjs → index-BvGihCJp.mjs} +954 -718
  58. package/dist/_chunks/index-BvGihCJp.mjs.map +1 -0
  59. package/dist/_chunks/{index-CdT0kHZ8.js → index-DqZnjo8F.js} +935 -698
  60. package/dist/_chunks/index-DqZnjo8F.js.map +1 -0
  61. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  62. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  63. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  64. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  65. package/dist/_chunks/{layout-C6dxWYT7.js → layout-CmaemAO3.js} +5 -4
  66. package/dist/_chunks/{layout-C6dxWYT7.js.map → layout-CmaemAO3.js.map} +1 -1
  67. package/dist/_chunks/{layout-BNqvLR_b.mjs → layout-ykHSe2KQ.mjs} +5 -4
  68. package/dist/_chunks/{layout-BNqvLR_b.mjs.map → layout-ykHSe2KQ.mjs.map} +1 -1
  69. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  70. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  71. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  72. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  73. package/dist/_chunks/{relations-DtFaDnP1.js → relations-D9fKsCLY.js} +3 -7
  74. package/dist/_chunks/relations-D9fKsCLY.js.map +1 -0
  75. package/dist/_chunks/{relations-CkKqKw65.mjs → relations-u-Vz51Ea.mjs} +3 -7
  76. package/dist/_chunks/relations-u-Vz51Ea.mjs.map +1 -0
  77. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  78. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  79. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  80. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  81. package/dist/admin/index.js +2 -1
  82. package/dist/admin/index.js.map +1 -1
  83. package/dist/admin/index.mjs +5 -4
  84. package/dist/admin/src/exports.d.ts +1 -1
  85. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  86. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  87. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +0 -32
  88. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  89. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  90. package/dist/admin/src/preview/constants.d.ts +1 -0
  91. package/dist/admin/src/preview/index.d.ts +4 -0
  92. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  93. package/dist/admin/src/services/api.d.ts +1 -1
  94. package/dist/admin/src/services/components.d.ts +2 -2
  95. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  96. package/dist/admin/src/services/documents.d.ts +19 -17
  97. package/dist/admin/src/services/init.d.ts +1 -1
  98. package/dist/admin/src/services/relations.d.ts +2 -2
  99. package/dist/admin/src/services/uid.d.ts +3 -3
  100. package/dist/admin/src/utils/validation.d.ts +4 -1
  101. package/dist/server/index.js +421 -183
  102. package/dist/server/index.js.map +1 -1
  103. package/dist/server/index.mjs +421 -183
  104. package/dist/server/index.mjs.map +1 -1
  105. package/dist/server/src/bootstrap.d.ts.map +1 -1
  106. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  107. package/dist/server/src/controllers/index.d.ts.map +1 -1
  108. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  109. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  110. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  111. package/dist/server/src/history/services/history.d.ts.map +1 -1
  112. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  113. package/dist/server/src/history/services/utils.d.ts +3 -3
  114. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  115. package/dist/server/src/index.d.ts +4 -4
  116. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  117. package/dist/server/src/preview/constants.d.ts +2 -0
  118. package/dist/server/src/preview/constants.d.ts.map +1 -0
  119. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  120. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  121. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  122. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  123. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  124. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  125. package/dist/server/src/preview/index.d.ts +4 -0
  126. package/dist/server/src/preview/index.d.ts.map +1 -0
  127. package/dist/server/src/preview/routes/index.d.ts +8 -0
  128. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  129. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  130. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  131. package/dist/server/src/preview/services/index.d.ts +15 -0
  132. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  133. package/dist/server/src/preview/services/preview-config.d.ts +30 -0
  134. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  135. package/dist/server/src/preview/services/preview.d.ts +12 -0
  136. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  137. package/dist/server/src/preview/utils.d.ts +18 -0
  138. package/dist/server/src/preview/utils.d.ts.map +1 -0
  139. package/dist/server/src/routes/index.d.ts.map +1 -1
  140. package/dist/server/src/services/document-metadata.d.ts +8 -8
  141. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  142. package/dist/server/src/services/index.d.ts +4 -4
  143. package/dist/server/src/services/index.d.ts.map +1 -1
  144. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  145. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  146. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  147. package/dist/server/src/utils/index.d.ts +2 -0
  148. package/dist/server/src/utils/index.d.ts.map +1 -1
  149. package/dist/shared/contracts/collection-types.d.ts +3 -1
  150. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  151. package/dist/shared/contracts/index.d.ts +1 -0
  152. package/dist/shared/contracts/index.d.ts.map +1 -1
  153. package/dist/shared/contracts/preview.d.ts +27 -0
  154. package/dist/shared/contracts/preview.d.ts.map +1 -0
  155. package/dist/shared/index.js +4 -0
  156. package/dist/shared/index.js.map +1 -1
  157. package/dist/shared/index.mjs +4 -0
  158. package/dist/shared/index.mjs.map +1 -1
  159. package/package.json +13 -13
  160. package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +0 -1
  161. package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +0 -1
  162. package/dist/_chunks/Field-CdK7ZLmv.js.map +0 -1
  163. package/dist/_chunks/Field-tHCw4lGA.mjs.map +0 -1
  164. package/dist/_chunks/Form-BJxdTv3Q.mjs.map +0 -1
  165. package/dist/_chunks/Form-C_0KTVvV.js.map +0 -1
  166. package/dist/_chunks/History-DR2txJLE.mjs.map +0 -1
  167. package/dist/_chunks/History-nuEzM5qm.js.map +0 -1
  168. package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +0 -1
  169. package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +0 -1
  170. package/dist/_chunks/Relations-CIYDdKU-.mjs.map +0 -1
  171. package/dist/_chunks/Relations-Dhuurpx2.js.map +0 -1
  172. package/dist/_chunks/index-C9TJPyni.mjs.map +0 -1
  173. package/dist/_chunks/index-CdT0kHZ8.js.map +0 -1
  174. package/dist/_chunks/relations-CkKqKw65.mjs.map +0 -1
  175. package/dist/_chunks/relations-DtFaDnP1.js.map +0 -1
  176. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  177. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  178. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  179. package/strapi-server.js +0 -3
@@ -1,16 +1,17 @@
1
- import { CrossCircle, More, WarningCircle, ListPlus, Pencil, Trash, Check, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
1
+ import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Link as Link$1, Feather } from "@strapi/icons";
2
2
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import { useStrapiApp, createContext, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useQueryParams, useTracking, useForm, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
3
+ import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table, useClipboard } from "@strapi/admin/strapi-admin";
4
4
  import * as React from "react";
5
5
  import { lazy } from "react";
6
- import { Menu, Button, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, Box, SingleSelect, SingleSelectOption, Loader, IconButton, Tooltip, LinkButton } from "@strapi/design-system";
6
+ import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
7
+ import mapValues from "lodash/fp/mapValues";
7
8
  import { useIntl } from "react-intl";
8
- import { useParams, Navigate, useNavigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
9
- import { styled } from "styled-components";
9
+ import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
10
10
  import * as yup from "yup";
11
11
  import { ValidationError } from "yup";
12
12
  import pipe from "lodash/fp/pipe";
13
13
  import { intervalToDuration, isPast } from "date-fns";
14
+ import { styled } from "styled-components";
14
15
  import { stringify } from "qs";
15
16
  import { createSlice, combineReducers } from "@reduxjs/toolkit";
16
17
  const __variableDynamicImportRuntimeHelper = (glob, path) => {
@@ -100,6 +101,7 @@ const DocumentRBAC = ({ children, permissions }) => {
100
101
  if (!slug) {
101
102
  throw new Error("Cannot find the slug param in the URL");
102
103
  }
104
+ const [{ rawQuery }] = useQueryParams();
103
105
  const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
104
106
  const contentTypePermissions = React.useMemo(() => {
105
107
  const contentTypePermissions2 = userPermissions.filter(
@@ -110,7 +112,14 @@ const DocumentRBAC = ({ children, permissions }) => {
110
112
  return { ...acc, [action]: [permission] };
111
113
  }, {});
112
114
  }, [slug, userPermissions]);
113
- const { isLoading, allowedActions } = useRBAC(contentTypePermissions, permissions ?? void 0);
115
+ const { isLoading, allowedActions } = useRBAC(
116
+ contentTypePermissions,
117
+ permissions ?? void 0,
118
+ // TODO: useRBAC context should be typed and built differently
119
+ // We are passing raw query as context to the hook so that it can
120
+ // rely on the locale provided from DocumentRBAC for its permission calculations.
121
+ rawQuery
122
+ );
114
123
  const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
115
124
  const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
116
125
  const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
@@ -158,7 +167,8 @@ const contentManagerApi = adminApi.enhanceEndpoints({
158
167
  "Document",
159
168
  "InitialData",
160
169
  "HistoryVersion",
161
- "Relations"
170
+ "Relations",
171
+ "UidAvailability"
162
172
  ]
163
173
  });
164
174
  const documentApi = contentManagerApi.injectEndpoints({
@@ -188,7 +198,10 @@ const documentApi = contentManagerApi.injectEndpoints({
188
198
  params
189
199
  }
190
200
  }),
191
- invalidatesTags: (_result, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
201
+ invalidatesTags: (_result, _error, { model }) => [
202
+ { type: "Document", id: `${model}_LIST` },
203
+ { type: "UidAvailability", id: model }
204
+ ]
192
205
  }),
193
206
  /**
194
207
  * Creates a new collection-type document. This should ONLY be used for collection-types.
@@ -205,7 +218,8 @@ const documentApi = contentManagerApi.injectEndpoints({
205
218
  }),
206
219
  invalidatesTags: (result, _error, { model }) => [
207
220
  { type: "Document", id: `${model}_LIST` },
208
- "Relations"
221
+ "Relations",
222
+ { type: "UidAvailability", id: model }
209
223
  ]
210
224
  }),
211
225
  deleteDocument: builder.mutation({
@@ -246,7 +260,8 @@ const documentApi = contentManagerApi.injectEndpoints({
246
260
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
247
261
  },
248
262
  { type: "Document", id: `${model}_LIST` },
249
- "Relations"
263
+ "Relations",
264
+ { type: "UidAvailability", id: model }
250
265
  ];
251
266
  }
252
267
  }),
@@ -371,7 +386,8 @@ const documentApi = contentManagerApi.injectEndpoints({
371
386
  type: "Document",
372
387
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
373
388
  },
374
- "Relations"
389
+ "Relations",
390
+ { type: "UidAvailability", id: model }
375
391
  ];
376
392
  },
377
393
  async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
@@ -454,20 +470,39 @@ const buildValidParams = (query) => {
454
470
  const isBaseQueryError = (error) => {
455
471
  return error.name !== void 0;
456
472
  };
457
- const createYupSchema = (attributes = {}, components = {}) => {
473
+ const arrayValidator = (attribute, options) => ({
474
+ message: translatedErrors.required,
475
+ test(value) {
476
+ if (options.status === "draft") {
477
+ return true;
478
+ }
479
+ if (!attribute.required) {
480
+ return true;
481
+ }
482
+ if (!value) {
483
+ return false;
484
+ }
485
+ if (Array.isArray(value) && value.length === 0) {
486
+ return false;
487
+ }
488
+ return true;
489
+ }
490
+ });
491
+ const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
458
492
  const createModelSchema = (attributes2) => yup.object().shape(
459
493
  Object.entries(attributes2).reduce((acc, [name, attribute]) => {
460
494
  if (DOCUMENT_META_FIELDS.includes(name)) {
461
495
  return acc;
462
496
  }
463
497
  const validations = [
498
+ addNullableValidation,
464
499
  addRequiredValidation,
465
500
  addMinLengthValidation,
466
501
  addMaxLengthValidation,
467
502
  addMinValidation,
468
503
  addMaxValidation,
469
504
  addRegexValidation
470
- ].map((fn) => fn(attribute));
505
+ ].map((fn) => fn(attribute, options));
471
506
  const transformSchema = pipe(...validations);
472
507
  switch (attribute.type) {
473
508
  case "component": {
@@ -477,12 +512,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
477
512
  ...acc,
478
513
  [name]: transformSchema(
479
514
  yup.array().of(createModelSchema(attributes3).nullable(false))
480
- )
515
+ ).test(arrayValidator(attribute, options))
481
516
  };
482
517
  } else {
483
518
  return {
484
519
  ...acc,
485
- [name]: transformSchema(createModelSchema(attributes3))
520
+ [name]: transformSchema(createModelSchema(attributes3).nullable())
486
521
  };
487
522
  }
488
523
  }
@@ -504,7 +539,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
504
539
  }
505
540
  )
506
541
  )
507
- )
542
+ ).test(arrayValidator(attribute, options))
508
543
  };
509
544
  case "relation":
510
545
  return {
@@ -516,7 +551,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
516
551
  } else if (Array.isArray(value)) {
517
552
  return yup.array().of(
518
553
  yup.object().shape({
519
- id: yup.string().required()
554
+ id: yup.number().required()
520
555
  })
521
556
  );
522
557
  } else if (typeof value === "object") {
@@ -594,13 +629,7 @@ const createAttributeSchema = (attribute) => {
594
629
  return yup.mixed();
595
630
  }
596
631
  };
597
- const addRequiredValidation = (attribute) => (schema) => {
598
- if ((attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") && attribute.required && "min" in schema) {
599
- return schema.min(1, translatedErrors.required);
600
- }
601
- if (attribute.required && attribute.type !== "relation") {
602
- return schema.required(translatedErrors.required);
603
- }
632
+ const nullableSchema = (schema) => {
604
633
  return schema?.nullable ? schema.nullable() : (
605
634
  // In some cases '.nullable' will not be available on the schema.
606
635
  // e.g. when the schema has been built using yup.lazy (e.g. for relations).
@@ -608,7 +637,22 @@ const addRequiredValidation = (attribute) => (schema) => {
608
637
  schema
609
638
  );
610
639
  };
611
- const addMinLengthValidation = (attribute) => (schema) => {
640
+ const addNullableValidation = () => (schema) => {
641
+ return nullableSchema(schema);
642
+ };
643
+ const addRequiredValidation = (attribute, options) => (schema) => {
644
+ if (options.status === "draft" || !attribute.required) {
645
+ return schema;
646
+ }
647
+ if (attribute.required && "required" in schema) {
648
+ return schema.required(translatedErrors.required);
649
+ }
650
+ return schema;
651
+ };
652
+ const addMinLengthValidation = (attribute, options) => (schema) => {
653
+ if (options.status === "draft") {
654
+ return schema;
655
+ }
612
656
  if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
613
657
  return schema.min(attribute.minLength, {
614
658
  ...translatedErrors.minLength,
@@ -630,32 +674,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
630
674
  }
631
675
  return schema;
632
676
  };
633
- const addMinValidation = (attribute) => (schema) => {
634
- if ("min" in attribute) {
677
+ const addMinValidation = (attribute, options) => (schema) => {
678
+ if (options.status === "draft") {
679
+ return schema;
680
+ }
681
+ if ("min" in attribute && "min" in schema) {
635
682
  const min = toInteger(attribute.min);
636
- if (attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") {
637
- if (!attribute.required && "test" in schema && min) {
638
- return schema.test(
639
- "custom-min",
640
- {
641
- ...translatedErrors.min,
642
- values: {
643
- min: attribute.min
644
- }
645
- },
646
- (value) => {
647
- if (!value) {
648
- return true;
649
- }
650
- if (Array.isArray(value) && value.length === 0) {
651
- return true;
652
- }
653
- return value.length >= min;
654
- }
655
- );
656
- }
657
- }
658
- if ("min" in schema && min) {
683
+ if (min) {
659
684
  return schema.min(min, {
660
685
  ...translatedErrors.min,
661
686
  values: {
@@ -773,19 +798,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
773
798
  }, {});
774
799
  return componentsByKey;
775
800
  };
776
- const useDocument = (args, opts) => {
801
+ const HOOKS = {
802
+ /**
803
+ * Hook that allows to mutate the displayed headers of the list view table
804
+ * @constant
805
+ * @type {string}
806
+ */
807
+ INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
808
+ /**
809
+ * Hook that allows to mutate the CM's collection types links pre-set filters
810
+ * @constant
811
+ * @type {string}
812
+ */
813
+ MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
814
+ /**
815
+ * Hook that allows to mutate the CM's edit view layout
816
+ * @constant
817
+ * @type {string}
818
+ */
819
+ MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
820
+ /**
821
+ * Hook that allows to mutate the CM's single types links pre-set filters
822
+ * @constant
823
+ * @type {string}
824
+ */
825
+ MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
826
+ };
827
+ const contentTypesApi = contentManagerApi.injectEndpoints({
828
+ endpoints: (builder) => ({
829
+ getContentTypeConfiguration: builder.query({
830
+ query: (uid) => ({
831
+ url: `/content-manager/content-types/${uid}/configuration`,
832
+ method: "GET"
833
+ }),
834
+ transformResponse: (response) => response.data,
835
+ providesTags: (_result, _error, uid) => [
836
+ { type: "ContentTypesConfiguration", id: uid },
837
+ { type: "ContentTypeSettings", id: "LIST" }
838
+ ]
839
+ }),
840
+ getAllContentTypeSettings: builder.query({
841
+ query: () => "/content-manager/content-types-settings",
842
+ transformResponse: (response) => response.data,
843
+ providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
844
+ }),
845
+ updateContentTypeConfiguration: builder.mutation({
846
+ query: ({ uid, ...body }) => ({
847
+ url: `/content-manager/content-types/${uid}/configuration`,
848
+ method: "PUT",
849
+ data: body
850
+ }),
851
+ transformResponse: (response) => response.data,
852
+ invalidatesTags: (_result, _error, { uid }) => [
853
+ { type: "ContentTypesConfiguration", id: uid },
854
+ { type: "ContentTypeSettings", id: "LIST" },
855
+ // Is this necessary?
856
+ { type: "InitialData" }
857
+ ]
858
+ })
859
+ })
860
+ });
861
+ const {
862
+ useGetContentTypeConfigurationQuery,
863
+ useGetAllContentTypeSettingsQuery,
864
+ useUpdateContentTypeConfigurationMutation
865
+ } = contentTypesApi;
866
+ const checkIfAttributeIsDisplayable = (attribute) => {
867
+ const { type } = attribute;
868
+ if (type === "relation") {
869
+ return !attribute.relation.toLowerCase().includes("morph");
870
+ }
871
+ return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
872
+ };
873
+ const getMainField = (attribute, mainFieldName, { schemas, components }) => {
874
+ if (!mainFieldName) {
875
+ return void 0;
876
+ }
877
+ const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
878
+ // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
879
+ schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
880
+ );
881
+ return {
882
+ name: mainFieldName,
883
+ type: mainFieldType ?? "string"
884
+ };
885
+ };
886
+ const DEFAULT_SETTINGS = {
887
+ bulkable: false,
888
+ filterable: false,
889
+ searchable: false,
890
+ pagination: false,
891
+ defaultSortBy: "",
892
+ defaultSortOrder: "asc",
893
+ mainField: "id",
894
+ pageSize: 10
895
+ };
896
+ const useDocumentLayout = (model) => {
897
+ const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
898
+ const [{ query }] = useQueryParams();
899
+ const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
777
900
  const { toggleNotification } = useNotification();
778
901
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
902
+ const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
779
903
  const {
780
- currentData: data,
781
- isLoading: isLoadingDocument,
782
- isFetching: isFetchingDocument,
783
- error
784
- } = useGetDocumentQuery(args, {
785
- ...opts,
786
- skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
787
- });
788
- const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
904
+ data,
905
+ isLoading: isLoadingConfigs,
906
+ error,
907
+ isFetching: isFetchingConfigs
908
+ } = useGetContentTypeConfigurationQuery(model);
909
+ const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
789
910
  React.useEffect(() => {
790
911
  if (error) {
791
912
  toggleNotification({
@@ -793,93 +914,349 @@ const useDocument = (args, opts) => {
793
914
  message: formatAPIError(error)
794
915
  });
795
916
  }
796
- }, [toggleNotification, error, formatAPIError, args.collectionType]);
797
- const validationSchema = React.useMemo(() => {
798
- if (!schema) {
799
- return null;
800
- }
801
- return createYupSchema(schema.attributes, components);
802
- }, [schema, components]);
803
- const validate = React.useCallback(
804
- (document) => {
805
- if (!validationSchema) {
806
- throw new Error(
807
- "There is no validation schema generated, this is likely due to the schema not being loaded yet."
808
- );
809
- }
810
- try {
811
- validationSchema.validateSync(document, { abortEarly: false, strict: true });
812
- return null;
813
- } catch (error2) {
814
- if (error2 instanceof ValidationError) {
815
- return getYupValidationErrors(error2);
816
- }
817
- throw error2;
818
- }
917
+ }, [error, formatAPIError, toggleNotification]);
918
+ const editLayout = React.useMemo(
919
+ () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
920
+ layout: [],
921
+ components: {},
922
+ metadatas: {},
923
+ options: {},
924
+ settings: DEFAULT_SETTINGS
819
925
  },
820
- [validationSchema]
926
+ [data, isLoading, schemas, schema, components]
927
+ );
928
+ const listLayout = React.useMemo(() => {
929
+ return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
930
+ layout: [],
931
+ metadatas: {},
932
+ options: {},
933
+ settings: DEFAULT_SETTINGS
934
+ };
935
+ }, [data, isLoading, schemas, schema, components]);
936
+ const { layout: edit } = React.useMemo(
937
+ () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
938
+ layout: editLayout,
939
+ query
940
+ }),
941
+ [editLayout, query, runHookWaterfall]
821
942
  );
822
- const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
823
943
  return {
824
- components,
825
- document: data?.data,
826
- meta: data?.meta,
944
+ error,
827
945
  isLoading,
828
- schema,
829
- validate
830
- };
831
- };
832
- const useDoc = () => {
833
- const { id, slug, collectionType, origin } = useParams();
834
- const [{ query }] = useQueryParams();
835
- const params = React.useMemo(() => buildValidParams(query), [query]);
836
- if (!collectionType) {
837
- throw new Error("Could not find collectionType in url params");
838
- }
839
- if (!slug) {
840
- throw new Error("Could not find model in url params");
841
- }
842
- return {
843
- collectionType,
844
- model: slug,
845
- id: origin || id === "create" ? void 0 : id,
846
- ...useDocument(
847
- { documentId: origin || id, model: slug, collectionType, params },
848
- {
849
- skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
850
- }
851
- )
946
+ edit,
947
+ list: listLayout
852
948
  };
853
949
  };
854
- const prefixPluginTranslations = (trad, pluginId) => {
855
- if (!pluginId) {
856
- throw new TypeError("pluginId can't be empty");
857
- }
858
- return Object.keys(trad).reduce((acc, current) => {
859
- acc[`${pluginId}.${current}`] = trad[current];
860
- return acc;
861
- }, {});
862
- };
863
- const getTranslation = (id) => `content-manager.${id}`;
864
- const DEFAULT_UNEXPECTED_ERROR_MSG = {
865
- id: "notification.error",
866
- defaultMessage: "An error occurred, please try again"
950
+ const useDocLayout = () => {
951
+ const { model } = useDoc();
952
+ return useDocumentLayout(model);
867
953
  };
868
- const useDocumentActions = () => {
869
- const { toggleNotification } = useNotification();
870
- const { formatMessage } = useIntl();
871
- const { trackUsage } = useTracking();
872
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
873
- const [deleteDocument] = useDeleteDocumentMutation();
874
- const _delete = React.useCallback(
875
- async ({ collectionType, model, documentId, params }, trackerProperty) => {
876
- try {
877
- trackUsage("willDeleteEntry", trackerProperty);
878
- const res = await deleteDocument({
879
- collectionType,
880
- model,
881
- documentId,
882
- params
954
+ const formatEditLayout = (data, {
955
+ schemas,
956
+ schema,
957
+ components
958
+ }) => {
959
+ let currentPanelIndex = 0;
960
+ const panelledEditAttributes = convertEditLayoutToFieldLayouts(
961
+ data.contentType.layouts.edit,
962
+ schema?.attributes,
963
+ data.contentType.metadatas,
964
+ { configurations: data.components, schemas: components },
965
+ schemas
966
+ ).reduce((panels, row) => {
967
+ if (row.some((field) => field.type === "dynamiczone")) {
968
+ panels.push([row]);
969
+ currentPanelIndex += 2;
970
+ } else {
971
+ if (!panels[currentPanelIndex]) {
972
+ panels.push([row]);
973
+ } else {
974
+ panels[currentPanelIndex].push(row);
975
+ }
976
+ }
977
+ return panels;
978
+ }, []);
979
+ const componentEditAttributes = Object.entries(data.components).reduce(
980
+ (acc, [uid, configuration]) => {
981
+ acc[uid] = {
982
+ layout: convertEditLayoutToFieldLayouts(
983
+ configuration.layouts.edit,
984
+ components[uid].attributes,
985
+ configuration.metadatas,
986
+ { configurations: data.components, schemas: components }
987
+ ),
988
+ settings: {
989
+ ...configuration.settings,
990
+ icon: components[uid].info.icon,
991
+ displayName: components[uid].info.displayName
992
+ }
993
+ };
994
+ return acc;
995
+ },
996
+ {}
997
+ );
998
+ const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
999
+ (acc, [attribute, metadata]) => {
1000
+ return {
1001
+ ...acc,
1002
+ [attribute]: metadata.edit
1003
+ };
1004
+ },
1005
+ {}
1006
+ );
1007
+ return {
1008
+ layout: panelledEditAttributes,
1009
+ components: componentEditAttributes,
1010
+ metadatas: editMetadatas,
1011
+ settings: {
1012
+ ...data.contentType.settings,
1013
+ displayName: schema?.info.displayName
1014
+ },
1015
+ options: {
1016
+ ...schema?.options,
1017
+ ...schema?.pluginOptions,
1018
+ ...data.contentType.options
1019
+ }
1020
+ };
1021
+ };
1022
+ const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
1023
+ return rows.map(
1024
+ (row) => row.map((field) => {
1025
+ const attribute = attributes[field.name];
1026
+ if (!attribute) {
1027
+ return null;
1028
+ }
1029
+ const { edit: metadata } = metadatas[field.name];
1030
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1031
+ return {
1032
+ attribute,
1033
+ disabled: !metadata.editable,
1034
+ hint: metadata.description,
1035
+ label: metadata.label ?? "",
1036
+ name: field.name,
1037
+ // @ts-expect-error – mainField does exist on the metadata for a relation.
1038
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1039
+ schemas,
1040
+ components: components?.schemas ?? {}
1041
+ }),
1042
+ placeholder: metadata.placeholder ?? "",
1043
+ required: attribute.required ?? false,
1044
+ size: field.size,
1045
+ unique: "unique" in attribute ? attribute.unique : false,
1046
+ visible: metadata.visible ?? true,
1047
+ type: attribute.type
1048
+ };
1049
+ }).filter((field) => field !== null)
1050
+ );
1051
+ };
1052
+ const formatListLayout = (data, {
1053
+ schemas,
1054
+ schema,
1055
+ components
1056
+ }) => {
1057
+ const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
1058
+ (acc, [attribute, metadata]) => {
1059
+ return {
1060
+ ...acc,
1061
+ [attribute]: metadata.list
1062
+ };
1063
+ },
1064
+ {}
1065
+ );
1066
+ const listAttributes = convertListLayoutToFieldLayouts(
1067
+ data.contentType.layouts.list,
1068
+ schema?.attributes,
1069
+ listMetadatas,
1070
+ { configurations: data.components, schemas: components },
1071
+ schemas
1072
+ );
1073
+ return {
1074
+ layout: listAttributes,
1075
+ settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
1076
+ metadatas: listMetadatas,
1077
+ options: {
1078
+ ...schema?.options,
1079
+ ...schema?.pluginOptions,
1080
+ ...data.contentType.options
1081
+ }
1082
+ };
1083
+ };
1084
+ const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
1085
+ return columns.map((name) => {
1086
+ const attribute = attributes[name];
1087
+ if (!attribute) {
1088
+ return null;
1089
+ }
1090
+ const metadata = metadatas[name];
1091
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1092
+ return {
1093
+ attribute,
1094
+ label: metadata.label ?? "",
1095
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1096
+ schemas,
1097
+ components: components?.schemas ?? {}
1098
+ }),
1099
+ name,
1100
+ searchable: metadata.searchable ?? true,
1101
+ sortable: metadata.sortable ?? true
1102
+ };
1103
+ }).filter((field) => field !== null);
1104
+ };
1105
+ const useDocument = (args, opts) => {
1106
+ const { toggleNotification } = useNotification();
1107
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1108
+ const {
1109
+ currentData: data,
1110
+ isLoading: isLoadingDocument,
1111
+ isFetching: isFetchingDocument,
1112
+ error
1113
+ } = useGetDocumentQuery(args, {
1114
+ ...opts,
1115
+ skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
1116
+ });
1117
+ const {
1118
+ components,
1119
+ schema,
1120
+ schemas,
1121
+ isLoading: isLoadingSchema
1122
+ } = useContentTypeSchema(args.model);
1123
+ React.useEffect(() => {
1124
+ if (error) {
1125
+ toggleNotification({
1126
+ type: "danger",
1127
+ message: formatAPIError(error)
1128
+ });
1129
+ }
1130
+ }, [toggleNotification, error, formatAPIError, args.collectionType]);
1131
+ const validationSchema = React.useMemo(() => {
1132
+ if (!schema) {
1133
+ return null;
1134
+ }
1135
+ return createYupSchema(schema.attributes, components);
1136
+ }, [schema, components]);
1137
+ const validate = React.useCallback(
1138
+ (document) => {
1139
+ if (!validationSchema) {
1140
+ throw new Error(
1141
+ "There is no validation schema generated, this is likely due to the schema not being loaded yet."
1142
+ );
1143
+ }
1144
+ try {
1145
+ validationSchema.validateSync(document, { abortEarly: false, strict: true });
1146
+ return null;
1147
+ } catch (error2) {
1148
+ if (error2 instanceof ValidationError) {
1149
+ return getYupValidationErrors(error2);
1150
+ }
1151
+ throw error2;
1152
+ }
1153
+ },
1154
+ [validationSchema]
1155
+ );
1156
+ const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
1157
+ const hasError = !!error;
1158
+ return {
1159
+ components,
1160
+ document: data?.data,
1161
+ meta: data?.meta,
1162
+ isLoading,
1163
+ hasError,
1164
+ schema,
1165
+ schemas,
1166
+ validate
1167
+ };
1168
+ };
1169
+ const useDoc = () => {
1170
+ const { id, slug, collectionType, origin } = useParams();
1171
+ const [{ query }] = useQueryParams();
1172
+ const params = React.useMemo(() => buildValidParams(query), [query]);
1173
+ if (!collectionType) {
1174
+ throw new Error("Could not find collectionType in url params");
1175
+ }
1176
+ if (!slug) {
1177
+ throw new Error("Could not find model in url params");
1178
+ }
1179
+ const document = useDocument(
1180
+ { documentId: origin || id, model: slug, collectionType, params },
1181
+ {
1182
+ skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
1183
+ }
1184
+ );
1185
+ const returnId = origin || id === "create" ? void 0 : id;
1186
+ return {
1187
+ collectionType,
1188
+ model: slug,
1189
+ id: returnId,
1190
+ ...document
1191
+ };
1192
+ };
1193
+ const useContentManagerContext = () => {
1194
+ const {
1195
+ collectionType,
1196
+ model,
1197
+ id,
1198
+ components,
1199
+ isLoading: isLoadingDoc,
1200
+ schema,
1201
+ schemas
1202
+ } = useDoc();
1203
+ const layout = useDocumentLayout(model);
1204
+ const form = useForm("useContentManagerContext", (state) => state);
1205
+ const isSingleType = collectionType === SINGLE_TYPES;
1206
+ const slug = model;
1207
+ const isCreatingEntry = id === "create";
1208
+ useContentTypeSchema();
1209
+ const isLoading = isLoadingDoc || layout.isLoading;
1210
+ const error = layout.error;
1211
+ return {
1212
+ error,
1213
+ isLoading,
1214
+ // Base metadata
1215
+ model,
1216
+ collectionType,
1217
+ id,
1218
+ slug,
1219
+ isCreatingEntry,
1220
+ isSingleType,
1221
+ hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
1222
+ // All schema infos
1223
+ components,
1224
+ contentType: schema,
1225
+ contentTypes: schemas,
1226
+ // Form state
1227
+ form,
1228
+ // layout infos
1229
+ layout
1230
+ };
1231
+ };
1232
+ const prefixPluginTranslations = (trad, pluginId) => {
1233
+ return Object.keys(trad).reduce((acc, current) => {
1234
+ acc[`${pluginId}.${current}`] = trad[current];
1235
+ return acc;
1236
+ }, {});
1237
+ };
1238
+ const getTranslation = (id) => `content-manager.${id}`;
1239
+ const DEFAULT_UNEXPECTED_ERROR_MSG = {
1240
+ id: "notification.error",
1241
+ defaultMessage: "An error occurred, please try again"
1242
+ };
1243
+ const useDocumentActions = () => {
1244
+ const { toggleNotification } = useNotification();
1245
+ const { formatMessage } = useIntl();
1246
+ const { trackUsage } = useTracking();
1247
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1248
+ const navigate = useNavigate();
1249
+ const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
1250
+ const [deleteDocument] = useDeleteDocumentMutation();
1251
+ const _delete = React.useCallback(
1252
+ async ({ collectionType, model, documentId, params }, trackerProperty) => {
1253
+ try {
1254
+ trackUsage("willDeleteEntry", trackerProperty);
1255
+ const res = await deleteDocument({
1256
+ collectionType,
1257
+ model,
1258
+ documentId,
1259
+ params
883
1260
  });
884
1261
  if ("error" in res) {
885
1262
  toggleNotification({
@@ -1184,6 +1561,7 @@ const useDocumentActions = () => {
1184
1561
  defaultMessage: "Saved document"
1185
1562
  })
1186
1563
  });
1564
+ setCurrentStep("contentManager.success");
1187
1565
  return res.data;
1188
1566
  } catch (err) {
1189
1567
  toggleNotification({
@@ -1223,7 +1601,7 @@ const useDocumentActions = () => {
1223
1601
  throw err;
1224
1602
  }
1225
1603
  },
1226
- [autoCloneDocument, formatAPIError, formatMessage, toggleNotification]
1604
+ [autoCloneDocument, formatMessage, toggleNotification]
1227
1605
  );
1228
1606
  const [cloneDocument] = useCloneDocumentMutation();
1229
1607
  const clone = React.useCallback(
@@ -1249,6 +1627,7 @@ const useDocumentActions = () => {
1249
1627
  defaultMessage: "Cloned document"
1250
1628
  })
1251
1629
  });
1630
+ navigate(`../../${res.data.data.documentId}`, { relative: "path" });
1252
1631
  return res.data;
1253
1632
  } catch (err) {
1254
1633
  toggleNotification({
@@ -1259,7 +1638,7 @@ const useDocumentActions = () => {
1259
1638
  throw err;
1260
1639
  }
1261
1640
  },
1262
- [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
1641
+ [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
1263
1642
  );
1264
1643
  const [getDoc] = useLazyGetDocumentQuery();
1265
1644
  const getDocument = React.useCallback(
@@ -1285,7 +1664,7 @@ const useDocumentActions = () => {
1285
1664
  };
1286
1665
  };
1287
1666
  const ProtectedHistoryPage = lazy(
1288
- () => import("./History-DR2txJLE.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1667
+ () => import("./History-BevwkPO1.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1289
1668
  );
1290
1669
  const routes$1 = [
1291
1670
  {
@@ -1298,31 +1677,31 @@ const routes$1 = [
1298
1677
  }
1299
1678
  ];
1300
1679
  const ProtectedEditViewPage = lazy(
1301
- () => import("./EditViewPage-B7VgwJaG.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1680
+ () => import("./EditViewPage-RXrFLav2.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1302
1681
  );
1303
1682
  const ProtectedListViewPage = lazy(
1304
- () => import("./ListViewPage-B_GaWgRH.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1683
+ () => import("./ListViewPage-C1PyuYRS.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1305
1684
  );
1306
1685
  const ProtectedListConfiguration = lazy(
1307
- () => import("./ListConfigurationPage-voFVtXu6.mjs").then((mod) => ({
1686
+ () => import("./ListConfigurationPage-DNfZDtDA.mjs").then((mod) => ({
1308
1687
  default: mod.ProtectedListConfiguration
1309
1688
  }))
1310
1689
  );
1311
1690
  const ProtectedEditConfigurationPage = lazy(
1312
- () => import("./EditConfigurationPage-D7PrLO8j.mjs").then((mod) => ({
1691
+ () => import("./EditConfigurationPage-DqL8Pq5r.mjs").then((mod) => ({
1313
1692
  default: mod.ProtectedEditConfigurationPage
1314
1693
  }))
1315
1694
  );
1316
1695
  const ProtectedComponentConfigurationPage = lazy(
1317
- () => import("./ComponentConfigurationPage-B3yDbeU1.mjs").then((mod) => ({
1696
+ () => import("./ComponentConfigurationPage-TYDPg5WG.mjs").then((mod) => ({
1318
1697
  default: mod.ProtectedComponentConfigurationPage
1319
1698
  }))
1320
1699
  );
1321
1700
  const NoPermissions = lazy(
1322
- () => import("./NoPermissionsPage-B5baIHal.mjs").then((mod) => ({ default: mod.NoPermissions }))
1701
+ () => import("./NoPermissionsPage-8BM-LWta.mjs").then((mod) => ({ default: mod.NoPermissions }))
1323
1702
  );
1324
1703
  const NoContentType = lazy(
1325
- () => import("./NoContentTypePage-CYiGpsbj.mjs").then((mod) => ({ default: mod.NoContentType }))
1704
+ () => import("./NoContentTypePage-C9q744z1.mjs").then((mod) => ({ default: mod.NoContentType }))
1326
1705
  );
1327
1706
  const CollectionTypePages = () => {
1328
1707
  const { collectionType } = useParams();
@@ -1503,7 +1882,7 @@ const DocumentActionsMenu = ({
1503
1882
  };
1504
1883
  return /* @__PURE__ */ jsxs(Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
1505
1884
  /* @__PURE__ */ jsxs(
1506
- StyledMoreButton,
1885
+ Menu.Trigger,
1507
1886
  {
1508
1887
  disabled: isDisabled,
1509
1888
  size: "S",
@@ -1521,7 +1900,7 @@ const DocumentActionsMenu = ({
1521
1900
  ]
1522
1901
  }
1523
1902
  ),
1524
- /* @__PURE__ */ jsxs(Menu.Content, { top: "4px", maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1903
+ /* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1525
1904
  actions2.map((action) => {
1526
1905
  return /* @__PURE__ */ jsx(
1527
1906
  Menu.Item,
@@ -1619,11 +1998,6 @@ const convertActionVariantToIconColor = (variant = "secondary") => {
1619
1998
  return "primary600";
1620
1999
  }
1621
2000
  };
1622
- const StyledMoreButton = styled(Menu.Trigger)`
1623
- & > span {
1624
- display: flex;
1625
- }
1626
- `;
1627
2001
  const DocumentActionConfirmDialog = ({
1628
2002
  onClose,
1629
2003
  onCancel,
@@ -1650,11 +2024,11 @@ const DocumentActionConfirmDialog = ({
1650
2024
  /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
1651
2025
  /* @__PURE__ */ jsx(Dialog.Body, { children: content }),
1652
2026
  /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
1653
- /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({
2027
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
1654
2028
  id: "app.components.Button.cancel",
1655
2029
  defaultMessage: "Cancel"
1656
2030
  }) }) }),
1657
- /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, children: formatMessage({
2031
+ /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
1658
2032
  id: "app.components.Button.confirm",
1659
2033
  defaultMessage: "Confirm"
1660
2034
  }) })
@@ -1681,6 +2055,18 @@ const DocumentActionModal = ({
1681
2055
  typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
1682
2056
  ] }) });
1683
2057
  };
2058
+ const transformData = (data) => {
2059
+ if (Array.isArray(data)) {
2060
+ return data.map(transformData);
2061
+ }
2062
+ if (typeof data === "object" && data !== null) {
2063
+ if ("apiData" in data) {
2064
+ return data.apiData;
2065
+ }
2066
+ return mapValues(transformData)(data);
2067
+ }
2068
+ return data;
2069
+ };
1684
2070
  const PublishAction$1 = ({
1685
2071
  activeTab,
1686
2072
  documentId,
@@ -1693,12 +2079,10 @@ const PublishAction$1 = ({
1693
2079
  const navigate = useNavigate();
1694
2080
  const { toggleNotification } = useNotification();
1695
2081
  const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
2082
+ const isListView = useMatch(LIST_PATH) !== null;
1696
2083
  const isCloning = useMatch(CLONE_PATH) !== null;
1697
2084
  const { formatMessage } = useIntl();
1698
- const { canPublish, canCreate, canUpdate } = useDocumentRBAC(
1699
- "PublishAction",
1700
- ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
1701
- );
2085
+ const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
1702
2086
  const { publish } = useDocumentActions();
1703
2087
  const [
1704
2088
  countDraftRelations,
@@ -1750,24 +2134,25 @@ const PublishAction$1 = ({
1750
2134
  }
1751
2135
  }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
1752
2136
  React.useEffect(() => {
1753
- if (documentId) {
1754
- const fetchDraftRelationsCount = async () => {
1755
- const { data, error } = await countDraftRelations({
1756
- collectionType,
1757
- model,
1758
- documentId,
1759
- params
1760
- });
1761
- if (error) {
1762
- throw error;
1763
- }
1764
- if (data) {
1765
- setServerCountOfDraftRelations(data.data);
1766
- }
1767
- };
1768
- fetchDraftRelationsCount();
2137
+ if (!document || !document.documentId || isListView) {
2138
+ return;
1769
2139
  }
1770
- }, [documentId, countDraftRelations, collectionType, model, params]);
2140
+ const fetchDraftRelationsCount = async () => {
2141
+ const { data, error } = await countDraftRelations({
2142
+ collectionType,
2143
+ model,
2144
+ documentId,
2145
+ params
2146
+ });
2147
+ if (error) {
2148
+ throw error;
2149
+ }
2150
+ if (data) {
2151
+ setServerCountOfDraftRelations(data.data);
2152
+ }
2153
+ };
2154
+ fetchDraftRelationsCount();
2155
+ }, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
1771
2156
  const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
1772
2157
  if (!schema?.options?.draftAndPublish) {
1773
2158
  return null;
@@ -1775,7 +2160,9 @@ const PublishAction$1 = ({
1775
2160
  const performPublish = async () => {
1776
2161
  setSubmitting(true);
1777
2162
  try {
1778
- const { errors } = await validate();
2163
+ const { errors } = await validate(true, {
2164
+ status: "published"
2165
+ });
1779
2166
  if (errors) {
1780
2167
  toggleNotification({
1781
2168
  type: "danger",
@@ -1793,7 +2180,7 @@ const PublishAction$1 = ({
1793
2180
  documentId,
1794
2181
  params
1795
2182
  },
1796
- formValues
2183
+ transformData(formValues)
1797
2184
  );
1798
2185
  if ("data" in res && collectionType !== SINGLE_TYPES) {
1799
2186
  navigate({
@@ -1808,7 +2195,8 @@ const PublishAction$1 = ({
1808
2195
  }
1809
2196
  };
1810
2197
  const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
1811
- const hasDraftRelations = totalDraftRelations > 0;
2198
+ const enableDraftRelationsCount = false;
2199
+ const hasDraftRelations = enableDraftRelationsCount;
1812
2200
  return {
1813
2201
  /**
1814
2202
  * Disabled when:
@@ -1825,9 +2213,6 @@ const PublishAction$1 = ({
1825
2213
  defaultMessage: "Publish"
1826
2214
  }),
1827
2215
  onClick: async () => {
1828
- if (hasDraftRelations) {
1829
- return;
1830
- }
1831
2216
  await performPublish();
1832
2217
  },
1833
2218
  dialog: hasDraftRelations ? {
@@ -1866,10 +2251,6 @@ const UpdateAction = ({
1866
2251
  const cloneMatch = useMatch(CLONE_PATH);
1867
2252
  const isCloning = cloneMatch !== null;
1868
2253
  const { formatMessage } = useIntl();
1869
- useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
1870
- canCreate: canCreate2,
1871
- canUpdate: canUpdate2
1872
- }));
1873
2254
  const { create, update, clone } = useDocumentActions();
1874
2255
  const [{ query, rawQuery }] = useQueryParams();
1875
2256
  const params = React.useMemo(() => buildValidParams(query), [query]);
@@ -1895,7 +2276,9 @@ const UpdateAction = ({
1895
2276
  onClick: async () => {
1896
2277
  setSubmitting(true);
1897
2278
  try {
1898
- const { errors } = await validate();
2279
+ const { errors } = await validate(true, {
2280
+ status: "draft"
2281
+ });
1899
2282
  if (errors) {
1900
2283
  toggleNotification({
1901
2284
  type: "danger",
@@ -1913,7 +2296,7 @@ const UpdateAction = ({
1913
2296
  documentId: cloneMatch.params.origin,
1914
2297
  params
1915
2298
  },
1916
- document
2299
+ transformData(document)
1917
2300
  );
1918
2301
  if ("data" in res) {
1919
2302
  navigate(
@@ -1934,7 +2317,7 @@ const UpdateAction = ({
1934
2317
  documentId,
1935
2318
  params
1936
2319
  },
1937
- document
2320
+ transformData(document)
1938
2321
  );
1939
2322
  if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1940
2323
  setErrors(formatValidationErrors(res.error));
@@ -1947,7 +2330,7 @@ const UpdateAction = ({
1947
2330
  model,
1948
2331
  params
1949
2332
  },
1950
- document
2333
+ transformData(document)
1951
2334
  );
1952
2335
  if ("data" in res && collectionType !== SINGLE_TYPES) {
1953
2336
  navigate(
@@ -2000,7 +2383,7 @@ const UnpublishAction$1 = ({
2000
2383
  id: "app.utils.unpublish",
2001
2384
  defaultMessage: "Unpublish"
2002
2385
  }),
2003
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2386
+ icon: /* @__PURE__ */ jsx(Cross, {}),
2004
2387
  onClick: async () => {
2005
2388
  if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
2006
2389
  if (!documentId) {
@@ -2112,7 +2495,7 @@ const DiscardAction = ({
2112
2495
  id: "content-manager.actions.discard.label",
2113
2496
  defaultMessage: "Discard changes"
2114
2497
  }),
2115
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2498
+ icon: /* @__PURE__ */ jsx(Cross, {}),
2116
2499
  position: ["panel", "table-row"],
2117
2500
  variant: "danger",
2118
2501
  dialog: {
@@ -2140,11 +2523,6 @@ const DiscardAction = ({
2140
2523
  };
2141
2524
  };
2142
2525
  DiscardAction.type = "discard";
2143
- const StyledCrossCircle = styled(CrossCircle)`
2144
- path {
2145
- fill: currentColor;
2146
- }
2147
- `;
2148
2526
  const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
2149
2527
  const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
2150
2528
  const RelativeTime = React.forwardRef(
@@ -2192,7 +2570,7 @@ const getDisplayName = ({
2192
2570
  };
2193
2571
  const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2194
2572
  const DocumentStatus = ({ status = "draft", ...restProps }) => {
2195
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
2573
+ const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
2196
2574
  return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
2197
2575
  };
2198
2576
  const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
@@ -2291,12 +2669,12 @@ const Information = ({ activeTab }) => {
2291
2669
  isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
2292
2670
  label: formatMessage({
2293
2671
  id: "content-manager.containers.edit.information.last-published.label",
2294
- defaultMessage: "Last published"
2672
+ defaultMessage: "Published"
2295
2673
  }),
2296
2674
  value: formatMessage(
2297
2675
  {
2298
2676
  id: "content-manager.containers.edit.information.last-published.value",
2299
- defaultMessage: `Published {time}{isAnonymous, select, true {} other { by {author}}}`
2677
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2300
2678
  },
2301
2679
  {
2302
2680
  time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
@@ -2309,12 +2687,12 @@ const Information = ({ activeTab }) => {
2309
2687
  isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
2310
2688
  label: formatMessage({
2311
2689
  id: "content-manager.containers.edit.information.last-draft.label",
2312
- defaultMessage: "Last draft"
2690
+ defaultMessage: "Updated"
2313
2691
  }),
2314
2692
  value: formatMessage(
2315
2693
  {
2316
2694
  id: "content-manager.containers.edit.information.last-draft.value",
2317
- defaultMessage: `Modified {time}{isAnonymous, select, true {} other { by {author}}}`
2695
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2318
2696
  },
2319
2697
  {
2320
2698
  time: /* @__PURE__ */ jsx(
@@ -2332,12 +2710,12 @@ const Information = ({ activeTab }) => {
2332
2710
  isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
2333
2711
  label: formatMessage({
2334
2712
  id: "content-manager.containers.edit.information.document.label",
2335
- defaultMessage: "Document"
2713
+ defaultMessage: "Created"
2336
2714
  }),
2337
2715
  value: formatMessage(
2338
2716
  {
2339
2717
  id: "content-manager.containers.edit.information.document.value",
2340
- defaultMessage: `Created {time}{isAnonymous, select, true {} other { by {author}}}`
2718
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2341
2719
  },
2342
2720
  {
2343
2721
  time: /* @__PURE__ */ jsx(
@@ -2375,523 +2753,277 @@ const Information = ({ activeTab }) => {
2375
2753
  );
2376
2754
  };
2377
2755
  const HeaderActions = ({ actions: actions2 }) => {
2378
- return /* @__PURE__ */ jsx(Flex, { children: actions2.map((action) => {
2379
- if ("options" in action) {
2756
+ const [dialogId, setDialogId] = React.useState(null);
2757
+ const handleClick = (action) => async (e) => {
2758
+ if (!("options" in action)) {
2759
+ const { onClick = () => false, dialog, id } = action;
2760
+ const muteDialog = await onClick(e);
2761
+ if (dialog && !muteDialog) {
2762
+ e.preventDefault();
2763
+ setDialogId(id);
2764
+ }
2765
+ }
2766
+ };
2767
+ const handleClose = () => {
2768
+ setDialogId(null);
2769
+ };
2770
+ return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
2771
+ if (action.options) {
2380
2772
  return /* @__PURE__ */ jsx(
2381
2773
  SingleSelect,
2382
2774
  {
2383
2775
  size: "S",
2384
- disabled: action.disabled,
2385
- "aria-label": action.label,
2386
2776
  onChange: action.onSelect,
2387
- value: action.value,
2777
+ "aria-label": action.label,
2778
+ ...action,
2388
2779
  children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
2389
2780
  },
2390
2781
  action.id
2391
2782
  );
2392
2783
  } else {
2393
- return null;
2394
- }
2395
- }) });
2396
- };
2397
- const ConfigureTheViewAction = ({ collectionType, model }) => {
2398
- const navigate = useNavigate();
2399
- const { formatMessage } = useIntl();
2400
- return {
2401
- label: formatMessage({
2402
- id: "app.links.configure-view",
2403
- defaultMessage: "Configure the view"
2404
- }),
2405
- icon: /* @__PURE__ */ jsx(ListPlus, {}),
2406
- onClick: () => {
2407
- navigate(`../${collectionType}/${model}/configurations/edit`);
2408
- },
2409
- position: "header"
2410
- };
2411
- };
2412
- ConfigureTheViewAction.type = "configure-the-view";
2413
- const EditTheModelAction = ({ model }) => {
2414
- const navigate = useNavigate();
2415
- const { formatMessage } = useIntl();
2416
- return {
2417
- label: formatMessage({
2418
- id: "content-manager.link-to-ctb",
2419
- defaultMessage: "Edit the model"
2420
- }),
2421
- icon: /* @__PURE__ */ jsx(Pencil, {}),
2422
- onClick: () => {
2423
- navigate(`/plugins/content-type-builder/content-types/${model}`);
2424
- },
2425
- position: "header"
2426
- };
2427
- };
2428
- EditTheModelAction.type = "edit-the-model";
2429
- const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2430
- const navigate = useNavigate();
2431
- const { formatMessage } = useIntl();
2432
- const listViewPathMatch = useMatch(LIST_PATH);
2433
- const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
2434
- const { delete: deleteAction } = useDocumentActions();
2435
- const { toggleNotification } = useNotification();
2436
- const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
2437
- return {
2438
- disabled: !canDelete || !document,
2439
- label: formatMessage({
2440
- id: "content-manager.actions.delete.label",
2441
- defaultMessage: "Delete document"
2442
- }),
2443
- icon: /* @__PURE__ */ jsx(Trash, {}),
2444
- dialog: {
2445
- type: "dialog",
2446
- title: formatMessage({
2447
- id: "app.components.ConfirmDialog.title",
2448
- defaultMessage: "Confirmation"
2449
- }),
2450
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
2451
- /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2452
- /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2453
- id: "content-manager.actions.delete.dialog.body",
2454
- defaultMessage: "Are you sure?"
2455
- }) })
2456
- ] }),
2457
- onConfirm: async () => {
2458
- if (!listViewPathMatch) {
2459
- setSubmitting(true);
2460
- }
2461
- try {
2462
- if (!documentId && collectionType !== SINGLE_TYPES) {
2463
- console.error(
2464
- "You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
2465
- );
2466
- toggleNotification({
2467
- message: formatMessage({
2468
- id: "content-manager.actions.delete.error",
2469
- defaultMessage: "An error occurred while trying to delete the document."
2470
- }),
2471
- type: "danger"
2472
- });
2473
- return;
2474
- }
2475
- const res = await deleteAction({
2476
- documentId,
2477
- model,
2478
- collectionType,
2479
- params: {
2480
- locale: "*"
2784
+ if (action.type === "icon") {
2785
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2786
+ /* @__PURE__ */ jsx(
2787
+ IconButton,
2788
+ {
2789
+ disabled: action.disabled,
2790
+ label: action.label,
2791
+ size: "S",
2792
+ onClick: handleClick(action),
2793
+ children: action.icon
2481
2794
  }
2482
- });
2483
- if (!("error" in res)) {
2484
- navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
2485
- }
2486
- } finally {
2487
- if (!listViewPathMatch) {
2488
- setSubmitting(false);
2489
- }
2490
- }
2795
+ ),
2796
+ action.dialog ? /* @__PURE__ */ jsx(
2797
+ HeaderActionDialog,
2798
+ {
2799
+ ...action.dialog,
2800
+ isOpen: dialogId === action.id,
2801
+ onClose: handleClose
2802
+ }
2803
+ ) : null
2804
+ ] }, action.id);
2491
2805
  }
2492
- },
2493
- variant: "danger",
2494
- position: ["header", "table-row"]
2495
- };
2496
- };
2497
- DeleteAction$1.type = "delete";
2498
- const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
2499
- const Panels = () => {
2500
- const isCloning = useMatch(CLONE_PATH) !== null;
2501
- const [
2502
- {
2503
- query: { status }
2504
- }
2505
- ] = useQueryParams({
2506
- status: "draft"
2507
- });
2508
- const { model, id, document, meta, collectionType } = useDoc();
2509
- const plugins = useStrapiApp("Panels", (state) => state.plugins);
2510
- const props = {
2511
- activeTab: status,
2512
- model,
2513
- documentId: id,
2514
- document: isCloning ? void 0 : document,
2515
- meta: isCloning ? void 0 : meta,
2516
- collectionType
2517
- };
2518
- return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
2519
- DescriptionComponentRenderer,
2520
- {
2521
- props,
2522
- descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
2523
- children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
2524
2806
  }
2525
- ) });
2526
- };
2527
- const ActionsPanel = () => {
2528
- const { formatMessage } = useIntl();
2529
- return {
2530
- title: formatMessage({
2531
- id: "content-manager.containers.edit.panels.default.title",
2532
- defaultMessage: "Document"
2533
- }),
2534
- content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
2535
- };
2536
- };
2537
- ActionsPanel.type = "actions";
2538
- const ActionsPanelContent = () => {
2539
- const isCloning = useMatch(CLONE_PATH) !== null;
2540
- const [
2541
- {
2542
- query: { status = "draft" }
2543
- }
2544
- ] = useQueryParams();
2545
- const { model, id, document, meta, collectionType } = useDoc();
2546
- const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
2547
- const props = {
2548
- activeTab: status,
2549
- model,
2550
- documentId: id,
2551
- document: isCloning ? void 0 : document,
2552
- meta: isCloning ? void 0 : meta,
2553
- collectionType
2554
- };
2555
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
2556
- /* @__PURE__ */ jsx(
2557
- DescriptionComponentRenderer,
2558
- {
2559
- props,
2560
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
2561
- children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
2562
- }
2563
- ),
2564
- /* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
2565
- ] });
2807
+ }) });
2566
2808
  };
2567
- const Panel = React.forwardRef(({ children, title }, ref) => {
2568
- return /* @__PURE__ */ jsxs(
2569
- Flex,
2570
- {
2571
- ref,
2572
- tag: "aside",
2573
- "aria-labelledby": "additional-information",
2574
- background: "neutral0",
2575
- borderColor: "neutral150",
2576
- hasRadius: true,
2577
- paddingBottom: 4,
2578
- paddingLeft: 4,
2579
- paddingRight: 4,
2580
- paddingTop: 4,
2581
- shadow: "tableShadow",
2582
- gap: 3,
2583
- direction: "column",
2584
- justifyContent: "stretch",
2585
- alignItems: "flex-start",
2586
- children: [
2587
- /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
2588
- children
2589
- ]
2809
+ const HeaderActionDialog = ({
2810
+ onClose,
2811
+ onCancel,
2812
+ title,
2813
+ content: Content,
2814
+ isOpen
2815
+ }) => {
2816
+ const handleClose = async () => {
2817
+ if (onCancel) {
2818
+ await onCancel();
2590
2819
  }
2591
- );
2592
- });
2593
- const HOOKS = {
2594
- /**
2595
- * Hook that allows to mutate the displayed headers of the list view table
2596
- * @constant
2597
- * @type {string}
2598
- */
2599
- INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
2600
- /**
2601
- * Hook that allows to mutate the CM's collection types links pre-set filters
2602
- * @constant
2603
- * @type {string}
2604
- */
2605
- MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
2606
- /**
2607
- * Hook that allows to mutate the CM's edit view layout
2608
- * @constant
2609
- * @type {string}
2610
- */
2611
- MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
2612
- /**
2613
- * Hook that allows to mutate the CM's single types links pre-set filters
2614
- * @constant
2615
- * @type {string}
2616
- */
2617
- MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
2820
+ onClose();
2821
+ };
2822
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2823
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2824
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
2825
+ ] }) });
2618
2826
  };
2619
- const contentTypesApi = contentManagerApi.injectEndpoints({
2620
- endpoints: (builder) => ({
2621
- getContentTypeConfiguration: builder.query({
2622
- query: (uid) => ({
2623
- url: `/content-manager/content-types/${uid}/configuration`,
2624
- method: "GET"
2625
- }),
2626
- transformResponse: (response) => response.data,
2627
- providesTags: (_result, _error, uid) => [
2628
- { type: "ContentTypesConfiguration", id: uid },
2629
- { type: "ContentTypeSettings", id: "LIST" }
2630
- ]
2631
- }),
2632
- getAllContentTypeSettings: builder.query({
2633
- query: () => "/content-manager/content-types-settings",
2634
- transformResponse: (response) => response.data,
2635
- providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
2827
+ const ConfigureTheViewAction = ({ collectionType, model }) => {
2828
+ const navigate = useNavigate();
2829
+ const { formatMessage } = useIntl();
2830
+ return {
2831
+ label: formatMessage({
2832
+ id: "app.links.configure-view",
2833
+ defaultMessage: "Configure the view"
2636
2834
  }),
2637
- updateContentTypeConfiguration: builder.mutation({
2638
- query: ({ uid, ...body }) => ({
2639
- url: `/content-manager/content-types/${uid}/configuration`,
2640
- method: "PUT",
2641
- data: body
2642
- }),
2643
- transformResponse: (response) => response.data,
2644
- invalidatesTags: (_result, _error, { uid }) => [
2645
- { type: "ContentTypesConfiguration", id: uid },
2646
- { type: "ContentTypeSettings", id: "LIST" },
2647
- // Is this necessary?
2648
- { type: "InitialData" }
2649
- ]
2650
- })
2651
- })
2652
- });
2653
- const {
2654
- useGetContentTypeConfigurationQuery,
2655
- useGetAllContentTypeSettingsQuery,
2656
- useUpdateContentTypeConfigurationMutation
2657
- } = contentTypesApi;
2658
- const checkIfAttributeIsDisplayable = (attribute) => {
2659
- const { type } = attribute;
2660
- if (type === "relation") {
2661
- return !attribute.relation.toLowerCase().includes("morph");
2662
- }
2663
- return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
2835
+ icon: /* @__PURE__ */ jsx(ListPlus, {}),
2836
+ onClick: () => {
2837
+ navigate(`../${collectionType}/${model}/configurations/edit`);
2838
+ },
2839
+ position: "header"
2840
+ };
2664
2841
  };
2665
- const getMainField = (attribute, mainFieldName, { schemas, components }) => {
2666
- if (!mainFieldName) {
2667
- return void 0;
2668
- }
2669
- const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
2670
- // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
2671
- schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
2672
- );
2842
+ ConfigureTheViewAction.type = "configure-the-view";
2843
+ const EditTheModelAction = ({ model }) => {
2844
+ const navigate = useNavigate();
2845
+ const { formatMessage } = useIntl();
2673
2846
  return {
2674
- name: mainFieldName,
2675
- type: mainFieldType ?? "string"
2847
+ label: formatMessage({
2848
+ id: "content-manager.link-to-ctb",
2849
+ defaultMessage: "Edit the model"
2850
+ }),
2851
+ icon: /* @__PURE__ */ jsx(Pencil, {}),
2852
+ onClick: () => {
2853
+ navigate(`/plugins/content-type-builder/content-types/${model}`);
2854
+ },
2855
+ position: "header"
2676
2856
  };
2677
2857
  };
2678
- const DEFAULT_SETTINGS = {
2679
- bulkable: false,
2680
- filterable: false,
2681
- searchable: false,
2682
- pagination: false,
2683
- defaultSortBy: "",
2684
- defaultSortOrder: "asc",
2685
- mainField: "id",
2686
- pageSize: 10
2687
- };
2688
- const useDocumentLayout = (model) => {
2689
- const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
2690
- const [{ query }] = useQueryParams();
2691
- const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
2858
+ EditTheModelAction.type = "edit-the-model";
2859
+ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2860
+ const navigate = useNavigate();
2861
+ const { formatMessage } = useIntl();
2862
+ const listViewPathMatch = useMatch(LIST_PATH);
2863
+ const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
2864
+ const { delete: deleteAction } = useDocumentActions();
2692
2865
  const { toggleNotification } = useNotification();
2693
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
2694
- const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
2695
- const {
2696
- data,
2697
- isLoading: isLoadingConfigs,
2698
- error,
2699
- isFetching: isFetchingConfigs
2700
- } = useGetContentTypeConfigurationQuery(model);
2701
- const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
2702
- React.useEffect(() => {
2703
- if (error) {
2704
- toggleNotification({
2705
- type: "danger",
2706
- message: formatAPIError(error)
2707
- });
2708
- }
2709
- }, [error, formatAPIError, toggleNotification]);
2710
- const editLayout = React.useMemo(
2711
- () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
2712
- layout: [],
2713
- components: {},
2714
- metadatas: {},
2715
- options: {},
2716
- settings: DEFAULT_SETTINGS
2717
- },
2718
- [data, isLoading, schemas, schema, components]
2719
- );
2720
- const listLayout = React.useMemo(() => {
2721
- return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
2722
- layout: [],
2723
- metadatas: {},
2724
- options: {},
2725
- settings: DEFAULT_SETTINGS
2726
- };
2727
- }, [data, isLoading, schemas, schema, components]);
2728
- const { layout: edit } = React.useMemo(
2729
- () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
2730
- layout: editLayout,
2731
- query
2732
- }),
2733
- [editLayout, query, runHookWaterfall]
2734
- );
2866
+ const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
2867
+ const isLocalized = document?.locale != null;
2735
2868
  return {
2736
- error,
2737
- isLoading,
2738
- edit,
2739
- list: listLayout
2740
- };
2741
- };
2742
- const useDocLayout = () => {
2743
- const { model } = useDoc();
2744
- return useDocumentLayout(model);
2745
- };
2746
- const formatEditLayout = (data, {
2747
- schemas,
2748
- schema,
2749
- components
2750
- }) => {
2751
- let currentPanelIndex = 0;
2752
- const panelledEditAttributes = convertEditLayoutToFieldLayouts(
2753
- data.contentType.layouts.edit,
2754
- schema?.attributes,
2755
- data.contentType.metadatas,
2756
- { configurations: data.components, schemas: components },
2757
- schemas
2758
- ).reduce((panels, row) => {
2759
- if (row.some((field) => field.type === "dynamiczone")) {
2760
- panels.push([row]);
2761
- currentPanelIndex += 2;
2762
- } else {
2763
- if (!panels[currentPanelIndex]) {
2764
- panels.push([]);
2765
- }
2766
- panels[currentPanelIndex].push(row);
2767
- }
2768
- return panels;
2769
- }, []);
2770
- const componentEditAttributes = Object.entries(data.components).reduce(
2771
- (acc, [uid, configuration]) => {
2772
- acc[uid] = {
2773
- layout: convertEditLayoutToFieldLayouts(
2774
- configuration.layouts.edit,
2775
- components[uid].attributes,
2776
- configuration.metadatas
2777
- ),
2778
- settings: {
2779
- ...configuration.settings,
2780
- icon: components[uid].info.icon,
2781
- displayName: components[uid].info.displayName
2869
+ disabled: !canDelete || !document,
2870
+ label: formatMessage(
2871
+ {
2872
+ id: "content-manager.actions.delete.label",
2873
+ defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
2874
+ },
2875
+ { isLocalized }
2876
+ ),
2877
+ icon: /* @__PURE__ */ jsx(Trash, {}),
2878
+ dialog: {
2879
+ type: "dialog",
2880
+ title: formatMessage({
2881
+ id: "app.components.ConfirmDialog.title",
2882
+ defaultMessage: "Confirmation"
2883
+ }),
2884
+ content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
2885
+ /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2886
+ /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2887
+ id: "content-manager.actions.delete.dialog.body",
2888
+ defaultMessage: "Are you sure?"
2889
+ }) })
2890
+ ] }),
2891
+ onConfirm: async () => {
2892
+ if (!listViewPathMatch) {
2893
+ setSubmitting(true);
2894
+ }
2895
+ try {
2896
+ if (!documentId && collectionType !== SINGLE_TYPES) {
2897
+ console.error(
2898
+ "You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
2899
+ );
2900
+ toggleNotification({
2901
+ message: formatMessage({
2902
+ id: "content-manager.actions.delete.error",
2903
+ defaultMessage: "An error occurred while trying to delete the document."
2904
+ }),
2905
+ type: "danger"
2906
+ });
2907
+ return;
2908
+ }
2909
+ const res = await deleteAction({
2910
+ documentId,
2911
+ model,
2912
+ collectionType,
2913
+ params: {
2914
+ locale: "*"
2915
+ }
2916
+ });
2917
+ if (!("error" in res)) {
2918
+ navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
2919
+ }
2920
+ } finally {
2921
+ if (!listViewPathMatch) {
2922
+ setSubmitting(false);
2923
+ }
2782
2924
  }
2783
- };
2784
- return acc;
2785
- },
2786
- {}
2787
- );
2788
- const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
2789
- (acc, [attribute, metadata]) => {
2790
- return {
2791
- ...acc,
2792
- [attribute]: metadata.edit
2793
- };
2794
- },
2795
- {}
2796
- );
2797
- return {
2798
- layout: panelledEditAttributes,
2799
- components: componentEditAttributes,
2800
- metadatas: editMetadatas,
2801
- settings: {
2802
- ...data.contentType.settings,
2803
- displayName: schema?.info.displayName
2925
+ }
2804
2926
  },
2805
- options: {
2806
- ...schema?.options,
2807
- ...schema?.pluginOptions,
2808
- ...data.contentType.options
2809
- }
2927
+ variant: "danger",
2928
+ position: ["header", "table-row"]
2810
2929
  };
2811
2930
  };
2812
- const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
2813
- return rows.map(
2814
- (row) => row.map((field) => {
2815
- const attribute = attributes[field.name];
2816
- if (!attribute) {
2817
- return null;
2818
- }
2819
- const { edit: metadata } = metadatas[field.name];
2820
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
2821
- return {
2822
- attribute,
2823
- disabled: !metadata.editable,
2824
- hint: metadata.description,
2825
- label: metadata.label ?? "",
2826
- name: field.name,
2827
- // @ts-expect-error – mainField does exist on the metadata for a relation.
2828
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
2829
- schemas,
2830
- components: components?.schemas ?? {}
2831
- }),
2832
- placeholder: metadata.placeholder ?? "",
2833
- required: attribute.required ?? false,
2834
- size: field.size,
2835
- unique: "unique" in attribute ? attribute.unique : false,
2836
- visible: metadata.visible ?? true,
2837
- type: attribute.type
2838
- };
2839
- }).filter((field) => field !== null)
2840
- );
2931
+ DeleteAction$1.type = "delete";
2932
+ const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
2933
+ const Panels = () => {
2934
+ const isCloning = useMatch(CLONE_PATH) !== null;
2935
+ const [
2936
+ {
2937
+ query: { status }
2938
+ }
2939
+ ] = useQueryParams({
2940
+ status: "draft"
2941
+ });
2942
+ const { model, id, document, meta, collectionType } = useDoc();
2943
+ const plugins = useStrapiApp("Panels", (state) => state.plugins);
2944
+ const props = {
2945
+ activeTab: status,
2946
+ model,
2947
+ documentId: id,
2948
+ document: isCloning ? void 0 : document,
2949
+ meta: isCloning ? void 0 : meta,
2950
+ collectionType
2951
+ };
2952
+ return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
2953
+ DescriptionComponentRenderer,
2954
+ {
2955
+ props,
2956
+ descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
2957
+ children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
2958
+ }
2959
+ ) });
2841
2960
  };
2842
- const formatListLayout = (data, {
2843
- schemas,
2844
- schema,
2845
- components
2846
- }) => {
2847
- const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
2848
- (acc, [attribute, metadata]) => {
2849
- return {
2850
- ...acc,
2851
- [attribute]: metadata.list
2852
- };
2853
- },
2854
- {}
2855
- );
2856
- const listAttributes = convertListLayoutToFieldLayouts(
2857
- data.contentType.layouts.list,
2858
- schema?.attributes,
2859
- listMetadatas,
2860
- { configurations: data.components, schemas: components },
2861
- schemas
2862
- );
2961
+ const ActionsPanel = () => {
2962
+ const { formatMessage } = useIntl();
2863
2963
  return {
2864
- layout: listAttributes,
2865
- settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
2866
- metadatas: listMetadatas,
2867
- options: {
2868
- ...schema?.options,
2869
- ...schema?.pluginOptions,
2870
- ...data.contentType.options
2871
- }
2964
+ title: formatMessage({
2965
+ id: "content-manager.containers.edit.panels.default.title",
2966
+ defaultMessage: "Entry"
2967
+ }),
2968
+ content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
2872
2969
  };
2873
2970
  };
2874
- const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
2875
- return columns.map((name) => {
2876
- const attribute = attributes[name];
2877
- if (!attribute) {
2878
- return null;
2971
+ ActionsPanel.type = "actions";
2972
+ const ActionsPanelContent = () => {
2973
+ const isCloning = useMatch(CLONE_PATH) !== null;
2974
+ const [
2975
+ {
2976
+ query: { status = "draft" }
2879
2977
  }
2880
- const metadata = metadatas[name];
2881
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
2882
- return {
2883
- attribute,
2884
- label: metadata.label ?? "",
2885
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
2886
- schemas,
2887
- components: components?.schemas ?? {}
2888
- }),
2889
- name,
2890
- searchable: metadata.searchable ?? true,
2891
- sortable: metadata.sortable ?? true
2892
- };
2893
- }).filter((field) => field !== null);
2978
+ ] = useQueryParams();
2979
+ const { model, id, document, meta, collectionType } = useDoc();
2980
+ const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
2981
+ const props = {
2982
+ activeTab: status,
2983
+ model,
2984
+ documentId: id,
2985
+ document: isCloning ? void 0 : document,
2986
+ meta: isCloning ? void 0 : meta,
2987
+ collectionType
2988
+ };
2989
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
2990
+ /* @__PURE__ */ jsx(
2991
+ DescriptionComponentRenderer,
2992
+ {
2993
+ props,
2994
+ descriptions: plugins["content-manager"].apis.getDocumentActions(),
2995
+ children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
2996
+ }
2997
+ ),
2998
+ /* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
2999
+ ] });
2894
3000
  };
3001
+ const Panel = React.forwardRef(({ children, title }, ref) => {
3002
+ return /* @__PURE__ */ jsxs(
3003
+ Flex,
3004
+ {
3005
+ ref,
3006
+ tag: "aside",
3007
+ "aria-labelledby": "additional-information",
3008
+ background: "neutral0",
3009
+ borderColor: "neutral150",
3010
+ hasRadius: true,
3011
+ paddingBottom: 4,
3012
+ paddingLeft: 4,
3013
+ paddingRight: 4,
3014
+ paddingTop: 4,
3015
+ shadow: "tableShadow",
3016
+ gap: 3,
3017
+ direction: "column",
3018
+ justifyContent: "stretch",
3019
+ alignItems: "flex-start",
3020
+ children: [
3021
+ /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
3022
+ children
3023
+ ]
3024
+ }
3025
+ );
3026
+ });
2895
3027
  const ConfirmBulkActionDialog = ({
2896
3028
  onToggleDialog,
2897
3029
  isOpen = false,
@@ -2930,6 +3062,7 @@ const ConfirmDialogPublishAll = ({
2930
3062
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
2931
3063
  const { model, schema } = useDoc();
2932
3064
  const [{ query }] = useQueryParams();
3065
+ const enableDraftRelationsCount = false;
2933
3066
  const {
2934
3067
  data: countDraftRelations = 0,
2935
3068
  isLoading,
@@ -2941,7 +3074,7 @@ const ConfirmDialogPublishAll = ({
2941
3074
  locale: query?.plugins?.i18n?.locale
2942
3075
  },
2943
3076
  {
2944
- skip: selectedEntries.length === 0
3077
+ skip: !enableDraftRelationsCount
2945
3078
  }
2946
3079
  );
2947
3080
  React.useEffect(() => {
@@ -3126,7 +3259,7 @@ const SelectedEntriesTableContent = ({
3126
3259
  status: row.status
3127
3260
  }
3128
3261
  ) }),
3129
- /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
3262
+ /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3130
3263
  IconButton,
3131
3264
  {
3132
3265
  tag: Link,
@@ -3149,9 +3282,10 @@ const SelectedEntriesTableContent = ({
3149
3282
  ),
3150
3283
  target: "_blank",
3151
3284
  marginLeft: "auto",
3152
- children: /* @__PURE__ */ jsx(Pencil, {})
3285
+ variant: "ghost",
3286
+ children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
3153
3287
  }
3154
- ) })
3288
+ ) }) })
3155
3289
  ] }, row.id)) })
3156
3290
  ] });
3157
3291
  };
@@ -3188,7 +3322,13 @@ const SelectedEntriesModalContent = ({
3188
3322
  );
3189
3323
  const { rows, validationErrors } = React.useMemo(() => {
3190
3324
  if (data.length > 0 && schema) {
3191
- const validate = createYupSchema(schema.attributes, components);
3325
+ const validate = createYupSchema(
3326
+ schema.attributes,
3327
+ components,
3328
+ // Since this is the "Publish" action, the validation
3329
+ // schema must enforce the rules for published entities
3330
+ { status: "published" }
3331
+ );
3192
3332
  const validationErrors2 = {};
3193
3333
  const rows2 = data.map((entry) => {
3194
3334
  try {
@@ -3538,7 +3678,7 @@ const TableActions = ({ document }) => {
3538
3678
  DescriptionComponentRenderer,
3539
3679
  {
3540
3680
  props,
3541
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
3681
+ descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
3542
3682
  children: (actions2) => {
3543
3683
  const tableRowActions = actions2.filter((action) => {
3544
3684
  const positions = Array.isArray(action.position) ? action.position : [action.position];
@@ -3649,7 +3789,7 @@ const CloneAction = ({ model, documentId }) => {
3649
3789
  }),
3650
3790
  content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
3651
3791
  footer: ({ onClose }) => {
3652
- return /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
3792
+ return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3653
3793
  /* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
3654
3794
  id: "cancel",
3655
3795
  defaultMessage: "Cancel"
@@ -3861,6 +4001,97 @@ const { setInitialData } = actions;
3861
4001
  const reducer = combineReducers({
3862
4002
  app: reducer$1
3863
4003
  });
4004
+ const previewApi = contentManagerApi.injectEndpoints({
4005
+ endpoints: (builder) => ({
4006
+ getPreviewUrl: builder.query({
4007
+ query({ query, params }) {
4008
+ return {
4009
+ url: `/content-manager/preview/url/${params.contentType}`,
4010
+ method: "GET",
4011
+ config: {
4012
+ params: query
4013
+ }
4014
+ };
4015
+ }
4016
+ })
4017
+ })
4018
+ });
4019
+ const { useGetPreviewUrlQuery } = previewApi;
4020
+ const PreviewSidePanel = ({ model, documentId, document }) => {
4021
+ const { formatMessage } = useIntl();
4022
+ const { toggleNotification } = useNotification();
4023
+ const { copy } = useClipboard();
4024
+ const { trackUsage } = useTracking();
4025
+ const { data, error } = useGetPreviewUrlQuery({
4026
+ params: {
4027
+ contentType: model
4028
+ },
4029
+ query: {
4030
+ documentId,
4031
+ locale: document?.locale,
4032
+ status: document?.status
4033
+ }
4034
+ });
4035
+ if (!data?.data?.url || error) {
4036
+ return null;
4037
+ }
4038
+ const { url } = data.data;
4039
+ const handleCopyLink = () => {
4040
+ copy(url);
4041
+ toggleNotification({
4042
+ message: formatMessage({
4043
+ id: "content-manager.preview.copy.success",
4044
+ defaultMessage: "Copied preview link"
4045
+ }),
4046
+ type: "success"
4047
+ });
4048
+ };
4049
+ const handleClick = () => {
4050
+ trackUsage("willOpenPreview");
4051
+ };
4052
+ return {
4053
+ title: formatMessage({ id: "content-manager.preview.panel.title", defaultMessage: "Preview" }),
4054
+ content: /* @__PURE__ */ jsxs(Flex, { gap: 2, width: "100%", children: [
4055
+ /* @__PURE__ */ jsx(
4056
+ Button,
4057
+ {
4058
+ variant: "tertiary",
4059
+ tag: Link,
4060
+ to: url,
4061
+ onClick: handleClick,
4062
+ target: "_blank",
4063
+ flex: "auto",
4064
+ children: formatMessage({
4065
+ id: "content-manager.preview.panel.button",
4066
+ defaultMessage: "Open preview"
4067
+ })
4068
+ }
4069
+ ),
4070
+ /* @__PURE__ */ jsx(
4071
+ IconButton,
4072
+ {
4073
+ type: "button",
4074
+ label: formatMessage({
4075
+ id: "preview.copy.label",
4076
+ defaultMessage: "Copy preview link"
4077
+ }),
4078
+ onClick: handleCopyLink,
4079
+ children: /* @__PURE__ */ jsx(Link$1, {})
4080
+ }
4081
+ )
4082
+ ] })
4083
+ };
4084
+ };
4085
+ const FEATURE_ID = "preview";
4086
+ const previewAdmin = {
4087
+ bootstrap(app) {
4088
+ if (!window.strapi.future.isEnabled(FEATURE_ID)) {
4089
+ return;
4090
+ }
4091
+ const contentManagerPluginApis = app.getPlugin("content-manager").apis;
4092
+ contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
4093
+ }
4094
+ };
3864
4095
  const index = {
3865
4096
  register(app) {
3866
4097
  const cm = new ContentManagerPlugin();
@@ -3880,7 +4111,7 @@ const index = {
3880
4111
  app.router.addRoute({
3881
4112
  path: "content-manager/*",
3882
4113
  lazy: async () => {
3883
- const { Layout } = await import("./layout-BNqvLR_b.mjs");
4114
+ const { Layout } = await import("./layout-ykHSe2KQ.mjs");
3884
4115
  return {
3885
4116
  Component: Layout
3886
4117
  };
@@ -3893,11 +4124,14 @@ const index = {
3893
4124
  if (typeof historyAdmin.bootstrap === "function") {
3894
4125
  historyAdmin.bootstrap(app);
3895
4126
  }
4127
+ if (typeof previewAdmin.bootstrap === "function") {
4128
+ previewAdmin.bootstrap(app);
4129
+ }
3896
4130
  },
3897
4131
  async registerTrads({ locales }) {
3898
4132
  const importedTrads = await Promise.all(
3899
4133
  locales.map((locale) => {
3900
- 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-BrCTWlZv.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 }) => {
4134
+ 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-CZw4xdPY.mjs"), "./translations/es.json": () => import("./es-D34tqjMw.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr--pg5jUbt.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-BHqhDq4V.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 }) => {
3901
4135
  return {
3902
4136
  data: prefixPluginTranslations(data, PLUGIN_ID),
3903
4137
  locale
@@ -3918,13 +4152,15 @@ export {
3918
4152
  BulkActionsRenderer as B,
3919
4153
  COLLECTION_TYPES as C,
3920
4154
  DocumentStatus as D,
3921
- DEFAULT_SETTINGS as E,
3922
- convertEditLayoutToFieldLayouts as F,
3923
- useDocument as G,
4155
+ extractContentTypeComponents as E,
4156
+ DEFAULT_SETTINGS as F,
4157
+ convertEditLayoutToFieldLayouts as G,
3924
4158
  HOOKS as H,
3925
4159
  InjectionZone as I,
3926
- index as J,
3927
- useDocumentActions as K,
4160
+ useDocument as J,
4161
+ index as K,
4162
+ useContentManagerContext as L,
4163
+ useDocumentActions as M,
3928
4164
  Panels as P,
3929
4165
  RelativeTime as R,
3930
4166
  SINGLE_TYPES as S,
@@ -3942,18 +4178,18 @@ export {
3942
4178
  PERMISSIONS as k,
3943
4179
  DocumentRBAC as l,
3944
4180
  DOCUMENT_META_FIELDS as m,
3945
- useDocLayout as n,
3946
- useGetContentTypeConfigurationQuery as o,
3947
- CREATOR_FIELDS as p,
3948
- getMainField as q,
3949
- getDisplayName as r,
4181
+ CLONE_PATH as n,
4182
+ useDocLayout as o,
4183
+ useGetContentTypeConfigurationQuery as p,
4184
+ CREATOR_FIELDS as q,
4185
+ getMainField as r,
3950
4186
  setInitialData as s,
3951
- checkIfAttributeIsDisplayable as t,
4187
+ getDisplayName as t,
3952
4188
  useContentTypeSchema as u,
3953
- useGetAllDocumentsQuery as v,
3954
- convertListLayoutToFieldLayouts as w,
3955
- capitalise as x,
3956
- useUpdateContentTypeConfigurationMutation as y,
3957
- extractContentTypeComponents as z
4189
+ checkIfAttributeIsDisplayable as v,
4190
+ useGetAllDocumentsQuery as w,
4191
+ convertListLayoutToFieldLayouts as x,
4192
+ capitalise as y,
4193
+ useUpdateContentTypeConfigurationMutation as z
3958
4194
  };
3959
- //# sourceMappingURL=index-C9TJPyni.mjs.map
4195
+ //# sourceMappingURL=index-BvGihCJp.mjs.map