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