@strapi/content-manager 0.0.0-experimental.afa3b513b8f95459043f33fb94f4bac03af1474f → 0.0.0-experimental.b9dd0757c8a7db6ee1063edc33424319784ae3a6
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-G4EIirP8.js → ComponentConfigurationPage-B-r3vk8T.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-G4EIirP8.js.map → ComponentConfigurationPage-B-r3vk8T.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CnL10QYC.mjs → ComponentConfigurationPage-Dp3ZXzP_.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CnL10QYC.mjs.map → ComponentConfigurationPage-Dp3ZXzP_.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-B2AA1kVF.js → EditConfigurationPage-Cs-8XG8_.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-B2AA1kVF.js.map → EditConfigurationPage-Cs-8XG8_.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-I2kKh9dx.mjs → EditConfigurationPage-qFNC9RPm.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-I2kKh9dx.mjs.map → EditConfigurationPage-qFNC9RPm.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CHgoNwlc.js → EditViewPage-CqMtsGgl.js} +15 -5
- package/dist/_chunks/EditViewPage-CqMtsGgl.js.map +1 -0
- package/dist/_chunks/{EditViewPage-zFjJK0s8.mjs → EditViewPage-noMD5CfK.mjs} +15 -5
- package/dist/_chunks/EditViewPage-noMD5CfK.mjs.map +1 -0
- package/dist/_chunks/{Field-DPAzUS1M.mjs → Field-BMxOXDMC.mjs} +69 -25
- package/dist/_chunks/Field-BMxOXDMC.mjs.map +1 -0
- package/dist/_chunks/{Field-9DePZh-0.js → Field-BWObiIQ3.js} +69 -25
- package/dist/_chunks/Field-BWObiIQ3.js.map +1 -0
- package/dist/_chunks/{Form-CEkENbkF.mjs → Form-BTT42lt4.mjs} +3 -3
- package/dist/_chunks/Form-BTT42lt4.mjs.map +1 -0
- package/dist/_chunks/{Form-DPm-KZ1A.js → Form-CZ9hswVy.js} +3 -3
- package/dist/_chunks/Form-CZ9hswVy.js.map +1 -0
- package/dist/_chunks/{History-utls71em.mjs → History-CQf4ssdU.mjs} +24 -11
- package/dist/_chunks/History-CQf4ssdU.mjs.map +1 -0
- package/dist/_chunks/{History-DXSbTWez.js → History-DdZTjeEU.js} +23 -10
- package/dist/_chunks/History-DdZTjeEU.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-D5C7ACZ_.js → ListConfigurationPage-C-8hLgKb.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-D5C7ACZ_.js.map → ListConfigurationPage-C-8hLgKb.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-CuMXWWqb.mjs → ListConfigurationPage-DXy-IKAk.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-CuMXWWqb.mjs.map → ListConfigurationPage-DXy-IKAk.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-DfuwH1tt.js → ListViewPage-CPbs8bml.js} +4 -4
- package/dist/_chunks/{ListViewPage-DfuwH1tt.js.map → ListViewPage-CPbs8bml.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-CdKd-PS_.mjs → ListViewPage-DAvl-VG5.mjs} +4 -4
- package/dist/_chunks/{ListViewPage-CdKd-PS_.mjs.map → ListViewPage-DAvl-VG5.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BIxlkWWi.js → NoContentTypePage-Bz_9RdLr.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BIxlkWWi.js.map → NoContentTypePage-Bz_9RdLr.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DkToTT7u.mjs → NoContentTypePage-D-DbFSFh.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DkToTT7u.mjs.map → NoContentTypePage-D-DbFSFh.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DlWi4BAH.mjs → NoPermissionsPage-BzSfwl62.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DlWi4BAH.mjs.map → NoPermissionsPage-BzSfwl62.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Bu4GWYb-.js → NoPermissionsPage-De5GsnjI.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Bu4GWYb-.js.map → NoPermissionsPage-De5GsnjI.js.map} +1 -1
- package/dist/_chunks/{Relations-QP5yn9_z.mjs → Relations-CsjdyIXg.mjs} +32 -23
- package/dist/_chunks/Relations-CsjdyIXg.mjs.map +1 -0
- package/dist/_chunks/{Relations-CFjTESWQ.js → Relations-DLMpxASn.js} +32 -23
- package/dist/_chunks/Relations-DLMpxASn.js.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-BHfS6_D5.mjs → index-D1ol0KTz.mjs} +933 -867
- package/dist/_chunks/index-D1ol0KTz.mjs.map +1 -0
- package/dist/_chunks/{index-DXiHxy70.js → index-DFWNpb4M.js} +931 -865
- package/dist/_chunks/index-DFWNpb4M.js.map +1 -0
- package/dist/_chunks/{layout-bE-WUnQ0.js → layout-CfocPPPK.js} +3 -3
- package/dist/_chunks/{layout-bE-WUnQ0.js.map → layout-CfocPPPK.js.map} +1 -1
- package/dist/_chunks/{layout-DX_52HSH.mjs → layout-DZAT9E_K.mjs} +3 -3
- package/dist/_chunks/{layout-DX_52HSH.mjs.map → layout-DZAT9E_K.mjs.map} +1 -1
- package/dist/_chunks/{relations-SCVAL_aJ.mjs → relations-BOmKF9Py.mjs} +2 -2
- package/dist/_chunks/{relations-SCVAL_aJ.mjs.map → relations-BOmKF9Py.mjs.map} +1 -1
- package/dist/_chunks/{relations-D706vblp.js → relations-CDuOkPbo.js} +2 -2
- package/dist/_chunks/{relations-D706vblp.js.map → relations-CDuOkPbo.js.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 +9 -9
- package/dist/_chunks/EditViewPage-CHgoNwlc.js.map +0 -1
- package/dist/_chunks/EditViewPage-zFjJK0s8.mjs.map +0 -1
- package/dist/_chunks/Field-9DePZh-0.js.map +0 -1
- package/dist/_chunks/Field-DPAzUS1M.mjs.map +0 -1
- package/dist/_chunks/Form-CEkENbkF.mjs.map +0 -1
- package/dist/_chunks/Form-DPm-KZ1A.js.map +0 -1
- package/dist/_chunks/History-DXSbTWez.js.map +0 -1
- package/dist/_chunks/History-utls71em.mjs.map +0 -1
- package/dist/_chunks/Relations-CFjTESWQ.js.map +0 -1
- package/dist/_chunks/Relations-QP5yn9_z.mjs.map +0 -1
- package/dist/_chunks/index-BHfS6_D5.mjs.map +0 -1
- package/dist/_chunks/index-DXiHxy70.js.map +0 -1
@@ -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,398 +913,657 @@ 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
|
-
|
904
|
-
|
905
|
-
});
|
906
|
-
return { error: res.error };
|
907
|
-
}
|
908
|
-
toggleNotification({
|
909
|
-
type: "success",
|
910
|
-
message: formatMessage({
|
911
|
-
id: getTranslation("success.record.delete"),
|
912
|
-
defaultMessage: "Deleted document"
|
913
|
-
})
|
914
|
-
});
|
915
|
-
trackUsage("didDeleteEntry", trackerProperty);
|
916
|
-
return res.data;
|
917
|
-
} catch (err) {
|
918
|
-
toggleNotification({
|
919
|
-
type: "danger",
|
920
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
921
|
-
});
|
922
|
-
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
923
|
-
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([row]);
|
972
|
+
} else {
|
973
|
+
panels[currentPanelIndex].push(row);
|
924
974
|
}
|
925
|
-
}
|
926
|
-
|
927
|
-
);
|
928
|
-
const
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
message: formatAPIError(res.error)
|
942
|
-
});
|
943
|
-
return { error: res.error };
|
975
|
+
}
|
976
|
+
return panels;
|
977
|
+
}, []);
|
978
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
979
|
+
(acc, [uid, configuration]) => {
|
980
|
+
acc[uid] = {
|
981
|
+
layout: convertEditLayoutToFieldLayouts(
|
982
|
+
configuration.layouts.edit,
|
983
|
+
components[uid].attributes,
|
984
|
+
configuration.metadatas,
|
985
|
+
{ configurations: data.components, schemas: components }
|
986
|
+
),
|
987
|
+
settings: {
|
988
|
+
...configuration.settings,
|
989
|
+
icon: components[uid].info.icon,
|
990
|
+
displayName: components[uid].info.displayName
|
944
991
|
}
|
945
|
-
|
946
|
-
|
947
|
-
title: formatMessage({
|
948
|
-
id: getTranslation("success.records.delete"),
|
949
|
-
defaultMessage: "Successfully deleted."
|
950
|
-
}),
|
951
|
-
message: ""
|
952
|
-
});
|
953
|
-
trackUsage("didBulkDeleteEntries");
|
954
|
-
return res.data;
|
955
|
-
} catch (err) {
|
956
|
-
toggleNotification({
|
957
|
-
type: "danger",
|
958
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
959
|
-
});
|
960
|
-
trackUsage("didNotBulkDeleteEntries");
|
961
|
-
throw err;
|
962
|
-
}
|
992
|
+
};
|
993
|
+
return acc;
|
963
994
|
},
|
964
|
-
|
995
|
+
{}
|
965
996
|
);
|
966
|
-
const
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
model,
|
973
|
-
documentId,
|
974
|
-
params
|
975
|
-
});
|
976
|
-
if ("error" in res) {
|
977
|
-
toggleNotification({
|
978
|
-
type: "danger",
|
979
|
-
message: formatAPIError(res.error)
|
980
|
-
});
|
981
|
-
return { error: res.error };
|
982
|
-
}
|
983
|
-
toggleNotification({
|
984
|
-
type: "success",
|
985
|
-
message: formatMessage({
|
986
|
-
id: "content-manager.success.record.discard",
|
987
|
-
defaultMessage: "Changes discarded"
|
988
|
-
})
|
989
|
-
});
|
990
|
-
return res.data;
|
991
|
-
} catch (err) {
|
992
|
-
toggleNotification({
|
993
|
-
type: "danger",
|
994
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
995
|
-
});
|
996
|
-
throw err;
|
997
|
-
}
|
997
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
998
|
+
(acc, [attribute, metadata]) => {
|
999
|
+
return {
|
1000
|
+
...acc,
|
1001
|
+
[attribute]: metadata.edit
|
1002
|
+
};
|
998
1003
|
},
|
999
|
-
|
1004
|
+
{}
|
1000
1005
|
);
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
model,
|
1009
|
-
documentId,
|
1010
|
-
data,
|
1011
|
-
params
|
1012
|
-
});
|
1013
|
-
if ("error" in res) {
|
1014
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1015
|
-
return { error: res.error };
|
1016
|
-
}
|
1017
|
-
trackUsage("didPublishEntry");
|
1018
|
-
toggleNotification({
|
1019
|
-
type: "success",
|
1020
|
-
message: formatMessage({
|
1021
|
-
id: getTranslation("success.record.publish"),
|
1022
|
-
defaultMessage: "Published document"
|
1023
|
-
})
|
1024
|
-
});
|
1025
|
-
return res.data;
|
1026
|
-
} catch (err) {
|
1027
|
-
toggleNotification({
|
1028
|
-
type: "danger",
|
1029
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1030
|
-
});
|
1031
|
-
throw err;
|
1032
|
-
}
|
1006
|
+
return {
|
1007
|
+
layout: panelledEditAttributes,
|
1008
|
+
components: componentEditAttributes,
|
1009
|
+
metadatas: editMetadatas,
|
1010
|
+
settings: {
|
1011
|
+
...data.contentType.settings,
|
1012
|
+
displayName: schema?.info.displayName
|
1033
1013
|
},
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
return { error: res.error };
|
1048
|
-
}
|
1049
|
-
toggleNotification({
|
1050
|
-
type: "success",
|
1051
|
-
message: formatMessage({
|
1052
|
-
id: getTranslation("success.record.publish"),
|
1053
|
-
defaultMessage: "Published document"
|
1054
|
-
})
|
1055
|
-
});
|
1056
|
-
return res.data;
|
1057
|
-
} catch (err) {
|
1058
|
-
toggleNotification({
|
1059
|
-
type: "danger",
|
1060
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1061
|
-
});
|
1062
|
-
throw err;
|
1014
|
+
options: {
|
1015
|
+
...schema?.options,
|
1016
|
+
...schema?.pluginOptions,
|
1017
|
+
...data.contentType.options
|
1018
|
+
}
|
1019
|
+
};
|
1020
|
+
};
|
1021
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1022
|
+
return rows.map(
|
1023
|
+
(row) => row.map((field) => {
|
1024
|
+
const attribute = attributes[field.name];
|
1025
|
+
if (!attribute) {
|
1026
|
+
return null;
|
1063
1027
|
}
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1028
|
+
const { edit: metadata } = metadatas[field.name];
|
1029
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1030
|
+
return {
|
1031
|
+
attribute,
|
1032
|
+
disabled: !metadata.editable,
|
1033
|
+
hint: metadata.description,
|
1034
|
+
label: metadata.label ?? "",
|
1035
|
+
name: field.name,
|
1036
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1037
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1038
|
+
schemas,
|
1039
|
+
components: components?.schemas ?? {}
|
1040
|
+
}),
|
1041
|
+
placeholder: metadata.placeholder ?? "",
|
1042
|
+
required: attribute.required ?? false,
|
1043
|
+
size: field.size,
|
1044
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1045
|
+
visible: metadata.visible ?? true,
|
1046
|
+
type: attribute.type
|
1047
|
+
};
|
1048
|
+
}).filter((field) => field !== null)
|
1072
1049
|
);
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1050
|
+
};
|
1051
|
+
const formatListLayout = (data, {
|
1052
|
+
schemas,
|
1053
|
+
schema,
|
1054
|
+
components
|
1055
|
+
}) => {
|
1056
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1057
|
+
(acc, [attribute, metadata]) => {
|
1058
|
+
return {
|
1059
|
+
...acc,
|
1060
|
+
[attribute]: metadata.list
|
1061
|
+
};
|
1062
|
+
},
|
1063
|
+
{}
|
1064
|
+
);
|
1065
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1066
|
+
data.contentType.layouts.list,
|
1067
|
+
schema?.attributes,
|
1068
|
+
listMetadatas,
|
1069
|
+
{ configurations: data.components, schemas: components },
|
1070
|
+
schemas
|
1071
|
+
);
|
1072
|
+
return {
|
1073
|
+
layout: listAttributes,
|
1074
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1075
|
+
metadatas: listMetadatas,
|
1076
|
+
options: {
|
1077
|
+
...schema?.options,
|
1078
|
+
...schema?.pluginOptions,
|
1079
|
+
...data.contentType.options
|
1080
|
+
}
|
1081
|
+
};
|
1082
|
+
};
|
1083
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1084
|
+
return columns.map((name) => {
|
1085
|
+
const attribute = attributes[name];
|
1086
|
+
if (!attribute) {
|
1087
|
+
return null;
|
1088
|
+
}
|
1089
|
+
const metadata = metadatas[name];
|
1090
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1091
|
+
return {
|
1092
|
+
attribute,
|
1093
|
+
label: metadata.label ?? "",
|
1094
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1095
|
+
schemas,
|
1096
|
+
components: components?.schemas ?? {}
|
1097
|
+
}),
|
1098
|
+
name,
|
1099
|
+
searchable: metadata.searchable ?? true,
|
1100
|
+
sortable: metadata.sortable ?? true
|
1101
|
+
};
|
1102
|
+
}).filter((field) => field !== null);
|
1103
|
+
};
|
1104
|
+
const useDocument = (args, opts) => {
|
1105
|
+
const { toggleNotification } = useNotification();
|
1106
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1107
|
+
const {
|
1108
|
+
currentData: data,
|
1109
|
+
isLoading: isLoadingDocument,
|
1110
|
+
isFetching: isFetchingDocument,
|
1111
|
+
error
|
1112
|
+
} = useGetDocumentQuery(args, {
|
1113
|
+
...opts,
|
1114
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1115
|
+
});
|
1116
|
+
const {
|
1117
|
+
components,
|
1118
|
+
schema,
|
1119
|
+
schemas,
|
1120
|
+
isLoading: isLoadingSchema
|
1121
|
+
} = useContentTypeSchema(args.model);
|
1122
|
+
React.useEffect(() => {
|
1123
|
+
if (error) {
|
1124
|
+
toggleNotification({
|
1125
|
+
type: "danger",
|
1126
|
+
message: formatAPIError(error)
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1130
|
+
const validationSchema = React.useMemo(() => {
|
1131
|
+
if (!schema) {
|
1132
|
+
return null;
|
1133
|
+
}
|
1134
|
+
return createYupSchema(schema.attributes, components);
|
1135
|
+
}, [schema, components]);
|
1136
|
+
const validate = React.useCallback(
|
1137
|
+
(document) => {
|
1138
|
+
if (!validationSchema) {
|
1139
|
+
throw new Error(
|
1140
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1141
|
+
);
|
1142
|
+
}
|
1143
|
+
try {
|
1144
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1145
|
+
return null;
|
1146
|
+
} catch (error2) {
|
1147
|
+
if (error2 instanceof ValidationError) {
|
1148
|
+
return getYupValidationErrors(error2);
|
1089
1149
|
}
|
1090
|
-
|
1091
|
-
toggleNotification({
|
1092
|
-
type: "success",
|
1093
|
-
message: formatMessage({
|
1094
|
-
id: getTranslation("success.record.save"),
|
1095
|
-
defaultMessage: "Saved document"
|
1096
|
-
})
|
1097
|
-
});
|
1098
|
-
return res.data;
|
1099
|
-
} catch (err) {
|
1100
|
-
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1101
|
-
toggleNotification({
|
1102
|
-
type: "danger",
|
1103
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1104
|
-
});
|
1105
|
-
throw err;
|
1150
|
+
throw error2;
|
1106
1151
|
}
|
1107
1152
|
},
|
1108
|
-
[
|
1153
|
+
[validationSchema]
|
1109
1154
|
);
|
1110
|
-
const
|
1111
|
-
const
|
1112
|
-
|
1155
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1156
|
+
const hasError = !!error;
|
1157
|
+
return {
|
1158
|
+
components,
|
1159
|
+
document: data?.data,
|
1160
|
+
meta: data?.meta,
|
1161
|
+
isLoading,
|
1162
|
+
hasError,
|
1163
|
+
schema,
|
1164
|
+
schemas,
|
1165
|
+
validate
|
1166
|
+
};
|
1167
|
+
};
|
1168
|
+
const useDoc = () => {
|
1169
|
+
const { id, slug, collectionType, origin } = useParams();
|
1170
|
+
const [{ query }] = useQueryParams();
|
1171
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1172
|
+
if (!collectionType) {
|
1173
|
+
throw new Error("Could not find collectionType in url params");
|
1174
|
+
}
|
1175
|
+
if (!slug) {
|
1176
|
+
throw new Error("Could not find model in url params");
|
1177
|
+
}
|
1178
|
+
const document = useDocument(
|
1179
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1180
|
+
{
|
1181
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1182
|
+
}
|
1183
|
+
);
|
1184
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1185
|
+
return {
|
1186
|
+
collectionType,
|
1187
|
+
model: slug,
|
1188
|
+
id: returnId,
|
1189
|
+
...document
|
1190
|
+
};
|
1191
|
+
};
|
1192
|
+
const useContentManagerContext = () => {
|
1193
|
+
const {
|
1194
|
+
collectionType,
|
1195
|
+
model,
|
1196
|
+
id,
|
1197
|
+
components,
|
1198
|
+
isLoading: isLoadingDoc,
|
1199
|
+
schema,
|
1200
|
+
schemas
|
1201
|
+
} = useDoc();
|
1202
|
+
const layout = useDocumentLayout(model);
|
1203
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1204
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1205
|
+
const slug = model;
|
1206
|
+
const isCreatingEntry = id === "create";
|
1207
|
+
useContentTypeSchema();
|
1208
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1209
|
+
const error = layout.error;
|
1210
|
+
return {
|
1211
|
+
error,
|
1212
|
+
isLoading,
|
1213
|
+
// Base metadata
|
1214
|
+
model,
|
1215
|
+
collectionType,
|
1216
|
+
id,
|
1217
|
+
slug,
|
1218
|
+
isCreatingEntry,
|
1219
|
+
isSingleType,
|
1220
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1221
|
+
// All schema infos
|
1222
|
+
components,
|
1223
|
+
contentType: schema,
|
1224
|
+
contentTypes: schemas,
|
1225
|
+
// Form state
|
1226
|
+
form,
|
1227
|
+
// layout infos
|
1228
|
+
layout
|
1229
|
+
};
|
1230
|
+
};
|
1231
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1232
|
+
if (!pluginId) {
|
1233
|
+
throw new TypeError("pluginId can't be empty");
|
1234
|
+
}
|
1235
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1236
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1237
|
+
return acc;
|
1238
|
+
}, {});
|
1239
|
+
};
|
1240
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1241
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1242
|
+
id: "notification.error",
|
1243
|
+
defaultMessage: "An error occurred, please try again"
|
1244
|
+
};
|
1245
|
+
const useDocumentActions = () => {
|
1246
|
+
const { toggleNotification } = useNotification();
|
1247
|
+
const { formatMessage } = useIntl();
|
1248
|
+
const { trackUsage } = useTracking();
|
1249
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1250
|
+
const navigate = useNavigate();
|
1251
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1252
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1253
|
+
const _delete = React.useCallback(
|
1254
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1113
1255
|
try {
|
1114
|
-
trackUsage("
|
1115
|
-
const res = await
|
1256
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1257
|
+
const res = await deleteDocument({
|
1116
1258
|
collectionType,
|
1117
1259
|
model,
|
1118
1260
|
documentId,
|
1119
|
-
params
|
1120
|
-
data: {
|
1121
|
-
discardDraft
|
1122
|
-
}
|
1261
|
+
params
|
1123
1262
|
});
|
1124
1263
|
if ("error" in res) {
|
1125
|
-
toggleNotification({
|
1264
|
+
toggleNotification({
|
1265
|
+
type: "danger",
|
1266
|
+
message: formatAPIError(res.error)
|
1267
|
+
});
|
1126
1268
|
return { error: res.error };
|
1127
1269
|
}
|
1128
|
-
trackUsage("didUnpublishEntry");
|
1129
1270
|
toggleNotification({
|
1130
1271
|
type: "success",
|
1131
1272
|
message: formatMessage({
|
1132
|
-
id: getTranslation("success.record.
|
1133
|
-
defaultMessage: "
|
1273
|
+
id: getTranslation("success.record.delete"),
|
1274
|
+
defaultMessage: "Deleted document"
|
1134
1275
|
})
|
1135
1276
|
});
|
1277
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1136
1278
|
return res.data;
|
1137
1279
|
} catch (err) {
|
1138
1280
|
toggleNotification({
|
1139
1281
|
type: "danger",
|
1140
1282
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1141
1283
|
});
|
1284
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1142
1285
|
throw err;
|
1143
1286
|
}
|
1144
1287
|
},
|
1145
|
-
[trackUsage,
|
1288
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1146
1289
|
);
|
1147
|
-
const [
|
1148
|
-
const
|
1290
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1291
|
+
const deleteMany = React.useCallback(
|
1149
1292
|
async ({ model, documentIds, params }) => {
|
1150
1293
|
try {
|
1151
|
-
trackUsage("
|
1152
|
-
const res = await
|
1294
|
+
trackUsage("willBulkDeleteEntries");
|
1295
|
+
const res = await deleteManyDocuments({
|
1153
1296
|
model,
|
1154
1297
|
documentIds,
|
1155
1298
|
params
|
1156
1299
|
});
|
1157
1300
|
if ("error" in res) {
|
1158
|
-
toggleNotification({
|
1301
|
+
toggleNotification({
|
1302
|
+
type: "danger",
|
1303
|
+
message: formatAPIError(res.error)
|
1304
|
+
});
|
1159
1305
|
return { error: res.error };
|
1160
1306
|
}
|
1161
|
-
trackUsage("didBulkUnpublishEntries");
|
1162
1307
|
toggleNotification({
|
1163
1308
|
type: "success",
|
1164
1309
|
title: formatMessage({
|
1165
|
-
id: getTranslation("success.records.
|
1166
|
-
defaultMessage: "Successfully
|
1310
|
+
id: getTranslation("success.records.delete"),
|
1311
|
+
defaultMessage: "Successfully deleted."
|
1167
1312
|
}),
|
1168
1313
|
message: ""
|
1169
1314
|
});
|
1315
|
+
trackUsage("didBulkDeleteEntries");
|
1170
1316
|
return res.data;
|
1171
1317
|
} catch (err) {
|
1172
1318
|
toggleNotification({
|
1173
1319
|
type: "danger",
|
1174
1320
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1175
1321
|
});
|
1176
|
-
trackUsage("
|
1322
|
+
trackUsage("didNotBulkDeleteEntries");
|
1177
1323
|
throw err;
|
1178
1324
|
}
|
1179
1325
|
},
|
1180
|
-
[trackUsage,
|
1326
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1181
1327
|
);
|
1182
|
-
const [
|
1183
|
-
const
|
1184
|
-
async ({ model, params }
|
1328
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1329
|
+
const discard = React.useCallback(
|
1330
|
+
async ({ collectionType, model, documentId, params }) => {
|
1185
1331
|
try {
|
1186
|
-
const res = await
|
1332
|
+
const res = await discardDocument({
|
1333
|
+
collectionType,
|
1187
1334
|
model,
|
1188
|
-
|
1335
|
+
documentId,
|
1189
1336
|
params
|
1190
1337
|
});
|
1191
1338
|
if ("error" in res) {
|
1192
|
-
toggleNotification({
|
1193
|
-
|
1339
|
+
toggleNotification({
|
1340
|
+
type: "danger",
|
1341
|
+
message: formatAPIError(res.error)
|
1342
|
+
});
|
1194
1343
|
return { error: res.error };
|
1195
1344
|
}
|
1196
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1197
1345
|
toggleNotification({
|
1198
1346
|
type: "success",
|
1199
1347
|
message: formatMessage({
|
1200
|
-
id:
|
1201
|
-
defaultMessage: "
|
1202
|
-
})
|
1348
|
+
id: "content-manager.success.record.discard",
|
1349
|
+
defaultMessage: "Changes discarded"
|
1350
|
+
})
|
1351
|
+
});
|
1352
|
+
return res.data;
|
1353
|
+
} catch (err) {
|
1354
|
+
toggleNotification({
|
1355
|
+
type: "danger",
|
1356
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1357
|
+
});
|
1358
|
+
throw err;
|
1359
|
+
}
|
1360
|
+
},
|
1361
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1362
|
+
);
|
1363
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1364
|
+
const publish = React.useCallback(
|
1365
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1366
|
+
try {
|
1367
|
+
trackUsage("willPublishEntry");
|
1368
|
+
const res = await publishDocument({
|
1369
|
+
collectionType,
|
1370
|
+
model,
|
1371
|
+
documentId,
|
1372
|
+
data,
|
1373
|
+
params
|
1374
|
+
});
|
1375
|
+
if ("error" in res) {
|
1376
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1377
|
+
return { error: res.error };
|
1378
|
+
}
|
1379
|
+
trackUsage("didPublishEntry");
|
1380
|
+
toggleNotification({
|
1381
|
+
type: "success",
|
1382
|
+
message: formatMessage({
|
1383
|
+
id: getTranslation("success.record.publish"),
|
1384
|
+
defaultMessage: "Published document"
|
1385
|
+
})
|
1386
|
+
});
|
1387
|
+
return res.data;
|
1388
|
+
} catch (err) {
|
1389
|
+
toggleNotification({
|
1390
|
+
type: "danger",
|
1391
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1392
|
+
});
|
1393
|
+
throw err;
|
1394
|
+
}
|
1395
|
+
},
|
1396
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1397
|
+
);
|
1398
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1399
|
+
const publishMany = React.useCallback(
|
1400
|
+
async ({ model, documentIds, params }) => {
|
1401
|
+
try {
|
1402
|
+
const res = await publishManyDocuments({
|
1403
|
+
model,
|
1404
|
+
documentIds,
|
1405
|
+
params
|
1406
|
+
});
|
1407
|
+
if ("error" in res) {
|
1408
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1409
|
+
return { error: res.error };
|
1410
|
+
}
|
1411
|
+
toggleNotification({
|
1412
|
+
type: "success",
|
1413
|
+
message: formatMessage({
|
1414
|
+
id: getTranslation("success.record.publish"),
|
1415
|
+
defaultMessage: "Published document"
|
1416
|
+
})
|
1417
|
+
});
|
1418
|
+
return res.data;
|
1419
|
+
} catch (err) {
|
1420
|
+
toggleNotification({
|
1421
|
+
type: "danger",
|
1422
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1423
|
+
});
|
1424
|
+
throw err;
|
1425
|
+
}
|
1426
|
+
},
|
1427
|
+
[
|
1428
|
+
// trackUsage,
|
1429
|
+
publishManyDocuments,
|
1430
|
+
toggleNotification,
|
1431
|
+
formatMessage,
|
1432
|
+
formatAPIError
|
1433
|
+
]
|
1434
|
+
);
|
1435
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1436
|
+
const update = React.useCallback(
|
1437
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1438
|
+
try {
|
1439
|
+
trackUsage("willEditEntry", trackerProperty);
|
1440
|
+
const res = await updateDocument({
|
1441
|
+
collectionType,
|
1442
|
+
model,
|
1443
|
+
documentId,
|
1444
|
+
data,
|
1445
|
+
params
|
1446
|
+
});
|
1447
|
+
if ("error" in res) {
|
1448
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1449
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1450
|
+
return { error: res.error };
|
1451
|
+
}
|
1452
|
+
trackUsage("didEditEntry", trackerProperty);
|
1453
|
+
toggleNotification({
|
1454
|
+
type: "success",
|
1455
|
+
message: formatMessage({
|
1456
|
+
id: getTranslation("success.record.save"),
|
1457
|
+
defaultMessage: "Saved document"
|
1458
|
+
})
|
1459
|
+
});
|
1460
|
+
return res.data;
|
1461
|
+
} catch (err) {
|
1462
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1463
|
+
toggleNotification({
|
1464
|
+
type: "danger",
|
1465
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1466
|
+
});
|
1467
|
+
throw err;
|
1468
|
+
}
|
1469
|
+
},
|
1470
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1471
|
+
);
|
1472
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1473
|
+
const unpublish = React.useCallback(
|
1474
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1475
|
+
try {
|
1476
|
+
trackUsage("willUnpublishEntry");
|
1477
|
+
const res = await unpublishDocument({
|
1478
|
+
collectionType,
|
1479
|
+
model,
|
1480
|
+
documentId,
|
1481
|
+
params,
|
1482
|
+
data: {
|
1483
|
+
discardDraft
|
1484
|
+
}
|
1485
|
+
});
|
1486
|
+
if ("error" in res) {
|
1487
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1488
|
+
return { error: res.error };
|
1489
|
+
}
|
1490
|
+
trackUsage("didUnpublishEntry");
|
1491
|
+
toggleNotification({
|
1492
|
+
type: "success",
|
1493
|
+
message: formatMessage({
|
1494
|
+
id: getTranslation("success.record.unpublish"),
|
1495
|
+
defaultMessage: "Unpublished document"
|
1496
|
+
})
|
1497
|
+
});
|
1498
|
+
return res.data;
|
1499
|
+
} catch (err) {
|
1500
|
+
toggleNotification({
|
1501
|
+
type: "danger",
|
1502
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1503
|
+
});
|
1504
|
+
throw err;
|
1505
|
+
}
|
1506
|
+
},
|
1507
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1508
|
+
);
|
1509
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1510
|
+
const unpublishMany = React.useCallback(
|
1511
|
+
async ({ model, documentIds, params }) => {
|
1512
|
+
try {
|
1513
|
+
trackUsage("willBulkUnpublishEntries");
|
1514
|
+
const res = await unpublishManyDocuments({
|
1515
|
+
model,
|
1516
|
+
documentIds,
|
1517
|
+
params
|
1518
|
+
});
|
1519
|
+
if ("error" in res) {
|
1520
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1521
|
+
return { error: res.error };
|
1522
|
+
}
|
1523
|
+
trackUsage("didBulkUnpublishEntries");
|
1524
|
+
toggleNotification({
|
1525
|
+
type: "success",
|
1526
|
+
title: formatMessage({
|
1527
|
+
id: getTranslation("success.records.unpublish"),
|
1528
|
+
defaultMessage: "Successfully unpublished."
|
1529
|
+
}),
|
1530
|
+
message: ""
|
1531
|
+
});
|
1532
|
+
return res.data;
|
1533
|
+
} catch (err) {
|
1534
|
+
toggleNotification({
|
1535
|
+
type: "danger",
|
1536
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1537
|
+
});
|
1538
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1539
|
+
throw err;
|
1540
|
+
}
|
1541
|
+
},
|
1542
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1543
|
+
);
|
1544
|
+
const [createDocument] = useCreateDocumentMutation();
|
1545
|
+
const create = React.useCallback(
|
1546
|
+
async ({ model, params }, data, trackerProperty) => {
|
1547
|
+
try {
|
1548
|
+
const res = await createDocument({
|
1549
|
+
model,
|
1550
|
+
data,
|
1551
|
+
params
|
1552
|
+
});
|
1553
|
+
if ("error" in res) {
|
1554
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1555
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1556
|
+
return { error: res.error };
|
1557
|
+
}
|
1558
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1559
|
+
toggleNotification({
|
1560
|
+
type: "success",
|
1561
|
+
message: formatMessage({
|
1562
|
+
id: getTranslation("success.record.save"),
|
1563
|
+
defaultMessage: "Saved document"
|
1564
|
+
})
|
1203
1565
|
});
|
1566
|
+
setCurrentStep("contentManager.success");
|
1204
1567
|
return res.data;
|
1205
1568
|
} catch (err) {
|
1206
1569
|
toggleNotification({
|
@@ -1303,7 +1666,7 @@ const useDocumentActions = () => {
|
|
1303
1666
|
};
|
1304
1667
|
};
|
1305
1668
|
const ProtectedHistoryPage = lazy(
|
1306
|
-
() => import("./History-
|
1669
|
+
() => import("./History-CQf4ssdU.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1307
1670
|
);
|
1308
1671
|
const routes$1 = [
|
1309
1672
|
{
|
@@ -1316,31 +1679,31 @@ const routes$1 = [
|
|
1316
1679
|
}
|
1317
1680
|
];
|
1318
1681
|
const ProtectedEditViewPage = lazy(
|
1319
|
-
() => import("./EditViewPage-
|
1682
|
+
() => import("./EditViewPage-noMD5CfK.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1320
1683
|
);
|
1321
1684
|
const ProtectedListViewPage = lazy(
|
1322
|
-
() => import("./ListViewPage-
|
1685
|
+
() => import("./ListViewPage-DAvl-VG5.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1323
1686
|
);
|
1324
1687
|
const ProtectedListConfiguration = lazy(
|
1325
|
-
() => import("./ListConfigurationPage-
|
1688
|
+
() => import("./ListConfigurationPage-DXy-IKAk.mjs").then((mod) => ({
|
1326
1689
|
default: mod.ProtectedListConfiguration
|
1327
1690
|
}))
|
1328
1691
|
);
|
1329
1692
|
const ProtectedEditConfigurationPage = lazy(
|
1330
|
-
() => import("./EditConfigurationPage-
|
1693
|
+
() => import("./EditConfigurationPage-qFNC9RPm.mjs").then((mod) => ({
|
1331
1694
|
default: mod.ProtectedEditConfigurationPage
|
1332
1695
|
}))
|
1333
1696
|
);
|
1334
1697
|
const ProtectedComponentConfigurationPage = lazy(
|
1335
|
-
() => import("./ComponentConfigurationPage-
|
1698
|
+
() => import("./ComponentConfigurationPage-Dp3ZXzP_.mjs").then((mod) => ({
|
1336
1699
|
default: mod.ProtectedComponentConfigurationPage
|
1337
1700
|
}))
|
1338
1701
|
);
|
1339
1702
|
const NoPermissions = lazy(
|
1340
|
-
() => import("./NoPermissionsPage-
|
1703
|
+
() => import("./NoPermissionsPage-BzSfwl62.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1341
1704
|
);
|
1342
1705
|
const NoContentType = lazy(
|
1343
|
-
() => import("./NoContentTypePage-
|
1706
|
+
() => import("./NoContentTypePage-D-DbFSFh.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1344
1707
|
);
|
1345
1708
|
const CollectionTypePages = () => {
|
1346
1709
|
const { collectionType } = useParams();
|
@@ -1787,7 +2150,9 @@ const PublishAction$1 = ({
|
|
1787
2150
|
const performPublish = async () => {
|
1788
2151
|
setSubmitting(true);
|
1789
2152
|
try {
|
1790
|
-
const { errors } = await validate(
|
2153
|
+
const { errors } = await validate(true, {
|
2154
|
+
status: "published"
|
2155
|
+
});
|
1791
2156
|
if (errors) {
|
1792
2157
|
toggleNotification({
|
1793
2158
|
type: "danger",
|
@@ -1901,18 +2266,18 @@ const UpdateAction = ({
|
|
1901
2266
|
onClick: async () => {
|
1902
2267
|
setSubmitting(true);
|
1903
2268
|
try {
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
})
|
1914
|
-
|
1915
|
-
|
2269
|
+
const { errors } = await validate(true, {
|
2270
|
+
status: "draft"
|
2271
|
+
});
|
2272
|
+
if (errors) {
|
2273
|
+
toggleNotification({
|
2274
|
+
type: "danger",
|
2275
|
+
message: formatMessage({
|
2276
|
+
id: "content-manager.validation.error",
|
2277
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2278
|
+
})
|
2279
|
+
});
|
2280
|
+
return;
|
1916
2281
|
}
|
1917
2282
|
if (isCloning) {
|
1918
2283
|
const res = await clone(
|
@@ -2294,12 +2659,12 @@ const Information = ({ activeTab }) => {
|
|
2294
2659
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2295
2660
|
label: formatMessage({
|
2296
2661
|
id: "content-manager.containers.edit.information.last-published.label",
|
2297
|
-
defaultMessage: "
|
2662
|
+
defaultMessage: "Published"
|
2298
2663
|
}),
|
2299
2664
|
value: formatMessage(
|
2300
2665
|
{
|
2301
2666
|
id: "content-manager.containers.edit.information.last-published.value",
|
2302
|
-
defaultMessage: `
|
2667
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2303
2668
|
},
|
2304
2669
|
{
|
2305
2670
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2312,12 +2677,12 @@ const Information = ({ activeTab }) => {
|
|
2312
2677
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2313
2678
|
label: formatMessage({
|
2314
2679
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2315
|
-
defaultMessage: "
|
2680
|
+
defaultMessage: "Updated"
|
2316
2681
|
}),
|
2317
2682
|
value: formatMessage(
|
2318
2683
|
{
|
2319
2684
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2320
|
-
defaultMessage: `
|
2685
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2321
2686
|
},
|
2322
2687
|
{
|
2323
2688
|
time: /* @__PURE__ */ jsx(
|
@@ -2335,12 +2700,12 @@ const Information = ({ activeTab }) => {
|
|
2335
2700
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2336
2701
|
label: formatMessage({
|
2337
2702
|
id: "content-manager.containers.edit.information.document.label",
|
2338
|
-
defaultMessage: "
|
2703
|
+
defaultMessage: "Created"
|
2339
2704
|
}),
|
2340
2705
|
value: formatMessage(
|
2341
2706
|
{
|
2342
2707
|
id: "content-manager.containers.edit.information.document.value",
|
2343
|
-
defaultMessage: `
|
2708
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2344
2709
|
},
|
2345
2710
|
{
|
2346
2711
|
time: /* @__PURE__ */ jsx(
|
@@ -2398,10 +2763,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2398
2763
|
SingleSelect,
|
2399
2764
|
{
|
2400
2765
|
size: "S",
|
2401
|
-
disabled: action.disabled,
|
2402
|
-
"aria-label": action.label,
|
2403
2766
|
onChange: action.onSelect,
|
2404
|
-
|
2767
|
+
"aria-label": action.label,
|
2768
|
+
...action,
|
2405
2769
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2406
2770
|
},
|
2407
2771
|
action.id
|
@@ -2465,490 +2829,191 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
|
|
2465
2829
|
position: "header"
|
2466
2830
|
};
|
2467
2831
|
};
|
2468
|
-
ConfigureTheViewAction.type = "configure-the-view";
|
2469
|
-
const EditTheModelAction = ({ model }) => {
|
2470
|
-
const navigate = useNavigate();
|
2471
|
-
const { formatMessage } = useIntl();
|
2472
|
-
return {
|
2473
|
-
label: formatMessage({
|
2474
|
-
id: "content-manager.link-to-ctb",
|
2475
|
-
defaultMessage: "Edit the model"
|
2476
|
-
}),
|
2477
|
-
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2478
|
-
onClick: () => {
|
2479
|
-
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2480
|
-
},
|
2481
|
-
position: "header"
|
2482
|
-
};
|
2483
|
-
};
|
2484
|
-
EditTheModelAction.type = "edit-the-model";
|
2485
|
-
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2486
|
-
const navigate = useNavigate();
|
2487
|
-
const { formatMessage } = useIntl();
|
2488
|
-
const listViewPathMatch = useMatch(LIST_PATH);
|
2489
|
-
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2490
|
-
const { delete: deleteAction } = useDocumentActions();
|
2491
|
-
const { toggleNotification } = useNotification();
|
2492
|
-
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2493
|
-
return {
|
2494
|
-
disabled: !canDelete || !document,
|
2495
|
-
label: formatMessage({
|
2496
|
-
id: "content-manager.actions.delete.label",
|
2497
|
-
defaultMessage: "Delete document"
|
2498
|
-
}),
|
2499
|
-
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2500
|
-
dialog: {
|
2501
|
-
type: "dialog",
|
2502
|
-
title: formatMessage({
|
2503
|
-
id: "app.components.ConfirmDialog.title",
|
2504
|
-
defaultMessage: "Confirmation"
|
2505
|
-
}),
|
2506
|
-
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2507
|
-
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2508
|
-
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2509
|
-
id: "content-manager.actions.delete.dialog.body",
|
2510
|
-
defaultMessage: "Are you sure?"
|
2511
|
-
}) })
|
2512
|
-
] }),
|
2513
|
-
onConfirm: async () => {
|
2514
|
-
if (!listViewPathMatch) {
|
2515
|
-
setSubmitting(true);
|
2516
|
-
}
|
2517
|
-
try {
|
2518
|
-
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2519
|
-
console.error(
|
2520
|
-
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2521
|
-
);
|
2522
|
-
toggleNotification({
|
2523
|
-
message: formatMessage({
|
2524
|
-
id: "content-manager.actions.delete.error",
|
2525
|
-
defaultMessage: "An error occurred while trying to delete the document."
|
2526
|
-
}),
|
2527
|
-
type: "danger"
|
2528
|
-
});
|
2529
|
-
return;
|
2530
|
-
}
|
2531
|
-
const res = await deleteAction({
|
2532
|
-
documentId,
|
2533
|
-
model,
|
2534
|
-
collectionType,
|
2535
|
-
params: {
|
2536
|
-
locale: "*"
|
2537
|
-
}
|
2538
|
-
});
|
2539
|
-
if (!("error" in res)) {
|
2540
|
-
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2541
|
-
}
|
2542
|
-
} finally {
|
2543
|
-
if (!listViewPathMatch) {
|
2544
|
-
setSubmitting(false);
|
2545
|
-
}
|
2546
|
-
}
|
2547
|
-
}
|
2548
|
-
},
|
2549
|
-
variant: "danger",
|
2550
|
-
position: ["header", "table-row"]
|
2551
|
-
};
|
2552
|
-
};
|
2553
|
-
DeleteAction$1.type = "delete";
|
2554
|
-
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2555
|
-
const Panels = () => {
|
2556
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
2557
|
-
const [
|
2558
|
-
{
|
2559
|
-
query: { status }
|
2560
|
-
}
|
2561
|
-
] = useQueryParams({
|
2562
|
-
status: "draft"
|
2563
|
-
});
|
2564
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2565
|
-
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2566
|
-
const props = {
|
2567
|
-
activeTab: status,
|
2568
|
-
model,
|
2569
|
-
documentId: id,
|
2570
|
-
document: isCloning ? void 0 : document,
|
2571
|
-
meta: isCloning ? void 0 : meta,
|
2572
|
-
collectionType
|
2573
|
-
};
|
2574
|
-
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2575
|
-
DescriptionComponentRenderer,
|
2576
|
-
{
|
2577
|
-
props,
|
2578
|
-
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2579
|
-
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2580
|
-
}
|
2581
|
-
) });
|
2582
|
-
};
|
2583
|
-
const ActionsPanel = () => {
|
2584
|
-
const { formatMessage } = useIntl();
|
2585
|
-
return {
|
2586
|
-
title: formatMessage({
|
2587
|
-
id: "content-manager.containers.edit.panels.default.title",
|
2588
|
-
defaultMessage: "Entry"
|
2589
|
-
}),
|
2590
|
-
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2591
|
-
};
|
2592
|
-
};
|
2593
|
-
ActionsPanel.type = "actions";
|
2594
|
-
const ActionsPanelContent = () => {
|
2595
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
2596
|
-
const [
|
2597
|
-
{
|
2598
|
-
query: { status = "draft" }
|
2599
|
-
}
|
2600
|
-
] = useQueryParams();
|
2601
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2602
|
-
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2603
|
-
const props = {
|
2604
|
-
activeTab: status,
|
2605
|
-
model,
|
2606
|
-
documentId: id,
|
2607
|
-
document: isCloning ? void 0 : document,
|
2608
|
-
meta: isCloning ? void 0 : meta,
|
2609
|
-
collectionType
|
2610
|
-
};
|
2611
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2612
|
-
/* @__PURE__ */ jsx(
|
2613
|
-
DescriptionComponentRenderer,
|
2614
|
-
{
|
2615
|
-
props,
|
2616
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2617
|
-
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2618
|
-
}
|
2619
|
-
),
|
2620
|
-
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2621
|
-
] });
|
2622
|
-
};
|
2623
|
-
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2624
|
-
return /* @__PURE__ */ jsxs(
|
2625
|
-
Flex,
|
2626
|
-
{
|
2627
|
-
ref,
|
2628
|
-
tag: "aside",
|
2629
|
-
"aria-labelledby": "additional-information",
|
2630
|
-
background: "neutral0",
|
2631
|
-
borderColor: "neutral150",
|
2632
|
-
hasRadius: true,
|
2633
|
-
paddingBottom: 4,
|
2634
|
-
paddingLeft: 4,
|
2635
|
-
paddingRight: 4,
|
2636
|
-
paddingTop: 4,
|
2637
|
-
shadow: "tableShadow",
|
2638
|
-
gap: 3,
|
2639
|
-
direction: "column",
|
2640
|
-
justifyContent: "stretch",
|
2641
|
-
alignItems: "flex-start",
|
2642
|
-
children: [
|
2643
|
-
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2644
|
-
children
|
2645
|
-
]
|
2646
|
-
}
|
2647
|
-
);
|
2648
|
-
});
|
2649
|
-
const HOOKS = {
|
2650
|
-
/**
|
2651
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2652
|
-
* @constant
|
2653
|
-
* @type {string}
|
2654
|
-
*/
|
2655
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2656
|
-
/**
|
2657
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2658
|
-
* @constant
|
2659
|
-
* @type {string}
|
2660
|
-
*/
|
2661
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2662
|
-
/**
|
2663
|
-
* Hook that allows to mutate the CM's edit view layout
|
2664
|
-
* @constant
|
2665
|
-
* @type {string}
|
2666
|
-
*/
|
2667
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2668
|
-
/**
|
2669
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2670
|
-
* @constant
|
2671
|
-
* @type {string}
|
2672
|
-
*/
|
2673
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2674
|
-
};
|
2675
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2676
|
-
endpoints: (builder) => ({
|
2677
|
-
getContentTypeConfiguration: builder.query({
|
2678
|
-
query: (uid) => ({
|
2679
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2680
|
-
method: "GET"
|
2681
|
-
}),
|
2682
|
-
transformResponse: (response) => response.data,
|
2683
|
-
providesTags: (_result, _error, uid) => [
|
2684
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2685
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
2686
|
-
]
|
2687
|
-
}),
|
2688
|
-
getAllContentTypeSettings: builder.query({
|
2689
|
-
query: () => "/content-manager/content-types-settings",
|
2690
|
-
transformResponse: (response) => response.data,
|
2691
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
2692
|
-
}),
|
2693
|
-
updateContentTypeConfiguration: builder.mutation({
|
2694
|
-
query: ({ uid, ...body }) => ({
|
2695
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2696
|
-
method: "PUT",
|
2697
|
-
data: body
|
2698
|
-
}),
|
2699
|
-
transformResponse: (response) => response.data,
|
2700
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
2701
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2702
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
2703
|
-
// Is this necessary?
|
2704
|
-
{ type: "InitialData" }
|
2705
|
-
]
|
2706
|
-
})
|
2707
|
-
})
|
2708
|
-
});
|
2709
|
-
const {
|
2710
|
-
useGetContentTypeConfigurationQuery,
|
2711
|
-
useGetAllContentTypeSettingsQuery,
|
2712
|
-
useUpdateContentTypeConfigurationMutation
|
2713
|
-
} = contentTypesApi;
|
2714
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
2715
|
-
const { type } = attribute;
|
2716
|
-
if (type === "relation") {
|
2717
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
2718
|
-
}
|
2719
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
2720
|
-
};
|
2721
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
2722
|
-
if (!mainFieldName) {
|
2723
|
-
return void 0;
|
2724
|
-
}
|
2725
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
2726
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
2727
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
2728
|
-
);
|
2729
|
-
return {
|
2730
|
-
name: mainFieldName,
|
2731
|
-
type: mainFieldType ?? "string"
|
2732
|
-
};
|
2733
|
-
};
|
2734
|
-
const DEFAULT_SETTINGS = {
|
2735
|
-
bulkable: false,
|
2736
|
-
filterable: false,
|
2737
|
-
searchable: false,
|
2738
|
-
pagination: false,
|
2739
|
-
defaultSortBy: "",
|
2740
|
-
defaultSortOrder: "asc",
|
2741
|
-
mainField: "id",
|
2742
|
-
pageSize: 10
|
2743
|
-
};
|
2744
|
-
const useDocumentLayout = (model) => {
|
2745
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
2746
|
-
const [{ query }] = useQueryParams();
|
2747
|
-
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
2748
|
-
const { toggleNotification } = useNotification();
|
2749
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
2750
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
2751
|
-
const {
|
2752
|
-
data,
|
2753
|
-
isLoading: isLoadingConfigs,
|
2754
|
-
error,
|
2755
|
-
isFetching: isFetchingConfigs
|
2756
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2757
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2758
|
-
React.useEffect(() => {
|
2759
|
-
if (error) {
|
2760
|
-
toggleNotification({
|
2761
|
-
type: "danger",
|
2762
|
-
message: formatAPIError(error)
|
2763
|
-
});
|
2764
|
-
}
|
2765
|
-
}, [error, formatAPIError, toggleNotification]);
|
2766
|
-
const editLayout = React.useMemo(
|
2767
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2768
|
-
layout: [],
|
2769
|
-
components: {},
|
2770
|
-
metadatas: {},
|
2771
|
-
options: {},
|
2772
|
-
settings: DEFAULT_SETTINGS
|
2773
|
-
},
|
2774
|
-
[data, isLoading, schemas, schema, components]
|
2775
|
-
);
|
2776
|
-
const listLayout = React.useMemo(() => {
|
2777
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2778
|
-
layout: [],
|
2779
|
-
metadatas: {},
|
2780
|
-
options: {},
|
2781
|
-
settings: DEFAULT_SETTINGS
|
2782
|
-
};
|
2783
|
-
}, [data, isLoading, schemas, schema, components]);
|
2784
|
-
const { layout: edit } = React.useMemo(
|
2785
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2786
|
-
layout: editLayout,
|
2787
|
-
query
|
2788
|
-
}),
|
2789
|
-
[editLayout, query, runHookWaterfall]
|
2790
|
-
);
|
2791
|
-
return {
|
2792
|
-
error,
|
2793
|
-
isLoading,
|
2794
|
-
edit,
|
2795
|
-
list: listLayout
|
2796
|
-
};
|
2797
|
-
};
|
2798
|
-
const useDocLayout = () => {
|
2799
|
-
const { model } = useDoc();
|
2800
|
-
return useDocumentLayout(model);
|
2801
|
-
};
|
2802
|
-
const formatEditLayout = (data, {
|
2803
|
-
schemas,
|
2804
|
-
schema,
|
2805
|
-
components
|
2806
|
-
}) => {
|
2807
|
-
let currentPanelIndex = 0;
|
2808
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
2809
|
-
data.contentType.layouts.edit,
|
2810
|
-
schema?.attributes,
|
2811
|
-
data.contentType.metadatas,
|
2812
|
-
{ configurations: data.components, schemas: components },
|
2813
|
-
schemas
|
2814
|
-
).reduce((panels, row) => {
|
2815
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2816
|
-
panels.push([row]);
|
2817
|
-
currentPanelIndex += 2;
|
2818
|
-
} else {
|
2819
|
-
if (!panels[currentPanelIndex]) {
|
2820
|
-
panels.push([]);
|
2821
|
-
}
|
2822
|
-
panels[currentPanelIndex].push(row);
|
2823
|
-
}
|
2824
|
-
return panels;
|
2825
|
-
}, []);
|
2826
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
2827
|
-
(acc, [uid, configuration]) => {
|
2828
|
-
acc[uid] = {
|
2829
|
-
layout: convertEditLayoutToFieldLayouts(
|
2830
|
-
configuration.layouts.edit,
|
2831
|
-
components[uid].attributes,
|
2832
|
-
configuration.metadatas,
|
2833
|
-
{ configurations: data.components, schemas: components }
|
2834
|
-
),
|
2835
|
-
settings: {
|
2836
|
-
...configuration.settings,
|
2837
|
-
icon: components[uid].info.icon,
|
2838
|
-
displayName: components[uid].info.displayName
|
2839
|
-
}
|
2840
|
-
};
|
2841
|
-
return acc;
|
2842
|
-
},
|
2843
|
-
{}
|
2844
|
-
);
|
2845
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2846
|
-
(acc, [attribute, metadata]) => {
|
2847
|
-
return {
|
2848
|
-
...acc,
|
2849
|
-
[attribute]: metadata.edit
|
2850
|
-
};
|
2851
|
-
},
|
2852
|
-
{}
|
2853
|
-
);
|
2832
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2833
|
+
const EditTheModelAction = ({ model }) => {
|
2834
|
+
const navigate = useNavigate();
|
2835
|
+
const { formatMessage } = useIntl();
|
2854
2836
|
return {
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2837
|
+
label: formatMessage({
|
2838
|
+
id: "content-manager.link-to-ctb",
|
2839
|
+
defaultMessage: "Edit the model"
|
2840
|
+
}),
|
2841
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2842
|
+
onClick: () => {
|
2843
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2861
2844
|
},
|
2862
|
-
|
2863
|
-
...schema?.options,
|
2864
|
-
...schema?.pluginOptions,
|
2865
|
-
...data.contentType.options
|
2866
|
-
}
|
2845
|
+
position: "header"
|
2867
2846
|
};
|
2868
2847
|
};
|
2869
|
-
|
2870
|
-
|
2871
|
-
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2848
|
+
EditTheModelAction.type = "edit-the-model";
|
2849
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2850
|
+
const navigate = useNavigate();
|
2851
|
+
const { formatMessage } = useIntl();
|
2852
|
+
const listViewPathMatch = useMatch(LIST_PATH);
|
2853
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2854
|
+
const { delete: deleteAction } = useDocumentActions();
|
2855
|
+
const { toggleNotification } = useNotification();
|
2856
|
+
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2857
|
+
const isLocalized = document?.locale != null;
|
2858
|
+
return {
|
2859
|
+
disabled: !canDelete || !document,
|
2860
|
+
label: formatMessage(
|
2861
|
+
{
|
2862
|
+
id: "content-manager.actions.delete.label",
|
2863
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2864
|
+
},
|
2865
|
+
{ isLocalized }
|
2866
|
+
),
|
2867
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2868
|
+
dialog: {
|
2869
|
+
type: "dialog",
|
2870
|
+
title: formatMessage({
|
2871
|
+
id: "app.components.ConfirmDialog.title",
|
2872
|
+
defaultMessage: "Confirmation"
|
2873
|
+
}),
|
2874
|
+
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2875
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2876
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2877
|
+
id: "content-manager.actions.delete.dialog.body",
|
2878
|
+
defaultMessage: "Are you sure?"
|
2879
|
+
}) })
|
2880
|
+
] }),
|
2881
|
+
onConfirm: async () => {
|
2882
|
+
if (!listViewPathMatch) {
|
2883
|
+
setSubmitting(true);
|
2884
|
+
}
|
2885
|
+
try {
|
2886
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2887
|
+
console.error(
|
2888
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2889
|
+
);
|
2890
|
+
toggleNotification({
|
2891
|
+
message: formatMessage({
|
2892
|
+
id: "content-manager.actions.delete.error",
|
2893
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2894
|
+
}),
|
2895
|
+
type: "danger"
|
2896
|
+
});
|
2897
|
+
return;
|
2898
|
+
}
|
2899
|
+
const res = await deleteAction({
|
2900
|
+
documentId,
|
2901
|
+
model,
|
2902
|
+
collectionType,
|
2903
|
+
params: {
|
2904
|
+
locale: "*"
|
2905
|
+
}
|
2906
|
+
});
|
2907
|
+
if (!("error" in res)) {
|
2908
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2909
|
+
}
|
2910
|
+
} finally {
|
2911
|
+
if (!listViewPathMatch) {
|
2912
|
+
setSubmitting(false);
|
2913
|
+
}
|
2914
|
+
}
|
2875
2915
|
}
|
2876
|
-
const { edit: metadata } = metadatas[field.name];
|
2877
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2878
|
-
return {
|
2879
|
-
attribute,
|
2880
|
-
disabled: !metadata.editable,
|
2881
|
-
hint: metadata.description,
|
2882
|
-
label: metadata.label ?? "",
|
2883
|
-
name: field.name,
|
2884
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2885
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2886
|
-
schemas,
|
2887
|
-
components: components?.schemas ?? {}
|
2888
|
-
}),
|
2889
|
-
placeholder: metadata.placeholder ?? "",
|
2890
|
-
required: attribute.required ?? false,
|
2891
|
-
size: field.size,
|
2892
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2893
|
-
visible: metadata.visible ?? true,
|
2894
|
-
type: attribute.type
|
2895
|
-
};
|
2896
|
-
}).filter((field) => field !== null)
|
2897
|
-
);
|
2898
|
-
};
|
2899
|
-
const formatListLayout = (data, {
|
2900
|
-
schemas,
|
2901
|
-
schema,
|
2902
|
-
components
|
2903
|
-
}) => {
|
2904
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2905
|
-
(acc, [attribute, metadata]) => {
|
2906
|
-
return {
|
2907
|
-
...acc,
|
2908
|
-
[attribute]: metadata.list
|
2909
|
-
};
|
2910
2916
|
},
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2917
|
+
variant: "danger",
|
2918
|
+
position: ["header", "table-row"]
|
2919
|
+
};
|
2920
|
+
};
|
2921
|
+
DeleteAction$1.type = "delete";
|
2922
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2923
|
+
const Panels = () => {
|
2924
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2925
|
+
const [
|
2926
|
+
{
|
2927
|
+
query: { status }
|
2928
|
+
}
|
2929
|
+
] = useQueryParams({
|
2930
|
+
status: "draft"
|
2931
|
+
});
|
2932
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2933
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2934
|
+
const props = {
|
2935
|
+
activeTab: status,
|
2936
|
+
model,
|
2937
|
+
documentId: id,
|
2938
|
+
document: isCloning ? void 0 : document,
|
2939
|
+
meta: isCloning ? void 0 : meta,
|
2940
|
+
collectionType
|
2941
|
+
};
|
2942
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2943
|
+
DescriptionComponentRenderer,
|
2944
|
+
{
|
2945
|
+
props,
|
2946
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2947
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2928
2948
|
}
|
2949
|
+
) });
|
2950
|
+
};
|
2951
|
+
const ActionsPanel = () => {
|
2952
|
+
const { formatMessage } = useIntl();
|
2953
|
+
return {
|
2954
|
+
title: formatMessage({
|
2955
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2956
|
+
defaultMessage: "Entry"
|
2957
|
+
}),
|
2958
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2929
2959
|
};
|
2930
2960
|
};
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2961
|
+
ActionsPanel.type = "actions";
|
2962
|
+
const ActionsPanelContent = () => {
|
2963
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2964
|
+
const [
|
2965
|
+
{
|
2966
|
+
query: { status = "draft" }
|
2936
2967
|
}
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2968
|
+
] = useQueryParams();
|
2969
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2970
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2971
|
+
const props = {
|
2972
|
+
activeTab: status,
|
2973
|
+
model,
|
2974
|
+
documentId: id,
|
2975
|
+
document: isCloning ? void 0 : document,
|
2976
|
+
meta: isCloning ? void 0 : meta,
|
2977
|
+
collectionType
|
2978
|
+
};
|
2979
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2980
|
+
/* @__PURE__ */ jsx(
|
2981
|
+
DescriptionComponentRenderer,
|
2982
|
+
{
|
2983
|
+
props,
|
2984
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2985
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2986
|
+
}
|
2987
|
+
),
|
2988
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2989
|
+
] });
|
2951
2990
|
};
|
2991
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2992
|
+
return /* @__PURE__ */ jsxs(
|
2993
|
+
Flex,
|
2994
|
+
{
|
2995
|
+
ref,
|
2996
|
+
tag: "aside",
|
2997
|
+
"aria-labelledby": "additional-information",
|
2998
|
+
background: "neutral0",
|
2999
|
+
borderColor: "neutral150",
|
3000
|
+
hasRadius: true,
|
3001
|
+
paddingBottom: 4,
|
3002
|
+
paddingLeft: 4,
|
3003
|
+
paddingRight: 4,
|
3004
|
+
paddingTop: 4,
|
3005
|
+
shadow: "tableShadow",
|
3006
|
+
gap: 3,
|
3007
|
+
direction: "column",
|
3008
|
+
justifyContent: "stretch",
|
3009
|
+
alignItems: "flex-start",
|
3010
|
+
children: [
|
3011
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3012
|
+
children
|
3013
|
+
]
|
3014
|
+
}
|
3015
|
+
);
|
3016
|
+
});
|
2952
3017
|
const ConfirmBulkActionDialog = ({
|
2953
3018
|
onToggleDialog,
|
2954
3019
|
isOpen = false,
|
@@ -3945,7 +4010,7 @@ const index = {
|
|
3945
4010
|
app.router.addRoute({
|
3946
4011
|
path: "content-manager/*",
|
3947
4012
|
lazy: async () => {
|
3948
|
-
const { Layout } = await import("./layout-
|
4013
|
+
const { Layout } = await import("./layout-DZAT9E_K.mjs");
|
3949
4014
|
return {
|
3950
4015
|
Component: Layout
|
3951
4016
|
};
|
@@ -3962,7 +4027,7 @@ const index = {
|
|
3962
4027
|
async registerTrads({ locales }) {
|
3963
4028
|
const importedTrads = await Promise.all(
|
3964
4029
|
locales.map((locale) => {
|
3965
|
-
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-
|
4030
|
+
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 }) => {
|
3966
4031
|
return {
|
3967
4032
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3968
4033
|
locale
|
@@ -3990,7 +4055,8 @@ export {
|
|
3990
4055
|
InjectionZone as I,
|
3991
4056
|
useDocument as J,
|
3992
4057
|
index as K,
|
3993
|
-
|
4058
|
+
useContentManagerContext as L,
|
4059
|
+
useDocumentActions as M,
|
3994
4060
|
Panels as P,
|
3995
4061
|
RelativeTime as R,
|
3996
4062
|
SINGLE_TYPES as S,
|
@@ -4022,4 +4088,4 @@ export {
|
|
4022
4088
|
capitalise as y,
|
4023
4089
|
useUpdateContentTypeConfigurationMutation as z
|
4024
4090
|
};
|
4025
|
-
//# sourceMappingURL=index-
|
4091
|
+
//# sourceMappingURL=index-D1ol0KTz.mjs.map
|