@strapi/content-manager 0.0.0-experimental.65ad956ae83ac65d866b9bb3e8c022c34b85468f → 0.0.0-experimental.65b9961ce81496e349024ceb95be1d5946f2c429
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-CO977CPh.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-_zF8p6CY.js.map → ComponentConfigurationPage-CO977CPh.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs → ComponentConfigurationPage-CQroR9Qk.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs.map → ComponentConfigurationPage-CQroR9Qk.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js → EditConfigurationPage-BPgoE-kf.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js.map → EditConfigurationPage-BPgoE-kf.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs → EditConfigurationPage-tVCJ5vWC.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs.map → EditConfigurationPage-tVCJ5vWC.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-DeTn7rAF.mjs → EditViewPage-8mOu02ji.mjs} +15 -5
- package/dist/_chunks/EditViewPage-8mOu02ji.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-G9uNzwYL.js → EditViewPage-BMVgUNOX.js} +15 -5
- package/dist/_chunks/EditViewPage-BMVgUNOX.js.map +1 -0
- package/dist/_chunks/{Field-CnCKhI1R.mjs → Field-CJPYzwD7.mjs} +70 -26
- package/dist/_chunks/Field-CJPYzwD7.mjs.map +1 -0
- package/dist/_chunks/{Field-DDHUWEfV.js → Field-CdSLKFQk.js} +70 -26
- package/dist/_chunks/Field-CdSLKFQk.js.map +1 -0
- package/dist/_chunks/{Form-IvVVwqRL.mjs → Form-DJOJ-GF1.mjs} +3 -3
- package/dist/_chunks/Form-DJOJ-GF1.mjs.map +1 -0
- package/dist/_chunks/{Form-DYETaKUX.js → Form-eP5bZwap.js} +3 -3
- package/dist/_chunks/Form-eP5bZwap.js.map +1 -0
- package/dist/_chunks/{History-CnZDctSO.js → History-B-Mrquzu.js} +23 -10
- package/dist/_chunks/History-B-Mrquzu.js.map +1 -0
- package/dist/_chunks/{History-BMunT-do.mjs → History-MnQLtk1g.mjs} +24 -11
- package/dist/_chunks/History-MnQLtk1g.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs → ListConfigurationPage-BcycI8Lw.mjs} +3 -3
- package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs.map → ListConfigurationPage-BcycI8Lw.mjs.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-BynalOp8.js → ListConfigurationPage-C0n4rUzH.js} +3 -3
- package/dist/_chunks/{ListConfigurationPage-BynalOp8.js.map → ListConfigurationPage-C0n4rUzH.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-_5gS-DOF.mjs → ListViewPage-CRXONXwZ.mjs} +10 -6
- package/dist/_chunks/ListViewPage-CRXONXwZ.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-I88Ouzoq.js → ListViewPage-q0SHVPUS.js} +10 -6
- package/dist/_chunks/ListViewPage-q0SHVPUS.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js → NoContentTypePage-Bh3komDV.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js.map → NoContentTypePage-Bh3komDV.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs → NoContentTypePage-ukzFRF3z.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs.map → NoContentTypePage-ukzFRF3z.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs → NoPermissionsPage-B4sD7Ble.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs.map → NoPermissionsPage-B4sD7Ble.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js → NoPermissionsPage-BGBpj_Y1.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js.map → NoPermissionsPage-BGBpj_Y1.js.map} +1 -1
- package/dist/_chunks/{Relations-BPgFQeGj.js → Relations-B53wYe8g.js} +32 -23
- package/dist/_chunks/Relations-B53wYe8g.js.map +1 -0
- package/dist/_chunks/{Relations-Chdt5qWc.mjs → Relations-CIexb8gr.mjs} +32 -23
- package/dist/_chunks/Relations-CIexb8gr.mjs.map +1 -0
- package/dist/_chunks/{en-BVzUkPxZ.js → en-Bm0D0IWz.js} +8 -8
- package/dist/_chunks/{en-BVzUkPxZ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-CPTj6CjC.mjs → en-DKV44jRb.mjs} +8 -8
- package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-D4UGPFZC.mjs → index-CJ2vYwuT.mjs} +931 -869
- package/dist/_chunks/index-CJ2vYwuT.mjs.map +1 -0
- package/dist/_chunks/{index-BhbLFX4l.js → index-DbT2sx-Q.js} +929 -867
- package/dist/_chunks/index-DbT2sx-Q.js.map +1 -0
- package/dist/_chunks/{layout-CYA7s0qO.js → layout-CeBSIkmP.js} +3 -3
- package/dist/_chunks/{layout-CYA7s0qO.js.map → layout-CeBSIkmP.js.map} +1 -1
- package/dist/_chunks/{layout-D4HI4_PS.mjs → layout-vzKSrr7p.mjs} +3 -3
- package/dist/_chunks/{layout-D4HI4_PS.mjs.map → layout-vzKSrr7p.mjs.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-DDZ9OxNo.js → relations-Cl-6t9iz.js} +2 -2
- package/dist/_chunks/{relations-DDZ9OxNo.js.map → relations-Cl-6t9iz.js.map} +1 -1
- package/dist/_chunks/{relations-1pXaYpBK.mjs → relations-DI0lguF0.mjs} +2 -2
- package/dist/_chunks/{relations-1pXaYpBK.mjs.map → relations-DI0lguF0.mjs.map} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/Header.d.ts +1 -0
- package/dist/server/index.js +30 -16
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +30 -16
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/_chunks/EditViewPage-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,396 +913,436 @@ 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
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1232
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1233
|
+
return acc;
|
1234
|
+
}, {});
|
1235
|
+
};
|
1236
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1237
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1238
|
+
id: "notification.error",
|
1239
|
+
defaultMessage: "An error occurred, please try again"
|
1240
|
+
};
|
1241
|
+
const useDocumentActions = () => {
|
1242
|
+
const { toggleNotification } = useNotification();
|
1243
|
+
const { formatMessage } = useIntl();
|
1244
|
+
const { trackUsage } = useTracking();
|
1245
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1246
|
+
const navigate = useNavigate();
|
1247
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1248
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1249
|
+
const _delete = React.useCallback(
|
1250
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1113
1251
|
try {
|
1114
|
-
trackUsage("
|
1115
|
-
const res = await
|
1252
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1253
|
+
const res = await deleteDocument({
|
1116
1254
|
collectionType,
|
1117
1255
|
model,
|
1118
1256
|
documentId,
|
1119
|
-
params
|
1120
|
-
data: {
|
1121
|
-
discardDraft
|
1122
|
-
}
|
1257
|
+
params
|
1123
1258
|
});
|
1124
1259
|
if ("error" in res) {
|
1125
|
-
toggleNotification({
|
1260
|
+
toggleNotification({
|
1261
|
+
type: "danger",
|
1262
|
+
message: formatAPIError(res.error)
|
1263
|
+
});
|
1126
1264
|
return { error: res.error };
|
1127
1265
|
}
|
1128
|
-
trackUsage("didUnpublishEntry");
|
1129
1266
|
toggleNotification({
|
1130
1267
|
type: "success",
|
1131
1268
|
message: formatMessage({
|
1132
|
-
id: getTranslation("success.record.
|
1133
|
-
defaultMessage: "
|
1269
|
+
id: getTranslation("success.record.delete"),
|
1270
|
+
defaultMessage: "Deleted document"
|
1134
1271
|
})
|
1135
1272
|
});
|
1273
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1136
1274
|
return res.data;
|
1137
1275
|
} catch (err) {
|
1138
1276
|
toggleNotification({
|
1139
1277
|
type: "danger",
|
1140
1278
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1141
1279
|
});
|
1280
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1142
1281
|
throw err;
|
1143
1282
|
}
|
1144
1283
|
},
|
1145
|
-
[trackUsage,
|
1284
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1146
1285
|
);
|
1147
|
-
const [
|
1148
|
-
const
|
1286
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1287
|
+
const deleteMany = React.useCallback(
|
1149
1288
|
async ({ model, documentIds, params }) => {
|
1150
1289
|
try {
|
1151
|
-
trackUsage("
|
1152
|
-
const res = await
|
1290
|
+
trackUsage("willBulkDeleteEntries");
|
1291
|
+
const res = await deleteManyDocuments({
|
1153
1292
|
model,
|
1154
1293
|
documentIds,
|
1155
1294
|
params
|
1156
1295
|
});
|
1157
1296
|
if ("error" in res) {
|
1158
|
-
toggleNotification({
|
1297
|
+
toggleNotification({
|
1298
|
+
type: "danger",
|
1299
|
+
message: formatAPIError(res.error)
|
1300
|
+
});
|
1159
1301
|
return { error: res.error };
|
1160
1302
|
}
|
1161
|
-
trackUsage("didBulkUnpublishEntries");
|
1162
1303
|
toggleNotification({
|
1163
1304
|
type: "success",
|
1164
1305
|
title: formatMessage({
|
1165
|
-
id: getTranslation("success.records.
|
1166
|
-
defaultMessage: "Successfully
|
1306
|
+
id: getTranslation("success.records.delete"),
|
1307
|
+
defaultMessage: "Successfully deleted."
|
1167
1308
|
}),
|
1168
1309
|
message: ""
|
1169
1310
|
});
|
1311
|
+
trackUsage("didBulkDeleteEntries");
|
1170
1312
|
return res.data;
|
1171
1313
|
} catch (err) {
|
1172
1314
|
toggleNotification({
|
1173
1315
|
type: "danger",
|
1174
1316
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1175
1317
|
});
|
1176
|
-
trackUsage("
|
1318
|
+
trackUsage("didNotBulkDeleteEntries");
|
1177
1319
|
throw err;
|
1178
1320
|
}
|
1179
1321
|
},
|
1180
|
-
[trackUsage,
|
1322
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1181
1323
|
);
|
1182
|
-
const [
|
1183
|
-
const
|
1184
|
-
async ({ model, params }
|
1324
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1325
|
+
const discard = React.useCallback(
|
1326
|
+
async ({ collectionType, model, documentId, params }) => {
|
1185
1327
|
try {
|
1186
|
-
const res = await
|
1328
|
+
const res = await discardDocument({
|
1329
|
+
collectionType,
|
1187
1330
|
model,
|
1188
|
-
|
1331
|
+
documentId,
|
1189
1332
|
params
|
1190
1333
|
});
|
1191
1334
|
if ("error" in res) {
|
1192
|
-
toggleNotification({
|
1193
|
-
|
1335
|
+
toggleNotification({
|
1336
|
+
type: "danger",
|
1337
|
+
message: formatAPIError(res.error)
|
1338
|
+
});
|
1194
1339
|
return { error: res.error };
|
1195
1340
|
}
|
1196
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1197
1341
|
toggleNotification({
|
1198
1342
|
type: "success",
|
1199
1343
|
message: formatMessage({
|
1200
|
-
id:
|
1201
|
-
defaultMessage: "
|
1344
|
+
id: "content-manager.success.record.discard",
|
1345
|
+
defaultMessage: "Changes discarded"
|
1202
1346
|
})
|
1203
1347
|
});
|
1204
1348
|
return res.data;
|
@@ -1207,11 +1351,226 @@ const useDocumentActions = () => {
|
|
1207
1351
|
type: "danger",
|
1208
1352
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1209
1353
|
});
|
1210
|
-
trackUsage("didNotCreateEntry", { error: err, ...trackerProperty });
|
1211
1354
|
throw err;
|
1212
1355
|
}
|
1213
1356
|
},
|
1214
|
-
[
|
1357
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1358
|
+
);
|
1359
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1360
|
+
const publish = React.useCallback(
|
1361
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1362
|
+
try {
|
1363
|
+
trackUsage("willPublishEntry");
|
1364
|
+
const res = await publishDocument({
|
1365
|
+
collectionType,
|
1366
|
+
model,
|
1367
|
+
documentId,
|
1368
|
+
data,
|
1369
|
+
params
|
1370
|
+
});
|
1371
|
+
if ("error" in res) {
|
1372
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1373
|
+
return { error: res.error };
|
1374
|
+
}
|
1375
|
+
trackUsage("didPublishEntry");
|
1376
|
+
toggleNotification({
|
1377
|
+
type: "success",
|
1378
|
+
message: formatMessage({
|
1379
|
+
id: getTranslation("success.record.publish"),
|
1380
|
+
defaultMessage: "Published document"
|
1381
|
+
})
|
1382
|
+
});
|
1383
|
+
return res.data;
|
1384
|
+
} catch (err) {
|
1385
|
+
toggleNotification({
|
1386
|
+
type: "danger",
|
1387
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1388
|
+
});
|
1389
|
+
throw err;
|
1390
|
+
}
|
1391
|
+
},
|
1392
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1393
|
+
);
|
1394
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1395
|
+
const publishMany = React.useCallback(
|
1396
|
+
async ({ model, documentIds, params }) => {
|
1397
|
+
try {
|
1398
|
+
const res = await publishManyDocuments({
|
1399
|
+
model,
|
1400
|
+
documentIds,
|
1401
|
+
params
|
1402
|
+
});
|
1403
|
+
if ("error" in res) {
|
1404
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1405
|
+
return { error: res.error };
|
1406
|
+
}
|
1407
|
+
toggleNotification({
|
1408
|
+
type: "success",
|
1409
|
+
message: formatMessage({
|
1410
|
+
id: getTranslation("success.record.publish"),
|
1411
|
+
defaultMessage: "Published document"
|
1412
|
+
})
|
1413
|
+
});
|
1414
|
+
return res.data;
|
1415
|
+
} catch (err) {
|
1416
|
+
toggleNotification({
|
1417
|
+
type: "danger",
|
1418
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1419
|
+
});
|
1420
|
+
throw err;
|
1421
|
+
}
|
1422
|
+
},
|
1423
|
+
[
|
1424
|
+
// trackUsage,
|
1425
|
+
publishManyDocuments,
|
1426
|
+
toggleNotification,
|
1427
|
+
formatMessage,
|
1428
|
+
formatAPIError
|
1429
|
+
]
|
1430
|
+
);
|
1431
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1432
|
+
const update = React.useCallback(
|
1433
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1434
|
+
try {
|
1435
|
+
trackUsage("willEditEntry", trackerProperty);
|
1436
|
+
const res = await updateDocument({
|
1437
|
+
collectionType,
|
1438
|
+
model,
|
1439
|
+
documentId,
|
1440
|
+
data,
|
1441
|
+
params
|
1442
|
+
});
|
1443
|
+
if ("error" in res) {
|
1444
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1445
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1446
|
+
return { error: res.error };
|
1447
|
+
}
|
1448
|
+
trackUsage("didEditEntry", trackerProperty);
|
1449
|
+
toggleNotification({
|
1450
|
+
type: "success",
|
1451
|
+
message: formatMessage({
|
1452
|
+
id: getTranslation("success.record.save"),
|
1453
|
+
defaultMessage: "Saved document"
|
1454
|
+
})
|
1455
|
+
});
|
1456
|
+
return res.data;
|
1457
|
+
} catch (err) {
|
1458
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1459
|
+
toggleNotification({
|
1460
|
+
type: "danger",
|
1461
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1462
|
+
});
|
1463
|
+
throw err;
|
1464
|
+
}
|
1465
|
+
},
|
1466
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1467
|
+
);
|
1468
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1469
|
+
const unpublish = React.useCallback(
|
1470
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1471
|
+
try {
|
1472
|
+
trackUsage("willUnpublishEntry");
|
1473
|
+
const res = await unpublishDocument({
|
1474
|
+
collectionType,
|
1475
|
+
model,
|
1476
|
+
documentId,
|
1477
|
+
params,
|
1478
|
+
data: {
|
1479
|
+
discardDraft
|
1480
|
+
}
|
1481
|
+
});
|
1482
|
+
if ("error" in res) {
|
1483
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1484
|
+
return { error: res.error };
|
1485
|
+
}
|
1486
|
+
trackUsage("didUnpublishEntry");
|
1487
|
+
toggleNotification({
|
1488
|
+
type: "success",
|
1489
|
+
message: formatMessage({
|
1490
|
+
id: getTranslation("success.record.unpublish"),
|
1491
|
+
defaultMessage: "Unpublished document"
|
1492
|
+
})
|
1493
|
+
});
|
1494
|
+
return res.data;
|
1495
|
+
} catch (err) {
|
1496
|
+
toggleNotification({
|
1497
|
+
type: "danger",
|
1498
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1499
|
+
});
|
1500
|
+
throw err;
|
1501
|
+
}
|
1502
|
+
},
|
1503
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1504
|
+
);
|
1505
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1506
|
+
const unpublishMany = React.useCallback(
|
1507
|
+
async ({ model, documentIds, params }) => {
|
1508
|
+
try {
|
1509
|
+
trackUsage("willBulkUnpublishEntries");
|
1510
|
+
const res = await unpublishManyDocuments({
|
1511
|
+
model,
|
1512
|
+
documentIds,
|
1513
|
+
params
|
1514
|
+
});
|
1515
|
+
if ("error" in res) {
|
1516
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1517
|
+
return { error: res.error };
|
1518
|
+
}
|
1519
|
+
trackUsage("didBulkUnpublishEntries");
|
1520
|
+
toggleNotification({
|
1521
|
+
type: "success",
|
1522
|
+
title: formatMessage({
|
1523
|
+
id: getTranslation("success.records.unpublish"),
|
1524
|
+
defaultMessage: "Successfully unpublished."
|
1525
|
+
}),
|
1526
|
+
message: ""
|
1527
|
+
});
|
1528
|
+
return res.data;
|
1529
|
+
} catch (err) {
|
1530
|
+
toggleNotification({
|
1531
|
+
type: "danger",
|
1532
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1533
|
+
});
|
1534
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1535
|
+
throw err;
|
1536
|
+
}
|
1537
|
+
},
|
1538
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1539
|
+
);
|
1540
|
+
const [createDocument] = useCreateDocumentMutation();
|
1541
|
+
const create = React.useCallback(
|
1542
|
+
async ({ model, params }, data, trackerProperty) => {
|
1543
|
+
try {
|
1544
|
+
const res = await createDocument({
|
1545
|
+
model,
|
1546
|
+
data,
|
1547
|
+
params
|
1548
|
+
});
|
1549
|
+
if ("error" in res) {
|
1550
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1551
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1552
|
+
return { error: res.error };
|
1553
|
+
}
|
1554
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1555
|
+
toggleNotification({
|
1556
|
+
type: "success",
|
1557
|
+
message: formatMessage({
|
1558
|
+
id: getTranslation("success.record.save"),
|
1559
|
+
defaultMessage: "Saved document"
|
1560
|
+
})
|
1561
|
+
});
|
1562
|
+
setCurrentStep("contentManager.success");
|
1563
|
+
return res.data;
|
1564
|
+
} catch (err) {
|
1565
|
+
toggleNotification({
|
1566
|
+
type: "danger",
|
1567
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1568
|
+
});
|
1569
|
+
trackUsage("didNotCreateEntry", { error: err, ...trackerProperty });
|
1570
|
+
throw err;
|
1571
|
+
}
|
1572
|
+
},
|
1573
|
+
[createDocument, formatAPIError, formatMessage, toggleNotification, trackUsage]
|
1215
1574
|
);
|
1216
1575
|
const [autoCloneDocument] = useAutoCloneDocumentMutation();
|
1217
1576
|
const autoClone = React.useCallback(
|
@@ -1303,7 +1662,7 @@ const useDocumentActions = () => {
|
|
1303
1662
|
};
|
1304
1663
|
};
|
1305
1664
|
const ProtectedHistoryPage = lazy(
|
1306
|
-
() => import("./History-
|
1665
|
+
() => import("./History-MnQLtk1g.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1307
1666
|
);
|
1308
1667
|
const routes$1 = [
|
1309
1668
|
{
|
@@ -1316,31 +1675,31 @@ const routes$1 = [
|
|
1316
1675
|
}
|
1317
1676
|
];
|
1318
1677
|
const ProtectedEditViewPage = lazy(
|
1319
|
-
() => import("./EditViewPage-
|
1678
|
+
() => import("./EditViewPage-8mOu02ji.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1320
1679
|
);
|
1321
1680
|
const ProtectedListViewPage = lazy(
|
1322
|
-
() => import("./ListViewPage-
|
1681
|
+
() => import("./ListViewPage-CRXONXwZ.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1323
1682
|
);
|
1324
1683
|
const ProtectedListConfiguration = lazy(
|
1325
|
-
() => import("./ListConfigurationPage-
|
1684
|
+
() => import("./ListConfigurationPage-BcycI8Lw.mjs").then((mod) => ({
|
1326
1685
|
default: mod.ProtectedListConfiguration
|
1327
1686
|
}))
|
1328
1687
|
);
|
1329
1688
|
const ProtectedEditConfigurationPage = lazy(
|
1330
|
-
() => import("./EditConfigurationPage-
|
1689
|
+
() => import("./EditConfigurationPage-tVCJ5vWC.mjs").then((mod) => ({
|
1331
1690
|
default: mod.ProtectedEditConfigurationPage
|
1332
1691
|
}))
|
1333
1692
|
);
|
1334
1693
|
const ProtectedComponentConfigurationPage = lazy(
|
1335
|
-
() => import("./ComponentConfigurationPage-
|
1694
|
+
() => import("./ComponentConfigurationPage-CQroR9Qk.mjs").then((mod) => ({
|
1336
1695
|
default: mod.ProtectedComponentConfigurationPage
|
1337
1696
|
}))
|
1338
1697
|
);
|
1339
1698
|
const NoPermissions = lazy(
|
1340
|
-
() => import("./NoPermissionsPage-
|
1699
|
+
() => import("./NoPermissionsPage-B4sD7Ble.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1341
1700
|
);
|
1342
1701
|
const NoContentType = lazy(
|
1343
|
-
() => import("./NoContentTypePage-
|
1702
|
+
() => import("./NoContentTypePage-ukzFRF3z.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1344
1703
|
);
|
1345
1704
|
const CollectionTypePages = () => {
|
1346
1705
|
const { collectionType } = useParams();
|
@@ -1539,7 +1898,7 @@ const DocumentActionsMenu = ({
|
|
1539
1898
|
]
|
1540
1899
|
}
|
1541
1900
|
),
|
1542
|
-
/* @__PURE__ */ jsxs(Menu.Content, {
|
1901
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1543
1902
|
actions2.map((action) => {
|
1544
1903
|
return /* @__PURE__ */ jsx(
|
1545
1904
|
Menu.Item,
|
@@ -1787,7 +2146,9 @@ const PublishAction$1 = ({
|
|
1787
2146
|
const performPublish = async () => {
|
1788
2147
|
setSubmitting(true);
|
1789
2148
|
try {
|
1790
|
-
const { errors } = await validate(
|
2149
|
+
const { errors } = await validate(true, {
|
2150
|
+
status: "published"
|
2151
|
+
});
|
1791
2152
|
if (errors) {
|
1792
2153
|
toggleNotification({
|
1793
2154
|
type: "danger",
|
@@ -1901,18 +2262,18 @@ const UpdateAction = ({
|
|
1901
2262
|
onClick: async () => {
|
1902
2263
|
setSubmitting(true);
|
1903
2264
|
try {
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
})
|
1914
|
-
|
1915
|
-
|
2265
|
+
const { errors } = await validate(true, {
|
2266
|
+
status: "draft"
|
2267
|
+
});
|
2268
|
+
if (errors) {
|
2269
|
+
toggleNotification({
|
2270
|
+
type: "danger",
|
2271
|
+
message: formatMessage({
|
2272
|
+
id: "content-manager.validation.error",
|
2273
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2274
|
+
})
|
2275
|
+
});
|
2276
|
+
return;
|
1916
2277
|
}
|
1917
2278
|
if (isCloning) {
|
1918
2279
|
const res = await clone(
|
@@ -2294,12 +2655,12 @@ const Information = ({ activeTab }) => {
|
|
2294
2655
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2295
2656
|
label: formatMessage({
|
2296
2657
|
id: "content-manager.containers.edit.information.last-published.label",
|
2297
|
-
defaultMessage: "
|
2658
|
+
defaultMessage: "Published"
|
2298
2659
|
}),
|
2299
2660
|
value: formatMessage(
|
2300
2661
|
{
|
2301
2662
|
id: "content-manager.containers.edit.information.last-published.value",
|
2302
|
-
defaultMessage: `
|
2663
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2303
2664
|
},
|
2304
2665
|
{
|
2305
2666
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2312,12 +2673,12 @@ const Information = ({ activeTab }) => {
|
|
2312
2673
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2313
2674
|
label: formatMessage({
|
2314
2675
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2315
|
-
defaultMessage: "
|
2676
|
+
defaultMessage: "Updated"
|
2316
2677
|
}),
|
2317
2678
|
value: formatMessage(
|
2318
2679
|
{
|
2319
2680
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2320
|
-
defaultMessage: `
|
2681
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2321
2682
|
},
|
2322
2683
|
{
|
2323
2684
|
time: /* @__PURE__ */ jsx(
|
@@ -2335,12 +2696,12 @@ const Information = ({ activeTab }) => {
|
|
2335
2696
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2336
2697
|
label: formatMessage({
|
2337
2698
|
id: "content-manager.containers.edit.information.document.label",
|
2338
|
-
defaultMessage: "
|
2699
|
+
defaultMessage: "Created"
|
2339
2700
|
}),
|
2340
2701
|
value: formatMessage(
|
2341
2702
|
{
|
2342
2703
|
id: "content-manager.containers.edit.information.document.value",
|
2343
|
-
defaultMessage: `
|
2704
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2344
2705
|
},
|
2345
2706
|
{
|
2346
2707
|
time: /* @__PURE__ */ jsx(
|
@@ -2398,10 +2759,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2398
2759
|
SingleSelect,
|
2399
2760
|
{
|
2400
2761
|
size: "S",
|
2401
|
-
disabled: action.disabled,
|
2402
|
-
"aria-label": action.label,
|
2403
2762
|
onChange: action.onSelect,
|
2404
|
-
|
2763
|
+
"aria-label": action.label,
|
2764
|
+
...action,
|
2405
2765
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2406
2766
|
},
|
2407
2767
|
action.id
|
@@ -2465,490 +2825,191 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
|
|
2465
2825
|
position: "header"
|
2466
2826
|
};
|
2467
2827
|
};
|
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
|
-
);
|
2828
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2829
|
+
const EditTheModelAction = ({ model }) => {
|
2830
|
+
const navigate = useNavigate();
|
2831
|
+
const { formatMessage } = useIntl();
|
2854
2832
|
return {
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2833
|
+
label: formatMessage({
|
2834
|
+
id: "content-manager.link-to-ctb",
|
2835
|
+
defaultMessage: "Edit the model"
|
2836
|
+
}),
|
2837
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2838
|
+
onClick: () => {
|
2839
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2861
2840
|
},
|
2862
|
-
|
2863
|
-
...schema?.options,
|
2864
|
-
...schema?.pluginOptions,
|
2865
|
-
...data.contentType.options
|
2866
|
-
}
|
2841
|
+
position: "header"
|
2867
2842
|
};
|
2868
2843
|
};
|
2869
|
-
|
2870
|
-
|
2871
|
-
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2844
|
+
EditTheModelAction.type = "edit-the-model";
|
2845
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2846
|
+
const navigate = useNavigate();
|
2847
|
+
const { formatMessage } = useIntl();
|
2848
|
+
const listViewPathMatch = useMatch(LIST_PATH);
|
2849
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2850
|
+
const { delete: deleteAction } = useDocumentActions();
|
2851
|
+
const { toggleNotification } = useNotification();
|
2852
|
+
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2853
|
+
const isLocalized = document?.locale != null;
|
2854
|
+
return {
|
2855
|
+
disabled: !canDelete || !document,
|
2856
|
+
label: formatMessage(
|
2857
|
+
{
|
2858
|
+
id: "content-manager.actions.delete.label",
|
2859
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2860
|
+
},
|
2861
|
+
{ isLocalized }
|
2862
|
+
),
|
2863
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2864
|
+
dialog: {
|
2865
|
+
type: "dialog",
|
2866
|
+
title: formatMessage({
|
2867
|
+
id: "app.components.ConfirmDialog.title",
|
2868
|
+
defaultMessage: "Confirmation"
|
2869
|
+
}),
|
2870
|
+
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2871
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2872
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2873
|
+
id: "content-manager.actions.delete.dialog.body",
|
2874
|
+
defaultMessage: "Are you sure?"
|
2875
|
+
}) })
|
2876
|
+
] }),
|
2877
|
+
onConfirm: async () => {
|
2878
|
+
if (!listViewPathMatch) {
|
2879
|
+
setSubmitting(true);
|
2880
|
+
}
|
2881
|
+
try {
|
2882
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2883
|
+
console.error(
|
2884
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2885
|
+
);
|
2886
|
+
toggleNotification({
|
2887
|
+
message: formatMessage({
|
2888
|
+
id: "content-manager.actions.delete.error",
|
2889
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2890
|
+
}),
|
2891
|
+
type: "danger"
|
2892
|
+
});
|
2893
|
+
return;
|
2894
|
+
}
|
2895
|
+
const res = await deleteAction({
|
2896
|
+
documentId,
|
2897
|
+
model,
|
2898
|
+
collectionType,
|
2899
|
+
params: {
|
2900
|
+
locale: "*"
|
2901
|
+
}
|
2902
|
+
});
|
2903
|
+
if (!("error" in res)) {
|
2904
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2905
|
+
}
|
2906
|
+
} finally {
|
2907
|
+
if (!listViewPathMatch) {
|
2908
|
+
setSubmitting(false);
|
2909
|
+
}
|
2910
|
+
}
|
2875
2911
|
}
|
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
2912
|
},
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2913
|
+
variant: "danger",
|
2914
|
+
position: ["header", "table-row"]
|
2915
|
+
};
|
2916
|
+
};
|
2917
|
+
DeleteAction$1.type = "delete";
|
2918
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2919
|
+
const Panels = () => {
|
2920
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2921
|
+
const [
|
2922
|
+
{
|
2923
|
+
query: { status }
|
2924
|
+
}
|
2925
|
+
] = useQueryParams({
|
2926
|
+
status: "draft"
|
2927
|
+
});
|
2928
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2929
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2930
|
+
const props = {
|
2931
|
+
activeTab: status,
|
2932
|
+
model,
|
2933
|
+
documentId: id,
|
2934
|
+
document: isCloning ? void 0 : document,
|
2935
|
+
meta: isCloning ? void 0 : meta,
|
2936
|
+
collectionType
|
2937
|
+
};
|
2938
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2939
|
+
DescriptionComponentRenderer,
|
2940
|
+
{
|
2941
|
+
props,
|
2942
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2943
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2928
2944
|
}
|
2945
|
+
) });
|
2946
|
+
};
|
2947
|
+
const ActionsPanel = () => {
|
2948
|
+
const { formatMessage } = useIntl();
|
2949
|
+
return {
|
2950
|
+
title: formatMessage({
|
2951
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2952
|
+
defaultMessage: "Entry"
|
2953
|
+
}),
|
2954
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2929
2955
|
};
|
2930
2956
|
};
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2957
|
+
ActionsPanel.type = "actions";
|
2958
|
+
const ActionsPanelContent = () => {
|
2959
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2960
|
+
const [
|
2961
|
+
{
|
2962
|
+
query: { status = "draft" }
|
2936
2963
|
}
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2964
|
+
] = useQueryParams();
|
2965
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2966
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2967
|
+
const props = {
|
2968
|
+
activeTab: status,
|
2969
|
+
model,
|
2970
|
+
documentId: id,
|
2971
|
+
document: isCloning ? void 0 : document,
|
2972
|
+
meta: isCloning ? void 0 : meta,
|
2973
|
+
collectionType
|
2974
|
+
};
|
2975
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2976
|
+
/* @__PURE__ */ jsx(
|
2977
|
+
DescriptionComponentRenderer,
|
2978
|
+
{
|
2979
|
+
props,
|
2980
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2981
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2982
|
+
}
|
2983
|
+
),
|
2984
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2985
|
+
] });
|
2951
2986
|
};
|
2987
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2988
|
+
return /* @__PURE__ */ jsxs(
|
2989
|
+
Flex,
|
2990
|
+
{
|
2991
|
+
ref,
|
2992
|
+
tag: "aside",
|
2993
|
+
"aria-labelledby": "additional-information",
|
2994
|
+
background: "neutral0",
|
2995
|
+
borderColor: "neutral150",
|
2996
|
+
hasRadius: true,
|
2997
|
+
paddingBottom: 4,
|
2998
|
+
paddingLeft: 4,
|
2999
|
+
paddingRight: 4,
|
3000
|
+
paddingTop: 4,
|
3001
|
+
shadow: "tableShadow",
|
3002
|
+
gap: 3,
|
3003
|
+
direction: "column",
|
3004
|
+
justifyContent: "stretch",
|
3005
|
+
alignItems: "flex-start",
|
3006
|
+
children: [
|
3007
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3008
|
+
children
|
3009
|
+
]
|
3010
|
+
}
|
3011
|
+
);
|
3012
|
+
});
|
2952
3013
|
const ConfirmBulkActionDialog = ({
|
2953
3014
|
onToggleDialog,
|
2954
3015
|
isOpen = false,
|
@@ -3945,7 +4006,7 @@ const index = {
|
|
3945
4006
|
app.router.addRoute({
|
3946
4007
|
path: "content-manager/*",
|
3947
4008
|
lazy: async () => {
|
3948
|
-
const { Layout } = await import("./layout-
|
4009
|
+
const { Layout } = await import("./layout-vzKSrr7p.mjs");
|
3949
4010
|
return {
|
3950
4011
|
Component: Layout
|
3951
4012
|
};
|
@@ -3962,7 +4023,7 @@ const index = {
|
|
3962
4023
|
async registerTrads({ locales }) {
|
3963
4024
|
const importedTrads = await Promise.all(
|
3964
4025
|
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-
|
4026
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-DKV44jRb.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-CtsUxOvk.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
|
3966
4027
|
return {
|
3967
4028
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3968
4029
|
locale
|
@@ -3990,7 +4051,8 @@ export {
|
|
3990
4051
|
InjectionZone as I,
|
3991
4052
|
useDocument as J,
|
3992
4053
|
index as K,
|
3993
|
-
|
4054
|
+
useContentManagerContext as L,
|
4055
|
+
useDocumentActions as M,
|
3994
4056
|
Panels as P,
|
3995
4057
|
RelativeTime as R,
|
3996
4058
|
SINGLE_TYPES as S,
|
@@ -4022,4 +4084,4 @@ export {
|
|
4022
4084
|
capitalise as y,
|
4023
4085
|
useUpdateContentTypeConfigurationMutation as z
|
4024
4086
|
};
|
4025
|
-
//# sourceMappingURL=index-
|
4087
|
+
//# sourceMappingURL=index-CJ2vYwuT.mjs.map
|