@strapi/content-manager 0.0.0-experimental.e60ec1829240dae21c1e1d29076681c322288813 → 0.0.0-experimental.eba25ec571b091c6bde1104eb6c753debdf15462

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 (253) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{CardDragPreview-DSVYodBX.js → CardDragPreview-C0QyJgRA.js} +10 -14
  3. package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -0
  4. package/dist/_chunks/{CardDragPreview-ikSG4M46.mjs → CardDragPreview-DOxamsuj.mjs} +7 -9
  5. package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -0
  6. package/dist/_chunks/{ComponentConfigurationPage-BPvzFjM7.mjs → ComponentConfigurationPage-BaJMOQyq.mjs} +4 -4
  7. package/dist/_chunks/{ComponentConfigurationPage-BPvzFjM7.mjs.map → ComponentConfigurationPage-BaJMOQyq.mjs.map} +1 -1
  8. package/dist/_chunks/{ComponentConfigurationPage-DjWJdz6Y.js → ComponentConfigurationPage-N-CTtgQa.js} +4 -4
  9. package/dist/_chunks/{ComponentConfigurationPage-DjWJdz6Y.js.map → ComponentConfigurationPage-N-CTtgQa.js.map} +1 -1
  10. package/dist/_chunks/{ComponentIcon-BBQsYCVn.js → ComponentIcon-BXdiCGQp.js} +8 -2
  11. package/dist/_chunks/ComponentIcon-BXdiCGQp.js.map +1 -0
  12. package/dist/_chunks/{ComponentIcon-BOFnK76n.mjs → ComponentIcon-u4bIXTFY.mjs} +9 -3
  13. package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -0
  14. package/dist/_chunks/{EditConfigurationPage-Dmv83RlS.js → EditConfigurationPage-BHkjAbxH.js} +4 -4
  15. package/dist/_chunks/{EditConfigurationPage-Dmv83RlS.js.map → EditConfigurationPage-BHkjAbxH.js.map} +1 -1
  16. package/dist/_chunks/{EditConfigurationPage-DacbqQ_f.mjs → EditConfigurationPage-CKK-5LfX.mjs} +4 -4
  17. package/dist/_chunks/{EditConfigurationPage-DacbqQ_f.mjs.map → EditConfigurationPage-CKK-5LfX.mjs.map} +1 -1
  18. package/dist/_chunks/EditViewPage-B11aeMcf.mjs +254 -0
  19. package/dist/_chunks/EditViewPage-B11aeMcf.mjs.map +1 -0
  20. package/dist/_chunks/{EditViewPage-DvNpQkam.js → EditViewPage-QPUftxUd.js} +101 -52
  21. package/dist/_chunks/EditViewPage-QPUftxUd.js.map +1 -0
  22. package/dist/_chunks/{Field-6gvGdPBV.mjs → Field-Bj_RgtGo.mjs} +1077 -814
  23. package/dist/_chunks/Field-Bj_RgtGo.mjs.map +1 -0
  24. package/dist/_chunks/{Field-DmVKIAOo.js → Field-DUK83cfh.js} +1121 -859
  25. package/dist/_chunks/Field-DUK83cfh.js.map +1 -0
  26. package/dist/_chunks/{Form-CPZC9vWa.js → Form-DHmBRlHd.js} +66 -46
  27. package/dist/_chunks/Form-DHmBRlHd.js.map +1 -0
  28. package/dist/_chunks/{Form-DW6K1IH-.mjs → Form-DLMSoXV7.mjs} +66 -45
  29. package/dist/_chunks/Form-DLMSoXV7.mjs.map +1 -0
  30. package/dist/_chunks/{History-Dmr9fmUA.mjs → History-CfCSNlG9.mjs} +181 -144
  31. package/dist/_chunks/History-CfCSNlG9.mjs.map +1 -0
  32. package/dist/_chunks/{History-DeAPlvtv.js → History-Di3zm4HT.js} +181 -145
  33. package/dist/_chunks/History-Di3zm4HT.js.map +1 -0
  34. package/dist/_chunks/{ListConfigurationPage-DhwvYcNv.mjs → ListConfigurationPage-0mtv_iqk.mjs} +67 -56
  35. package/dist/_chunks/ListConfigurationPage-0mtv_iqk.mjs.map +1 -0
  36. package/dist/_chunks/{ListConfigurationPage-DPCwW5Vr.js → ListConfigurationPage-Cq361KIt.js} +70 -60
  37. package/dist/_chunks/ListConfigurationPage-Cq361KIt.js.map +1 -0
  38. package/dist/_chunks/{ListViewPage-BtAwuYLE.mjs → ListViewPage-BxLVROX8.mjs} +175 -159
  39. package/dist/_chunks/ListViewPage-BxLVROX8.mjs.map +1 -0
  40. package/dist/_chunks/{ListViewPage-5ySZ-VUs.js → ListViewPage-DFDcG8gM.js} +178 -162
  41. package/dist/_chunks/ListViewPage-DFDcG8gM.js.map +1 -0
  42. package/dist/_chunks/{NoContentTypePage-DSPxnxxp.mjs → NoContentTypePage-BRfDd67_.mjs} +3 -3
  43. package/dist/_chunks/NoContentTypePage-BRfDd67_.mjs.map +1 -0
  44. package/dist/_chunks/{NoContentTypePage-DOC_yWOf.js → NoContentTypePage-BSyvnDZZ.js} +3 -3
  45. package/dist/_chunks/NoContentTypePage-BSyvnDZZ.js.map +1 -0
  46. package/dist/_chunks/{NoPermissionsPage-UWDC-1Tw.mjs → NoPermissionsPage-CV9V8KWa.mjs} +2 -2
  47. package/dist/_chunks/{NoPermissionsPage-UWDC-1Tw.mjs.map → NoPermissionsPage-CV9V8KWa.mjs.map} +1 -1
  48. package/dist/_chunks/{NoPermissionsPage-Dwu8rRJu.js → NoPermissionsPage-DyLphsn_.js} +2 -2
  49. package/dist/_chunks/{NoPermissionsPage-Dwu8rRJu.js.map → NoPermissionsPage-DyLphsn_.js.map} +1 -1
  50. package/dist/_chunks/Preview-C_B1nx3g.mjs +272 -0
  51. package/dist/_chunks/Preview-C_B1nx3g.mjs.map +1 -0
  52. package/dist/_chunks/Preview-D_3aO6Ly.js +291 -0
  53. package/dist/_chunks/Preview-D_3aO6Ly.js.map +1 -0
  54. package/dist/_chunks/{Relations-J8cscLlR.mjs → Relations-C6pwmDXh.mjs} +135 -89
  55. package/dist/_chunks/Relations-C6pwmDXh.mjs.map +1 -0
  56. package/dist/_chunks/{Relations-CgWtgnPe.js → Relations-Cne2AlrL.js} +138 -93
  57. package/dist/_chunks/Relations-Cne2AlrL.js.map +1 -0
  58. package/dist/_chunks/{en-MBPul9Su.mjs → en-DhFUjrNW.mjs} +37 -18
  59. package/dist/_chunks/{en-MBPul9Su.mjs.map → en-DhFUjrNW.mjs.map} +1 -1
  60. package/dist/_chunks/{en-C-V1_90f.js → en-Ic0kXjxB.js} +37 -18
  61. package/dist/_chunks/{en-C-V1_90f.js.map → en-Ic0kXjxB.js.map} +1 -1
  62. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  63. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  64. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  65. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  66. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  67. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  68. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  69. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  70. package/dist/_chunks/{index-CwRRo1V9.mjs → index-BpxR3En4.mjs} +1835 -824
  71. package/dist/_chunks/index-BpxR3En4.mjs.map +1 -0
  72. package/dist/_chunks/{index-C6AH2hEl.js → index-T-aWjbj2.js} +1788 -777
  73. package/dist/_chunks/index-T-aWjbj2.js.map +1 -0
  74. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  75. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  76. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  77. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  78. package/dist/_chunks/{layout-B_SXLhqf.js → layout-BEuNwv-F.js} +45 -29
  79. package/dist/_chunks/layout-BEuNwv-F.js.map +1 -0
  80. package/dist/_chunks/{layout-jIDzX0Fp.mjs → layout-DhMZ_lDx.mjs} +45 -27
  81. package/dist/_chunks/layout-DhMZ_lDx.mjs.map +1 -0
  82. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  83. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  84. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  85. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  86. package/dist/_chunks/{relations-CuvIgCqI.mjs → relations-BdnxoX6f.mjs} +6 -7
  87. package/dist/_chunks/relations-BdnxoX6f.mjs.map +1 -0
  88. package/dist/_chunks/{relations-iBMa_OFG.js → relations-kLcuobLk.js} +6 -7
  89. package/dist/_chunks/relations-kLcuobLk.js.map +1 -0
  90. package/dist/_chunks/useDebounce-CtcjDB3L.js +28 -0
  91. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  92. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  93. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  94. package/dist/_chunks/useDragAndDrop-DdHgKsqq.mjs.map +1 -1
  95. package/dist/_chunks/useDragAndDrop-J0TUUbR6.js.map +1 -1
  96. package/dist/admin/index.js +3 -1
  97. package/dist/admin/index.js.map +1 -1
  98. package/dist/admin/index.mjs +9 -7
  99. package/dist/admin/src/components/ComponentIcon.d.ts +6 -3
  100. package/dist/admin/src/content-manager.d.ts +3 -3
  101. package/dist/admin/src/exports.d.ts +2 -1
  102. package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
  103. package/dist/admin/src/history/index.d.ts +3 -0
  104. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  105. package/dist/admin/src/hooks/useDocument.d.ts +37 -9
  106. package/dist/admin/src/hooks/useDocumentActions.d.ts +24 -3
  107. package/dist/admin/src/hooks/useDocumentLayout.d.ts +2 -2
  108. package/dist/admin/src/hooks/useDragAndDrop.d.ts +4 -4
  109. package/dist/admin/src/hooks/useKeyboardDragAndDrop.d.ts +1 -1
  110. package/dist/admin/src/index.d.ts +1 -0
  111. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  112. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +11 -4
  113. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
  114. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksInput.d.ts +3 -3
  115. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
  116. package/dist/admin/src/pages/EditView/components/FormInputs/Component/Input.d.ts +2 -2
  117. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.d.ts +3 -5
  118. package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +1 -1
  119. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +30 -18
  120. package/dist/admin/src/pages/EditView/components/FormInputs/UID.d.ts +2 -2
  121. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +3 -49
  122. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/Field.d.ts +2 -2
  123. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  124. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +16 -53
  125. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  126. package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +2 -10
  127. package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
  128. package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
  129. package/dist/admin/src/pages/ListView/components/BulkActions/PublishAction.d.ts +9 -26
  130. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  131. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  132. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  133. package/dist/admin/src/preview/constants.d.ts +1 -0
  134. package/dist/admin/src/preview/index.d.ts +4 -0
  135. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  136. package/dist/admin/src/preview/routes.d.ts +3 -0
  137. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  138. package/dist/admin/src/router.d.ts +1 -1
  139. package/dist/admin/src/services/api.d.ts +2 -3
  140. package/dist/admin/src/services/components.d.ts +2 -2
  141. package/dist/admin/src/services/contentTypes.d.ts +5 -5
  142. package/dist/admin/src/services/documents.d.ts +31 -20
  143. package/dist/admin/src/services/init.d.ts +2 -2
  144. package/dist/admin/src/services/relations.d.ts +3 -3
  145. package/dist/admin/src/services/uid.d.ts +3 -3
  146. package/dist/admin/src/utils/api.d.ts +4 -18
  147. package/dist/admin/src/utils/validation.d.ts +5 -7
  148. package/dist/server/index.js +852 -436
  149. package/dist/server/index.js.map +1 -1
  150. package/dist/server/index.mjs +859 -443
  151. package/dist/server/index.mjs.map +1 -1
  152. package/dist/server/src/bootstrap.d.ts.map +1 -1
  153. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  154. package/dist/server/src/controllers/index.d.ts.map +1 -1
  155. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  156. package/dist/server/src/controllers/single-types.d.ts.map +1 -1
  157. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  158. package/dist/server/src/controllers/utils/metadata.d.ts +22 -0
  159. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -0
  160. package/dist/server/src/controllers/validation/dimensions.d.ts +11 -0
  161. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -0
  162. package/dist/server/src/controllers/validation/index.d.ts +1 -1
  163. package/dist/server/src/history/services/history.d.ts.map +1 -1
  164. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  165. package/dist/server/src/history/services/utils.d.ts +4 -4
  166. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  167. package/dist/server/src/index.d.ts +21 -42
  168. package/dist/server/src/index.d.ts.map +1 -1
  169. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  170. package/dist/server/src/preview/constants.d.ts +2 -0
  171. package/dist/server/src/preview/constants.d.ts.map +1 -0
  172. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  173. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  174. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  175. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  176. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  177. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  178. package/dist/server/src/preview/index.d.ts +4 -0
  179. package/dist/server/src/preview/index.d.ts.map +1 -0
  180. package/dist/server/src/preview/routes/index.d.ts +8 -0
  181. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  182. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  183. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  184. package/dist/server/src/preview/services/index.d.ts +16 -0
  185. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  186. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  187. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  188. package/dist/server/src/preview/services/preview.d.ts +12 -0
  189. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  190. package/dist/server/src/preview/utils.d.ts +19 -0
  191. package/dist/server/src/preview/utils.d.ts.map +1 -0
  192. package/dist/server/src/register.d.ts.map +1 -1
  193. package/dist/server/src/routes/index.d.ts.map +1 -1
  194. package/dist/server/src/services/document-manager.d.ts +13 -12
  195. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  196. package/dist/server/src/services/document-metadata.d.ts +14 -35
  197. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  198. package/dist/server/src/services/index.d.ts +21 -42
  199. package/dist/server/src/services/index.d.ts.map +1 -1
  200. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  201. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  202. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  203. package/dist/server/src/services/utils/populate.d.ts +8 -1
  204. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  205. package/dist/server/src/utils/index.d.ts +2 -0
  206. package/dist/server/src/utils/index.d.ts.map +1 -1
  207. package/dist/shared/contracts/collection-types.d.ts +17 -7
  208. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  209. package/dist/shared/contracts/index.d.ts +1 -0
  210. package/dist/shared/contracts/index.d.ts.map +1 -1
  211. package/dist/shared/contracts/preview.d.ts +27 -0
  212. package/dist/shared/contracts/preview.d.ts.map +1 -0
  213. package/dist/shared/contracts/relations.d.ts +2 -2
  214. package/dist/shared/contracts/relations.d.ts.map +1 -1
  215. package/dist/shared/index.js +4 -0
  216. package/dist/shared/index.js.map +1 -1
  217. package/dist/shared/index.mjs +4 -0
  218. package/dist/shared/index.mjs.map +1 -1
  219. package/package.json +19 -20
  220. package/dist/_chunks/CardDragPreview-DSVYodBX.js.map +0 -1
  221. package/dist/_chunks/CardDragPreview-ikSG4M46.mjs.map +0 -1
  222. package/dist/_chunks/ComponentIcon-BBQsYCVn.js.map +0 -1
  223. package/dist/_chunks/ComponentIcon-BOFnK76n.mjs.map +0 -1
  224. package/dist/_chunks/EditViewPage-DDS6H9HO.mjs +0 -203
  225. package/dist/_chunks/EditViewPage-DDS6H9HO.mjs.map +0 -1
  226. package/dist/_chunks/EditViewPage-DvNpQkam.js.map +0 -1
  227. package/dist/_chunks/Field-6gvGdPBV.mjs.map +0 -1
  228. package/dist/_chunks/Field-DmVKIAOo.js.map +0 -1
  229. package/dist/_chunks/Form-CPZC9vWa.js.map +0 -1
  230. package/dist/_chunks/Form-DW6K1IH-.mjs.map +0 -1
  231. package/dist/_chunks/History-DeAPlvtv.js.map +0 -1
  232. package/dist/_chunks/History-Dmr9fmUA.mjs.map +0 -1
  233. package/dist/_chunks/ListConfigurationPage-DPCwW5Vr.js.map +0 -1
  234. package/dist/_chunks/ListConfigurationPage-DhwvYcNv.mjs.map +0 -1
  235. package/dist/_chunks/ListViewPage-5ySZ-VUs.js.map +0 -1
  236. package/dist/_chunks/ListViewPage-BtAwuYLE.mjs.map +0 -1
  237. package/dist/_chunks/NoContentTypePage-DOC_yWOf.js.map +0 -1
  238. package/dist/_chunks/NoContentTypePage-DSPxnxxp.mjs.map +0 -1
  239. package/dist/_chunks/Relations-CgWtgnPe.js.map +0 -1
  240. package/dist/_chunks/Relations-J8cscLlR.mjs.map +0 -1
  241. package/dist/_chunks/index-C6AH2hEl.js.map +0 -1
  242. package/dist/_chunks/index-CwRRo1V9.mjs.map +0 -1
  243. package/dist/_chunks/layout-B_SXLhqf.js.map +0 -1
  244. package/dist/_chunks/layout-jIDzX0Fp.mjs.map +0 -1
  245. package/dist/_chunks/relations-CuvIgCqI.mjs.map +0 -1
  246. package/dist/_chunks/relations-iBMa_OFG.js.map +0 -1
  247. package/dist/_chunks/urls-CbOsUOoW.mjs +0 -7
  248. package/dist/_chunks/urls-CbOsUOoW.mjs.map +0 -1
  249. package/dist/_chunks/urls-DzZya_gm.js +0 -6
  250. package/dist/_chunks/urls-DzZya_gm.js.map +0 -1
  251. package/dist/server/src/controllers/utils/dimensions.d.ts +0 -5
  252. package/dist/server/src/controllers/utils/dimensions.d.ts.map +0 -1
  253. package/strapi-server.js +0 -3
@@ -1,17 +1,16 @@
1
- import { ClockCounterClockwise, CrossCircle, More, WarningCircle, Cog, Pencil, Trash, ChevronRight, Duplicate, Feather } from "@strapi/icons";
1
+ import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
2
2
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
3
- import { useStrapiApp, useQueryParams, createContext, useAuth, useRBAC, Page, getFetchClient, translatedErrors, useNotification, useAPIErrorHandler, useTracking, useForm, BackButton, DescriptionComponentRenderer } from "@strapi/admin/strapi-admin";
4
- import { stringify } from "qs";
5
- import { useIntl } from "react-intl";
6
- import { useNavigate, useParams, Navigate, useMatch, NavLink } from "react-router-dom";
3
+ import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
7
4
  import * as React from "react";
8
5
  import { lazy } from "react";
9
- import { Menu, VisuallyHidden, Flex, Typography, Dialog, DialogBody, DialogFooter, Button, ModalLayout, ModalHeader, ModalBody, Box, Radio, Status, SingleSelect, SingleSelectOption, LinkButton } from "@strapi/design-system";
10
- import styled from "styled-components";
6
+ import { Menu, Button, VisuallyHidden, Flex, Dialog, Modal, Typography, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
7
+ import mapValues from "lodash/fp/mapValues";
8
+ import { useIntl } from "react-intl";
9
+ import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
10
+ import { styled } from "styled-components";
11
11
  import * as yup from "yup";
12
12
  import { ValidationError } from "yup";
13
- import { createApi } from "@reduxjs/toolkit/query/react";
14
- import { isAxiosError } from "axios";
13
+ import { stringify } from "qs";
15
14
  import pipe from "lodash/fp/pipe";
16
15
  import { intervalToDuration, isPast } from "date-fns";
17
16
  import { createSlice, combineReducers } from "@reduxjs/toolkit";
@@ -51,42 +50,6 @@ const useInjectionZone = (area) => {
51
50
  const [page, position] = area.split(".");
52
51
  return contentManagerPlugin.getInjectedComponents(page, position);
53
52
  };
54
- const HistoryAction = ({ model, document }) => {
55
- const { formatMessage } = useIntl();
56
- const [{ query }] = useQueryParams();
57
- const navigate = useNavigate();
58
- const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
59
- if (!window.strapi.features.isEnabled("cms-content-history")) {
60
- return null;
61
- }
62
- return {
63
- icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
64
- label: formatMessage({
65
- id: "content-manager.history.document-action",
66
- defaultMessage: "Content History"
67
- }),
68
- onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
69
- disabled: (
70
- /**
71
- * The user is creating a new document.
72
- * It hasn't been saved yet, so there's no history to go to
73
- */
74
- !document || /**
75
- * The document has been created but the current dimension has never been saved.
76
- * For example, the user is creating a new locale in an existing document,
77
- * so there's no history for the document in that locale
78
- */
79
- !document.id || /**
80
- * History is only available for content types created by the user.
81
- * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
82
- * which start with `admin::` or `plugin::`
83
- */
84
- !model.startsWith("api::")
85
- ),
86
- position: "header"
87
- };
88
- };
89
- HistoryAction.type = "history";
90
53
  const ID = "id";
91
54
  const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
92
55
  const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
@@ -138,6 +101,7 @@ const DocumentRBAC = ({ children, permissions }) => {
138
101
  if (!slug) {
139
102
  throw new Error("Cannot find the slug param in the URL");
140
103
  }
104
+ const [{ rawQuery }] = useQueryParams();
141
105
  const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
142
106
  const contentTypePermissions = React.useMemo(() => {
143
107
  const contentTypePermissions2 = userPermissions.filter(
@@ -148,7 +112,14 @@ const DocumentRBAC = ({ children, permissions }) => {
148
112
  return { ...acc, [action]: [permission] };
149
113
  }, {});
150
114
  }, [slug, userPermissions]);
151
- 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
+ );
152
123
  const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
153
124
  const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
154
125
  const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
@@ -157,9 +128,8 @@ const DocumentRBAC = ({ children, permissions }) => {
157
128
  const name = removeNumericalStrings(fieldName.split("."));
158
129
  const componentFieldNames = fieldsUserCanAction.filter((field) => field.split(".").length > 1);
159
130
  if (fieldType === "component") {
160
- const componentOrDynamicZoneFields = componentFieldNames.map((field) => field.split("."));
161
- return componentOrDynamicZoneFields.some((field) => {
162
- return field.includes(fieldName);
131
+ return componentFieldNames.some((field) => {
132
+ return field.includes(name.join("."));
163
133
  });
164
134
  }
165
135
  if (name.length > 1) {
@@ -189,89 +159,20 @@ const extractAndDedupeFields = (permissions = []) => permissions.flatMap((permis
189
159
  (field, index2, arr) => arr.indexOf(field) === index2 && typeof field === "string"
190
160
  );
191
161
  const removeNumericalStrings = (arr) => arr.filter((item) => isNaN(Number(item)));
192
- const buildValidParams = (query) => {
193
- if (!query)
194
- return query;
195
- const { plugins: _, ...validQueryParams } = {
196
- ...query,
197
- ...Object.values(query?.plugins ?? {}).reduce(
198
- (acc, current) => Object.assign(acc, current),
199
- {}
200
- )
201
- };
202
- if ("_q" in validQueryParams) {
203
- validQueryParams._q = encodeURIComponent(validQueryParams._q);
204
- }
205
- return validQueryParams;
206
- };
207
- const axiosBaseQuery = () => async (query, { signal }) => {
208
- try {
209
- const { get, post, del, put } = getFetchClient();
210
- if (typeof query === "string") {
211
- const result = await get(query, { signal });
212
- return { data: result.data };
213
- } else {
214
- const { url, method = "GET", data, config } = query;
215
- if (method === "POST") {
216
- const result2 = await post(url, data, { ...config, signal });
217
- return { data: result2.data };
218
- }
219
- if (method === "DELETE") {
220
- const result2 = await del(url, { ...config, signal });
221
- return { data: result2.data };
222
- }
223
- if (method === "PUT") {
224
- const result2 = await put(url, data, { ...config, signal });
225
- return { data: result2.data };
226
- }
227
- const result = await get(url, { ...config, signal });
228
- return { data: result.data };
229
- }
230
- } catch (err) {
231
- if (isAxiosError(err)) {
232
- if (typeof err.response?.data === "object" && err.response?.data !== null && "error" in err.response?.data) {
233
- return { data: void 0, error: err.response?.data.error };
234
- } else {
235
- return {
236
- data: void 0,
237
- error: {
238
- name: "UnknownError",
239
- message: "There was an unknown error response from the API",
240
- details: err.response?.data,
241
- status: err.response?.status
242
- }
243
- };
244
- }
245
- }
246
- const error = err;
247
- return {
248
- data: void 0,
249
- error: {
250
- name: error.name,
251
- message: error.message,
252
- stack: error.stack
253
- }
254
- };
255
- }
256
- };
257
- const isBaseQueryError = (error) => {
258
- return error.name !== void 0;
259
- };
260
- const contentManagerApi = createApi({
261
- reducerPath: "contentManagerApi",
262
- baseQuery: axiosBaseQuery(),
263
- tagTypes: [
162
+ const contentManagerApi = adminApi.enhanceEndpoints({
163
+ addTagTypes: [
264
164
  "ComponentConfiguration",
265
165
  "ContentTypesConfiguration",
266
166
  "ContentTypeSettings",
267
167
  "Document",
268
168
  "InitialData",
269
169
  "HistoryVersion",
270
- "Relations"
271
- ],
272
- endpoints: () => ({})
170
+ "Relations",
171
+ "UidAvailability"
172
+ ]
273
173
  });
274
174
  const documentApi = contentManagerApi.injectEndpoints({
175
+ overrideExisting: true,
275
176
  endpoints: (builder) => ({
276
177
  autoCloneDocument: builder.mutation({
277
178
  query: ({ model, sourceId, query }) => ({
@@ -281,7 +182,12 @@ const documentApi = contentManagerApi.injectEndpoints({
281
182
  params: query
282
183
  }
283
184
  }),
284
- invalidatesTags: (_result, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
185
+ invalidatesTags: (_result, error, { model }) => {
186
+ if (error) {
187
+ return [];
188
+ }
189
+ return [{ type: "Document", id: `${model}_LIST` }];
190
+ }
285
191
  }),
286
192
  cloneDocument: builder.mutation({
287
193
  query: ({ model, sourceId, data, params }) => ({
@@ -292,7 +198,10 @@ const documentApi = contentManagerApi.injectEndpoints({
292
198
  params
293
199
  }
294
200
  }),
295
- 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
+ ]
296
205
  }),
297
206
  /**
298
207
  * Creates a new collection-type document. This should ONLY be used for collection-types.
@@ -309,7 +218,8 @@ const documentApi = contentManagerApi.injectEndpoints({
309
218
  }),
310
219
  invalidatesTags: (result, _error, { model }) => [
311
220
  { type: "Document", id: `${model}_LIST` },
312
- "Relations"
221
+ "Relations",
222
+ { type: "UidAvailability", id: model }
313
223
  ]
314
224
  }),
315
225
  deleteDocument: builder.mutation({
@@ -325,12 +235,15 @@ const documentApi = contentManagerApi.injectEndpoints({
325
235
  ]
326
236
  }),
327
237
  deleteManyDocuments: builder.mutation({
328
- query: ({ model, ...body }) => ({
238
+ query: ({ model, params, ...body }) => ({
329
239
  url: `/content-manager/collection-types/${model}/actions/bulkDelete`,
330
240
  method: "POST",
331
- data: body
241
+ data: body,
242
+ config: {
243
+ params
244
+ }
332
245
  }),
333
- invalidatesTags: (_res, _error, { model, documentIds }) => documentIds.map((id) => ({ type: "Document", id: `${model}_${id}` }))
246
+ invalidatesTags: (_res, _error, { model }) => [{ type: "Document", id: `${model}_LIST` }]
334
247
  }),
335
248
  discardDocument: builder.mutation({
336
249
  query: ({ collectionType, model, documentId, params }) => ({
@@ -347,7 +260,8 @@ const documentApi = contentManagerApi.injectEndpoints({
347
260
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
348
261
  },
349
262
  { type: "Document", id: `${model}_LIST` },
350
- "Relations"
263
+ "Relations",
264
+ { type: "UidAvailability", id: model }
351
265
  ];
352
266
  }
353
267
  }),
@@ -360,11 +274,12 @@ const documentApi = contentManagerApi.injectEndpoints({
360
274
  url: `/content-manager/collection-types/${model}`,
361
275
  method: "GET",
362
276
  config: {
363
- params
277
+ params: stringify(params, { encode: true })
364
278
  }
365
279
  }),
366
280
  providesTags: (result, _error, arg) => {
367
281
  return [
282
+ { type: "Document", id: `ALL_LIST` },
368
283
  { type: "Document", id: `${arg.model}_LIST` },
369
284
  ...result?.results.map(({ documentId }) => ({
370
285
  type: "Document",
@@ -403,6 +318,11 @@ const documentApi = contentManagerApi.injectEndpoints({
403
318
  {
404
319
  type: "Document",
405
320
  id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
321
+ },
322
+ // Make it easy to invalidate all individual documents queries for a model
323
+ {
324
+ type: "Document",
325
+ id: `${model}_ALL_ITEMS`
406
326
  }
407
327
  ];
408
328
  }
@@ -441,10 +361,13 @@ const documentApi = contentManagerApi.injectEndpoints({
441
361
  }
442
362
  }),
443
363
  publishManyDocuments: builder.mutation({
444
- query: ({ model, ...body }) => ({
364
+ query: ({ model, params, ...body }) => ({
445
365
  url: `/content-manager/collection-types/${model}/actions/bulkPublish`,
446
366
  method: "POST",
447
- data: body
367
+ data: body,
368
+ config: {
369
+ params
370
+ }
448
371
  }),
449
372
  invalidatesTags: (_res, _error, { model, documentIds }) => documentIds.map((id) => ({ type: "Document", id: `${model}_${id}` }))
450
373
  }),
@@ -463,8 +386,21 @@ const documentApi = contentManagerApi.injectEndpoints({
463
386
  type: "Document",
464
387
  id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
465
388
  },
466
- "Relations"
389
+ "Relations",
390
+ { type: "UidAvailability", id: model }
467
391
  ];
392
+ },
393
+ async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
394
+ const patchResult = dispatch(
395
+ documentApi.util.updateQueryData("getDocument", patch, (draft) => {
396
+ Object.assign(draft.data, data);
397
+ })
398
+ );
399
+ try {
400
+ await queryFulfilled;
401
+ } catch {
402
+ patchResult.undo();
403
+ }
468
404
  }
469
405
  }),
470
406
  unpublishDocument: builder.mutation({
@@ -486,10 +422,13 @@ const documentApi = contentManagerApi.injectEndpoints({
486
422
  }
487
423
  }),
488
424
  unpublishManyDocuments: builder.mutation({
489
- query: ({ model, ...body }) => ({
425
+ query: ({ model, params, ...body }) => ({
490
426
  url: `/content-manager/collection-types/${model}/actions/bulkUnpublish`,
491
427
  method: "POST",
492
- data: body
428
+ data: body,
429
+ config: {
430
+ params
431
+ }
493
432
  }),
494
433
  invalidatesTags: (_res, _error, { model, documentIds }) => documentIds.map((id) => ({ type: "Document", id: `${model}_${id}` }))
495
434
  })
@@ -513,20 +452,54 @@ const {
513
452
  useUnpublishDocumentMutation,
514
453
  useUnpublishManyDocumentsMutation
515
454
  } = documentApi;
516
- const createYupSchema = (attributes = {}, components = {}) => {
455
+ const buildValidParams = (query) => {
456
+ if (!query)
457
+ return query;
458
+ const { plugins: _, ...validQueryParams } = {
459
+ ...query,
460
+ ...Object.values(query?.plugins ?? {}).reduce(
461
+ (acc, current) => Object.assign(acc, current),
462
+ {}
463
+ )
464
+ };
465
+ return validQueryParams;
466
+ };
467
+ const isBaseQueryError = (error) => {
468
+ return error.name !== void 0;
469
+ };
470
+ const arrayValidator = (attribute, options) => ({
471
+ message: translatedErrors.required,
472
+ test(value) {
473
+ if (options.status === "draft") {
474
+ return true;
475
+ }
476
+ if (!attribute.required) {
477
+ return true;
478
+ }
479
+ if (!value) {
480
+ return false;
481
+ }
482
+ if (Array.isArray(value) && value.length === 0) {
483
+ return false;
484
+ }
485
+ return true;
486
+ }
487
+ });
488
+ const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
517
489
  const createModelSchema = (attributes2) => yup.object().shape(
518
490
  Object.entries(attributes2).reduce((acc, [name, attribute]) => {
519
491
  if (DOCUMENT_META_FIELDS.includes(name)) {
520
492
  return acc;
521
493
  }
522
494
  const validations = [
495
+ addNullableValidation,
523
496
  addRequiredValidation,
524
497
  addMinLengthValidation,
525
498
  addMaxLengthValidation,
526
499
  addMinValidation,
527
500
  addMaxValidation,
528
501
  addRegexValidation
529
- ].map((fn) => fn(attribute));
502
+ ].map((fn) => fn(attribute, options));
530
503
  const transformSchema = pipe(...validations);
531
504
  switch (attribute.type) {
532
505
  case "component": {
@@ -536,12 +509,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
536
509
  ...acc,
537
510
  [name]: transformSchema(
538
511
  yup.array().of(createModelSchema(attributes3).nullable(false))
539
- )
512
+ ).test(arrayValidator(attribute, options))
540
513
  };
541
514
  } else {
542
515
  return {
543
516
  ...acc,
544
- [name]: transformSchema(createModelSchema(attributes3))
517
+ [name]: transformSchema(createModelSchema(attributes3).nullable())
545
518
  };
546
519
  }
547
520
  }
@@ -552,24 +525,42 @@ const createYupSchema = (attributes = {}, components = {}) => {
552
525
  yup.array().of(
553
526
  yup.lazy(
554
527
  (data) => {
555
- const { attributes: attributes3 } = components[data.__component];
556
- return yup.object().shape({
528
+ const attributes3 = components?.[data?.__component]?.attributes;
529
+ const validation = yup.object().shape({
557
530
  __component: yup.string().required().oneOf(Object.keys(components))
558
- }).nullable(false).concat(createModelSchema(attributes3));
531
+ }).nullable(false);
532
+ if (!attributes3) {
533
+ return validation;
534
+ }
535
+ return validation.concat(createModelSchema(attributes3));
559
536
  }
560
537
  )
561
538
  )
562
- )
539
+ ).test(arrayValidator(attribute, options))
563
540
  };
564
541
  case "relation":
565
542
  return {
566
543
  ...acc,
567
544
  [name]: transformSchema(
568
- yup.array().of(
569
- yup.object().shape({
570
- id: yup.string().required()
571
- })
572
- )
545
+ yup.lazy((value) => {
546
+ if (!value) {
547
+ return yup.mixed().nullable(true);
548
+ } else if (Array.isArray(value)) {
549
+ return yup.array().of(
550
+ yup.object().shape({
551
+ id: yup.number().required()
552
+ })
553
+ );
554
+ } else if (typeof value === "object") {
555
+ return yup.object();
556
+ } else {
557
+ return yup.mixed().test(
558
+ "type-error",
559
+ "Relation values must be either null, an array of objects with {id} or an object.",
560
+ () => false
561
+ );
562
+ }
563
+ })
573
564
  )
574
565
  };
575
566
  default:
@@ -609,6 +600,14 @@ const createAttributeSchema = (attribute) => {
609
600
  if (!value || typeof value === "string" && value.length === 0) {
610
601
  return true;
611
602
  }
603
+ if (typeof value === "object") {
604
+ try {
605
+ JSON.stringify(value);
606
+ return true;
607
+ } catch (err) {
608
+ return false;
609
+ }
610
+ }
612
611
  try {
613
612
  JSON.parse(value);
614
613
  return true;
@@ -627,16 +626,30 @@ const createAttributeSchema = (attribute) => {
627
626
  return yup.mixed();
628
627
  }
629
628
  };
630
- const addRequiredValidation = (attribute) => (schema) => {
631
- if (attribute.required) {
632
- return schema.required({
633
- id: translatedErrors.required.id,
634
- defaultMessage: "This field is required."
635
- });
629
+ const nullableSchema = (schema) => {
630
+ return schema?.nullable ? schema.nullable() : (
631
+ // In some cases '.nullable' will not be available on the schema.
632
+ // e.g. when the schema has been built using yup.lazy (e.g. for relations).
633
+ // In these cases we should just return the schema as it is.
634
+ schema
635
+ );
636
+ };
637
+ const addNullableValidation = () => (schema) => {
638
+ return nullableSchema(schema);
639
+ };
640
+ const addRequiredValidation = (attribute, options) => (schema) => {
641
+ if (options.status === "draft" || !attribute.required) {
642
+ return schema;
643
+ }
644
+ if (attribute.required && "required" in schema) {
645
+ return schema.required(translatedErrors.required);
636
646
  }
637
- return schema.nullable();
647
+ return schema;
638
648
  };
639
- const addMinLengthValidation = (attribute) => (schema) => {
649
+ const addMinLengthValidation = (attribute, options) => (schema) => {
650
+ if (options.status === "draft") {
651
+ return schema;
652
+ }
640
653
  if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
641
654
  return schema.min(attribute.minLength, {
642
655
  ...translatedErrors.minLength,
@@ -658,10 +671,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
658
671
  }
659
672
  return schema;
660
673
  };
661
- const addMinValidation = (attribute) => (schema) => {
662
- if ("min" in attribute) {
674
+ const addMinValidation = (attribute, options) => (schema) => {
675
+ if (options.status === "draft") {
676
+ return schema;
677
+ }
678
+ if ("min" in attribute && "min" in schema) {
663
679
  const min = toInteger(attribute.min);
664
- if ("min" in schema && min) {
680
+ if (min) {
665
681
  return schema.min(min, {
666
682
  ...translatedErrors.min,
667
683
  values: {
@@ -706,24 +722,6 @@ const addRegexValidation = (attribute) => (schema) => {
706
722
  }
707
723
  return schema;
708
724
  };
709
- const extractValuesFromYupError = (errorType, errorParams) => {
710
- if (!errorType || !errorParams) {
711
- return {};
712
- }
713
- return {
714
- [errorType]: errorParams[errorType]
715
- };
716
- };
717
- const getInnerErrors = (error) => (error?.inner || []).reduce((acc, currentError) => {
718
- if (currentError.path) {
719
- acc[currentError.path.split("[").join(".").split("]").join("")] = {
720
- id: currentError.message,
721
- defaultMessage: currentError.message,
722
- values: extractValuesFromYupError(currentError?.type, currentError?.params)
723
- };
724
- }
725
- return acc;
726
- }, {});
727
725
  const initApi = contentManagerApi.injectEndpoints({
728
726
  endpoints: (builder) => ({
729
727
  getInitialData: builder.query({
@@ -737,27 +735,20 @@ const { useGetInitialDataQuery } = initApi;
737
735
  const useContentTypeSchema = (model) => {
738
736
  const { toggleNotification } = useNotification();
739
737
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
740
- const { components, contentType, contentTypes, error, isLoading, isFetching } = useGetInitialDataQuery(void 0, {
741
- selectFromResult: (res) => {
742
- const contentType2 = res.data?.contentTypes.find((ct) => ct.uid === model);
743
- const componentsByKey = res.data?.components.reduce(
744
- (acc, component) => {
745
- acc[component.uid] = component;
746
- return acc;
747
- },
748
- {}
749
- );
750
- const components2 = extractContentTypeComponents(contentType2?.attributes, componentsByKey);
751
- return {
752
- isLoading: res.isLoading,
753
- isFetching: res.isFetching,
754
- error: res.error,
755
- components: Object.keys(components2).length === 0 ? void 0 : components2,
756
- contentType: contentType2,
757
- contentTypes: res.data?.contentTypes ?? []
758
- };
759
- }
760
- });
738
+ const { data, error, isLoading, isFetching } = useGetInitialDataQuery(void 0);
739
+ const { components, contentType, contentTypes } = React.useMemo(() => {
740
+ const contentType2 = data?.contentTypes.find((ct) => ct.uid === model);
741
+ const componentsByKey = data?.components.reduce((acc, component) => {
742
+ acc[component.uid] = component;
743
+ return acc;
744
+ }, {});
745
+ const components2 = extractContentTypeComponents(contentType2?.attributes, componentsByKey);
746
+ return {
747
+ components: Object.keys(components2).length === 0 ? void 0 : components2,
748
+ contentType: contentType2,
749
+ contentTypes: data?.contentTypes ?? []
750
+ };
751
+ }, [model, data]);
761
752
  React.useEffect(() => {
762
753
  if (error) {
763
754
  toggleNotification({
@@ -804,16 +795,328 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
804
795
  }, {});
805
796
  return componentsByKey;
806
797
  };
807
- const useDocument = (args, opts) => {
798
+ const HOOKS = {
799
+ /**
800
+ * Hook that allows to mutate the displayed headers of the list view table
801
+ * @constant
802
+ * @type {string}
803
+ */
804
+ INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
805
+ /**
806
+ * Hook that allows to mutate the CM's collection types links pre-set filters
807
+ * @constant
808
+ * @type {string}
809
+ */
810
+ MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
811
+ /**
812
+ * Hook that allows to mutate the CM's edit view layout
813
+ * @constant
814
+ * @type {string}
815
+ */
816
+ MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
817
+ /**
818
+ * Hook that allows to mutate the CM's single types links pre-set filters
819
+ * @constant
820
+ * @type {string}
821
+ */
822
+ MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
823
+ };
824
+ const contentTypesApi = contentManagerApi.injectEndpoints({
825
+ endpoints: (builder) => ({
826
+ getContentTypeConfiguration: builder.query({
827
+ query: (uid) => ({
828
+ url: `/content-manager/content-types/${uid}/configuration`,
829
+ method: "GET"
830
+ }),
831
+ transformResponse: (response) => response.data,
832
+ providesTags: (_result, _error, uid) => [
833
+ { type: "ContentTypesConfiguration", id: uid },
834
+ { type: "ContentTypeSettings", id: "LIST" }
835
+ ]
836
+ }),
837
+ getAllContentTypeSettings: builder.query({
838
+ query: () => "/content-manager/content-types-settings",
839
+ transformResponse: (response) => response.data,
840
+ providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
841
+ }),
842
+ updateContentTypeConfiguration: builder.mutation({
843
+ query: ({ uid, ...body }) => ({
844
+ url: `/content-manager/content-types/${uid}/configuration`,
845
+ method: "PUT",
846
+ data: body
847
+ }),
848
+ transformResponse: (response) => response.data,
849
+ invalidatesTags: (_result, _error, { uid }) => [
850
+ { type: "ContentTypesConfiguration", id: uid },
851
+ { type: "ContentTypeSettings", id: "LIST" },
852
+ // Is this necessary?
853
+ { type: "InitialData" }
854
+ ]
855
+ })
856
+ })
857
+ });
858
+ const {
859
+ useGetContentTypeConfigurationQuery,
860
+ useGetAllContentTypeSettingsQuery,
861
+ useUpdateContentTypeConfigurationMutation
862
+ } = contentTypesApi;
863
+ const checkIfAttributeIsDisplayable = (attribute) => {
864
+ const { type } = attribute;
865
+ if (type === "relation") {
866
+ return !attribute.relation.toLowerCase().includes("morph");
867
+ }
868
+ return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
869
+ };
870
+ const getMainField = (attribute, mainFieldName, { schemas, components }) => {
871
+ if (!mainFieldName) {
872
+ return void 0;
873
+ }
874
+ const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
875
+ // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
876
+ schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
877
+ );
878
+ return {
879
+ name: mainFieldName,
880
+ type: mainFieldType ?? "string"
881
+ };
882
+ };
883
+ const DEFAULT_SETTINGS = {
884
+ bulkable: false,
885
+ filterable: false,
886
+ searchable: false,
887
+ pagination: false,
888
+ defaultSortBy: "",
889
+ defaultSortOrder: "asc",
890
+ mainField: "id",
891
+ pageSize: 10
892
+ };
893
+ const useDocumentLayout = (model) => {
894
+ const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
895
+ const [{ query }] = useQueryParams();
896
+ const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
808
897
  const { toggleNotification } = useNotification();
809
898
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
899
+ const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
810
900
  const {
811
- currentData: data,
812
- isLoading: isLoadingDocument,
813
- isFetching: isFetchingDocument,
814
- error
815
- } = useGetDocumentQuery(args, opts);
816
- const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
901
+ data,
902
+ isLoading: isLoadingConfigs,
903
+ error,
904
+ isFetching: isFetchingConfigs
905
+ } = useGetContentTypeConfigurationQuery(model);
906
+ const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
907
+ React.useEffect(() => {
908
+ if (error) {
909
+ toggleNotification({
910
+ type: "danger",
911
+ message: formatAPIError(error)
912
+ });
913
+ }
914
+ }, [error, formatAPIError, toggleNotification]);
915
+ const editLayout = React.useMemo(
916
+ () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
917
+ layout: [],
918
+ components: {},
919
+ metadatas: {},
920
+ options: {},
921
+ settings: DEFAULT_SETTINGS
922
+ },
923
+ [data, isLoading, schemas, schema, components]
924
+ );
925
+ const listLayout = React.useMemo(() => {
926
+ return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
927
+ layout: [],
928
+ metadatas: {},
929
+ options: {},
930
+ settings: DEFAULT_SETTINGS
931
+ };
932
+ }, [data, isLoading, schemas, schema, components]);
933
+ const { layout: edit } = React.useMemo(
934
+ () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
935
+ layout: editLayout,
936
+ query
937
+ }),
938
+ [editLayout, query, runHookWaterfall]
939
+ );
940
+ return {
941
+ error,
942
+ isLoading,
943
+ edit,
944
+ list: listLayout
945
+ };
946
+ };
947
+ const useDocLayout = () => {
948
+ const { model } = useDoc();
949
+ return useDocumentLayout(model);
950
+ };
951
+ const formatEditLayout = (data, {
952
+ schemas,
953
+ schema,
954
+ components
955
+ }) => {
956
+ let currentPanelIndex = 0;
957
+ const panelledEditAttributes = convertEditLayoutToFieldLayouts(
958
+ data.contentType.layouts.edit,
959
+ schema?.attributes,
960
+ data.contentType.metadatas,
961
+ { configurations: data.components, schemas: components },
962
+ schemas
963
+ ).reduce((panels, row) => {
964
+ if (row.some((field) => field.type === "dynamiczone")) {
965
+ panels.push([row]);
966
+ currentPanelIndex += 2;
967
+ } else {
968
+ if (!panels[currentPanelIndex]) {
969
+ panels.push([row]);
970
+ } else {
971
+ panels[currentPanelIndex].push(row);
972
+ }
973
+ }
974
+ return panels;
975
+ }, []);
976
+ const componentEditAttributes = Object.entries(data.components).reduce(
977
+ (acc, [uid, configuration]) => {
978
+ acc[uid] = {
979
+ layout: convertEditLayoutToFieldLayouts(
980
+ configuration.layouts.edit,
981
+ components[uid].attributes,
982
+ configuration.metadatas,
983
+ { configurations: data.components, schemas: components }
984
+ ),
985
+ settings: {
986
+ ...configuration.settings,
987
+ icon: components[uid].info.icon,
988
+ displayName: components[uid].info.displayName
989
+ }
990
+ };
991
+ return acc;
992
+ },
993
+ {}
994
+ );
995
+ const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
996
+ (acc, [attribute, metadata]) => {
997
+ return {
998
+ ...acc,
999
+ [attribute]: metadata.edit
1000
+ };
1001
+ },
1002
+ {}
1003
+ );
1004
+ return {
1005
+ layout: panelledEditAttributes,
1006
+ components: componentEditAttributes,
1007
+ metadatas: editMetadatas,
1008
+ settings: {
1009
+ ...data.contentType.settings,
1010
+ displayName: schema?.info.displayName
1011
+ },
1012
+ options: {
1013
+ ...schema?.options,
1014
+ ...schema?.pluginOptions,
1015
+ ...data.contentType.options
1016
+ }
1017
+ };
1018
+ };
1019
+ const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
1020
+ return rows.map(
1021
+ (row) => row.map((field) => {
1022
+ const attribute = attributes[field.name];
1023
+ if (!attribute) {
1024
+ return null;
1025
+ }
1026
+ const { edit: metadata } = metadatas[field.name];
1027
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1028
+ return {
1029
+ attribute,
1030
+ disabled: !metadata.editable,
1031
+ hint: metadata.description,
1032
+ label: metadata.label ?? "",
1033
+ name: field.name,
1034
+ // @ts-expect-error – mainField does exist on the metadata for a relation.
1035
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1036
+ schemas,
1037
+ components: components?.schemas ?? {}
1038
+ }),
1039
+ placeholder: metadata.placeholder ?? "",
1040
+ required: attribute.required ?? false,
1041
+ size: field.size,
1042
+ unique: "unique" in attribute ? attribute.unique : false,
1043
+ visible: metadata.visible ?? true,
1044
+ type: attribute.type
1045
+ };
1046
+ }).filter((field) => field !== null)
1047
+ );
1048
+ };
1049
+ const formatListLayout = (data, {
1050
+ schemas,
1051
+ schema,
1052
+ components
1053
+ }) => {
1054
+ const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
1055
+ (acc, [attribute, metadata]) => {
1056
+ return {
1057
+ ...acc,
1058
+ [attribute]: metadata.list
1059
+ };
1060
+ },
1061
+ {}
1062
+ );
1063
+ const listAttributes = convertListLayoutToFieldLayouts(
1064
+ data.contentType.layouts.list,
1065
+ schema?.attributes,
1066
+ listMetadatas,
1067
+ { configurations: data.components, schemas: components },
1068
+ schemas
1069
+ );
1070
+ return {
1071
+ layout: listAttributes,
1072
+ settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
1073
+ metadatas: listMetadatas,
1074
+ options: {
1075
+ ...schema?.options,
1076
+ ...schema?.pluginOptions,
1077
+ ...data.contentType.options
1078
+ }
1079
+ };
1080
+ };
1081
+ const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
1082
+ return columns.map((name) => {
1083
+ const attribute = attributes[name];
1084
+ if (!attribute) {
1085
+ return null;
1086
+ }
1087
+ const metadata = metadatas[name];
1088
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1089
+ return {
1090
+ attribute,
1091
+ label: metadata.label ?? "",
1092
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1093
+ schemas,
1094
+ components: components?.schemas ?? {}
1095
+ }),
1096
+ name,
1097
+ searchable: metadata.searchable ?? true,
1098
+ sortable: metadata.sortable ?? true
1099
+ };
1100
+ }).filter((field) => field !== null);
1101
+ };
1102
+ const useDocument = (args, opts) => {
1103
+ const { toggleNotification } = useNotification();
1104
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1105
+ const {
1106
+ currentData: data,
1107
+ isLoading: isLoadingDocument,
1108
+ isFetching: isFetchingDocument,
1109
+ error
1110
+ } = useGetDocumentQuery(args, {
1111
+ ...opts,
1112
+ skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
1113
+ });
1114
+ const {
1115
+ components,
1116
+ schema,
1117
+ schemas,
1118
+ isLoading: isLoadingSchema
1119
+ } = useContentTypeSchema(args.model);
817
1120
  React.useEffect(() => {
818
1121
  if (error) {
819
1122
  toggleNotification({
@@ -840,7 +1143,7 @@ const useDocument = (args, opts) => {
840
1143
  return null;
841
1144
  } catch (error2) {
842
1145
  if (error2 instanceof ValidationError) {
843
- return getInnerErrors(error2);
1146
+ return getYupValidationErrors(error2);
844
1147
  }
845
1148
  throw error2;
846
1149
  }
@@ -848,12 +1151,15 @@ const useDocument = (args, opts) => {
848
1151
  [validationSchema]
849
1152
  );
850
1153
  const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
1154
+ const hasError = !!error;
851
1155
  return {
852
1156
  components,
853
1157
  document: data?.data,
854
1158
  meta: data?.meta,
855
1159
  isLoading,
1160
+ hasError,
856
1161
  schema,
1162
+ schemas,
857
1163
  validate
858
1164
  };
859
1165
  };
@@ -867,22 +1173,60 @@ const useDoc = () => {
867
1173
  if (!slug) {
868
1174
  throw new Error("Could not find model in url params");
869
1175
  }
1176
+ const document = useDocument(
1177
+ { documentId: origin || id, model: slug, collectionType, params },
1178
+ {
1179
+ skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
1180
+ }
1181
+ );
1182
+ const returnId = origin || id === "create" ? void 0 : id;
870
1183
  return {
871
1184
  collectionType,
872
1185
  model: slug,
873
- id: origin || id === "create" ? void 0 : id,
874
- ...useDocument(
875
- { documentId: origin || id, model: slug, collectionType, params },
876
- {
877
- skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
878
- }
879
- )
1186
+ id: returnId,
1187
+ ...document
1188
+ };
1189
+ };
1190
+ const useContentManagerContext = () => {
1191
+ const {
1192
+ collectionType,
1193
+ model,
1194
+ id,
1195
+ components,
1196
+ isLoading: isLoadingDoc,
1197
+ schema,
1198
+ schemas
1199
+ } = useDoc();
1200
+ const layout = useDocumentLayout(model);
1201
+ const form = useForm("useContentManagerContext", (state) => state);
1202
+ const isSingleType = collectionType === SINGLE_TYPES;
1203
+ const slug = model;
1204
+ const isCreatingEntry = id === "create";
1205
+ useContentTypeSchema();
1206
+ const isLoading = isLoadingDoc || layout.isLoading;
1207
+ const error = layout.error;
1208
+ return {
1209
+ error,
1210
+ isLoading,
1211
+ // Base metadata
1212
+ model,
1213
+ collectionType,
1214
+ id,
1215
+ slug,
1216
+ isCreatingEntry,
1217
+ isSingleType,
1218
+ hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
1219
+ // All schema infos
1220
+ components,
1221
+ contentType: schema,
1222
+ contentTypes: schemas,
1223
+ // Form state
1224
+ form,
1225
+ // layout infos
1226
+ layout
880
1227
  };
881
1228
  };
882
1229
  const prefixPluginTranslations = (trad, pluginId) => {
883
- if (!pluginId) {
884
- throw new TypeError("pluginId can't be empty");
885
- }
886
1230
  return Object.keys(trad).reduce((acc, current) => {
887
1231
  acc[`${pluginId}.${current}`] = trad[current];
888
1232
  return acc;
@@ -898,6 +1242,8 @@ const useDocumentActions = () => {
898
1242
  const { formatMessage } = useIntl();
899
1243
  const { trackUsage } = useTracking();
900
1244
  const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
1245
+ const navigate = useNavigate();
1246
+ const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
901
1247
  const [deleteDocument] = useDeleteDocumentMutation();
902
1248
  const _delete = React.useCallback(
903
1249
  async ({ collectionType, model, documentId, params }, trackerProperty) => {
@@ -936,14 +1282,15 @@ const useDocumentActions = () => {
936
1282
  },
937
1283
  [trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
938
1284
  );
939
- const [discardDocument] = useDiscardDocumentMutation();
940
- const discard = React.useCallback(
941
- async ({ collectionType, model, documentId }) => {
1285
+ const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
1286
+ const deleteMany = React.useCallback(
1287
+ async ({ model, documentIds, params }) => {
942
1288
  try {
943
- const res = await discardDocument({
944
- collectionType,
1289
+ trackUsage("willBulkDeleteEntries");
1290
+ const res = await deleteManyDocuments({
945
1291
  model,
946
- documentId
1292
+ documentIds,
1293
+ params
947
1294
  });
948
1295
  if ("error" in res) {
949
1296
  toggleNotification({
@@ -954,36 +1301,74 @@ const useDocumentActions = () => {
954
1301
  }
955
1302
  toggleNotification({
956
1303
  type: "success",
957
- message: formatMessage({
958
- id: "content-manager.success.record.discard",
959
- defaultMessage: "Changes discarded"
960
- })
1304
+ title: formatMessage({
1305
+ id: getTranslation("success.records.delete"),
1306
+ defaultMessage: "Successfully deleted."
1307
+ }),
1308
+ message: ""
961
1309
  });
1310
+ trackUsage("didBulkDeleteEntries");
962
1311
  return res.data;
963
1312
  } catch (err) {
964
1313
  toggleNotification({
965
1314
  type: "danger",
966
1315
  message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
967
1316
  });
1317
+ trackUsage("didNotBulkDeleteEntries");
968
1318
  throw err;
969
1319
  }
970
1320
  },
971
- [discardDocument, formatAPIError, formatMessage, toggleNotification]
1321
+ [trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
972
1322
  );
973
- const [publishDocument] = usePublishDocumentMutation();
974
- const publish = React.useCallback(
975
- async ({ collectionType, model, documentId, params }, data) => {
1323
+ const [discardDocument] = useDiscardDocumentMutation();
1324
+ const discard = React.useCallback(
1325
+ async ({ collectionType, model, documentId, params }) => {
976
1326
  try {
977
- trackUsage("willPublishEntry");
978
- const res = await publishDocument({
1327
+ const res = await discardDocument({
979
1328
  collectionType,
980
1329
  model,
981
1330
  documentId,
982
- data,
983
1331
  params
984
1332
  });
985
1333
  if ("error" in res) {
986
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1334
+ toggleNotification({
1335
+ type: "danger",
1336
+ message: formatAPIError(res.error)
1337
+ });
1338
+ return { error: res.error };
1339
+ }
1340
+ toggleNotification({
1341
+ type: "success",
1342
+ message: formatMessage({
1343
+ id: "content-manager.success.record.discard",
1344
+ defaultMessage: "Changes discarded"
1345
+ })
1346
+ });
1347
+ return res.data;
1348
+ } catch (err) {
1349
+ toggleNotification({
1350
+ type: "danger",
1351
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1352
+ });
1353
+ throw err;
1354
+ }
1355
+ },
1356
+ [discardDocument, formatAPIError, formatMessage, toggleNotification]
1357
+ );
1358
+ const [publishDocument] = usePublishDocumentMutation();
1359
+ const publish = React.useCallback(
1360
+ async ({ collectionType, model, documentId, params }, data) => {
1361
+ try {
1362
+ trackUsage("willPublishEntry");
1363
+ const res = await publishDocument({
1364
+ collectionType,
1365
+ model,
1366
+ documentId,
1367
+ data,
1368
+ params
1369
+ });
1370
+ if ("error" in res) {
1371
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
987
1372
  return { error: res.error };
988
1373
  }
989
1374
  trackUsage("didPublishEntry");
@@ -1005,6 +1390,43 @@ const useDocumentActions = () => {
1005
1390
  },
1006
1391
  [trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
1007
1392
  );
1393
+ const [publishManyDocuments] = usePublishManyDocumentsMutation();
1394
+ const publishMany = React.useCallback(
1395
+ async ({ model, documentIds, params }) => {
1396
+ try {
1397
+ const res = await publishManyDocuments({
1398
+ model,
1399
+ documentIds,
1400
+ params
1401
+ });
1402
+ if ("error" in res) {
1403
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1404
+ return { error: res.error };
1405
+ }
1406
+ toggleNotification({
1407
+ type: "success",
1408
+ message: formatMessage({
1409
+ id: getTranslation("success.record.publish"),
1410
+ defaultMessage: "Published document"
1411
+ })
1412
+ });
1413
+ return res.data;
1414
+ } catch (err) {
1415
+ toggleNotification({
1416
+ type: "danger",
1417
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1418
+ });
1419
+ throw err;
1420
+ }
1421
+ },
1422
+ [
1423
+ // trackUsage,
1424
+ publishManyDocuments,
1425
+ toggleNotification,
1426
+ formatMessage,
1427
+ formatAPIError
1428
+ ]
1429
+ );
1008
1430
  const [updateDocument] = useUpdateDocumentMutation();
1009
1431
  const update = React.useCallback(
1010
1432
  async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
@@ -1079,6 +1501,41 @@ const useDocumentActions = () => {
1079
1501
  },
1080
1502
  [trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
1081
1503
  );
1504
+ const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
1505
+ const unpublishMany = React.useCallback(
1506
+ async ({ model, documentIds, params }) => {
1507
+ try {
1508
+ trackUsage("willBulkUnpublishEntries");
1509
+ const res = await unpublishManyDocuments({
1510
+ model,
1511
+ documentIds,
1512
+ params
1513
+ });
1514
+ if ("error" in res) {
1515
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1516
+ return { error: res.error };
1517
+ }
1518
+ trackUsage("didBulkUnpublishEntries");
1519
+ toggleNotification({
1520
+ type: "success",
1521
+ title: formatMessage({
1522
+ id: getTranslation("success.records.unpublish"),
1523
+ defaultMessage: "Successfully unpublished."
1524
+ }),
1525
+ message: ""
1526
+ });
1527
+ return res.data;
1528
+ } catch (err) {
1529
+ toggleNotification({
1530
+ type: "danger",
1531
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1532
+ });
1533
+ trackUsage("didNotBulkUnpublishEntries");
1534
+ throw err;
1535
+ }
1536
+ },
1537
+ [trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
1538
+ );
1082
1539
  const [createDocument] = useCreateDocumentMutation();
1083
1540
  const create = React.useCallback(
1084
1541
  async ({ model, params }, data, trackerProperty) => {
@@ -1101,6 +1558,7 @@ const useDocumentActions = () => {
1101
1558
  defaultMessage: "Saved document"
1102
1559
  })
1103
1560
  });
1561
+ setCurrentStep("contentManager.success");
1104
1562
  return res.data;
1105
1563
  } catch (err) {
1106
1564
  toggleNotification({
@@ -1122,7 +1580,6 @@ const useDocumentActions = () => {
1122
1580
  sourceId
1123
1581
  });
1124
1582
  if ("error" in res) {
1125
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1126
1583
  return { error: res.error };
1127
1584
  }
1128
1585
  toggleNotification({
@@ -1141,7 +1598,7 @@ const useDocumentActions = () => {
1141
1598
  throw err;
1142
1599
  }
1143
1600
  },
1144
- [autoCloneDocument, formatAPIError, formatMessage, toggleNotification]
1601
+ [autoCloneDocument, formatMessage, toggleNotification]
1145
1602
  );
1146
1603
  const [cloneDocument] = useCloneDocumentMutation();
1147
1604
  const clone = React.useCallback(
@@ -1167,6 +1624,7 @@ const useDocumentActions = () => {
1167
1624
  defaultMessage: "Cloned document"
1168
1625
  })
1169
1626
  });
1627
+ navigate(`../../${res.data.data.documentId}`, { relative: "path" });
1170
1628
  return res.data;
1171
1629
  } catch (err) {
1172
1630
  toggleNotification({
@@ -1177,7 +1635,7 @@ const useDocumentActions = () => {
1177
1635
  throw err;
1178
1636
  }
1179
1637
  },
1180
- [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
1638
+ [cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
1181
1639
  );
1182
1640
  const [getDoc] = useLazyGetDocumentQuery();
1183
1641
  const getDocument = React.useCallback(
@@ -1192,17 +1650,20 @@ const useDocumentActions = () => {
1192
1650
  clone,
1193
1651
  create,
1194
1652
  delete: _delete,
1653
+ deleteMany,
1195
1654
  discard,
1196
1655
  getDocument,
1197
1656
  publish,
1657
+ publishMany,
1198
1658
  unpublish,
1659
+ unpublishMany,
1199
1660
  update
1200
1661
  };
1201
1662
  };
1202
- const ProtectedHistoryPage = lazy(
1203
- () => import("./History-Dmr9fmUA.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1663
+ const ProtectedHistoryPage = React.lazy(
1664
+ () => import("./History-CfCSNlG9.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
1204
1665
  );
1205
- const routes$1 = [
1666
+ const routes$2 = [
1206
1667
  {
1207
1668
  path: ":collectionType/:slug/:id/history",
1208
1669
  Component: ProtectedHistoryPage
@@ -1212,32 +1673,45 @@ const routes$1 = [
1212
1673
  Component: ProtectedHistoryPage
1213
1674
  }
1214
1675
  ];
1676
+ const ProtectedPreviewPage = React.lazy(
1677
+ () => import("./Preview-C_B1nx3g.mjs").then((mod) => ({ default: mod.ProtectedPreviewPage }))
1678
+ );
1679
+ const routes$1 = [
1680
+ {
1681
+ path: ":collectionType/:slug/:id/preview",
1682
+ Component: ProtectedPreviewPage
1683
+ },
1684
+ {
1685
+ path: ":collectionType/:slug/preview",
1686
+ Component: ProtectedPreviewPage
1687
+ }
1688
+ ];
1215
1689
  const ProtectedEditViewPage = lazy(
1216
- () => import("./EditViewPage-DDS6H9HO.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1690
+ () => import("./EditViewPage-B11aeMcf.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
1217
1691
  );
1218
1692
  const ProtectedListViewPage = lazy(
1219
- () => import("./ListViewPage-BtAwuYLE.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1693
+ () => import("./ListViewPage-BxLVROX8.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
1220
1694
  );
1221
1695
  const ProtectedListConfiguration = lazy(
1222
- () => import("./ListConfigurationPage-DhwvYcNv.mjs").then((mod) => ({
1696
+ () => import("./ListConfigurationPage-0mtv_iqk.mjs").then((mod) => ({
1223
1697
  default: mod.ProtectedListConfiguration
1224
1698
  }))
1225
1699
  );
1226
1700
  const ProtectedEditConfigurationPage = lazy(
1227
- () => import("./EditConfigurationPage-DacbqQ_f.mjs").then((mod) => ({
1701
+ () => import("./EditConfigurationPage-CKK-5LfX.mjs").then((mod) => ({
1228
1702
  default: mod.ProtectedEditConfigurationPage
1229
1703
  }))
1230
1704
  );
1231
1705
  const ProtectedComponentConfigurationPage = lazy(
1232
- () => import("./ComponentConfigurationPage-BPvzFjM7.mjs").then((mod) => ({
1706
+ () => import("./ComponentConfigurationPage-BaJMOQyq.mjs").then((mod) => ({
1233
1707
  default: mod.ProtectedComponentConfigurationPage
1234
1708
  }))
1235
1709
  );
1236
1710
  const NoPermissions = lazy(
1237
- () => import("./NoPermissionsPage-UWDC-1Tw.mjs").then((mod) => ({ default: mod.NoPermissions }))
1711
+ () => import("./NoPermissionsPage-CV9V8KWa.mjs").then((mod) => ({ default: mod.NoPermissions }))
1238
1712
  );
1239
1713
  const NoContentType = lazy(
1240
- () => import("./NoContentTypePage-DSPxnxxp.mjs").then((mod) => ({ default: mod.NoContentType }))
1714
+ () => import("./NoContentTypePage-BRfDd67_.mjs").then((mod) => ({ default: mod.NoContentType }))
1241
1715
  );
1242
1716
  const CollectionTypePages = () => {
1243
1717
  const { collectionType } = useParams();
@@ -1249,7 +1723,7 @@ const CollectionTypePages = () => {
1249
1723
  const CLONE_RELATIVE_PATH = ":collectionType/:slug/clone/:origin";
1250
1724
  const CLONE_PATH = `/content-manager/${CLONE_RELATIVE_PATH}`;
1251
1725
  const LIST_RELATIVE_PATH = ":collectionType/:slug";
1252
- const LIST_PATH = `/content-manager/${LIST_RELATIVE_PATH}`;
1726
+ const LIST_PATH = `/content-manager/collection-types/:slug`;
1253
1727
  const routes = [
1254
1728
  {
1255
1729
  path: LIST_RELATIVE_PATH,
@@ -1283,6 +1757,7 @@ const routes = [
1283
1757
  path: "no-content-types",
1284
1758
  Component: NoContentType
1285
1759
  },
1760
+ ...routes$2,
1286
1761
  ...routes$1
1287
1762
  ];
1288
1763
  const DocumentActions = ({ actions: actions2 }) => {
@@ -1351,12 +1826,14 @@ const DocumentActionButton = (action) => {
1351
1826
  /* @__PURE__ */ jsx(
1352
1827
  Button,
1353
1828
  {
1354
- flex: 1,
1829
+ flex: "auto",
1355
1830
  startIcon: action.icon,
1356
1831
  disabled: action.disabled,
1357
1832
  onClick: handleClick(action),
1358
1833
  justifyContent: "center",
1359
1834
  variant: action.variant || "default",
1835
+ paddingTop: "7px",
1836
+ paddingBottom: "7px",
1360
1837
  children: action.label
1361
1838
  }
1362
1839
  ),
@@ -1364,7 +1841,7 @@ const DocumentActionButton = (action) => {
1364
1841
  DocumentActionConfirmDialog,
1365
1842
  {
1366
1843
  ...action.dialog,
1367
- variant: action.variant,
1844
+ variant: action.dialog?.variant ?? action.variant,
1368
1845
  isOpen: dialogId === action.id,
1369
1846
  onClose: handleClose
1370
1847
  }
@@ -1379,6 +1856,11 @@ const DocumentActionButton = (action) => {
1379
1856
  ) : null
1380
1857
  ] });
1381
1858
  };
1859
+ const MenuItem = styled(Menu.Item)`
1860
+ &:hover {
1861
+ background: ${({ theme, isVariantDanger, isDisabled }) => isVariantDanger && !isDisabled ? theme.colors.danger100 : "neutral"};
1862
+ }
1863
+ `;
1382
1864
  const DocumentActionsMenu = ({
1383
1865
  actions: actions2,
1384
1866
  children,
@@ -1421,49 +1903,48 @@ const DocumentActionsMenu = ({
1421
1903
  disabled: isDisabled,
1422
1904
  size: "S",
1423
1905
  endIcon: null,
1424
- paddingTop: "7px",
1425
- paddingLeft: "9px",
1426
- paddingRight: "9px",
1906
+ paddingTop: "4px",
1907
+ paddingLeft: "7px",
1908
+ paddingRight: "7px",
1427
1909
  variant,
1428
1910
  children: [
1429
1911
  /* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
1430
- /* @__PURE__ */ jsx(VisuallyHidden, { as: "span", children: label || formatMessage({
1912
+ /* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: label || formatMessage({
1431
1913
  id: "content-manager.containers.edit.panels.default.more-actions",
1432
1914
  defaultMessage: "More document actions"
1433
1915
  }) })
1434
1916
  ]
1435
1917
  }
1436
1918
  ),
1437
- /* @__PURE__ */ jsxs(Menu.Content, { top: "4px", maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1919
+ /* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1438
1920
  actions2.map((action) => {
1439
1921
  return /* @__PURE__ */ jsx(
1440
- Menu.Item,
1922
+ MenuItem,
1441
1923
  {
1442
1924
  disabled: action.disabled,
1443
1925
  onSelect: handleClick(action),
1444
1926
  display: "block",
1445
- children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
1446
- /* @__PURE__ */ jsxs(Flex, { color: convertActionVariantToColor(action.variant), gap: 2, as: "span", children: [
1447
- action.icon,
1448
- action.label
1449
- ] }),
1450
- action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
1451
- Flex,
1452
- {
1453
- alignItems: "center",
1454
- background: "alternative100",
1455
- borderStyle: "solid",
1456
- borderColor: "alternative200",
1457
- borderWidth: "1px",
1458
- height: 5,
1459
- paddingLeft: 2,
1460
- paddingRight: 2,
1461
- hasRadius: true,
1462
- color: "alternative600",
1463
- children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
1464
- }
1465
- )
1466
- ] })
1927
+ isVariantDanger: action.variant === "danger",
1928
+ isDisabled: action.disabled,
1929
+ children: /* @__PURE__ */ jsx(Flex, { justifyContent: "space-between", gap: 4, children: /* @__PURE__ */ jsxs(
1930
+ Flex,
1931
+ {
1932
+ color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
1933
+ gap: 2,
1934
+ tag: "span",
1935
+ children: [
1936
+ /* @__PURE__ */ jsx(
1937
+ Flex,
1938
+ {
1939
+ tag: "span",
1940
+ color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
1941
+ children: action.icon
1942
+ }
1943
+ ),
1944
+ action.label
1945
+ ]
1946
+ }
1947
+ ) })
1467
1948
  },
1468
1949
  action.id
1469
1950
  );
@@ -1505,6 +1986,18 @@ const convertActionVariantToColor = (variant = "secondary") => {
1505
1986
  return "primary600";
1506
1987
  }
1507
1988
  };
1989
+ const convertActionVariantToIconColor = (variant = "secondary") => {
1990
+ switch (variant) {
1991
+ case "danger":
1992
+ return "danger600";
1993
+ case "secondary":
1994
+ return "neutral500";
1995
+ case "success":
1996
+ return "success600";
1997
+ default:
1998
+ return "primary600";
1999
+ }
2000
+ };
1508
2001
  const DocumentActionConfirmDialog = ({
1509
2002
  onClose,
1510
2003
  onCancel,
@@ -1527,61 +2020,54 @@ const DocumentActionConfirmDialog = ({
1527
2020
  }
1528
2021
  onClose();
1529
2022
  };
1530
- return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
1531
- /* @__PURE__ */ jsx(DialogBody, { children: content }),
1532
- /* @__PURE__ */ jsx(
1533
- DialogFooter,
1534
- {
1535
- startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
1536
- id: "app.components.Button.cancel",
1537
- defaultMessage: "Cancel"
1538
- }) }),
1539
- endAction: /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, children: formatMessage({
1540
- id: "app.components.Button.confirm",
1541
- defaultMessage: "Confirm"
1542
- }) })
1543
- }
1544
- )
1545
- ] });
2023
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2024
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2025
+ /* @__PURE__ */ jsx(Dialog.Body, { children: content }),
2026
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
2027
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
2028
+ id: "app.components.Button.cancel",
2029
+ defaultMessage: "Cancel"
2030
+ }) }) }),
2031
+ /* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
2032
+ id: "app.components.Button.confirm",
2033
+ defaultMessage: "Confirm"
2034
+ }) })
2035
+ ] })
2036
+ ] }) });
1546
2037
  };
1547
2038
  const DocumentActionModal = ({
1548
2039
  isOpen,
1549
2040
  title,
1550
2041
  onClose,
1551
2042
  footer: Footer,
1552
- content,
2043
+ content: Content,
1553
2044
  onModalClose
1554
2045
  }) => {
1555
- const id = React.useId();
1556
- if (!isOpen) {
1557
- return null;
1558
- }
1559
2046
  const handleClose = () => {
1560
2047
  if (onClose) {
1561
2048
  onClose();
1562
2049
  }
1563
2050
  onModalClose();
1564
2051
  };
1565
- return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
1566
- /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", as: "h2", id, children: title }) }),
1567
- /* @__PURE__ */ jsx(ModalBody, { children: content }),
1568
- /* @__PURE__ */ jsx(
1569
- Box,
1570
- {
1571
- paddingTop: 4,
1572
- paddingBottom: 4,
1573
- paddingLeft: 5,
1574
- paddingRight: 5,
1575
- borderWidth: "1px 0 0 0",
1576
- borderStyle: "solid",
1577
- borderColor: "neutral150",
1578
- background: "neutral100",
1579
- children: typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
1580
- }
1581
- )
1582
- ] });
2052
+ return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
2053
+ /* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
2054
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
2055
+ typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
2056
+ ] }) });
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;
1583
2069
  };
1584
- const PublishAction = ({
2070
+ const PublishAction$1 = ({
1585
2071
  activeTab,
1586
2072
  documentId,
1587
2073
  model,
@@ -1593,13 +2079,18 @@ const PublishAction = ({
1593
2079
  const navigate = useNavigate();
1594
2080
  const { toggleNotification } = useNotification();
1595
2081
  const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
2082
+ const isListView = useMatch(LIST_PATH) !== null;
1596
2083
  const isCloning = useMatch(CLONE_PATH) !== null;
2084
+ const { id } = useParams();
1597
2085
  const { formatMessage } = useIntl();
1598
- const { canPublish, canCreate, canUpdate } = useDocumentRBAC(
1599
- "PublishAction",
1600
- ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
1601
- );
2086
+ const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
1602
2087
  const { publish } = useDocumentActions();
2088
+ const [
2089
+ countDraftRelations,
2090
+ { isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
2091
+ ] = useLazyGetDraftRelationCountQuery();
2092
+ const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
2093
+ const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
1603
2094
  const [{ query, rawQuery }] = useQueryParams();
1604
2095
  const params = React.useMemo(() => buildValidParams(query), [query]);
1605
2096
  const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
@@ -1608,10 +2099,107 @@ const PublishAction = ({
1608
2099
  const validate = useForm("PublishAction", (state) => state.validate);
1609
2100
  const setErrors = useForm("PublishAction", (state) => state.setErrors);
1610
2101
  const formValues = useForm("PublishAction", ({ values }) => values);
2102
+ React.useEffect(() => {
2103
+ if (isErrorDraftRelations) {
2104
+ toggleNotification({
2105
+ type: "danger",
2106
+ message: formatMessage({
2107
+ id: getTranslation("error.records.fetch-draft-relatons"),
2108
+ defaultMessage: "An error occurred while fetching draft relations on this document."
2109
+ })
2110
+ });
2111
+ }
2112
+ }, [isErrorDraftRelations, toggleNotification, formatMessage]);
2113
+ React.useEffect(() => {
2114
+ const localDraftRelations = /* @__PURE__ */ new Set();
2115
+ const extractDraftRelations = (data) => {
2116
+ const relations = data.connect || [];
2117
+ relations.forEach((relation) => {
2118
+ if (relation.status === "draft") {
2119
+ localDraftRelations.add(relation.id);
2120
+ }
2121
+ });
2122
+ };
2123
+ const traverseAndExtract = (data) => {
2124
+ Object.entries(data).forEach(([key, value]) => {
2125
+ if (key === "connect" && Array.isArray(value)) {
2126
+ extractDraftRelations({ connect: value });
2127
+ } else if (typeof value === "object" && value !== null) {
2128
+ traverseAndExtract(value);
2129
+ }
2130
+ });
2131
+ };
2132
+ if (!documentId || modified) {
2133
+ traverseAndExtract(formValues);
2134
+ setLocalCountOfDraftRelations(localDraftRelations.size);
2135
+ }
2136
+ }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
2137
+ React.useEffect(() => {
2138
+ if (!document || !document.documentId || isListView) {
2139
+ return;
2140
+ }
2141
+ const fetchDraftRelationsCount = async () => {
2142
+ const { data, error } = await countDraftRelations({
2143
+ collectionType,
2144
+ model,
2145
+ documentId,
2146
+ params
2147
+ });
2148
+ if (error) {
2149
+ throw error;
2150
+ }
2151
+ if (data) {
2152
+ setServerCountOfDraftRelations(data.data);
2153
+ }
2154
+ };
2155
+ fetchDraftRelationsCount();
2156
+ }, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
1611
2157
  const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
1612
2158
  if (!schema?.options?.draftAndPublish) {
1613
2159
  return null;
1614
2160
  }
2161
+ const performPublish = async () => {
2162
+ setSubmitting(true);
2163
+ try {
2164
+ const { errors } = await validate(true, {
2165
+ status: "published"
2166
+ });
2167
+ if (errors) {
2168
+ toggleNotification({
2169
+ type: "danger",
2170
+ message: formatMessage({
2171
+ id: "content-manager.validation.error",
2172
+ defaultMessage: "There are validation errors in your document. Please fix them before saving."
2173
+ })
2174
+ });
2175
+ return;
2176
+ }
2177
+ const res = await publish(
2178
+ {
2179
+ collectionType,
2180
+ model,
2181
+ documentId,
2182
+ params
2183
+ },
2184
+ transformData(formValues)
2185
+ );
2186
+ if ("data" in res && collectionType !== SINGLE_TYPES) {
2187
+ if (id === "create") {
2188
+ navigate({
2189
+ pathname: `../${collectionType}/${model}/${res.data.documentId}`,
2190
+ search: rawQuery
2191
+ });
2192
+ }
2193
+ } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2194
+ setErrors(formatValidationErrors(res.error));
2195
+ }
2196
+ } finally {
2197
+ setSubmitting(false);
2198
+ }
2199
+ };
2200
+ const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
2201
+ const enableDraftRelationsCount = false;
2202
+ const hasDraftRelations = enableDraftRelationsCount;
1615
2203
  return {
1616
2204
  /**
1617
2205
  * Disabled when:
@@ -1621,52 +2209,39 @@ const PublishAction = ({
1621
2209
  * - the document is already published & not modified
1622
2210
  * - the document is being created & not modified
1623
2211
  * - the user doesn't have the permission to publish
1624
- * - the user doesn't have the permission to create a new document
1625
- * - the user doesn't have the permission to update the document
1626
2212
  */
1627
- disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish || Boolean(!document?.documentId && !canCreate || document?.documentId && !canUpdate),
2213
+ disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
1628
2214
  label: formatMessage({
1629
2215
  id: "app.utils.publish",
1630
2216
  defaultMessage: "Publish"
1631
2217
  }),
1632
2218
  onClick: async () => {
1633
- setSubmitting(true);
1634
- try {
1635
- const { errors } = await validate();
1636
- if (errors) {
1637
- toggleNotification({
1638
- type: "danger",
1639
- message: formatMessage({
1640
- id: "content-manager.validation.error",
1641
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
1642
- })
1643
- });
1644
- return;
1645
- }
1646
- const res = await publish(
1647
- {
1648
- collectionType,
1649
- model,
1650
- documentId,
1651
- params
1652
- },
1653
- formValues
1654
- );
1655
- if ("data" in res && collectionType !== SINGLE_TYPES) {
1656
- navigate({
1657
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1658
- search: rawQuery
1659
- });
1660
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1661
- setErrors(formatValidationErrors(res.error));
2219
+ await performPublish();
2220
+ },
2221
+ dialog: hasDraftRelations ? {
2222
+ type: "dialog",
2223
+ variant: "danger",
2224
+ footer: null,
2225
+ title: formatMessage({
2226
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
2227
+ defaultMessage: "Confirmation"
2228
+ }),
2229
+ content: formatMessage(
2230
+ {
2231
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
2232
+ defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
2233
+ },
2234
+ {
2235
+ count: totalDraftRelations
1662
2236
  }
1663
- } finally {
1664
- setSubmitting(false);
2237
+ ),
2238
+ onConfirm: async () => {
2239
+ await performPublish();
1665
2240
  }
1666
- }
2241
+ } : void 0
1667
2242
  };
1668
2243
  };
1669
- PublishAction.type = "publish";
2244
+ PublishAction$1.type = "publish";
1670
2245
  const UpdateAction = ({
1671
2246
  activeTab,
1672
2247
  documentId,
@@ -1679,10 +2254,6 @@ const UpdateAction = ({
1679
2254
  const cloneMatch = useMatch(CLONE_PATH);
1680
2255
  const isCloning = cloneMatch !== null;
1681
2256
  const { formatMessage } = useIntl();
1682
- const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
1683
- canCreate: canCreate2,
1684
- canUpdate: canUpdate2
1685
- }));
1686
2257
  const { create, update, clone } = useDocumentActions();
1687
2258
  const [{ query, rawQuery }] = useQueryParams();
1688
2259
  const params = React.useMemo(() => buildValidParams(query), [query]);
@@ -1699,18 +2270,18 @@ const UpdateAction = ({
1699
2270
  * - the form is submitting
1700
2271
  * - the document is not modified & we're not cloning (you can save a clone entity straight away)
1701
2272
  * - the active tab is the published tab
1702
- * - the user doesn't have the permission to create a new document
1703
- * - the user doesn't have the permission to update the document
1704
2273
  */
1705
- disabled: isSubmitting || !modified && !isCloning || activeTab === "published" || Boolean(!documentId && !canCreate || documentId && !canUpdate),
2274
+ disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
1706
2275
  label: formatMessage({
1707
- id: "content-manager.containers.Edit.save",
2276
+ id: "global.save",
1708
2277
  defaultMessage: "Save"
1709
2278
  }),
1710
2279
  onClick: async () => {
1711
2280
  setSubmitting(true);
1712
2281
  try {
1713
- const { errors } = await validate();
2282
+ const { errors } = await validate(true, {
2283
+ status: "draft"
2284
+ });
1714
2285
  if (errors) {
1715
2286
  toggleNotification({
1716
2287
  type: "danger",
@@ -1728,13 +2299,16 @@ const UpdateAction = ({
1728
2299
  documentId: cloneMatch.params.origin,
1729
2300
  params
1730
2301
  },
1731
- document
2302
+ transformData(document)
1732
2303
  );
1733
2304
  if ("data" in res) {
1734
- navigate({
1735
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1736
- search: rawQuery
1737
- });
2305
+ navigate(
2306
+ {
2307
+ pathname: `../${res.data.documentId}`,
2308
+ search: rawQuery
2309
+ },
2310
+ { relative: "path" }
2311
+ );
1738
2312
  } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1739
2313
  setErrors(formatValidationErrors(res.error));
1740
2314
  }
@@ -1746,7 +2320,7 @@ const UpdateAction = ({
1746
2320
  documentId,
1747
2321
  params
1748
2322
  },
1749
- document
2323
+ transformData(document)
1750
2324
  );
1751
2325
  if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1752
2326
  setErrors(formatValidationErrors(res.error));
@@ -1759,13 +2333,16 @@ const UpdateAction = ({
1759
2333
  model,
1760
2334
  params
1761
2335
  },
1762
- document
2336
+ transformData(document)
1763
2337
  );
1764
2338
  if ("data" in res && collectionType !== SINGLE_TYPES) {
1765
- navigate({
1766
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1767
- search: rawQuery
1768
- });
2339
+ navigate(
2340
+ {
2341
+ pathname: `../${res.data.documentId}`,
2342
+ search: rawQuery
2343
+ },
2344
+ { replace: true, relative: "path" }
2345
+ );
1769
2346
  } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1770
2347
  setErrors(formatValidationErrors(res.error));
1771
2348
  }
@@ -1781,7 +2358,7 @@ const UNPUBLISH_DRAFT_OPTIONS = {
1781
2358
  KEEP: "keep",
1782
2359
  DISCARD: "discard"
1783
2360
  };
1784
- const UnpublishAction = ({
2361
+ const UnpublishAction$1 = ({
1785
2362
  activeTab,
1786
2363
  documentId,
1787
2364
  model,
@@ -1797,10 +2374,8 @@ const UnpublishAction = ({
1797
2374
  const { toggleNotification } = useNotification();
1798
2375
  const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
1799
2376
  const isDocumentModified = document?.status === "modified";
1800
- const handleChange = (e) => {
1801
- if ("value" in e.target) {
1802
- setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
1803
- }
2377
+ const handleChange = (value) => {
2378
+ setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
1804
2379
  };
1805
2380
  if (!schema?.options?.draftAndPublish) {
1806
2381
  return null;
@@ -1811,7 +2386,7 @@ const UnpublishAction = ({
1811
2386
  id: "app.utils.unpublish",
1812
2387
  defaultMessage: "Unpublish"
1813
2388
  }),
1814
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2389
+ icon: /* @__PURE__ */ jsx(Cross, {}),
1815
2390
  onClick: async () => {
1816
2391
  if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
1817
2392
  if (!documentId) {
@@ -1844,45 +2419,30 @@ const UnpublishAction = ({
1844
2419
  content: /* @__PURE__ */ jsxs(Flex, { alignItems: "flex-start", direction: "column", gap: 6, children: [
1845
2420
  /* @__PURE__ */ jsxs(Flex, { width: "100%", direction: "column", gap: 2, children: [
1846
2421
  /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
1847
- /* @__PURE__ */ jsx(Typography, { as: "p", variant: "omega", textAlign: "center", children: formatMessage({
2422
+ /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
1848
2423
  id: "content-manager.actions.unpublish.dialog.body",
1849
2424
  defaultMessage: "Are you sure?"
1850
2425
  }) })
1851
2426
  ] }),
1852
2427
  /* @__PURE__ */ jsxs(
1853
- Flex,
2428
+ Radio.Group,
1854
2429
  {
1855
- onChange: handleChange,
1856
- direction: "column",
1857
- alignItems: "flex-start",
1858
- as: "fieldset",
1859
- gap: 3,
2430
+ defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
2431
+ name: "discard-options",
2432
+ "aria-label": formatMessage({
2433
+ id: "content-manager.actions.unpublish.dialog.radio-label",
2434
+ defaultMessage: "Choose an option to unpublish the document."
2435
+ }),
2436
+ onValueChange: handleChange,
1860
2437
  children: [
1861
- /* @__PURE__ */ jsx(VisuallyHidden, { as: "legend" }),
1862
- /* @__PURE__ */ jsx(
1863
- Radio,
1864
- {
1865
- checked: shouldKeepDraft,
1866
- value: UNPUBLISH_DRAFT_OPTIONS.KEEP,
1867
- name: "discard-options",
1868
- children: formatMessage({
1869
- id: "content-manager.actions.unpublish.dialog.option.keep-draft",
1870
- defaultMessage: "Keep draft"
1871
- })
1872
- }
1873
- ),
1874
- /* @__PURE__ */ jsx(
1875
- Radio,
1876
- {
1877
- checked: !shouldKeepDraft,
1878
- value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
1879
- name: "discard-options",
1880
- children: formatMessage({
1881
- id: "content-manager.actions.unpublish.dialog.option.replace-draft",
1882
- defaultMessage: "Replace draft"
1883
- })
1884
- }
1885
- )
2438
+ /* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
2439
+ id: "content-manager.actions.unpublish.dialog.option.keep-draft",
2440
+ defaultMessage: "Keep draft"
2441
+ }) }),
2442
+ /* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
2443
+ id: "content-manager.actions.unpublish.dialog.option.replace-draft",
2444
+ defaultMessage: "Replace draft"
2445
+ }) })
1886
2446
  ]
1887
2447
  }
1888
2448
  )
@@ -1915,7 +2475,7 @@ const UnpublishAction = ({
1915
2475
  position: ["panel", "table-row"]
1916
2476
  };
1917
2477
  };
1918
- UnpublishAction.type = "unpublish";
2478
+ UnpublishAction$1.type = "unpublish";
1919
2479
  const DiscardAction = ({
1920
2480
  activeTab,
1921
2481
  documentId,
@@ -1938,7 +2498,7 @@ const DiscardAction = ({
1938
2498
  id: "content-manager.actions.discard.label",
1939
2499
  defaultMessage: "Discard changes"
1940
2500
  }),
1941
- icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
2501
+ icon: /* @__PURE__ */ jsx(Cross, {}),
1942
2502
  position: ["panel", "table-row"],
1943
2503
  variant: "danger",
1944
2504
  dialog: {
@@ -1949,7 +2509,7 @@ const DiscardAction = ({
1949
2509
  }),
1950
2510
  content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
1951
2511
  /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
1952
- /* @__PURE__ */ jsx(Typography, { as: "p", variant: "omega", textAlign: "center", children: formatMessage({
2512
+ /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
1953
2513
  id: "content-manager.actions.discard.dialog.body",
1954
2514
  defaultMessage: "Are you sure?"
1955
2515
  }) })
@@ -1966,12 +2526,7 @@ const DiscardAction = ({
1966
2526
  };
1967
2527
  };
1968
2528
  DiscardAction.type = "discard";
1969
- const StyledCrossCircle = styled(CrossCircle)`
1970
- path {
1971
- fill: currentColor;
1972
- }
1973
- `;
1974
- const DEFAULT_ACTIONS = [PublishAction, UpdateAction, UnpublishAction, DiscardAction];
2529
+ const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
1975
2530
  const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
1976
2531
  const RelativeTime = React.forwardRef(
1977
2532
  ({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
@@ -1983,7 +2538,7 @@ const RelativeTime = React.forwardRef(
1983
2538
  });
1984
2539
  const unit = intervals.find((intervalUnit) => {
1985
2540
  return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
1986
- });
2541
+ }) ?? "seconds";
1987
2542
  const relativeTime = isPast(timestamp) ? -interval[unit] : interval[unit];
1988
2543
  const customInterval = customIntervals.find(
1989
2544
  (custom) => interval[custom.unit] < custom.threshold
@@ -2017,34 +2572,34 @@ const getDisplayName = ({
2017
2572
  return email ?? "";
2018
2573
  };
2019
2574
  const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2020
- const DocumentStatus = ({ status = "draft", ...restProps }) => {
2021
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
2022
- return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { as: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
2575
+ const DocumentStatus = ({ status = "draft", size = "S", ...restProps }) => {
2576
+ const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
2577
+ const { formatMessage } = useIntl();
2578
+ return /* @__PURE__ */ jsx(Status, { ...restProps, size, variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: formatMessage({
2579
+ id: `content-manager.containers.List.${status}`,
2580
+ defaultMessage: capitalise(status)
2581
+ }) }) });
2023
2582
  };
2024
2583
  const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
2025
2584
  const { formatMessage } = useIntl();
2026
2585
  const isCloning = useMatch(CLONE_PATH) !== null;
2586
+ const params = useParams();
2027
2587
  const title = isCreating ? formatMessage({
2028
2588
  id: "content-manager.containers.edit.title.new",
2029
2589
  defaultMessage: "Create an entry"
2030
2590
  }) : documentTitle;
2031
- return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 8, paddingBottom: 4, gap: 3, children: [
2032
- /* @__PURE__ */ jsx(BackButton, {}),
2033
- /* @__PURE__ */ jsxs(
2034
- Flex,
2591
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
2592
+ /* @__PURE__ */ jsx(
2593
+ BackButton,
2035
2594
  {
2036
- width: "100%",
2037
- justifyContent: "space-between",
2038
- paddingTop: 1,
2039
- gap: "80px",
2040
- alignItems: "flex-start",
2041
- children: [
2042
- /* @__PURE__ */ jsx(Typography, { variant: "alpha", as: "h1", children: title }),
2043
- /* @__PURE__ */ jsx(HeaderToolbar, {})
2044
- ]
2595
+ fallback: params.collectionType === SINGLE_TYPES ? void 0 : `../${COLLECTION_TYPES}/${params.slug}`
2045
2596
  }
2046
2597
  ),
2047
- status ? /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
2598
+ /* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
2599
+ /* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
2600
+ /* @__PURE__ */ jsx(HeaderToolbar, {})
2601
+ ] }),
2602
+ status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
2048
2603
  ] });
2049
2604
  };
2050
2605
  const HeaderToolbar = () => {
@@ -2127,12 +2682,12 @@ const Information = ({ activeTab }) => {
2127
2682
  isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
2128
2683
  label: formatMessage({
2129
2684
  id: "content-manager.containers.edit.information.last-published.label",
2130
- defaultMessage: "Last published"
2685
+ defaultMessage: "Published"
2131
2686
  }),
2132
2687
  value: formatMessage(
2133
2688
  {
2134
2689
  id: "content-manager.containers.edit.information.last-published.value",
2135
- defaultMessage: `Published {time}{isAnonymous, select, true {} other { by {author}}}`
2690
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2136
2691
  },
2137
2692
  {
2138
2693
  time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
@@ -2145,12 +2700,12 @@ const Information = ({ activeTab }) => {
2145
2700
  isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
2146
2701
  label: formatMessage({
2147
2702
  id: "content-manager.containers.edit.information.last-draft.label",
2148
- defaultMessage: "Last draft"
2703
+ defaultMessage: "Updated"
2149
2704
  }),
2150
2705
  value: formatMessage(
2151
2706
  {
2152
2707
  id: "content-manager.containers.edit.information.last-draft.value",
2153
- defaultMessage: `Modified {time}{isAnonymous, select, true {} other { by {author}}}`
2708
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2154
2709
  },
2155
2710
  {
2156
2711
  time: /* @__PURE__ */ jsx(
@@ -2168,12 +2723,12 @@ const Information = ({ activeTab }) => {
2168
2723
  isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
2169
2724
  label: formatMessage({
2170
2725
  id: "content-manager.containers.edit.information.document.label",
2171
- defaultMessage: "Document"
2726
+ defaultMessage: "Created"
2172
2727
  }),
2173
2728
  value: formatMessage(
2174
2729
  {
2175
2730
  id: "content-manager.containers.edit.information.document.value",
2176
- defaultMessage: `Created {time}{isAnonymous, select, true {} other { by {author}}}`
2731
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2177
2732
  },
2178
2733
  {
2179
2734
  time: /* @__PURE__ */ jsx(
@@ -2196,7 +2751,7 @@ const Information = ({ activeTab }) => {
2196
2751
  borderColor: "neutral150",
2197
2752
  direction: "column",
2198
2753
  marginTop: 2,
2199
- as: "dl",
2754
+ tag: "dl",
2200
2755
  padding: 5,
2201
2756
  gap: 3,
2202
2757
  alignItems: "flex-start",
@@ -2204,41 +2759,93 @@ const Information = ({ activeTab }) => {
2204
2759
  marginRight: "-0.4rem",
2205
2760
  width: "calc(100% + 8px)",
2206
2761
  children: information.map((info) => /* @__PURE__ */ jsxs(Flex, { gap: 1, direction: "column", alignItems: "flex-start", children: [
2207
- /* @__PURE__ */ jsx(Typography, { as: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
2208
- /* @__PURE__ */ jsx(Typography, { as: "dd", variant: "pi", textColor: "neutral600", children: info.value })
2762
+ /* @__PURE__ */ jsx(Typography, { tag: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
2763
+ /* @__PURE__ */ jsx(Typography, { tag: "dd", variant: "pi", textColor: "neutral600", children: info.value })
2209
2764
  ] }, info.label))
2210
2765
  }
2211
2766
  );
2212
2767
  };
2213
2768
  const HeaderActions = ({ actions: actions2 }) => {
2214
- return /* @__PURE__ */ jsx(Flex, { children: actions2.map((action) => {
2215
- if ("options" in action) {
2769
+ const [dialogId, setDialogId] = React.useState(null);
2770
+ const handleClick = (action) => async (e) => {
2771
+ if (!("options" in action)) {
2772
+ const { onClick = () => false, dialog, id } = action;
2773
+ const muteDialog = await onClick(e);
2774
+ if (dialog && !muteDialog) {
2775
+ e.preventDefault();
2776
+ setDialogId(id);
2777
+ }
2778
+ }
2779
+ };
2780
+ const handleClose = () => {
2781
+ setDialogId(null);
2782
+ };
2783
+ return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
2784
+ if (action.options) {
2216
2785
  return /* @__PURE__ */ jsx(
2217
2786
  SingleSelect,
2218
2787
  {
2219
2788
  size: "S",
2220
- disabled: action.disabled,
2221
- "aria-label": action.label,
2222
2789
  onChange: action.onSelect,
2223
- value: action.value,
2790
+ "aria-label": action.label,
2791
+ ...action,
2224
2792
  children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
2225
2793
  },
2226
2794
  action.id
2227
2795
  );
2228
2796
  } else {
2229
- return null;
2230
- }
2231
- }) });
2232
- };
2233
- const ConfigureTheViewAction = ({ collectionType, model }) => {
2234
- const navigate = useNavigate();
2235
- const { formatMessage } = useIntl();
2797
+ if (action.type === "icon") {
2798
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
2799
+ /* @__PURE__ */ jsx(
2800
+ IconButton,
2801
+ {
2802
+ disabled: action.disabled,
2803
+ label: action.label,
2804
+ size: "S",
2805
+ onClick: handleClick(action),
2806
+ children: action.icon
2807
+ }
2808
+ ),
2809
+ action.dialog ? /* @__PURE__ */ jsx(
2810
+ HeaderActionDialog,
2811
+ {
2812
+ ...action.dialog,
2813
+ isOpen: dialogId === action.id,
2814
+ onClose: handleClose
2815
+ }
2816
+ ) : null
2817
+ ] }, action.id);
2818
+ }
2819
+ }
2820
+ }) });
2821
+ };
2822
+ const HeaderActionDialog = ({
2823
+ onClose,
2824
+ onCancel,
2825
+ title,
2826
+ content: Content,
2827
+ isOpen
2828
+ }) => {
2829
+ const handleClose = async () => {
2830
+ if (onCancel) {
2831
+ await onCancel();
2832
+ }
2833
+ onClose();
2834
+ };
2835
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
2836
+ /* @__PURE__ */ jsx(Dialog.Header, { children: title }),
2837
+ typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
2838
+ ] }) });
2839
+ };
2840
+ const ConfigureTheViewAction = ({ collectionType, model }) => {
2841
+ const navigate = useNavigate();
2842
+ const { formatMessage } = useIntl();
2236
2843
  return {
2237
2844
  label: formatMessage({
2238
2845
  id: "app.links.configure-view",
2239
2846
  defaultMessage: "Configure the view"
2240
2847
  }),
2241
- icon: /* @__PURE__ */ jsx(StyledCog, {}),
2848
+ icon: /* @__PURE__ */ jsx(ListPlus, {}),
2242
2849
  onClick: () => {
2243
2850
  navigate(`../${collectionType}/${model}/configurations/edit`);
2244
2851
  },
@@ -2246,11 +2853,6 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
2246
2853
  };
2247
2854
  };
2248
2855
  ConfigureTheViewAction.type = "configure-the-view";
2249
- const StyledCog = styled(Cog)`
2250
- path {
2251
- fill: currentColor;
2252
- }
2253
- `;
2254
2856
  const EditTheModelAction = ({ model }) => {
2255
2857
  const navigate = useNavigate();
2256
2858
  const { formatMessage } = useIntl();
@@ -2259,7 +2861,7 @@ const EditTheModelAction = ({ model }) => {
2259
2861
  id: "content-manager.link-to-ctb",
2260
2862
  defaultMessage: "Edit the model"
2261
2863
  }),
2262
- icon: /* @__PURE__ */ jsx(StyledPencil$1, {}),
2864
+ icon: /* @__PURE__ */ jsx(Pencil, {}),
2263
2865
  onClick: () => {
2264
2866
  navigate(`/plugins/content-type-builder/content-types/${model}`);
2265
2867
  },
@@ -2267,12 +2869,7 @@ const EditTheModelAction = ({ model }) => {
2267
2869
  };
2268
2870
  };
2269
2871
  EditTheModelAction.type = "edit-the-model";
2270
- const StyledPencil$1 = styled(Pencil)`
2271
- path {
2272
- fill: currentColor;
2273
- }
2274
- `;
2275
- const DeleteAction = ({ documentId, model, collectionType, document }) => {
2872
+ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2276
2873
  const navigate = useNavigate();
2277
2874
  const { formatMessage } = useIntl();
2278
2875
  const listViewPathMatch = useMatch(LIST_PATH);
@@ -2280,13 +2877,17 @@ const DeleteAction = ({ documentId, model, collectionType, document }) => {
2280
2877
  const { delete: deleteAction } = useDocumentActions();
2281
2878
  const { toggleNotification } = useNotification();
2282
2879
  const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
2880
+ const isLocalized = document?.locale != null;
2283
2881
  return {
2284
2882
  disabled: !canDelete || !document,
2285
- label: formatMessage({
2286
- id: "content-manager.actions.delete.label",
2287
- defaultMessage: "Delete document"
2288
- }),
2289
- icon: /* @__PURE__ */ jsx(StyledTrash, {}),
2883
+ label: formatMessage(
2884
+ {
2885
+ id: "content-manager.actions.delete.label",
2886
+ defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
2887
+ },
2888
+ { isLocalized }
2889
+ ),
2890
+ icon: /* @__PURE__ */ jsx(Trash, {}),
2290
2891
  dialog: {
2291
2892
  type: "dialog",
2292
2893
  title: formatMessage({
@@ -2295,7 +2896,7 @@ const DeleteAction = ({ documentId, model, collectionType, document }) => {
2295
2896
  }),
2296
2897
  content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
2297
2898
  /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2298
- /* @__PURE__ */ jsx(Typography, { as: "p", variant: "omega", textAlign: "center", children: formatMessage({
2899
+ /* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2299
2900
  id: "content-manager.actions.delete.dialog.body",
2300
2901
  defaultMessage: "Are you sure?"
2301
2902
  }) })
@@ -2340,13 +2941,8 @@ const DeleteAction = ({ documentId, model, collectionType, document }) => {
2340
2941
  position: ["header", "table-row"]
2341
2942
  };
2342
2943
  };
2343
- DeleteAction.type = "delete";
2344
- const StyledTrash = styled(Trash)`
2345
- path {
2346
- fill: currentColor;
2347
- }
2348
- `;
2349
- const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction];
2944
+ DeleteAction$1.type = "delete";
2945
+ const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
2350
2946
  const Panels = () => {
2351
2947
  const isCloning = useMatch(CLONE_PATH) !== null;
2352
2948
  const [
@@ -2380,7 +2976,7 @@ const ActionsPanel = () => {
2380
2976
  return {
2381
2977
  title: formatMessage({
2382
2978
  id: "content-manager.containers.edit.panels.default.title",
2383
- defaultMessage: "Document"
2979
+ defaultMessage: "Entry"
2384
2980
  }),
2385
2981
  content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
2386
2982
  };
@@ -2420,7 +3016,7 @@ const Panel = React.forwardRef(({ children, title }, ref) => {
2420
3016
  Flex,
2421
3017
  {
2422
3018
  ref,
2423
- as: "aside",
3019
+ tag: "aside",
2424
3020
  "aria-labelledby": "additional-information",
2425
3021
  background: "neutral0",
2426
3022
  borderColor: "neutral150",
@@ -2435,13 +3031,590 @@ const Panel = React.forwardRef(({ children, title }, ref) => {
2435
3031
  justifyContent: "stretch",
2436
3032
  alignItems: "flex-start",
2437
3033
  children: [
2438
- /* @__PURE__ */ jsx(Typography, { as: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
3034
+ /* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
2439
3035
  children
2440
3036
  ]
2441
3037
  }
2442
3038
  );
2443
3039
  });
2444
- const DEFAULT_BULK_ACTIONS = [];
3040
+ const ConfirmBulkActionDialog = ({
3041
+ onToggleDialog,
3042
+ isOpen = false,
3043
+ dialogBody,
3044
+ endAction
3045
+ }) => {
3046
+ const { formatMessage } = useIntl();
3047
+ return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
3048
+ /* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
3049
+ id: "app.components.ConfirmDialog.title",
3050
+ defaultMessage: "Confirmation"
3051
+ }) }),
3052
+ /* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3053
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3054
+ dialogBody
3055
+ ] }) }),
3056
+ /* @__PURE__ */ jsxs(Dialog.Footer, { children: [
3057
+ /* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
3058
+ id: "app.components.Button.cancel",
3059
+ defaultMessage: "Cancel"
3060
+ }) }) }),
3061
+ endAction
3062
+ ] })
3063
+ ] }) });
3064
+ };
3065
+ const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
3066
+ const ConfirmDialogPublishAll = ({
3067
+ isOpen,
3068
+ onToggleDialog,
3069
+ isConfirmButtonLoading = false,
3070
+ onConfirm
3071
+ }) => {
3072
+ const { formatMessage } = useIntl();
3073
+ const selectedEntries = useTable("ConfirmDialogPublishAll", (state) => state.selectedRows);
3074
+ const { toggleNotification } = useNotification();
3075
+ const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
3076
+ const { model, schema } = useDoc();
3077
+ const [{ query }] = useQueryParams();
3078
+ const enableDraftRelationsCount = false;
3079
+ const {
3080
+ data: countDraftRelations = 0,
3081
+ isLoading,
3082
+ error
3083
+ } = useGetManyDraftRelationCountQuery(
3084
+ {
3085
+ model,
3086
+ documentIds: selectedEntries.map((entry) => entry.documentId),
3087
+ locale: query?.plugins?.i18n?.locale
3088
+ },
3089
+ {
3090
+ skip: !enableDraftRelationsCount
3091
+ }
3092
+ );
3093
+ React.useEffect(() => {
3094
+ if (error) {
3095
+ toggleNotification({ type: "danger", message: formatAPIError(error) });
3096
+ }
3097
+ }, [error, formatAPIError, toggleNotification]);
3098
+ if (error) {
3099
+ return null;
3100
+ }
3101
+ return /* @__PURE__ */ jsx(
3102
+ ConfirmBulkActionDialog,
3103
+ {
3104
+ isOpen: isOpen && !isLoading,
3105
+ onToggleDialog,
3106
+ dialogBody: /* @__PURE__ */ jsxs(Fragment, { children: [
3107
+ /* @__PURE__ */ jsxs(Typography, { id: "confirm-description", textAlign: "center", children: [
3108
+ countDraftRelations > 0 && formatMessage(
3109
+ {
3110
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
3111
+ defaultMessage: "<b>{count} {count, plural, one { relation } other { relations } } out of {entities} { entities, plural, one { entry } other { entries } } {count, plural, one { is } other { are } }</b> not published yet and might lead to unexpected behavior. "
3112
+ },
3113
+ {
3114
+ b: BoldChunk$1,
3115
+ count: countDraftRelations,
3116
+ entities: selectedEntries.length
3117
+ }
3118
+ ),
3119
+ formatMessage({
3120
+ id: getTranslation("popUpWarning.bodyMessage.contentType.publish.all"),
3121
+ defaultMessage: "Are you sure you want to publish these entries?"
3122
+ })
3123
+ ] }),
3124
+ schema?.pluginOptions && "i18n" in schema.pluginOptions && schema?.pluginOptions.i18n && /* @__PURE__ */ jsx(Typography, { textColor: "danger500", textAlign: "center", children: formatMessage(
3125
+ {
3126
+ id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
3127
+ defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
3128
+ },
3129
+ {
3130
+ em: Emphasis
3131
+ }
3132
+ ) })
3133
+ ] }),
3134
+ endAction: /* @__PURE__ */ jsx(
3135
+ Button,
3136
+ {
3137
+ onClick: onConfirm,
3138
+ variant: "secondary",
3139
+ startIcon: /* @__PURE__ */ jsx(Check, {}),
3140
+ loading: isConfirmButtonLoading,
3141
+ children: formatMessage({
3142
+ id: "app.utils.publish",
3143
+ defaultMessage: "Publish"
3144
+ })
3145
+ }
3146
+ )
3147
+ }
3148
+ );
3149
+ };
3150
+ const TypographyMaxWidth = styled(Typography)`
3151
+ max-width: 300px;
3152
+ `;
3153
+ const formatErrorMessages = (errors, parentKey, formatMessage) => {
3154
+ const messages = [];
3155
+ Object.entries(errors).forEach(([key, value]) => {
3156
+ const currentKey = parentKey ? `${parentKey}.${key}` : key;
3157
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
3158
+ if ("id" in value && "defaultMessage" in value) {
3159
+ messages.push(
3160
+ formatMessage(
3161
+ {
3162
+ id: `${value.id}.withField`,
3163
+ defaultMessage: value.defaultMessage
3164
+ },
3165
+ { field: currentKey }
3166
+ )
3167
+ );
3168
+ } else {
3169
+ messages.push(
3170
+ ...formatErrorMessages(
3171
+ // @ts-expect-error TODO: check why value is not compatible with FormErrors
3172
+ value,
3173
+ currentKey,
3174
+ formatMessage
3175
+ )
3176
+ );
3177
+ }
3178
+ } else {
3179
+ messages.push(
3180
+ formatMessage(
3181
+ {
3182
+ id: `${value}.withField`,
3183
+ defaultMessage: value
3184
+ },
3185
+ { field: currentKey }
3186
+ )
3187
+ );
3188
+ }
3189
+ });
3190
+ return messages;
3191
+ };
3192
+ const EntryValidationText = ({ validationErrors, status }) => {
3193
+ const { formatMessage } = useIntl();
3194
+ if (validationErrors) {
3195
+ const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
3196
+ " "
3197
+ );
3198
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3199
+ /* @__PURE__ */ jsx(CrossCircle, { fill: "danger600" }),
3200
+ /* @__PURE__ */ jsx(Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
3201
+ ] });
3202
+ }
3203
+ if (status === "published") {
3204
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3205
+ /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
3206
+ /* @__PURE__ */ jsx(Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
3207
+ id: "content-manager.bulk-publish.already-published",
3208
+ defaultMessage: "Already Published"
3209
+ }) })
3210
+ ] });
3211
+ }
3212
+ if (status === "modified") {
3213
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3214
+ /* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
3215
+ /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3216
+ id: "content-manager.bulk-publish.modified",
3217
+ defaultMessage: "Ready to publish changes"
3218
+ }) })
3219
+ ] });
3220
+ }
3221
+ return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3222
+ /* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
3223
+ /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3224
+ id: "app.utils.ready-to-publish",
3225
+ defaultMessage: "Ready to publish"
3226
+ }) })
3227
+ ] });
3228
+ };
3229
+ const TABLE_HEADERS = [
3230
+ { name: "id", label: "id" },
3231
+ { name: "name", label: "name" },
3232
+ { name: "status", label: "status" },
3233
+ { name: "publicationStatus", label: "Publication status" }
3234
+ ];
3235
+ const SelectedEntriesTableContent = ({
3236
+ isPublishing,
3237
+ rowsToDisplay = [],
3238
+ entriesToPublish = [],
3239
+ validationErrors = {}
3240
+ }) => {
3241
+ const { pathname } = useLocation();
3242
+ const { formatMessage } = useIntl();
3243
+ const {
3244
+ list: {
3245
+ settings: { mainField }
3246
+ }
3247
+ } = useDocLayout();
3248
+ const shouldDisplayMainField = mainField != null && mainField !== "id";
3249
+ return /* @__PURE__ */ jsxs(Table.Content, { children: [
3250
+ /* @__PURE__ */ jsxs(Table.Head, { children: [
3251
+ /* @__PURE__ */ jsx(Table.HeaderCheckboxCell, {}),
3252
+ TABLE_HEADERS.filter((head) => head.name !== "name" || shouldDisplayMainField).map(
3253
+ (head) => /* @__PURE__ */ jsx(Table.HeaderCell, { ...head }, head.name)
3254
+ )
3255
+ ] }),
3256
+ /* @__PURE__ */ jsx(Table.Loading, {}),
3257
+ /* @__PURE__ */ jsx(Table.Body, { children: rowsToDisplay.map((row, index2) => /* @__PURE__ */ jsxs(Table.Row, { children: [
3258
+ /* @__PURE__ */ jsx(Table.CheckboxCell, { id: row.id }),
3259
+ /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { children: row.id }) }),
3260
+ shouldDisplayMainField && /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Typography, { children: row[mainField] }) }),
3261
+ /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(DocumentStatus, { status: row.status, maxWidth: "min-content" }) }),
3262
+ /* @__PURE__ */ jsx(Table.Cell, { children: isPublishing && entriesToPublish.includes(row.documentId) ? /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3263
+ /* @__PURE__ */ jsx(Typography, { children: formatMessage({
3264
+ id: "content-manager.success.record.publishing",
3265
+ defaultMessage: "Publishing..."
3266
+ }) }),
3267
+ /* @__PURE__ */ jsx(Loader, { small: true })
3268
+ ] }) : /* @__PURE__ */ jsx(
3269
+ EntryValidationText,
3270
+ {
3271
+ validationErrors: validationErrors[row.documentId],
3272
+ status: row.status
3273
+ }
3274
+ ) }),
3275
+ /* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3276
+ IconButton,
3277
+ {
3278
+ tag: Link,
3279
+ to: {
3280
+ pathname: `${pathname}/${row.documentId}`,
3281
+ search: row.locale && `?plugins[i18n][locale]=${row.locale}`
3282
+ },
3283
+ state: { from: pathname },
3284
+ label: formatMessage({
3285
+ id: "content-manager.bulk-publish.edit",
3286
+ defaultMessage: "Edit"
3287
+ }),
3288
+ target: "_blank",
3289
+ marginLeft: "auto",
3290
+ variant: "ghost",
3291
+ children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
3292
+ }
3293
+ ) }) })
3294
+ ] }, row.id)) })
3295
+ ] });
3296
+ };
3297
+ const BoldChunk = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
3298
+ const SelectedEntriesModalContent = ({
3299
+ listViewSelectedEntries,
3300
+ toggleModal,
3301
+ setListViewSelectedDocuments,
3302
+ model
3303
+ }) => {
3304
+ const { formatMessage } = useIntl();
3305
+ const { schema, components } = useContentTypeSchema(model);
3306
+ const documentIds = listViewSelectedEntries.map(({ documentId }) => documentId);
3307
+ const [{ query }] = useQueryParams();
3308
+ const params = React.useMemo(() => buildValidParams(query), [query]);
3309
+ const { data, isLoading, isFetching, refetch } = useGetAllDocumentsQuery(
3310
+ {
3311
+ model,
3312
+ params: {
3313
+ page: "1",
3314
+ pageSize: documentIds.length.toString(),
3315
+ sort: query.sort,
3316
+ filters: {
3317
+ documentId: {
3318
+ $in: documentIds
3319
+ }
3320
+ },
3321
+ locale: query.plugins?.i18n?.locale
3322
+ }
3323
+ },
3324
+ {
3325
+ selectFromResult: ({ data: data2, ...restRes }) => ({ data: data2?.results ?? [], ...restRes })
3326
+ }
3327
+ );
3328
+ const { rows, validationErrors } = React.useMemo(() => {
3329
+ if (data.length > 0 && schema) {
3330
+ const validate = createYupSchema(
3331
+ schema.attributes,
3332
+ components,
3333
+ // Since this is the "Publish" action, the validation
3334
+ // schema must enforce the rules for published entities
3335
+ { status: "published" }
3336
+ );
3337
+ const validationErrors2 = {};
3338
+ const rows2 = data.map((entry) => {
3339
+ try {
3340
+ validate.validateSync(entry, { abortEarly: false });
3341
+ return entry;
3342
+ } catch (e) {
3343
+ if (e instanceof ValidationError) {
3344
+ validationErrors2[entry.documentId] = getYupValidationErrors(e);
3345
+ }
3346
+ return entry;
3347
+ }
3348
+ });
3349
+ return { rows: rows2, validationErrors: validationErrors2 };
3350
+ }
3351
+ return {
3352
+ rows: [],
3353
+ validationErrors: {}
3354
+ };
3355
+ }, [components, data, schema]);
3356
+ const [publishedCount, setPublishedCount] = React.useState(0);
3357
+ const [isDialogOpen, setIsDialogOpen] = React.useState(false);
3358
+ const { publishMany: bulkPublishAction } = useDocumentActions();
3359
+ const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation();
3360
+ const selectedRows = useTable("publishAction", (state) => state.selectedRows);
3361
+ const selectedEntries = rows.filter(
3362
+ (entry) => selectedRows.some((selectedEntry) => selectedEntry.documentId === entry.documentId)
3363
+ );
3364
+ const entriesToPublish = selectedEntries.filter((entry) => !validationErrors[entry.documentId]).map((entry) => entry.documentId);
3365
+ const selectedEntriesWithErrorsCount = selectedEntries.filter(
3366
+ ({ documentId }) => validationErrors[documentId]
3367
+ ).length;
3368
+ const selectedEntriesPublished = selectedEntries.filter(
3369
+ ({ status }) => status === "published"
3370
+ ).length;
3371
+ const selectedEntriesWithNoErrorsCount = selectedEntries.length - selectedEntriesWithErrorsCount - selectedEntriesPublished;
3372
+ const toggleDialog = () => setIsDialogOpen((prev) => !prev);
3373
+ const handleConfirmBulkPublish = async () => {
3374
+ toggleDialog();
3375
+ const res = await bulkPublishAction({ model, documentIds: entriesToPublish, params });
3376
+ if (!("error" in res)) {
3377
+ setPublishedCount(res.count);
3378
+ const unpublishedEntries = rows.filter((row) => {
3379
+ return !entriesToPublish.includes(row.documentId);
3380
+ });
3381
+ setListViewSelectedDocuments(unpublishedEntries);
3382
+ }
3383
+ };
3384
+ const getFormattedCountMessage = () => {
3385
+ if (publishedCount) {
3386
+ return formatMessage(
3387
+ {
3388
+ id: getTranslation("containers.list.selectedEntriesModal.publishedCount"),
3389
+ defaultMessage: "<b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} published. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action."
3390
+ },
3391
+ {
3392
+ publishedCount,
3393
+ withErrorsCount: selectedEntriesWithErrorsCount,
3394
+ b: BoldChunk
3395
+ }
3396
+ );
3397
+ }
3398
+ return formatMessage(
3399
+ {
3400
+ id: getTranslation("containers.list.selectedEntriesModal.selectedCount"),
3401
+ defaultMessage: "<b>{alreadyPublishedCount}</b> {alreadyPublishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{readyToPublishCount}</b> {readyToPublishCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action."
3402
+ },
3403
+ {
3404
+ readyToPublishCount: selectedEntriesWithNoErrorsCount,
3405
+ withErrorsCount: selectedEntriesWithErrorsCount,
3406
+ alreadyPublishedCount: selectedEntriesPublished,
3407
+ b: BoldChunk
3408
+ }
3409
+ );
3410
+ };
3411
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3412
+ /* @__PURE__ */ jsxs(Modal.Body, { children: [
3413
+ /* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
3414
+ /* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
3415
+ SelectedEntriesTableContent,
3416
+ {
3417
+ isPublishing: isSubmittingForm,
3418
+ rowsToDisplay: rows,
3419
+ entriesToPublish,
3420
+ validationErrors
3421
+ }
3422
+ ) })
3423
+ ] }),
3424
+ /* @__PURE__ */ jsxs(Modal.Footer, { children: [
3425
+ /* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
3426
+ id: "app.components.Button.cancel",
3427
+ defaultMessage: "Cancel"
3428
+ }) }),
3429
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
3430
+ /* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
3431
+ /* @__PURE__ */ jsx(
3432
+ Button,
3433
+ {
3434
+ onClick: toggleDialog,
3435
+ disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
3436
+ loading: isSubmittingForm,
3437
+ children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
3438
+ }
3439
+ )
3440
+ ] })
3441
+ ] }),
3442
+ /* @__PURE__ */ jsx(
3443
+ ConfirmDialogPublishAll,
3444
+ {
3445
+ isOpen: isDialogOpen,
3446
+ onToggleDialog: toggleDialog,
3447
+ isConfirmButtonLoading: isSubmittingForm,
3448
+ onConfirm: handleConfirmBulkPublish
3449
+ }
3450
+ )
3451
+ ] });
3452
+ };
3453
+ const PublishAction = ({ documents, model }) => {
3454
+ const { formatMessage } = useIntl();
3455
+ const hasPublishPermission = useDocumentRBAC("unpublishAction", (state) => state.canPublish);
3456
+ const showPublishButton = hasPublishPermission && documents.some(({ status }) => status !== "published");
3457
+ const setListViewSelectedDocuments = useTable("publishAction", (state) => state.selectRow);
3458
+ const refetchList = () => {
3459
+ contentManagerApi.util.invalidateTags([{ type: "Document", id: `${model}_LIST` }]);
3460
+ };
3461
+ if (!showPublishButton)
3462
+ return null;
3463
+ return {
3464
+ actionType: "publish",
3465
+ variant: "tertiary",
3466
+ label: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" }),
3467
+ dialog: {
3468
+ type: "modal",
3469
+ title: formatMessage({
3470
+ id: getTranslation("containers.ListPage.selectedEntriesModal.title"),
3471
+ defaultMessage: "Publish entries"
3472
+ }),
3473
+ content: ({ onClose }) => {
3474
+ return /* @__PURE__ */ jsx(Table.Root, { rows: documents, defaultSelectedRows: documents, headers: TABLE_HEADERS, children: /* @__PURE__ */ jsx(
3475
+ SelectedEntriesModalContent,
3476
+ {
3477
+ listViewSelectedEntries: documents,
3478
+ toggleModal: () => {
3479
+ onClose();
3480
+ refetchList();
3481
+ },
3482
+ setListViewSelectedDocuments,
3483
+ model
3484
+ }
3485
+ ) });
3486
+ },
3487
+ onClose: () => {
3488
+ refetchList();
3489
+ }
3490
+ }
3491
+ };
3492
+ };
3493
+ const BulkActionsRenderer = () => {
3494
+ const plugins = useStrapiApp("BulkActionsRenderer", (state) => state.plugins);
3495
+ const { model, collectionType } = useDoc();
3496
+ const { selectedRows } = useTable("BulkActionsRenderer", (state) => state);
3497
+ return /* @__PURE__ */ jsx(Flex, { gap: 2, children: /* @__PURE__ */ jsx(
3498
+ DescriptionComponentRenderer,
3499
+ {
3500
+ props: {
3501
+ model,
3502
+ collectionType,
3503
+ documents: selectedRows
3504
+ },
3505
+ descriptions: plugins["content-manager"].apis.getBulkActions(),
3506
+ children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
3507
+ }
3508
+ ) });
3509
+ };
3510
+ const DeleteAction = ({ documents, model }) => {
3511
+ const { formatMessage } = useIntl();
3512
+ const { schema: contentType } = useDoc();
3513
+ const selectRow = useTable("DeleteAction", (state) => state.selectRow);
3514
+ const hasI18nEnabled = Boolean(contentType?.pluginOptions?.i18n);
3515
+ const [{ query }] = useQueryParams();
3516
+ const params = React.useMemo(() => buildValidParams(query), [query]);
3517
+ const hasDeletePermission = useDocumentRBAC("deleteAction", (state) => state.canDelete);
3518
+ const { deleteMany: bulkDeleteAction } = useDocumentActions();
3519
+ const documentIds = documents.map(({ documentId }) => documentId);
3520
+ const handleConfirmBulkDelete = async () => {
3521
+ const res = await bulkDeleteAction({
3522
+ documentIds,
3523
+ model,
3524
+ params
3525
+ });
3526
+ if (!("error" in res)) {
3527
+ selectRow([]);
3528
+ }
3529
+ };
3530
+ if (!hasDeletePermission)
3531
+ return null;
3532
+ return {
3533
+ variant: "danger-light",
3534
+ label: formatMessage({ id: "global.delete", defaultMessage: "Delete" }),
3535
+ dialog: {
3536
+ type: "dialog",
3537
+ title: formatMessage({
3538
+ id: "app.components.ConfirmDialog.title",
3539
+ defaultMessage: "Confirmation"
3540
+ }),
3541
+ content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3542
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3543
+ /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3544
+ id: "popUpWarning.bodyMessage.contentType.delete.all",
3545
+ defaultMessage: "Are you sure you want to delete these entries?"
3546
+ }) }),
3547
+ hasI18nEnabled && /* @__PURE__ */ jsx(Box, { textAlign: "center", padding: 3, children: /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
3548
+ {
3549
+ id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
3550
+ defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
3551
+ },
3552
+ {
3553
+ em: Emphasis
3554
+ }
3555
+ ) }) })
3556
+ ] }),
3557
+ onConfirm: handleConfirmBulkDelete
3558
+ }
3559
+ };
3560
+ };
3561
+ DeleteAction.type = "delete";
3562
+ const UnpublishAction = ({ documents, model }) => {
3563
+ const { formatMessage } = useIntl();
3564
+ const { schema } = useDoc();
3565
+ const selectRow = useTable("UnpublishAction", (state) => state.selectRow);
3566
+ const hasPublishPermission = useDocumentRBAC("unpublishAction", (state) => state.canPublish);
3567
+ const hasI18nEnabled = Boolean(schema?.pluginOptions?.i18n);
3568
+ const hasDraftAndPublishEnabled = Boolean(schema?.options?.draftAndPublish);
3569
+ const { unpublishMany: bulkUnpublishAction } = useDocumentActions();
3570
+ const documentIds = documents.map(({ documentId }) => documentId);
3571
+ const [{ query }] = useQueryParams();
3572
+ const params = React.useMemo(() => buildValidParams(query), [query]);
3573
+ const handleConfirmBulkUnpublish = async () => {
3574
+ const data = await bulkUnpublishAction({ documentIds, model, params });
3575
+ if (!("error" in data)) {
3576
+ selectRow([]);
3577
+ }
3578
+ };
3579
+ const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
3580
+ if (!showUnpublishButton)
3581
+ return null;
3582
+ return {
3583
+ variant: "tertiary",
3584
+ label: formatMessage({ id: "app.utils.unpublish", defaultMessage: "Unpublish" }),
3585
+ dialog: {
3586
+ type: "dialog",
3587
+ title: formatMessage({
3588
+ id: "app.components.ConfirmDialog.title",
3589
+ defaultMessage: "Confirmation"
3590
+ }),
3591
+ content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
3592
+ /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
3593
+ /* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
3594
+ id: "popUpWarning.bodyMessage.contentType.unpublish.all",
3595
+ defaultMessage: "Are you sure you want to unpublish these entries?"
3596
+ }) }),
3597
+ hasI18nEnabled && /* @__PURE__ */ jsx(Box, { textAlign: "center", padding: 3, children: /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
3598
+ {
3599
+ id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
3600
+ defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
3601
+ },
3602
+ {
3603
+ em: Emphasis
3604
+ }
3605
+ ) }) })
3606
+ ] }),
3607
+ confirmButton: formatMessage({
3608
+ id: "app.utils.unpublish",
3609
+ defaultMessage: "Unpublish"
3610
+ }),
3611
+ onConfirm: handleConfirmBulkUnpublish
3612
+ }
3613
+ };
3614
+ };
3615
+ UnpublishAction.type = "unpublish";
3616
+ const Emphasis = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
3617
+ const DEFAULT_BULK_ACTIONS = [PublishAction, UnpublishAction, DeleteAction];
2445
3618
  const AutoCloneFailureModalBody = ({ prohibitedFields }) => {
2446
3619
  const { formatMessage } = useIntl();
2447
3620
  const getDefaultErrorMessage = (reason) => {
@@ -2473,7 +3646,7 @@ const AutoCloneFailureModalBody = ({ prohibitedFields }) => {
2473
3646
  hasRadius: true,
2474
3647
  padding: 6,
2475
3648
  children: [
2476
- /* @__PURE__ */ jsx(Flex, { direction: "row", as: "ol", children: fieldPath.map((pathSegment, index2) => /* @__PURE__ */ jsxs(Typography, { fontWeight: "semiBold", as: "li", children: [
3649
+ /* @__PURE__ */ jsx(Flex, { direction: "row", tag: "ol", children: fieldPath.map((pathSegment, index2) => /* @__PURE__ */ jsxs(Typography, { fontWeight: "semiBold", tag: "li", children: [
2477
3650
  pathSegment,
2478
3651
  index2 !== fieldPath.length - 1 && /* @__PURE__ */ jsx(
2479
3652
  ChevronRight,
@@ -2485,7 +3658,7 @@ const AutoCloneFailureModalBody = ({ prohibitedFields }) => {
2485
3658
  }
2486
3659
  )
2487
3660
  ] }, index2)) }),
2488
- /* @__PURE__ */ jsx(Typography, { as: "p", textColor: "neutral600", children: formatMessage({
3661
+ /* @__PURE__ */ jsx(Typography, { tag: "p", textColor: "neutral600", children: formatMessage({
2489
3662
  id: getTranslation(`containers.list.autoCloneModal.error.${reason}`),
2490
3663
  defaultMessage: getDefaultErrorMessage(reason)
2491
3664
  }) })
@@ -2510,7 +3683,7 @@ const TableActions = ({ document }) => {
2510
3683
  DescriptionComponentRenderer,
2511
3684
  {
2512
3685
  props,
2513
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
3686
+ descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
2514
3687
  children: (actions2) => {
2515
3688
  const tableRowActions = actions2.filter((action) => {
2516
3689
  const positions = Array.isArray(action.position) ? action.position : [action.position];
@@ -2621,7 +3794,7 @@ const CloneAction = ({ model, documentId }) => {
2621
3794
  }),
2622
3795
  content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
2623
3796
  footer: ({ onClose }) => {
2624
- return /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", children: [
3797
+ return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
2625
3798
  /* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
2626
3799
  id: "cancel",
2627
3800
  defaultMessage: "Cancel"
@@ -2629,7 +3802,7 @@ const CloneAction = ({ model, documentId }) => {
2629
3802
  /* @__PURE__ */ jsx(
2630
3803
  LinkButton,
2631
3804
  {
2632
- as: NavLink,
3805
+ tag: NavLink,
2633
3806
  to: {
2634
3807
  pathname: `clone/${documentId}`
2635
3808
  },
@@ -2662,8 +3835,7 @@ class ContentManagerPlugin {
2662
3835
  documentActions = [
2663
3836
  ...DEFAULT_ACTIONS,
2664
3837
  ...DEFAULT_TABLE_ROW_ACTIONS,
2665
- ...DEFAULT_HEADER_ACTIONS,
2666
- HistoryAction
3838
+ ...DEFAULT_HEADER_ACTIONS
2667
3839
  ];
2668
3840
  editViewSidePanels = [ActionsPanel];
2669
3841
  headerActions = [];
@@ -2752,9 +3924,65 @@ const getPrintableType = (value) => {
2752
3924
  }
2753
3925
  return nativeType;
2754
3926
  };
2755
- const initialState = {
2756
- collectionTypeLinks: [],
2757
- components: [],
3927
+ const HistoryAction = ({ model, document }) => {
3928
+ const { formatMessage } = useIntl();
3929
+ const [{ query }] = useQueryParams();
3930
+ const navigate = useNavigate();
3931
+ const { trackUsage } = useTracking();
3932
+ const { pathname } = useLocation();
3933
+ const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
3934
+ if (!window.strapi.features.isEnabled("cms-content-history")) {
3935
+ return null;
3936
+ }
3937
+ const handleOnClick = () => {
3938
+ const destination = { pathname: "history", search: pluginsQueryParams };
3939
+ trackUsage("willNavigate", {
3940
+ from: pathname,
3941
+ to: `${pathname}/${destination.pathname}`
3942
+ });
3943
+ navigate(destination);
3944
+ };
3945
+ return {
3946
+ icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
3947
+ label: formatMessage({
3948
+ id: "content-manager.history.document-action",
3949
+ defaultMessage: "Content History"
3950
+ }),
3951
+ onClick: handleOnClick,
3952
+ disabled: (
3953
+ /**
3954
+ * The user is creating a new document.
3955
+ * It hasn't been saved yet, so there's no history to go to
3956
+ */
3957
+ !document || /**
3958
+ * The document has been created but the current dimension has never been saved.
3959
+ * For example, the user is creating a new locale in an existing document,
3960
+ * so there's no history for the document in that locale
3961
+ */
3962
+ !document.id || /**
3963
+ * History is only available for content types created by the user.
3964
+ * These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
3965
+ * which start with `admin::` or `plugin::`
3966
+ */
3967
+ !model.startsWith("api::")
3968
+ ),
3969
+ position: "header"
3970
+ };
3971
+ };
3972
+ HistoryAction.type = "history";
3973
+ const historyAdmin = {
3974
+ bootstrap(app) {
3975
+ const { addDocumentAction } = app.getPlugin("content-manager").apis;
3976
+ addDocumentAction((actions2) => {
3977
+ const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
3978
+ actions2.splice(indexOfDeleteAction, 0, HistoryAction);
3979
+ return actions2;
3980
+ });
3981
+ }
3982
+ };
3983
+ const initialState = {
3984
+ collectionTypeLinks: [],
3985
+ components: [],
2758
3986
  fieldSizes: {},
2759
3987
  models: [],
2760
3988
  singleTypeLinks: [],
@@ -2788,316 +4016,78 @@ const { setInitialData } = actions;
2788
4016
  const reducer = combineReducers({
2789
4017
  app: reducer$1
2790
4018
  });
2791
- const HOOKS = {
2792
- /**
2793
- * Hook that allows to mutate the displayed headers of the list view table
2794
- * @constant
2795
- * @type {string}
2796
- */
2797
- INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
2798
- /**
2799
- * Hook that allows to mutate the CM's collection types links pre-set filters
2800
- * @constant
2801
- * @type {string}
2802
- */
2803
- MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
2804
- /**
2805
- * Hook that allows to mutate the CM's edit view layout
2806
- * @constant
2807
- * @type {string}
2808
- */
2809
- MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
2810
- /**
2811
- * Hook that allows to mutate the CM's single types links pre-set filters
2812
- * @constant
2813
- * @type {string}
2814
- */
2815
- MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
2816
- };
2817
- const contentTypesApi = contentManagerApi.injectEndpoints({
4019
+ const previewApi = contentManagerApi.injectEndpoints({
2818
4020
  endpoints: (builder) => ({
2819
- getContentTypeConfiguration: builder.query({
2820
- query: (uid) => ({
2821
- url: `/content-manager/content-types/${uid}/configuration`,
2822
- method: "GET"
2823
- }),
2824
- transformResponse: (response) => response.data,
2825
- providesTags: (_result, _error, uid) => [
2826
- { type: "ContentTypesConfiguration", id: uid },
2827
- { type: "ContentTypeSettings", id: "LIST" }
2828
- ]
2829
- }),
2830
- getAllContentTypeSettings: builder.query({
2831
- query: () => "/content-manager/content-types-settings",
2832
- transformResponse: (response) => response.data,
2833
- providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
2834
- }),
2835
- updateContentTypeConfiguration: builder.mutation({
2836
- query: ({ uid, ...body }) => ({
2837
- url: `/content-manager/content-types/${uid}/configuration`,
2838
- method: "PUT",
2839
- data: body
2840
- }),
2841
- transformResponse: (response) => response.data,
2842
- invalidatesTags: (_result, _error, { uid }) => [
2843
- { type: "ContentTypesConfiguration", id: uid },
2844
- { type: "ContentTypeSettings", id: "LIST" },
2845
- // Is this necessary?
2846
- { type: "InitialData" }
2847
- ]
4021
+ getPreviewUrl: builder.query({
4022
+ query({ query, params }) {
4023
+ return {
4024
+ url: `/content-manager/preview/url/${params.contentType}`,
4025
+ method: "GET",
4026
+ config: {
4027
+ params: query
4028
+ }
4029
+ };
4030
+ }
2848
4031
  })
2849
4032
  })
2850
4033
  });
2851
- const {
2852
- useGetContentTypeConfigurationQuery,
2853
- useGetAllContentTypeSettingsQuery,
2854
- useUpdateContentTypeConfigurationMutation
2855
- } = contentTypesApi;
2856
- const checkIfAttributeIsDisplayable = (attribute) => {
2857
- const { type } = attribute;
2858
- if (type === "relation") {
2859
- return !attribute.relation.toLowerCase().includes("morph");
2860
- }
2861
- return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
2862
- };
2863
- const getMainField = (attribute, mainFieldName, { schemas, components }) => {
2864
- if (!mainFieldName) {
2865
- return void 0;
2866
- }
2867
- const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
2868
- // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
2869
- schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
2870
- );
2871
- return {
2872
- name: mainFieldName,
2873
- type: mainFieldType ?? "string"
2874
- };
2875
- };
2876
- const DEFAULT_SETTINGS = {
2877
- bulkable: false,
2878
- filterable: false,
2879
- searchable: false,
2880
- pagination: false,
2881
- defaultSortBy: "",
2882
- defaultSortOrder: "asc",
2883
- mainField: "id",
2884
- pageSize: 10
2885
- };
2886
- const useDocumentLayout = (model) => {
2887
- const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
4034
+ const { useGetPreviewUrlQuery } = previewApi;
4035
+ const PreviewSidePanel = ({ model, documentId, document }) => {
4036
+ const { formatMessage } = useIntl();
4037
+ const { trackUsage } = useTracking();
4038
+ const { pathname } = useLocation();
2888
4039
  const [{ query }] = useQueryParams();
2889
- const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
2890
- const { toggleNotification } = useNotification();
2891
- const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
2892
- const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
2893
- const {
2894
- data,
2895
- isLoading: isLoadingConfigs,
2896
- error,
2897
- isFetching: isFetchingConfigs
2898
- } = useGetContentTypeConfigurationQuery(model);
2899
- const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
2900
- React.useEffect(() => {
2901
- if (error) {
2902
- toggleNotification({
2903
- type: "danger",
2904
- message: formatAPIError(error)
2905
- });
2906
- }
2907
- }, [error, formatAPIError, toggleNotification]);
2908
- const editLayout = React.useMemo(
2909
- () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
2910
- layout: [],
2911
- components: {},
2912
- metadatas: {},
2913
- options: {},
2914
- settings: DEFAULT_SETTINGS
4040
+ const { data, error } = useGetPreviewUrlQuery({
4041
+ params: {
4042
+ contentType: model
2915
4043
  },
2916
- [data, isLoading, schemas, schema, components]
2917
- );
2918
- const listLayout = React.useMemo(() => {
2919
- return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
2920
- layout: [],
2921
- metadatas: {},
2922
- options: {},
2923
- settings: DEFAULT_SETTINGS
2924
- };
2925
- }, [data, isLoading, schemas, schema, components]);
2926
- const { layout: edit } = React.useMemo(
2927
- () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
2928
- layout: editLayout,
2929
- query
2930
- }),
2931
- [editLayout, query, runHookWaterfall]
2932
- );
2933
- return {
2934
- error,
2935
- isLoading,
2936
- edit,
2937
- list: listLayout
2938
- };
2939
- };
2940
- const useDocLayout = () => {
2941
- const { model } = useDoc();
2942
- return useDocumentLayout(model);
2943
- };
2944
- const formatEditLayout = (data, {
2945
- schemas,
2946
- schema,
2947
- components
2948
- }) => {
2949
- let currentPanelIndex = 0;
2950
- const panelledEditAttributes = convertEditLayoutToFieldLayouts(
2951
- data.contentType.layouts.edit,
2952
- schema?.attributes,
2953
- data.contentType.metadatas,
2954
- { configurations: data.components, schemas: components },
2955
- schemas
2956
- ).reduce((panels, row) => {
2957
- if (row.some((field) => field.type === "dynamiczone")) {
2958
- panels.push([row]);
2959
- currentPanelIndex += 2;
2960
- } else {
2961
- if (!panels[currentPanelIndex]) {
2962
- panels.push([]);
2963
- }
2964
- panels[currentPanelIndex].push(row);
2965
- }
2966
- return panels;
2967
- }, []);
2968
- const componentEditAttributes = Object.entries(data.components).reduce(
2969
- (acc, [uid, configuration]) => {
2970
- acc[uid] = {
2971
- layout: convertEditLayoutToFieldLayouts(
2972
- configuration.layouts.edit,
2973
- components[uid].attributes,
2974
- configuration.metadatas
2975
- ),
2976
- settings: {
2977
- ...configuration.settings,
2978
- icon: components[uid].info.icon,
2979
- displayName: components[uid].info.displayName
2980
- }
2981
- };
2982
- return acc;
2983
- },
2984
- {}
2985
- );
2986
- const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
2987
- (acc, [attribute, metadata]) => {
2988
- return {
2989
- ...acc,
2990
- [attribute]: metadata.edit
2991
- };
2992
- },
2993
- {}
2994
- );
2995
- return {
2996
- layout: panelledEditAttributes,
2997
- components: componentEditAttributes,
2998
- metadatas: editMetadatas,
2999
- settings: {
3000
- ...data.contentType.settings,
3001
- displayName: schema?.info.displayName
3002
- },
3003
- options: {
3004
- ...schema?.options,
3005
- ...schema?.pluginOptions,
3006
- ...data.contentType.options
4044
+ query: {
4045
+ documentId,
4046
+ locale: document?.locale,
4047
+ status: document?.status
3007
4048
  }
4049
+ });
4050
+ if (!data?.data?.url || error) {
4051
+ return null;
4052
+ }
4053
+ const trackNavigation = () => {
4054
+ const destinationPathname = pathname.replace(/\/$/, "") + "/preview";
4055
+ trackUsage("willNavigate", { from: pathname, to: destinationPathname });
3008
4056
  };
3009
- };
3010
- const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
3011
- return rows.map(
3012
- (row) => row.map((field) => {
3013
- const attribute = attributes[field.name];
3014
- if (!attribute) {
3015
- return null;
3016
- }
3017
- const { edit: metadata } = metadatas[field.name];
3018
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
3019
- return {
3020
- attribute,
3021
- disabled: !metadata.editable,
3022
- hint: metadata.description,
3023
- label: metadata.label ?? "",
3024
- name: field.name,
3025
- // @ts-expect-error – mainField does exist on the metadata for a relation.
3026
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
3027
- schemas,
3028
- components: components?.schemas ?? {}
3029
- }),
3030
- placeholder: metadata.placeholder ?? "",
3031
- required: attribute.required ?? false,
3032
- size: field.size,
3033
- unique: "unique" in attribute ? attribute.unique : false,
3034
- visible: metadata.visible ?? true,
3035
- type: attribute.type
3036
- };
3037
- }).filter((field) => field !== null)
3038
- );
3039
- };
3040
- const formatListLayout = (data, {
3041
- schemas,
3042
- schema,
3043
- components
3044
- }) => {
3045
- const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
3046
- (acc, [attribute, metadata]) => {
3047
- return {
3048
- ...acc,
3049
- [attribute]: metadata.list
3050
- };
3051
- },
3052
- {}
3053
- );
3054
- const listAttributes = convertListLayoutToFieldLayouts(
3055
- data.contentType.layouts.list,
3056
- schema?.attributes,
3057
- listMetadatas,
3058
- { configurations: data.components, schemas: components },
3059
- schemas
3060
- );
3061
4057
  return {
3062
- layout: listAttributes,
3063
- settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
3064
- metadatas: listMetadatas,
3065
- options: {
3066
- ...schema?.options,
3067
- ...schema?.pluginOptions,
3068
- ...data.contentType.options
3069
- }
4058
+ title: formatMessage({ id: "content-manager.preview.panel.title", defaultMessage: "Preview" }),
4059
+ content: /* @__PURE__ */ jsx(Flex, { gap: 2, width: "100%", children: /* @__PURE__ */ jsx(
4060
+ Button,
4061
+ {
4062
+ variant: "tertiary",
4063
+ tag: Link,
4064
+ to: { pathname: "preview", search: stringify(query, { encode: false }) },
4065
+ onClick: trackNavigation,
4066
+ flex: "auto",
4067
+ children: formatMessage({
4068
+ id: "content-manager.preview.panel.button",
4069
+ defaultMessage: "Open preview"
4070
+ })
4071
+ }
4072
+ ) })
3070
4073
  };
3071
4074
  };
3072
- const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
3073
- return columns.map((name) => {
3074
- const attribute = attributes[name];
3075
- if (!attribute) {
3076
- return null;
4075
+ const FEATURE_ID = "preview";
4076
+ const previewAdmin = {
4077
+ bootstrap(app) {
4078
+ if (!window.strapi.future.isEnabled(FEATURE_ID)) {
4079
+ return;
3077
4080
  }
3078
- const metadata = metadatas[name];
3079
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
3080
- return {
3081
- attribute,
3082
- label: metadata.label ?? "",
3083
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
3084
- schemas,
3085
- components: components?.schemas ?? {}
3086
- }),
3087
- name,
3088
- searchable: metadata.searchable ?? true,
3089
- sortable: metadata.sortable ?? true
3090
- };
3091
- }).filter((field) => field !== null);
4081
+ const contentManagerPluginApis = app.getPlugin("content-manager").apis;
4082
+ contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
4083
+ }
3092
4084
  };
3093
4085
  const index = {
3094
4086
  register(app) {
3095
4087
  const cm = new ContentManagerPlugin();
3096
4088
  app.addReducers({
3097
- [contentManagerApi.reducerPath]: contentManagerApi.reducer,
3098
4089
  [PLUGIN_ID]: reducer
3099
4090
  });
3100
- app.addMiddlewares([() => contentManagerApi.middleware]);
3101
4091
  app.addMenuLink({
3102
4092
  to: PLUGIN_ID,
3103
4093
  icon: Feather,
@@ -3106,14 +4096,32 @@ const index = {
3106
4096
  defaultMessage: "Content Manager"
3107
4097
  },
3108
4098
  permissions: [],
3109
- Component: () => import("./layout-jIDzX0Fp.mjs").then((mod) => ({ default: mod.Layout }))
4099
+ position: 1
4100
+ });
4101
+ app.router.addRoute({
4102
+ path: "content-manager/*",
4103
+ lazy: async () => {
4104
+ const { Layout } = await import("./layout-DhMZ_lDx.mjs");
4105
+ return {
4106
+ Component: Layout
4107
+ };
4108
+ },
4109
+ children: routes
3110
4110
  });
3111
4111
  app.registerPlugin(cm.config);
3112
4112
  },
4113
+ bootstrap(app) {
4114
+ if (typeof historyAdmin.bootstrap === "function") {
4115
+ historyAdmin.bootstrap(app);
4116
+ }
4117
+ if (typeof previewAdmin.bootstrap === "function") {
4118
+ previewAdmin.bootstrap(app);
4119
+ }
4120
+ },
3113
4121
  async registerTrads({ locales }) {
3114
4122
  const importedTrads = await Promise.all(
3115
4123
  locales.map((locale) => {
3116
- 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-MBPul9Su.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 }) => {
4124
+ 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-DhFUjrNW.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 }) => {
3117
4125
  return {
3118
4126
  data: prefixPluginTranslations(data, PLUGIN_ID),
3119
4127
  locale
@@ -3131,45 +4139,48 @@ const index = {
3131
4139
  };
3132
4140
  export {
3133
4141
  ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD as A,
3134
- extractContentTypeComponents as B,
4142
+ BulkActionsRenderer as B,
3135
4143
  COLLECTION_TYPES as C,
3136
4144
  DocumentStatus as D,
3137
- DEFAULT_SETTINGS as E,
3138
- convertEditLayoutToFieldLayouts as F,
3139
- useDocument as G,
4145
+ extractContentTypeComponents as E,
4146
+ DEFAULT_SETTINGS as F,
4147
+ convertEditLayoutToFieldLayouts as G,
3140
4148
  HOOKS as H,
3141
4149
  InjectionZone as I,
3142
- index as J,
3143
- useDocumentActions as K,
4150
+ useDocument as J,
4151
+ useGetPreviewUrlQuery as K,
4152
+ index as L,
4153
+ useContentManagerContext as M,
4154
+ useDocumentActions as N,
3144
4155
  Panels as P,
3145
4156
  RelativeTime as R,
3146
4157
  SINGLE_TYPES as S,
3147
4158
  TableActions as T,
3148
- useGetAllContentTypeSettingsQuery as a,
3149
- useDoc as b,
3150
- buildValidParams as c,
3151
- contentManagerApi as d,
3152
- useDocumentRBAC as e,
3153
- useDocumentLayout as f,
4159
+ useGetInitialDataQuery as a,
4160
+ useGetAllContentTypeSettingsQuery as b,
4161
+ useDoc as c,
4162
+ buildValidParams as d,
4163
+ contentManagerApi as e,
4164
+ useDocumentRBAC as f,
3154
4165
  getTranslation as g,
3155
- createYupSchema as h,
3156
- Header as i,
3157
- PERMISSIONS as j,
3158
- DocumentRBAC as k,
3159
- DOCUMENT_META_FIELDS as l,
3160
- useDocLayout as m,
3161
- useContentTypeSchema as n,
3162
- useGetContentTypeConfigurationQuery as o,
3163
- CREATOR_FIELDS as p,
3164
- getMainField as q,
3165
- routes as r,
4166
+ useDocumentLayout as h,
4167
+ createYupSchema as i,
4168
+ Header as j,
4169
+ PERMISSIONS as k,
4170
+ DocumentRBAC as l,
4171
+ DOCUMENT_META_FIELDS as m,
4172
+ CLONE_PATH as n,
4173
+ useDocLayout as o,
4174
+ useGetContentTypeConfigurationQuery as p,
4175
+ CREATOR_FIELDS as q,
4176
+ getMainField as r,
3166
4177
  setInitialData as s,
3167
4178
  getDisplayName as t,
3168
- useGetInitialDataQuery as u,
4179
+ useContentTypeSchema as u,
3169
4180
  checkIfAttributeIsDisplayable as v,
3170
4181
  useGetAllDocumentsQuery as w,
3171
4182
  convertListLayoutToFieldLayouts as x,
3172
4183
  capitalise as y,
3173
4184
  useUpdateContentTypeConfigurationMutation as z
3174
4185
  };
3175
- //# sourceMappingURL=index-CwRRo1V9.mjs.map
4186
+ //# sourceMappingURL=index-BpxR3En4.mjs.map