@strapi/content-manager 0.0.0-experimental.81dfdf02b1367004c7deed9e01afa9d3a15d0fa5 → 0.0.0-experimental.86fea32ae4240d73f76516d7238e302b6b927e88

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 (103) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-qemkOlnj.mjs → ComponentConfigurationPage-B2g3icXu.mjs} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-qemkOlnj.mjs.map → ComponentConfigurationPage-B2g3icXu.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-D_M8iBw5.js → ComponentConfigurationPage-CzDn8Uxh.js} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-D_M8iBw5.js.map → ComponentConfigurationPage-CzDn8Uxh.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-BePwPuHy.js → EditConfigurationPage-Bcbi6r5y.js} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-BePwPuHy.js.map → EditConfigurationPage-Bcbi6r5y.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-CjUrEewK.mjs → EditConfigurationPage-DSA1zONV.mjs} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-CjUrEewK.mjs.map → EditConfigurationPage-DSA1zONV.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-B-RJeiJD.js → EditViewPage-BvcMXaP2.js} +15 -5
  10. package/dist/_chunks/EditViewPage-BvcMXaP2.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-De8GyU8P.mjs → EditViewPage-Ca2EmJpb.mjs} +15 -5
  12. package/dist/_chunks/EditViewPage-Ca2EmJpb.mjs.map +1 -0
  13. package/dist/_chunks/{Field-pb2o8uBe.mjs → Field-BEYkgCZ0.mjs} +86 -80
  14. package/dist/_chunks/Field-BEYkgCZ0.mjs.map +1 -0
  15. package/dist/_chunks/{Field-dq8Tg1M_.js → Field-CmaWxdpf.js} +90 -84
  16. package/dist/_chunks/Field-CmaWxdpf.js.map +1 -0
  17. package/dist/_chunks/{Form-DJn0Dxha.mjs → Form-BJVbU6w4.mjs} +16 -8
  18. package/dist/_chunks/Form-BJVbU6w4.mjs.map +1 -0
  19. package/dist/_chunks/{Form-DGIf4jQU.js → Form-DAUpPBVM.js} +16 -8
  20. package/dist/_chunks/Form-DAUpPBVM.js.map +1 -0
  21. package/dist/_chunks/{History-Dh2NEHnR.js → History-Bw9vfT1k.js} +23 -10
  22. package/dist/_chunks/History-Bw9vfT1k.js.map +1 -0
  23. package/dist/_chunks/{History-BowL3JKP.mjs → History-M6Pk9CoY.mjs} +24 -11
  24. package/dist/_chunks/History-M6Pk9CoY.mjs.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-BpVOB-hn.mjs → ListConfigurationPage-D7ior2zq.mjs} +2 -2
  26. package/dist/_chunks/{ListConfigurationPage-BpVOB-hn.mjs.map → ListConfigurationPage-D7ior2zq.mjs.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-BxYCWz9e.js → ListConfigurationPage-DBVqF5fc.js} +2 -2
  28. package/dist/_chunks/{ListConfigurationPage-BxYCWz9e.js.map → ListConfigurationPage-DBVqF5fc.js.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-CXFUjZQC.mjs → ListViewPage-BH37wONY.mjs} +40 -36
  30. package/dist/_chunks/ListViewPage-BH37wONY.mjs.map +1 -0
  31. package/dist/_chunks/{ListViewPage-4XsciqHZ.js → ListViewPage-MZu-8OKX.js} +43 -39
  32. package/dist/_chunks/ListViewPage-MZu-8OKX.js.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-C8OpoHeU.js → NoContentTypePage-C9lRMTCa.js} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-C8OpoHeU.js.map → NoContentTypePage-C9lRMTCa.js.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-DuhOTp3x.mjs → NoContentTypePage-DRp7Aem_.mjs} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-DuhOTp3x.mjs.map → NoContentTypePage-DRp7Aem_.mjs.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-y_r7DVA2.js → NoPermissionsPage-COs61PpB.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-y_r7DVA2.js.map → NoPermissionsPage-COs61PpB.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-DVz3mzDz.mjs → NoPermissionsPage-CzhRt5CA.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-DVz3mzDz.mjs.map → NoPermissionsPage-CzhRt5CA.mjs.map} +1 -1
  41. package/dist/_chunks/{Relations-CVNLrn1Y.mjs → Relations-68XxIzPI.mjs} +49 -28
  42. package/dist/_chunks/Relations-68XxIzPI.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-DPFCAa7b.js → Relations-CsGlulU_.js} +49 -28
  44. package/dist/_chunks/Relations-CsGlulU_.js.map +1 -0
  45. package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
  46. package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
  47. package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
  48. package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  49. package/dist/_chunks/{index-DiMrfcfy.mjs → index-CsfwpRfc.mjs} +1896 -1773
  50. package/dist/_chunks/index-CsfwpRfc.mjs.map +1 -0
  51. package/dist/_chunks/{index-C3fJE-1-.js → index-oDq3VO9j.js} +1893 -1769
  52. package/dist/_chunks/index-oDq3VO9j.js.map +1 -0
  53. package/dist/_chunks/{layout-ls3gxfpH.mjs → layout-C5uSVTqi.mjs} +5 -4
  54. package/dist/_chunks/{layout-ls3gxfpH.mjs.map → layout-C5uSVTqi.mjs.map} +1 -1
  55. package/dist/_chunks/{layout-C788OmNr.js → layout-Euka-kfv.js} +5 -4
  56. package/dist/_chunks/{layout-C788OmNr.js.map → layout-Euka-kfv.js.map} +1 -1
  57. package/dist/_chunks/{relations-CLcOmGO0.mjs → relations-BpHVgFuV.mjs} +2 -2
  58. package/dist/_chunks/{relations-CLcOmGO0.mjs.map → relations-BpHVgFuV.mjs.map} +1 -1
  59. package/dist/_chunks/{relations-DYeotliT.js → relations-DG7kmxa0.js} +2 -2
  60. package/dist/_chunks/{relations-DYeotliT.js.map → relations-DG7kmxa0.js.map} +1 -1
  61. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  62. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  63. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  65. package/dist/admin/index.js +2 -1
  66. package/dist/admin/index.js.map +1 -1
  67. package/dist/admin/index.mjs +3 -2
  68. package/dist/admin/src/exports.d.ts +1 -1
  69. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  70. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +0 -32
  71. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  72. package/dist/admin/src/services/documents.d.ts +3 -1
  73. package/dist/server/index.js +54 -22
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/server/index.mjs +54 -22
  76. package/dist/server/index.mjs.map +1 -1
  77. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  78. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  79. package/dist/server/src/history/services/history.d.ts.map +1 -1
  80. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  81. package/dist/server/src/history/services/utils.d.ts +1 -0
  82. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  83. package/dist/shared/contracts/collection-types.d.ts +3 -1
  84. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  85. package/package.json +12 -12
  86. package/dist/_chunks/EditViewPage-B-RJeiJD.js.map +0 -1
  87. package/dist/_chunks/EditViewPage-De8GyU8P.mjs.map +0 -1
  88. package/dist/_chunks/Field-dq8Tg1M_.js.map +0 -1
  89. package/dist/_chunks/Field-pb2o8uBe.mjs.map +0 -1
  90. package/dist/_chunks/Form-DGIf4jQU.js.map +0 -1
  91. package/dist/_chunks/Form-DJn0Dxha.mjs.map +0 -1
  92. package/dist/_chunks/History-BowL3JKP.mjs.map +0 -1
  93. package/dist/_chunks/History-Dh2NEHnR.js.map +0 -1
  94. package/dist/_chunks/ListViewPage-4XsciqHZ.js.map +0 -1
  95. package/dist/_chunks/ListViewPage-CXFUjZQC.mjs.map +0 -1
  96. package/dist/_chunks/Relations-CVNLrn1Y.mjs.map +0 -1
  97. package/dist/_chunks/Relations-DPFCAa7b.js.map +0 -1
  98. package/dist/_chunks/index-C3fJE-1-.js.map +0 -1
  99. package/dist/_chunks/index-DiMrfcfy.mjs.map +0 -1
  100. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  101. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  102. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  103. package/strapi-server.js +0 -3
@@ -4,12 +4,13 @@ const jsxRuntime = require("react/jsx-runtime");
4
4
  const strapiAdmin = require("@strapi/admin/strapi-admin");
5
5
  const React = require("react");
6
6
  const designSystem = require("@strapi/design-system");
7
+ const mapValues = require("lodash/fp/mapValues");
7
8
  const reactIntl = require("react-intl");
8
9
  const reactRouterDom = require("react-router-dom");
9
- const styledComponents = require("styled-components");
10
10
  const yup = require("yup");
11
11
  const pipe = require("lodash/fp/pipe");
12
12
  const dateFns = require("date-fns");
13
+ const styledComponents = require("styled-components");
13
14
  const qs = require("qs");
14
15
  const toolkit = require("@reduxjs/toolkit");
15
16
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
@@ -32,6 +33,7 @@ function _interopNamespace(e) {
32
33
  return Object.freeze(n);
33
34
  }
34
35
  const React__namespace = /* @__PURE__ */ _interopNamespace(React);
36
+ const mapValues__default = /* @__PURE__ */ _interopDefault(mapValues);
35
37
  const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
36
38
  const pipe__default = /* @__PURE__ */ _interopDefault(pipe);
37
39
  const __variableDynamicImportRuntimeHelper = (glob, path) => {
@@ -121,6 +123,7 @@ const DocumentRBAC = ({ children, permissions }) => {
121
123
  if (!slug) {
122
124
  throw new Error("Cannot find the slug param in the URL");
123
125
  }
126
+ const [{ rawQuery }] = strapiAdmin.useQueryParams();
124
127
  const userPermissions = strapiAdmin.useAuth("DocumentRBAC", (state) => state.permissions);
125
128
  const contentTypePermissions = React__namespace.useMemo(() => {
126
129
  const contentTypePermissions2 = userPermissions.filter(
@@ -131,7 +134,14 @@ const DocumentRBAC = ({ children, permissions }) => {
131
134
  return { ...acc, [action]: [permission] };
132
135
  }, {});
133
136
  }, [slug, userPermissions]);
134
- const { isLoading, allowedActions } = strapiAdmin.useRBAC(contentTypePermissions, permissions ?? void 0);
137
+ const { isLoading, allowedActions } = strapiAdmin.useRBAC(
138
+ contentTypePermissions,
139
+ permissions ?? void 0,
140
+ // TODO: useRBAC context should be typed and built differently
141
+ // We are passing raw query as context to the hook so that it can
142
+ // rely on the locale provided from DocumentRBAC for its permission calculations.
143
+ rawQuery
144
+ );
135
145
  const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
136
146
  const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
137
147
  const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
@@ -482,6 +492,24 @@ const buildValidParams = (query) => {
482
492
  const isBaseQueryError = (error) => {
483
493
  return error.name !== void 0;
484
494
  };
495
+ const arrayValidator = (attribute, options) => ({
496
+ message: strapiAdmin.translatedErrors.required,
497
+ test(value) {
498
+ if (options.status === "draft") {
499
+ return true;
500
+ }
501
+ if (!attribute.required) {
502
+ return true;
503
+ }
504
+ if (!value) {
505
+ return false;
506
+ }
507
+ if (Array.isArray(value) && value.length === 0) {
508
+ return false;
509
+ }
510
+ return true;
511
+ }
512
+ });
485
513
  const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
486
514
  const createModelSchema = (attributes2) => yup__namespace.object().shape(
487
515
  Object.entries(attributes2).reduce((acc, [name, attribute]) => {
@@ -489,6 +517,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
489
517
  return acc;
490
518
  }
491
519
  const validations = [
520
+ addNullableValidation,
492
521
  addRequiredValidation,
493
522
  addMinLengthValidation,
494
523
  addMaxLengthValidation,
@@ -505,12 +534,12 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
505
534
  ...acc,
506
535
  [name]: transformSchema(
507
536
  yup__namespace.array().of(createModelSchema(attributes3).nullable(false))
508
- )
537
+ ).test(arrayValidator(attribute, options))
509
538
  };
510
539
  } else {
511
540
  return {
512
541
  ...acc,
513
- [name]: transformSchema(createModelSchema(attributes3))
542
+ [name]: transformSchema(createModelSchema(attributes3).nullable())
514
543
  };
515
544
  }
516
545
  }
@@ -532,7 +561,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
532
561
  }
533
562
  )
534
563
  )
535
- )
564
+ ).test(arrayValidator(attribute, options))
536
565
  };
537
566
  case "relation":
538
567
  return {
@@ -544,7 +573,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
544
573
  } else if (Array.isArray(value)) {
545
574
  return yup__namespace.array().of(
546
575
  yup__namespace.object().shape({
547
- id: yup__namespace.string().required()
576
+ id: yup__namespace.number().required()
548
577
  })
549
578
  );
550
579
  } else if (typeof value === "object") {
@@ -630,17 +659,17 @@ const nullableSchema = (schema) => {
630
659
  schema
631
660
  );
632
661
  };
662
+ const addNullableValidation = () => (schema) => {
663
+ return nullableSchema(schema);
664
+ };
633
665
  const addRequiredValidation = (attribute, options) => (schema) => {
634
- if (options.status === "draft") {
635
- return nullableSchema(schema);
636
- }
637
- if ((attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") && attribute.required && "min" in schema) {
638
- return schema.min(1, strapiAdmin.translatedErrors.required);
666
+ if (options.status === "draft" || !attribute.required) {
667
+ return schema;
639
668
  }
640
- if (attribute.required && attribute.type !== "relation") {
669
+ if (attribute.required && "required" in schema) {
641
670
  return schema.required(strapiAdmin.translatedErrors.required);
642
671
  }
643
- return nullableSchema(schema);
672
+ return schema;
644
673
  };
645
674
  const addMinLengthValidation = (attribute, options) => (schema) => {
646
675
  if (options.status === "draft") {
@@ -668,31 +697,12 @@ const addMaxLengthValidation = (attribute) => (schema) => {
668
697
  return schema;
669
698
  };
670
699
  const addMinValidation = (attribute, options) => (schema) => {
671
- if ("min" in attribute) {
700
+ if (options.status === "draft") {
701
+ return schema;
702
+ }
703
+ if ("min" in attribute && "min" in schema) {
672
704
  const min = toInteger(attribute.min);
673
- if (attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") {
674
- if (options.status !== "draft" && !attribute.required && "test" in schema && min) {
675
- return schema.test(
676
- "custom-min",
677
- {
678
- ...strapiAdmin.translatedErrors.min,
679
- values: {
680
- min: attribute.min
681
- }
682
- },
683
- (value) => {
684
- if (!value) {
685
- return true;
686
- }
687
- if (Array.isArray(value) && value.length === 0) {
688
- return true;
689
- }
690
- return value.length >= min;
691
- }
692
- );
693
- }
694
- }
695
- if ("min" in schema && min) {
705
+ if (min) {
696
706
  return schema.min(min, {
697
707
  ...strapiAdmin.translatedErrors.min,
698
708
  values: {
@@ -810,19 +820,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
810
820
  }, {});
811
821
  return componentsByKey;
812
822
  };
813
- const useDocument = (args, opts) => {
823
+ const HOOKS = {
824
+ /**
825
+ * Hook that allows to mutate the displayed headers of the list view table
826
+ * @constant
827
+ * @type {string}
828
+ */
829
+ INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
830
+ /**
831
+ * Hook that allows to mutate the CM's collection types links pre-set filters
832
+ * @constant
833
+ * @type {string}
834
+ */
835
+ MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
836
+ /**
837
+ * Hook that allows to mutate the CM's edit view layout
838
+ * @constant
839
+ * @type {string}
840
+ */
841
+ MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
842
+ /**
843
+ * Hook that allows to mutate the CM's single types links pre-set filters
844
+ * @constant
845
+ * @type {string}
846
+ */
847
+ MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
848
+ };
849
+ const contentTypesApi = contentManagerApi.injectEndpoints({
850
+ endpoints: (builder) => ({
851
+ getContentTypeConfiguration: builder.query({
852
+ query: (uid) => ({
853
+ url: `/content-manager/content-types/${uid}/configuration`,
854
+ method: "GET"
855
+ }),
856
+ transformResponse: (response) => response.data,
857
+ providesTags: (_result, _error, uid) => [
858
+ { type: "ContentTypesConfiguration", id: uid },
859
+ { type: "ContentTypeSettings", id: "LIST" }
860
+ ]
861
+ }),
862
+ getAllContentTypeSettings: builder.query({
863
+ query: () => "/content-manager/content-types-settings",
864
+ transformResponse: (response) => response.data,
865
+ providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
866
+ }),
867
+ updateContentTypeConfiguration: builder.mutation({
868
+ query: ({ uid, ...body }) => ({
869
+ url: `/content-manager/content-types/${uid}/configuration`,
870
+ method: "PUT",
871
+ data: body
872
+ }),
873
+ transformResponse: (response) => response.data,
874
+ invalidatesTags: (_result, _error, { uid }) => [
875
+ { type: "ContentTypesConfiguration", id: uid },
876
+ { type: "ContentTypeSettings", id: "LIST" },
877
+ // Is this necessary?
878
+ { type: "InitialData" }
879
+ ]
880
+ })
881
+ })
882
+ });
883
+ const {
884
+ useGetContentTypeConfigurationQuery,
885
+ useGetAllContentTypeSettingsQuery,
886
+ useUpdateContentTypeConfigurationMutation
887
+ } = contentTypesApi;
888
+ const checkIfAttributeIsDisplayable = (attribute) => {
889
+ const { type } = attribute;
890
+ if (type === "relation") {
891
+ return !attribute.relation.toLowerCase().includes("morph");
892
+ }
893
+ return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
894
+ };
895
+ const getMainField = (attribute, mainFieldName, { schemas, components }) => {
896
+ if (!mainFieldName) {
897
+ return void 0;
898
+ }
899
+ const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
900
+ // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
901
+ schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
902
+ );
903
+ return {
904
+ name: mainFieldName,
905
+ type: mainFieldType ?? "string"
906
+ };
907
+ };
908
+ const DEFAULT_SETTINGS = {
909
+ bulkable: false,
910
+ filterable: false,
911
+ searchable: false,
912
+ pagination: false,
913
+ defaultSortBy: "",
914
+ defaultSortOrder: "asc",
915
+ mainField: "id",
916
+ pageSize: 10
917
+ };
918
+ const useDocumentLayout = (model) => {
919
+ const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
920
+ const [{ query }] = strapiAdmin.useQueryParams();
921
+ const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
814
922
  const { toggleNotification } = strapiAdmin.useNotification();
815
923
  const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
924
+ const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
816
925
  const {
817
- currentData: data,
818
- isLoading: isLoadingDocument,
819
- isFetching: isFetchingDocument,
820
- error
821
- } = useGetDocumentQuery(args, {
822
- ...opts,
823
- skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
824
- });
825
- const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
926
+ data,
927
+ isLoading: isLoadingConfigs,
928
+ error,
929
+ isFetching: isFetchingConfigs
930
+ } = useGetContentTypeConfigurationQuery(model);
931
+ const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
826
932
  React__namespace.useEffect(() => {
827
933
  if (error) {
828
934
  toggleNotification({
@@ -830,398 +936,656 @@ const useDocument = (args, opts) => {
830
936
  message: formatAPIError(error)
831
937
  });
832
938
  }
833
- }, [toggleNotification, error, formatAPIError, args.collectionType]);
834
- const validationSchema = React__namespace.useMemo(() => {
835
- if (!schema) {
836
- return null;
837
- }
838
- return createYupSchema(schema.attributes, components);
839
- }, [schema, components]);
840
- const validate = React__namespace.useCallback(
841
- (document) => {
842
- if (!validationSchema) {
843
- throw new Error(
844
- "There is no validation schema generated, this is likely due to the schema not being loaded yet."
845
- );
846
- }
847
- try {
848
- validationSchema.validateSync(document, { abortEarly: false, strict: true });
849
- return null;
850
- } catch (error2) {
851
- if (error2 instanceof yup.ValidationError) {
852
- return strapiAdmin.getYupValidationErrors(error2);
853
- }
854
- throw error2;
855
- }
939
+ }, [error, formatAPIError, toggleNotification]);
940
+ const editLayout = React__namespace.useMemo(
941
+ () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
942
+ layout: [],
943
+ components: {},
944
+ metadatas: {},
945
+ options: {},
946
+ settings: DEFAULT_SETTINGS
856
947
  },
857
- [validationSchema]
948
+ [data, isLoading, schemas, schema, components]
949
+ );
950
+ const listLayout = React__namespace.useMemo(() => {
951
+ return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
952
+ layout: [],
953
+ metadatas: {},
954
+ options: {},
955
+ settings: DEFAULT_SETTINGS
956
+ };
957
+ }, [data, isLoading, schemas, schema, components]);
958
+ const { layout: edit } = React__namespace.useMemo(
959
+ () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
960
+ layout: editLayout,
961
+ query
962
+ }),
963
+ [editLayout, query, runHookWaterfall]
858
964
  );
859
- const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
860
965
  return {
861
- components,
862
- document: data?.data,
863
- meta: data?.meta,
966
+ error,
864
967
  isLoading,
865
- schema,
866
- validate
867
- };
868
- };
869
- const useDoc = () => {
870
- const { id, slug, collectionType, origin } = reactRouterDom.useParams();
871
- const [{ query }] = strapiAdmin.useQueryParams();
872
- const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
873
- if (!collectionType) {
874
- throw new Error("Could not find collectionType in url params");
875
- }
876
- if (!slug) {
877
- throw new Error("Could not find model in url params");
878
- }
879
- return {
880
- collectionType,
881
- model: slug,
882
- id: origin || id === "create" ? void 0 : id,
883
- ...useDocument(
884
- { documentId: origin || id, model: slug, collectionType, params },
885
- {
886
- skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
887
- }
888
- )
968
+ edit,
969
+ list: listLayout
889
970
  };
890
971
  };
891
- const prefixPluginTranslations = (trad, pluginId) => {
892
- if (!pluginId) {
893
- throw new TypeError("pluginId can't be empty");
894
- }
895
- return Object.keys(trad).reduce((acc, current) => {
896
- acc[`${pluginId}.${current}`] = trad[current];
897
- return acc;
898
- }, {});
899
- };
900
- const getTranslation = (id) => `content-manager.${id}`;
901
- const DEFAULT_UNEXPECTED_ERROR_MSG = {
902
- id: "notification.error",
903
- defaultMessage: "An error occurred, please try again"
972
+ const useDocLayout = () => {
973
+ const { model } = useDoc();
974
+ return useDocumentLayout(model);
904
975
  };
905
- const useDocumentActions = () => {
906
- const { toggleNotification } = strapiAdmin.useNotification();
907
- const { formatMessage } = reactIntl.useIntl();
908
- const { trackUsage } = strapiAdmin.useTracking();
909
- const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
910
- const navigate = reactRouterDom.useNavigate();
911
- const [deleteDocument] = useDeleteDocumentMutation();
912
- const _delete = React__namespace.useCallback(
913
- async ({ collectionType, model, documentId, params }, trackerProperty) => {
914
- try {
915
- trackUsage("willDeleteEntry", trackerProperty);
916
- const res = await deleteDocument({
917
- collectionType,
918
- model,
919
- documentId,
920
- params
921
- });
922
- if ("error" in res) {
923
- toggleNotification({
924
- type: "danger",
925
- message: formatAPIError(res.error)
926
- });
927
- return { error: res.error };
928
- }
929
- toggleNotification({
930
- type: "success",
931
- message: formatMessage({
932
- id: getTranslation("success.record.delete"),
933
- defaultMessage: "Deleted document"
934
- })
935
- });
936
- trackUsage("didDeleteEntry", trackerProperty);
937
- return res.data;
938
- } catch (err) {
939
- toggleNotification({
940
- type: "danger",
941
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
942
- });
943
- trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
944
- throw err;
976
+ const formatEditLayout = (data, {
977
+ schemas,
978
+ schema,
979
+ components
980
+ }) => {
981
+ let currentPanelIndex = 0;
982
+ const panelledEditAttributes = convertEditLayoutToFieldLayouts(
983
+ data.contentType.layouts.edit,
984
+ schema?.attributes,
985
+ data.contentType.metadatas,
986
+ { configurations: data.components, schemas: components },
987
+ schemas
988
+ ).reduce((panels, row) => {
989
+ if (row.some((field) => field.type === "dynamiczone")) {
990
+ panels.push([row]);
991
+ currentPanelIndex += 2;
992
+ } else {
993
+ if (!panels[currentPanelIndex]) {
994
+ panels.push([]);
945
995
  }
946
- },
947
- [trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
948
- );
949
- const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
950
- const deleteMany = React__namespace.useCallback(
951
- async ({ model, documentIds, params }) => {
952
- try {
953
- trackUsage("willBulkDeleteEntries");
954
- const res = await deleteManyDocuments({
955
- model,
956
- documentIds,
957
- params
958
- });
959
- if ("error" in res) {
960
- toggleNotification({
961
- type: "danger",
962
- message: formatAPIError(res.error)
963
- });
964
- return { error: res.error };
996
+ panels[currentPanelIndex].push(row);
997
+ }
998
+ return panels;
999
+ }, []);
1000
+ const componentEditAttributes = Object.entries(data.components).reduce(
1001
+ (acc, [uid, configuration]) => {
1002
+ acc[uid] = {
1003
+ layout: convertEditLayoutToFieldLayouts(
1004
+ configuration.layouts.edit,
1005
+ components[uid].attributes,
1006
+ configuration.metadatas,
1007
+ { configurations: data.components, schemas: components }
1008
+ ),
1009
+ settings: {
1010
+ ...configuration.settings,
1011
+ icon: components[uid].info.icon,
1012
+ displayName: components[uid].info.displayName
965
1013
  }
966
- toggleNotification({
967
- type: "success",
968
- title: formatMessage({
969
- id: getTranslation("success.records.delete"),
970
- defaultMessage: "Successfully deleted."
971
- }),
972
- message: ""
973
- });
974
- trackUsage("didBulkDeleteEntries");
975
- return res.data;
976
- } catch (err) {
977
- toggleNotification({
978
- type: "danger",
979
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
980
- });
981
- trackUsage("didNotBulkDeleteEntries");
982
- throw err;
983
- }
1014
+ };
1015
+ return acc;
984
1016
  },
985
- [trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
1017
+ {}
986
1018
  );
987
- const [discardDocument] = useDiscardDocumentMutation();
988
- const discard = React__namespace.useCallback(
989
- async ({ collectionType, model, documentId, params }) => {
990
- try {
991
- const res = await discardDocument({
992
- collectionType,
993
- model,
994
- documentId,
995
- params
996
- });
997
- if ("error" in res) {
998
- toggleNotification({
999
- type: "danger",
1000
- message: formatAPIError(res.error)
1001
- });
1002
- return { error: res.error };
1003
- }
1004
- toggleNotification({
1005
- type: "success",
1006
- message: formatMessage({
1007
- id: "content-manager.success.record.discard",
1008
- defaultMessage: "Changes discarded"
1009
- })
1010
- });
1011
- return res.data;
1012
- } catch (err) {
1013
- toggleNotification({
1014
- type: "danger",
1015
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1016
- });
1017
- throw err;
1018
- }
1019
+ const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
1020
+ (acc, [attribute, metadata]) => {
1021
+ return {
1022
+ ...acc,
1023
+ [attribute]: metadata.edit
1024
+ };
1019
1025
  },
1020
- [discardDocument, formatAPIError, formatMessage, toggleNotification]
1026
+ {}
1021
1027
  );
1022
- const [publishDocument] = usePublishDocumentMutation();
1023
- const publish = React__namespace.useCallback(
1024
- async ({ collectionType, model, documentId, params }, data) => {
1025
- try {
1026
- trackUsage("willPublishEntry");
1027
- const res = await publishDocument({
1028
- collectionType,
1029
- model,
1030
- documentId,
1031
- data,
1032
- params
1033
- });
1034
- if ("error" in res) {
1035
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1036
- return { error: res.error };
1037
- }
1038
- trackUsage("didPublishEntry");
1039
- toggleNotification({
1040
- type: "success",
1041
- message: formatMessage({
1042
- id: getTranslation("success.record.publish"),
1043
- defaultMessage: "Published document"
1044
- })
1045
- });
1046
- return res.data;
1047
- } catch (err) {
1048
- toggleNotification({
1049
- type: "danger",
1050
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1051
- });
1052
- throw err;
1053
- }
1028
+ return {
1029
+ layout: panelledEditAttributes,
1030
+ components: componentEditAttributes,
1031
+ metadatas: editMetadatas,
1032
+ settings: {
1033
+ ...data.contentType.settings,
1034
+ displayName: schema?.info.displayName
1054
1035
  },
1055
- [trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
1056
- );
1057
- const [publishManyDocuments] = usePublishManyDocumentsMutation();
1058
- const publishMany = React__namespace.useCallback(
1059
- async ({ model, documentIds, params }) => {
1060
- try {
1061
- const res = await publishManyDocuments({
1062
- model,
1063
- documentIds,
1064
- params
1065
- });
1066
- if ("error" in res) {
1067
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1068
- return { error: res.error };
1069
- }
1070
- toggleNotification({
1071
- type: "success",
1072
- message: formatMessage({
1073
- id: getTranslation("success.record.publish"),
1074
- defaultMessage: "Published document"
1075
- })
1076
- });
1077
- return res.data;
1078
- } catch (err) {
1079
- toggleNotification({
1080
- type: "danger",
1081
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1082
- });
1083
- throw err;
1036
+ options: {
1037
+ ...schema?.options,
1038
+ ...schema?.pluginOptions,
1039
+ ...data.contentType.options
1040
+ }
1041
+ };
1042
+ };
1043
+ const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
1044
+ return rows.map(
1045
+ (row) => row.map((field) => {
1046
+ const attribute = attributes[field.name];
1047
+ if (!attribute) {
1048
+ return null;
1084
1049
  }
1085
- },
1086
- [
1087
- // trackUsage,
1088
- publishManyDocuments,
1089
- toggleNotification,
1090
- formatMessage,
1091
- formatAPIError
1092
- ]
1050
+ const { edit: metadata } = metadatas[field.name];
1051
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1052
+ return {
1053
+ attribute,
1054
+ disabled: !metadata.editable,
1055
+ hint: metadata.description,
1056
+ label: metadata.label ?? "",
1057
+ name: field.name,
1058
+ // @ts-expect-error – mainField does exist on the metadata for a relation.
1059
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1060
+ schemas,
1061
+ components: components?.schemas ?? {}
1062
+ }),
1063
+ placeholder: metadata.placeholder ?? "",
1064
+ required: attribute.required ?? false,
1065
+ size: field.size,
1066
+ unique: "unique" in attribute ? attribute.unique : false,
1067
+ visible: metadata.visible ?? true,
1068
+ type: attribute.type
1069
+ };
1070
+ }).filter((field) => field !== null)
1093
1071
  );
1094
- const [updateDocument] = useUpdateDocumentMutation();
1095
- const update = React__namespace.useCallback(
1096
- async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
1097
- try {
1098
- trackUsage("willEditEntry", trackerProperty);
1099
- const res = await updateDocument({
1100
- collectionType,
1101
- model,
1102
- documentId,
1103
- data,
1104
- params
1105
- });
1106
- if ("error" in res) {
1107
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1108
- trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
1109
- return { error: res.error };
1072
+ };
1073
+ const formatListLayout = (data, {
1074
+ schemas,
1075
+ schema,
1076
+ components
1077
+ }) => {
1078
+ const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
1079
+ (acc, [attribute, metadata]) => {
1080
+ return {
1081
+ ...acc,
1082
+ [attribute]: metadata.list
1083
+ };
1084
+ },
1085
+ {}
1086
+ );
1087
+ const listAttributes = convertListLayoutToFieldLayouts(
1088
+ data.contentType.layouts.list,
1089
+ schema?.attributes,
1090
+ listMetadatas,
1091
+ { configurations: data.components, schemas: components },
1092
+ schemas
1093
+ );
1094
+ return {
1095
+ layout: listAttributes,
1096
+ settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
1097
+ metadatas: listMetadatas,
1098
+ options: {
1099
+ ...schema?.options,
1100
+ ...schema?.pluginOptions,
1101
+ ...data.contentType.options
1102
+ }
1103
+ };
1104
+ };
1105
+ const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
1106
+ return columns.map((name) => {
1107
+ const attribute = attributes[name];
1108
+ if (!attribute) {
1109
+ return null;
1110
+ }
1111
+ const metadata = metadatas[name];
1112
+ const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
1113
+ return {
1114
+ attribute,
1115
+ label: metadata.label ?? "",
1116
+ mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
1117
+ schemas,
1118
+ components: components?.schemas ?? {}
1119
+ }),
1120
+ name,
1121
+ searchable: metadata.searchable ?? true,
1122
+ sortable: metadata.sortable ?? true
1123
+ };
1124
+ }).filter((field) => field !== null);
1125
+ };
1126
+ const useDocument = (args, opts) => {
1127
+ const { toggleNotification } = strapiAdmin.useNotification();
1128
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
1129
+ const {
1130
+ currentData: data,
1131
+ isLoading: isLoadingDocument,
1132
+ isFetching: isFetchingDocument,
1133
+ error
1134
+ } = useGetDocumentQuery(args, {
1135
+ ...opts,
1136
+ skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
1137
+ });
1138
+ const {
1139
+ components,
1140
+ schema,
1141
+ schemas,
1142
+ isLoading: isLoadingSchema
1143
+ } = useContentTypeSchema(args.model);
1144
+ React__namespace.useEffect(() => {
1145
+ if (error) {
1146
+ toggleNotification({
1147
+ type: "danger",
1148
+ message: formatAPIError(error)
1149
+ });
1150
+ }
1151
+ }, [toggleNotification, error, formatAPIError, args.collectionType]);
1152
+ const validationSchema = React__namespace.useMemo(() => {
1153
+ if (!schema) {
1154
+ return null;
1155
+ }
1156
+ return createYupSchema(schema.attributes, components);
1157
+ }, [schema, components]);
1158
+ const validate = React__namespace.useCallback(
1159
+ (document) => {
1160
+ if (!validationSchema) {
1161
+ throw new Error(
1162
+ "There is no validation schema generated, this is likely due to the schema not being loaded yet."
1163
+ );
1164
+ }
1165
+ try {
1166
+ validationSchema.validateSync(document, { abortEarly: false, strict: true });
1167
+ return null;
1168
+ } catch (error2) {
1169
+ if (error2 instanceof yup.ValidationError) {
1170
+ return strapiAdmin.getYupValidationErrors(error2);
1110
1171
  }
1111
- trackUsage("didEditEntry", trackerProperty);
1112
- toggleNotification({
1113
- type: "success",
1114
- message: formatMessage({
1115
- id: getTranslation("success.record.save"),
1116
- defaultMessage: "Saved document"
1117
- })
1118
- });
1119
- return res.data;
1120
- } catch (err) {
1121
- trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
1122
- toggleNotification({
1123
- type: "danger",
1124
- message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1125
- });
1126
- throw err;
1172
+ throw error2;
1127
1173
  }
1128
1174
  },
1129
- [trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
1175
+ [validationSchema]
1130
1176
  );
1131
- const [unpublishDocument] = useUnpublishDocumentMutation();
1132
- const unpublish = React__namespace.useCallback(
1133
- async ({ collectionType, model, documentId, params }, discardDraft = false) => {
1177
+ const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
1178
+ const hasError = !!error;
1179
+ return {
1180
+ components,
1181
+ document: data?.data,
1182
+ meta: data?.meta,
1183
+ isLoading,
1184
+ hasError,
1185
+ schema,
1186
+ schemas,
1187
+ validate
1188
+ };
1189
+ };
1190
+ const useDoc = () => {
1191
+ const { id, slug, collectionType, origin } = reactRouterDom.useParams();
1192
+ const [{ query }] = strapiAdmin.useQueryParams();
1193
+ const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
1194
+ if (!collectionType) {
1195
+ throw new Error("Could not find collectionType in url params");
1196
+ }
1197
+ if (!slug) {
1198
+ throw new Error("Could not find model in url params");
1199
+ }
1200
+ const document = useDocument(
1201
+ { documentId: origin || id, model: slug, collectionType, params },
1202
+ {
1203
+ skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
1204
+ }
1205
+ );
1206
+ const returnId = origin || id === "create" ? void 0 : id;
1207
+ return {
1208
+ collectionType,
1209
+ model: slug,
1210
+ id: returnId,
1211
+ ...document
1212
+ };
1213
+ };
1214
+ const useContentManagerContext = () => {
1215
+ const {
1216
+ collectionType,
1217
+ model,
1218
+ id,
1219
+ components,
1220
+ isLoading: isLoadingDoc,
1221
+ schema,
1222
+ schemas
1223
+ } = useDoc();
1224
+ const layout = useDocumentLayout(model);
1225
+ const form = strapiAdmin.useForm("useContentManagerContext", (state) => state);
1226
+ const isSingleType = collectionType === SINGLE_TYPES;
1227
+ const slug = model;
1228
+ const isCreatingEntry = id === "create";
1229
+ useContentTypeSchema();
1230
+ const isLoading = isLoadingDoc || layout.isLoading;
1231
+ const error = layout.error;
1232
+ return {
1233
+ error,
1234
+ isLoading,
1235
+ // Base metadata
1236
+ model,
1237
+ collectionType,
1238
+ id,
1239
+ slug,
1240
+ isCreatingEntry,
1241
+ isSingleType,
1242
+ hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
1243
+ // All schema infos
1244
+ components,
1245
+ contentType: schema,
1246
+ contentTypes: schemas,
1247
+ // Form state
1248
+ form,
1249
+ // layout infos
1250
+ layout
1251
+ };
1252
+ };
1253
+ const prefixPluginTranslations = (trad, pluginId) => {
1254
+ if (!pluginId) {
1255
+ throw new TypeError("pluginId can't be empty");
1256
+ }
1257
+ return Object.keys(trad).reduce((acc, current) => {
1258
+ acc[`${pluginId}.${current}`] = trad[current];
1259
+ return acc;
1260
+ }, {});
1261
+ };
1262
+ const getTranslation = (id) => `content-manager.${id}`;
1263
+ const DEFAULT_UNEXPECTED_ERROR_MSG = {
1264
+ id: "notification.error",
1265
+ defaultMessage: "An error occurred, please try again"
1266
+ };
1267
+ const useDocumentActions = () => {
1268
+ const { toggleNotification } = strapiAdmin.useNotification();
1269
+ const { formatMessage } = reactIntl.useIntl();
1270
+ const { trackUsage } = strapiAdmin.useTracking();
1271
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
1272
+ const navigate = reactRouterDom.useNavigate();
1273
+ const setCurrentStep = strapiAdmin.useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
1274
+ const [deleteDocument] = useDeleteDocumentMutation();
1275
+ const _delete = React__namespace.useCallback(
1276
+ async ({ collectionType, model, documentId, params }, trackerProperty) => {
1134
1277
  try {
1135
- trackUsage("willUnpublishEntry");
1136
- const res = await unpublishDocument({
1278
+ trackUsage("willDeleteEntry", trackerProperty);
1279
+ const res = await deleteDocument({
1137
1280
  collectionType,
1138
1281
  model,
1139
1282
  documentId,
1140
- params,
1141
- data: {
1142
- discardDraft
1143
- }
1283
+ params
1144
1284
  });
1145
1285
  if ("error" in res) {
1146
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1286
+ toggleNotification({
1287
+ type: "danger",
1288
+ message: formatAPIError(res.error)
1289
+ });
1147
1290
  return { error: res.error };
1148
1291
  }
1149
- trackUsage("didUnpublishEntry");
1150
1292
  toggleNotification({
1151
1293
  type: "success",
1152
1294
  message: formatMessage({
1153
- id: getTranslation("success.record.unpublish"),
1154
- defaultMessage: "Unpublished document"
1295
+ id: getTranslation("success.record.delete"),
1296
+ defaultMessage: "Deleted document"
1155
1297
  })
1156
1298
  });
1299
+ trackUsage("didDeleteEntry", trackerProperty);
1157
1300
  return res.data;
1158
1301
  } catch (err) {
1159
1302
  toggleNotification({
1160
1303
  type: "danger",
1161
1304
  message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1162
1305
  });
1306
+ trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
1163
1307
  throw err;
1164
1308
  }
1165
1309
  },
1166
- [trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
1310
+ [trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
1167
1311
  );
1168
- const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
1169
- const unpublishMany = React__namespace.useCallback(
1312
+ const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
1313
+ const deleteMany = React__namespace.useCallback(
1170
1314
  async ({ model, documentIds, params }) => {
1171
1315
  try {
1172
- trackUsage("willBulkUnpublishEntries");
1173
- const res = await unpublishManyDocuments({
1316
+ trackUsage("willBulkDeleteEntries");
1317
+ const res = await deleteManyDocuments({
1174
1318
  model,
1175
1319
  documentIds,
1176
1320
  params
1177
1321
  });
1178
1322
  if ("error" in res) {
1179
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1323
+ toggleNotification({
1324
+ type: "danger",
1325
+ message: formatAPIError(res.error)
1326
+ });
1180
1327
  return { error: res.error };
1181
1328
  }
1182
- trackUsage("didBulkUnpublishEntries");
1183
1329
  toggleNotification({
1184
1330
  type: "success",
1185
1331
  title: formatMessage({
1186
- id: getTranslation("success.records.unpublish"),
1187
- defaultMessage: "Successfully unpublished."
1332
+ id: getTranslation("success.records.delete"),
1333
+ defaultMessage: "Successfully deleted."
1188
1334
  }),
1189
1335
  message: ""
1190
1336
  });
1337
+ trackUsage("didBulkDeleteEntries");
1191
1338
  return res.data;
1192
1339
  } catch (err) {
1193
1340
  toggleNotification({
1194
1341
  type: "danger",
1195
1342
  message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1196
1343
  });
1197
- trackUsage("didNotBulkUnpublishEntries");
1344
+ trackUsage("didNotBulkDeleteEntries");
1198
1345
  throw err;
1199
1346
  }
1200
1347
  },
1201
- [trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
1348
+ [trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
1202
1349
  );
1203
- const [createDocument] = useCreateDocumentMutation();
1204
- const create = React__namespace.useCallback(
1205
- async ({ model, params }, data, trackerProperty) => {
1350
+ const [discardDocument] = useDiscardDocumentMutation();
1351
+ const discard = React__namespace.useCallback(
1352
+ async ({ collectionType, model, documentId, params }) => {
1206
1353
  try {
1207
- const res = await createDocument({
1354
+ const res = await discardDocument({
1355
+ collectionType,
1208
1356
  model,
1209
- data,
1357
+ documentId,
1210
1358
  params
1211
1359
  });
1212
1360
  if ("error" in res) {
1213
- toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1214
- trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
1361
+ toggleNotification({
1362
+ type: "danger",
1363
+ message: formatAPIError(res.error)
1364
+ });
1215
1365
  return { error: res.error };
1216
1366
  }
1217
- trackUsage("didCreateEntry", trackerProperty);
1218
1367
  toggleNotification({
1219
1368
  type: "success",
1220
1369
  message: formatMessage({
1221
- id: getTranslation("success.record.save"),
1222
- defaultMessage: "Saved document"
1370
+ id: "content-manager.success.record.discard",
1371
+ defaultMessage: "Changes discarded"
1372
+ })
1373
+ });
1374
+ return res.data;
1375
+ } catch (err) {
1376
+ toggleNotification({
1377
+ type: "danger",
1378
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1379
+ });
1380
+ throw err;
1381
+ }
1382
+ },
1383
+ [discardDocument, formatAPIError, formatMessage, toggleNotification]
1384
+ );
1385
+ const [publishDocument] = usePublishDocumentMutation();
1386
+ const publish = React__namespace.useCallback(
1387
+ async ({ collectionType, model, documentId, params }, data) => {
1388
+ try {
1389
+ trackUsage("willPublishEntry");
1390
+ const res = await publishDocument({
1391
+ collectionType,
1392
+ model,
1393
+ documentId,
1394
+ data,
1395
+ params
1396
+ });
1397
+ if ("error" in res) {
1398
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1399
+ return { error: res.error };
1400
+ }
1401
+ trackUsage("didPublishEntry");
1402
+ toggleNotification({
1403
+ type: "success",
1404
+ message: formatMessage({
1405
+ id: getTranslation("success.record.publish"),
1406
+ defaultMessage: "Published document"
1407
+ })
1408
+ });
1409
+ return res.data;
1410
+ } catch (err) {
1411
+ toggleNotification({
1412
+ type: "danger",
1413
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1414
+ });
1415
+ throw err;
1416
+ }
1417
+ },
1418
+ [trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
1419
+ );
1420
+ const [publishManyDocuments] = usePublishManyDocumentsMutation();
1421
+ const publishMany = React__namespace.useCallback(
1422
+ async ({ model, documentIds, params }) => {
1423
+ try {
1424
+ const res = await publishManyDocuments({
1425
+ model,
1426
+ documentIds,
1427
+ params
1428
+ });
1429
+ if ("error" in res) {
1430
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1431
+ return { error: res.error };
1432
+ }
1433
+ toggleNotification({
1434
+ type: "success",
1435
+ message: formatMessage({
1436
+ id: getTranslation("success.record.publish"),
1437
+ defaultMessage: "Published document"
1438
+ })
1439
+ });
1440
+ return res.data;
1441
+ } catch (err) {
1442
+ toggleNotification({
1443
+ type: "danger",
1444
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1445
+ });
1446
+ throw err;
1447
+ }
1448
+ },
1449
+ [
1450
+ // trackUsage,
1451
+ publishManyDocuments,
1452
+ toggleNotification,
1453
+ formatMessage,
1454
+ formatAPIError
1455
+ ]
1456
+ );
1457
+ const [updateDocument] = useUpdateDocumentMutation();
1458
+ const update = React__namespace.useCallback(
1459
+ async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
1460
+ try {
1461
+ trackUsage("willEditEntry", trackerProperty);
1462
+ const res = await updateDocument({
1463
+ collectionType,
1464
+ model,
1465
+ documentId,
1466
+ data,
1467
+ params
1468
+ });
1469
+ if ("error" in res) {
1470
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1471
+ trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
1472
+ return { error: res.error };
1473
+ }
1474
+ trackUsage("didEditEntry", trackerProperty);
1475
+ toggleNotification({
1476
+ type: "success",
1477
+ message: formatMessage({
1478
+ id: getTranslation("success.record.save"),
1479
+ defaultMessage: "Saved document"
1480
+ })
1481
+ });
1482
+ return res.data;
1483
+ } catch (err) {
1484
+ trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
1485
+ toggleNotification({
1486
+ type: "danger",
1487
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1488
+ });
1489
+ throw err;
1490
+ }
1491
+ },
1492
+ [trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
1493
+ );
1494
+ const [unpublishDocument] = useUnpublishDocumentMutation();
1495
+ const unpublish = React__namespace.useCallback(
1496
+ async ({ collectionType, model, documentId, params }, discardDraft = false) => {
1497
+ try {
1498
+ trackUsage("willUnpublishEntry");
1499
+ const res = await unpublishDocument({
1500
+ collectionType,
1501
+ model,
1502
+ documentId,
1503
+ params,
1504
+ data: {
1505
+ discardDraft
1506
+ }
1507
+ });
1508
+ if ("error" in res) {
1509
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1510
+ return { error: res.error };
1511
+ }
1512
+ trackUsage("didUnpublishEntry");
1513
+ toggleNotification({
1514
+ type: "success",
1515
+ message: formatMessage({
1516
+ id: getTranslation("success.record.unpublish"),
1517
+ defaultMessage: "Unpublished document"
1518
+ })
1519
+ });
1520
+ return res.data;
1521
+ } catch (err) {
1522
+ toggleNotification({
1523
+ type: "danger",
1524
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1525
+ });
1526
+ throw err;
1527
+ }
1528
+ },
1529
+ [trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
1530
+ );
1531
+ const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
1532
+ const unpublishMany = React__namespace.useCallback(
1533
+ async ({ model, documentIds, params }) => {
1534
+ try {
1535
+ trackUsage("willBulkUnpublishEntries");
1536
+ const res = await unpublishManyDocuments({
1537
+ model,
1538
+ documentIds,
1539
+ params
1540
+ });
1541
+ if ("error" in res) {
1542
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1543
+ return { error: res.error };
1544
+ }
1545
+ trackUsage("didBulkUnpublishEntries");
1546
+ toggleNotification({
1547
+ type: "success",
1548
+ title: formatMessage({
1549
+ id: getTranslation("success.records.unpublish"),
1550
+ defaultMessage: "Successfully unpublished."
1551
+ }),
1552
+ message: ""
1553
+ });
1554
+ return res.data;
1555
+ } catch (err) {
1556
+ toggleNotification({
1557
+ type: "danger",
1558
+ message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
1559
+ });
1560
+ trackUsage("didNotBulkUnpublishEntries");
1561
+ throw err;
1562
+ }
1563
+ },
1564
+ [trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
1565
+ );
1566
+ const [createDocument] = useCreateDocumentMutation();
1567
+ const create = React__namespace.useCallback(
1568
+ async ({ model, params }, data, trackerProperty) => {
1569
+ try {
1570
+ const res = await createDocument({
1571
+ model,
1572
+ data,
1573
+ params
1574
+ });
1575
+ if ("error" in res) {
1576
+ toggleNotification({ type: "danger", message: formatAPIError(res.error) });
1577
+ trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
1578
+ return { error: res.error };
1579
+ }
1580
+ trackUsage("didCreateEntry", trackerProperty);
1581
+ toggleNotification({
1582
+ type: "success",
1583
+ message: formatMessage({
1584
+ id: getTranslation("success.record.save"),
1585
+ defaultMessage: "Saved document"
1223
1586
  })
1224
1587
  });
1588
+ setCurrentStep("contentManager.success");
1225
1589
  return res.data;
1226
1590
  } catch (err) {
1227
1591
  toggleNotification({
@@ -1324,7 +1688,7 @@ const useDocumentActions = () => {
1324
1688
  };
1325
1689
  };
1326
1690
  const ProtectedHistoryPage = React.lazy(
1327
- () => Promise.resolve().then(() => require("./History-Dh2NEHnR.js")).then((mod) => ({ default: mod.ProtectedHistoryPage }))
1691
+ () => Promise.resolve().then(() => require("./History-Bw9vfT1k.js")).then((mod) => ({ default: mod.ProtectedHistoryPage }))
1328
1692
  );
1329
1693
  const routes$1 = [
1330
1694
  {
@@ -1337,31 +1701,31 @@ const routes$1 = [
1337
1701
  }
1338
1702
  ];
1339
1703
  const ProtectedEditViewPage = React.lazy(
1340
- () => Promise.resolve().then(() => require("./EditViewPage-B-RJeiJD.js")).then((mod) => ({ default: mod.ProtectedEditViewPage }))
1704
+ () => Promise.resolve().then(() => require("./EditViewPage-BvcMXaP2.js")).then((mod) => ({ default: mod.ProtectedEditViewPage }))
1341
1705
  );
1342
1706
  const ProtectedListViewPage = React.lazy(
1343
- () => Promise.resolve().then(() => require("./ListViewPage-4XsciqHZ.js")).then((mod) => ({ default: mod.ProtectedListViewPage }))
1707
+ () => Promise.resolve().then(() => require("./ListViewPage-MZu-8OKX.js")).then((mod) => ({ default: mod.ProtectedListViewPage }))
1344
1708
  );
1345
1709
  const ProtectedListConfiguration = React.lazy(
1346
- () => Promise.resolve().then(() => require("./ListConfigurationPage-BxYCWz9e.js")).then((mod) => ({
1710
+ () => Promise.resolve().then(() => require("./ListConfigurationPage-DBVqF5fc.js")).then((mod) => ({
1347
1711
  default: mod.ProtectedListConfiguration
1348
1712
  }))
1349
1713
  );
1350
1714
  const ProtectedEditConfigurationPage = React.lazy(
1351
- () => Promise.resolve().then(() => require("./EditConfigurationPage-BePwPuHy.js")).then((mod) => ({
1715
+ () => Promise.resolve().then(() => require("./EditConfigurationPage-Bcbi6r5y.js")).then((mod) => ({
1352
1716
  default: mod.ProtectedEditConfigurationPage
1353
1717
  }))
1354
1718
  );
1355
1719
  const ProtectedComponentConfigurationPage = React.lazy(
1356
- () => Promise.resolve().then(() => require("./ComponentConfigurationPage-D_M8iBw5.js")).then((mod) => ({
1720
+ () => Promise.resolve().then(() => require("./ComponentConfigurationPage-CzDn8Uxh.js")).then((mod) => ({
1357
1721
  default: mod.ProtectedComponentConfigurationPage
1358
1722
  }))
1359
1723
  );
1360
1724
  const NoPermissions = React.lazy(
1361
- () => Promise.resolve().then(() => require("./NoPermissionsPage-y_r7DVA2.js")).then((mod) => ({ default: mod.NoPermissions }))
1725
+ () => Promise.resolve().then(() => require("./NoPermissionsPage-COs61PpB.js")).then((mod) => ({ default: mod.NoPermissions }))
1362
1726
  );
1363
1727
  const NoContentType = React.lazy(
1364
- () => Promise.resolve().then(() => require("./NoContentTypePage-C8OpoHeU.js")).then((mod) => ({ default: mod.NoContentType }))
1728
+ () => Promise.resolve().then(() => require("./NoContentTypePage-C9lRMTCa.js")).then((mod) => ({ default: mod.NoContentType }))
1365
1729
  );
1366
1730
  const CollectionTypePages = () => {
1367
1731
  const { collectionType } = reactRouterDom.useParams();
@@ -1415,1067 +1779,749 @@ const DocumentActions = ({ actions: actions2 }) => {
1415
1779
  if (action.position === void 0) {
1416
1780
  return true;
1417
1781
  }
1418
- const positions = Array.isArray(action.position) ? action.position : [action.position];
1419
- return positions.includes("panel");
1420
- });
1421
- if (!primaryAction) {
1422
- return null;
1423
- }
1424
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
1425
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
1426
- /* @__PURE__ */ jsxRuntime.jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
1427
- restActions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
1428
- DocumentActionsMenu,
1429
- {
1430
- actions: restActions,
1431
- label: formatMessage({
1432
- id: "content-manager.containers.edit.panels.default.more-actions",
1433
- defaultMessage: "More document actions"
1434
- })
1435
- }
1436
- ) : null
1437
- ] }),
1438
- secondaryAction ? /* @__PURE__ */ jsxRuntime.jsx(
1439
- DocumentActionButton,
1440
- {
1441
- ...secondaryAction,
1442
- variant: secondaryAction.variant || "secondary"
1443
- }
1444
- ) : null
1445
- ] });
1446
- };
1447
- const DocumentActionButton = (action) => {
1448
- const [dialogId, setDialogId] = React__namespace.useState(null);
1449
- const { toggleNotification } = strapiAdmin.useNotification();
1450
- const handleClick = (action2) => async (e) => {
1451
- const { onClick = () => false, dialog, id } = action2;
1452
- const muteDialog = await onClick(e);
1453
- if (dialog && !muteDialog) {
1454
- switch (dialog.type) {
1455
- case "notification":
1456
- toggleNotification({
1457
- title: dialog.title,
1458
- message: dialog.content,
1459
- type: dialog.status,
1460
- timeout: dialog.timeout,
1461
- onClose: dialog.onClose
1462
- });
1463
- break;
1464
- case "dialog":
1465
- case "modal":
1466
- e.preventDefault();
1467
- setDialogId(id);
1468
- }
1469
- }
1470
- };
1471
- const handleClose = () => {
1472
- setDialogId(null);
1473
- };
1474
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1475
- /* @__PURE__ */ jsxRuntime.jsx(
1476
- designSystem.Button,
1477
- {
1478
- flex: "auto",
1479
- startIcon: action.icon,
1480
- disabled: action.disabled,
1481
- onClick: handleClick(action),
1482
- justifyContent: "center",
1483
- variant: action.variant || "default",
1484
- paddingTop: "7px",
1485
- paddingBottom: "7px",
1486
- children: action.label
1487
- }
1488
- ),
1489
- action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
1490
- DocumentActionConfirmDialog,
1491
- {
1492
- ...action.dialog,
1493
- variant: action.dialog?.variant ?? action.variant,
1494
- isOpen: dialogId === action.id,
1495
- onClose: handleClose
1496
- }
1497
- ) : null,
1498
- action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
1499
- DocumentActionModal,
1500
- {
1501
- ...action.dialog,
1502
- onModalClose: handleClose,
1503
- isOpen: dialogId === action.id
1504
- }
1505
- ) : null
1506
- ] });
1507
- };
1508
- const DocumentActionsMenu = ({
1509
- actions: actions2,
1510
- children,
1511
- label,
1512
- variant = "tertiary"
1513
- }) => {
1514
- const [isOpen, setIsOpen] = React__namespace.useState(false);
1515
- const [dialogId, setDialogId] = React__namespace.useState(null);
1516
- const { formatMessage } = reactIntl.useIntl();
1517
- const { toggleNotification } = strapiAdmin.useNotification();
1518
- const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
1519
- const handleClick = (action) => async (e) => {
1520
- const { onClick = () => false, dialog, id } = action;
1521
- const muteDialog = await onClick(e);
1522
- if (dialog && !muteDialog) {
1523
- switch (dialog.type) {
1524
- case "notification":
1525
- toggleNotification({
1526
- title: dialog.title,
1527
- message: dialog.content,
1528
- type: dialog.status,
1529
- timeout: dialog.timeout,
1530
- onClose: dialog.onClose
1531
- });
1532
- break;
1533
- case "dialog":
1534
- case "modal":
1535
- setDialogId(id);
1536
- }
1537
- }
1538
- };
1539
- const handleClose = () => {
1540
- setDialogId(null);
1541
- setIsOpen(false);
1542
- };
1543
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
1544
- /* @__PURE__ */ jsxRuntime.jsxs(
1545
- StyledMoreButton,
1546
- {
1547
- disabled: isDisabled,
1548
- size: "S",
1549
- endIcon: null,
1550
- paddingTop: "4px",
1551
- paddingLeft: "7px",
1552
- paddingRight: "7px",
1553
- variant,
1554
- children: [
1555
- /* @__PURE__ */ jsxRuntime.jsx(Icons.More, { "aria-hidden": true, focusable: false }),
1556
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: label || formatMessage({
1557
- id: "content-manager.containers.edit.panels.default.more-actions",
1558
- defaultMessage: "More document actions"
1559
- }) })
1560
- ]
1561
- }
1562
- ),
1563
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, { top: "4px", maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1564
- actions2.map((action) => {
1565
- return /* @__PURE__ */ jsxRuntime.jsx(
1566
- designSystem.Menu.Item,
1567
- {
1568
- disabled: action.disabled,
1569
- onSelect: handleClick(action),
1570
- display: "block",
1571
- children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", gap: 4, children: [
1572
- /* @__PURE__ */ jsxRuntime.jsxs(
1573
- designSystem.Flex,
1574
- {
1575
- color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
1576
- gap: 2,
1577
- tag: "span",
1578
- children: [
1579
- /* @__PURE__ */ jsxRuntime.jsx(
1580
- designSystem.Flex,
1581
- {
1582
- tag: "span",
1583
- color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
1584
- children: action.icon
1585
- }
1586
- ),
1587
- action.label
1588
- ]
1589
- }
1590
- ),
1591
- action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsxRuntime.jsx(
1592
- designSystem.Flex,
1593
- {
1594
- alignItems: "center",
1595
- background: "alternative100",
1596
- borderStyle: "solid",
1597
- borderColor: "alternative200",
1598
- borderWidth: "1px",
1599
- height: 5,
1600
- paddingLeft: 2,
1601
- paddingRight: 2,
1602
- hasRadius: true,
1603
- color: "alternative600",
1604
- children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
1605
- }
1606
- )
1607
- ] })
1608
- },
1609
- action.id
1610
- );
1611
- }),
1612
- children
1613
- ] }),
1614
- actions2.map((action) => {
1615
- return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
1616
- action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
1617
- DocumentActionConfirmDialog,
1618
- {
1619
- ...action.dialog,
1620
- variant: action.variant,
1621
- isOpen: dialogId === action.id,
1622
- onClose: handleClose
1623
- }
1624
- ) : null,
1625
- action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
1626
- DocumentActionModal,
1627
- {
1628
- ...action.dialog,
1629
- onModalClose: handleClose,
1630
- isOpen: dialogId === action.id
1631
- }
1632
- ) : null
1633
- ] }, action.id);
1634
- })
1635
- ] });
1636
- };
1637
- const convertActionVariantToColor = (variant = "secondary") => {
1638
- switch (variant) {
1639
- case "danger":
1640
- return "danger600";
1641
- case "secondary":
1642
- return void 0;
1643
- case "success":
1644
- return "success600";
1645
- default:
1646
- return "primary600";
1647
- }
1648
- };
1649
- const convertActionVariantToIconColor = (variant = "secondary") => {
1650
- switch (variant) {
1651
- case "danger":
1652
- return "danger600";
1653
- case "secondary":
1654
- return "neutral500";
1655
- case "success":
1656
- return "success600";
1657
- default:
1658
- return "primary600";
1659
- }
1660
- };
1661
- const StyledMoreButton = styledComponents.styled(designSystem.Menu.Trigger)`
1662
- & > span {
1663
- display: flex;
1664
- }
1665
- `;
1666
- const DocumentActionConfirmDialog = ({
1667
- onClose,
1668
- onCancel,
1669
- onConfirm,
1670
- title,
1671
- content,
1672
- isOpen,
1673
- variant = "secondary"
1674
- }) => {
1675
- const { formatMessage } = reactIntl.useIntl();
1676
- const handleClose = async () => {
1677
- if (onCancel) {
1678
- await onCancel();
1679
- }
1680
- onClose();
1681
- };
1682
- const handleConfirm = async () => {
1683
- if (onConfirm) {
1684
- await onConfirm();
1685
- }
1686
- onClose();
1687
- };
1688
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
1689
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
1690
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: content }),
1691
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
1692
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({
1693
- id: "app.components.Button.cancel",
1694
- defaultMessage: "Cancel"
1695
- }) }) }),
1696
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleConfirm, variant, children: formatMessage({
1697
- id: "app.components.Button.confirm",
1698
- defaultMessage: "Confirm"
1699
- }) })
1700
- ] })
1701
- ] }) });
1702
- };
1703
- const DocumentActionModal = ({
1704
- isOpen,
1705
- title,
1706
- onClose,
1707
- footer: Footer,
1708
- content: Content,
1709
- onModalClose
1710
- }) => {
1711
- const handleClose = () => {
1712
- if (onClose) {
1713
- onClose();
1714
- }
1715
- onModalClose();
1716
- };
1717
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
1718
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
1719
- typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: Content }),
1720
- typeof Footer === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Footer, { onClose: handleClose }) : Footer
1721
- ] }) });
1722
- };
1723
- const PublishAction$1 = ({
1724
- activeTab,
1725
- documentId,
1726
- model,
1727
- collectionType,
1728
- meta,
1729
- document
1730
- }) => {
1731
- const { schema } = useDoc();
1732
- const navigate = reactRouterDom.useNavigate();
1733
- const { toggleNotification } = strapiAdmin.useNotification();
1734
- const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
1735
- const isListView = reactRouterDom.useMatch(LIST_PATH) !== null;
1736
- const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
1737
- const { formatMessage } = reactIntl.useIntl();
1738
- const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
1739
- const { publish } = useDocumentActions();
1740
- const [
1741
- countDraftRelations,
1742
- { isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
1743
- ] = useLazyGetDraftRelationCountQuery();
1744
- const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React__namespace.useState(0);
1745
- const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React__namespace.useState(0);
1746
- const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
1747
- const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
1748
- const modified = strapiAdmin.useForm("PublishAction", ({ modified: modified2 }) => modified2);
1749
- const setSubmitting = strapiAdmin.useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
1750
- const isSubmitting = strapiAdmin.useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
1751
- const validate = strapiAdmin.useForm("PublishAction", (state) => state.validate);
1752
- const setErrors = strapiAdmin.useForm("PublishAction", (state) => state.setErrors);
1753
- const formValues = strapiAdmin.useForm("PublishAction", ({ values }) => values);
1754
- React__namespace.useEffect(() => {
1755
- if (isErrorDraftRelations) {
1756
- toggleNotification({
1757
- type: "danger",
1758
- message: formatMessage({
1759
- id: getTranslation("error.records.fetch-draft-relatons"),
1760
- defaultMessage: "An error occurred while fetching draft relations on this document."
1761
- })
1762
- });
1763
- }
1764
- }, [isErrorDraftRelations, toggleNotification, formatMessage]);
1765
- React__namespace.useEffect(() => {
1766
- const localDraftRelations = /* @__PURE__ */ new Set();
1767
- const extractDraftRelations = (data) => {
1768
- const relations = data.connect || [];
1769
- relations.forEach((relation) => {
1770
- if (relation.status === "draft") {
1771
- localDraftRelations.add(relation.id);
1772
- }
1773
- });
1774
- };
1775
- const traverseAndExtract = (data) => {
1776
- Object.entries(data).forEach(([key, value]) => {
1777
- if (key === "connect" && Array.isArray(value)) {
1778
- extractDraftRelations({ connect: value });
1779
- } else if (typeof value === "object" && value !== null) {
1780
- traverseAndExtract(value);
1781
- }
1782
- });
1783
- };
1784
- if (!documentId || modified) {
1785
- traverseAndExtract(formValues);
1786
- setLocalCountOfDraftRelations(localDraftRelations.size);
1787
- }
1788
- }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
1789
- React__namespace.useEffect(() => {
1790
- if (documentId && !isListView) {
1791
- const fetchDraftRelationsCount = async () => {
1792
- const { data, error } = await countDraftRelations({
1793
- collectionType,
1794
- model,
1795
- documentId,
1796
- params
1797
- });
1798
- if (error) {
1799
- throw error;
1800
- }
1801
- if (data) {
1802
- setServerCountOfDraftRelations(data.data);
1803
- }
1804
- };
1805
- fetchDraftRelationsCount();
1806
- }
1807
- }, [isListView, documentId, countDraftRelations, collectionType, model, params]);
1808
- const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
1809
- if (!schema?.options?.draftAndPublish) {
1782
+ const positions = Array.isArray(action.position) ? action.position : [action.position];
1783
+ return positions.includes("panel");
1784
+ });
1785
+ if (!primaryAction) {
1810
1786
  return null;
1811
1787
  }
1812
- const performPublish = async () => {
1813
- setSubmitting(true);
1814
- try {
1815
- const { errors } = await validate();
1816
- if (errors) {
1817
- toggleNotification({
1818
- type: "danger",
1819
- message: formatMessage({
1820
- id: "content-manager.validation.error",
1821
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
1822
- })
1823
- });
1824
- return;
1825
- }
1826
- const res = await publish(
1827
- {
1828
- collectionType,
1829
- model,
1830
- documentId,
1831
- params
1832
- },
1833
- formValues
1834
- );
1835
- if ("data" in res && collectionType !== SINGLE_TYPES) {
1836
- navigate({
1837
- pathname: `../${collectionType}/${model}/${res.data.documentId}`,
1838
- search: rawQuery
1839
- });
1840
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1841
- setErrors(formatValidationErrors(res.error));
1842
- }
1843
- } finally {
1844
- setSubmitting(false);
1845
- }
1846
- };
1847
- const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
1848
- const hasDraftRelations = totalDraftRelations > 0;
1849
- return {
1850
- /**
1851
- * Disabled when:
1852
- * - currently if you're cloning a document we don't support publish & clone at the same time.
1853
- * - the form is submitting
1854
- * - the active tab is the published tab
1855
- * - the document is already published & not modified
1856
- * - the document is being created & not modified
1857
- * - the user doesn't have the permission to publish
1858
- */
1859
- disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
1860
- label: formatMessage({
1861
- id: "app.utils.publish",
1862
- defaultMessage: "Publish"
1863
- }),
1864
- onClick: async () => {
1865
- if (hasDraftRelations) {
1866
- return;
1867
- }
1868
- await performPublish();
1869
- },
1870
- dialog: hasDraftRelations ? {
1871
- type: "dialog",
1872
- variant: "danger",
1873
- footer: null,
1874
- title: formatMessage({
1875
- id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
1876
- defaultMessage: "Confirmation"
1877
- }),
1878
- content: formatMessage(
1879
- {
1880
- id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
1881
- defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
1882
- },
1788
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
1789
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
1790
+ /* @__PURE__ */ jsxRuntime.jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
1791
+ restActions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
1792
+ DocumentActionsMenu,
1883
1793
  {
1884
- count: totalDraftRelations
1794
+ actions: restActions,
1795
+ label: formatMessage({
1796
+ id: "content-manager.containers.edit.panels.default.more-actions",
1797
+ defaultMessage: "More document actions"
1798
+ })
1885
1799
  }
1886
- ),
1887
- onConfirm: async () => {
1888
- await performPublish();
1800
+ ) : null
1801
+ ] }),
1802
+ secondaryAction ? /* @__PURE__ */ jsxRuntime.jsx(
1803
+ DocumentActionButton,
1804
+ {
1805
+ ...secondaryAction,
1806
+ variant: secondaryAction.variant || "secondary"
1889
1807
  }
1890
- } : void 0
1891
- };
1808
+ ) : null
1809
+ ] });
1892
1810
  };
1893
- PublishAction$1.type = "publish";
1894
- const UpdateAction = ({
1895
- activeTab,
1896
- documentId,
1897
- model,
1898
- collectionType
1899
- }) => {
1900
- const navigate = reactRouterDom.useNavigate();
1811
+ const DocumentActionButton = (action) => {
1812
+ const [dialogId, setDialogId] = React__namespace.useState(null);
1901
1813
  const { toggleNotification } = strapiAdmin.useNotification();
1902
- const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
1903
- const cloneMatch = reactRouterDom.useMatch(CLONE_PATH);
1904
- const isCloning = cloneMatch !== null;
1905
- const { formatMessage } = reactIntl.useIntl();
1906
- const { create, update, clone } = useDocumentActions();
1907
- const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
1908
- const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
1909
- const isSubmitting = strapiAdmin.useForm("UpdateAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
1910
- const modified = strapiAdmin.useForm("UpdateAction", ({ modified: modified2 }) => modified2);
1911
- const setSubmitting = strapiAdmin.useForm("UpdateAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
1912
- const document = strapiAdmin.useForm("UpdateAction", ({ values }) => values);
1913
- const validate = strapiAdmin.useForm("UpdateAction", (state) => state.validate);
1914
- const setErrors = strapiAdmin.useForm("UpdateAction", (state) => state.setErrors);
1915
- const resetForm = strapiAdmin.useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
1916
- return {
1917
- /**
1918
- * Disabled when:
1919
- * - the form is submitting
1920
- * - the document is not modified & we're not cloning (you can save a clone entity straight away)
1921
- * - the active tab is the published tab
1922
- */
1923
- disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
1924
- label: formatMessage({
1925
- id: "content-manager.containers.Edit.save",
1926
- defaultMessage: "Save"
1927
- }),
1928
- onClick: async () => {
1929
- setSubmitting(true);
1930
- try {
1931
- if (activeTab !== "draft") {
1932
- const { errors } = await validate();
1933
- if (errors) {
1934
- toggleNotification({
1935
- type: "danger",
1936
- message: formatMessage({
1937
- id: "content-manager.validation.error",
1938
- defaultMessage: "There are validation errors in your document. Please fix them before saving."
1939
- })
1940
- });
1941
- return;
1942
- }
1943
- }
1944
- if (isCloning) {
1945
- const res = await clone(
1946
- {
1947
- model,
1948
- documentId: cloneMatch.params.origin,
1949
- params
1950
- },
1951
- document
1952
- );
1953
- if ("data" in res) {
1954
- navigate(
1955
- {
1956
- pathname: `../${res.data.documentId}`,
1957
- search: rawQuery
1958
- },
1959
- { relative: "path" }
1960
- );
1961
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1962
- setErrors(formatValidationErrors(res.error));
1963
- }
1964
- } else if (documentId || collectionType === SINGLE_TYPES) {
1965
- const res = await update(
1966
- {
1967
- collectionType,
1968
- model,
1969
- documentId,
1970
- params
1971
- },
1972
- document
1973
- );
1974
- if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1975
- setErrors(formatValidationErrors(res.error));
1976
- } else {
1977
- resetForm();
1978
- }
1979
- } else {
1980
- const res = await create(
1981
- {
1982
- model,
1983
- params
1984
- },
1985
- document
1986
- );
1987
- if ("data" in res && collectionType !== SINGLE_TYPES) {
1988
- navigate(
1989
- {
1990
- pathname: `../${res.data.documentId}`,
1991
- search: rawQuery
1992
- },
1993
- { replace: true, relative: "path" }
1994
- );
1995
- } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
1996
- setErrors(formatValidationErrors(res.error));
1997
- }
1998
- }
1999
- } finally {
2000
- setSubmitting(false);
1814
+ const handleClick = (action2) => async (e) => {
1815
+ const { onClick = () => false, dialog, id } = action2;
1816
+ const muteDialog = await onClick(e);
1817
+ if (dialog && !muteDialog) {
1818
+ switch (dialog.type) {
1819
+ case "notification":
1820
+ toggleNotification({
1821
+ title: dialog.title,
1822
+ message: dialog.content,
1823
+ type: dialog.status,
1824
+ timeout: dialog.timeout,
1825
+ onClose: dialog.onClose
1826
+ });
1827
+ break;
1828
+ case "dialog":
1829
+ case "modal":
1830
+ e.preventDefault();
1831
+ setDialogId(id);
2001
1832
  }
2002
1833
  }
2003
1834
  };
1835
+ const handleClose = () => {
1836
+ setDialogId(null);
1837
+ };
1838
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1839
+ /* @__PURE__ */ jsxRuntime.jsx(
1840
+ designSystem.Button,
1841
+ {
1842
+ flex: "auto",
1843
+ startIcon: action.icon,
1844
+ disabled: action.disabled,
1845
+ onClick: handleClick(action),
1846
+ justifyContent: "center",
1847
+ variant: action.variant || "default",
1848
+ paddingTop: "7px",
1849
+ paddingBottom: "7px",
1850
+ children: action.label
1851
+ }
1852
+ ),
1853
+ action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
1854
+ DocumentActionConfirmDialog,
1855
+ {
1856
+ ...action.dialog,
1857
+ variant: action.dialog?.variant ?? action.variant,
1858
+ isOpen: dialogId === action.id,
1859
+ onClose: handleClose
1860
+ }
1861
+ ) : null,
1862
+ action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
1863
+ DocumentActionModal,
1864
+ {
1865
+ ...action.dialog,
1866
+ onModalClose: handleClose,
1867
+ isOpen: dialogId === action.id
1868
+ }
1869
+ ) : null
1870
+ ] });
2004
1871
  };
2005
- UpdateAction.type = "update";
2006
- const UNPUBLISH_DRAFT_OPTIONS = {
2007
- KEEP: "keep",
2008
- DISCARD: "discard"
2009
- };
2010
- const UnpublishAction$1 = ({
2011
- activeTab,
2012
- documentId,
2013
- model,
2014
- collectionType,
2015
- document
1872
+ const DocumentActionsMenu = ({
1873
+ actions: actions2,
1874
+ children,
1875
+ label,
1876
+ variant = "tertiary"
2016
1877
  }) => {
1878
+ const [isOpen, setIsOpen] = React__namespace.useState(false);
1879
+ const [dialogId, setDialogId] = React__namespace.useState(null);
2017
1880
  const { formatMessage } = reactIntl.useIntl();
2018
- const { schema } = useDoc();
2019
- const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
2020
- const { unpublish } = useDocumentActions();
2021
- const [{ query }] = strapiAdmin.useQueryParams();
2022
- const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
2023
1881
  const { toggleNotification } = strapiAdmin.useNotification();
2024
- const [shouldKeepDraft, setShouldKeepDraft] = React__namespace.useState(true);
2025
- const isDocumentModified = document?.status === "modified";
2026
- const handleChange = (value) => {
2027
- setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
2028
- };
2029
- if (!schema?.options?.draftAndPublish) {
2030
- return null;
2031
- }
2032
- return {
2033
- disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
2034
- label: formatMessage({
2035
- id: "app.utils.unpublish",
2036
- defaultMessage: "Unpublish"
2037
- }),
2038
- icon: /* @__PURE__ */ jsxRuntime.jsx(StyledCrossCircle, {}),
2039
- onClick: async () => {
2040
- if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
2041
- if (!documentId) {
2042
- console.error(
2043
- "You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
2044
- );
1882
+ const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
1883
+ const handleClick = (action) => async (e) => {
1884
+ const { onClick = () => false, dialog, id } = action;
1885
+ const muteDialog = await onClick(e);
1886
+ if (dialog && !muteDialog) {
1887
+ switch (dialog.type) {
1888
+ case "notification":
2045
1889
  toggleNotification({
2046
- message: formatMessage({
2047
- id: "content-manager.actions.unpublish.error",
2048
- defaultMessage: "An error occurred while trying to unpublish the document."
2049
- }),
2050
- type: "danger"
1890
+ title: dialog.title,
1891
+ message: dialog.content,
1892
+ type: dialog.status,
1893
+ timeout: dialog.timeout,
1894
+ onClose: dialog.onClose
2051
1895
  });
2052
- }
2053
- return;
1896
+ break;
1897
+ case "dialog":
1898
+ case "modal":
1899
+ setDialogId(id);
2054
1900
  }
2055
- await unpublish({
2056
- collectionType,
2057
- model,
2058
- documentId,
2059
- params
2060
- });
2061
- },
2062
- dialog: isDocumentModified ? {
2063
- type: "dialog",
2064
- title: formatMessage({
2065
- id: "app.components.ConfirmDialog.title",
2066
- defaultMessage: "Confirmation"
2067
- }),
2068
- content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", direction: "column", gap: 6, children: [
2069
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", direction: "column", gap: 2, children: [
2070
- /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2071
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2072
- id: "content-manager.actions.unpublish.dialog.body",
2073
- defaultMessage: "Are you sure?"
1901
+ }
1902
+ };
1903
+ const handleClose = () => {
1904
+ setDialogId(null);
1905
+ setIsOpen(false);
1906
+ };
1907
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
1908
+ /* @__PURE__ */ jsxRuntime.jsxs(
1909
+ designSystem.Menu.Trigger,
1910
+ {
1911
+ disabled: isDisabled,
1912
+ size: "S",
1913
+ endIcon: null,
1914
+ paddingTop: "4px",
1915
+ paddingLeft: "7px",
1916
+ paddingRight: "7px",
1917
+ variant,
1918
+ children: [
1919
+ /* @__PURE__ */ jsxRuntime.jsx(Icons.More, { "aria-hidden": true, focusable: false }),
1920
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: label || formatMessage({
1921
+ id: "content-manager.containers.edit.panels.default.more-actions",
1922
+ defaultMessage: "More document actions"
2074
1923
  }) })
2075
- ] }),
2076
- /* @__PURE__ */ jsxRuntime.jsxs(
2077
- designSystem.Radio.Group,
2078
- {
2079
- defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
2080
- name: "discard-options",
2081
- "aria-label": formatMessage({
2082
- id: "content-manager.actions.unpublish.dialog.radio-label",
2083
- defaultMessage: "Choose an option to unpublish the document."
2084
- }),
2085
- onValueChange: handleChange,
2086
- children: [
2087
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
2088
- id: "content-manager.actions.unpublish.dialog.option.keep-draft",
2089
- defaultMessage: "Keep draft"
2090
- }) }),
2091
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
2092
- id: "content-manager.actions.unpublish.dialog.option.replace-draft",
2093
- defaultMessage: "Replace draft"
2094
- }) })
2095
- ]
2096
- }
2097
- )
2098
- ] }),
2099
- onConfirm: async () => {
2100
- if (!documentId && collectionType !== SINGLE_TYPES) {
2101
- console.error(
2102
- "You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
2103
- );
2104
- toggleNotification({
2105
- message: formatMessage({
2106
- id: "content-manager.actions.unpublish.error",
2107
- defaultMessage: "An error occurred while trying to unpublish the document."
2108
- }),
2109
- type: "danger"
2110
- });
2111
- }
2112
- await unpublish(
1924
+ ]
1925
+ }
1926
+ ),
1927
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
1928
+ actions2.map((action) => {
1929
+ return /* @__PURE__ */ jsxRuntime.jsx(
1930
+ designSystem.Menu.Item,
2113
1931
  {
2114
- collectionType,
2115
- model,
2116
- documentId,
2117
- params
1932
+ disabled: action.disabled,
1933
+ onSelect: handleClick(action),
1934
+ display: "block",
1935
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", gap: 4, children: [
1936
+ /* @__PURE__ */ jsxRuntime.jsxs(
1937
+ designSystem.Flex,
1938
+ {
1939
+ color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
1940
+ gap: 2,
1941
+ tag: "span",
1942
+ children: [
1943
+ /* @__PURE__ */ jsxRuntime.jsx(
1944
+ designSystem.Flex,
1945
+ {
1946
+ tag: "span",
1947
+ color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
1948
+ children: action.icon
1949
+ }
1950
+ ),
1951
+ action.label
1952
+ ]
1953
+ }
1954
+ ),
1955
+ action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsxRuntime.jsx(
1956
+ designSystem.Flex,
1957
+ {
1958
+ alignItems: "center",
1959
+ background: "alternative100",
1960
+ borderStyle: "solid",
1961
+ borderColor: "alternative200",
1962
+ borderWidth: "1px",
1963
+ height: 5,
1964
+ paddingLeft: 2,
1965
+ paddingRight: 2,
1966
+ hasRadius: true,
1967
+ color: "alternative600",
1968
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
1969
+ }
1970
+ )
1971
+ ] })
2118
1972
  },
2119
- !shouldKeepDraft
1973
+ action.id
2120
1974
  );
2121
- }
2122
- } : void 0,
2123
- variant: "danger",
2124
- position: ["panel", "table-row"]
1975
+ }),
1976
+ children
1977
+ ] }),
1978
+ actions2.map((action) => {
1979
+ return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
1980
+ action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
1981
+ DocumentActionConfirmDialog,
1982
+ {
1983
+ ...action.dialog,
1984
+ variant: action.variant,
1985
+ isOpen: dialogId === action.id,
1986
+ onClose: handleClose
1987
+ }
1988
+ ) : null,
1989
+ action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
1990
+ DocumentActionModal,
1991
+ {
1992
+ ...action.dialog,
1993
+ onModalClose: handleClose,
1994
+ isOpen: dialogId === action.id
1995
+ }
1996
+ ) : null
1997
+ ] }, action.id);
1998
+ })
1999
+ ] });
2000
+ };
2001
+ const convertActionVariantToColor = (variant = "secondary") => {
2002
+ switch (variant) {
2003
+ case "danger":
2004
+ return "danger600";
2005
+ case "secondary":
2006
+ return void 0;
2007
+ case "success":
2008
+ return "success600";
2009
+ default:
2010
+ return "primary600";
2011
+ }
2012
+ };
2013
+ const convertActionVariantToIconColor = (variant = "secondary") => {
2014
+ switch (variant) {
2015
+ case "danger":
2016
+ return "danger600";
2017
+ case "secondary":
2018
+ return "neutral500";
2019
+ case "success":
2020
+ return "success600";
2021
+ default:
2022
+ return "primary600";
2023
+ }
2024
+ };
2025
+ const DocumentActionConfirmDialog = ({
2026
+ onClose,
2027
+ onCancel,
2028
+ onConfirm,
2029
+ title,
2030
+ content,
2031
+ isOpen,
2032
+ variant = "secondary"
2033
+ }) => {
2034
+ const { formatMessage } = reactIntl.useIntl();
2035
+ const handleClose = async () => {
2036
+ if (onCancel) {
2037
+ await onCancel();
2038
+ }
2039
+ onClose();
2040
+ };
2041
+ const handleConfirm = async () => {
2042
+ if (onConfirm) {
2043
+ await onConfirm();
2044
+ }
2045
+ onClose();
2125
2046
  };
2047
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
2048
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
2049
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: content }),
2050
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
2051
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
2052
+ id: "app.components.Button.cancel",
2053
+ defaultMessage: "Cancel"
2054
+ }) }) }),
2055
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
2056
+ id: "app.components.Button.confirm",
2057
+ defaultMessage: "Confirm"
2058
+ }) })
2059
+ ] })
2060
+ ] }) });
2126
2061
  };
2127
- UnpublishAction$1.type = "unpublish";
2128
- const DiscardAction = ({
2129
- activeTab,
2130
- documentId,
2131
- model,
2132
- collectionType,
2133
- document
2062
+ const DocumentActionModal = ({
2063
+ isOpen,
2064
+ title,
2065
+ onClose,
2066
+ footer: Footer,
2067
+ content: Content,
2068
+ onModalClose
2134
2069
  }) => {
2135
- const { formatMessage } = reactIntl.useIntl();
2136
- const { schema } = useDoc();
2137
- const canUpdate = useDocumentRBAC("DiscardAction", ({ canUpdate: canUpdate2 }) => canUpdate2);
2138
- const { discard } = useDocumentActions();
2139
- const [{ query }] = strapiAdmin.useQueryParams();
2140
- const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
2141
- if (!schema?.options?.draftAndPublish) {
2142
- return null;
2143
- }
2144
- return {
2145
- disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
2146
- label: formatMessage({
2147
- id: "content-manager.actions.discard.label",
2148
- defaultMessage: "Discard changes"
2149
- }),
2150
- icon: /* @__PURE__ */ jsxRuntime.jsx(StyledCrossCircle, {}),
2151
- position: ["panel", "table-row"],
2152
- variant: "danger",
2153
- dialog: {
2154
- type: "dialog",
2155
- title: formatMessage({
2156
- id: "app.components.ConfirmDialog.title",
2157
- defaultMessage: "Confirmation"
2158
- }),
2159
- content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
2160
- /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2161
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2162
- id: "content-manager.actions.discard.dialog.body",
2163
- defaultMessage: "Are you sure?"
2164
- }) })
2165
- ] }),
2166
- onConfirm: async () => {
2167
- await discard({
2168
- collectionType,
2169
- model,
2170
- documentId,
2171
- params
2172
- });
2173
- }
2070
+ const handleClose = () => {
2071
+ if (onClose) {
2072
+ onClose();
2174
2073
  }
2074
+ onModalClose();
2175
2075
  };
2076
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
2077
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
2078
+ typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: Content }),
2079
+ typeof Footer === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Footer, { onClose: handleClose }) : Footer
2080
+ ] }) });
2176
2081
  };
2177
- DiscardAction.type = "discard";
2178
- const StyledCrossCircle = styledComponents.styled(Icons.CrossCircle)`
2179
- path {
2180
- fill: currentColor;
2181
- }
2182
- `;
2183
- const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
2184
- const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
2185
- const RelativeTime = React__namespace.forwardRef(
2186
- ({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
2187
- const { formatRelativeTime, formatDate, formatTime } = reactIntl.useIntl();
2188
- const interval = dateFns.intervalToDuration({
2189
- start: timestamp,
2190
- end: Date.now()
2191
- // see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
2192
- });
2193
- const unit = intervals.find((intervalUnit) => {
2194
- return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
2195
- });
2196
- const relativeTime = dateFns.isPast(timestamp) ? -interval[unit] : interval[unit];
2197
- const customInterval = customIntervals.find(
2198
- (custom) => interval[custom.unit] < custom.threshold
2199
- );
2200
- const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
2201
- return /* @__PURE__ */ jsxRuntime.jsx(
2202
- "time",
2203
- {
2204
- ref: forwardedRef,
2205
- dateTime: timestamp.toISOString(),
2206
- role: "time",
2207
- title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
2208
- ...restProps,
2209
- children: displayText
2210
- }
2211
- );
2212
- }
2213
- );
2214
- const getDisplayName = ({
2215
- firstname,
2216
- lastname,
2217
- username,
2218
- email
2219
- } = {}) => {
2220
- if (username) {
2221
- return username;
2082
+ const transformData = (data) => {
2083
+ if (Array.isArray(data)) {
2084
+ return data.map(transformData);
2222
2085
  }
2223
- if (firstname) {
2224
- return `${firstname} ${lastname ?? ""}`.trim();
2086
+ if (typeof data === "object" && data !== null) {
2087
+ if ("apiData" in data) {
2088
+ return data.apiData;
2089
+ }
2090
+ return mapValues__default.default(transformData)(data);
2225
2091
  }
2226
- return email ?? "";
2227
- };
2228
- const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2229
- const DocumentStatus = ({ status = "draft", ...restProps }) => {
2230
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
2231
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
2092
+ return data;
2232
2093
  };
2233
- const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
2234
- const { formatMessage } = reactIntl.useIntl();
2094
+ const PublishAction$1 = ({
2095
+ activeTab,
2096
+ documentId,
2097
+ model,
2098
+ collectionType,
2099
+ meta,
2100
+ document
2101
+ }) => {
2102
+ const { schema } = useDoc();
2103
+ const navigate = reactRouterDom.useNavigate();
2104
+ const { toggleNotification } = strapiAdmin.useNotification();
2105
+ const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
2106
+ const isListView = reactRouterDom.useMatch(LIST_PATH) !== null;
2235
2107
  const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2236
- const title = isCreating ? formatMessage({
2237
- id: "content-manager.containers.edit.title.new",
2238
- defaultMessage: "Create an entry"
2239
- }) : documentTitle;
2240
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
2241
- /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.BackButton, {}),
2242
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
2243
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: title }),
2244
- /* @__PURE__ */ jsxRuntime.jsx(HeaderToolbar, {})
2245
- ] }),
2246
- status ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
2247
- ] });
2248
- };
2249
- const HeaderToolbar = () => {
2250
2108
  const { formatMessage } = reactIntl.useIntl();
2251
- const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2109
+ const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
2110
+ const { publish } = useDocumentActions();
2252
2111
  const [
2253
- {
2254
- query: { status = "draft" }
2112
+ countDraftRelations,
2113
+ { isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
2114
+ ] = useLazyGetDraftRelationCountQuery();
2115
+ const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React__namespace.useState(0);
2116
+ const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React__namespace.useState(0);
2117
+ const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
2118
+ const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
2119
+ const modified = strapiAdmin.useForm("PublishAction", ({ modified: modified2 }) => modified2);
2120
+ const setSubmitting = strapiAdmin.useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
2121
+ const isSubmitting = strapiAdmin.useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
2122
+ const validate = strapiAdmin.useForm("PublishAction", (state) => state.validate);
2123
+ const setErrors = strapiAdmin.useForm("PublishAction", (state) => state.setErrors);
2124
+ const formValues = strapiAdmin.useForm("PublishAction", ({ values }) => values);
2125
+ React__namespace.useEffect(() => {
2126
+ if (isErrorDraftRelations) {
2127
+ toggleNotification({
2128
+ type: "danger",
2129
+ message: formatMessage({
2130
+ id: getTranslation("error.records.fetch-draft-relatons"),
2131
+ defaultMessage: "An error occurred while fetching draft relations on this document."
2132
+ })
2133
+ });
2255
2134
  }
2256
- ] = strapiAdmin.useQueryParams();
2257
- const { model, id, document, meta, collectionType } = useDoc();
2258
- const plugins = strapiAdmin.useStrapiApp("HeaderToolbar", (state) => state.plugins);
2259
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
2260
- /* @__PURE__ */ jsxRuntime.jsx(
2261
- strapiAdmin.DescriptionComponentRenderer,
2262
- {
2263
- props: {
2264
- activeTab: status,
2265
- model,
2266
- documentId: id,
2267
- document: isCloning ? void 0 : document,
2268
- meta: isCloning ? void 0 : meta,
2269
- collectionType
2270
- },
2271
- descriptions: plugins["content-manager"].apis.getHeaderActions(),
2272
- children: (actions2) => {
2273
- if (actions2.length > 0) {
2274
- return /* @__PURE__ */ jsxRuntime.jsx(HeaderActions, { actions: actions2 });
2275
- } else {
2276
- return null;
2277
- }
2135
+ }, [isErrorDraftRelations, toggleNotification, formatMessage]);
2136
+ React__namespace.useEffect(() => {
2137
+ const localDraftRelations = /* @__PURE__ */ new Set();
2138
+ const extractDraftRelations = (data) => {
2139
+ const relations = data.connect || [];
2140
+ relations.forEach((relation) => {
2141
+ if (relation.status === "draft") {
2142
+ localDraftRelations.add(relation.id);
2278
2143
  }
2279
- }
2280
- ),
2281
- /* @__PURE__ */ jsxRuntime.jsx(
2282
- strapiAdmin.DescriptionComponentRenderer,
2283
- {
2284
- props: {
2285
- activeTab: status,
2286
- model,
2287
- documentId: id,
2288
- document: isCloning ? void 0 : document,
2289
- meta: isCloning ? void 0 : meta,
2290
- collectionType
2291
- },
2292
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
2293
- children: (actions2) => {
2294
- const headerActions = actions2.filter((action) => {
2295
- const positions = Array.isArray(action.position) ? action.position : [action.position];
2296
- return positions.includes("header");
2297
- });
2298
- return /* @__PURE__ */ jsxRuntime.jsx(
2299
- DocumentActionsMenu,
2300
- {
2301
- actions: headerActions,
2302
- label: formatMessage({
2303
- id: "content-manager.containers.edit.header.more-actions",
2304
- defaultMessage: "More actions"
2305
- }),
2306
- children: /* @__PURE__ */ jsxRuntime.jsx(Information, { activeTab: status })
2307
- }
2308
- );
2144
+ });
2145
+ };
2146
+ const traverseAndExtract = (data) => {
2147
+ Object.entries(data).forEach(([key, value]) => {
2148
+ if (key === "connect" && Array.isArray(value)) {
2149
+ extractDraftRelations({ connect: value });
2150
+ } else if (typeof value === "object" && value !== null) {
2151
+ traverseAndExtract(value);
2309
2152
  }
2153
+ });
2154
+ };
2155
+ if (!documentId || modified) {
2156
+ traverseAndExtract(formValues);
2157
+ setLocalCountOfDraftRelations(localDraftRelations.size);
2158
+ }
2159
+ }, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
2160
+ React__namespace.useEffect(() => {
2161
+ if (!document || !document.documentId || isListView) {
2162
+ return;
2163
+ }
2164
+ const fetchDraftRelationsCount = async () => {
2165
+ const { data, error } = await countDraftRelations({
2166
+ collectionType,
2167
+ model,
2168
+ documentId,
2169
+ params
2170
+ });
2171
+ if (error) {
2172
+ throw error;
2310
2173
  }
2311
- )
2312
- ] });
2313
- };
2314
- const Information = ({ activeTab }) => {
2315
- const { formatMessage } = reactIntl.useIntl();
2316
- const { document, meta } = useDoc();
2317
- if (!document || !document.id) {
2174
+ if (data) {
2175
+ setServerCountOfDraftRelations(data.data);
2176
+ }
2177
+ };
2178
+ fetchDraftRelationsCount();
2179
+ }, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
2180
+ const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
2181
+ if (!schema?.options?.draftAndPublish) {
2318
2182
  return null;
2319
2183
  }
2320
- const createAndUpdateDocument = activeTab === "draft" ? document : meta?.availableStatus.find((status) => status.publishedAt === null);
2321
- const publishDocument = activeTab === "published" ? document : meta?.availableStatus.find((status) => status.publishedAt !== null);
2322
- const creator = createAndUpdateDocument?.[CREATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[CREATED_BY_ATTRIBUTE_NAME]) : null;
2323
- const updator = createAndUpdateDocument?.[UPDATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[UPDATED_BY_ATTRIBUTE_NAME]) : null;
2324
- const information = [
2325
- {
2326
- isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
2327
- label: formatMessage({
2328
- id: "content-manager.containers.edit.information.last-published.label",
2329
- defaultMessage: "Last published"
2330
- }),
2331
- value: formatMessage(
2184
+ const performPublish = async () => {
2185
+ setSubmitting(true);
2186
+ try {
2187
+ const { errors } = await validate(true, {
2188
+ status: "published"
2189
+ });
2190
+ if (errors) {
2191
+ toggleNotification({
2192
+ type: "danger",
2193
+ message: formatMessage({
2194
+ id: "content-manager.validation.error",
2195
+ defaultMessage: "There are validation errors in your document. Please fix them before saving."
2196
+ })
2197
+ });
2198
+ return;
2199
+ }
2200
+ const res = await publish(
2332
2201
  {
2333
- id: "content-manager.containers.edit.information.last-published.value",
2334
- defaultMessage: `Published {time}{isAnonymous, select, true {} other { by {author}}}`
2202
+ collectionType,
2203
+ model,
2204
+ documentId,
2205
+ params
2335
2206
  },
2336
- {
2337
- time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
2338
- isAnonymous: !publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME],
2339
- author: publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME] ? getDisplayName(publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME]) : null
2340
- }
2341
- )
2207
+ transformData(formValues)
2208
+ );
2209
+ if ("data" in res && collectionType !== SINGLE_TYPES) {
2210
+ navigate({
2211
+ pathname: `../${collectionType}/${model}/${res.data.documentId}`,
2212
+ search: rawQuery
2213
+ });
2214
+ } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2215
+ setErrors(formatValidationErrors(res.error));
2216
+ }
2217
+ } finally {
2218
+ setSubmitting(false);
2219
+ }
2220
+ };
2221
+ const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
2222
+ const enableDraftRelationsCount = false;
2223
+ const hasDraftRelations = enableDraftRelationsCount;
2224
+ return {
2225
+ /**
2226
+ * Disabled when:
2227
+ * - currently if you're cloning a document we don't support publish & clone at the same time.
2228
+ * - the form is submitting
2229
+ * - the active tab is the published tab
2230
+ * - the document is already published & not modified
2231
+ * - the document is being created & not modified
2232
+ * - the user doesn't have the permission to publish
2233
+ */
2234
+ disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
2235
+ label: formatMessage({
2236
+ id: "app.utils.publish",
2237
+ defaultMessage: "Publish"
2238
+ }),
2239
+ onClick: async () => {
2240
+ await performPublish();
2342
2241
  },
2343
- {
2344
- isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
2345
- label: formatMessage({
2346
- id: "content-manager.containers.edit.information.last-draft.label",
2347
- defaultMessage: "Last draft"
2242
+ dialog: hasDraftRelations ? {
2243
+ type: "dialog",
2244
+ variant: "danger",
2245
+ footer: null,
2246
+ title: formatMessage({
2247
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
2248
+ defaultMessage: "Confirmation"
2348
2249
  }),
2349
- value: formatMessage(
2250
+ content: formatMessage(
2350
2251
  {
2351
- id: "content-manager.containers.edit.information.last-draft.value",
2352
- defaultMessage: `Modified {time}{isAnonymous, select, true {} other { by {author}}}`
2252
+ id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
2253
+ defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
2353
2254
  },
2354
2255
  {
2355
- time: /* @__PURE__ */ jsxRuntime.jsx(
2356
- RelativeTime,
2357
- {
2358
- timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
2359
- }
2360
- ),
2361
- isAnonymous: !updator,
2362
- author: updator
2256
+ count: totalDraftRelations
2363
2257
  }
2364
- )
2365
- },
2366
- {
2367
- isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
2368
- label: formatMessage({
2369
- id: "content-manager.containers.edit.information.document.label",
2370
- defaultMessage: "Document"
2371
- }),
2372
- value: formatMessage(
2373
- {
2374
- id: "content-manager.containers.edit.information.document.value",
2375
- defaultMessage: `Created {time}{isAnonymous, select, true {} other { by {author}}}`
2376
- },
2377
- {
2378
- time: /* @__PURE__ */ jsxRuntime.jsx(
2379
- RelativeTime,
2380
- {
2381
- timestamp: new Date(createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME])
2382
- }
2383
- ),
2384
- isAnonymous: !creator,
2385
- author: creator
2258
+ ),
2259
+ onConfirm: async () => {
2260
+ await performPublish();
2261
+ }
2262
+ } : void 0
2263
+ };
2264
+ };
2265
+ PublishAction$1.type = "publish";
2266
+ const UpdateAction = ({
2267
+ activeTab,
2268
+ documentId,
2269
+ model,
2270
+ collectionType
2271
+ }) => {
2272
+ const navigate = reactRouterDom.useNavigate();
2273
+ const { toggleNotification } = strapiAdmin.useNotification();
2274
+ const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
2275
+ const cloneMatch = reactRouterDom.useMatch(CLONE_PATH);
2276
+ const isCloning = cloneMatch !== null;
2277
+ const { formatMessage } = reactIntl.useIntl();
2278
+ const { create, update, clone } = useDocumentActions();
2279
+ const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
2280
+ const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
2281
+ const isSubmitting = strapiAdmin.useForm("UpdateAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
2282
+ const modified = strapiAdmin.useForm("UpdateAction", ({ modified: modified2 }) => modified2);
2283
+ const setSubmitting = strapiAdmin.useForm("UpdateAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
2284
+ const document = strapiAdmin.useForm("UpdateAction", ({ values }) => values);
2285
+ const validate = strapiAdmin.useForm("UpdateAction", (state) => state.validate);
2286
+ const setErrors = strapiAdmin.useForm("UpdateAction", (state) => state.setErrors);
2287
+ const resetForm = strapiAdmin.useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
2288
+ return {
2289
+ /**
2290
+ * Disabled when:
2291
+ * - the form is submitting
2292
+ * - the document is not modified & we're not cloning (you can save a clone entity straight away)
2293
+ * - the active tab is the published tab
2294
+ */
2295
+ disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
2296
+ label: formatMessage({
2297
+ id: "content-manager.containers.Edit.save",
2298
+ defaultMessage: "Save"
2299
+ }),
2300
+ onClick: async () => {
2301
+ setSubmitting(true);
2302
+ try {
2303
+ const { errors } = await validate(true, {
2304
+ status: "draft"
2305
+ });
2306
+ if (errors) {
2307
+ toggleNotification({
2308
+ type: "danger",
2309
+ message: formatMessage({
2310
+ id: "content-manager.validation.error",
2311
+ defaultMessage: "There are validation errors in your document. Please fix them before saving."
2312
+ })
2313
+ });
2314
+ return;
2386
2315
  }
2387
- )
2388
- }
2389
- ].filter((info) => info.isDisplayed);
2390
- return /* @__PURE__ */ jsxRuntime.jsx(
2391
- designSystem.Flex,
2392
- {
2393
- borderWidth: "1px 0 0 0",
2394
- borderStyle: "solid",
2395
- borderColor: "neutral150",
2396
- direction: "column",
2397
- marginTop: 2,
2398
- tag: "dl",
2399
- padding: 5,
2400
- gap: 3,
2401
- alignItems: "flex-start",
2402
- marginLeft: "-0.4rem",
2403
- marginRight: "-0.4rem",
2404
- width: "calc(100% + 8px)",
2405
- children: information.map((info) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, direction: "column", alignItems: "flex-start", children: [
2406
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
2407
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "dd", variant: "pi", textColor: "neutral600", children: info.value })
2408
- ] }, info.label))
2316
+ if (isCloning) {
2317
+ const res = await clone(
2318
+ {
2319
+ model,
2320
+ documentId: cloneMatch.params.origin,
2321
+ params
2322
+ },
2323
+ transformData(document)
2324
+ );
2325
+ if ("data" in res) {
2326
+ navigate(
2327
+ {
2328
+ pathname: `../${res.data.documentId}`,
2329
+ search: rawQuery
2330
+ },
2331
+ { relative: "path" }
2332
+ );
2333
+ } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2334
+ setErrors(formatValidationErrors(res.error));
2335
+ }
2336
+ } else if (documentId || collectionType === SINGLE_TYPES) {
2337
+ const res = await update(
2338
+ {
2339
+ collectionType,
2340
+ model,
2341
+ documentId,
2342
+ params
2343
+ },
2344
+ transformData(document)
2345
+ );
2346
+ if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2347
+ setErrors(formatValidationErrors(res.error));
2348
+ } else {
2349
+ resetForm();
2350
+ }
2351
+ } else {
2352
+ const res = await create(
2353
+ {
2354
+ model,
2355
+ params
2356
+ },
2357
+ transformData(document)
2358
+ );
2359
+ if ("data" in res && collectionType !== SINGLE_TYPES) {
2360
+ navigate(
2361
+ {
2362
+ pathname: `../${res.data.documentId}`,
2363
+ search: rawQuery
2364
+ },
2365
+ { replace: true, relative: "path" }
2366
+ );
2367
+ } else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
2368
+ setErrors(formatValidationErrors(res.error));
2369
+ }
2370
+ }
2371
+ } finally {
2372
+ setSubmitting(false);
2373
+ }
2409
2374
  }
2410
- );
2375
+ };
2411
2376
  };
2412
- const HeaderActions = ({ actions: actions2 }) => {
2413
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: actions2.map((action) => {
2414
- if ("options" in action) {
2415
- return /* @__PURE__ */ jsxRuntime.jsx(
2416
- designSystem.SingleSelect,
2417
- {
2418
- size: "S",
2419
- disabled: action.disabled,
2420
- "aria-label": action.label,
2421
- onChange: action.onSelect,
2422
- value: action.value,
2423
- children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
2424
- },
2425
- action.id
2426
- );
2427
- } else {
2428
- return null;
2429
- }
2430
- }) });
2377
+ UpdateAction.type = "update";
2378
+ const UNPUBLISH_DRAFT_OPTIONS = {
2379
+ KEEP: "keep",
2380
+ DISCARD: "discard"
2431
2381
  };
2432
- const ConfigureTheViewAction = ({ collectionType, model }) => {
2433
- const navigate = reactRouterDom.useNavigate();
2382
+ const UnpublishAction$1 = ({
2383
+ activeTab,
2384
+ documentId,
2385
+ model,
2386
+ collectionType,
2387
+ document
2388
+ }) => {
2434
2389
  const { formatMessage } = reactIntl.useIntl();
2435
- return {
2436
- label: formatMessage({
2437
- id: "app.links.configure-view",
2438
- defaultMessage: "Configure the view"
2439
- }),
2440
- icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.ListPlus, {}),
2441
- onClick: () => {
2442
- navigate(`../${collectionType}/${model}/configurations/edit`);
2443
- },
2444
- position: "header"
2390
+ const { schema } = useDoc();
2391
+ const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
2392
+ const { unpublish } = useDocumentActions();
2393
+ const [{ query }] = strapiAdmin.useQueryParams();
2394
+ const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
2395
+ const { toggleNotification } = strapiAdmin.useNotification();
2396
+ const [shouldKeepDraft, setShouldKeepDraft] = React__namespace.useState(true);
2397
+ const isDocumentModified = document?.status === "modified";
2398
+ const handleChange = (value) => {
2399
+ setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
2445
2400
  };
2446
- };
2447
- ConfigureTheViewAction.type = "configure-the-view";
2448
- const EditTheModelAction = ({ model }) => {
2449
- const navigate = reactRouterDom.useNavigate();
2450
- const { formatMessage } = reactIntl.useIntl();
2401
+ if (!schema?.options?.draftAndPublish) {
2402
+ return null;
2403
+ }
2451
2404
  return {
2405
+ disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
2452
2406
  label: formatMessage({
2453
- id: "content-manager.link-to-ctb",
2454
- defaultMessage: "Edit the model"
2407
+ id: "app.utils.unpublish",
2408
+ defaultMessage: "Unpublish"
2455
2409
  }),
2456
- icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
2457
- onClick: () => {
2458
- navigate(`/plugins/content-type-builder/content-types/${model}`);
2410
+ icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {}),
2411
+ onClick: async () => {
2412
+ if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
2413
+ if (!documentId) {
2414
+ console.error(
2415
+ "You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
2416
+ );
2417
+ toggleNotification({
2418
+ message: formatMessage({
2419
+ id: "content-manager.actions.unpublish.error",
2420
+ defaultMessage: "An error occurred while trying to unpublish the document."
2421
+ }),
2422
+ type: "danger"
2423
+ });
2424
+ }
2425
+ return;
2426
+ }
2427
+ await unpublish({
2428
+ collectionType,
2429
+ model,
2430
+ documentId,
2431
+ params
2432
+ });
2459
2433
  },
2460
- position: "header"
2434
+ dialog: isDocumentModified ? {
2435
+ type: "dialog",
2436
+ title: formatMessage({
2437
+ id: "app.components.ConfirmDialog.title",
2438
+ defaultMessage: "Confirmation"
2439
+ }),
2440
+ content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", direction: "column", gap: 6, children: [
2441
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", direction: "column", gap: 2, children: [
2442
+ /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2443
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2444
+ id: "content-manager.actions.unpublish.dialog.body",
2445
+ defaultMessage: "Are you sure?"
2446
+ }) })
2447
+ ] }),
2448
+ /* @__PURE__ */ jsxRuntime.jsxs(
2449
+ designSystem.Radio.Group,
2450
+ {
2451
+ defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
2452
+ name: "discard-options",
2453
+ "aria-label": formatMessage({
2454
+ id: "content-manager.actions.unpublish.dialog.radio-label",
2455
+ defaultMessage: "Choose an option to unpublish the document."
2456
+ }),
2457
+ onValueChange: handleChange,
2458
+ children: [
2459
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
2460
+ id: "content-manager.actions.unpublish.dialog.option.keep-draft",
2461
+ defaultMessage: "Keep draft"
2462
+ }) }),
2463
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
2464
+ id: "content-manager.actions.unpublish.dialog.option.replace-draft",
2465
+ defaultMessage: "Replace draft"
2466
+ }) })
2467
+ ]
2468
+ }
2469
+ )
2470
+ ] }),
2471
+ onConfirm: async () => {
2472
+ if (!documentId && collectionType !== SINGLE_TYPES) {
2473
+ console.error(
2474
+ "You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
2475
+ );
2476
+ toggleNotification({
2477
+ message: formatMessage({
2478
+ id: "content-manager.actions.unpublish.error",
2479
+ defaultMessage: "An error occurred while trying to unpublish the document."
2480
+ }),
2481
+ type: "danger"
2482
+ });
2483
+ }
2484
+ await unpublish(
2485
+ {
2486
+ collectionType,
2487
+ model,
2488
+ documentId,
2489
+ params
2490
+ },
2491
+ !shouldKeepDraft
2492
+ );
2493
+ }
2494
+ } : void 0,
2495
+ variant: "danger",
2496
+ position: ["panel", "table-row"]
2461
2497
  };
2462
2498
  };
2463
- EditTheModelAction.type = "edit-the-model";
2464
- const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2465
- const navigate = reactRouterDom.useNavigate();
2499
+ UnpublishAction$1.type = "unpublish";
2500
+ const DiscardAction = ({
2501
+ activeTab,
2502
+ documentId,
2503
+ model,
2504
+ collectionType,
2505
+ document
2506
+ }) => {
2466
2507
  const { formatMessage } = reactIntl.useIntl();
2467
- const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
2468
- const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
2469
- const { delete: deleteAction } = useDocumentActions();
2470
- const { toggleNotification } = strapiAdmin.useNotification();
2471
- const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
2508
+ const { schema } = useDoc();
2509
+ const canUpdate = useDocumentRBAC("DiscardAction", ({ canUpdate: canUpdate2 }) => canUpdate2);
2510
+ const { discard } = useDocumentActions();
2511
+ const [{ query }] = strapiAdmin.useQueryParams();
2512
+ const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
2513
+ if (!schema?.options?.draftAndPublish) {
2514
+ return null;
2515
+ }
2472
2516
  return {
2473
- disabled: !canDelete || !document,
2517
+ disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
2474
2518
  label: formatMessage({
2475
- id: "content-manager.actions.delete.label",
2476
- defaultMessage: "Delete document"
2519
+ id: "content-manager.actions.discard.label",
2520
+ defaultMessage: "Discard changes"
2477
2521
  }),
2478
- icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
2522
+ icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {}),
2523
+ position: ["panel", "table-row"],
2524
+ variant: "danger",
2479
2525
  dialog: {
2480
2526
  type: "dialog",
2481
2527
  title: formatMessage({
@@ -2485,92 +2531,90 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2485
2531
  content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
2486
2532
  /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2487
2533
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2488
- id: "content-manager.actions.delete.dialog.body",
2534
+ id: "content-manager.actions.discard.dialog.body",
2489
2535
  defaultMessage: "Are you sure?"
2490
2536
  }) })
2491
2537
  ] }),
2492
2538
  onConfirm: async () => {
2493
- if (!listViewPathMatch) {
2494
- setSubmitting(true);
2495
- }
2496
- try {
2497
- if (!documentId && collectionType !== SINGLE_TYPES) {
2498
- console.error(
2499
- "You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
2500
- );
2501
- toggleNotification({
2502
- message: formatMessage({
2503
- id: "content-manager.actions.delete.error",
2504
- defaultMessage: "An error occurred while trying to delete the document."
2505
- }),
2506
- type: "danger"
2507
- });
2508
- return;
2509
- }
2510
- const res = await deleteAction({
2511
- documentId,
2512
- model,
2513
- collectionType,
2514
- params: {
2515
- locale: "*"
2516
- }
2517
- });
2518
- if (!("error" in res)) {
2519
- navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
2520
- }
2521
- } finally {
2522
- if (!listViewPathMatch) {
2523
- setSubmitting(false);
2524
- }
2525
- }
2539
+ await discard({
2540
+ collectionType,
2541
+ model,
2542
+ documentId,
2543
+ params
2544
+ });
2545
+ }
2546
+ }
2547
+ };
2548
+ };
2549
+ DiscardAction.type = "discard";
2550
+ const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
2551
+ const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
2552
+ const RelativeTime = React__namespace.forwardRef(
2553
+ ({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
2554
+ const { formatRelativeTime, formatDate, formatTime } = reactIntl.useIntl();
2555
+ const interval = dateFns.intervalToDuration({
2556
+ start: timestamp,
2557
+ end: Date.now()
2558
+ // see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
2559
+ });
2560
+ const unit = intervals.find((intervalUnit) => {
2561
+ return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
2562
+ });
2563
+ const relativeTime = dateFns.isPast(timestamp) ? -interval[unit] : interval[unit];
2564
+ const customInterval = customIntervals.find(
2565
+ (custom) => interval[custom.unit] < custom.threshold
2566
+ );
2567
+ const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
2568
+ return /* @__PURE__ */ jsxRuntime.jsx(
2569
+ "time",
2570
+ {
2571
+ ref: forwardedRef,
2572
+ dateTime: timestamp.toISOString(),
2573
+ role: "time",
2574
+ title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
2575
+ ...restProps,
2576
+ children: displayText
2526
2577
  }
2527
- },
2528
- variant: "danger",
2529
- position: ["header", "table-row"]
2530
- };
2578
+ );
2579
+ }
2580
+ );
2581
+ const getDisplayName = ({
2582
+ firstname,
2583
+ lastname,
2584
+ username,
2585
+ email
2586
+ } = {}) => {
2587
+ if (username) {
2588
+ return username;
2589
+ }
2590
+ if (firstname) {
2591
+ return `${firstname} ${lastname ?? ""}`.trim();
2592
+ }
2593
+ return email ?? "";
2531
2594
  };
2532
- DeleteAction$1.type = "delete";
2533
- const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
2534
- const Panels = () => {
2535
- const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2536
- const [
2537
- {
2538
- query: { status }
2539
- }
2540
- ] = strapiAdmin.useQueryParams({
2541
- status: "draft"
2542
- });
2543
- const { model, id, document, meta, collectionType } = useDoc();
2544
- const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
2545
- const props = {
2546
- activeTab: status,
2547
- model,
2548
- documentId: id,
2549
- document: isCloning ? void 0 : document,
2550
- meta: isCloning ? void 0 : meta,
2551
- collectionType
2552
- };
2553
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
2554
- strapiAdmin.DescriptionComponentRenderer,
2555
- {
2556
- props,
2557
- descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
2558
- children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
2559
- }
2560
- ) });
2595
+ const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2596
+ const DocumentStatus = ({ status = "draft", ...restProps }) => {
2597
+ const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
2598
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
2561
2599
  };
2562
- const ActionsPanel = () => {
2600
+ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
2563
2601
  const { formatMessage } = reactIntl.useIntl();
2564
- return {
2565
- title: formatMessage({
2566
- id: "content-manager.containers.edit.panels.default.title",
2567
- defaultMessage: "Document"
2568
- }),
2569
- content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
2570
- };
2602
+ const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2603
+ const title = isCreating ? formatMessage({
2604
+ id: "content-manager.containers.edit.title.new",
2605
+ defaultMessage: "Create an entry"
2606
+ }) : documentTitle;
2607
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
2608
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.BackButton, {}),
2609
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
2610
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: title }),
2611
+ /* @__PURE__ */ jsxRuntime.jsx(HeaderToolbar, {})
2612
+ ] }),
2613
+ status ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
2614
+ ] });
2571
2615
  };
2572
- ActionsPanel.type = "actions";
2573
- const ActionsPanelContent = () => {
2616
+ const HeaderToolbar = () => {
2617
+ const { formatMessage } = reactIntl.useIntl();
2574
2618
  const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2575
2619
  const [
2576
2620
  {
@@ -2578,355 +2622,432 @@ const ActionsPanelContent = () => {
2578
2622
  }
2579
2623
  ] = strapiAdmin.useQueryParams();
2580
2624
  const { model, id, document, meta, collectionType } = useDoc();
2581
- const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
2582
- const props = {
2583
- activeTab: status,
2584
- model,
2585
- documentId: id,
2586
- document: isCloning ? void 0 : document,
2587
- meta: isCloning ? void 0 : meta,
2588
- collectionType
2589
- };
2590
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
2625
+ const plugins = strapiAdmin.useStrapiApp("HeaderToolbar", (state) => state.plugins);
2626
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
2591
2627
  /* @__PURE__ */ jsxRuntime.jsx(
2592
2628
  strapiAdmin.DescriptionComponentRenderer,
2593
2629
  {
2594
- props,
2595
- descriptions: plugins["content-manager"].apis.getDocumentActions(),
2596
- children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
2630
+ props: {
2631
+ activeTab: status,
2632
+ model,
2633
+ documentId: id,
2634
+ document: isCloning ? void 0 : document,
2635
+ meta: isCloning ? void 0 : meta,
2636
+ collectionType
2637
+ },
2638
+ descriptions: plugins["content-manager"].apis.getHeaderActions(),
2639
+ children: (actions2) => {
2640
+ if (actions2.length > 0) {
2641
+ return /* @__PURE__ */ jsxRuntime.jsx(HeaderActions, { actions: actions2 });
2642
+ } else {
2643
+ return null;
2644
+ }
2645
+ }
2597
2646
  }
2598
2647
  ),
2599
- /* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
2648
+ /* @__PURE__ */ jsxRuntime.jsx(
2649
+ strapiAdmin.DescriptionComponentRenderer,
2650
+ {
2651
+ props: {
2652
+ activeTab: status,
2653
+ model,
2654
+ documentId: id,
2655
+ document: isCloning ? void 0 : document,
2656
+ meta: isCloning ? void 0 : meta,
2657
+ collectionType
2658
+ },
2659
+ descriptions: plugins["content-manager"].apis.getDocumentActions(),
2660
+ children: (actions2) => {
2661
+ const headerActions = actions2.filter((action) => {
2662
+ const positions = Array.isArray(action.position) ? action.position : [action.position];
2663
+ return positions.includes("header");
2664
+ });
2665
+ return /* @__PURE__ */ jsxRuntime.jsx(
2666
+ DocumentActionsMenu,
2667
+ {
2668
+ actions: headerActions,
2669
+ label: formatMessage({
2670
+ id: "content-manager.containers.edit.header.more-actions",
2671
+ defaultMessage: "More actions"
2672
+ }),
2673
+ children: /* @__PURE__ */ jsxRuntime.jsx(Information, { activeTab: status })
2674
+ }
2675
+ );
2676
+ }
2677
+ }
2678
+ )
2600
2679
  ] });
2601
2680
  };
2602
- const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
2603
- return /* @__PURE__ */ jsxRuntime.jsxs(
2604
- designSystem.Flex,
2681
+ const Information = ({ activeTab }) => {
2682
+ const { formatMessage } = reactIntl.useIntl();
2683
+ const { document, meta } = useDoc();
2684
+ if (!document || !document.id) {
2685
+ return null;
2686
+ }
2687
+ const createAndUpdateDocument = activeTab === "draft" ? document : meta?.availableStatus.find((status) => status.publishedAt === null);
2688
+ const publishDocument = activeTab === "published" ? document : meta?.availableStatus.find((status) => status.publishedAt !== null);
2689
+ const creator = createAndUpdateDocument?.[CREATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[CREATED_BY_ATTRIBUTE_NAME]) : null;
2690
+ const updator = createAndUpdateDocument?.[UPDATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[UPDATED_BY_ATTRIBUTE_NAME]) : null;
2691
+ const information = [
2605
2692
  {
2606
- ref,
2607
- tag: "aside",
2608
- "aria-labelledby": "additional-information",
2609
- background: "neutral0",
2610
- borderColor: "neutral150",
2611
- hasRadius: true,
2612
- paddingBottom: 4,
2613
- paddingLeft: 4,
2614
- paddingRight: 4,
2615
- paddingTop: 4,
2616
- shadow: "tableShadow",
2617
- gap: 3,
2618
- direction: "column",
2619
- justifyContent: "stretch",
2620
- alignItems: "flex-start",
2621
- children: [
2622
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
2623
- children
2624
- ]
2625
- }
2626
- );
2627
- });
2628
- const HOOKS = {
2629
- /**
2630
- * Hook that allows to mutate the displayed headers of the list view table
2631
- * @constant
2632
- * @type {string}
2633
- */
2634
- INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
2635
- /**
2636
- * Hook that allows to mutate the CM's collection types links pre-set filters
2637
- * @constant
2638
- * @type {string}
2639
- */
2640
- MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
2641
- /**
2642
- * Hook that allows to mutate the CM's edit view layout
2643
- * @constant
2644
- * @type {string}
2645
- */
2646
- MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
2647
- /**
2648
- * Hook that allows to mutate the CM's single types links pre-set filters
2649
- * @constant
2650
- * @type {string}
2651
- */
2652
- MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
2653
- };
2654
- const contentTypesApi = contentManagerApi.injectEndpoints({
2655
- endpoints: (builder) => ({
2656
- getContentTypeConfiguration: builder.query({
2657
- query: (uid) => ({
2658
- url: `/content-manager/content-types/${uid}/configuration`,
2659
- method: "GET"
2693
+ isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
2694
+ label: formatMessage({
2695
+ id: "content-manager.containers.edit.information.last-published.label",
2696
+ defaultMessage: "Published"
2660
2697
  }),
2661
- transformResponse: (response) => response.data,
2662
- providesTags: (_result, _error, uid) => [
2663
- { type: "ContentTypesConfiguration", id: uid },
2664
- { type: "ContentTypeSettings", id: "LIST" }
2665
- ]
2666
- }),
2667
- getAllContentTypeSettings: builder.query({
2668
- query: () => "/content-manager/content-types-settings",
2669
- transformResponse: (response) => response.data,
2670
- providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
2671
- }),
2672
- updateContentTypeConfiguration: builder.mutation({
2673
- query: ({ uid, ...body }) => ({
2674
- url: `/content-manager/content-types/${uid}/configuration`,
2675
- method: "PUT",
2676
- data: body
2698
+ value: formatMessage(
2699
+ {
2700
+ id: "content-manager.containers.edit.information.last-published.value",
2701
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2702
+ },
2703
+ {
2704
+ time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
2705
+ isAnonymous: !publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME],
2706
+ author: publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME] ? getDisplayName(publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME]) : null
2707
+ }
2708
+ )
2709
+ },
2710
+ {
2711
+ isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
2712
+ label: formatMessage({
2713
+ id: "content-manager.containers.edit.information.last-draft.label",
2714
+ defaultMessage: "Updated"
2715
+ }),
2716
+ value: formatMessage(
2717
+ {
2718
+ id: "content-manager.containers.edit.information.last-draft.value",
2719
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2720
+ },
2721
+ {
2722
+ time: /* @__PURE__ */ jsxRuntime.jsx(
2723
+ RelativeTime,
2724
+ {
2725
+ timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
2726
+ }
2727
+ ),
2728
+ isAnonymous: !updator,
2729
+ author: updator
2730
+ }
2731
+ )
2732
+ },
2733
+ {
2734
+ isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
2735
+ label: formatMessage({
2736
+ id: "content-manager.containers.edit.information.document.label",
2737
+ defaultMessage: "Created"
2677
2738
  }),
2678
- transformResponse: (response) => response.data,
2679
- invalidatesTags: (_result, _error, { uid }) => [
2680
- { type: "ContentTypesConfiguration", id: uid },
2681
- { type: "ContentTypeSettings", id: "LIST" },
2682
- // Is this necessary?
2683
- { type: "InitialData" }
2684
- ]
2685
- })
2686
- })
2687
- });
2688
- const {
2689
- useGetContentTypeConfigurationQuery,
2690
- useGetAllContentTypeSettingsQuery,
2691
- useUpdateContentTypeConfigurationMutation
2692
- } = contentTypesApi;
2693
- const checkIfAttributeIsDisplayable = (attribute) => {
2694
- const { type } = attribute;
2695
- if (type === "relation") {
2696
- return !attribute.relation.toLowerCase().includes("morph");
2697
- }
2698
- return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
2699
- };
2700
- const getMainField = (attribute, mainFieldName, { schemas, components }) => {
2701
- if (!mainFieldName) {
2702
- return void 0;
2703
- }
2704
- const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
2705
- // @ts-expect-error – `targetModel` does exist on the attribute for a relation.
2706
- schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
2739
+ value: formatMessage(
2740
+ {
2741
+ id: "content-manager.containers.edit.information.document.value",
2742
+ defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
2743
+ },
2744
+ {
2745
+ time: /* @__PURE__ */ jsxRuntime.jsx(
2746
+ RelativeTime,
2747
+ {
2748
+ timestamp: new Date(createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME])
2749
+ }
2750
+ ),
2751
+ isAnonymous: !creator,
2752
+ author: creator
2753
+ }
2754
+ )
2755
+ }
2756
+ ].filter((info) => info.isDisplayed);
2757
+ return /* @__PURE__ */ jsxRuntime.jsx(
2758
+ designSystem.Flex,
2759
+ {
2760
+ borderWidth: "1px 0 0 0",
2761
+ borderStyle: "solid",
2762
+ borderColor: "neutral150",
2763
+ direction: "column",
2764
+ marginTop: 2,
2765
+ tag: "dl",
2766
+ padding: 5,
2767
+ gap: 3,
2768
+ alignItems: "flex-start",
2769
+ marginLeft: "-0.4rem",
2770
+ marginRight: "-0.4rem",
2771
+ width: "calc(100% + 8px)",
2772
+ children: information.map((info) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, direction: "column", alignItems: "flex-start", children: [
2773
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
2774
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "dd", variant: "pi", textColor: "neutral600", children: info.value })
2775
+ ] }, info.label))
2776
+ }
2707
2777
  );
2708
- return {
2709
- name: mainFieldName,
2710
- type: mainFieldType ?? "string"
2711
- };
2712
- };
2713
- const DEFAULT_SETTINGS = {
2714
- bulkable: false,
2715
- filterable: false,
2716
- searchable: false,
2717
- pagination: false,
2718
- defaultSortBy: "",
2719
- defaultSortOrder: "asc",
2720
- mainField: "id",
2721
- pageSize: 10
2722
2778
  };
2723
- const useDocumentLayout = (model) => {
2724
- const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
2725
- const [{ query }] = strapiAdmin.useQueryParams();
2726
- const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
2727
- const { toggleNotification } = strapiAdmin.useNotification();
2728
- const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
2729
- const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
2730
- const {
2731
- data,
2732
- isLoading: isLoadingConfigs,
2733
- error,
2734
- isFetching: isFetchingConfigs
2735
- } = useGetContentTypeConfigurationQuery(model);
2736
- const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
2737
- React__namespace.useEffect(() => {
2738
- if (error) {
2739
- toggleNotification({
2740
- type: "danger",
2741
- message: formatAPIError(error)
2742
- });
2779
+ const HeaderActions = ({ actions: actions2 }) => {
2780
+ const [dialogId, setDialogId] = React__namespace.useState(null);
2781
+ const handleClick = (action) => async (e) => {
2782
+ if (!("options" in action)) {
2783
+ const { onClick = () => false, dialog, id } = action;
2784
+ const muteDialog = await onClick(e);
2785
+ if (dialog && !muteDialog) {
2786
+ e.preventDefault();
2787
+ setDialogId(id);
2788
+ }
2743
2789
  }
2744
- }, [error, formatAPIError, toggleNotification]);
2745
- const editLayout = React__namespace.useMemo(
2746
- () => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
2747
- layout: [],
2748
- components: {},
2749
- metadatas: {},
2750
- options: {},
2751
- settings: DEFAULT_SETTINGS
2752
- },
2753
- [data, isLoading, schemas, schema, components]
2754
- );
2755
- const listLayout = React__namespace.useMemo(() => {
2756
- return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
2757
- layout: [],
2758
- metadatas: {},
2759
- options: {},
2760
- settings: DEFAULT_SETTINGS
2761
- };
2762
- }, [data, isLoading, schemas, schema, components]);
2763
- const { layout: edit } = React__namespace.useMemo(
2764
- () => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
2765
- layout: editLayout,
2766
- query
2767
- }),
2768
- [editLayout, query, runHookWaterfall]
2769
- );
2770
- return {
2771
- error,
2772
- isLoading,
2773
- edit,
2774
- list: listLayout
2775
2790
  };
2776
- };
2777
- const useDocLayout = () => {
2778
- const { model } = useDoc();
2779
- return useDocumentLayout(model);
2780
- };
2781
- const formatEditLayout = (data, {
2782
- schemas,
2783
- schema,
2784
- components
2785
- }) => {
2786
- let currentPanelIndex = 0;
2787
- const panelledEditAttributes = convertEditLayoutToFieldLayouts(
2788
- data.contentType.layouts.edit,
2789
- schema?.attributes,
2790
- data.contentType.metadatas,
2791
- { configurations: data.components, schemas: components },
2792
- schemas
2793
- ).reduce((panels, row) => {
2794
- if (row.some((field) => field.type === "dynamiczone")) {
2795
- panels.push([row]);
2796
- currentPanelIndex += 2;
2791
+ const handleClose = () => {
2792
+ setDialogId(null);
2793
+ };
2794
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 1, children: actions2.map((action) => {
2795
+ if (action.options) {
2796
+ return /* @__PURE__ */ jsxRuntime.jsx(
2797
+ designSystem.SingleSelect,
2798
+ {
2799
+ size: "S",
2800
+ onChange: action.onSelect,
2801
+ "aria-label": action.label,
2802
+ ...action,
2803
+ children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
2804
+ },
2805
+ action.id
2806
+ );
2797
2807
  } else {
2798
- if (!panels[currentPanelIndex]) {
2799
- panels.push([]);
2808
+ if (action.type === "icon") {
2809
+ return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
2810
+ /* @__PURE__ */ jsxRuntime.jsx(
2811
+ designSystem.IconButton,
2812
+ {
2813
+ disabled: action.disabled,
2814
+ label: action.label,
2815
+ size: "S",
2816
+ onClick: handleClick(action),
2817
+ children: action.icon
2818
+ }
2819
+ ),
2820
+ action.dialog ? /* @__PURE__ */ jsxRuntime.jsx(
2821
+ HeaderActionDialog,
2822
+ {
2823
+ ...action.dialog,
2824
+ isOpen: dialogId === action.id,
2825
+ onClose: handleClose
2826
+ }
2827
+ ) : null
2828
+ ] }, action.id);
2800
2829
  }
2801
- panels[currentPanelIndex].push(row);
2802
2830
  }
2803
- return panels;
2804
- }, []);
2805
- const componentEditAttributes = Object.entries(data.components).reduce(
2806
- (acc, [uid, configuration]) => {
2807
- acc[uid] = {
2808
- layout: convertEditLayoutToFieldLayouts(
2809
- configuration.layouts.edit,
2810
- components[uid].attributes,
2811
- configuration.metadatas
2812
- ),
2813
- settings: {
2814
- ...configuration.settings,
2815
- icon: components[uid].info.icon,
2816
- displayName: components[uid].info.displayName
2817
- }
2818
- };
2819
- return acc;
2820
- },
2821
- {}
2822
- );
2823
- const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
2824
- (acc, [attribute, metadata]) => {
2825
- return {
2826
- ...acc,
2827
- [attribute]: metadata.edit
2828
- };
2831
+ }) });
2832
+ };
2833
+ const HeaderActionDialog = ({
2834
+ onClose,
2835
+ onCancel,
2836
+ title,
2837
+ content: Content,
2838
+ isOpen
2839
+ }) => {
2840
+ const handleClose = async () => {
2841
+ if (onCancel) {
2842
+ await onCancel();
2843
+ }
2844
+ onClose();
2845
+ };
2846
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
2847
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
2848
+ typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : Content
2849
+ ] }) });
2850
+ };
2851
+ const ConfigureTheViewAction = ({ collectionType, model }) => {
2852
+ const navigate = reactRouterDom.useNavigate();
2853
+ const { formatMessage } = reactIntl.useIntl();
2854
+ return {
2855
+ label: formatMessage({
2856
+ id: "app.links.configure-view",
2857
+ defaultMessage: "Configure the view"
2858
+ }),
2859
+ icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.ListPlus, {}),
2860
+ onClick: () => {
2861
+ navigate(`../${collectionType}/${model}/configurations/edit`);
2829
2862
  },
2830
- {}
2831
- );
2863
+ position: "header"
2864
+ };
2865
+ };
2866
+ ConfigureTheViewAction.type = "configure-the-view";
2867
+ const EditTheModelAction = ({ model }) => {
2868
+ const navigate = reactRouterDom.useNavigate();
2869
+ const { formatMessage } = reactIntl.useIntl();
2832
2870
  return {
2833
- layout: panelledEditAttributes,
2834
- components: componentEditAttributes,
2835
- metadatas: editMetadatas,
2836
- settings: {
2837
- ...data.contentType.settings,
2838
- displayName: schema?.info.displayName
2871
+ label: formatMessage({
2872
+ id: "content-manager.link-to-ctb",
2873
+ defaultMessage: "Edit the model"
2874
+ }),
2875
+ icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
2876
+ onClick: () => {
2877
+ navigate(`/plugins/content-type-builder/content-types/${model}`);
2839
2878
  },
2840
- options: {
2841
- ...schema?.options,
2842
- ...schema?.pluginOptions,
2843
- ...data.contentType.options
2844
- }
2879
+ position: "header"
2845
2880
  };
2846
2881
  };
2847
- const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
2848
- return rows.map(
2849
- (row) => row.map((field) => {
2850
- const attribute = attributes[field.name];
2851
- if (!attribute) {
2852
- return null;
2882
+ EditTheModelAction.type = "edit-the-model";
2883
+ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
2884
+ const navigate = reactRouterDom.useNavigate();
2885
+ const { formatMessage } = reactIntl.useIntl();
2886
+ const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
2887
+ const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
2888
+ const { delete: deleteAction } = useDocumentActions();
2889
+ const { toggleNotification } = strapiAdmin.useNotification();
2890
+ const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
2891
+ const isLocalized = document?.locale != null;
2892
+ return {
2893
+ disabled: !canDelete || !document,
2894
+ label: formatMessage(
2895
+ {
2896
+ id: "content-manager.actions.delete.label",
2897
+ defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
2898
+ },
2899
+ { isLocalized }
2900
+ ),
2901
+ icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
2902
+ dialog: {
2903
+ type: "dialog",
2904
+ title: formatMessage({
2905
+ id: "app.components.ConfirmDialog.title",
2906
+ defaultMessage: "Confirmation"
2907
+ }),
2908
+ content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
2909
+ /* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
2910
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
2911
+ id: "content-manager.actions.delete.dialog.body",
2912
+ defaultMessage: "Are you sure?"
2913
+ }) })
2914
+ ] }),
2915
+ onConfirm: async () => {
2916
+ if (!listViewPathMatch) {
2917
+ setSubmitting(true);
2918
+ }
2919
+ try {
2920
+ if (!documentId && collectionType !== SINGLE_TYPES) {
2921
+ console.error(
2922
+ "You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
2923
+ );
2924
+ toggleNotification({
2925
+ message: formatMessage({
2926
+ id: "content-manager.actions.delete.error",
2927
+ defaultMessage: "An error occurred while trying to delete the document."
2928
+ }),
2929
+ type: "danger"
2930
+ });
2931
+ return;
2932
+ }
2933
+ const res = await deleteAction({
2934
+ documentId,
2935
+ model,
2936
+ collectionType,
2937
+ params: {
2938
+ locale: "*"
2939
+ }
2940
+ });
2941
+ if (!("error" in res)) {
2942
+ navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
2943
+ }
2944
+ } finally {
2945
+ if (!listViewPathMatch) {
2946
+ setSubmitting(false);
2947
+ }
2948
+ }
2853
2949
  }
2854
- const { edit: metadata } = metadatas[field.name];
2855
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
2856
- return {
2857
- attribute,
2858
- disabled: !metadata.editable,
2859
- hint: metadata.description,
2860
- label: metadata.label ?? "",
2861
- name: field.name,
2862
- // @ts-expect-error – mainField does exist on the metadata for a relation.
2863
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
2864
- schemas,
2865
- components: components?.schemas ?? {}
2866
- }),
2867
- placeholder: metadata.placeholder ?? "",
2868
- required: attribute.required ?? false,
2869
- size: field.size,
2870
- unique: "unique" in attribute ? attribute.unique : false,
2871
- visible: metadata.visible ?? true,
2872
- type: attribute.type
2873
- };
2874
- }).filter((field) => field !== null)
2875
- );
2876
- };
2877
- const formatListLayout = (data, {
2878
- schemas,
2879
- schema,
2880
- components
2881
- }) => {
2882
- const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
2883
- (acc, [attribute, metadata]) => {
2884
- return {
2885
- ...acc,
2886
- [attribute]: metadata.list
2887
- };
2888
2950
  },
2889
- {}
2890
- );
2891
- const listAttributes = convertListLayoutToFieldLayouts(
2892
- data.contentType.layouts.list,
2893
- schema?.attributes,
2894
- listMetadatas,
2895
- { configurations: data.components, schemas: components },
2896
- schemas
2897
- );
2898
- return {
2899
- layout: listAttributes,
2900
- settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
2901
- metadatas: listMetadatas,
2902
- options: {
2903
- ...schema?.options,
2904
- ...schema?.pluginOptions,
2905
- ...data.contentType.options
2951
+ variant: "danger",
2952
+ position: ["header", "table-row"]
2953
+ };
2954
+ };
2955
+ DeleteAction$1.type = "delete";
2956
+ const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
2957
+ const Panels = () => {
2958
+ const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2959
+ const [
2960
+ {
2961
+ query: { status }
2962
+ }
2963
+ ] = strapiAdmin.useQueryParams({
2964
+ status: "draft"
2965
+ });
2966
+ const { model, id, document, meta, collectionType } = useDoc();
2967
+ const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
2968
+ const props = {
2969
+ activeTab: status,
2970
+ model,
2971
+ documentId: id,
2972
+ document: isCloning ? void 0 : document,
2973
+ meta: isCloning ? void 0 : meta,
2974
+ collectionType
2975
+ };
2976
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
2977
+ strapiAdmin.DescriptionComponentRenderer,
2978
+ {
2979
+ props,
2980
+ descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
2981
+ children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
2906
2982
  }
2983
+ ) });
2984
+ };
2985
+ const ActionsPanel = () => {
2986
+ const { formatMessage } = reactIntl.useIntl();
2987
+ return {
2988
+ title: formatMessage({
2989
+ id: "content-manager.containers.edit.panels.default.title",
2990
+ defaultMessage: "Entry"
2991
+ }),
2992
+ content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
2907
2993
  };
2908
2994
  };
2909
- const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
2910
- return columns.map((name) => {
2911
- const attribute = attributes[name];
2912
- if (!attribute) {
2913
- return null;
2995
+ ActionsPanel.type = "actions";
2996
+ const ActionsPanelContent = () => {
2997
+ const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
2998
+ const [
2999
+ {
3000
+ query: { status = "draft" }
2914
3001
  }
2915
- const metadata = metadatas[name];
2916
- const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
2917
- return {
2918
- attribute,
2919
- label: metadata.label ?? "",
2920
- mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
2921
- schemas,
2922
- components: components?.schemas ?? {}
2923
- }),
2924
- name,
2925
- searchable: metadata.searchable ?? true,
2926
- sortable: metadata.sortable ?? true
2927
- };
2928
- }).filter((field) => field !== null);
3002
+ ] = strapiAdmin.useQueryParams();
3003
+ const { model, id, document, meta, collectionType } = useDoc();
3004
+ const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
3005
+ const props = {
3006
+ activeTab: status,
3007
+ model,
3008
+ documentId: id,
3009
+ document: isCloning ? void 0 : document,
3010
+ meta: isCloning ? void 0 : meta,
3011
+ collectionType
3012
+ };
3013
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
3014
+ /* @__PURE__ */ jsxRuntime.jsx(
3015
+ strapiAdmin.DescriptionComponentRenderer,
3016
+ {
3017
+ props,
3018
+ descriptions: plugins["content-manager"].apis.getDocumentActions(),
3019
+ children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
3020
+ }
3021
+ ),
3022
+ /* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
3023
+ ] });
2929
3024
  };
3025
+ const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
3026
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3027
+ designSystem.Flex,
3028
+ {
3029
+ ref,
3030
+ tag: "aside",
3031
+ "aria-labelledby": "additional-information",
3032
+ background: "neutral0",
3033
+ borderColor: "neutral150",
3034
+ hasRadius: true,
3035
+ paddingBottom: 4,
3036
+ paddingLeft: 4,
3037
+ paddingRight: 4,
3038
+ paddingTop: 4,
3039
+ shadow: "tableShadow",
3040
+ gap: 3,
3041
+ direction: "column",
3042
+ justifyContent: "stretch",
3043
+ alignItems: "flex-start",
3044
+ children: [
3045
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
3046
+ children
3047
+ ]
3048
+ }
3049
+ );
3050
+ });
2930
3051
  const ConfirmBulkActionDialog = ({
2931
3052
  onToggleDialog,
2932
3053
  isOpen = false,
@@ -2965,6 +3086,7 @@ const ConfirmDialogPublishAll = ({
2965
3086
  const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler(getTranslation);
2966
3087
  const { model, schema } = useDoc();
2967
3088
  const [{ query }] = strapiAdmin.useQueryParams();
3089
+ const enableDraftRelationsCount = false;
2968
3090
  const {
2969
3091
  data: countDraftRelations = 0,
2970
3092
  isLoading,
@@ -2976,7 +3098,7 @@ const ConfirmDialogPublishAll = ({
2976
3098
  locale: query?.plugins?.i18n?.locale
2977
3099
  },
2978
3100
  {
2979
- skip: selectedEntries.length === 0
3101
+ skip: !enableDraftRelationsCount
2980
3102
  }
2981
3103
  );
2982
3104
  React__namespace.useEffect(() => {
@@ -3161,7 +3283,7 @@ const SelectedEntriesTableContent = ({
3161
3283
  status: row.status
3162
3284
  }
3163
3285
  ) }),
3164
- /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
3286
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(
3165
3287
  designSystem.IconButton,
3166
3288
  {
3167
3289
  tag: reactRouterDom.Link,
@@ -3184,9 +3306,10 @@ const SelectedEntriesTableContent = ({
3184
3306
  ),
3185
3307
  target: "_blank",
3186
3308
  marginLeft: "auto",
3187
- children: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {})
3309
+ variant: "ghost",
3310
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, { width: "1.6rem", height: "1.6rem" })
3188
3311
  }
3189
- ) })
3312
+ ) }) })
3190
3313
  ] }, row.id)) })
3191
3314
  ] });
3192
3315
  };
@@ -3921,7 +4044,7 @@ const index = {
3921
4044
  app.router.addRoute({
3922
4045
  path: "content-manager/*",
3923
4046
  lazy: async () => {
3924
- const { Layout } = await Promise.resolve().then(() => require("./layout-C788OmNr.js"));
4047
+ const { Layout } = await Promise.resolve().then(() => require("./layout-Euka-kfv.js"));
3925
4048
  return {
3926
4049
  Component: Layout
3927
4050
  };
@@ -3938,7 +4061,7 @@ const index = {
3938
4061
  async registerTrads({ locales }) {
3939
4062
  const importedTrads = await Promise.all(
3940
4063
  locales.map((locale) => {
3941
- return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => Promise.resolve().then(() => require("./ar-BUUWXIYu.js")), "./translations/ca.json": () => Promise.resolve().then(() => require("./ca-Cmk45QO6.js")), "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-CkJy6B2v.js")), "./translations/de.json": () => Promise.resolve().then(() => require("./de-CCEmbAah.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-uOUIxfcQ.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-EUonQTon.js")), "./translations/eu.json": () => Promise.resolve().then(() => require("./eu-VDH-3ovk.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-B7kGGg3E.js")), "./translations/gu.json": () => Promise.resolve().then(() => require("./gu-BRmF601H.js")), "./translations/hi.json": () => Promise.resolve().then(() => require("./hi-CCJBptSq.js")), "./translations/hu.json": () => Promise.resolve().then(() => require("./hu-sNV_yLYy.js")), "./translations/id.json": () => Promise.resolve().then(() => require("./id-B5Ser98A.js")), "./translations/it.json": () => Promise.resolve().then(() => require("./it-DkBIs7vD.js")), "./translations/ja.json": () => Promise.resolve().then(() => require("./ja-CcFe8diO.js")), "./translations/ko.json": () => Promise.resolve().then(() => require("./ko-woFZPmLk.js")), "./translations/ml.json": () => Promise.resolve().then(() => require("./ml-C2W8N8k1.js")), "./translations/ms.json": () => Promise.resolve().then(() => require("./ms-BuFotyP_.js")), "./translations/nl.json": () => Promise.resolve().then(() => require("./nl-bbEOHChV.js")), "./translations/pl.json": () => Promise.resolve().then(() => require("./pl-uzwG-hk7.js")), "./translations/pt-BR.json": () => Promise.resolve().then(() => require("./pt-BR-BiOz37D9.js")), "./translations/pt.json": () => Promise.resolve().then(() => require("./pt-CeXQuq50.js")), "./translations/ru.json": () => Promise.resolve().then(() => require("./ru-BT3ybNny.js")), "./translations/sa.json": () => Promise.resolve().then(() => require("./sa-CcvkYInH.js")), "./translations/sk.json": () => Promise.resolve().then(() => require("./sk-CvY09Xjv.js")), "./translations/sv.json": () => Promise.resolve().then(() => require("./sv-MYDuzgvT.js")), "./translations/th.json": () => Promise.resolve().then(() => require("./th-D9_GfAjc.js")), "./translations/tr.json": () => Promise.resolve().then(() => require("./tr-D9UH-O_R.js")), "./translations/uk.json": () => Promise.resolve().then(() => require("./uk-C8EiqJY7.js")), "./translations/vi.json": () => Promise.resolve().then(() => require("./vi-CJlYDheJ.js")), "./translations/zh-Hans.json": () => Promise.resolve().then(() => require("./zh-Hans-9kOncHGw.js")), "./translations/zh.json": () => Promise.resolve().then(() => require("./zh-CQQfszqR.js")) }), `./translations/${locale}.json`).then(({ default: data }) => {
4064
+ return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => Promise.resolve().then(() => require("./ar-BUUWXIYu.js")), "./translations/ca.json": () => Promise.resolve().then(() => require("./ca-Cmk45QO6.js")), "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-CkJy6B2v.js")), "./translations/de.json": () => Promise.resolve().then(() => require("./de-CCEmbAah.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-Bm0D0IWz.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-EUonQTon.js")), "./translations/eu.json": () => Promise.resolve().then(() => require("./eu-VDH-3ovk.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-B7kGGg3E.js")), "./translations/gu.json": () => Promise.resolve().then(() => require("./gu-BRmF601H.js")), "./translations/hi.json": () => Promise.resolve().then(() => require("./hi-CCJBptSq.js")), "./translations/hu.json": () => Promise.resolve().then(() => require("./hu-sNV_yLYy.js")), "./translations/id.json": () => Promise.resolve().then(() => require("./id-B5Ser98A.js")), "./translations/it.json": () => Promise.resolve().then(() => require("./it-DkBIs7vD.js")), "./translations/ja.json": () => Promise.resolve().then(() => require("./ja-CcFe8diO.js")), "./translations/ko.json": () => Promise.resolve().then(() => require("./ko-woFZPmLk.js")), "./translations/ml.json": () => Promise.resolve().then(() => require("./ml-C2W8N8k1.js")), "./translations/ms.json": () => Promise.resolve().then(() => require("./ms-BuFotyP_.js")), "./translations/nl.json": () => Promise.resolve().then(() => require("./nl-bbEOHChV.js")), "./translations/pl.json": () => Promise.resolve().then(() => require("./pl-uzwG-hk7.js")), "./translations/pt-BR.json": () => Promise.resolve().then(() => require("./pt-BR-BiOz37D9.js")), "./translations/pt.json": () => Promise.resolve().then(() => require("./pt-CeXQuq50.js")), "./translations/ru.json": () => Promise.resolve().then(() => require("./ru-BT3ybNny.js")), "./translations/sa.json": () => Promise.resolve().then(() => require("./sa-CcvkYInH.js")), "./translations/sk.json": () => Promise.resolve().then(() => require("./sk-CvY09Xjv.js")), "./translations/sv.json": () => Promise.resolve().then(() => require("./sv-MYDuzgvT.js")), "./translations/th.json": () => Promise.resolve().then(() => require("./th-D9_GfAjc.js")), "./translations/tr.json": () => Promise.resolve().then(() => require("./tr-D9UH-O_R.js")), "./translations/uk.json": () => Promise.resolve().then(() => require("./uk-C8EiqJY7.js")), "./translations/vi.json": () => Promise.resolve().then(() => require("./vi-CJlYDheJ.js")), "./translations/zh-Hans.json": () => Promise.resolve().then(() => require("./zh-Hans-9kOncHGw.js")), "./translations/zh.json": () => Promise.resolve().then(() => require("./zh-CQQfszqR.js")) }), `./translations/${locale}.json`).then(({ default: data }) => {
3942
4065
  return {
3943
4066
  data: prefixPluginTranslations(data, PLUGIN_ID),
3944
4067
  locale
@@ -3984,6 +4107,7 @@ exports.getMainField = getMainField;
3984
4107
  exports.getTranslation = getTranslation;
3985
4108
  exports.index = index;
3986
4109
  exports.setInitialData = setInitialData;
4110
+ exports.useContentManagerContext = useContentManagerContext;
3987
4111
  exports.useContentTypeSchema = useContentTypeSchema;
3988
4112
  exports.useDoc = useDoc;
3989
4113
  exports.useDocLayout = useDocLayout;
@@ -3996,4 +4120,4 @@ exports.useGetAllDocumentsQuery = useGetAllDocumentsQuery;
3996
4120
  exports.useGetContentTypeConfigurationQuery = useGetContentTypeConfigurationQuery;
3997
4121
  exports.useGetInitialDataQuery = useGetInitialDataQuery;
3998
4122
  exports.useUpdateContentTypeConfigurationMutation = useUpdateContentTypeConfigurationMutation;
3999
- //# sourceMappingURL=index-C3fJE-1-.js.map
4123
+ //# sourceMappingURL=index-oDq3VO9j.js.map