@strapi/content-manager 0.0.0-experimental.afa3b513b8f95459043f33fb94f4bac03af1474f → 0.0.0-experimental.b1d7921ddb1b36c84b58a3946e1dc9dbda91b2dc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-G4EIirP8.js → ComponentConfigurationPage-CQDCxI8x.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-G4EIirP8.js.map → ComponentConfigurationPage-CQDCxI8x.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CnL10QYC.mjs → ComponentConfigurationPage-jmWwucg_.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CnL10QYC.mjs.map → ComponentConfigurationPage-jmWwucg_.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-B2AA1kVF.js → EditConfigurationPage-Ce4bIm4n.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-B2AA1kVF.js.map → EditConfigurationPage-Ce4bIm4n.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-I2kKh9dx.mjs → EditConfigurationPage-W07CEdm2.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-I2kKh9dx.mjs.map → EditConfigurationPage-W07CEdm2.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CHgoNwlc.js → EditViewPage-CqHMM0P0.js} +15 -5
- package/dist/_chunks/EditViewPage-CqHMM0P0.js.map +1 -0
- package/dist/_chunks/{EditViewPage-zFjJK0s8.mjs → EditViewPage-al5OO1NR.mjs} +15 -5
- package/dist/_chunks/EditViewPage-al5OO1NR.mjs.map +1 -0
- package/dist/_chunks/{Field-9DePZh-0.js → Field-DSOUlTCm.js} +69 -25
- package/dist/_chunks/Field-DSOUlTCm.js.map +1 -0
- package/dist/_chunks/{Field-DPAzUS1M.mjs → Field-EeG6NQ7x.mjs} +69 -25
- package/dist/_chunks/Field-EeG6NQ7x.mjs.map +1 -0
- package/dist/_chunks/{Form-CEkENbkF.mjs → Form-BAo9ANb_.mjs} +3 -3
- package/dist/_chunks/Form-BAo9ANb_.mjs.map +1 -0
- package/dist/_chunks/{Form-DPm-KZ1A.js → Form-DAEfHKzm.js} +3 -3
- package/dist/_chunks/Form-DAEfHKzm.js.map +1 -0
- package/dist/_chunks/{History-utls71em.mjs → History-BpLIu67W.mjs} +24 -11
- package/dist/_chunks/History-BpLIu67W.mjs.map +1 -0
- package/dist/_chunks/{History-DXSbTWez.js → History-CTFvy6XH.js} +23 -10
- package/dist/_chunks/History-CTFvy6XH.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-D5C7ACZ_.js → ListConfigurationPage-CDzlMBz_.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-D5C7ACZ_.js.map → ListConfigurationPage-CDzlMBz_.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-CuMXWWqb.mjs → ListConfigurationPage-DOqj5f8Y.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-CuMXWWqb.mjs.map → ListConfigurationPage-DOqj5f8Y.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-CdKd-PS_.mjs → ListViewPage-BbXYNI0v.mjs} +4 -4
- package/dist/_chunks/{ListViewPage-CdKd-PS_.mjs.map → ListViewPage-BbXYNI0v.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-DfuwH1tt.js → ListViewPage-D0fpPYKp.js} +4 -4
- package/dist/_chunks/{ListViewPage-DfuwH1tt.js.map → ListViewPage-D0fpPYKp.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BIxlkWWi.js → NoContentTypePage-DTzkSAV5.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BIxlkWWi.js.map → NoContentTypePage-DTzkSAV5.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DkToTT7u.mjs → NoContentTypePage-w2Q0VVOT.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DkToTT7u.mjs.map → NoContentTypePage-w2Q0VVOT.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Bu4GWYb-.js → NoPermissionsPage-BoI2rU68.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Bu4GWYb-.js.map → NoPermissionsPage-BoI2rU68.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DlWi4BAH.mjs → NoPermissionsPage-Km0Vk5Wp.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DlWi4BAH.mjs.map → NoPermissionsPage-Km0Vk5Wp.mjs.map} +1 -1
- package/dist/_chunks/{Relations-QP5yn9_z.mjs → Relations-C_bpmSuQ.mjs} +50 -28
- package/dist/_chunks/Relations-C_bpmSuQ.mjs.map +1 -0
- package/dist/_chunks/{Relations-CFjTESWQ.js → Relations-D6Nz5ksc.js} +50 -28
- package/dist/_chunks/Relations-D6Nz5ksc.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-DXiHxy70.js → index-BsMu2oVP.js} +947 -868
- package/dist/_chunks/index-BsMu2oVP.js.map +1 -0
- package/dist/_chunks/{index-BHfS6_D5.mjs → index-DcQ6xogO.mjs} +948 -870
- package/dist/_chunks/index-DcQ6xogO.mjs.map +1 -0
- package/dist/_chunks/{layout-bE-WUnQ0.js → layout-B4aCAdTt.js} +3 -3
- package/dist/_chunks/{layout-bE-WUnQ0.js.map → layout-B4aCAdTt.js.map} +1 -1
- package/dist/_chunks/{layout-DX_52HSH.mjs → layout-BavJ6v4B.mjs} +3 -3
- package/dist/_chunks/{layout-DX_52HSH.mjs.map → layout-BavJ6v4B.mjs.map} +1 -1
- package/dist/_chunks/{relations-SCVAL_aJ.mjs → relations-DMG453Od.mjs} +2 -2
- package/dist/_chunks/{relations-SCVAL_aJ.mjs.map → relations-DMG453Od.mjs.map} +1 -1
- package/dist/_chunks/{relations-D706vblp.js → relations-Lrm9nz_m.js} +2 -2
- package/dist/_chunks/{relations-D706vblp.js.map → relations-Lrm9nz_m.js.map} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/Header.d.ts +1 -0
- package/dist/server/index.js +67 -28
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +67 -28
- 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/controllers/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- package/dist/server/src/services/document-metadata.d.ts +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/_chunks/EditViewPage-CHgoNwlc.js.map +0 -1
- package/dist/_chunks/EditViewPage-zFjJK0s8.mjs.map +0 -1
- package/dist/_chunks/Field-9DePZh-0.js.map +0 -1
- package/dist/_chunks/Field-DPAzUS1M.mjs.map +0 -1
- package/dist/_chunks/Form-CEkENbkF.mjs.map +0 -1
- package/dist/_chunks/Form-DPm-KZ1A.js.map +0 -1
- package/dist/_chunks/History-DXSbTWez.js.map +0 -1
- package/dist/_chunks/History-utls71em.mjs.map +0 -1
- package/dist/_chunks/Relations-CFjTESWQ.js.map +0 -1
- package/dist/_chunks/Relations-QP5yn9_z.mjs.map +0 -1
- package/dist/_chunks/index-BHfS6_D5.mjs.map +0 -1
- package/dist/_chunks/index-DXiHxy70.js.map +0 -1
@@ -1,9 +1,10 @@
|
|
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";
|
7
|
+
import mapValues from "lodash/fp/mapValues";
|
7
8
|
import { useIntl } from "react-intl";
|
8
9
|
import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
|
9
10
|
import * as yup from "yup";
|
@@ -100,6 +101,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
100
101
|
if (!slug) {
|
101
102
|
throw new Error("Cannot find the slug param in the URL");
|
102
103
|
}
|
104
|
+
const [{ rawQuery }] = useQueryParams();
|
103
105
|
const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
|
104
106
|
const contentTypePermissions = React.useMemo(() => {
|
105
107
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -110,7 +112,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
110
112
|
return { ...acc, [action]: [permission] };
|
111
113
|
}, {});
|
112
114
|
}, [slug, userPermissions]);
|
113
|
-
const { isLoading, allowedActions } = useRBAC(
|
115
|
+
const { isLoading, allowedActions } = useRBAC(
|
116
|
+
contentTypePermissions,
|
117
|
+
permissions ?? void 0,
|
118
|
+
// TODO: useRBAC context should be typed and built differently
|
119
|
+
// We are passing raw query as context to the hook so that it can
|
120
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
121
|
+
rawQuery
|
122
|
+
);
|
114
123
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
115
124
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
116
125
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -461,6 +470,24 @@ const buildValidParams = (query) => {
|
|
461
470
|
const isBaseQueryError = (error) => {
|
462
471
|
return error.name !== void 0;
|
463
472
|
};
|
473
|
+
const arrayValidator = (attribute, options) => ({
|
474
|
+
message: translatedErrors.required,
|
475
|
+
test(value) {
|
476
|
+
if (options.status === "draft") {
|
477
|
+
return true;
|
478
|
+
}
|
479
|
+
if (!attribute.required) {
|
480
|
+
return true;
|
481
|
+
}
|
482
|
+
if (!value) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
if (Array.isArray(value) && value.length === 0) {
|
486
|
+
return false;
|
487
|
+
}
|
488
|
+
return true;
|
489
|
+
}
|
490
|
+
});
|
464
491
|
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
465
492
|
const createModelSchema = (attributes2) => yup.object().shape(
|
466
493
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
@@ -468,6 +495,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
468
495
|
return acc;
|
469
496
|
}
|
470
497
|
const validations = [
|
498
|
+
addNullableValidation,
|
471
499
|
addRequiredValidation,
|
472
500
|
addMinLengthValidation,
|
473
501
|
addMaxLengthValidation,
|
@@ -484,12 +512,12 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
484
512
|
...acc,
|
485
513
|
[name]: transformSchema(
|
486
514
|
yup.array().of(createModelSchema(attributes3).nullable(false))
|
487
|
-
)
|
515
|
+
).test(arrayValidator(attribute, options))
|
488
516
|
};
|
489
517
|
} else {
|
490
518
|
return {
|
491
519
|
...acc,
|
492
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
520
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
493
521
|
};
|
494
522
|
}
|
495
523
|
}
|
@@ -511,7 +539,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
511
539
|
}
|
512
540
|
)
|
513
541
|
)
|
514
|
-
)
|
542
|
+
).test(arrayValidator(attribute, options))
|
515
543
|
};
|
516
544
|
case "relation":
|
517
545
|
return {
|
@@ -523,7 +551,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
523
551
|
} else if (Array.isArray(value)) {
|
524
552
|
return yup.array().of(
|
525
553
|
yup.object().shape({
|
526
|
-
id: yup.
|
554
|
+
id: yup.number().required()
|
527
555
|
})
|
528
556
|
);
|
529
557
|
} else if (typeof value === "object") {
|
@@ -609,17 +637,17 @@ const nullableSchema = (schema) => {
|
|
609
637
|
schema
|
610
638
|
);
|
611
639
|
};
|
640
|
+
const addNullableValidation = () => (schema) => {
|
641
|
+
return nullableSchema(schema);
|
642
|
+
};
|
612
643
|
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);
|
644
|
+
if (options.status === "draft" || !attribute.required) {
|
645
|
+
return schema;
|
618
646
|
}
|
619
|
-
if (attribute.required &&
|
647
|
+
if (attribute.required && "required" in schema) {
|
620
648
|
return schema.required(translatedErrors.required);
|
621
649
|
}
|
622
|
-
return
|
650
|
+
return schema;
|
623
651
|
};
|
624
652
|
const addMinLengthValidation = (attribute, options) => (schema) => {
|
625
653
|
if (options.status === "draft") {
|
@@ -647,31 +675,12 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
647
675
|
return schema;
|
648
676
|
};
|
649
677
|
const addMinValidation = (attribute, options) => (schema) => {
|
650
|
-
if ("
|
678
|
+
if (options.status === "draft") {
|
679
|
+
return schema;
|
680
|
+
}
|
681
|
+
if ("min" in attribute && "min" in schema) {
|
651
682
|
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) {
|
683
|
+
if (min) {
|
675
684
|
return schema.min(min, {
|
676
685
|
...translatedErrors.min,
|
677
686
|
values: {
|
@@ -789,19 +798,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
789
798
|
}, {});
|
790
799
|
return componentsByKey;
|
791
800
|
};
|
792
|
-
const
|
801
|
+
const HOOKS = {
|
802
|
+
/**
|
803
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
804
|
+
* @constant
|
805
|
+
* @type {string}
|
806
|
+
*/
|
807
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
808
|
+
/**
|
809
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
810
|
+
* @constant
|
811
|
+
* @type {string}
|
812
|
+
*/
|
813
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
814
|
+
/**
|
815
|
+
* Hook that allows to mutate the CM's edit view layout
|
816
|
+
* @constant
|
817
|
+
* @type {string}
|
818
|
+
*/
|
819
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
820
|
+
/**
|
821
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
822
|
+
* @constant
|
823
|
+
* @type {string}
|
824
|
+
*/
|
825
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
826
|
+
};
|
827
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
828
|
+
endpoints: (builder) => ({
|
829
|
+
getContentTypeConfiguration: builder.query({
|
830
|
+
query: (uid) => ({
|
831
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
832
|
+
method: "GET"
|
833
|
+
}),
|
834
|
+
transformResponse: (response) => response.data,
|
835
|
+
providesTags: (_result, _error, uid) => [
|
836
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
837
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
838
|
+
]
|
839
|
+
}),
|
840
|
+
getAllContentTypeSettings: builder.query({
|
841
|
+
query: () => "/content-manager/content-types-settings",
|
842
|
+
transformResponse: (response) => response.data,
|
843
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
844
|
+
}),
|
845
|
+
updateContentTypeConfiguration: builder.mutation({
|
846
|
+
query: ({ uid, ...body }) => ({
|
847
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
848
|
+
method: "PUT",
|
849
|
+
data: body
|
850
|
+
}),
|
851
|
+
transformResponse: (response) => response.data,
|
852
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
853
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
854
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
855
|
+
// Is this necessary?
|
856
|
+
{ type: "InitialData" }
|
857
|
+
]
|
858
|
+
})
|
859
|
+
})
|
860
|
+
});
|
861
|
+
const {
|
862
|
+
useGetContentTypeConfigurationQuery,
|
863
|
+
useGetAllContentTypeSettingsQuery,
|
864
|
+
useUpdateContentTypeConfigurationMutation
|
865
|
+
} = contentTypesApi;
|
866
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
867
|
+
const { type } = attribute;
|
868
|
+
if (type === "relation") {
|
869
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
870
|
+
}
|
871
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
872
|
+
};
|
873
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
874
|
+
if (!mainFieldName) {
|
875
|
+
return void 0;
|
876
|
+
}
|
877
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
878
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
879
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
880
|
+
);
|
881
|
+
return {
|
882
|
+
name: mainFieldName,
|
883
|
+
type: mainFieldType ?? "string"
|
884
|
+
};
|
885
|
+
};
|
886
|
+
const DEFAULT_SETTINGS = {
|
887
|
+
bulkable: false,
|
888
|
+
filterable: false,
|
889
|
+
searchable: false,
|
890
|
+
pagination: false,
|
891
|
+
defaultSortBy: "",
|
892
|
+
defaultSortOrder: "asc",
|
893
|
+
mainField: "id",
|
894
|
+
pageSize: 10
|
895
|
+
};
|
896
|
+
const useDocumentLayout = (model) => {
|
897
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
898
|
+
const [{ query }] = useQueryParams();
|
899
|
+
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
793
900
|
const { toggleNotification } = useNotification();
|
794
901
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
902
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
795
903
|
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);
|
904
|
+
data,
|
905
|
+
isLoading: isLoadingConfigs,
|
906
|
+
error,
|
907
|
+
isFetching: isFetchingConfigs
|
908
|
+
} = useGetContentTypeConfigurationQuery(model);
|
909
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
805
910
|
React.useEffect(() => {
|
806
911
|
if (error) {
|
807
912
|
toggleNotification({
|
@@ -809,398 +914,656 @@ const useDocument = (args, opts) => {
|
|
809
914
|
message: formatAPIError(error)
|
810
915
|
});
|
811
916
|
}
|
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
|
-
}
|
917
|
+
}, [error, formatAPIError, toggleNotification]);
|
918
|
+
const editLayout = React.useMemo(
|
919
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
920
|
+
layout: [],
|
921
|
+
components: {},
|
922
|
+
metadatas: {},
|
923
|
+
options: {},
|
924
|
+
settings: DEFAULT_SETTINGS
|
835
925
|
},
|
836
|
-
[
|
926
|
+
[data, isLoading, schemas, schema, components]
|
927
|
+
);
|
928
|
+
const listLayout = React.useMemo(() => {
|
929
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
930
|
+
layout: [],
|
931
|
+
metadatas: {},
|
932
|
+
options: {},
|
933
|
+
settings: DEFAULT_SETTINGS
|
934
|
+
};
|
935
|
+
}, [data, isLoading, schemas, schema, components]);
|
936
|
+
const { layout: edit } = React.useMemo(
|
937
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
938
|
+
layout: editLayout,
|
939
|
+
query
|
940
|
+
}),
|
941
|
+
[editLayout, query, runHookWaterfall]
|
837
942
|
);
|
838
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
839
943
|
return {
|
840
|
-
|
841
|
-
document: data?.data,
|
842
|
-
meta: data?.meta,
|
944
|
+
error,
|
843
945
|
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
|
-
)
|
946
|
+
edit,
|
947
|
+
list: listLayout
|
868
948
|
};
|
869
949
|
};
|
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"
|
950
|
+
const useDocLayout = () => {
|
951
|
+
const { model } = useDoc();
|
952
|
+
return useDocumentLayout(model);
|
883
953
|
};
|
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;
|
954
|
+
const formatEditLayout = (data, {
|
955
|
+
schemas,
|
956
|
+
schema,
|
957
|
+
components
|
958
|
+
}) => {
|
959
|
+
let currentPanelIndex = 0;
|
960
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
961
|
+
data.contentType.layouts.edit,
|
962
|
+
schema?.attributes,
|
963
|
+
data.contentType.metadatas,
|
964
|
+
{ configurations: data.components, schemas: components },
|
965
|
+
schemas
|
966
|
+
).reduce((panels, row) => {
|
967
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
968
|
+
panels.push([row]);
|
969
|
+
currentPanelIndex += 2;
|
970
|
+
} else {
|
971
|
+
if (!panels[currentPanelIndex]) {
|
972
|
+
panels.push([]);
|
924
973
|
}
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
const
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
});
|
943
|
-
return { error: res.error };
|
974
|
+
panels[currentPanelIndex].push(row);
|
975
|
+
}
|
976
|
+
return panels;
|
977
|
+
}, []);
|
978
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
979
|
+
(acc, [uid, configuration]) => {
|
980
|
+
acc[uid] = {
|
981
|
+
layout: convertEditLayoutToFieldLayouts(
|
982
|
+
configuration.layouts.edit,
|
983
|
+
components[uid].attributes,
|
984
|
+
configuration.metadatas,
|
985
|
+
{ configurations: data.components, schemas: components }
|
986
|
+
),
|
987
|
+
settings: {
|
988
|
+
...configuration.settings,
|
989
|
+
icon: components[uid].info.icon,
|
990
|
+
displayName: components[uid].info.displayName
|
944
991
|
}
|
945
|
-
|
946
|
-
|
947
|
-
title: formatMessage({
|
948
|
-
id: getTranslation("success.records.delete"),
|
949
|
-
defaultMessage: "Successfully deleted."
|
950
|
-
}),
|
951
|
-
message: ""
|
952
|
-
});
|
953
|
-
trackUsage("didBulkDeleteEntries");
|
954
|
-
return res.data;
|
955
|
-
} catch (err) {
|
956
|
-
toggleNotification({
|
957
|
-
type: "danger",
|
958
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
959
|
-
});
|
960
|
-
trackUsage("didNotBulkDeleteEntries");
|
961
|
-
throw err;
|
962
|
-
}
|
992
|
+
};
|
993
|
+
return acc;
|
963
994
|
},
|
964
|
-
|
995
|
+
{}
|
965
996
|
);
|
966
|
-
const
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
model,
|
973
|
-
documentId,
|
974
|
-
params
|
975
|
-
});
|
976
|
-
if ("error" in res) {
|
977
|
-
toggleNotification({
|
978
|
-
type: "danger",
|
979
|
-
message: formatAPIError(res.error)
|
980
|
-
});
|
981
|
-
return { error: res.error };
|
982
|
-
}
|
983
|
-
toggleNotification({
|
984
|
-
type: "success",
|
985
|
-
message: formatMessage({
|
986
|
-
id: "content-manager.success.record.discard",
|
987
|
-
defaultMessage: "Changes discarded"
|
988
|
-
})
|
989
|
-
});
|
990
|
-
return res.data;
|
991
|
-
} catch (err) {
|
992
|
-
toggleNotification({
|
993
|
-
type: "danger",
|
994
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
995
|
-
});
|
996
|
-
throw err;
|
997
|
-
}
|
997
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
998
|
+
(acc, [attribute, metadata]) => {
|
999
|
+
return {
|
1000
|
+
...acc,
|
1001
|
+
[attribute]: metadata.edit
|
1002
|
+
};
|
998
1003
|
},
|
999
|
-
|
1004
|
+
{}
|
1000
1005
|
);
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
model,
|
1009
|
-
documentId,
|
1010
|
-
data,
|
1011
|
-
params
|
1012
|
-
});
|
1013
|
-
if ("error" in res) {
|
1014
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1015
|
-
return { error: res.error };
|
1016
|
-
}
|
1017
|
-
trackUsage("didPublishEntry");
|
1018
|
-
toggleNotification({
|
1019
|
-
type: "success",
|
1020
|
-
message: formatMessage({
|
1021
|
-
id: getTranslation("success.record.publish"),
|
1022
|
-
defaultMessage: "Published document"
|
1023
|
-
})
|
1024
|
-
});
|
1025
|
-
return res.data;
|
1026
|
-
} catch (err) {
|
1027
|
-
toggleNotification({
|
1028
|
-
type: "danger",
|
1029
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1030
|
-
});
|
1031
|
-
throw err;
|
1032
|
-
}
|
1006
|
+
return {
|
1007
|
+
layout: panelledEditAttributes,
|
1008
|
+
components: componentEditAttributes,
|
1009
|
+
metadatas: editMetadatas,
|
1010
|
+
settings: {
|
1011
|
+
...data.contentType.settings,
|
1012
|
+
displayName: schema?.info.displayName
|
1033
1013
|
},
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
return { error: res.error };
|
1048
|
-
}
|
1049
|
-
toggleNotification({
|
1050
|
-
type: "success",
|
1051
|
-
message: formatMessage({
|
1052
|
-
id: getTranslation("success.record.publish"),
|
1053
|
-
defaultMessage: "Published document"
|
1054
|
-
})
|
1055
|
-
});
|
1056
|
-
return res.data;
|
1057
|
-
} catch (err) {
|
1058
|
-
toggleNotification({
|
1059
|
-
type: "danger",
|
1060
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1061
|
-
});
|
1062
|
-
throw err;
|
1014
|
+
options: {
|
1015
|
+
...schema?.options,
|
1016
|
+
...schema?.pluginOptions,
|
1017
|
+
...data.contentType.options
|
1018
|
+
}
|
1019
|
+
};
|
1020
|
+
};
|
1021
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1022
|
+
return rows.map(
|
1023
|
+
(row) => row.map((field) => {
|
1024
|
+
const attribute = attributes[field.name];
|
1025
|
+
if (!attribute) {
|
1026
|
+
return null;
|
1063
1027
|
}
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1028
|
+
const { edit: metadata } = metadatas[field.name];
|
1029
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1030
|
+
return {
|
1031
|
+
attribute,
|
1032
|
+
disabled: !metadata.editable,
|
1033
|
+
hint: metadata.description,
|
1034
|
+
label: metadata.label ?? "",
|
1035
|
+
name: field.name,
|
1036
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1037
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1038
|
+
schemas,
|
1039
|
+
components: components?.schemas ?? {}
|
1040
|
+
}),
|
1041
|
+
placeholder: metadata.placeholder ?? "",
|
1042
|
+
required: attribute.required ?? false,
|
1043
|
+
size: field.size,
|
1044
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1045
|
+
visible: metadata.visible ?? true,
|
1046
|
+
type: attribute.type
|
1047
|
+
};
|
1048
|
+
}).filter((field) => field !== null)
|
1072
1049
|
);
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1050
|
+
};
|
1051
|
+
const formatListLayout = (data, {
|
1052
|
+
schemas,
|
1053
|
+
schema,
|
1054
|
+
components
|
1055
|
+
}) => {
|
1056
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1057
|
+
(acc, [attribute, metadata]) => {
|
1058
|
+
return {
|
1059
|
+
...acc,
|
1060
|
+
[attribute]: metadata.list
|
1061
|
+
};
|
1062
|
+
},
|
1063
|
+
{}
|
1064
|
+
);
|
1065
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1066
|
+
data.contentType.layouts.list,
|
1067
|
+
schema?.attributes,
|
1068
|
+
listMetadatas,
|
1069
|
+
{ configurations: data.components, schemas: components },
|
1070
|
+
schemas
|
1071
|
+
);
|
1072
|
+
return {
|
1073
|
+
layout: listAttributes,
|
1074
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1075
|
+
metadatas: listMetadatas,
|
1076
|
+
options: {
|
1077
|
+
...schema?.options,
|
1078
|
+
...schema?.pluginOptions,
|
1079
|
+
...data.contentType.options
|
1080
|
+
}
|
1081
|
+
};
|
1082
|
+
};
|
1083
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1084
|
+
return columns.map((name) => {
|
1085
|
+
const attribute = attributes[name];
|
1086
|
+
if (!attribute) {
|
1087
|
+
return null;
|
1088
|
+
}
|
1089
|
+
const metadata = metadatas[name];
|
1090
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1091
|
+
return {
|
1092
|
+
attribute,
|
1093
|
+
label: metadata.label ?? "",
|
1094
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1095
|
+
schemas,
|
1096
|
+
components: components?.schemas ?? {}
|
1097
|
+
}),
|
1098
|
+
name,
|
1099
|
+
searchable: metadata.searchable ?? true,
|
1100
|
+
sortable: metadata.sortable ?? true
|
1101
|
+
};
|
1102
|
+
}).filter((field) => field !== null);
|
1103
|
+
};
|
1104
|
+
const useDocument = (args, opts) => {
|
1105
|
+
const { toggleNotification } = useNotification();
|
1106
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1107
|
+
const {
|
1108
|
+
currentData: data,
|
1109
|
+
isLoading: isLoadingDocument,
|
1110
|
+
isFetching: isFetchingDocument,
|
1111
|
+
error
|
1112
|
+
} = useGetDocumentQuery(args, {
|
1113
|
+
...opts,
|
1114
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1115
|
+
});
|
1116
|
+
const {
|
1117
|
+
components,
|
1118
|
+
schema,
|
1119
|
+
schemas,
|
1120
|
+
isLoading: isLoadingSchema
|
1121
|
+
} = useContentTypeSchema(args.model);
|
1122
|
+
React.useEffect(() => {
|
1123
|
+
if (error) {
|
1124
|
+
toggleNotification({
|
1125
|
+
type: "danger",
|
1126
|
+
message: formatAPIError(error)
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1130
|
+
const validationSchema = React.useMemo(() => {
|
1131
|
+
if (!schema) {
|
1132
|
+
return null;
|
1133
|
+
}
|
1134
|
+
return createYupSchema(schema.attributes, components);
|
1135
|
+
}, [schema, components]);
|
1136
|
+
const validate = React.useCallback(
|
1137
|
+
(document) => {
|
1138
|
+
if (!validationSchema) {
|
1139
|
+
throw new Error(
|
1140
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1141
|
+
);
|
1142
|
+
}
|
1143
|
+
try {
|
1144
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1145
|
+
return null;
|
1146
|
+
} catch (error2) {
|
1147
|
+
if (error2 instanceof ValidationError) {
|
1148
|
+
return getYupValidationErrors(error2);
|
1089
1149
|
}
|
1090
|
-
|
1091
|
-
toggleNotification({
|
1092
|
-
type: "success",
|
1093
|
-
message: formatMessage({
|
1094
|
-
id: getTranslation("success.record.save"),
|
1095
|
-
defaultMessage: "Saved document"
|
1096
|
-
})
|
1097
|
-
});
|
1098
|
-
return res.data;
|
1099
|
-
} catch (err) {
|
1100
|
-
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1101
|
-
toggleNotification({
|
1102
|
-
type: "danger",
|
1103
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1104
|
-
});
|
1105
|
-
throw err;
|
1150
|
+
throw error2;
|
1106
1151
|
}
|
1107
1152
|
},
|
1108
|
-
[
|
1153
|
+
[validationSchema]
|
1109
1154
|
);
|
1110
|
-
const
|
1111
|
-
const
|
1112
|
-
|
1155
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1156
|
+
const hasError = !!error;
|
1157
|
+
return {
|
1158
|
+
components,
|
1159
|
+
document: data?.data,
|
1160
|
+
meta: data?.meta,
|
1161
|
+
isLoading,
|
1162
|
+
hasError,
|
1163
|
+
schema,
|
1164
|
+
schemas,
|
1165
|
+
validate
|
1166
|
+
};
|
1167
|
+
};
|
1168
|
+
const useDoc = () => {
|
1169
|
+
const { id, slug, collectionType, origin } = useParams();
|
1170
|
+
const [{ query }] = useQueryParams();
|
1171
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1172
|
+
if (!collectionType) {
|
1173
|
+
throw new Error("Could not find collectionType in url params");
|
1174
|
+
}
|
1175
|
+
if (!slug) {
|
1176
|
+
throw new Error("Could not find model in url params");
|
1177
|
+
}
|
1178
|
+
const document = useDocument(
|
1179
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1180
|
+
{
|
1181
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1182
|
+
}
|
1183
|
+
);
|
1184
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1185
|
+
return {
|
1186
|
+
collectionType,
|
1187
|
+
model: slug,
|
1188
|
+
id: returnId,
|
1189
|
+
...document
|
1190
|
+
};
|
1191
|
+
};
|
1192
|
+
const useContentManagerContext = () => {
|
1193
|
+
const {
|
1194
|
+
collectionType,
|
1195
|
+
model,
|
1196
|
+
id,
|
1197
|
+
components,
|
1198
|
+
isLoading: isLoadingDoc,
|
1199
|
+
schema,
|
1200
|
+
schemas
|
1201
|
+
} = useDoc();
|
1202
|
+
const layout = useDocumentLayout(model);
|
1203
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1204
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1205
|
+
const slug = model;
|
1206
|
+
const isCreatingEntry = id === "create";
|
1207
|
+
useContentTypeSchema();
|
1208
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1209
|
+
const error = layout.error;
|
1210
|
+
return {
|
1211
|
+
error,
|
1212
|
+
isLoading,
|
1213
|
+
// Base metadata
|
1214
|
+
model,
|
1215
|
+
collectionType,
|
1216
|
+
id,
|
1217
|
+
slug,
|
1218
|
+
isCreatingEntry,
|
1219
|
+
isSingleType,
|
1220
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1221
|
+
// All schema infos
|
1222
|
+
components,
|
1223
|
+
contentType: schema,
|
1224
|
+
contentTypes: schemas,
|
1225
|
+
// Form state
|
1226
|
+
form,
|
1227
|
+
// layout infos
|
1228
|
+
layout
|
1229
|
+
};
|
1230
|
+
};
|
1231
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1232
|
+
if (!pluginId) {
|
1233
|
+
throw new TypeError("pluginId can't be empty");
|
1234
|
+
}
|
1235
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1236
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1237
|
+
return acc;
|
1238
|
+
}, {});
|
1239
|
+
};
|
1240
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1241
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1242
|
+
id: "notification.error",
|
1243
|
+
defaultMessage: "An error occurred, please try again"
|
1244
|
+
};
|
1245
|
+
const useDocumentActions = () => {
|
1246
|
+
const { toggleNotification } = useNotification();
|
1247
|
+
const { formatMessage } = useIntl();
|
1248
|
+
const { trackUsage } = useTracking();
|
1249
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1250
|
+
const navigate = useNavigate();
|
1251
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1252
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1253
|
+
const _delete = React.useCallback(
|
1254
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1113
1255
|
try {
|
1114
|
-
trackUsage("
|
1115
|
-
const res = await
|
1256
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1257
|
+
const res = await deleteDocument({
|
1116
1258
|
collectionType,
|
1117
1259
|
model,
|
1118
1260
|
documentId,
|
1119
|
-
params
|
1120
|
-
data: {
|
1121
|
-
discardDraft
|
1122
|
-
}
|
1261
|
+
params
|
1123
1262
|
});
|
1124
1263
|
if ("error" in res) {
|
1125
|
-
toggleNotification({
|
1264
|
+
toggleNotification({
|
1265
|
+
type: "danger",
|
1266
|
+
message: formatAPIError(res.error)
|
1267
|
+
});
|
1126
1268
|
return { error: res.error };
|
1127
1269
|
}
|
1128
|
-
trackUsage("didUnpublishEntry");
|
1129
1270
|
toggleNotification({
|
1130
1271
|
type: "success",
|
1131
1272
|
message: formatMessage({
|
1132
|
-
id: getTranslation("success.record.
|
1133
|
-
defaultMessage: "
|
1273
|
+
id: getTranslation("success.record.delete"),
|
1274
|
+
defaultMessage: "Deleted document"
|
1134
1275
|
})
|
1135
1276
|
});
|
1277
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1136
1278
|
return res.data;
|
1137
1279
|
} catch (err) {
|
1138
1280
|
toggleNotification({
|
1139
1281
|
type: "danger",
|
1140
1282
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1141
1283
|
});
|
1284
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1142
1285
|
throw err;
|
1143
1286
|
}
|
1144
1287
|
},
|
1145
|
-
[trackUsage,
|
1288
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1146
1289
|
);
|
1147
|
-
const [
|
1148
|
-
const
|
1290
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1291
|
+
const deleteMany = React.useCallback(
|
1149
1292
|
async ({ model, documentIds, params }) => {
|
1150
1293
|
try {
|
1151
|
-
trackUsage("
|
1152
|
-
const res = await
|
1294
|
+
trackUsage("willBulkDeleteEntries");
|
1295
|
+
const res = await deleteManyDocuments({
|
1153
1296
|
model,
|
1154
1297
|
documentIds,
|
1155
1298
|
params
|
1156
1299
|
});
|
1157
1300
|
if ("error" in res) {
|
1158
|
-
toggleNotification({
|
1301
|
+
toggleNotification({
|
1302
|
+
type: "danger",
|
1303
|
+
message: formatAPIError(res.error)
|
1304
|
+
});
|
1159
1305
|
return { error: res.error };
|
1160
1306
|
}
|
1161
|
-
trackUsage("didBulkUnpublishEntries");
|
1162
1307
|
toggleNotification({
|
1163
1308
|
type: "success",
|
1164
1309
|
title: formatMessage({
|
1165
|
-
id: getTranslation("success.records.
|
1166
|
-
defaultMessage: "Successfully
|
1310
|
+
id: getTranslation("success.records.delete"),
|
1311
|
+
defaultMessage: "Successfully deleted."
|
1167
1312
|
}),
|
1168
1313
|
message: ""
|
1169
1314
|
});
|
1315
|
+
trackUsage("didBulkDeleteEntries");
|
1170
1316
|
return res.data;
|
1171
1317
|
} catch (err) {
|
1172
1318
|
toggleNotification({
|
1173
1319
|
type: "danger",
|
1174
1320
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1175
1321
|
});
|
1176
|
-
trackUsage("
|
1322
|
+
trackUsage("didNotBulkDeleteEntries");
|
1177
1323
|
throw err;
|
1178
1324
|
}
|
1179
1325
|
},
|
1180
|
-
[trackUsage,
|
1326
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1181
1327
|
);
|
1182
|
-
const [
|
1183
|
-
const
|
1184
|
-
async ({ model, params }
|
1328
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1329
|
+
const discard = React.useCallback(
|
1330
|
+
async ({ collectionType, model, documentId, params }) => {
|
1185
1331
|
try {
|
1186
|
-
const res = await
|
1332
|
+
const res = await discardDocument({
|
1333
|
+
collectionType,
|
1187
1334
|
model,
|
1188
|
-
|
1335
|
+
documentId,
|
1189
1336
|
params
|
1190
1337
|
});
|
1191
1338
|
if ("error" in res) {
|
1192
|
-
toggleNotification({
|
1193
|
-
|
1339
|
+
toggleNotification({
|
1340
|
+
type: "danger",
|
1341
|
+
message: formatAPIError(res.error)
|
1342
|
+
});
|
1194
1343
|
return { error: res.error };
|
1195
1344
|
}
|
1196
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1197
1345
|
toggleNotification({
|
1198
1346
|
type: "success",
|
1199
1347
|
message: formatMessage({
|
1200
|
-
id:
|
1201
|
-
defaultMessage: "
|
1348
|
+
id: "content-manager.success.record.discard",
|
1349
|
+
defaultMessage: "Changes discarded"
|
1350
|
+
})
|
1351
|
+
});
|
1352
|
+
return res.data;
|
1353
|
+
} catch (err) {
|
1354
|
+
toggleNotification({
|
1355
|
+
type: "danger",
|
1356
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1357
|
+
});
|
1358
|
+
throw err;
|
1359
|
+
}
|
1360
|
+
},
|
1361
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1362
|
+
);
|
1363
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1364
|
+
const publish = React.useCallback(
|
1365
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1366
|
+
try {
|
1367
|
+
trackUsage("willPublishEntry");
|
1368
|
+
const res = await publishDocument({
|
1369
|
+
collectionType,
|
1370
|
+
model,
|
1371
|
+
documentId,
|
1372
|
+
data,
|
1373
|
+
params
|
1374
|
+
});
|
1375
|
+
if ("error" in res) {
|
1376
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1377
|
+
return { error: res.error };
|
1378
|
+
}
|
1379
|
+
trackUsage("didPublishEntry");
|
1380
|
+
toggleNotification({
|
1381
|
+
type: "success",
|
1382
|
+
message: formatMessage({
|
1383
|
+
id: getTranslation("success.record.publish"),
|
1384
|
+
defaultMessage: "Published document"
|
1385
|
+
})
|
1386
|
+
});
|
1387
|
+
return res.data;
|
1388
|
+
} catch (err) {
|
1389
|
+
toggleNotification({
|
1390
|
+
type: "danger",
|
1391
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1392
|
+
});
|
1393
|
+
throw err;
|
1394
|
+
}
|
1395
|
+
},
|
1396
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1397
|
+
);
|
1398
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1399
|
+
const publishMany = React.useCallback(
|
1400
|
+
async ({ model, documentIds, params }) => {
|
1401
|
+
try {
|
1402
|
+
const res = await publishManyDocuments({
|
1403
|
+
model,
|
1404
|
+
documentIds,
|
1405
|
+
params
|
1406
|
+
});
|
1407
|
+
if ("error" in res) {
|
1408
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1409
|
+
return { error: res.error };
|
1410
|
+
}
|
1411
|
+
toggleNotification({
|
1412
|
+
type: "success",
|
1413
|
+
message: formatMessage({
|
1414
|
+
id: getTranslation("success.record.publish"),
|
1415
|
+
defaultMessage: "Published document"
|
1416
|
+
})
|
1417
|
+
});
|
1418
|
+
return res.data;
|
1419
|
+
} catch (err) {
|
1420
|
+
toggleNotification({
|
1421
|
+
type: "danger",
|
1422
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1423
|
+
});
|
1424
|
+
throw err;
|
1425
|
+
}
|
1426
|
+
},
|
1427
|
+
[
|
1428
|
+
// trackUsage,
|
1429
|
+
publishManyDocuments,
|
1430
|
+
toggleNotification,
|
1431
|
+
formatMessage,
|
1432
|
+
formatAPIError
|
1433
|
+
]
|
1434
|
+
);
|
1435
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1436
|
+
const update = React.useCallback(
|
1437
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1438
|
+
try {
|
1439
|
+
trackUsage("willEditEntry", trackerProperty);
|
1440
|
+
const res = await updateDocument({
|
1441
|
+
collectionType,
|
1442
|
+
model,
|
1443
|
+
documentId,
|
1444
|
+
data,
|
1445
|
+
params
|
1446
|
+
});
|
1447
|
+
if ("error" in res) {
|
1448
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1449
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1450
|
+
return { error: res.error };
|
1451
|
+
}
|
1452
|
+
trackUsage("didEditEntry", trackerProperty);
|
1453
|
+
toggleNotification({
|
1454
|
+
type: "success",
|
1455
|
+
message: formatMessage({
|
1456
|
+
id: getTranslation("success.record.save"),
|
1457
|
+
defaultMessage: "Saved document"
|
1458
|
+
})
|
1459
|
+
});
|
1460
|
+
return res.data;
|
1461
|
+
} catch (err) {
|
1462
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1463
|
+
toggleNotification({
|
1464
|
+
type: "danger",
|
1465
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1466
|
+
});
|
1467
|
+
throw err;
|
1468
|
+
}
|
1469
|
+
},
|
1470
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1471
|
+
);
|
1472
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1473
|
+
const unpublish = React.useCallback(
|
1474
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1475
|
+
try {
|
1476
|
+
trackUsage("willUnpublishEntry");
|
1477
|
+
const res = await unpublishDocument({
|
1478
|
+
collectionType,
|
1479
|
+
model,
|
1480
|
+
documentId,
|
1481
|
+
params,
|
1482
|
+
data: {
|
1483
|
+
discardDraft
|
1484
|
+
}
|
1485
|
+
});
|
1486
|
+
if ("error" in res) {
|
1487
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1488
|
+
return { error: res.error };
|
1489
|
+
}
|
1490
|
+
trackUsage("didUnpublishEntry");
|
1491
|
+
toggleNotification({
|
1492
|
+
type: "success",
|
1493
|
+
message: formatMessage({
|
1494
|
+
id: getTranslation("success.record.unpublish"),
|
1495
|
+
defaultMessage: "Unpublished document"
|
1496
|
+
})
|
1497
|
+
});
|
1498
|
+
return res.data;
|
1499
|
+
} catch (err) {
|
1500
|
+
toggleNotification({
|
1501
|
+
type: "danger",
|
1502
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1503
|
+
});
|
1504
|
+
throw err;
|
1505
|
+
}
|
1506
|
+
},
|
1507
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1508
|
+
);
|
1509
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1510
|
+
const unpublishMany = React.useCallback(
|
1511
|
+
async ({ model, documentIds, params }) => {
|
1512
|
+
try {
|
1513
|
+
trackUsage("willBulkUnpublishEntries");
|
1514
|
+
const res = await unpublishManyDocuments({
|
1515
|
+
model,
|
1516
|
+
documentIds,
|
1517
|
+
params
|
1518
|
+
});
|
1519
|
+
if ("error" in res) {
|
1520
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1521
|
+
return { error: res.error };
|
1522
|
+
}
|
1523
|
+
trackUsage("didBulkUnpublishEntries");
|
1524
|
+
toggleNotification({
|
1525
|
+
type: "success",
|
1526
|
+
title: formatMessage({
|
1527
|
+
id: getTranslation("success.records.unpublish"),
|
1528
|
+
defaultMessage: "Successfully unpublished."
|
1529
|
+
}),
|
1530
|
+
message: ""
|
1531
|
+
});
|
1532
|
+
return res.data;
|
1533
|
+
} catch (err) {
|
1534
|
+
toggleNotification({
|
1535
|
+
type: "danger",
|
1536
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1537
|
+
});
|
1538
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1539
|
+
throw err;
|
1540
|
+
}
|
1541
|
+
},
|
1542
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1543
|
+
);
|
1544
|
+
const [createDocument] = useCreateDocumentMutation();
|
1545
|
+
const create = React.useCallback(
|
1546
|
+
async ({ model, params }, data, trackerProperty) => {
|
1547
|
+
try {
|
1548
|
+
const res = await createDocument({
|
1549
|
+
model,
|
1550
|
+
data,
|
1551
|
+
params
|
1552
|
+
});
|
1553
|
+
if ("error" in res) {
|
1554
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1555
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1556
|
+
return { error: res.error };
|
1557
|
+
}
|
1558
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1559
|
+
toggleNotification({
|
1560
|
+
type: "success",
|
1561
|
+
message: formatMessage({
|
1562
|
+
id: getTranslation("success.record.save"),
|
1563
|
+
defaultMessage: "Saved document"
|
1202
1564
|
})
|
1203
1565
|
});
|
1566
|
+
setCurrentStep("contentManager.success");
|
1204
1567
|
return res.data;
|
1205
1568
|
} catch (err) {
|
1206
1569
|
toggleNotification({
|
@@ -1303,7 +1666,7 @@ const useDocumentActions = () => {
|
|
1303
1666
|
};
|
1304
1667
|
};
|
1305
1668
|
const ProtectedHistoryPage = lazy(
|
1306
|
-
() => import("./History-
|
1669
|
+
() => import("./History-BpLIu67W.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1307
1670
|
);
|
1308
1671
|
const routes$1 = [
|
1309
1672
|
{
|
@@ -1316,31 +1679,31 @@ const routes$1 = [
|
|
1316
1679
|
}
|
1317
1680
|
];
|
1318
1681
|
const ProtectedEditViewPage = lazy(
|
1319
|
-
() => import("./EditViewPage-
|
1682
|
+
() => import("./EditViewPage-al5OO1NR.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1320
1683
|
);
|
1321
1684
|
const ProtectedListViewPage = lazy(
|
1322
|
-
() => import("./ListViewPage-
|
1685
|
+
() => import("./ListViewPage-BbXYNI0v.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1323
1686
|
);
|
1324
1687
|
const ProtectedListConfiguration = lazy(
|
1325
|
-
() => import("./ListConfigurationPage-
|
1688
|
+
() => import("./ListConfigurationPage-DOqj5f8Y.mjs").then((mod) => ({
|
1326
1689
|
default: mod.ProtectedListConfiguration
|
1327
1690
|
}))
|
1328
1691
|
);
|
1329
1692
|
const ProtectedEditConfigurationPage = lazy(
|
1330
|
-
() => import("./EditConfigurationPage-
|
1693
|
+
() => import("./EditConfigurationPage-W07CEdm2.mjs").then((mod) => ({
|
1331
1694
|
default: mod.ProtectedEditConfigurationPage
|
1332
1695
|
}))
|
1333
1696
|
);
|
1334
1697
|
const ProtectedComponentConfigurationPage = lazy(
|
1335
|
-
() => import("./ComponentConfigurationPage-
|
1698
|
+
() => import("./ComponentConfigurationPage-jmWwucg_.mjs").then((mod) => ({
|
1336
1699
|
default: mod.ProtectedComponentConfigurationPage
|
1337
1700
|
}))
|
1338
1701
|
);
|
1339
1702
|
const NoPermissions = lazy(
|
1340
|
-
() => import("./NoPermissionsPage-
|
1703
|
+
() => import("./NoPermissionsPage-Km0Vk5Wp.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1341
1704
|
);
|
1342
1705
|
const NoContentType = lazy(
|
1343
|
-
() => import("./NoContentTypePage-
|
1706
|
+
() => import("./NoContentTypePage-w2Q0VVOT.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1344
1707
|
);
|
1345
1708
|
const CollectionTypePages = () => {
|
1346
1709
|
const { collectionType } = useParams();
|
@@ -1694,6 +2057,18 @@ const DocumentActionModal = ({
|
|
1694
2057
|
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
1695
2058
|
] }) });
|
1696
2059
|
};
|
2060
|
+
const transformData = (data) => {
|
2061
|
+
if (Array.isArray(data)) {
|
2062
|
+
return data.map(transformData);
|
2063
|
+
}
|
2064
|
+
if (typeof data === "object" && data !== null) {
|
2065
|
+
if ("apiData" in data) {
|
2066
|
+
return data.apiData;
|
2067
|
+
}
|
2068
|
+
return mapValues(transformData)(data);
|
2069
|
+
}
|
2070
|
+
return data;
|
2071
|
+
};
|
1697
2072
|
const PublishAction$1 = ({
|
1698
2073
|
activeTab,
|
1699
2074
|
documentId,
|
@@ -1787,7 +2162,9 @@ const PublishAction$1 = ({
|
|
1787
2162
|
const performPublish = async () => {
|
1788
2163
|
setSubmitting(true);
|
1789
2164
|
try {
|
1790
|
-
const { errors } = await validate(
|
2165
|
+
const { errors } = await validate(true, {
|
2166
|
+
status: "published"
|
2167
|
+
});
|
1791
2168
|
if (errors) {
|
1792
2169
|
toggleNotification({
|
1793
2170
|
type: "danger",
|
@@ -1805,7 +2182,7 @@ const PublishAction$1 = ({
|
|
1805
2182
|
documentId,
|
1806
2183
|
params
|
1807
2184
|
},
|
1808
|
-
formValues
|
2185
|
+
transformData(formValues)
|
1809
2186
|
);
|
1810
2187
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1811
2188
|
navigate({
|
@@ -1901,18 +2278,18 @@ const UpdateAction = ({
|
|
1901
2278
|
onClick: async () => {
|
1902
2279
|
setSubmitting(true);
|
1903
2280
|
try {
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
})
|
1914
|
-
|
1915
|
-
|
2281
|
+
const { errors } = await validate(true, {
|
2282
|
+
status: "draft"
|
2283
|
+
});
|
2284
|
+
if (errors) {
|
2285
|
+
toggleNotification({
|
2286
|
+
type: "danger",
|
2287
|
+
message: formatMessage({
|
2288
|
+
id: "content-manager.validation.error",
|
2289
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2290
|
+
})
|
2291
|
+
});
|
2292
|
+
return;
|
1916
2293
|
}
|
1917
2294
|
if (isCloning) {
|
1918
2295
|
const res = await clone(
|
@@ -1921,7 +2298,7 @@ const UpdateAction = ({
|
|
1921
2298
|
documentId: cloneMatch.params.origin,
|
1922
2299
|
params
|
1923
2300
|
},
|
1924
|
-
document
|
2301
|
+
transformData(document)
|
1925
2302
|
);
|
1926
2303
|
if ("data" in res) {
|
1927
2304
|
navigate(
|
@@ -1942,7 +2319,7 @@ const UpdateAction = ({
|
|
1942
2319
|
documentId,
|
1943
2320
|
params
|
1944
2321
|
},
|
1945
|
-
document
|
2322
|
+
transformData(document)
|
1946
2323
|
);
|
1947
2324
|
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1948
2325
|
setErrors(formatValidationErrors(res.error));
|
@@ -1955,7 +2332,7 @@ const UpdateAction = ({
|
|
1955
2332
|
model,
|
1956
2333
|
params
|
1957
2334
|
},
|
1958
|
-
document
|
2335
|
+
transformData(document)
|
1959
2336
|
);
|
1960
2337
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1961
2338
|
navigate(
|
@@ -2294,12 +2671,12 @@ const Information = ({ activeTab }) => {
|
|
2294
2671
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2295
2672
|
label: formatMessage({
|
2296
2673
|
id: "content-manager.containers.edit.information.last-published.label",
|
2297
|
-
defaultMessage: "
|
2674
|
+
defaultMessage: "Published"
|
2298
2675
|
}),
|
2299
2676
|
value: formatMessage(
|
2300
2677
|
{
|
2301
2678
|
id: "content-manager.containers.edit.information.last-published.value",
|
2302
|
-
defaultMessage: `
|
2679
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2303
2680
|
},
|
2304
2681
|
{
|
2305
2682
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2312,12 +2689,12 @@ const Information = ({ activeTab }) => {
|
|
2312
2689
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2313
2690
|
label: formatMessage({
|
2314
2691
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2315
|
-
defaultMessage: "
|
2692
|
+
defaultMessage: "Updated"
|
2316
2693
|
}),
|
2317
2694
|
value: formatMessage(
|
2318
2695
|
{
|
2319
2696
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2320
|
-
defaultMessage: `
|
2697
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2321
2698
|
},
|
2322
2699
|
{
|
2323
2700
|
time: /* @__PURE__ */ jsx(
|
@@ -2335,12 +2712,12 @@ const Information = ({ activeTab }) => {
|
|
2335
2712
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2336
2713
|
label: formatMessage({
|
2337
2714
|
id: "content-manager.containers.edit.information.document.label",
|
2338
|
-
defaultMessage: "
|
2715
|
+
defaultMessage: "Created"
|
2339
2716
|
}),
|
2340
2717
|
value: formatMessage(
|
2341
2718
|
{
|
2342
2719
|
id: "content-manager.containers.edit.information.document.value",
|
2343
|
-
defaultMessage: `
|
2720
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2344
2721
|
},
|
2345
2722
|
{
|
2346
2723
|
time: /* @__PURE__ */ jsx(
|
@@ -2398,10 +2775,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2398
2775
|
SingleSelect,
|
2399
2776
|
{
|
2400
2777
|
size: "S",
|
2401
|
-
disabled: action.disabled,
|
2402
|
-
"aria-label": action.label,
|
2403
2778
|
onChange: action.onSelect,
|
2404
|
-
|
2779
|
+
"aria-label": action.label,
|
2780
|
+
...action,
|
2405
2781
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2406
2782
|
},
|
2407
2783
|
action.id
|
@@ -2465,490 +2841,191 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
|
|
2465
2841
|
position: "header"
|
2466
2842
|
};
|
2467
2843
|
};
|
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
|
-
);
|
2844
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2845
|
+
const EditTheModelAction = ({ model }) => {
|
2846
|
+
const navigate = useNavigate();
|
2847
|
+
const { formatMessage } = useIntl();
|
2854
2848
|
return {
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2849
|
+
label: formatMessage({
|
2850
|
+
id: "content-manager.link-to-ctb",
|
2851
|
+
defaultMessage: "Edit the model"
|
2852
|
+
}),
|
2853
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2854
|
+
onClick: () => {
|
2855
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2861
2856
|
},
|
2862
|
-
|
2863
|
-
...schema?.options,
|
2864
|
-
...schema?.pluginOptions,
|
2865
|
-
...data.contentType.options
|
2866
|
-
}
|
2857
|
+
position: "header"
|
2867
2858
|
};
|
2868
2859
|
};
|
2869
|
-
|
2870
|
-
|
2871
|
-
|
2872
|
-
|
2873
|
-
|
2874
|
-
|
2860
|
+
EditTheModelAction.type = "edit-the-model";
|
2861
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2862
|
+
const navigate = useNavigate();
|
2863
|
+
const { formatMessage } = useIntl();
|
2864
|
+
const listViewPathMatch = useMatch(LIST_PATH);
|
2865
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2866
|
+
const { delete: deleteAction } = useDocumentActions();
|
2867
|
+
const { toggleNotification } = useNotification();
|
2868
|
+
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2869
|
+
const isLocalized = document?.locale != null;
|
2870
|
+
return {
|
2871
|
+
disabled: !canDelete || !document,
|
2872
|
+
label: formatMessage(
|
2873
|
+
{
|
2874
|
+
id: "content-manager.actions.delete.label",
|
2875
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2876
|
+
},
|
2877
|
+
{ isLocalized }
|
2878
|
+
),
|
2879
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2880
|
+
dialog: {
|
2881
|
+
type: "dialog",
|
2882
|
+
title: formatMessage({
|
2883
|
+
id: "app.components.ConfirmDialog.title",
|
2884
|
+
defaultMessage: "Confirmation"
|
2885
|
+
}),
|
2886
|
+
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2887
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2888
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2889
|
+
id: "content-manager.actions.delete.dialog.body",
|
2890
|
+
defaultMessage: "Are you sure?"
|
2891
|
+
}) })
|
2892
|
+
] }),
|
2893
|
+
onConfirm: async () => {
|
2894
|
+
if (!listViewPathMatch) {
|
2895
|
+
setSubmitting(true);
|
2896
|
+
}
|
2897
|
+
try {
|
2898
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2899
|
+
console.error(
|
2900
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2901
|
+
);
|
2902
|
+
toggleNotification({
|
2903
|
+
message: formatMessage({
|
2904
|
+
id: "content-manager.actions.delete.error",
|
2905
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2906
|
+
}),
|
2907
|
+
type: "danger"
|
2908
|
+
});
|
2909
|
+
return;
|
2910
|
+
}
|
2911
|
+
const res = await deleteAction({
|
2912
|
+
documentId,
|
2913
|
+
model,
|
2914
|
+
collectionType,
|
2915
|
+
params: {
|
2916
|
+
locale: "*"
|
2917
|
+
}
|
2918
|
+
});
|
2919
|
+
if (!("error" in res)) {
|
2920
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2921
|
+
}
|
2922
|
+
} finally {
|
2923
|
+
if (!listViewPathMatch) {
|
2924
|
+
setSubmitting(false);
|
2925
|
+
}
|
2926
|
+
}
|
2875
2927
|
}
|
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
2928
|
},
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
2922
|
-
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2929
|
+
variant: "danger",
|
2930
|
+
position: ["header", "table-row"]
|
2931
|
+
};
|
2932
|
+
};
|
2933
|
+
DeleteAction$1.type = "delete";
|
2934
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2935
|
+
const Panels = () => {
|
2936
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2937
|
+
const [
|
2938
|
+
{
|
2939
|
+
query: { status }
|
2940
|
+
}
|
2941
|
+
] = useQueryParams({
|
2942
|
+
status: "draft"
|
2943
|
+
});
|
2944
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2945
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2946
|
+
const props = {
|
2947
|
+
activeTab: status,
|
2948
|
+
model,
|
2949
|
+
documentId: id,
|
2950
|
+
document: isCloning ? void 0 : document,
|
2951
|
+
meta: isCloning ? void 0 : meta,
|
2952
|
+
collectionType
|
2953
|
+
};
|
2954
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2955
|
+
DescriptionComponentRenderer,
|
2956
|
+
{
|
2957
|
+
props,
|
2958
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2959
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2928
2960
|
}
|
2961
|
+
) });
|
2962
|
+
};
|
2963
|
+
const ActionsPanel = () => {
|
2964
|
+
const { formatMessage } = useIntl();
|
2965
|
+
return {
|
2966
|
+
title: formatMessage({
|
2967
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2968
|
+
defaultMessage: "Entry"
|
2969
|
+
}),
|
2970
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2929
2971
|
};
|
2930
2972
|
};
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2973
|
+
ActionsPanel.type = "actions";
|
2974
|
+
const ActionsPanelContent = () => {
|
2975
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2976
|
+
const [
|
2977
|
+
{
|
2978
|
+
query: { status = "draft" }
|
2936
2979
|
}
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2949
|
-
|
2950
|
-
|
2980
|
+
] = useQueryParams();
|
2981
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2982
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2983
|
+
const props = {
|
2984
|
+
activeTab: status,
|
2985
|
+
model,
|
2986
|
+
documentId: id,
|
2987
|
+
document: isCloning ? void 0 : document,
|
2988
|
+
meta: isCloning ? void 0 : meta,
|
2989
|
+
collectionType
|
2990
|
+
};
|
2991
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2992
|
+
/* @__PURE__ */ jsx(
|
2993
|
+
DescriptionComponentRenderer,
|
2994
|
+
{
|
2995
|
+
props,
|
2996
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2997
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2998
|
+
}
|
2999
|
+
),
|
3000
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3001
|
+
] });
|
2951
3002
|
};
|
3003
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
3004
|
+
return /* @__PURE__ */ jsxs(
|
3005
|
+
Flex,
|
3006
|
+
{
|
3007
|
+
ref,
|
3008
|
+
tag: "aside",
|
3009
|
+
"aria-labelledby": "additional-information",
|
3010
|
+
background: "neutral0",
|
3011
|
+
borderColor: "neutral150",
|
3012
|
+
hasRadius: true,
|
3013
|
+
paddingBottom: 4,
|
3014
|
+
paddingLeft: 4,
|
3015
|
+
paddingRight: 4,
|
3016
|
+
paddingTop: 4,
|
3017
|
+
shadow: "tableShadow",
|
3018
|
+
gap: 3,
|
3019
|
+
direction: "column",
|
3020
|
+
justifyContent: "stretch",
|
3021
|
+
alignItems: "flex-start",
|
3022
|
+
children: [
|
3023
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3024
|
+
children
|
3025
|
+
]
|
3026
|
+
}
|
3027
|
+
);
|
3028
|
+
});
|
2952
3029
|
const ConfirmBulkActionDialog = ({
|
2953
3030
|
onToggleDialog,
|
2954
3031
|
isOpen = false,
|
@@ -3945,7 +4022,7 @@ const index = {
|
|
3945
4022
|
app.router.addRoute({
|
3946
4023
|
path: "content-manager/*",
|
3947
4024
|
lazy: async () => {
|
3948
|
-
const { Layout } = await import("./layout-
|
4025
|
+
const { Layout } = await import("./layout-BavJ6v4B.mjs");
|
3949
4026
|
return {
|
3950
4027
|
Component: Layout
|
3951
4028
|
};
|
@@ -3962,7 +4039,7 @@ const index = {
|
|
3962
4039
|
async registerTrads({ locales }) {
|
3963
4040
|
const importedTrads = await Promise.all(
|
3964
4041
|
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-
|
4042
|
+
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
4043
|
return {
|
3967
4044
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3968
4045
|
locale
|
@@ -3990,7 +4067,8 @@ export {
|
|
3990
4067
|
InjectionZone as I,
|
3991
4068
|
useDocument as J,
|
3992
4069
|
index as K,
|
3993
|
-
|
4070
|
+
useContentManagerContext as L,
|
4071
|
+
useDocumentActions as M,
|
3994
4072
|
Panels as P,
|
3995
4073
|
RelativeTime as R,
|
3996
4074
|
SINGLE_TYPES as S,
|
@@ -4022,4 +4100,4 @@ export {
|
|
4022
4100
|
capitalise as y,
|
4023
4101
|
useUpdateContentTypeConfigurationMutation as z
|
4024
4102
|
};
|
4025
|
-
//# sourceMappingURL=index-
|
4103
|
+
//# sourceMappingURL=index-DcQ6xogO.mjs.map
|