@strapi/content-manager 0.0.0-experimental.3fd705928266d1b836afc8a30fceb35aac0ae2f8 → 0.0.0-experimental.438960f273755509510c3610187d9deb520ba2a0
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-_zF8p6CY.js → ComponentConfigurationPage-3feZ0gyp.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-_zF8p6CY.js.map → ComponentConfigurationPage-3feZ0gyp.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs → ComponentConfigurationPage-DkUdgHD9.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs.map → ComponentConfigurationPage-DkUdgHD9.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js → EditConfigurationPage-B0KA-x9U.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js.map → EditConfigurationPage-B0KA-x9U.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs → EditConfigurationPage-Ox5wFgpq.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs.map → EditConfigurationPage-Ox5wFgpq.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-G9uNzwYL.js → EditViewPage-OMv9CogC.js} +15 -5
- package/dist/_chunks/EditViewPage-OMv9CogC.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DeTn7rAF.mjs → EditViewPage-foKE8Al3.mjs} +15 -5
- package/dist/_chunks/EditViewPage-foKE8Al3.mjs.map +1 -0
- package/dist/_chunks/{Field-CnCKhI1R.mjs → Field-CLqZcnnc.mjs} +69 -25
- package/dist/_chunks/Field-CLqZcnnc.mjs.map +1 -0
- package/dist/_chunks/{Field-DDHUWEfV.js → Field-u09MCk3G.js} +69 -25
- package/dist/_chunks/Field-u09MCk3G.js.map +1 -0
- package/dist/_chunks/{Form-DYETaKUX.js → Form-B9c_Ti0q.js} +3 -3
- package/dist/_chunks/Form-B9c_Ti0q.js.map +1 -0
- package/dist/_chunks/{Form-IvVVwqRL.mjs → Form-CU4hRyJf.mjs} +3 -3
- package/dist/_chunks/Form-CU4hRyJf.mjs.map +1 -0
- package/dist/_chunks/{History-BMunT-do.mjs → History-BFyFzpSS.mjs} +25 -12
- package/dist/_chunks/History-BFyFzpSS.mjs.map +1 -0
- package/dist/_chunks/{History-CnZDctSO.js → History-OlickLyX.js} +24 -11
- package/dist/_chunks/History-OlickLyX.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs → ListConfigurationPage-Bu5Z_39o.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs.map → ListConfigurationPage-Bu5Z_39o.mjs.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-BynalOp8.js → ListConfigurationPage-D0AAi_cW.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-BynalOp8.js.map → ListConfigurationPage-D0AAi_cW.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-I88Ouzoq.js → ListViewPage--lV5p8Qi.js} +10 -6
- package/dist/_chunks/ListViewPage--lV5p8Qi.js.map +1 -0
- package/dist/_chunks/{ListViewPage-_5gS-DOF.mjs → ListViewPage-BAHxSPux.mjs} +10 -6
- package/dist/_chunks/ListViewPage-BAHxSPux.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs → NoContentTypePage-C6SMXW77.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs.map → NoContentTypePage-C6SMXW77.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js → NoContentTypePage-Dxl9oZqL.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js.map → NoContentTypePage-Dxl9oZqL.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js → NoPermissionsPage-BY1-rMng.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js.map → NoPermissionsPage-BY1-rMng.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs → NoPermissionsPage-o9BXzQeI.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs.map → NoPermissionsPage-o9BXzQeI.mjs.map} +1 -1
- package/dist/_chunks/{Relations-Chdt5qWc.mjs → Relations-BAK95JHc.mjs} +32 -23
- package/dist/_chunks/Relations-BAK95JHc.mjs.map +1 -0
- package/dist/_chunks/{Relations-BPgFQeGj.js → Relations-CHfwGkBG.js} +32 -23
- package/dist/_chunks/Relations-CHfwGkBG.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-D4UGPFZC.mjs → index-CxlpxzA5.mjs} +940 -863
- package/dist/_chunks/index-CxlpxzA5.mjs.map +1 -0
- package/dist/_chunks/{index-BhbLFX4l.js → index-_Mlmsefd.js} +938 -861
- package/dist/_chunks/index-_Mlmsefd.js.map +1 -0
- package/dist/_chunks/{layout-D4HI4_PS.mjs → layout-Cr0H40au.mjs} +3 -3
- package/dist/_chunks/{layout-D4HI4_PS.mjs.map → layout-Cr0H40au.mjs.map} +1 -1
- package/dist/_chunks/{layout-CYA7s0qO.js → layout-vcHVgSr1.js} +3 -3
- package/dist/_chunks/{layout-CYA7s0qO.js.map → layout-vcHVgSr1.js.map} +1 -1
- package/dist/_chunks/{relations-1pXaYpBK.mjs → relations-Dq60voyX.mjs} +2 -2
- package/dist/_chunks/{relations-1pXaYpBK.mjs.map → relations-Dq60voyX.mjs.map} +1 -1
- package/dist/_chunks/{relations-DDZ9OxNo.js → relations-hXUB80SH.js} +2 -2
- package/dist/_chunks/{relations-DDZ9OxNo.js.map → relations-hXUB80SH.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/admin/src/preview/constants.d.ts +1 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/server/index.js +45 -18
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +45 -18
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/preview/constants.d.ts +2 -0
- package/dist/server/src/preview/constants.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/package.json +12 -12
- package/dist/_chunks/EditViewPage-DeTn7rAF.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-G9uNzwYL.js.map +0 -1
- package/dist/_chunks/Field-CnCKhI1R.mjs.map +0 -1
- package/dist/_chunks/Field-DDHUWEfV.js.map +0 -1
- package/dist/_chunks/Form-DYETaKUX.js.map +0 -1
- package/dist/_chunks/Form-IvVVwqRL.mjs.map +0 -1
- package/dist/_chunks/History-BMunT-do.mjs.map +0 -1
- package/dist/_chunks/History-CnZDctSO.js.map +0 -1
- package/dist/_chunks/ListViewPage-I88Ouzoq.js.map +0 -1
- package/dist/_chunks/ListViewPage-_5gS-DOF.mjs.map +0 -1
- package/dist/_chunks/Relations-BPgFQeGj.js.map +0 -1
- package/dist/_chunks/Relations-Chdt5qWc.mjs.map +0 -1
- package/dist/_chunks/index-BhbLFX4l.js.map +0 -1
- package/dist/_chunks/index-D4UGPFZC.mjs.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,398 +913,656 @@ 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
|
-
type: "danger",
|
904
|
-
message: formatAPIError(res.error)
|
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([]);
|
924
972
|
}
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
const
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
});
|
943
|
-
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
|
944
990
|
}
|
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
|
-
}
|
991
|
+
};
|
992
|
+
return acc;
|
963
993
|
},
|
964
|
-
|
994
|
+
{}
|
965
995
|
);
|
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
|
-
}
|
996
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
997
|
+
(acc, [attribute, metadata]) => {
|
998
|
+
return {
|
999
|
+
...acc,
|
1000
|
+
[attribute]: metadata.edit
|
1001
|
+
};
|
998
1002
|
},
|
999
|
-
|
1003
|
+
{}
|
1000
1004
|
);
|
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
|
-
}
|
1005
|
+
return {
|
1006
|
+
layout: panelledEditAttributes,
|
1007
|
+
components: componentEditAttributes,
|
1008
|
+
metadatas: editMetadatas,
|
1009
|
+
settings: {
|
1010
|
+
...data.contentType.settings,
|
1011
|
+
displayName: schema?.info.displayName
|
1033
1012
|
},
|
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;
|
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;
|
1063
1026
|
}
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
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)
|
1072
1048
|
);
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
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);
|
1089
1148
|
}
|
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;
|
1149
|
+
throw error2;
|
1106
1150
|
}
|
1107
1151
|
},
|
1108
|
-
[
|
1152
|
+
[validationSchema]
|
1109
1153
|
);
|
1110
|
-
const
|
1111
|
-
const
|
1112
|
-
|
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
|
+
if (!pluginId) {
|
1232
|
+
throw new TypeError("pluginId can't be empty");
|
1233
|
+
}
|
1234
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1235
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1236
|
+
return acc;
|
1237
|
+
}, {});
|
1238
|
+
};
|
1239
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1240
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1241
|
+
id: "notification.error",
|
1242
|
+
defaultMessage: "An error occurred, please try again"
|
1243
|
+
};
|
1244
|
+
const useDocumentActions = () => {
|
1245
|
+
const { toggleNotification } = useNotification();
|
1246
|
+
const { formatMessage } = useIntl();
|
1247
|
+
const { trackUsage } = useTracking();
|
1248
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1249
|
+
const navigate = useNavigate();
|
1250
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1251
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1252
|
+
const _delete = React.useCallback(
|
1253
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1113
1254
|
try {
|
1114
|
-
trackUsage("
|
1115
|
-
const res = await
|
1255
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1256
|
+
const res = await deleteDocument({
|
1116
1257
|
collectionType,
|
1117
1258
|
model,
|
1118
1259
|
documentId,
|
1119
|
-
params
|
1120
|
-
data: {
|
1121
|
-
discardDraft
|
1122
|
-
}
|
1260
|
+
params
|
1123
1261
|
});
|
1124
1262
|
if ("error" in res) {
|
1125
|
-
toggleNotification({
|
1263
|
+
toggleNotification({
|
1264
|
+
type: "danger",
|
1265
|
+
message: formatAPIError(res.error)
|
1266
|
+
});
|
1126
1267
|
return { error: res.error };
|
1127
1268
|
}
|
1128
|
-
trackUsage("didUnpublishEntry");
|
1129
1269
|
toggleNotification({
|
1130
1270
|
type: "success",
|
1131
1271
|
message: formatMessage({
|
1132
|
-
id: getTranslation("success.record.
|
1133
|
-
defaultMessage: "
|
1272
|
+
id: getTranslation("success.record.delete"),
|
1273
|
+
defaultMessage: "Deleted document"
|
1134
1274
|
})
|
1135
1275
|
});
|
1276
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1136
1277
|
return res.data;
|
1137
1278
|
} catch (err) {
|
1138
1279
|
toggleNotification({
|
1139
1280
|
type: "danger",
|
1140
1281
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1141
1282
|
});
|
1283
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1142
1284
|
throw err;
|
1143
1285
|
}
|
1144
1286
|
},
|
1145
|
-
[trackUsage,
|
1287
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1146
1288
|
);
|
1147
|
-
const [
|
1148
|
-
const
|
1289
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1290
|
+
const deleteMany = React.useCallback(
|
1149
1291
|
async ({ model, documentIds, params }) => {
|
1150
1292
|
try {
|
1151
|
-
trackUsage("
|
1152
|
-
const res = await
|
1293
|
+
trackUsage("willBulkDeleteEntries");
|
1294
|
+
const res = await deleteManyDocuments({
|
1153
1295
|
model,
|
1154
1296
|
documentIds,
|
1155
1297
|
params
|
1156
1298
|
});
|
1157
1299
|
if ("error" in res) {
|
1158
|
-
toggleNotification({
|
1300
|
+
toggleNotification({
|
1301
|
+
type: "danger",
|
1302
|
+
message: formatAPIError(res.error)
|
1303
|
+
});
|
1159
1304
|
return { error: res.error };
|
1160
1305
|
}
|
1161
|
-
trackUsage("didBulkUnpublishEntries");
|
1162
1306
|
toggleNotification({
|
1163
1307
|
type: "success",
|
1164
1308
|
title: formatMessage({
|
1165
|
-
id: getTranslation("success.records.
|
1166
|
-
defaultMessage: "Successfully
|
1309
|
+
id: getTranslation("success.records.delete"),
|
1310
|
+
defaultMessage: "Successfully deleted."
|
1167
1311
|
}),
|
1168
1312
|
message: ""
|
1169
1313
|
});
|
1314
|
+
trackUsage("didBulkDeleteEntries");
|
1170
1315
|
return res.data;
|
1171
1316
|
} catch (err) {
|
1172
1317
|
toggleNotification({
|
1173
1318
|
type: "danger",
|
1174
1319
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1175
1320
|
});
|
1176
|
-
trackUsage("
|
1321
|
+
trackUsage("didNotBulkDeleteEntries");
|
1177
1322
|
throw err;
|
1178
1323
|
}
|
1179
1324
|
},
|
1180
|
-
[trackUsage,
|
1325
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1181
1326
|
);
|
1182
|
-
const [
|
1183
|
-
const
|
1184
|
-
async ({ model, params }
|
1327
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1328
|
+
const discard = React.useCallback(
|
1329
|
+
async ({ collectionType, model, documentId, params }) => {
|
1185
1330
|
try {
|
1186
|
-
const res = await
|
1331
|
+
const res = await discardDocument({
|
1332
|
+
collectionType,
|
1187
1333
|
model,
|
1188
|
-
|
1334
|
+
documentId,
|
1189
1335
|
params
|
1190
1336
|
});
|
1191
1337
|
if ("error" in res) {
|
1192
|
-
toggleNotification({
|
1193
|
-
|
1338
|
+
toggleNotification({
|
1339
|
+
type: "danger",
|
1340
|
+
message: formatAPIError(res.error)
|
1341
|
+
});
|
1194
1342
|
return { error: res.error };
|
1195
1343
|
}
|
1196
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1197
1344
|
toggleNotification({
|
1198
1345
|
type: "success",
|
1199
1346
|
message: formatMessage({
|
1200
|
-
id:
|
1201
|
-
defaultMessage: "
|
1347
|
+
id: "content-manager.success.record.discard",
|
1348
|
+
defaultMessage: "Changes discarded"
|
1349
|
+
})
|
1350
|
+
});
|
1351
|
+
return res.data;
|
1352
|
+
} catch (err) {
|
1353
|
+
toggleNotification({
|
1354
|
+
type: "danger",
|
1355
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1356
|
+
});
|
1357
|
+
throw err;
|
1358
|
+
}
|
1359
|
+
},
|
1360
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1361
|
+
);
|
1362
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1363
|
+
const publish = React.useCallback(
|
1364
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1365
|
+
try {
|
1366
|
+
trackUsage("willPublishEntry");
|
1367
|
+
const res = await publishDocument({
|
1368
|
+
collectionType,
|
1369
|
+
model,
|
1370
|
+
documentId,
|
1371
|
+
data,
|
1372
|
+
params
|
1373
|
+
});
|
1374
|
+
if ("error" in res) {
|
1375
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1376
|
+
return { error: res.error };
|
1377
|
+
}
|
1378
|
+
trackUsage("didPublishEntry");
|
1379
|
+
toggleNotification({
|
1380
|
+
type: "success",
|
1381
|
+
message: formatMessage({
|
1382
|
+
id: getTranslation("success.record.publish"),
|
1383
|
+
defaultMessage: "Published document"
|
1384
|
+
})
|
1385
|
+
});
|
1386
|
+
return res.data;
|
1387
|
+
} catch (err) {
|
1388
|
+
toggleNotification({
|
1389
|
+
type: "danger",
|
1390
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1391
|
+
});
|
1392
|
+
throw err;
|
1393
|
+
}
|
1394
|
+
},
|
1395
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1396
|
+
);
|
1397
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1398
|
+
const publishMany = React.useCallback(
|
1399
|
+
async ({ model, documentIds, params }) => {
|
1400
|
+
try {
|
1401
|
+
const res = await publishManyDocuments({
|
1402
|
+
model,
|
1403
|
+
documentIds,
|
1404
|
+
params
|
1405
|
+
});
|
1406
|
+
if ("error" in res) {
|
1407
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1408
|
+
return { error: res.error };
|
1409
|
+
}
|
1410
|
+
toggleNotification({
|
1411
|
+
type: "success",
|
1412
|
+
message: formatMessage({
|
1413
|
+
id: getTranslation("success.record.publish"),
|
1414
|
+
defaultMessage: "Published document"
|
1415
|
+
})
|
1416
|
+
});
|
1417
|
+
return res.data;
|
1418
|
+
} catch (err) {
|
1419
|
+
toggleNotification({
|
1420
|
+
type: "danger",
|
1421
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1422
|
+
});
|
1423
|
+
throw err;
|
1424
|
+
}
|
1425
|
+
},
|
1426
|
+
[
|
1427
|
+
// trackUsage,
|
1428
|
+
publishManyDocuments,
|
1429
|
+
toggleNotification,
|
1430
|
+
formatMessage,
|
1431
|
+
formatAPIError
|
1432
|
+
]
|
1433
|
+
);
|
1434
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1435
|
+
const update = React.useCallback(
|
1436
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1437
|
+
try {
|
1438
|
+
trackUsage("willEditEntry", trackerProperty);
|
1439
|
+
const res = await updateDocument({
|
1440
|
+
collectionType,
|
1441
|
+
model,
|
1442
|
+
documentId,
|
1443
|
+
data,
|
1444
|
+
params
|
1445
|
+
});
|
1446
|
+
if ("error" in res) {
|
1447
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1448
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1449
|
+
return { error: res.error };
|
1450
|
+
}
|
1451
|
+
trackUsage("didEditEntry", trackerProperty);
|
1452
|
+
toggleNotification({
|
1453
|
+
type: "success",
|
1454
|
+
message: formatMessage({
|
1455
|
+
id: getTranslation("success.record.save"),
|
1456
|
+
defaultMessage: "Saved document"
|
1457
|
+
})
|
1458
|
+
});
|
1459
|
+
return res.data;
|
1460
|
+
} catch (err) {
|
1461
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1462
|
+
toggleNotification({
|
1463
|
+
type: "danger",
|
1464
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1465
|
+
});
|
1466
|
+
throw err;
|
1467
|
+
}
|
1468
|
+
},
|
1469
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1470
|
+
);
|
1471
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1472
|
+
const unpublish = React.useCallback(
|
1473
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1474
|
+
try {
|
1475
|
+
trackUsage("willUnpublishEntry");
|
1476
|
+
const res = await unpublishDocument({
|
1477
|
+
collectionType,
|
1478
|
+
model,
|
1479
|
+
documentId,
|
1480
|
+
params,
|
1481
|
+
data: {
|
1482
|
+
discardDraft
|
1483
|
+
}
|
1484
|
+
});
|
1485
|
+
if ("error" in res) {
|
1486
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1487
|
+
return { error: res.error };
|
1488
|
+
}
|
1489
|
+
trackUsage("didUnpublishEntry");
|
1490
|
+
toggleNotification({
|
1491
|
+
type: "success",
|
1492
|
+
message: formatMessage({
|
1493
|
+
id: getTranslation("success.record.unpublish"),
|
1494
|
+
defaultMessage: "Unpublished document"
|
1495
|
+
})
|
1496
|
+
});
|
1497
|
+
return res.data;
|
1498
|
+
} catch (err) {
|
1499
|
+
toggleNotification({
|
1500
|
+
type: "danger",
|
1501
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1502
|
+
});
|
1503
|
+
throw err;
|
1504
|
+
}
|
1505
|
+
},
|
1506
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1507
|
+
);
|
1508
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1509
|
+
const unpublishMany = React.useCallback(
|
1510
|
+
async ({ model, documentIds, params }) => {
|
1511
|
+
try {
|
1512
|
+
trackUsage("willBulkUnpublishEntries");
|
1513
|
+
const res = await unpublishManyDocuments({
|
1514
|
+
model,
|
1515
|
+
documentIds,
|
1516
|
+
params
|
1517
|
+
});
|
1518
|
+
if ("error" in res) {
|
1519
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1520
|
+
return { error: res.error };
|
1521
|
+
}
|
1522
|
+
trackUsage("didBulkUnpublishEntries");
|
1523
|
+
toggleNotification({
|
1524
|
+
type: "success",
|
1525
|
+
title: formatMessage({
|
1526
|
+
id: getTranslation("success.records.unpublish"),
|
1527
|
+
defaultMessage: "Successfully unpublished."
|
1528
|
+
}),
|
1529
|
+
message: ""
|
1530
|
+
});
|
1531
|
+
return res.data;
|
1532
|
+
} catch (err) {
|
1533
|
+
toggleNotification({
|
1534
|
+
type: "danger",
|
1535
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1536
|
+
});
|
1537
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1538
|
+
throw err;
|
1539
|
+
}
|
1540
|
+
},
|
1541
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1542
|
+
);
|
1543
|
+
const [createDocument] = useCreateDocumentMutation();
|
1544
|
+
const create = React.useCallback(
|
1545
|
+
async ({ model, params }, data, trackerProperty) => {
|
1546
|
+
try {
|
1547
|
+
const res = await createDocument({
|
1548
|
+
model,
|
1549
|
+
data,
|
1550
|
+
params
|
1551
|
+
});
|
1552
|
+
if ("error" in res) {
|
1553
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1554
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1555
|
+
return { error: res.error };
|
1556
|
+
}
|
1557
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1558
|
+
toggleNotification({
|
1559
|
+
type: "success",
|
1560
|
+
message: formatMessage({
|
1561
|
+
id: getTranslation("success.record.save"),
|
1562
|
+
defaultMessage: "Saved document"
|
1202
1563
|
})
|
1203
1564
|
});
|
1565
|
+
setCurrentStep("contentManager.success");
|
1204
1566
|
return res.data;
|
1205
1567
|
} catch (err) {
|
1206
1568
|
toggleNotification({
|
@@ -1303,7 +1665,7 @@ const useDocumentActions = () => {
|
|
1303
1665
|
};
|
1304
1666
|
};
|
1305
1667
|
const ProtectedHistoryPage = lazy(
|
1306
|
-
() => import("./History-
|
1668
|
+
() => import("./History-BFyFzpSS.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1307
1669
|
);
|
1308
1670
|
const routes$1 = [
|
1309
1671
|
{
|
@@ -1316,31 +1678,31 @@ const routes$1 = [
|
|
1316
1678
|
}
|
1317
1679
|
];
|
1318
1680
|
const ProtectedEditViewPage = lazy(
|
1319
|
-
() => import("./EditViewPage-
|
1681
|
+
() => import("./EditViewPage-foKE8Al3.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1320
1682
|
);
|
1321
1683
|
const ProtectedListViewPage = lazy(
|
1322
|
-
() => import("./ListViewPage-
|
1684
|
+
() => import("./ListViewPage-BAHxSPux.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1323
1685
|
);
|
1324
1686
|
const ProtectedListConfiguration = lazy(
|
1325
|
-
() => import("./ListConfigurationPage-
|
1687
|
+
() => import("./ListConfigurationPage-Bu5Z_39o.mjs").then((mod) => ({
|
1326
1688
|
default: mod.ProtectedListConfiguration
|
1327
1689
|
}))
|
1328
1690
|
);
|
1329
1691
|
const ProtectedEditConfigurationPage = lazy(
|
1330
|
-
() => import("./EditConfigurationPage-
|
1692
|
+
() => import("./EditConfigurationPage-Ox5wFgpq.mjs").then((mod) => ({
|
1331
1693
|
default: mod.ProtectedEditConfigurationPage
|
1332
1694
|
}))
|
1333
1695
|
);
|
1334
1696
|
const ProtectedComponentConfigurationPage = lazy(
|
1335
|
-
() => import("./ComponentConfigurationPage-
|
1697
|
+
() => import("./ComponentConfigurationPage-DkUdgHD9.mjs").then((mod) => ({
|
1336
1698
|
default: mod.ProtectedComponentConfigurationPage
|
1337
1699
|
}))
|
1338
1700
|
);
|
1339
1701
|
const NoPermissions = lazy(
|
1340
|
-
() => import("./NoPermissionsPage-
|
1702
|
+
() => import("./NoPermissionsPage-o9BXzQeI.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1341
1703
|
);
|
1342
1704
|
const NoContentType = lazy(
|
1343
|
-
() => import("./NoContentTypePage-
|
1705
|
+
() => import("./NoContentTypePage-C6SMXW77.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1344
1706
|
);
|
1345
1707
|
const CollectionTypePages = () => {
|
1346
1708
|
const { collectionType } = useParams();
|
@@ -1539,7 +1901,7 @@ const DocumentActionsMenu = ({
|
|
1539
1901
|
]
|
1540
1902
|
}
|
1541
1903
|
),
|
1542
|
-
/* @__PURE__ */ jsxs(Menu.Content, {
|
1904
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1543
1905
|
actions2.map((action) => {
|
1544
1906
|
return /* @__PURE__ */ jsx(
|
1545
1907
|
Menu.Item,
|
@@ -1787,7 +2149,9 @@ const PublishAction$1 = ({
|
|
1787
2149
|
const performPublish = async () => {
|
1788
2150
|
setSubmitting(true);
|
1789
2151
|
try {
|
1790
|
-
const { errors } = await validate(
|
2152
|
+
const { errors } = await validate(true, {
|
2153
|
+
status: "published"
|
2154
|
+
});
|
1791
2155
|
if (errors) {
|
1792
2156
|
toggleNotification({
|
1793
2157
|
type: "danger",
|
@@ -1901,18 +2265,18 @@ const UpdateAction = ({
|
|
1901
2265
|
onClick: async () => {
|
1902
2266
|
setSubmitting(true);
|
1903
2267
|
try {
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
})
|
1914
|
-
|
1915
|
-
|
2268
|
+
const { errors } = await validate(true, {
|
2269
|
+
status: "draft"
|
2270
|
+
});
|
2271
|
+
if (errors) {
|
2272
|
+
toggleNotification({
|
2273
|
+
type: "danger",
|
2274
|
+
message: formatMessage({
|
2275
|
+
id: "content-manager.validation.error",
|
2276
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2277
|
+
})
|
2278
|
+
});
|
2279
|
+
return;
|
1916
2280
|
}
|
1917
2281
|
if (isCloning) {
|
1918
2282
|
const res = await clone(
|
@@ -2294,12 +2658,12 @@ const Information = ({ activeTab }) => {
|
|
2294
2658
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2295
2659
|
label: formatMessage({
|
2296
2660
|
id: "content-manager.containers.edit.information.last-published.label",
|
2297
|
-
defaultMessage: "
|
2661
|
+
defaultMessage: "Published"
|
2298
2662
|
}),
|
2299
2663
|
value: formatMessage(
|
2300
2664
|
{
|
2301
2665
|
id: "content-manager.containers.edit.information.last-published.value",
|
2302
|
-
defaultMessage: `
|
2666
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2303
2667
|
},
|
2304
2668
|
{
|
2305
2669
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2312,12 +2676,12 @@ const Information = ({ activeTab }) => {
|
|
2312
2676
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2313
2677
|
label: formatMessage({
|
2314
2678
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2315
|
-
defaultMessage: "
|
2679
|
+
defaultMessage: "Updated"
|
2316
2680
|
}),
|
2317
2681
|
value: formatMessage(
|
2318
2682
|
{
|
2319
2683
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2320
|
-
defaultMessage: `
|
2684
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2321
2685
|
},
|
2322
2686
|
{
|
2323
2687
|
time: /* @__PURE__ */ jsx(
|
@@ -2335,12 +2699,12 @@ const Information = ({ activeTab }) => {
|
|
2335
2699
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2336
2700
|
label: formatMessage({
|
2337
2701
|
id: "content-manager.containers.edit.information.document.label",
|
2338
|
-
defaultMessage: "
|
2702
|
+
defaultMessage: "Created"
|
2339
2703
|
}),
|
2340
2704
|
value: formatMessage(
|
2341
2705
|
{
|
2342
2706
|
id: "content-manager.containers.edit.information.document.value",
|
2343
|
-
defaultMessage: `
|
2707
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2344
2708
|
},
|
2345
2709
|
{
|
2346
2710
|
time: /* @__PURE__ */ jsx(
|
@@ -2398,10 +2762,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2398
2762
|
SingleSelect,
|
2399
2763
|
{
|
2400
2764
|
size: "S",
|
2401
|
-
disabled: action.disabled,
|
2402
|
-
"aria-label": action.label,
|
2403
2765
|
onChange: action.onSelect,
|
2404
|
-
|
2766
|
+
"aria-label": action.label,
|
2767
|
+
...action,
|
2405
2768
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2406
2769
|
},
|
2407
2770
|
action.id
|
@@ -2470,485 +2833,186 @@ const EditTheModelAction = ({ model }) => {
|
|
2470
2833
|
const navigate = useNavigate();
|
2471
2834
|
const { formatMessage } = useIntl();
|
2472
2835
|
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
|
-
);
|
2854
|
-
return {
|
2855
|
-
layout: panelledEditAttributes,
|
2856
|
-
components: componentEditAttributes,
|
2857
|
-
metadatas: editMetadatas,
|
2858
|
-
settings: {
|
2859
|
-
...data.contentType.settings,
|
2860
|
-
displayName: schema?.info.displayName
|
2836
|
+
label: formatMessage({
|
2837
|
+
id: "content-manager.link-to-ctb",
|
2838
|
+
defaultMessage: "Edit the model"
|
2839
|
+
}),
|
2840
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2841
|
+
onClick: () => {
|
2842
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2861
2843
|
},
|
2862
|
-
|
2863
|
-
...schema?.options,
|
2864
|
-
...schema?.pluginOptions,
|
2865
|
-
...data.contentType.options
|
2866
|
-
}
|
2844
|
+
position: "header"
|
2867
2845
|
};
|
2868
2846
|
};
|
2869
|
-
|
2870
|
-
|
2871
|
-
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2847
|
+
EditTheModelAction.type = "edit-the-model";
|
2848
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2849
|
+
const navigate = useNavigate();
|
2850
|
+
const { formatMessage } = useIntl();
|
2851
|
+
const listViewPathMatch = useMatch(LIST_PATH);
|
2852
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2853
|
+
const { delete: deleteAction } = useDocumentActions();
|
2854
|
+
const { toggleNotification } = useNotification();
|
2855
|
+
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2856
|
+
const isLocalized = document?.locale != null;
|
2857
|
+
return {
|
2858
|
+
disabled: !canDelete || !document,
|
2859
|
+
label: formatMessage(
|
2860
|
+
{
|
2861
|
+
id: "content-manager.actions.delete.label",
|
2862
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2863
|
+
},
|
2864
|
+
{ isLocalized }
|
2865
|
+
),
|
2866
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2867
|
+
dialog: {
|
2868
|
+
type: "dialog",
|
2869
|
+
title: formatMessage({
|
2870
|
+
id: "app.components.ConfirmDialog.title",
|
2871
|
+
defaultMessage: "Confirmation"
|
2872
|
+
}),
|
2873
|
+
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2874
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2875
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2876
|
+
id: "content-manager.actions.delete.dialog.body",
|
2877
|
+
defaultMessage: "Are you sure?"
|
2878
|
+
}) })
|
2879
|
+
] }),
|
2880
|
+
onConfirm: async () => {
|
2881
|
+
if (!listViewPathMatch) {
|
2882
|
+
setSubmitting(true);
|
2883
|
+
}
|
2884
|
+
try {
|
2885
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2886
|
+
console.error(
|
2887
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2888
|
+
);
|
2889
|
+
toggleNotification({
|
2890
|
+
message: formatMessage({
|
2891
|
+
id: "content-manager.actions.delete.error",
|
2892
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2893
|
+
}),
|
2894
|
+
type: "danger"
|
2895
|
+
});
|
2896
|
+
return;
|
2897
|
+
}
|
2898
|
+
const res = await deleteAction({
|
2899
|
+
documentId,
|
2900
|
+
model,
|
2901
|
+
collectionType,
|
2902
|
+
params: {
|
2903
|
+
locale: "*"
|
2904
|
+
}
|
2905
|
+
});
|
2906
|
+
if (!("error" in res)) {
|
2907
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2908
|
+
}
|
2909
|
+
} finally {
|
2910
|
+
if (!listViewPathMatch) {
|
2911
|
+
setSubmitting(false);
|
2912
|
+
}
|
2913
|
+
}
|
2875
2914
|
}
|
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
2915
|
},
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2916
|
+
variant: "danger",
|
2917
|
+
position: ["header", "table-row"]
|
2918
|
+
};
|
2919
|
+
};
|
2920
|
+
DeleteAction$1.type = "delete";
|
2921
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2922
|
+
const Panels = () => {
|
2923
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2924
|
+
const [
|
2925
|
+
{
|
2926
|
+
query: { status }
|
2927
|
+
}
|
2928
|
+
] = useQueryParams({
|
2929
|
+
status: "draft"
|
2930
|
+
});
|
2931
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2932
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2933
|
+
const props = {
|
2934
|
+
activeTab: status,
|
2935
|
+
model,
|
2936
|
+
documentId: id,
|
2937
|
+
document: isCloning ? void 0 : document,
|
2938
|
+
meta: isCloning ? void 0 : meta,
|
2939
|
+
collectionType
|
2940
|
+
};
|
2941
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2942
|
+
DescriptionComponentRenderer,
|
2943
|
+
{
|
2944
|
+
props,
|
2945
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2946
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2928
2947
|
}
|
2948
|
+
) });
|
2949
|
+
};
|
2950
|
+
const ActionsPanel = () => {
|
2951
|
+
const { formatMessage } = useIntl();
|
2952
|
+
return {
|
2953
|
+
title: formatMessage({
|
2954
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2955
|
+
defaultMessage: "Entry"
|
2956
|
+
}),
|
2957
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2929
2958
|
};
|
2930
2959
|
};
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2960
|
+
ActionsPanel.type = "actions";
|
2961
|
+
const ActionsPanelContent = () => {
|
2962
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2963
|
+
const [
|
2964
|
+
{
|
2965
|
+
query: { status = "draft" }
|
2936
2966
|
}
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2967
|
+
] = useQueryParams();
|
2968
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2969
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2970
|
+
const props = {
|
2971
|
+
activeTab: status,
|
2972
|
+
model,
|
2973
|
+
documentId: id,
|
2974
|
+
document: isCloning ? void 0 : document,
|
2975
|
+
meta: isCloning ? void 0 : meta,
|
2976
|
+
collectionType
|
2977
|
+
};
|
2978
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2979
|
+
/* @__PURE__ */ jsx(
|
2980
|
+
DescriptionComponentRenderer,
|
2981
|
+
{
|
2982
|
+
props,
|
2983
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2984
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2985
|
+
}
|
2986
|
+
),
|
2987
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2988
|
+
] });
|
2951
2989
|
};
|
2990
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2991
|
+
return /* @__PURE__ */ jsxs(
|
2992
|
+
Flex,
|
2993
|
+
{
|
2994
|
+
ref,
|
2995
|
+
tag: "aside",
|
2996
|
+
"aria-labelledby": "additional-information",
|
2997
|
+
background: "neutral0",
|
2998
|
+
borderColor: "neutral150",
|
2999
|
+
hasRadius: true,
|
3000
|
+
paddingBottom: 4,
|
3001
|
+
paddingLeft: 4,
|
3002
|
+
paddingRight: 4,
|
3003
|
+
paddingTop: 4,
|
3004
|
+
shadow: "tableShadow",
|
3005
|
+
gap: 3,
|
3006
|
+
direction: "column",
|
3007
|
+
justifyContent: "stretch",
|
3008
|
+
alignItems: "flex-start",
|
3009
|
+
children: [
|
3010
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
|
3011
|
+
children
|
3012
|
+
]
|
3013
|
+
}
|
3014
|
+
);
|
3015
|
+
});
|
2952
3016
|
const ConfirmBulkActionDialog = ({
|
2953
3017
|
onToggleDialog,
|
2954
3018
|
isOpen = false,
|
@@ -3926,6 +3990,15 @@ const { setInitialData } = actions;
|
|
3926
3990
|
const reducer = combineReducers({
|
3927
3991
|
app: reducer$1
|
3928
3992
|
});
|
3993
|
+
const FEATURE_ID = "preview";
|
3994
|
+
const previewAdmin = {
|
3995
|
+
bootstrap(app) {
|
3996
|
+
if (!window.strapi.future.isEnabled(FEATURE_ID)) {
|
3997
|
+
return {};
|
3998
|
+
}
|
3999
|
+
console.log("Bootstrapping preview admin");
|
4000
|
+
}
|
4001
|
+
};
|
3929
4002
|
const index = {
|
3930
4003
|
register(app) {
|
3931
4004
|
const cm = new ContentManagerPlugin();
|
@@ -3945,7 +4018,7 @@ const index = {
|
|
3945
4018
|
app.router.addRoute({
|
3946
4019
|
path: "content-manager/*",
|
3947
4020
|
lazy: async () => {
|
3948
|
-
const { Layout } = await import("./layout-
|
4021
|
+
const { Layout } = await import("./layout-Cr0H40au.mjs");
|
3949
4022
|
return {
|
3950
4023
|
Component: Layout
|
3951
4024
|
};
|
@@ -3958,11 +4031,14 @@ const index = {
|
|
3958
4031
|
if (typeof historyAdmin.bootstrap === "function") {
|
3959
4032
|
historyAdmin.bootstrap(app);
|
3960
4033
|
}
|
4034
|
+
if (typeof previewAdmin.bootstrap === "function") {
|
4035
|
+
previewAdmin.bootstrap(app);
|
4036
|
+
}
|
3961
4037
|
},
|
3962
4038
|
async registerTrads({ locales }) {
|
3963
4039
|
const importedTrads = await Promise.all(
|
3964
4040
|
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-
|
4041
|
+
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
4042
|
return {
|
3967
4043
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3968
4044
|
locale
|
@@ -3990,7 +4066,8 @@ export {
|
|
3990
4066
|
InjectionZone as I,
|
3991
4067
|
useDocument as J,
|
3992
4068
|
index as K,
|
3993
|
-
|
4069
|
+
useContentManagerContext as L,
|
4070
|
+
useDocumentActions as M,
|
3994
4071
|
Panels as P,
|
3995
4072
|
RelativeTime as R,
|
3996
4073
|
SINGLE_TYPES as S,
|
@@ -4022,4 +4099,4 @@ export {
|
|
4022
4099
|
capitalise as y,
|
4023
4100
|
useUpdateContentTypeConfigurationMutation as z
|
4024
4101
|
};
|
4025
|
-
//# sourceMappingURL=index-
|
4102
|
+
//# sourceMappingURL=index-CxlpxzA5.mjs.map
|