@strapi/content-manager 0.0.0-experimental.312e2942332daff7ae98a4f357d1913a4ae5e1ef → 0.0.0-experimental.3162602be5ecf801e9697f416d1467608d46ad32
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-BfOUhLa9.js → ComponentConfigurationPage-CO977CPh.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-BfOUhLa9.js.map → ComponentConfigurationPage-CO977CPh.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DgDrdk-k.mjs → ComponentConfigurationPage-CQroR9Qk.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DgDrdk-k.mjs.map → ComponentConfigurationPage-CQroR9Qk.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BcXQLYY9.js → EditConfigurationPage-BPgoE-kf.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-BcXQLYY9.js.map → EditConfigurationPage-BPgoE-kf.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CjV1kPAw.mjs → EditConfigurationPage-tVCJ5vWC.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-CjV1kPAw.mjs.map → EditConfigurationPage-tVCJ5vWC.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-s_bjnR0M.mjs → EditViewPage-8mOu02ji.mjs} +15 -5
- package/dist/_chunks/EditViewPage-8mOu02ji.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-BOeuvemd.js → EditViewPage-BMVgUNOX.js} +15 -5
- package/dist/_chunks/EditViewPage-BMVgUNOX.js.map +1 -0
- package/dist/_chunks/{Field-D9nHkdjy.mjs → Field-CJPYzwD7.mjs} +70 -26
- package/dist/_chunks/Field-CJPYzwD7.mjs.map +1 -0
- package/dist/_chunks/{Field-CvfOxLel.js → Field-CdSLKFQk.js} +70 -26
- package/dist/_chunks/Field-CdSLKFQk.js.map +1 -0
- package/dist/_chunks/{Form-G4C35wJ4.mjs → Form-DJOJ-GF1.mjs} +3 -3
- package/dist/_chunks/Form-DJOJ-GF1.mjs.map +1 -0
- package/dist/_chunks/{Form-BKnDhP2B.js → Form-eP5bZwap.js} +3 -3
- package/dist/_chunks/Form-eP5bZwap.js.map +1 -0
- package/dist/_chunks/{History-BIYOzHws.js → History-B-Mrquzu.js} +23 -10
- package/dist/_chunks/History-B-Mrquzu.js.map +1 -0
- package/dist/_chunks/{History-FWwaCNUD.mjs → History-MnQLtk1g.mjs} +24 -11
- package/dist/_chunks/History-MnQLtk1g.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BbOp66T2.mjs → ListConfigurationPage-BcycI8Lw.mjs} +3 -3
- package/dist/_chunks/{ListConfigurationPage-BbOp66T2.mjs.map → ListConfigurationPage-BcycI8Lw.mjs.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-N7prXhOp.js → ListConfigurationPage-C0n4rUzH.js} +3 -3
- package/dist/_chunks/{ListConfigurationPage-N7prXhOp.js.map → ListConfigurationPage-C0n4rUzH.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-DTSW3r3X.mjs → ListViewPage-CRXONXwZ.mjs} +4 -4
- package/dist/_chunks/{ListViewPage-DTSW3r3X.mjs.map → ListViewPage-CRXONXwZ.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-Djc5M_c0.js → ListViewPage-q0SHVPUS.js} +4 -4
- package/dist/_chunks/{ListViewPage-Djc5M_c0.js.map → ListViewPage-q0SHVPUS.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DCX-hEMB.js → NoContentTypePage-Bh3komDV.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DCX-hEMB.js.map → NoContentTypePage-Bh3komDV.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-A-6Pk0le.mjs → NoContentTypePage-ukzFRF3z.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-A-6Pk0le.mjs.map → NoContentTypePage-ukzFRF3z.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-B0vWytDx.mjs → NoPermissionsPage-B4sD7Ble.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-B0vWytDx.mjs.map → NoPermissionsPage-B4sD7Ble.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-PfJfspJV.js → NoPermissionsPage-BGBpj_Y1.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-PfJfspJV.js.map → NoPermissionsPage-BGBpj_Y1.js.map} +1 -1
- package/dist/_chunks/{Relations--9jwQ8HV.js → Relations-B53wYe8g.js} +32 -23
- package/dist/_chunks/Relations-B53wYe8g.js.map +1 -0
- package/dist/_chunks/{Relations-Ccdfw1dU.mjs → Relations-CIexb8gr.mjs} +32 -23
- package/dist/_chunks/Relations-CIexb8gr.mjs.map +1 -0
- package/dist/_chunks/{en-BVzUkPxZ.js → en-Bm0D0IWz.js} +8 -8
- package/dist/_chunks/{en-BVzUkPxZ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-CPTj6CjC.mjs → en-DKV44jRb.mjs} +8 -8
- package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-BwqXeHiv.mjs → index-CJ2vYwuT.mjs} +928 -868
- package/dist/_chunks/index-CJ2vYwuT.mjs.map +1 -0
- package/dist/_chunks/{index-jun-ZqyN.js → index-DbT2sx-Q.js} +926 -866
- package/dist/_chunks/index-DbT2sx-Q.js.map +1 -0
- package/dist/_chunks/{layout-T2xBqmuZ.js → layout-CeBSIkmP.js} +3 -3
- package/dist/_chunks/{layout-T2xBqmuZ.js.map → layout-CeBSIkmP.js.map} +1 -1
- package/dist/_chunks/{layout-BV5oiZQ9.mjs → layout-vzKSrr7p.mjs} +3 -3
- package/dist/_chunks/{layout-BV5oiZQ9.mjs.map → layout-vzKSrr7p.mjs.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-D8jegO_8.js → relations-Cl-6t9iz.js} +2 -2
- package/dist/_chunks/{relations-D8jegO_8.js.map → relations-Cl-6t9iz.js.map} +1 -1
- package/dist/_chunks/{relations-wAeF76DP.mjs → relations-DI0lguF0.mjs} +2 -2
- package/dist/_chunks/{relations-wAeF76DP.mjs.map → relations-DI0lguF0.mjs.map} +1 -1
- 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 +1 -0
- package/dist/server/index.js +27 -14
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +27 -14
- 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/package.json +11 -11
- package/dist/_chunks/EditViewPage-BOeuvemd.js.map +0 -1
- package/dist/_chunks/EditViewPage-s_bjnR0M.mjs.map +0 -1
- package/dist/_chunks/Field-CvfOxLel.js.map +0 -1
- package/dist/_chunks/Field-D9nHkdjy.mjs.map +0 -1
- package/dist/_chunks/Form-BKnDhP2B.js.map +0 -1
- package/dist/_chunks/Form-G4C35wJ4.mjs.map +0 -1
- package/dist/_chunks/History-BIYOzHws.js.map +0 -1
- package/dist/_chunks/History-FWwaCNUD.mjs.map +0 -1
- package/dist/_chunks/Relations--9jwQ8HV.js.map +0 -1
- package/dist/_chunks/Relations-Ccdfw1dU.mjs.map +0 -1
- package/dist/_chunks/index-BwqXeHiv.mjs.map +0 -1
- package/dist/_chunks/index-jun-ZqyN.js.map +0 -1
- package/strapi-server.js +0 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
|
2
2
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
3
|
-
import { useStrapiApp, createContext, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors,
|
3
|
+
import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
|
4
4
|
import * as React from "react";
|
5
5
|
import { lazy } from "react";
|
6
6
|
import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
|
@@ -100,6 +100,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
100
100
|
if (!slug) {
|
101
101
|
throw new Error("Cannot find the slug param in the URL");
|
102
102
|
}
|
103
|
+
const [{ rawQuery }] = useQueryParams();
|
103
104
|
const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
|
104
105
|
const contentTypePermissions = React.useMemo(() => {
|
105
106
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -110,7 +111,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
110
111
|
return { ...acc, [action]: [permission] };
|
111
112
|
}, {});
|
112
113
|
}, [slug, userPermissions]);
|
113
|
-
const { isLoading, allowedActions } = useRBAC(
|
114
|
+
const { isLoading, allowedActions } = useRBAC(
|
115
|
+
contentTypePermissions,
|
116
|
+
permissions ?? void 0,
|
117
|
+
// TODO: useRBAC context should be typed and built differently
|
118
|
+
// We are passing raw query as context to the hook so that it can
|
119
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
120
|
+
rawQuery
|
121
|
+
);
|
114
122
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
115
123
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
116
124
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -461,6 +469,24 @@ const buildValidParams = (query) => {
|
|
461
469
|
const isBaseQueryError = (error) => {
|
462
470
|
return error.name !== void 0;
|
463
471
|
};
|
472
|
+
const arrayValidator = (attribute, options) => ({
|
473
|
+
message: translatedErrors.required,
|
474
|
+
test(value) {
|
475
|
+
if (options.status === "draft") {
|
476
|
+
return true;
|
477
|
+
}
|
478
|
+
if (!attribute.required) {
|
479
|
+
return true;
|
480
|
+
}
|
481
|
+
if (!value) {
|
482
|
+
return false;
|
483
|
+
}
|
484
|
+
if (Array.isArray(value) && value.length === 0) {
|
485
|
+
return false;
|
486
|
+
}
|
487
|
+
return true;
|
488
|
+
}
|
489
|
+
});
|
464
490
|
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
465
491
|
const createModelSchema = (attributes2) => yup.object().shape(
|
466
492
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
@@ -468,6 +494,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
468
494
|
return acc;
|
469
495
|
}
|
470
496
|
const validations = [
|
497
|
+
addNullableValidation,
|
471
498
|
addRequiredValidation,
|
472
499
|
addMinLengthValidation,
|
473
500
|
addMaxLengthValidation,
|
@@ -484,12 +511,12 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
484
511
|
...acc,
|
485
512
|
[name]: transformSchema(
|
486
513
|
yup.array().of(createModelSchema(attributes3).nullable(false))
|
487
|
-
)
|
514
|
+
).test(arrayValidator(attribute, options))
|
488
515
|
};
|
489
516
|
} else {
|
490
517
|
return {
|
491
518
|
...acc,
|
492
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
519
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
493
520
|
};
|
494
521
|
}
|
495
522
|
}
|
@@ -511,7 +538,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
511
538
|
}
|
512
539
|
)
|
513
540
|
)
|
514
|
-
)
|
541
|
+
).test(arrayValidator(attribute, options))
|
515
542
|
};
|
516
543
|
case "relation":
|
517
544
|
return {
|
@@ -523,7 +550,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
523
550
|
} else if (Array.isArray(value)) {
|
524
551
|
return yup.array().of(
|
525
552
|
yup.object().shape({
|
526
|
-
id: yup.
|
553
|
+
id: yup.number().required()
|
527
554
|
})
|
528
555
|
);
|
529
556
|
} else if (typeof value === "object") {
|
@@ -609,17 +636,17 @@ const nullableSchema = (schema) => {
|
|
609
636
|
schema
|
610
637
|
);
|
611
638
|
};
|
639
|
+
const addNullableValidation = () => (schema) => {
|
640
|
+
return nullableSchema(schema);
|
641
|
+
};
|
612
642
|
const addRequiredValidation = (attribute, options) => (schema) => {
|
613
|
-
if (options.status === "draft") {
|
614
|
-
return
|
615
|
-
}
|
616
|
-
if ((attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") && attribute.required && "min" in schema) {
|
617
|
-
return schema.min(1, translatedErrors.required);
|
643
|
+
if (options.status === "draft" || !attribute.required) {
|
644
|
+
return schema;
|
618
645
|
}
|
619
|
-
if (attribute.required &&
|
646
|
+
if (attribute.required && "required" in schema) {
|
620
647
|
return schema.required(translatedErrors.required);
|
621
648
|
}
|
622
|
-
return
|
649
|
+
return schema;
|
623
650
|
};
|
624
651
|
const addMinLengthValidation = (attribute, options) => (schema) => {
|
625
652
|
if (options.status === "draft") {
|
@@ -647,31 +674,12 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
647
674
|
return schema;
|
648
675
|
};
|
649
676
|
const addMinValidation = (attribute, options) => (schema) => {
|
650
|
-
if ("
|
677
|
+
if (options.status === "draft") {
|
678
|
+
return schema;
|
679
|
+
}
|
680
|
+
if ("min" in attribute && "min" in schema) {
|
651
681
|
const min = toInteger(attribute.min);
|
652
|
-
if (
|
653
|
-
if (options.status !== "draft" && !attribute.required && "test" in schema && min) {
|
654
|
-
return schema.test(
|
655
|
-
"custom-min",
|
656
|
-
{
|
657
|
-
...translatedErrors.min,
|
658
|
-
values: {
|
659
|
-
min: attribute.min
|
660
|
-
}
|
661
|
-
},
|
662
|
-
(value) => {
|
663
|
-
if (!value) {
|
664
|
-
return true;
|
665
|
-
}
|
666
|
-
if (Array.isArray(value) && value.length === 0) {
|
667
|
-
return true;
|
668
|
-
}
|
669
|
-
return value.length >= min;
|
670
|
-
}
|
671
|
-
);
|
672
|
-
}
|
673
|
-
}
|
674
|
-
if ("min" in schema && min) {
|
682
|
+
if (min) {
|
675
683
|
return schema.min(min, {
|
676
684
|
...translatedErrors.min,
|
677
685
|
values: {
|
@@ -789,19 +797,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
789
797
|
}, {});
|
790
798
|
return componentsByKey;
|
791
799
|
};
|
792
|
-
const
|
800
|
+
const HOOKS = {
|
801
|
+
/**
|
802
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
803
|
+
* @constant
|
804
|
+
* @type {string}
|
805
|
+
*/
|
806
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
807
|
+
/**
|
808
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
809
|
+
* @constant
|
810
|
+
* @type {string}
|
811
|
+
*/
|
812
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
813
|
+
/**
|
814
|
+
* Hook that allows to mutate the CM's edit view layout
|
815
|
+
* @constant
|
816
|
+
* @type {string}
|
817
|
+
*/
|
818
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
819
|
+
/**
|
820
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
821
|
+
* @constant
|
822
|
+
* @type {string}
|
823
|
+
*/
|
824
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
825
|
+
};
|
826
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
827
|
+
endpoints: (builder) => ({
|
828
|
+
getContentTypeConfiguration: builder.query({
|
829
|
+
query: (uid) => ({
|
830
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
831
|
+
method: "GET"
|
832
|
+
}),
|
833
|
+
transformResponse: (response) => response.data,
|
834
|
+
providesTags: (_result, _error, uid) => [
|
835
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
836
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
837
|
+
]
|
838
|
+
}),
|
839
|
+
getAllContentTypeSettings: builder.query({
|
840
|
+
query: () => "/content-manager/content-types-settings",
|
841
|
+
transformResponse: (response) => response.data,
|
842
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
843
|
+
}),
|
844
|
+
updateContentTypeConfiguration: builder.mutation({
|
845
|
+
query: ({ uid, ...body }) => ({
|
846
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
847
|
+
method: "PUT",
|
848
|
+
data: body
|
849
|
+
}),
|
850
|
+
transformResponse: (response) => response.data,
|
851
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
852
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
853
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
854
|
+
// Is this necessary?
|
855
|
+
{ type: "InitialData" }
|
856
|
+
]
|
857
|
+
})
|
858
|
+
})
|
859
|
+
});
|
860
|
+
const {
|
861
|
+
useGetContentTypeConfigurationQuery,
|
862
|
+
useGetAllContentTypeSettingsQuery,
|
863
|
+
useUpdateContentTypeConfigurationMutation
|
864
|
+
} = contentTypesApi;
|
865
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
866
|
+
const { type } = attribute;
|
867
|
+
if (type === "relation") {
|
868
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
869
|
+
}
|
870
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
871
|
+
};
|
872
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
873
|
+
if (!mainFieldName) {
|
874
|
+
return void 0;
|
875
|
+
}
|
876
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
877
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
878
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
879
|
+
);
|
880
|
+
return {
|
881
|
+
name: mainFieldName,
|
882
|
+
type: mainFieldType ?? "string"
|
883
|
+
};
|
884
|
+
};
|
885
|
+
const DEFAULT_SETTINGS = {
|
886
|
+
bulkable: false,
|
887
|
+
filterable: false,
|
888
|
+
searchable: false,
|
889
|
+
pagination: false,
|
890
|
+
defaultSortBy: "",
|
891
|
+
defaultSortOrder: "asc",
|
892
|
+
mainField: "id",
|
893
|
+
pageSize: 10
|
894
|
+
};
|
895
|
+
const useDocumentLayout = (model) => {
|
896
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
897
|
+
const [{ query }] = useQueryParams();
|
898
|
+
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
793
899
|
const { toggleNotification } = useNotification();
|
794
900
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
901
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
795
902
|
const {
|
796
|
-
|
797
|
-
isLoading:
|
798
|
-
|
799
|
-
|
800
|
-
} =
|
801
|
-
|
802
|
-
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
803
|
-
});
|
804
|
-
const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
|
903
|
+
data,
|
904
|
+
isLoading: isLoadingConfigs,
|
905
|
+
error,
|
906
|
+
isFetching: isFetchingConfigs
|
907
|
+
} = useGetContentTypeConfigurationQuery(model);
|
908
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
805
909
|
React.useEffect(() => {
|
806
910
|
if (error) {
|
807
911
|
toggleNotification({
|
@@ -809,400 +913,653 @@ const useDocument = (args, opts) => {
|
|
809
913
|
message: formatAPIError(error)
|
810
914
|
});
|
811
915
|
}
|
812
|
-
}, [
|
813
|
-
const
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
(document) => {
|
821
|
-
if (!validationSchema) {
|
822
|
-
throw new Error(
|
823
|
-
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
824
|
-
);
|
825
|
-
}
|
826
|
-
try {
|
827
|
-
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
828
|
-
return null;
|
829
|
-
} catch (error2) {
|
830
|
-
if (error2 instanceof ValidationError) {
|
831
|
-
return getYupValidationErrors(error2);
|
832
|
-
}
|
833
|
-
throw error2;
|
834
|
-
}
|
916
|
+
}, [error, formatAPIError, toggleNotification]);
|
917
|
+
const editLayout = React.useMemo(
|
918
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
919
|
+
layout: [],
|
920
|
+
components: {},
|
921
|
+
metadatas: {},
|
922
|
+
options: {},
|
923
|
+
settings: DEFAULT_SETTINGS
|
835
924
|
},
|
836
|
-
[
|
925
|
+
[data, isLoading, schemas, schema, components]
|
926
|
+
);
|
927
|
+
const listLayout = React.useMemo(() => {
|
928
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
929
|
+
layout: [],
|
930
|
+
metadatas: {},
|
931
|
+
options: {},
|
932
|
+
settings: DEFAULT_SETTINGS
|
933
|
+
};
|
934
|
+
}, [data, isLoading, schemas, schema, components]);
|
935
|
+
const { layout: edit } = React.useMemo(
|
936
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
937
|
+
layout: editLayout,
|
938
|
+
query
|
939
|
+
}),
|
940
|
+
[editLayout, query, runHookWaterfall]
|
837
941
|
);
|
838
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
839
942
|
return {
|
840
|
-
|
841
|
-
document: data?.data,
|
842
|
-
meta: data?.meta,
|
943
|
+
error,
|
843
944
|
isLoading,
|
844
|
-
|
845
|
-
|
846
|
-
};
|
847
|
-
};
|
848
|
-
const useDoc = () => {
|
849
|
-
const { id, slug, collectionType, origin } = useParams();
|
850
|
-
const [{ query }] = useQueryParams();
|
851
|
-
const params = React.useMemo(() => buildValidParams(query), [query]);
|
852
|
-
if (!collectionType) {
|
853
|
-
throw new Error("Could not find collectionType in url params");
|
854
|
-
}
|
855
|
-
if (!slug) {
|
856
|
-
throw new Error("Could not find model in url params");
|
857
|
-
}
|
858
|
-
return {
|
859
|
-
collectionType,
|
860
|
-
model: slug,
|
861
|
-
id: origin || id === "create" ? void 0 : id,
|
862
|
-
...useDocument(
|
863
|
-
{ documentId: origin || id, model: slug, collectionType, params },
|
864
|
-
{
|
865
|
-
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
866
|
-
}
|
867
|
-
)
|
945
|
+
edit,
|
946
|
+
list: listLayout
|
868
947
|
};
|
869
948
|
};
|
870
|
-
const
|
871
|
-
|
872
|
-
|
873
|
-
}
|
874
|
-
return Object.keys(trad).reduce((acc, current) => {
|
875
|
-
acc[`${pluginId}.${current}`] = trad[current];
|
876
|
-
return acc;
|
877
|
-
}, {});
|
878
|
-
};
|
879
|
-
const getTranslation = (id) => `content-manager.${id}`;
|
880
|
-
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
881
|
-
id: "notification.error",
|
882
|
-
defaultMessage: "An error occurred, please try again"
|
949
|
+
const useDocLayout = () => {
|
950
|
+
const { model } = useDoc();
|
951
|
+
return useDocumentLayout(model);
|
883
952
|
};
|
884
|
-
const
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
const
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
toggleNotification({
|
904
|
-
type: "danger",
|
905
|
-
message: formatAPIError(res.error)
|
906
|
-
});
|
907
|
-
return { error: res.error };
|
908
|
-
}
|
909
|
-
toggleNotification({
|
910
|
-
type: "success",
|
911
|
-
message: formatMessage({
|
912
|
-
id: getTranslation("success.record.delete"),
|
913
|
-
defaultMessage: "Deleted document"
|
914
|
-
})
|
915
|
-
});
|
916
|
-
trackUsage("didDeleteEntry", trackerProperty);
|
917
|
-
return res.data;
|
918
|
-
} catch (err) {
|
919
|
-
toggleNotification({
|
920
|
-
type: "danger",
|
921
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
922
|
-
});
|
923
|
-
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
924
|
-
throw err;
|
953
|
+
const formatEditLayout = (data, {
|
954
|
+
schemas,
|
955
|
+
schema,
|
956
|
+
components
|
957
|
+
}) => {
|
958
|
+
let currentPanelIndex = 0;
|
959
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
960
|
+
data.contentType.layouts.edit,
|
961
|
+
schema?.attributes,
|
962
|
+
data.contentType.metadatas,
|
963
|
+
{ configurations: data.components, schemas: components },
|
964
|
+
schemas
|
965
|
+
).reduce((panels, row) => {
|
966
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
967
|
+
panels.push([row]);
|
968
|
+
currentPanelIndex += 2;
|
969
|
+
} else {
|
970
|
+
if (!panels[currentPanelIndex]) {
|
971
|
+
panels.push([]);
|
925
972
|
}
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
const
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
});
|
944
|
-
return { error: res.error };
|
973
|
+
panels[currentPanelIndex].push(row);
|
974
|
+
}
|
975
|
+
return panels;
|
976
|
+
}, []);
|
977
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
978
|
+
(acc, [uid, configuration]) => {
|
979
|
+
acc[uid] = {
|
980
|
+
layout: convertEditLayoutToFieldLayouts(
|
981
|
+
configuration.layouts.edit,
|
982
|
+
components[uid].attributes,
|
983
|
+
configuration.metadatas,
|
984
|
+
{ configurations: data.components, schemas: components }
|
985
|
+
),
|
986
|
+
settings: {
|
987
|
+
...configuration.settings,
|
988
|
+
icon: components[uid].info.icon,
|
989
|
+
displayName: components[uid].info.displayName
|
945
990
|
}
|
946
|
-
|
947
|
-
|
948
|
-
title: formatMessage({
|
949
|
-
id: getTranslation("success.records.delete"),
|
950
|
-
defaultMessage: "Successfully deleted."
|
951
|
-
}),
|
952
|
-
message: ""
|
953
|
-
});
|
954
|
-
trackUsage("didBulkDeleteEntries");
|
955
|
-
return res.data;
|
956
|
-
} catch (err) {
|
957
|
-
toggleNotification({
|
958
|
-
type: "danger",
|
959
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
960
|
-
});
|
961
|
-
trackUsage("didNotBulkDeleteEntries");
|
962
|
-
throw err;
|
963
|
-
}
|
991
|
+
};
|
992
|
+
return acc;
|
964
993
|
},
|
965
|
-
|
994
|
+
{}
|
966
995
|
);
|
967
|
-
const
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
model,
|
974
|
-
documentId,
|
975
|
-
params
|
976
|
-
});
|
977
|
-
if ("error" in res) {
|
978
|
-
toggleNotification({
|
979
|
-
type: "danger",
|
980
|
-
message: formatAPIError(res.error)
|
981
|
-
});
|
982
|
-
return { error: res.error };
|
983
|
-
}
|
984
|
-
toggleNotification({
|
985
|
-
type: "success",
|
986
|
-
message: formatMessage({
|
987
|
-
id: "content-manager.success.record.discard",
|
988
|
-
defaultMessage: "Changes discarded"
|
989
|
-
})
|
990
|
-
});
|
991
|
-
return res.data;
|
992
|
-
} catch (err) {
|
993
|
-
toggleNotification({
|
994
|
-
type: "danger",
|
995
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
996
|
-
});
|
997
|
-
throw err;
|
998
|
-
}
|
996
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
997
|
+
(acc, [attribute, metadata]) => {
|
998
|
+
return {
|
999
|
+
...acc,
|
1000
|
+
[attribute]: metadata.edit
|
1001
|
+
};
|
999
1002
|
},
|
1000
|
-
|
1003
|
+
{}
|
1001
1004
|
);
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
model,
|
1010
|
-
documentId,
|
1011
|
-
data,
|
1012
|
-
params
|
1013
|
-
});
|
1014
|
-
if ("error" in res) {
|
1015
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1016
|
-
return { error: res.error };
|
1017
|
-
}
|
1018
|
-
trackUsage("didPublishEntry");
|
1019
|
-
toggleNotification({
|
1020
|
-
type: "success",
|
1021
|
-
message: formatMessage({
|
1022
|
-
id: getTranslation("success.record.publish"),
|
1023
|
-
defaultMessage: "Published document"
|
1024
|
-
})
|
1025
|
-
});
|
1026
|
-
return res.data;
|
1027
|
-
} catch (err) {
|
1028
|
-
toggleNotification({
|
1029
|
-
type: "danger",
|
1030
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1031
|
-
});
|
1032
|
-
throw err;
|
1033
|
-
}
|
1005
|
+
return {
|
1006
|
+
layout: panelledEditAttributes,
|
1007
|
+
components: componentEditAttributes,
|
1008
|
+
metadatas: editMetadatas,
|
1009
|
+
settings: {
|
1010
|
+
...data.contentType.settings,
|
1011
|
+
displayName: schema?.info.displayName
|
1034
1012
|
},
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
return { error: res.error };
|
1049
|
-
}
|
1050
|
-
toggleNotification({
|
1051
|
-
type: "success",
|
1052
|
-
message: formatMessage({
|
1053
|
-
id: getTranslation("success.record.publish"),
|
1054
|
-
defaultMessage: "Published document"
|
1055
|
-
})
|
1056
|
-
});
|
1057
|
-
return res.data;
|
1058
|
-
} catch (err) {
|
1059
|
-
toggleNotification({
|
1060
|
-
type: "danger",
|
1061
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1062
|
-
});
|
1063
|
-
throw err;
|
1013
|
+
options: {
|
1014
|
+
...schema?.options,
|
1015
|
+
...schema?.pluginOptions,
|
1016
|
+
...data.contentType.options
|
1017
|
+
}
|
1018
|
+
};
|
1019
|
+
};
|
1020
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1021
|
+
return rows.map(
|
1022
|
+
(row) => row.map((field) => {
|
1023
|
+
const attribute = attributes[field.name];
|
1024
|
+
if (!attribute) {
|
1025
|
+
return null;
|
1064
1026
|
}
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1027
|
+
const { edit: metadata } = metadatas[field.name];
|
1028
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1029
|
+
return {
|
1030
|
+
attribute,
|
1031
|
+
disabled: !metadata.editable,
|
1032
|
+
hint: metadata.description,
|
1033
|
+
label: metadata.label ?? "",
|
1034
|
+
name: field.name,
|
1035
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1036
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1037
|
+
schemas,
|
1038
|
+
components: components?.schemas ?? {}
|
1039
|
+
}),
|
1040
|
+
placeholder: metadata.placeholder ?? "",
|
1041
|
+
required: attribute.required ?? false,
|
1042
|
+
size: field.size,
|
1043
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1044
|
+
visible: metadata.visible ?? true,
|
1045
|
+
type: attribute.type
|
1046
|
+
};
|
1047
|
+
}).filter((field) => field !== null)
|
1073
1048
|
);
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1049
|
+
};
|
1050
|
+
const formatListLayout = (data, {
|
1051
|
+
schemas,
|
1052
|
+
schema,
|
1053
|
+
components
|
1054
|
+
}) => {
|
1055
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1056
|
+
(acc, [attribute, metadata]) => {
|
1057
|
+
return {
|
1058
|
+
...acc,
|
1059
|
+
[attribute]: metadata.list
|
1060
|
+
};
|
1061
|
+
},
|
1062
|
+
{}
|
1063
|
+
);
|
1064
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1065
|
+
data.contentType.layouts.list,
|
1066
|
+
schema?.attributes,
|
1067
|
+
listMetadatas,
|
1068
|
+
{ configurations: data.components, schemas: components },
|
1069
|
+
schemas
|
1070
|
+
);
|
1071
|
+
return {
|
1072
|
+
layout: listAttributes,
|
1073
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1074
|
+
metadatas: listMetadatas,
|
1075
|
+
options: {
|
1076
|
+
...schema?.options,
|
1077
|
+
...schema?.pluginOptions,
|
1078
|
+
...data.contentType.options
|
1079
|
+
}
|
1080
|
+
};
|
1081
|
+
};
|
1082
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1083
|
+
return columns.map((name) => {
|
1084
|
+
const attribute = attributes[name];
|
1085
|
+
if (!attribute) {
|
1086
|
+
return null;
|
1087
|
+
}
|
1088
|
+
const metadata = metadatas[name];
|
1089
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1090
|
+
return {
|
1091
|
+
attribute,
|
1092
|
+
label: metadata.label ?? "",
|
1093
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1094
|
+
schemas,
|
1095
|
+
components: components?.schemas ?? {}
|
1096
|
+
}),
|
1097
|
+
name,
|
1098
|
+
searchable: metadata.searchable ?? true,
|
1099
|
+
sortable: metadata.sortable ?? true
|
1100
|
+
};
|
1101
|
+
}).filter((field) => field !== null);
|
1102
|
+
};
|
1103
|
+
const useDocument = (args, opts) => {
|
1104
|
+
const { toggleNotification } = useNotification();
|
1105
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1106
|
+
const {
|
1107
|
+
currentData: data,
|
1108
|
+
isLoading: isLoadingDocument,
|
1109
|
+
isFetching: isFetchingDocument,
|
1110
|
+
error
|
1111
|
+
} = useGetDocumentQuery(args, {
|
1112
|
+
...opts,
|
1113
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1114
|
+
});
|
1115
|
+
const {
|
1116
|
+
components,
|
1117
|
+
schema,
|
1118
|
+
schemas,
|
1119
|
+
isLoading: isLoadingSchema
|
1120
|
+
} = useContentTypeSchema(args.model);
|
1121
|
+
React.useEffect(() => {
|
1122
|
+
if (error) {
|
1123
|
+
toggleNotification({
|
1124
|
+
type: "danger",
|
1125
|
+
message: formatAPIError(error)
|
1126
|
+
});
|
1127
|
+
}
|
1128
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1129
|
+
const validationSchema = React.useMemo(() => {
|
1130
|
+
if (!schema) {
|
1131
|
+
return null;
|
1132
|
+
}
|
1133
|
+
return createYupSchema(schema.attributes, components);
|
1134
|
+
}, [schema, components]);
|
1135
|
+
const validate = React.useCallback(
|
1136
|
+
(document) => {
|
1137
|
+
if (!validationSchema) {
|
1138
|
+
throw new Error(
|
1139
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1140
|
+
);
|
1141
|
+
}
|
1142
|
+
try {
|
1143
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1144
|
+
return null;
|
1145
|
+
} catch (error2) {
|
1146
|
+
if (error2 instanceof ValidationError) {
|
1147
|
+
return getYupValidationErrors(error2);
|
1090
1148
|
}
|
1091
|
-
|
1092
|
-
toggleNotification({
|
1093
|
-
type: "success",
|
1094
|
-
message: formatMessage({
|
1095
|
-
id: getTranslation("success.record.save"),
|
1096
|
-
defaultMessage: "Saved document"
|
1097
|
-
})
|
1098
|
-
});
|
1099
|
-
return res.data;
|
1100
|
-
} catch (err) {
|
1101
|
-
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1102
|
-
toggleNotification({
|
1103
|
-
type: "danger",
|
1104
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1105
|
-
});
|
1106
|
-
throw err;
|
1149
|
+
throw error2;
|
1107
1150
|
}
|
1108
1151
|
},
|
1109
|
-
[
|
1152
|
+
[validationSchema]
|
1110
1153
|
);
|
1111
|
-
const
|
1112
|
-
const
|
1113
|
-
|
1154
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1155
|
+
const hasError = !!error;
|
1156
|
+
return {
|
1157
|
+
components,
|
1158
|
+
document: data?.data,
|
1159
|
+
meta: data?.meta,
|
1160
|
+
isLoading,
|
1161
|
+
hasError,
|
1162
|
+
schema,
|
1163
|
+
schemas,
|
1164
|
+
validate
|
1165
|
+
};
|
1166
|
+
};
|
1167
|
+
const useDoc = () => {
|
1168
|
+
const { id, slug, collectionType, origin } = useParams();
|
1169
|
+
const [{ query }] = useQueryParams();
|
1170
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1171
|
+
if (!collectionType) {
|
1172
|
+
throw new Error("Could not find collectionType in url params");
|
1173
|
+
}
|
1174
|
+
if (!slug) {
|
1175
|
+
throw new Error("Could not find model in url params");
|
1176
|
+
}
|
1177
|
+
const document = useDocument(
|
1178
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1179
|
+
{
|
1180
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1181
|
+
}
|
1182
|
+
);
|
1183
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1184
|
+
return {
|
1185
|
+
collectionType,
|
1186
|
+
model: slug,
|
1187
|
+
id: returnId,
|
1188
|
+
...document
|
1189
|
+
};
|
1190
|
+
};
|
1191
|
+
const useContentManagerContext = () => {
|
1192
|
+
const {
|
1193
|
+
collectionType,
|
1194
|
+
model,
|
1195
|
+
id,
|
1196
|
+
components,
|
1197
|
+
isLoading: isLoadingDoc,
|
1198
|
+
schema,
|
1199
|
+
schemas
|
1200
|
+
} = useDoc();
|
1201
|
+
const layout = useDocumentLayout(model);
|
1202
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1203
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1204
|
+
const slug = model;
|
1205
|
+
const isCreatingEntry = id === "create";
|
1206
|
+
useContentTypeSchema();
|
1207
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1208
|
+
const error = layout.error;
|
1209
|
+
return {
|
1210
|
+
error,
|
1211
|
+
isLoading,
|
1212
|
+
// Base metadata
|
1213
|
+
model,
|
1214
|
+
collectionType,
|
1215
|
+
id,
|
1216
|
+
slug,
|
1217
|
+
isCreatingEntry,
|
1218
|
+
isSingleType,
|
1219
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1220
|
+
// All schema infos
|
1221
|
+
components,
|
1222
|
+
contentType: schema,
|
1223
|
+
contentTypes: schemas,
|
1224
|
+
// Form state
|
1225
|
+
form,
|
1226
|
+
// layout infos
|
1227
|
+
layout
|
1228
|
+
};
|
1229
|
+
};
|
1230
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1231
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1232
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1233
|
+
return acc;
|
1234
|
+
}, {});
|
1235
|
+
};
|
1236
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1237
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1238
|
+
id: "notification.error",
|
1239
|
+
defaultMessage: "An error occurred, please try again"
|
1240
|
+
};
|
1241
|
+
const useDocumentActions = () => {
|
1242
|
+
const { toggleNotification } = useNotification();
|
1243
|
+
const { formatMessage } = useIntl();
|
1244
|
+
const { trackUsage } = useTracking();
|
1245
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1246
|
+
const navigate = useNavigate();
|
1247
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1248
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1249
|
+
const _delete = React.useCallback(
|
1250
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1114
1251
|
try {
|
1115
|
-
trackUsage("
|
1116
|
-
const res = await
|
1252
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1253
|
+
const res = await deleteDocument({
|
1117
1254
|
collectionType,
|
1118
1255
|
model,
|
1119
1256
|
documentId,
|
1120
|
-
params
|
1121
|
-
data: {
|
1122
|
-
discardDraft
|
1123
|
-
}
|
1257
|
+
params
|
1124
1258
|
});
|
1125
1259
|
if ("error" in res) {
|
1126
|
-
toggleNotification({
|
1260
|
+
toggleNotification({
|
1261
|
+
type: "danger",
|
1262
|
+
message: formatAPIError(res.error)
|
1263
|
+
});
|
1127
1264
|
return { error: res.error };
|
1128
1265
|
}
|
1129
|
-
trackUsage("didUnpublishEntry");
|
1130
1266
|
toggleNotification({
|
1131
1267
|
type: "success",
|
1132
1268
|
message: formatMessage({
|
1133
|
-
id: getTranslation("success.record.
|
1134
|
-
defaultMessage: "
|
1269
|
+
id: getTranslation("success.record.delete"),
|
1270
|
+
defaultMessage: "Deleted document"
|
1135
1271
|
})
|
1136
1272
|
});
|
1273
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1137
1274
|
return res.data;
|
1138
1275
|
} catch (err) {
|
1139
1276
|
toggleNotification({
|
1140
1277
|
type: "danger",
|
1141
1278
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1142
1279
|
});
|
1280
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1143
1281
|
throw err;
|
1144
1282
|
}
|
1145
1283
|
},
|
1146
|
-
[trackUsage,
|
1284
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1147
1285
|
);
|
1148
|
-
const [
|
1149
|
-
const
|
1286
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1287
|
+
const deleteMany = React.useCallback(
|
1150
1288
|
async ({ model, documentIds, params }) => {
|
1151
1289
|
try {
|
1152
|
-
trackUsage("
|
1153
|
-
const res = await
|
1290
|
+
trackUsage("willBulkDeleteEntries");
|
1291
|
+
const res = await deleteManyDocuments({
|
1154
1292
|
model,
|
1155
1293
|
documentIds,
|
1156
1294
|
params
|
1157
1295
|
});
|
1158
1296
|
if ("error" in res) {
|
1159
|
-
toggleNotification({
|
1297
|
+
toggleNotification({
|
1298
|
+
type: "danger",
|
1299
|
+
message: formatAPIError(res.error)
|
1300
|
+
});
|
1160
1301
|
return { error: res.error };
|
1161
1302
|
}
|
1162
|
-
trackUsage("didBulkUnpublishEntries");
|
1163
1303
|
toggleNotification({
|
1164
1304
|
type: "success",
|
1165
1305
|
title: formatMessage({
|
1166
|
-
id: getTranslation("success.records.
|
1167
|
-
defaultMessage: "Successfully
|
1306
|
+
id: getTranslation("success.records.delete"),
|
1307
|
+
defaultMessage: "Successfully deleted."
|
1168
1308
|
}),
|
1169
1309
|
message: ""
|
1170
1310
|
});
|
1311
|
+
trackUsage("didBulkDeleteEntries");
|
1171
1312
|
return res.data;
|
1172
1313
|
} catch (err) {
|
1173
1314
|
toggleNotification({
|
1174
1315
|
type: "danger",
|
1175
1316
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1176
1317
|
});
|
1177
|
-
trackUsage("
|
1318
|
+
trackUsage("didNotBulkDeleteEntries");
|
1178
1319
|
throw err;
|
1179
1320
|
}
|
1180
1321
|
},
|
1181
|
-
[trackUsage,
|
1322
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1182
1323
|
);
|
1183
|
-
const [
|
1184
|
-
const
|
1185
|
-
async ({ model, params }
|
1324
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1325
|
+
const discard = React.useCallback(
|
1326
|
+
async ({ collectionType, model, documentId, params }) => {
|
1186
1327
|
try {
|
1187
|
-
const res = await
|
1328
|
+
const res = await discardDocument({
|
1329
|
+
collectionType,
|
1188
1330
|
model,
|
1189
|
-
|
1331
|
+
documentId,
|
1190
1332
|
params
|
1191
1333
|
});
|
1192
1334
|
if ("error" in res) {
|
1193
|
-
toggleNotification({
|
1194
|
-
|
1335
|
+
toggleNotification({
|
1336
|
+
type: "danger",
|
1337
|
+
message: formatAPIError(res.error)
|
1338
|
+
});
|
1195
1339
|
return { error: res.error };
|
1196
1340
|
}
|
1197
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1198
1341
|
toggleNotification({
|
1199
1342
|
type: "success",
|
1200
1343
|
message: formatMessage({
|
1201
|
-
id:
|
1202
|
-
defaultMessage: "
|
1344
|
+
id: "content-manager.success.record.discard",
|
1345
|
+
defaultMessage: "Changes discarded"
|
1203
1346
|
})
|
1204
1347
|
});
|
1205
|
-
|
1348
|
+
return res.data;
|
1349
|
+
} catch (err) {
|
1350
|
+
toggleNotification({
|
1351
|
+
type: "danger",
|
1352
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1353
|
+
});
|
1354
|
+
throw err;
|
1355
|
+
}
|
1356
|
+
},
|
1357
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1358
|
+
);
|
1359
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1360
|
+
const publish = React.useCallback(
|
1361
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1362
|
+
try {
|
1363
|
+
trackUsage("willPublishEntry");
|
1364
|
+
const res = await publishDocument({
|
1365
|
+
collectionType,
|
1366
|
+
model,
|
1367
|
+
documentId,
|
1368
|
+
data,
|
1369
|
+
params
|
1370
|
+
});
|
1371
|
+
if ("error" in res) {
|
1372
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1373
|
+
return { error: res.error };
|
1374
|
+
}
|
1375
|
+
trackUsage("didPublishEntry");
|
1376
|
+
toggleNotification({
|
1377
|
+
type: "success",
|
1378
|
+
message: formatMessage({
|
1379
|
+
id: getTranslation("success.record.publish"),
|
1380
|
+
defaultMessage: "Published document"
|
1381
|
+
})
|
1382
|
+
});
|
1383
|
+
return res.data;
|
1384
|
+
} catch (err) {
|
1385
|
+
toggleNotification({
|
1386
|
+
type: "danger",
|
1387
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1388
|
+
});
|
1389
|
+
throw err;
|
1390
|
+
}
|
1391
|
+
},
|
1392
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1393
|
+
);
|
1394
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1395
|
+
const publishMany = React.useCallback(
|
1396
|
+
async ({ model, documentIds, params }) => {
|
1397
|
+
try {
|
1398
|
+
const res = await publishManyDocuments({
|
1399
|
+
model,
|
1400
|
+
documentIds,
|
1401
|
+
params
|
1402
|
+
});
|
1403
|
+
if ("error" in res) {
|
1404
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1405
|
+
return { error: res.error };
|
1406
|
+
}
|
1407
|
+
toggleNotification({
|
1408
|
+
type: "success",
|
1409
|
+
message: formatMessage({
|
1410
|
+
id: getTranslation("success.record.publish"),
|
1411
|
+
defaultMessage: "Published document"
|
1412
|
+
})
|
1413
|
+
});
|
1414
|
+
return res.data;
|
1415
|
+
} catch (err) {
|
1416
|
+
toggleNotification({
|
1417
|
+
type: "danger",
|
1418
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1419
|
+
});
|
1420
|
+
throw err;
|
1421
|
+
}
|
1422
|
+
},
|
1423
|
+
[
|
1424
|
+
// trackUsage,
|
1425
|
+
publishManyDocuments,
|
1426
|
+
toggleNotification,
|
1427
|
+
formatMessage,
|
1428
|
+
formatAPIError
|
1429
|
+
]
|
1430
|
+
);
|
1431
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1432
|
+
const update = React.useCallback(
|
1433
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1434
|
+
try {
|
1435
|
+
trackUsage("willEditEntry", trackerProperty);
|
1436
|
+
const res = await updateDocument({
|
1437
|
+
collectionType,
|
1438
|
+
model,
|
1439
|
+
documentId,
|
1440
|
+
data,
|
1441
|
+
params
|
1442
|
+
});
|
1443
|
+
if ("error" in res) {
|
1444
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1445
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1446
|
+
return { error: res.error };
|
1447
|
+
}
|
1448
|
+
trackUsage("didEditEntry", trackerProperty);
|
1449
|
+
toggleNotification({
|
1450
|
+
type: "success",
|
1451
|
+
message: formatMessage({
|
1452
|
+
id: getTranslation("success.record.save"),
|
1453
|
+
defaultMessage: "Saved document"
|
1454
|
+
})
|
1455
|
+
});
|
1456
|
+
return res.data;
|
1457
|
+
} catch (err) {
|
1458
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1459
|
+
toggleNotification({
|
1460
|
+
type: "danger",
|
1461
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1462
|
+
});
|
1463
|
+
throw err;
|
1464
|
+
}
|
1465
|
+
},
|
1466
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1467
|
+
);
|
1468
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1469
|
+
const unpublish = React.useCallback(
|
1470
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1471
|
+
try {
|
1472
|
+
trackUsage("willUnpublishEntry");
|
1473
|
+
const res = await unpublishDocument({
|
1474
|
+
collectionType,
|
1475
|
+
model,
|
1476
|
+
documentId,
|
1477
|
+
params,
|
1478
|
+
data: {
|
1479
|
+
discardDraft
|
1480
|
+
}
|
1481
|
+
});
|
1482
|
+
if ("error" in res) {
|
1483
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1484
|
+
return { error: res.error };
|
1485
|
+
}
|
1486
|
+
trackUsage("didUnpublishEntry");
|
1487
|
+
toggleNotification({
|
1488
|
+
type: "success",
|
1489
|
+
message: formatMessage({
|
1490
|
+
id: getTranslation("success.record.unpublish"),
|
1491
|
+
defaultMessage: "Unpublished document"
|
1492
|
+
})
|
1493
|
+
});
|
1494
|
+
return res.data;
|
1495
|
+
} catch (err) {
|
1496
|
+
toggleNotification({
|
1497
|
+
type: "danger",
|
1498
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1499
|
+
});
|
1500
|
+
throw err;
|
1501
|
+
}
|
1502
|
+
},
|
1503
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1504
|
+
);
|
1505
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1506
|
+
const unpublishMany = React.useCallback(
|
1507
|
+
async ({ model, documentIds, params }) => {
|
1508
|
+
try {
|
1509
|
+
trackUsage("willBulkUnpublishEntries");
|
1510
|
+
const res = await unpublishManyDocuments({
|
1511
|
+
model,
|
1512
|
+
documentIds,
|
1513
|
+
params
|
1514
|
+
});
|
1515
|
+
if ("error" in res) {
|
1516
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1517
|
+
return { error: res.error };
|
1518
|
+
}
|
1519
|
+
trackUsage("didBulkUnpublishEntries");
|
1520
|
+
toggleNotification({
|
1521
|
+
type: "success",
|
1522
|
+
title: formatMessage({
|
1523
|
+
id: getTranslation("success.records.unpublish"),
|
1524
|
+
defaultMessage: "Successfully unpublished."
|
1525
|
+
}),
|
1526
|
+
message: ""
|
1527
|
+
});
|
1528
|
+
return res.data;
|
1529
|
+
} catch (err) {
|
1530
|
+
toggleNotification({
|
1531
|
+
type: "danger",
|
1532
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1533
|
+
});
|
1534
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1535
|
+
throw err;
|
1536
|
+
}
|
1537
|
+
},
|
1538
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1539
|
+
);
|
1540
|
+
const [createDocument] = useCreateDocumentMutation();
|
1541
|
+
const create = React.useCallback(
|
1542
|
+
async ({ model, params }, data, trackerProperty) => {
|
1543
|
+
try {
|
1544
|
+
const res = await createDocument({
|
1545
|
+
model,
|
1546
|
+
data,
|
1547
|
+
params
|
1548
|
+
});
|
1549
|
+
if ("error" in res) {
|
1550
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1551
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1552
|
+
return { error: res.error };
|
1553
|
+
}
|
1554
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1555
|
+
toggleNotification({
|
1556
|
+
type: "success",
|
1557
|
+
message: formatMessage({
|
1558
|
+
id: getTranslation("success.record.save"),
|
1559
|
+
defaultMessage: "Saved document"
|
1560
|
+
})
|
1561
|
+
});
|
1562
|
+
setCurrentStep("contentManager.success");
|
1206
1563
|
return res.data;
|
1207
1564
|
} catch (err) {
|
1208
1565
|
toggleNotification({
|
@@ -1305,7 +1662,7 @@ const useDocumentActions = () => {
|
|
1305
1662
|
};
|
1306
1663
|
};
|
1307
1664
|
const ProtectedHistoryPage = lazy(
|
1308
|
-
() => import("./History-
|
1665
|
+
() => import("./History-MnQLtk1g.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1309
1666
|
);
|
1310
1667
|
const routes$1 = [
|
1311
1668
|
{
|
@@ -1318,31 +1675,31 @@ const routes$1 = [
|
|
1318
1675
|
}
|
1319
1676
|
];
|
1320
1677
|
const ProtectedEditViewPage = lazy(
|
1321
|
-
() => import("./EditViewPage-
|
1678
|
+
() => import("./EditViewPage-8mOu02ji.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1322
1679
|
);
|
1323
1680
|
const ProtectedListViewPage = lazy(
|
1324
|
-
() => import("./ListViewPage-
|
1681
|
+
() => import("./ListViewPage-CRXONXwZ.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1325
1682
|
);
|
1326
1683
|
const ProtectedListConfiguration = lazy(
|
1327
|
-
() => import("./ListConfigurationPage-
|
1684
|
+
() => import("./ListConfigurationPage-BcycI8Lw.mjs").then((mod) => ({
|
1328
1685
|
default: mod.ProtectedListConfiguration
|
1329
1686
|
}))
|
1330
1687
|
);
|
1331
1688
|
const ProtectedEditConfigurationPage = lazy(
|
1332
|
-
() => import("./EditConfigurationPage-
|
1689
|
+
() => import("./EditConfigurationPage-tVCJ5vWC.mjs").then((mod) => ({
|
1333
1690
|
default: mod.ProtectedEditConfigurationPage
|
1334
1691
|
}))
|
1335
1692
|
);
|
1336
1693
|
const ProtectedComponentConfigurationPage = lazy(
|
1337
|
-
() => import("./ComponentConfigurationPage-
|
1694
|
+
() => import("./ComponentConfigurationPage-CQroR9Qk.mjs").then((mod) => ({
|
1338
1695
|
default: mod.ProtectedComponentConfigurationPage
|
1339
1696
|
}))
|
1340
1697
|
);
|
1341
1698
|
const NoPermissions = lazy(
|
1342
|
-
() => import("./NoPermissionsPage-
|
1699
|
+
() => import("./NoPermissionsPage-B4sD7Ble.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1343
1700
|
);
|
1344
1701
|
const NoContentType = lazy(
|
1345
|
-
() => import("./NoContentTypePage-
|
1702
|
+
() => import("./NoContentTypePage-ukzFRF3z.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1346
1703
|
);
|
1347
1704
|
const CollectionTypePages = () => {
|
1348
1705
|
const { collectionType } = useParams();
|
@@ -1789,7 +2146,9 @@ const PublishAction$1 = ({
|
|
1789
2146
|
const performPublish = async () => {
|
1790
2147
|
setSubmitting(true);
|
1791
2148
|
try {
|
1792
|
-
const { errors } = await validate(
|
2149
|
+
const { errors } = await validate(true, {
|
2150
|
+
status: "published"
|
2151
|
+
});
|
1793
2152
|
if (errors) {
|
1794
2153
|
toggleNotification({
|
1795
2154
|
type: "danger",
|
@@ -1903,18 +2262,18 @@ const UpdateAction = ({
|
|
1903
2262
|
onClick: async () => {
|
1904
2263
|
setSubmitting(true);
|
1905
2264
|
try {
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
})
|
1916
|
-
|
1917
|
-
|
2265
|
+
const { errors } = await validate(true, {
|
2266
|
+
status: "draft"
|
2267
|
+
});
|
2268
|
+
if (errors) {
|
2269
|
+
toggleNotification({
|
2270
|
+
type: "danger",
|
2271
|
+
message: formatMessage({
|
2272
|
+
id: "content-manager.validation.error",
|
2273
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2274
|
+
})
|
2275
|
+
});
|
2276
|
+
return;
|
1918
2277
|
}
|
1919
2278
|
if (isCloning) {
|
1920
2279
|
const res = await clone(
|
@@ -2296,12 +2655,12 @@ const Information = ({ activeTab }) => {
|
|
2296
2655
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2297
2656
|
label: formatMessage({
|
2298
2657
|
id: "content-manager.containers.edit.information.last-published.label",
|
2299
|
-
defaultMessage: "
|
2658
|
+
defaultMessage: "Published"
|
2300
2659
|
}),
|
2301
2660
|
value: formatMessage(
|
2302
2661
|
{
|
2303
2662
|
id: "content-manager.containers.edit.information.last-published.value",
|
2304
|
-
defaultMessage: `
|
2663
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2305
2664
|
},
|
2306
2665
|
{
|
2307
2666
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2314,12 +2673,12 @@ const Information = ({ activeTab }) => {
|
|
2314
2673
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2315
2674
|
label: formatMessage({
|
2316
2675
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2317
|
-
defaultMessage: "
|
2676
|
+
defaultMessage: "Updated"
|
2318
2677
|
}),
|
2319
2678
|
value: formatMessage(
|
2320
2679
|
{
|
2321
2680
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2322
|
-
defaultMessage: `
|
2681
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2323
2682
|
},
|
2324
2683
|
{
|
2325
2684
|
time: /* @__PURE__ */ jsx(
|
@@ -2337,12 +2696,12 @@ const Information = ({ activeTab }) => {
|
|
2337
2696
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2338
2697
|
label: formatMessage({
|
2339
2698
|
id: "content-manager.containers.edit.information.document.label",
|
2340
|
-
defaultMessage: "
|
2699
|
+
defaultMessage: "Created"
|
2341
2700
|
}),
|
2342
2701
|
value: formatMessage(
|
2343
2702
|
{
|
2344
2703
|
id: "content-manager.containers.edit.information.document.value",
|
2345
|
-
defaultMessage: `
|
2704
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2346
2705
|
},
|
2347
2706
|
{
|
2348
2707
|
time: /* @__PURE__ */ jsx(
|
@@ -2400,10 +2759,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2400
2759
|
SingleSelect,
|
2401
2760
|
{
|
2402
2761
|
size: "S",
|
2403
|
-
disabled: action.disabled,
|
2404
|
-
"aria-label": action.label,
|
2405
2762
|
onChange: action.onSelect,
|
2406
|
-
|
2763
|
+
"aria-label": action.label,
|
2764
|
+
...action,
|
2407
2765
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2408
2766
|
},
|
2409
2767
|
action.id
|
@@ -2467,490 +2825,191 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
|
|
2467
2825
|
position: "header"
|
2468
2826
|
};
|
2469
2827
|
};
|
2470
|
-
ConfigureTheViewAction.type = "configure-the-view";
|
2471
|
-
const EditTheModelAction = ({ model }) => {
|
2472
|
-
const navigate = useNavigate();
|
2473
|
-
const { formatMessage } = useIntl();
|
2474
|
-
return {
|
2475
|
-
label: formatMessage({
|
2476
|
-
id: "content-manager.link-to-ctb",
|
2477
|
-
defaultMessage: "Edit the model"
|
2478
|
-
}),
|
2479
|
-
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2480
|
-
onClick: () => {
|
2481
|
-
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2482
|
-
},
|
2483
|
-
position: "header"
|
2484
|
-
};
|
2485
|
-
};
|
2486
|
-
EditTheModelAction.type = "edit-the-model";
|
2487
|
-
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2488
|
-
const navigate = useNavigate();
|
2489
|
-
const { formatMessage } = useIntl();
|
2490
|
-
const listViewPathMatch = useMatch(LIST_PATH);
|
2491
|
-
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2492
|
-
const { delete: deleteAction } = useDocumentActions();
|
2493
|
-
const { toggleNotification } = useNotification();
|
2494
|
-
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2495
|
-
return {
|
2496
|
-
disabled: !canDelete || !document,
|
2497
|
-
label: formatMessage({
|
2498
|
-
id: "content-manager.actions.delete.label",
|
2499
|
-
defaultMessage: "Delete document"
|
2500
|
-
}),
|
2501
|
-
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2502
|
-
dialog: {
|
2503
|
-
type: "dialog",
|
2504
|
-
title: formatMessage({
|
2505
|
-
id: "app.components.ConfirmDialog.title",
|
2506
|
-
defaultMessage: "Confirmation"
|
2507
|
-
}),
|
2508
|
-
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2509
|
-
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2510
|
-
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2511
|
-
id: "content-manager.actions.delete.dialog.body",
|
2512
|
-
defaultMessage: "Are you sure?"
|
2513
|
-
}) })
|
2514
|
-
] }),
|
2515
|
-
onConfirm: async () => {
|
2516
|
-
if (!listViewPathMatch) {
|
2517
|
-
setSubmitting(true);
|
2518
|
-
}
|
2519
|
-
try {
|
2520
|
-
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2521
|
-
console.error(
|
2522
|
-
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2523
|
-
);
|
2524
|
-
toggleNotification({
|
2525
|
-
message: formatMessage({
|
2526
|
-
id: "content-manager.actions.delete.error",
|
2527
|
-
defaultMessage: "An error occurred while trying to delete the document."
|
2528
|
-
}),
|
2529
|
-
type: "danger"
|
2530
|
-
});
|
2531
|
-
return;
|
2532
|
-
}
|
2533
|
-
const res = await deleteAction({
|
2534
|
-
documentId,
|
2535
|
-
model,
|
2536
|
-
collectionType,
|
2537
|
-
params: {
|
2538
|
-
locale: "*"
|
2539
|
-
}
|
2540
|
-
});
|
2541
|
-
if (!("error" in res)) {
|
2542
|
-
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2543
|
-
}
|
2544
|
-
} finally {
|
2545
|
-
if (!listViewPathMatch) {
|
2546
|
-
setSubmitting(false);
|
2547
|
-
}
|
2548
|
-
}
|
2549
|
-
}
|
2550
|
-
},
|
2551
|
-
variant: "danger",
|
2552
|
-
position: ["header", "table-row"]
|
2553
|
-
};
|
2554
|
-
};
|
2555
|
-
DeleteAction$1.type = "delete";
|
2556
|
-
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2557
|
-
const Panels = () => {
|
2558
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
2559
|
-
const [
|
2560
|
-
{
|
2561
|
-
query: { status }
|
2562
|
-
}
|
2563
|
-
] = useQueryParams({
|
2564
|
-
status: "draft"
|
2565
|
-
});
|
2566
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2567
|
-
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2568
|
-
const props = {
|
2569
|
-
activeTab: status,
|
2570
|
-
model,
|
2571
|
-
documentId: id,
|
2572
|
-
document: isCloning ? void 0 : document,
|
2573
|
-
meta: isCloning ? void 0 : meta,
|
2574
|
-
collectionType
|
2575
|
-
};
|
2576
|
-
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2577
|
-
DescriptionComponentRenderer,
|
2578
|
-
{
|
2579
|
-
props,
|
2580
|
-
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2581
|
-
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2582
|
-
}
|
2583
|
-
) });
|
2584
|
-
};
|
2585
|
-
const ActionsPanel = () => {
|
2586
|
-
const { formatMessage } = useIntl();
|
2587
|
-
return {
|
2588
|
-
title: formatMessage({
|
2589
|
-
id: "content-manager.containers.edit.panels.default.title",
|
2590
|
-
defaultMessage: "Entry"
|
2591
|
-
}),
|
2592
|
-
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2593
|
-
};
|
2594
|
-
};
|
2595
|
-
ActionsPanel.type = "actions";
|
2596
|
-
const ActionsPanelContent = () => {
|
2597
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
2598
|
-
const [
|
2599
|
-
{
|
2600
|
-
query: { status = "draft" }
|
2601
|
-
}
|
2602
|
-
] = useQueryParams();
|
2603
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2604
|
-
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2605
|
-
const props = {
|
2606
|
-
activeTab: status,
|
2607
|
-
model,
|
2608
|
-
documentId: id,
|
2609
|
-
document: isCloning ? void 0 : document,
|
2610
|
-
meta: isCloning ? void 0 : meta,
|
2611
|
-
collectionType
|
2612
|
-
};
|
2613
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2614
|
-
/* @__PURE__ */ jsx(
|
2615
|
-
DescriptionComponentRenderer,
|
2616
|
-
{
|
2617
|
-
props,
|
2618
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2619
|
-
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2620
|
-
}
|
2621
|
-
),
|
2622
|
-
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2623
|
-
] });
|
2624
|
-
};
|
2625
|
-
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2626
|
-
return /* @__PURE__ */ jsxs(
|
2627
|
-
Flex,
|
2628
|
-
{
|
2629
|
-
ref,
|
2630
|
-
tag: "aside",
|
2631
|
-
"aria-labelledby": "additional-information",
|
2632
|
-
background: "neutral0",
|
2633
|
-
borderColor: "neutral150",
|
2634
|
-
hasRadius: true,
|
2635
|
-
paddingBottom: 4,
|
2636
|
-
paddingLeft: 4,
|
2637
|
-
paddingRight: 4,
|
2638
|
-
paddingTop: 4,
|
2639
|
-
shadow: "tableShadow",
|
2640
|
-
gap: 3,
|
2641
|
-
direction: "column",
|
2642
|
-
justifyContent: "stretch",
|
2643
|
-
alignItems: "flex-start",
|
2644
|
-
children: [
|
2645
|
-
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2646
|
-
children
|
2647
|
-
]
|
2648
|
-
}
|
2649
|
-
);
|
2650
|
-
});
|
2651
|
-
const HOOKS = {
|
2652
|
-
/**
|
2653
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2654
|
-
* @constant
|
2655
|
-
* @type {string}
|
2656
|
-
*/
|
2657
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2658
|
-
/**
|
2659
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2660
|
-
* @constant
|
2661
|
-
* @type {string}
|
2662
|
-
*/
|
2663
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2664
|
-
/**
|
2665
|
-
* Hook that allows to mutate the CM's edit view layout
|
2666
|
-
* @constant
|
2667
|
-
* @type {string}
|
2668
|
-
*/
|
2669
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2670
|
-
/**
|
2671
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2672
|
-
* @constant
|
2673
|
-
* @type {string}
|
2674
|
-
*/
|
2675
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2676
|
-
};
|
2677
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2678
|
-
endpoints: (builder) => ({
|
2679
|
-
getContentTypeConfiguration: builder.query({
|
2680
|
-
query: (uid) => ({
|
2681
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2682
|
-
method: "GET"
|
2683
|
-
}),
|
2684
|
-
transformResponse: (response) => response.data,
|
2685
|
-
providesTags: (_result, _error, uid) => [
|
2686
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2687
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
2688
|
-
]
|
2689
|
-
}),
|
2690
|
-
getAllContentTypeSettings: builder.query({
|
2691
|
-
query: () => "/content-manager/content-types-settings",
|
2692
|
-
transformResponse: (response) => response.data,
|
2693
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
2694
|
-
}),
|
2695
|
-
updateContentTypeConfiguration: builder.mutation({
|
2696
|
-
query: ({ uid, ...body }) => ({
|
2697
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2698
|
-
method: "PUT",
|
2699
|
-
data: body
|
2700
|
-
}),
|
2701
|
-
transformResponse: (response) => response.data,
|
2702
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
2703
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2704
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
2705
|
-
// Is this necessary?
|
2706
|
-
{ type: "InitialData" }
|
2707
|
-
]
|
2708
|
-
})
|
2709
|
-
})
|
2710
|
-
});
|
2711
|
-
const {
|
2712
|
-
useGetContentTypeConfigurationQuery,
|
2713
|
-
useGetAllContentTypeSettingsQuery,
|
2714
|
-
useUpdateContentTypeConfigurationMutation
|
2715
|
-
} = contentTypesApi;
|
2716
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
2717
|
-
const { type } = attribute;
|
2718
|
-
if (type === "relation") {
|
2719
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
2720
|
-
}
|
2721
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
2722
|
-
};
|
2723
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
2724
|
-
if (!mainFieldName) {
|
2725
|
-
return void 0;
|
2726
|
-
}
|
2727
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
2728
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
2729
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
2730
|
-
);
|
2731
|
-
return {
|
2732
|
-
name: mainFieldName,
|
2733
|
-
type: mainFieldType ?? "string"
|
2734
|
-
};
|
2735
|
-
};
|
2736
|
-
const DEFAULT_SETTINGS = {
|
2737
|
-
bulkable: false,
|
2738
|
-
filterable: false,
|
2739
|
-
searchable: false,
|
2740
|
-
pagination: false,
|
2741
|
-
defaultSortBy: "",
|
2742
|
-
defaultSortOrder: "asc",
|
2743
|
-
mainField: "id",
|
2744
|
-
pageSize: 10
|
2745
|
-
};
|
2746
|
-
const useDocumentLayout = (model) => {
|
2747
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
2748
|
-
const [{ query }] = useQueryParams();
|
2749
|
-
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
2750
|
-
const { toggleNotification } = useNotification();
|
2751
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
2752
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
2753
|
-
const {
|
2754
|
-
data,
|
2755
|
-
isLoading: isLoadingConfigs,
|
2756
|
-
error,
|
2757
|
-
isFetching: isFetchingConfigs
|
2758
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2759
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2760
|
-
React.useEffect(() => {
|
2761
|
-
if (error) {
|
2762
|
-
toggleNotification({
|
2763
|
-
type: "danger",
|
2764
|
-
message: formatAPIError(error)
|
2765
|
-
});
|
2766
|
-
}
|
2767
|
-
}, [error, formatAPIError, toggleNotification]);
|
2768
|
-
const editLayout = React.useMemo(
|
2769
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2770
|
-
layout: [],
|
2771
|
-
components: {},
|
2772
|
-
metadatas: {},
|
2773
|
-
options: {},
|
2774
|
-
settings: DEFAULT_SETTINGS
|
2775
|
-
},
|
2776
|
-
[data, isLoading, schemas, schema, components]
|
2777
|
-
);
|
2778
|
-
const listLayout = React.useMemo(() => {
|
2779
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2780
|
-
layout: [],
|
2781
|
-
metadatas: {},
|
2782
|
-
options: {},
|
2783
|
-
settings: DEFAULT_SETTINGS
|
2784
|
-
};
|
2785
|
-
}, [data, isLoading, schemas, schema, components]);
|
2786
|
-
const { layout: edit } = React.useMemo(
|
2787
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2788
|
-
layout: editLayout,
|
2789
|
-
query
|
2790
|
-
}),
|
2791
|
-
[editLayout, query, runHookWaterfall]
|
2792
|
-
);
|
2793
|
-
return {
|
2794
|
-
error,
|
2795
|
-
isLoading,
|
2796
|
-
edit,
|
2797
|
-
list: listLayout
|
2798
|
-
};
|
2799
|
-
};
|
2800
|
-
const useDocLayout = () => {
|
2801
|
-
const { model } = useDoc();
|
2802
|
-
return useDocumentLayout(model);
|
2803
|
-
};
|
2804
|
-
const formatEditLayout = (data, {
|
2805
|
-
schemas,
|
2806
|
-
schema,
|
2807
|
-
components
|
2808
|
-
}) => {
|
2809
|
-
let currentPanelIndex = 0;
|
2810
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
2811
|
-
data.contentType.layouts.edit,
|
2812
|
-
schema?.attributes,
|
2813
|
-
data.contentType.metadatas,
|
2814
|
-
{ configurations: data.components, schemas: components },
|
2815
|
-
schemas
|
2816
|
-
).reduce((panels, row) => {
|
2817
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2818
|
-
panels.push([row]);
|
2819
|
-
currentPanelIndex += 2;
|
2820
|
-
} else {
|
2821
|
-
if (!panels[currentPanelIndex]) {
|
2822
|
-
panels.push([]);
|
2823
|
-
}
|
2824
|
-
panels[currentPanelIndex].push(row);
|
2825
|
-
}
|
2826
|
-
return panels;
|
2827
|
-
}, []);
|
2828
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
2829
|
-
(acc, [uid, configuration]) => {
|
2830
|
-
acc[uid] = {
|
2831
|
-
layout: convertEditLayoutToFieldLayouts(
|
2832
|
-
configuration.layouts.edit,
|
2833
|
-
components[uid].attributes,
|
2834
|
-
configuration.metadatas,
|
2835
|
-
{ configurations: data.components, schemas: components }
|
2836
|
-
),
|
2837
|
-
settings: {
|
2838
|
-
...configuration.settings,
|
2839
|
-
icon: components[uid].info.icon,
|
2840
|
-
displayName: components[uid].info.displayName
|
2841
|
-
}
|
2842
|
-
};
|
2843
|
-
return acc;
|
2844
|
-
},
|
2845
|
-
{}
|
2846
|
-
);
|
2847
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2848
|
-
(acc, [attribute, metadata]) => {
|
2849
|
-
return {
|
2850
|
-
...acc,
|
2851
|
-
[attribute]: metadata.edit
|
2852
|
-
};
|
2853
|
-
},
|
2854
|
-
{}
|
2855
|
-
);
|
2828
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2829
|
+
const EditTheModelAction = ({ model }) => {
|
2830
|
+
const navigate = useNavigate();
|
2831
|
+
const { formatMessage } = useIntl();
|
2856
2832
|
return {
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2833
|
+
label: formatMessage({
|
2834
|
+
id: "content-manager.link-to-ctb",
|
2835
|
+
defaultMessage: "Edit the model"
|
2836
|
+
}),
|
2837
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2838
|
+
onClick: () => {
|
2839
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2863
2840
|
},
|
2864
|
-
|
2865
|
-
...schema?.options,
|
2866
|
-
...schema?.pluginOptions,
|
2867
|
-
...data.contentType.options
|
2868
|
-
}
|
2841
|
+
position: "header"
|
2869
2842
|
};
|
2870
2843
|
};
|
2871
|
-
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2844
|
+
EditTheModelAction.type = "edit-the-model";
|
2845
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2846
|
+
const navigate = useNavigate();
|
2847
|
+
const { formatMessage } = useIntl();
|
2848
|
+
const listViewPathMatch = useMatch(LIST_PATH);
|
2849
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2850
|
+
const { delete: deleteAction } = useDocumentActions();
|
2851
|
+
const { toggleNotification } = useNotification();
|
2852
|
+
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2853
|
+
const isLocalized = document?.locale != null;
|
2854
|
+
return {
|
2855
|
+
disabled: !canDelete || !document,
|
2856
|
+
label: formatMessage(
|
2857
|
+
{
|
2858
|
+
id: "content-manager.actions.delete.label",
|
2859
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2860
|
+
},
|
2861
|
+
{ isLocalized }
|
2862
|
+
),
|
2863
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2864
|
+
dialog: {
|
2865
|
+
type: "dialog",
|
2866
|
+
title: formatMessage({
|
2867
|
+
id: "app.components.ConfirmDialog.title",
|
2868
|
+
defaultMessage: "Confirmation"
|
2869
|
+
}),
|
2870
|
+
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2871
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2872
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2873
|
+
id: "content-manager.actions.delete.dialog.body",
|
2874
|
+
defaultMessage: "Are you sure?"
|
2875
|
+
}) })
|
2876
|
+
] }),
|
2877
|
+
onConfirm: async () => {
|
2878
|
+
if (!listViewPathMatch) {
|
2879
|
+
setSubmitting(true);
|
2880
|
+
}
|
2881
|
+
try {
|
2882
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2883
|
+
console.error(
|
2884
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2885
|
+
);
|
2886
|
+
toggleNotification({
|
2887
|
+
message: formatMessage({
|
2888
|
+
id: "content-manager.actions.delete.error",
|
2889
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2890
|
+
}),
|
2891
|
+
type: "danger"
|
2892
|
+
});
|
2893
|
+
return;
|
2894
|
+
}
|
2895
|
+
const res = await deleteAction({
|
2896
|
+
documentId,
|
2897
|
+
model,
|
2898
|
+
collectionType,
|
2899
|
+
params: {
|
2900
|
+
locale: "*"
|
2901
|
+
}
|
2902
|
+
});
|
2903
|
+
if (!("error" in res)) {
|
2904
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2905
|
+
}
|
2906
|
+
} finally {
|
2907
|
+
if (!listViewPathMatch) {
|
2908
|
+
setSubmitting(false);
|
2909
|
+
}
|
2910
|
+
}
|
2877
2911
|
}
|
2878
|
-
const { edit: metadata } = metadatas[field.name];
|
2879
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2880
|
-
return {
|
2881
|
-
attribute,
|
2882
|
-
disabled: !metadata.editable,
|
2883
|
-
hint: metadata.description,
|
2884
|
-
label: metadata.label ?? "",
|
2885
|
-
name: field.name,
|
2886
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2887
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2888
|
-
schemas,
|
2889
|
-
components: components?.schemas ?? {}
|
2890
|
-
}),
|
2891
|
-
placeholder: metadata.placeholder ?? "",
|
2892
|
-
required: attribute.required ?? false,
|
2893
|
-
size: field.size,
|
2894
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2895
|
-
visible: metadata.visible ?? true,
|
2896
|
-
type: attribute.type
|
2897
|
-
};
|
2898
|
-
}).filter((field) => field !== null)
|
2899
|
-
);
|
2900
|
-
};
|
2901
|
-
const formatListLayout = (data, {
|
2902
|
-
schemas,
|
2903
|
-
schema,
|
2904
|
-
components
|
2905
|
-
}) => {
|
2906
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2907
|
-
(acc, [attribute, metadata]) => {
|
2908
|
-
return {
|
2909
|
-
...acc,
|
2910
|
-
[attribute]: metadata.list
|
2911
|
-
};
|
2912
2912
|
},
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2913
|
+
variant: "danger",
|
2914
|
+
position: ["header", "table-row"]
|
2915
|
+
};
|
2916
|
+
};
|
2917
|
+
DeleteAction$1.type = "delete";
|
2918
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2919
|
+
const Panels = () => {
|
2920
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2921
|
+
const [
|
2922
|
+
{
|
2923
|
+
query: { status }
|
2924
|
+
}
|
2925
|
+
] = useQueryParams({
|
2926
|
+
status: "draft"
|
2927
|
+
});
|
2928
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2929
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2930
|
+
const props = {
|
2931
|
+
activeTab: status,
|
2932
|
+
model,
|
2933
|
+
documentId: id,
|
2934
|
+
document: isCloning ? void 0 : document,
|
2935
|
+
meta: isCloning ? void 0 : meta,
|
2936
|
+
collectionType
|
2937
|
+
};
|
2938
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2939
|
+
DescriptionComponentRenderer,
|
2940
|
+
{
|
2941
|
+
props,
|
2942
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2943
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2930
2944
|
}
|
2945
|
+
) });
|
2946
|
+
};
|
2947
|
+
const ActionsPanel = () => {
|
2948
|
+
const { formatMessage } = useIntl();
|
2949
|
+
return {
|
2950
|
+
title: formatMessage({
|
2951
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2952
|
+
defaultMessage: "Entry"
|
2953
|
+
}),
|
2954
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2931
2955
|
};
|
2932
2956
|
};
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2957
|
+
ActionsPanel.type = "actions";
|
2958
|
+
const ActionsPanelContent = () => {
|
2959
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2960
|
+
const [
|
2961
|
+
{
|
2962
|
+
query: { status = "draft" }
|
2938
2963
|
}
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2951
|
-
|
2952
|
-
|
2964
|
+
] = useQueryParams();
|
2965
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2966
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2967
|
+
const props = {
|
2968
|
+
activeTab: status,
|
2969
|
+
model,
|
2970
|
+
documentId: id,
|
2971
|
+
document: isCloning ? void 0 : document,
|
2972
|
+
meta: isCloning ? void 0 : meta,
|
2973
|
+
collectionType
|
2974
|
+
};
|
2975
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2976
|
+
/* @__PURE__ */ jsx(
|
2977
|
+
DescriptionComponentRenderer,
|
2978
|
+
{
|
2979
|
+
props,
|
2980
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2981
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2982
|
+
}
|
2983
|
+
),
|
2984
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2985
|
+
] });
|
2953
2986
|
};
|
2987
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2988
|
+
return /* @__PURE__ */ jsxs(
|
2989
|
+
Flex,
|
2990
|
+
{
|
2991
|
+
ref,
|
2992
|
+
tag: "aside",
|
2993
|
+
"aria-labelledby": "additional-information",
|
2994
|
+
background: "neutral0",
|
2995
|
+
borderColor: "neutral150",
|
2996
|
+
hasRadius: true,
|
2997
|
+
paddingBottom: 4,
|
2998
|
+
paddingLeft: 4,
|
2999
|
+
paddingRight: 4,
|
3000
|
+
paddingTop: 4,
|
3001
|
+
shadow: "tableShadow",
|
3002
|
+
gap: 3,
|
3003
|
+
direction: "column",
|
3004
|
+
justifyContent: "stretch",
|
3005
|
+
alignItems: "flex-start",
|
3006
|
+
children: [
|
3007
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3008
|
+
children
|
3009
|
+
]
|
3010
|
+
}
|
3011
|
+
);
|
3012
|
+
});
|
2954
3013
|
const ConfirmBulkActionDialog = ({
|
2955
3014
|
onToggleDialog,
|
2956
3015
|
isOpen = false,
|
@@ -3947,7 +4006,7 @@ const index = {
|
|
3947
4006
|
app.router.addRoute({
|
3948
4007
|
path: "content-manager/*",
|
3949
4008
|
lazy: async () => {
|
3950
|
-
const { Layout } = await import("./layout-
|
4009
|
+
const { Layout } = await import("./layout-vzKSrr7p.mjs");
|
3951
4010
|
return {
|
3952
4011
|
Component: Layout
|
3953
4012
|
};
|
@@ -3964,7 +4023,7 @@ const index = {
|
|
3964
4023
|
async registerTrads({ locales }) {
|
3965
4024
|
const importedTrads = await Promise.all(
|
3966
4025
|
locales.map((locale) => {
|
3967
|
-
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-
|
4026
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-DKV44jRb.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
|
3968
4027
|
return {
|
3969
4028
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3970
4029
|
locale
|
@@ -3992,7 +4051,8 @@ export {
|
|
3992
4051
|
InjectionZone as I,
|
3993
4052
|
useDocument as J,
|
3994
4053
|
index as K,
|
3995
|
-
|
4054
|
+
useContentManagerContext as L,
|
4055
|
+
useDocumentActions as M,
|
3996
4056
|
Panels as P,
|
3997
4057
|
RelativeTime as R,
|
3998
4058
|
SINGLE_TYPES as S,
|
@@ -4024,4 +4084,4 @@ export {
|
|
4024
4084
|
capitalise as y,
|
4025
4085
|
useUpdateContentTypeConfigurationMutation as z
|
4026
4086
|
};
|
4027
|
-
//# sourceMappingURL=index-
|
4087
|
+
//# sourceMappingURL=index-CJ2vYwuT.mjs.map
|