@strapi/content-manager 0.0.0-experimental.afa3b513b8f95459043f33fb94f4bac03af1474f → 0.0.0-experimental.b9dd0757c8a7db6ee1063edc33424319784ae3a6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-G4EIirP8.js → ComponentConfigurationPage-B-r3vk8T.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-G4EIirP8.js.map → ComponentConfigurationPage-B-r3vk8T.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CnL10QYC.mjs → ComponentConfigurationPage-Dp3ZXzP_.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CnL10QYC.mjs.map → ComponentConfigurationPage-Dp3ZXzP_.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-B2AA1kVF.js → EditConfigurationPage-Cs-8XG8_.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-B2AA1kVF.js.map → EditConfigurationPage-Cs-8XG8_.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-I2kKh9dx.mjs → EditConfigurationPage-qFNC9RPm.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-I2kKh9dx.mjs.map → EditConfigurationPage-qFNC9RPm.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CHgoNwlc.js → EditViewPage-CqMtsGgl.js} +15 -5
- package/dist/_chunks/EditViewPage-CqMtsGgl.js.map +1 -0
- package/dist/_chunks/{EditViewPage-zFjJK0s8.mjs → EditViewPage-noMD5CfK.mjs} +15 -5
- package/dist/_chunks/EditViewPage-noMD5CfK.mjs.map +1 -0
- package/dist/_chunks/{Field-DPAzUS1M.mjs → Field-BMxOXDMC.mjs} +69 -25
- package/dist/_chunks/Field-BMxOXDMC.mjs.map +1 -0
- package/dist/_chunks/{Field-9DePZh-0.js → Field-BWObiIQ3.js} +69 -25
- package/dist/_chunks/Field-BWObiIQ3.js.map +1 -0
- package/dist/_chunks/{Form-CEkENbkF.mjs → Form-BTT42lt4.mjs} +3 -3
- package/dist/_chunks/Form-BTT42lt4.mjs.map +1 -0
- package/dist/_chunks/{Form-DPm-KZ1A.js → Form-CZ9hswVy.js} +3 -3
- package/dist/_chunks/Form-CZ9hswVy.js.map +1 -0
- package/dist/_chunks/{History-utls71em.mjs → History-CQf4ssdU.mjs} +24 -11
- package/dist/_chunks/History-CQf4ssdU.mjs.map +1 -0
- package/dist/_chunks/{History-DXSbTWez.js → History-DdZTjeEU.js} +23 -10
- package/dist/_chunks/History-DdZTjeEU.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-D5C7ACZ_.js → ListConfigurationPage-C-8hLgKb.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-D5C7ACZ_.js.map → ListConfigurationPage-C-8hLgKb.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-CuMXWWqb.mjs → ListConfigurationPage-DXy-IKAk.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-CuMXWWqb.mjs.map → ListConfigurationPage-DXy-IKAk.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-DfuwH1tt.js → ListViewPage-CPbs8bml.js} +4 -4
- package/dist/_chunks/{ListViewPage-DfuwH1tt.js.map → ListViewPage-CPbs8bml.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-CdKd-PS_.mjs → ListViewPage-DAvl-VG5.mjs} +4 -4
- package/dist/_chunks/{ListViewPage-CdKd-PS_.mjs.map → ListViewPage-DAvl-VG5.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BIxlkWWi.js → NoContentTypePage-Bz_9RdLr.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BIxlkWWi.js.map → NoContentTypePage-Bz_9RdLr.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DkToTT7u.mjs → NoContentTypePage-D-DbFSFh.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DkToTT7u.mjs.map → NoContentTypePage-D-DbFSFh.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DlWi4BAH.mjs → NoPermissionsPage-BzSfwl62.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DlWi4BAH.mjs.map → NoPermissionsPage-BzSfwl62.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Bu4GWYb-.js → NoPermissionsPage-De5GsnjI.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Bu4GWYb-.js.map → NoPermissionsPage-De5GsnjI.js.map} +1 -1
- package/dist/_chunks/{Relations-QP5yn9_z.mjs → Relations-CsjdyIXg.mjs} +32 -23
- package/dist/_chunks/Relations-CsjdyIXg.mjs.map +1 -0
- package/dist/_chunks/{Relations-CFjTESWQ.js → Relations-DLMpxASn.js} +32 -23
- package/dist/_chunks/Relations-DLMpxASn.js.map +1 -0
- package/dist/_chunks/{en-BVzUkPxZ.js → en-Bm0D0IWz.js} +8 -8
- package/dist/_chunks/{en-BVzUkPxZ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-CPTj6CjC.mjs → en-DKV44jRb.mjs} +8 -8
- package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-BHfS6_D5.mjs → index-D1ol0KTz.mjs} +933 -867
- package/dist/_chunks/index-D1ol0KTz.mjs.map +1 -0
- package/dist/_chunks/{index-DXiHxy70.js → index-DFWNpb4M.js} +931 -865
- package/dist/_chunks/index-DFWNpb4M.js.map +1 -0
- package/dist/_chunks/{layout-bE-WUnQ0.js → layout-CfocPPPK.js} +3 -3
- package/dist/_chunks/{layout-bE-WUnQ0.js.map → layout-CfocPPPK.js.map} +1 -1
- package/dist/_chunks/{layout-DX_52HSH.mjs → layout-DZAT9E_K.mjs} +3 -3
- package/dist/_chunks/{layout-DX_52HSH.mjs.map → layout-DZAT9E_K.mjs.map} +1 -1
- package/dist/_chunks/{relations-SCVAL_aJ.mjs → relations-BOmKF9Py.mjs} +2 -2
- package/dist/_chunks/{relations-SCVAL_aJ.mjs.map → relations-BOmKF9Py.mjs.map} +1 -1
- package/dist/_chunks/{relations-D706vblp.js → relations-CDuOkPbo.js} +2 -2
- package/dist/_chunks/{relations-D706vblp.js.map → relations-CDuOkPbo.js.map} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/Header.d.ts +1 -0
- package/dist/server/index.js +27 -14
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +27 -14
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/_chunks/EditViewPage-CHgoNwlc.js.map +0 -1
- package/dist/_chunks/EditViewPage-zFjJK0s8.mjs.map +0 -1
- package/dist/_chunks/Field-9DePZh-0.js.map +0 -1
- package/dist/_chunks/Field-DPAzUS1M.mjs.map +0 -1
- package/dist/_chunks/Form-CEkENbkF.mjs.map +0 -1
- package/dist/_chunks/Form-DPm-KZ1A.js.map +0 -1
- package/dist/_chunks/History-DXSbTWez.js.map +0 -1
- package/dist/_chunks/History-utls71em.mjs.map +0 -1
- package/dist/_chunks/Relations-CFjTESWQ.js.map +0 -1
- package/dist/_chunks/Relations-QP5yn9_z.mjs.map +0 -1
- package/dist/_chunks/index-BHfS6_D5.mjs.map +0 -1
- package/dist/_chunks/index-DXiHxy70.js.map +0 -1
@@ -121,6 +121,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
121
121
|
if (!slug) {
|
122
122
|
throw new Error("Cannot find the slug param in the URL");
|
123
123
|
}
|
124
|
+
const [{ rawQuery }] = strapiAdmin.useQueryParams();
|
124
125
|
const userPermissions = strapiAdmin.useAuth("DocumentRBAC", (state) => state.permissions);
|
125
126
|
const contentTypePermissions = React__namespace.useMemo(() => {
|
126
127
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -131,7 +132,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
131
132
|
return { ...acc, [action]: [permission] };
|
132
133
|
}, {});
|
133
134
|
}, [slug, userPermissions]);
|
134
|
-
const { isLoading, allowedActions } = strapiAdmin.useRBAC(
|
135
|
+
const { isLoading, allowedActions } = strapiAdmin.useRBAC(
|
136
|
+
contentTypePermissions,
|
137
|
+
permissions ?? void 0,
|
138
|
+
// TODO: useRBAC context should be typed and built differently
|
139
|
+
// We are passing raw query as context to the hook so that it can
|
140
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
141
|
+
rawQuery
|
142
|
+
);
|
135
143
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
136
144
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
137
145
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -482,6 +490,24 @@ const buildValidParams = (query) => {
|
|
482
490
|
const isBaseQueryError = (error) => {
|
483
491
|
return error.name !== void 0;
|
484
492
|
};
|
493
|
+
const arrayValidator = (attribute, options) => ({
|
494
|
+
message: strapiAdmin.translatedErrors.required,
|
495
|
+
test(value) {
|
496
|
+
if (options.status === "draft") {
|
497
|
+
return true;
|
498
|
+
}
|
499
|
+
if (!attribute.required) {
|
500
|
+
return true;
|
501
|
+
}
|
502
|
+
if (!value) {
|
503
|
+
return false;
|
504
|
+
}
|
505
|
+
if (Array.isArray(value) && value.length === 0) {
|
506
|
+
return false;
|
507
|
+
}
|
508
|
+
return true;
|
509
|
+
}
|
510
|
+
});
|
485
511
|
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
486
512
|
const createModelSchema = (attributes2) => yup__namespace.object().shape(
|
487
513
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
@@ -489,6 +515,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
489
515
|
return acc;
|
490
516
|
}
|
491
517
|
const validations = [
|
518
|
+
addNullableValidation,
|
492
519
|
addRequiredValidation,
|
493
520
|
addMinLengthValidation,
|
494
521
|
addMaxLengthValidation,
|
@@ -505,12 +532,12 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
505
532
|
...acc,
|
506
533
|
[name]: transformSchema(
|
507
534
|
yup__namespace.array().of(createModelSchema(attributes3).nullable(false))
|
508
|
-
)
|
535
|
+
).test(arrayValidator(attribute, options))
|
509
536
|
};
|
510
537
|
} else {
|
511
538
|
return {
|
512
539
|
...acc,
|
513
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
540
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
514
541
|
};
|
515
542
|
}
|
516
543
|
}
|
@@ -532,7 +559,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
532
559
|
}
|
533
560
|
)
|
534
561
|
)
|
535
|
-
)
|
562
|
+
).test(arrayValidator(attribute, options))
|
536
563
|
};
|
537
564
|
case "relation":
|
538
565
|
return {
|
@@ -544,7 +571,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
544
571
|
} else if (Array.isArray(value)) {
|
545
572
|
return yup__namespace.array().of(
|
546
573
|
yup__namespace.object().shape({
|
547
|
-
id: yup__namespace.
|
574
|
+
id: yup__namespace.number().required()
|
548
575
|
})
|
549
576
|
);
|
550
577
|
} else if (typeof value === "object") {
|
@@ -630,17 +657,17 @@ const nullableSchema = (schema) => {
|
|
630
657
|
schema
|
631
658
|
);
|
632
659
|
};
|
660
|
+
const addNullableValidation = () => (schema) => {
|
661
|
+
return nullableSchema(schema);
|
662
|
+
};
|
633
663
|
const addRequiredValidation = (attribute, options) => (schema) => {
|
634
|
-
if (options.status === "draft") {
|
635
|
-
return
|
636
|
-
}
|
637
|
-
if ((attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") && attribute.required && "min" in schema) {
|
638
|
-
return schema.min(1, strapiAdmin.translatedErrors.required);
|
664
|
+
if (options.status === "draft" || !attribute.required) {
|
665
|
+
return schema;
|
639
666
|
}
|
640
|
-
if (attribute.required &&
|
667
|
+
if (attribute.required && "required" in schema) {
|
641
668
|
return schema.required(strapiAdmin.translatedErrors.required);
|
642
669
|
}
|
643
|
-
return
|
670
|
+
return schema;
|
644
671
|
};
|
645
672
|
const addMinLengthValidation = (attribute, options) => (schema) => {
|
646
673
|
if (options.status === "draft") {
|
@@ -668,31 +695,12 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
668
695
|
return schema;
|
669
696
|
};
|
670
697
|
const addMinValidation = (attribute, options) => (schema) => {
|
671
|
-
if ("
|
698
|
+
if (options.status === "draft") {
|
699
|
+
return schema;
|
700
|
+
}
|
701
|
+
if ("min" in attribute && "min" in schema) {
|
672
702
|
const min = toInteger(attribute.min);
|
673
|
-
if (
|
674
|
-
if (options.status !== "draft" && !attribute.required && "test" in schema && min) {
|
675
|
-
return schema.test(
|
676
|
-
"custom-min",
|
677
|
-
{
|
678
|
-
...strapiAdmin.translatedErrors.min,
|
679
|
-
values: {
|
680
|
-
min: attribute.min
|
681
|
-
}
|
682
|
-
},
|
683
|
-
(value) => {
|
684
|
-
if (!value) {
|
685
|
-
return true;
|
686
|
-
}
|
687
|
-
if (Array.isArray(value) && value.length === 0) {
|
688
|
-
return true;
|
689
|
-
}
|
690
|
-
return value.length >= min;
|
691
|
-
}
|
692
|
-
);
|
693
|
-
}
|
694
|
-
}
|
695
|
-
if ("min" in schema && min) {
|
703
|
+
if (min) {
|
696
704
|
return schema.min(min, {
|
697
705
|
...strapiAdmin.translatedErrors.min,
|
698
706
|
values: {
|
@@ -810,19 +818,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
810
818
|
}, {});
|
811
819
|
return componentsByKey;
|
812
820
|
};
|
813
|
-
const
|
821
|
+
const HOOKS = {
|
822
|
+
/**
|
823
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
824
|
+
* @constant
|
825
|
+
* @type {string}
|
826
|
+
*/
|
827
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
828
|
+
/**
|
829
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
830
|
+
* @constant
|
831
|
+
* @type {string}
|
832
|
+
*/
|
833
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
834
|
+
/**
|
835
|
+
* Hook that allows to mutate the CM's edit view layout
|
836
|
+
* @constant
|
837
|
+
* @type {string}
|
838
|
+
*/
|
839
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
840
|
+
/**
|
841
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
842
|
+
* @constant
|
843
|
+
* @type {string}
|
844
|
+
*/
|
845
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
846
|
+
};
|
847
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
848
|
+
endpoints: (builder) => ({
|
849
|
+
getContentTypeConfiguration: builder.query({
|
850
|
+
query: (uid) => ({
|
851
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
852
|
+
method: "GET"
|
853
|
+
}),
|
854
|
+
transformResponse: (response) => response.data,
|
855
|
+
providesTags: (_result, _error, uid) => [
|
856
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
857
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
858
|
+
]
|
859
|
+
}),
|
860
|
+
getAllContentTypeSettings: builder.query({
|
861
|
+
query: () => "/content-manager/content-types-settings",
|
862
|
+
transformResponse: (response) => response.data,
|
863
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
864
|
+
}),
|
865
|
+
updateContentTypeConfiguration: builder.mutation({
|
866
|
+
query: ({ uid, ...body }) => ({
|
867
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
868
|
+
method: "PUT",
|
869
|
+
data: body
|
870
|
+
}),
|
871
|
+
transformResponse: (response) => response.data,
|
872
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
873
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
874
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
875
|
+
// Is this necessary?
|
876
|
+
{ type: "InitialData" }
|
877
|
+
]
|
878
|
+
})
|
879
|
+
})
|
880
|
+
});
|
881
|
+
const {
|
882
|
+
useGetContentTypeConfigurationQuery,
|
883
|
+
useGetAllContentTypeSettingsQuery,
|
884
|
+
useUpdateContentTypeConfigurationMutation
|
885
|
+
} = contentTypesApi;
|
886
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
887
|
+
const { type } = attribute;
|
888
|
+
if (type === "relation") {
|
889
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
890
|
+
}
|
891
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
892
|
+
};
|
893
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
894
|
+
if (!mainFieldName) {
|
895
|
+
return void 0;
|
896
|
+
}
|
897
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
898
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
899
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
900
|
+
);
|
901
|
+
return {
|
902
|
+
name: mainFieldName,
|
903
|
+
type: mainFieldType ?? "string"
|
904
|
+
};
|
905
|
+
};
|
906
|
+
const DEFAULT_SETTINGS = {
|
907
|
+
bulkable: false,
|
908
|
+
filterable: false,
|
909
|
+
searchable: false,
|
910
|
+
pagination: false,
|
911
|
+
defaultSortBy: "",
|
912
|
+
defaultSortOrder: "asc",
|
913
|
+
mainField: "id",
|
914
|
+
pageSize: 10
|
915
|
+
};
|
916
|
+
const useDocumentLayout = (model) => {
|
917
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
918
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
919
|
+
const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
814
920
|
const { toggleNotification } = strapiAdmin.useNotification();
|
815
921
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
922
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
816
923
|
const {
|
817
|
-
|
818
|
-
isLoading:
|
819
|
-
|
820
|
-
|
821
|
-
} =
|
822
|
-
|
823
|
-
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
824
|
-
});
|
825
|
-
const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
|
924
|
+
data,
|
925
|
+
isLoading: isLoadingConfigs,
|
926
|
+
error,
|
927
|
+
isFetching: isFetchingConfigs
|
928
|
+
} = useGetContentTypeConfigurationQuery(model);
|
929
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
826
930
|
React__namespace.useEffect(() => {
|
827
931
|
if (error) {
|
828
932
|
toggleNotification({
|
@@ -830,398 +934,657 @@ const useDocument = (args, opts) => {
|
|
830
934
|
message: formatAPIError(error)
|
831
935
|
});
|
832
936
|
}
|
833
|
-
}, [
|
834
|
-
const
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
(document) => {
|
842
|
-
if (!validationSchema) {
|
843
|
-
throw new Error(
|
844
|
-
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
845
|
-
);
|
846
|
-
}
|
847
|
-
try {
|
848
|
-
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
849
|
-
return null;
|
850
|
-
} catch (error2) {
|
851
|
-
if (error2 instanceof yup.ValidationError) {
|
852
|
-
return strapiAdmin.getYupValidationErrors(error2);
|
853
|
-
}
|
854
|
-
throw error2;
|
855
|
-
}
|
937
|
+
}, [error, formatAPIError, toggleNotification]);
|
938
|
+
const editLayout = React__namespace.useMemo(
|
939
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
940
|
+
layout: [],
|
941
|
+
components: {},
|
942
|
+
metadatas: {},
|
943
|
+
options: {},
|
944
|
+
settings: DEFAULT_SETTINGS
|
856
945
|
},
|
857
|
-
[
|
946
|
+
[data, isLoading, schemas, schema, components]
|
947
|
+
);
|
948
|
+
const listLayout = React__namespace.useMemo(() => {
|
949
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
950
|
+
layout: [],
|
951
|
+
metadatas: {},
|
952
|
+
options: {},
|
953
|
+
settings: DEFAULT_SETTINGS
|
954
|
+
};
|
955
|
+
}, [data, isLoading, schemas, schema, components]);
|
956
|
+
const { layout: edit } = React__namespace.useMemo(
|
957
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
958
|
+
layout: editLayout,
|
959
|
+
query
|
960
|
+
}),
|
961
|
+
[editLayout, query, runHookWaterfall]
|
858
962
|
);
|
859
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
860
963
|
return {
|
861
|
-
|
862
|
-
document: data?.data,
|
863
|
-
meta: data?.meta,
|
964
|
+
error,
|
864
965
|
isLoading,
|
865
|
-
|
866
|
-
|
867
|
-
};
|
868
|
-
};
|
869
|
-
const useDoc = () => {
|
870
|
-
const { id, slug, collectionType, origin } = reactRouterDom.useParams();
|
871
|
-
const [{ query }] = strapiAdmin.useQueryParams();
|
872
|
-
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
873
|
-
if (!collectionType) {
|
874
|
-
throw new Error("Could not find collectionType in url params");
|
875
|
-
}
|
876
|
-
if (!slug) {
|
877
|
-
throw new Error("Could not find model in url params");
|
878
|
-
}
|
879
|
-
return {
|
880
|
-
collectionType,
|
881
|
-
model: slug,
|
882
|
-
id: origin || id === "create" ? void 0 : id,
|
883
|
-
...useDocument(
|
884
|
-
{ documentId: origin || id, model: slug, collectionType, params },
|
885
|
-
{
|
886
|
-
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
887
|
-
}
|
888
|
-
)
|
966
|
+
edit,
|
967
|
+
list: listLayout
|
889
968
|
};
|
890
969
|
};
|
891
|
-
const
|
892
|
-
|
893
|
-
|
894
|
-
}
|
895
|
-
return Object.keys(trad).reduce((acc, current) => {
|
896
|
-
acc[`${pluginId}.${current}`] = trad[current];
|
897
|
-
return acc;
|
898
|
-
}, {});
|
899
|
-
};
|
900
|
-
const getTranslation = (id) => `content-manager.${id}`;
|
901
|
-
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
902
|
-
id: "notification.error",
|
903
|
-
defaultMessage: "An error occurred, please try again"
|
970
|
+
const useDocLayout = () => {
|
971
|
+
const { model } = useDoc();
|
972
|
+
return useDocumentLayout(model);
|
904
973
|
};
|
905
|
-
const
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
const
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
});
|
927
|
-
return { error: res.error };
|
928
|
-
}
|
929
|
-
toggleNotification({
|
930
|
-
type: "success",
|
931
|
-
message: formatMessage({
|
932
|
-
id: getTranslation("success.record.delete"),
|
933
|
-
defaultMessage: "Deleted document"
|
934
|
-
})
|
935
|
-
});
|
936
|
-
trackUsage("didDeleteEntry", trackerProperty);
|
937
|
-
return res.data;
|
938
|
-
} catch (err) {
|
939
|
-
toggleNotification({
|
940
|
-
type: "danger",
|
941
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
942
|
-
});
|
943
|
-
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
944
|
-
throw err;
|
974
|
+
const formatEditLayout = (data, {
|
975
|
+
schemas,
|
976
|
+
schema,
|
977
|
+
components
|
978
|
+
}) => {
|
979
|
+
let currentPanelIndex = 0;
|
980
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
981
|
+
data.contentType.layouts.edit,
|
982
|
+
schema?.attributes,
|
983
|
+
data.contentType.metadatas,
|
984
|
+
{ configurations: data.components, schemas: components },
|
985
|
+
schemas
|
986
|
+
).reduce((panels, row) => {
|
987
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
988
|
+
panels.push([row]);
|
989
|
+
currentPanelIndex += 2;
|
990
|
+
} else {
|
991
|
+
if (!panels[currentPanelIndex]) {
|
992
|
+
panels.push([row]);
|
993
|
+
} else {
|
994
|
+
panels[currentPanelIndex].push(row);
|
945
995
|
}
|
946
|
-
}
|
947
|
-
|
948
|
-
);
|
949
|
-
const
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
message: formatAPIError(res.error)
|
963
|
-
});
|
964
|
-
return { error: res.error };
|
996
|
+
}
|
997
|
+
return panels;
|
998
|
+
}, []);
|
999
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
1000
|
+
(acc, [uid, configuration]) => {
|
1001
|
+
acc[uid] = {
|
1002
|
+
layout: convertEditLayoutToFieldLayouts(
|
1003
|
+
configuration.layouts.edit,
|
1004
|
+
components[uid].attributes,
|
1005
|
+
configuration.metadatas,
|
1006
|
+
{ configurations: data.components, schemas: components }
|
1007
|
+
),
|
1008
|
+
settings: {
|
1009
|
+
...configuration.settings,
|
1010
|
+
icon: components[uid].info.icon,
|
1011
|
+
displayName: components[uid].info.displayName
|
965
1012
|
}
|
966
|
-
|
967
|
-
|
968
|
-
title: formatMessage({
|
969
|
-
id: getTranslation("success.records.delete"),
|
970
|
-
defaultMessage: "Successfully deleted."
|
971
|
-
}),
|
972
|
-
message: ""
|
973
|
-
});
|
974
|
-
trackUsage("didBulkDeleteEntries");
|
975
|
-
return res.data;
|
976
|
-
} catch (err) {
|
977
|
-
toggleNotification({
|
978
|
-
type: "danger",
|
979
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
980
|
-
});
|
981
|
-
trackUsage("didNotBulkDeleteEntries");
|
982
|
-
throw err;
|
983
|
-
}
|
1013
|
+
};
|
1014
|
+
return acc;
|
984
1015
|
},
|
985
|
-
|
1016
|
+
{}
|
986
1017
|
);
|
987
|
-
const
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
model,
|
994
|
-
documentId,
|
995
|
-
params
|
996
|
-
});
|
997
|
-
if ("error" in res) {
|
998
|
-
toggleNotification({
|
999
|
-
type: "danger",
|
1000
|
-
message: formatAPIError(res.error)
|
1001
|
-
});
|
1002
|
-
return { error: res.error };
|
1003
|
-
}
|
1004
|
-
toggleNotification({
|
1005
|
-
type: "success",
|
1006
|
-
message: formatMessage({
|
1007
|
-
id: "content-manager.success.record.discard",
|
1008
|
-
defaultMessage: "Changes discarded"
|
1009
|
-
})
|
1010
|
-
});
|
1011
|
-
return res.data;
|
1012
|
-
} catch (err) {
|
1013
|
-
toggleNotification({
|
1014
|
-
type: "danger",
|
1015
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1016
|
-
});
|
1017
|
-
throw err;
|
1018
|
-
}
|
1018
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1019
|
+
(acc, [attribute, metadata]) => {
|
1020
|
+
return {
|
1021
|
+
...acc,
|
1022
|
+
[attribute]: metadata.edit
|
1023
|
+
};
|
1019
1024
|
},
|
1020
|
-
|
1025
|
+
{}
|
1021
1026
|
);
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
model,
|
1030
|
-
documentId,
|
1031
|
-
data,
|
1032
|
-
params
|
1033
|
-
});
|
1034
|
-
if ("error" in res) {
|
1035
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1036
|
-
return { error: res.error };
|
1037
|
-
}
|
1038
|
-
trackUsage("didPublishEntry");
|
1039
|
-
toggleNotification({
|
1040
|
-
type: "success",
|
1041
|
-
message: formatMessage({
|
1042
|
-
id: getTranslation("success.record.publish"),
|
1043
|
-
defaultMessage: "Published document"
|
1044
|
-
})
|
1045
|
-
});
|
1046
|
-
return res.data;
|
1047
|
-
} catch (err) {
|
1048
|
-
toggleNotification({
|
1049
|
-
type: "danger",
|
1050
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1051
|
-
});
|
1052
|
-
throw err;
|
1053
|
-
}
|
1027
|
+
return {
|
1028
|
+
layout: panelledEditAttributes,
|
1029
|
+
components: componentEditAttributes,
|
1030
|
+
metadatas: editMetadatas,
|
1031
|
+
settings: {
|
1032
|
+
...data.contentType.settings,
|
1033
|
+
displayName: schema?.info.displayName
|
1054
1034
|
},
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
return { error: res.error };
|
1069
|
-
}
|
1070
|
-
toggleNotification({
|
1071
|
-
type: "success",
|
1072
|
-
message: formatMessage({
|
1073
|
-
id: getTranslation("success.record.publish"),
|
1074
|
-
defaultMessage: "Published document"
|
1075
|
-
})
|
1076
|
-
});
|
1077
|
-
return res.data;
|
1078
|
-
} catch (err) {
|
1079
|
-
toggleNotification({
|
1080
|
-
type: "danger",
|
1081
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1082
|
-
});
|
1083
|
-
throw err;
|
1035
|
+
options: {
|
1036
|
+
...schema?.options,
|
1037
|
+
...schema?.pluginOptions,
|
1038
|
+
...data.contentType.options
|
1039
|
+
}
|
1040
|
+
};
|
1041
|
+
};
|
1042
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1043
|
+
return rows.map(
|
1044
|
+
(row) => row.map((field) => {
|
1045
|
+
const attribute = attributes[field.name];
|
1046
|
+
if (!attribute) {
|
1047
|
+
return null;
|
1084
1048
|
}
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1049
|
+
const { edit: metadata } = metadatas[field.name];
|
1050
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1051
|
+
return {
|
1052
|
+
attribute,
|
1053
|
+
disabled: !metadata.editable,
|
1054
|
+
hint: metadata.description,
|
1055
|
+
label: metadata.label ?? "",
|
1056
|
+
name: field.name,
|
1057
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1058
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1059
|
+
schemas,
|
1060
|
+
components: components?.schemas ?? {}
|
1061
|
+
}),
|
1062
|
+
placeholder: metadata.placeholder ?? "",
|
1063
|
+
required: attribute.required ?? false,
|
1064
|
+
size: field.size,
|
1065
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1066
|
+
visible: metadata.visible ?? true,
|
1067
|
+
type: attribute.type
|
1068
|
+
};
|
1069
|
+
}).filter((field) => field !== null)
|
1093
1070
|
);
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1071
|
+
};
|
1072
|
+
const formatListLayout = (data, {
|
1073
|
+
schemas,
|
1074
|
+
schema,
|
1075
|
+
components
|
1076
|
+
}) => {
|
1077
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1078
|
+
(acc, [attribute, metadata]) => {
|
1079
|
+
return {
|
1080
|
+
...acc,
|
1081
|
+
[attribute]: metadata.list
|
1082
|
+
};
|
1083
|
+
},
|
1084
|
+
{}
|
1085
|
+
);
|
1086
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1087
|
+
data.contentType.layouts.list,
|
1088
|
+
schema?.attributes,
|
1089
|
+
listMetadatas,
|
1090
|
+
{ configurations: data.components, schemas: components },
|
1091
|
+
schemas
|
1092
|
+
);
|
1093
|
+
return {
|
1094
|
+
layout: listAttributes,
|
1095
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1096
|
+
metadatas: listMetadatas,
|
1097
|
+
options: {
|
1098
|
+
...schema?.options,
|
1099
|
+
...schema?.pluginOptions,
|
1100
|
+
...data.contentType.options
|
1101
|
+
}
|
1102
|
+
};
|
1103
|
+
};
|
1104
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1105
|
+
return columns.map((name) => {
|
1106
|
+
const attribute = attributes[name];
|
1107
|
+
if (!attribute) {
|
1108
|
+
return null;
|
1109
|
+
}
|
1110
|
+
const metadata = metadatas[name];
|
1111
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1112
|
+
return {
|
1113
|
+
attribute,
|
1114
|
+
label: metadata.label ?? "",
|
1115
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1116
|
+
schemas,
|
1117
|
+
components: components?.schemas ?? {}
|
1118
|
+
}),
|
1119
|
+
name,
|
1120
|
+
searchable: metadata.searchable ?? true,
|
1121
|
+
sortable: metadata.sortable ?? true
|
1122
|
+
};
|
1123
|
+
}).filter((field) => field !== null);
|
1124
|
+
};
|
1125
|
+
const useDocument = (args, opts) => {
|
1126
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1127
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1128
|
+
const {
|
1129
|
+
currentData: data,
|
1130
|
+
isLoading: isLoadingDocument,
|
1131
|
+
isFetching: isFetchingDocument,
|
1132
|
+
error
|
1133
|
+
} = useGetDocumentQuery(args, {
|
1134
|
+
...opts,
|
1135
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1136
|
+
});
|
1137
|
+
const {
|
1138
|
+
components,
|
1139
|
+
schema,
|
1140
|
+
schemas,
|
1141
|
+
isLoading: isLoadingSchema
|
1142
|
+
} = useContentTypeSchema(args.model);
|
1143
|
+
React__namespace.useEffect(() => {
|
1144
|
+
if (error) {
|
1145
|
+
toggleNotification({
|
1146
|
+
type: "danger",
|
1147
|
+
message: formatAPIError(error)
|
1148
|
+
});
|
1149
|
+
}
|
1150
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1151
|
+
const validationSchema = React__namespace.useMemo(() => {
|
1152
|
+
if (!schema) {
|
1153
|
+
return null;
|
1154
|
+
}
|
1155
|
+
return createYupSchema(schema.attributes, components);
|
1156
|
+
}, [schema, components]);
|
1157
|
+
const validate = React__namespace.useCallback(
|
1158
|
+
(document) => {
|
1159
|
+
if (!validationSchema) {
|
1160
|
+
throw new Error(
|
1161
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1162
|
+
);
|
1163
|
+
}
|
1164
|
+
try {
|
1165
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1166
|
+
return null;
|
1167
|
+
} catch (error2) {
|
1168
|
+
if (error2 instanceof yup.ValidationError) {
|
1169
|
+
return strapiAdmin.getYupValidationErrors(error2);
|
1110
1170
|
}
|
1111
|
-
|
1112
|
-
toggleNotification({
|
1113
|
-
type: "success",
|
1114
|
-
message: formatMessage({
|
1115
|
-
id: getTranslation("success.record.save"),
|
1116
|
-
defaultMessage: "Saved document"
|
1117
|
-
})
|
1118
|
-
});
|
1119
|
-
return res.data;
|
1120
|
-
} catch (err) {
|
1121
|
-
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1122
|
-
toggleNotification({
|
1123
|
-
type: "danger",
|
1124
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1125
|
-
});
|
1126
|
-
throw err;
|
1171
|
+
throw error2;
|
1127
1172
|
}
|
1128
1173
|
},
|
1129
|
-
[
|
1174
|
+
[validationSchema]
|
1130
1175
|
);
|
1131
|
-
const
|
1132
|
-
const
|
1133
|
-
|
1176
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1177
|
+
const hasError = !!error;
|
1178
|
+
return {
|
1179
|
+
components,
|
1180
|
+
document: data?.data,
|
1181
|
+
meta: data?.meta,
|
1182
|
+
isLoading,
|
1183
|
+
hasError,
|
1184
|
+
schema,
|
1185
|
+
schemas,
|
1186
|
+
validate
|
1187
|
+
};
|
1188
|
+
};
|
1189
|
+
const useDoc = () => {
|
1190
|
+
const { id, slug, collectionType, origin } = reactRouterDom.useParams();
|
1191
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
1192
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1193
|
+
if (!collectionType) {
|
1194
|
+
throw new Error("Could not find collectionType in url params");
|
1195
|
+
}
|
1196
|
+
if (!slug) {
|
1197
|
+
throw new Error("Could not find model in url params");
|
1198
|
+
}
|
1199
|
+
const document = useDocument(
|
1200
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1201
|
+
{
|
1202
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1203
|
+
}
|
1204
|
+
);
|
1205
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1206
|
+
return {
|
1207
|
+
collectionType,
|
1208
|
+
model: slug,
|
1209
|
+
id: returnId,
|
1210
|
+
...document
|
1211
|
+
};
|
1212
|
+
};
|
1213
|
+
const useContentManagerContext = () => {
|
1214
|
+
const {
|
1215
|
+
collectionType,
|
1216
|
+
model,
|
1217
|
+
id,
|
1218
|
+
components,
|
1219
|
+
isLoading: isLoadingDoc,
|
1220
|
+
schema,
|
1221
|
+
schemas
|
1222
|
+
} = useDoc();
|
1223
|
+
const layout = useDocumentLayout(model);
|
1224
|
+
const form = strapiAdmin.useForm("useContentManagerContext", (state) => state);
|
1225
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1226
|
+
const slug = model;
|
1227
|
+
const isCreatingEntry = id === "create";
|
1228
|
+
useContentTypeSchema();
|
1229
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1230
|
+
const error = layout.error;
|
1231
|
+
return {
|
1232
|
+
error,
|
1233
|
+
isLoading,
|
1234
|
+
// Base metadata
|
1235
|
+
model,
|
1236
|
+
collectionType,
|
1237
|
+
id,
|
1238
|
+
slug,
|
1239
|
+
isCreatingEntry,
|
1240
|
+
isSingleType,
|
1241
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1242
|
+
// All schema infos
|
1243
|
+
components,
|
1244
|
+
contentType: schema,
|
1245
|
+
contentTypes: schemas,
|
1246
|
+
// Form state
|
1247
|
+
form,
|
1248
|
+
// layout infos
|
1249
|
+
layout
|
1250
|
+
};
|
1251
|
+
};
|
1252
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1253
|
+
if (!pluginId) {
|
1254
|
+
throw new TypeError("pluginId can't be empty");
|
1255
|
+
}
|
1256
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1257
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1258
|
+
return acc;
|
1259
|
+
}, {});
|
1260
|
+
};
|
1261
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1262
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1263
|
+
id: "notification.error",
|
1264
|
+
defaultMessage: "An error occurred, please try again"
|
1265
|
+
};
|
1266
|
+
const useDocumentActions = () => {
|
1267
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1268
|
+
const { formatMessage } = reactIntl.useIntl();
|
1269
|
+
const { trackUsage } = strapiAdmin.useTracking();
|
1270
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1271
|
+
const navigate = reactRouterDom.useNavigate();
|
1272
|
+
const setCurrentStep = strapiAdmin.useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1273
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1274
|
+
const _delete = React__namespace.useCallback(
|
1275
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1134
1276
|
try {
|
1135
|
-
trackUsage("
|
1136
|
-
const res = await
|
1277
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1278
|
+
const res = await deleteDocument({
|
1137
1279
|
collectionType,
|
1138
1280
|
model,
|
1139
1281
|
documentId,
|
1140
|
-
params
|
1141
|
-
data: {
|
1142
|
-
discardDraft
|
1143
|
-
}
|
1282
|
+
params
|
1144
1283
|
});
|
1145
1284
|
if ("error" in res) {
|
1146
|
-
toggleNotification({
|
1285
|
+
toggleNotification({
|
1286
|
+
type: "danger",
|
1287
|
+
message: formatAPIError(res.error)
|
1288
|
+
});
|
1147
1289
|
return { error: res.error };
|
1148
1290
|
}
|
1149
|
-
trackUsage("didUnpublishEntry");
|
1150
1291
|
toggleNotification({
|
1151
1292
|
type: "success",
|
1152
1293
|
message: formatMessage({
|
1153
|
-
id: getTranslation("success.record.
|
1154
|
-
defaultMessage: "
|
1294
|
+
id: getTranslation("success.record.delete"),
|
1295
|
+
defaultMessage: "Deleted document"
|
1155
1296
|
})
|
1156
1297
|
});
|
1298
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1157
1299
|
return res.data;
|
1158
1300
|
} catch (err) {
|
1159
1301
|
toggleNotification({
|
1160
1302
|
type: "danger",
|
1161
1303
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1162
1304
|
});
|
1305
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1163
1306
|
throw err;
|
1164
1307
|
}
|
1165
1308
|
},
|
1166
|
-
[trackUsage,
|
1309
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1167
1310
|
);
|
1168
|
-
const [
|
1169
|
-
const
|
1311
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1312
|
+
const deleteMany = React__namespace.useCallback(
|
1170
1313
|
async ({ model, documentIds, params }) => {
|
1171
1314
|
try {
|
1172
|
-
trackUsage("
|
1173
|
-
const res = await
|
1315
|
+
trackUsage("willBulkDeleteEntries");
|
1316
|
+
const res = await deleteManyDocuments({
|
1174
1317
|
model,
|
1175
1318
|
documentIds,
|
1176
1319
|
params
|
1177
1320
|
});
|
1178
1321
|
if ("error" in res) {
|
1179
|
-
toggleNotification({
|
1322
|
+
toggleNotification({
|
1323
|
+
type: "danger",
|
1324
|
+
message: formatAPIError(res.error)
|
1325
|
+
});
|
1180
1326
|
return { error: res.error };
|
1181
1327
|
}
|
1182
|
-
trackUsage("didBulkUnpublishEntries");
|
1183
1328
|
toggleNotification({
|
1184
1329
|
type: "success",
|
1185
1330
|
title: formatMessage({
|
1186
|
-
id: getTranslation("success.records.
|
1187
|
-
defaultMessage: "Successfully
|
1331
|
+
id: getTranslation("success.records.delete"),
|
1332
|
+
defaultMessage: "Successfully deleted."
|
1188
1333
|
}),
|
1189
1334
|
message: ""
|
1190
1335
|
});
|
1336
|
+
trackUsage("didBulkDeleteEntries");
|
1191
1337
|
return res.data;
|
1192
1338
|
} catch (err) {
|
1193
1339
|
toggleNotification({
|
1194
1340
|
type: "danger",
|
1195
1341
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1196
1342
|
});
|
1197
|
-
trackUsage("
|
1343
|
+
trackUsage("didNotBulkDeleteEntries");
|
1198
1344
|
throw err;
|
1199
1345
|
}
|
1200
1346
|
},
|
1201
|
-
[trackUsage,
|
1347
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1202
1348
|
);
|
1203
|
-
const [
|
1204
|
-
const
|
1205
|
-
async ({ model, params }
|
1349
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1350
|
+
const discard = React__namespace.useCallback(
|
1351
|
+
async ({ collectionType, model, documentId, params }) => {
|
1206
1352
|
try {
|
1207
|
-
const res = await
|
1353
|
+
const res = await discardDocument({
|
1354
|
+
collectionType,
|
1208
1355
|
model,
|
1209
|
-
|
1356
|
+
documentId,
|
1210
1357
|
params
|
1211
1358
|
});
|
1212
1359
|
if ("error" in res) {
|
1213
|
-
toggleNotification({
|
1214
|
-
|
1360
|
+
toggleNotification({
|
1361
|
+
type: "danger",
|
1362
|
+
message: formatAPIError(res.error)
|
1363
|
+
});
|
1215
1364
|
return { error: res.error };
|
1216
1365
|
}
|
1217
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1218
1366
|
toggleNotification({
|
1219
1367
|
type: "success",
|
1220
1368
|
message: formatMessage({
|
1221
|
-
id:
|
1222
|
-
defaultMessage: "
|
1223
|
-
})
|
1369
|
+
id: "content-manager.success.record.discard",
|
1370
|
+
defaultMessage: "Changes discarded"
|
1371
|
+
})
|
1372
|
+
});
|
1373
|
+
return res.data;
|
1374
|
+
} catch (err) {
|
1375
|
+
toggleNotification({
|
1376
|
+
type: "danger",
|
1377
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1378
|
+
});
|
1379
|
+
throw err;
|
1380
|
+
}
|
1381
|
+
},
|
1382
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1383
|
+
);
|
1384
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1385
|
+
const publish = React__namespace.useCallback(
|
1386
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1387
|
+
try {
|
1388
|
+
trackUsage("willPublishEntry");
|
1389
|
+
const res = await publishDocument({
|
1390
|
+
collectionType,
|
1391
|
+
model,
|
1392
|
+
documentId,
|
1393
|
+
data,
|
1394
|
+
params
|
1395
|
+
});
|
1396
|
+
if ("error" in res) {
|
1397
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1398
|
+
return { error: res.error };
|
1399
|
+
}
|
1400
|
+
trackUsage("didPublishEntry");
|
1401
|
+
toggleNotification({
|
1402
|
+
type: "success",
|
1403
|
+
message: formatMessage({
|
1404
|
+
id: getTranslation("success.record.publish"),
|
1405
|
+
defaultMessage: "Published document"
|
1406
|
+
})
|
1407
|
+
});
|
1408
|
+
return res.data;
|
1409
|
+
} catch (err) {
|
1410
|
+
toggleNotification({
|
1411
|
+
type: "danger",
|
1412
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1413
|
+
});
|
1414
|
+
throw err;
|
1415
|
+
}
|
1416
|
+
},
|
1417
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1418
|
+
);
|
1419
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1420
|
+
const publishMany = React__namespace.useCallback(
|
1421
|
+
async ({ model, documentIds, params }) => {
|
1422
|
+
try {
|
1423
|
+
const res = await publishManyDocuments({
|
1424
|
+
model,
|
1425
|
+
documentIds,
|
1426
|
+
params
|
1427
|
+
});
|
1428
|
+
if ("error" in res) {
|
1429
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1430
|
+
return { error: res.error };
|
1431
|
+
}
|
1432
|
+
toggleNotification({
|
1433
|
+
type: "success",
|
1434
|
+
message: formatMessage({
|
1435
|
+
id: getTranslation("success.record.publish"),
|
1436
|
+
defaultMessage: "Published document"
|
1437
|
+
})
|
1438
|
+
});
|
1439
|
+
return res.data;
|
1440
|
+
} catch (err) {
|
1441
|
+
toggleNotification({
|
1442
|
+
type: "danger",
|
1443
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1444
|
+
});
|
1445
|
+
throw err;
|
1446
|
+
}
|
1447
|
+
},
|
1448
|
+
[
|
1449
|
+
// trackUsage,
|
1450
|
+
publishManyDocuments,
|
1451
|
+
toggleNotification,
|
1452
|
+
formatMessage,
|
1453
|
+
formatAPIError
|
1454
|
+
]
|
1455
|
+
);
|
1456
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1457
|
+
const update = React__namespace.useCallback(
|
1458
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1459
|
+
try {
|
1460
|
+
trackUsage("willEditEntry", trackerProperty);
|
1461
|
+
const res = await updateDocument({
|
1462
|
+
collectionType,
|
1463
|
+
model,
|
1464
|
+
documentId,
|
1465
|
+
data,
|
1466
|
+
params
|
1467
|
+
});
|
1468
|
+
if ("error" in res) {
|
1469
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1470
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1471
|
+
return { error: res.error };
|
1472
|
+
}
|
1473
|
+
trackUsage("didEditEntry", trackerProperty);
|
1474
|
+
toggleNotification({
|
1475
|
+
type: "success",
|
1476
|
+
message: formatMessage({
|
1477
|
+
id: getTranslation("success.record.save"),
|
1478
|
+
defaultMessage: "Saved document"
|
1479
|
+
})
|
1480
|
+
});
|
1481
|
+
return res.data;
|
1482
|
+
} catch (err) {
|
1483
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1484
|
+
toggleNotification({
|
1485
|
+
type: "danger",
|
1486
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1487
|
+
});
|
1488
|
+
throw err;
|
1489
|
+
}
|
1490
|
+
},
|
1491
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1492
|
+
);
|
1493
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1494
|
+
const unpublish = React__namespace.useCallback(
|
1495
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1496
|
+
try {
|
1497
|
+
trackUsage("willUnpublishEntry");
|
1498
|
+
const res = await unpublishDocument({
|
1499
|
+
collectionType,
|
1500
|
+
model,
|
1501
|
+
documentId,
|
1502
|
+
params,
|
1503
|
+
data: {
|
1504
|
+
discardDraft
|
1505
|
+
}
|
1506
|
+
});
|
1507
|
+
if ("error" in res) {
|
1508
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1509
|
+
return { error: res.error };
|
1510
|
+
}
|
1511
|
+
trackUsage("didUnpublishEntry");
|
1512
|
+
toggleNotification({
|
1513
|
+
type: "success",
|
1514
|
+
message: formatMessage({
|
1515
|
+
id: getTranslation("success.record.unpublish"),
|
1516
|
+
defaultMessage: "Unpublished document"
|
1517
|
+
})
|
1518
|
+
});
|
1519
|
+
return res.data;
|
1520
|
+
} catch (err) {
|
1521
|
+
toggleNotification({
|
1522
|
+
type: "danger",
|
1523
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1524
|
+
});
|
1525
|
+
throw err;
|
1526
|
+
}
|
1527
|
+
},
|
1528
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1529
|
+
);
|
1530
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1531
|
+
const unpublishMany = React__namespace.useCallback(
|
1532
|
+
async ({ model, documentIds, params }) => {
|
1533
|
+
try {
|
1534
|
+
trackUsage("willBulkUnpublishEntries");
|
1535
|
+
const res = await unpublishManyDocuments({
|
1536
|
+
model,
|
1537
|
+
documentIds,
|
1538
|
+
params
|
1539
|
+
});
|
1540
|
+
if ("error" in res) {
|
1541
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1542
|
+
return { error: res.error };
|
1543
|
+
}
|
1544
|
+
trackUsage("didBulkUnpublishEntries");
|
1545
|
+
toggleNotification({
|
1546
|
+
type: "success",
|
1547
|
+
title: formatMessage({
|
1548
|
+
id: getTranslation("success.records.unpublish"),
|
1549
|
+
defaultMessage: "Successfully unpublished."
|
1550
|
+
}),
|
1551
|
+
message: ""
|
1552
|
+
});
|
1553
|
+
return res.data;
|
1554
|
+
} catch (err) {
|
1555
|
+
toggleNotification({
|
1556
|
+
type: "danger",
|
1557
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1558
|
+
});
|
1559
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1560
|
+
throw err;
|
1561
|
+
}
|
1562
|
+
},
|
1563
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1564
|
+
);
|
1565
|
+
const [createDocument] = useCreateDocumentMutation();
|
1566
|
+
const create = React__namespace.useCallback(
|
1567
|
+
async ({ model, params }, data, trackerProperty) => {
|
1568
|
+
try {
|
1569
|
+
const res = await createDocument({
|
1570
|
+
model,
|
1571
|
+
data,
|
1572
|
+
params
|
1573
|
+
});
|
1574
|
+
if ("error" in res) {
|
1575
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1576
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1577
|
+
return { error: res.error };
|
1578
|
+
}
|
1579
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1580
|
+
toggleNotification({
|
1581
|
+
type: "success",
|
1582
|
+
message: formatMessage({
|
1583
|
+
id: getTranslation("success.record.save"),
|
1584
|
+
defaultMessage: "Saved document"
|
1585
|
+
})
|
1224
1586
|
});
|
1587
|
+
setCurrentStep("contentManager.success");
|
1225
1588
|
return res.data;
|
1226
1589
|
} catch (err) {
|
1227
1590
|
toggleNotification({
|
@@ -1324,7 +1687,7 @@ const useDocumentActions = () => {
|
|
1324
1687
|
};
|
1325
1688
|
};
|
1326
1689
|
const ProtectedHistoryPage = React.lazy(
|
1327
|
-
() => Promise.resolve().then(() => require("./History-
|
1690
|
+
() => Promise.resolve().then(() => require("./History-DdZTjeEU.js")).then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1328
1691
|
);
|
1329
1692
|
const routes$1 = [
|
1330
1693
|
{
|
@@ -1337,31 +1700,31 @@ const routes$1 = [
|
|
1337
1700
|
}
|
1338
1701
|
];
|
1339
1702
|
const ProtectedEditViewPage = React.lazy(
|
1340
|
-
() => Promise.resolve().then(() => require("./EditViewPage-
|
1703
|
+
() => Promise.resolve().then(() => require("./EditViewPage-CqMtsGgl.js")).then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1341
1704
|
);
|
1342
1705
|
const ProtectedListViewPage = React.lazy(
|
1343
|
-
() => Promise.resolve().then(() => require("./ListViewPage-
|
1706
|
+
() => Promise.resolve().then(() => require("./ListViewPage-CPbs8bml.js")).then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1344
1707
|
);
|
1345
1708
|
const ProtectedListConfiguration = React.lazy(
|
1346
|
-
() => Promise.resolve().then(() => require("./ListConfigurationPage-
|
1709
|
+
() => Promise.resolve().then(() => require("./ListConfigurationPage-C-8hLgKb.js")).then((mod) => ({
|
1347
1710
|
default: mod.ProtectedListConfiguration
|
1348
1711
|
}))
|
1349
1712
|
);
|
1350
1713
|
const ProtectedEditConfigurationPage = React.lazy(
|
1351
|
-
() => Promise.resolve().then(() => require("./EditConfigurationPage-
|
1714
|
+
() => Promise.resolve().then(() => require("./EditConfigurationPage-Cs-8XG8_.js")).then((mod) => ({
|
1352
1715
|
default: mod.ProtectedEditConfigurationPage
|
1353
1716
|
}))
|
1354
1717
|
);
|
1355
1718
|
const ProtectedComponentConfigurationPage = React.lazy(
|
1356
|
-
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-
|
1719
|
+
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-B-r3vk8T.js")).then((mod) => ({
|
1357
1720
|
default: mod.ProtectedComponentConfigurationPage
|
1358
1721
|
}))
|
1359
1722
|
);
|
1360
1723
|
const NoPermissions = React.lazy(
|
1361
|
-
() => Promise.resolve().then(() => require("./NoPermissionsPage-
|
1724
|
+
() => Promise.resolve().then(() => require("./NoPermissionsPage-De5GsnjI.js")).then((mod) => ({ default: mod.NoPermissions }))
|
1362
1725
|
);
|
1363
1726
|
const NoContentType = React.lazy(
|
1364
|
-
() => Promise.resolve().then(() => require("./NoContentTypePage-
|
1727
|
+
() => Promise.resolve().then(() => require("./NoContentTypePage-Bz_9RdLr.js")).then((mod) => ({ default: mod.NoContentType }))
|
1365
1728
|
);
|
1366
1729
|
const CollectionTypePages = () => {
|
1367
1730
|
const { collectionType } = reactRouterDom.useParams();
|
@@ -1808,7 +2171,9 @@ const PublishAction$1 = ({
|
|
1808
2171
|
const performPublish = async () => {
|
1809
2172
|
setSubmitting(true);
|
1810
2173
|
try {
|
1811
|
-
const { errors } = await validate(
|
2174
|
+
const { errors } = await validate(true, {
|
2175
|
+
status: "published"
|
2176
|
+
});
|
1812
2177
|
if (errors) {
|
1813
2178
|
toggleNotification({
|
1814
2179
|
type: "danger",
|
@@ -1922,18 +2287,18 @@ const UpdateAction = ({
|
|
1922
2287
|
onClick: async () => {
|
1923
2288
|
setSubmitting(true);
|
1924
2289
|
try {
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
})
|
1935
|
-
|
1936
|
-
|
2290
|
+
const { errors } = await validate(true, {
|
2291
|
+
status: "draft"
|
2292
|
+
});
|
2293
|
+
if (errors) {
|
2294
|
+
toggleNotification({
|
2295
|
+
type: "danger",
|
2296
|
+
message: formatMessage({
|
2297
|
+
id: "content-manager.validation.error",
|
2298
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2299
|
+
})
|
2300
|
+
});
|
2301
|
+
return;
|
1937
2302
|
}
|
1938
2303
|
if (isCloning) {
|
1939
2304
|
const res = await clone(
|
@@ -2315,12 +2680,12 @@ const Information = ({ activeTab }) => {
|
|
2315
2680
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2316
2681
|
label: formatMessage({
|
2317
2682
|
id: "content-manager.containers.edit.information.last-published.label",
|
2318
|
-
defaultMessage: "
|
2683
|
+
defaultMessage: "Published"
|
2319
2684
|
}),
|
2320
2685
|
value: formatMessage(
|
2321
2686
|
{
|
2322
2687
|
id: "content-manager.containers.edit.information.last-published.value",
|
2323
|
-
defaultMessage: `
|
2688
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2324
2689
|
},
|
2325
2690
|
{
|
2326
2691
|
time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2333,12 +2698,12 @@ const Information = ({ activeTab }) => {
|
|
2333
2698
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2334
2699
|
label: formatMessage({
|
2335
2700
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2336
|
-
defaultMessage: "
|
2701
|
+
defaultMessage: "Updated"
|
2337
2702
|
}),
|
2338
2703
|
value: formatMessage(
|
2339
2704
|
{
|
2340
2705
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2341
|
-
defaultMessage: `
|
2706
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2342
2707
|
},
|
2343
2708
|
{
|
2344
2709
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2356,12 +2721,12 @@ const Information = ({ activeTab }) => {
|
|
2356
2721
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2357
2722
|
label: formatMessage({
|
2358
2723
|
id: "content-manager.containers.edit.information.document.label",
|
2359
|
-
defaultMessage: "
|
2724
|
+
defaultMessage: "Created"
|
2360
2725
|
}),
|
2361
2726
|
value: formatMessage(
|
2362
2727
|
{
|
2363
2728
|
id: "content-manager.containers.edit.information.document.value",
|
2364
|
-
defaultMessage: `
|
2729
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2365
2730
|
},
|
2366
2731
|
{
|
2367
2732
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2419,10 +2784,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2419
2784
|
designSystem.SingleSelect,
|
2420
2785
|
{
|
2421
2786
|
size: "S",
|
2422
|
-
disabled: action.disabled,
|
2423
|
-
"aria-label": action.label,
|
2424
2787
|
onChange: action.onSelect,
|
2425
|
-
|
2788
|
+
"aria-label": action.label,
|
2789
|
+
...action,
|
2426
2790
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
|
2427
2791
|
},
|
2428
2792
|
action.id
|
@@ -2486,490 +2850,191 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
|
|
2486
2850
|
position: "header"
|
2487
2851
|
};
|
2488
2852
|
};
|
2489
|
-
ConfigureTheViewAction.type = "configure-the-view";
|
2490
|
-
const EditTheModelAction = ({ model }) => {
|
2491
|
-
const navigate = reactRouterDom.useNavigate();
|
2492
|
-
const { formatMessage } = reactIntl.useIntl();
|
2493
|
-
return {
|
2494
|
-
label: formatMessage({
|
2495
|
-
id: "content-manager.link-to-ctb",
|
2496
|
-
defaultMessage: "Edit the model"
|
2497
|
-
}),
|
2498
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
|
2499
|
-
onClick: () => {
|
2500
|
-
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2501
|
-
},
|
2502
|
-
position: "header"
|
2503
|
-
};
|
2504
|
-
};
|
2505
|
-
EditTheModelAction.type = "edit-the-model";
|
2506
|
-
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2507
|
-
const navigate = reactRouterDom.useNavigate();
|
2508
|
-
const { formatMessage } = reactIntl.useIntl();
|
2509
|
-
const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
|
2510
|
-
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2511
|
-
const { delete: deleteAction } = useDocumentActions();
|
2512
|
-
const { toggleNotification } = strapiAdmin.useNotification();
|
2513
|
-
const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
|
2514
|
-
return {
|
2515
|
-
disabled: !canDelete || !document,
|
2516
|
-
label: formatMessage({
|
2517
|
-
id: "content-manager.actions.delete.label",
|
2518
|
-
defaultMessage: "Delete document"
|
2519
|
-
}),
|
2520
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
|
2521
|
-
dialog: {
|
2522
|
-
type: "dialog",
|
2523
|
-
title: formatMessage({
|
2524
|
-
id: "app.components.ConfirmDialog.title",
|
2525
|
-
defaultMessage: "Confirmation"
|
2526
|
-
}),
|
2527
|
-
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2528
|
-
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2529
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2530
|
-
id: "content-manager.actions.delete.dialog.body",
|
2531
|
-
defaultMessage: "Are you sure?"
|
2532
|
-
}) })
|
2533
|
-
] }),
|
2534
|
-
onConfirm: async () => {
|
2535
|
-
if (!listViewPathMatch) {
|
2536
|
-
setSubmitting(true);
|
2537
|
-
}
|
2538
|
-
try {
|
2539
|
-
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2540
|
-
console.error(
|
2541
|
-
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2542
|
-
);
|
2543
|
-
toggleNotification({
|
2544
|
-
message: formatMessage({
|
2545
|
-
id: "content-manager.actions.delete.error",
|
2546
|
-
defaultMessage: "An error occurred while trying to delete the document."
|
2547
|
-
}),
|
2548
|
-
type: "danger"
|
2549
|
-
});
|
2550
|
-
return;
|
2551
|
-
}
|
2552
|
-
const res = await deleteAction({
|
2553
|
-
documentId,
|
2554
|
-
model,
|
2555
|
-
collectionType,
|
2556
|
-
params: {
|
2557
|
-
locale: "*"
|
2558
|
-
}
|
2559
|
-
});
|
2560
|
-
if (!("error" in res)) {
|
2561
|
-
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2562
|
-
}
|
2563
|
-
} finally {
|
2564
|
-
if (!listViewPathMatch) {
|
2565
|
-
setSubmitting(false);
|
2566
|
-
}
|
2567
|
-
}
|
2568
|
-
}
|
2569
|
-
},
|
2570
|
-
variant: "danger",
|
2571
|
-
position: ["header", "table-row"]
|
2572
|
-
};
|
2573
|
-
};
|
2574
|
-
DeleteAction$1.type = "delete";
|
2575
|
-
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2576
|
-
const Panels = () => {
|
2577
|
-
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2578
|
-
const [
|
2579
|
-
{
|
2580
|
-
query: { status }
|
2581
|
-
}
|
2582
|
-
] = strapiAdmin.useQueryParams({
|
2583
|
-
status: "draft"
|
2584
|
-
});
|
2585
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2586
|
-
const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
|
2587
|
-
const props = {
|
2588
|
-
activeTab: status,
|
2589
|
-
model,
|
2590
|
-
documentId: id,
|
2591
|
-
document: isCloning ? void 0 : document,
|
2592
|
-
meta: isCloning ? void 0 : meta,
|
2593
|
-
collectionType
|
2594
|
-
};
|
2595
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
2596
|
-
strapiAdmin.DescriptionComponentRenderer,
|
2597
|
-
{
|
2598
|
-
props,
|
2599
|
-
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2600
|
-
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
|
2601
|
-
}
|
2602
|
-
) });
|
2603
|
-
};
|
2604
|
-
const ActionsPanel = () => {
|
2605
|
-
const { formatMessage } = reactIntl.useIntl();
|
2606
|
-
return {
|
2607
|
-
title: formatMessage({
|
2608
|
-
id: "content-manager.containers.edit.panels.default.title",
|
2609
|
-
defaultMessage: "Entry"
|
2610
|
-
}),
|
2611
|
-
content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
|
2612
|
-
};
|
2613
|
-
};
|
2614
|
-
ActionsPanel.type = "actions";
|
2615
|
-
const ActionsPanelContent = () => {
|
2616
|
-
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2617
|
-
const [
|
2618
|
-
{
|
2619
|
-
query: { status = "draft" }
|
2620
|
-
}
|
2621
|
-
] = strapiAdmin.useQueryParams();
|
2622
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2623
|
-
const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2624
|
-
const props = {
|
2625
|
-
activeTab: status,
|
2626
|
-
model,
|
2627
|
-
documentId: id,
|
2628
|
-
document: isCloning ? void 0 : document,
|
2629
|
-
meta: isCloning ? void 0 : meta,
|
2630
|
-
collectionType
|
2631
|
-
};
|
2632
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2633
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
2634
|
-
strapiAdmin.DescriptionComponentRenderer,
|
2635
|
-
{
|
2636
|
-
props,
|
2637
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2638
|
-
children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
|
2639
|
-
}
|
2640
|
-
),
|
2641
|
-
/* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2642
|
-
] });
|
2643
|
-
};
|
2644
|
-
const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
|
2645
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
2646
|
-
designSystem.Flex,
|
2647
|
-
{
|
2648
|
-
ref,
|
2649
|
-
tag: "aside",
|
2650
|
-
"aria-labelledby": "additional-information",
|
2651
|
-
background: "neutral0",
|
2652
|
-
borderColor: "neutral150",
|
2653
|
-
hasRadius: true,
|
2654
|
-
paddingBottom: 4,
|
2655
|
-
paddingLeft: 4,
|
2656
|
-
paddingRight: 4,
|
2657
|
-
paddingTop: 4,
|
2658
|
-
shadow: "tableShadow",
|
2659
|
-
gap: 3,
|
2660
|
-
direction: "column",
|
2661
|
-
justifyContent: "stretch",
|
2662
|
-
alignItems: "flex-start",
|
2663
|
-
children: [
|
2664
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2665
|
-
children
|
2666
|
-
]
|
2667
|
-
}
|
2668
|
-
);
|
2669
|
-
});
|
2670
|
-
const HOOKS = {
|
2671
|
-
/**
|
2672
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2673
|
-
* @constant
|
2674
|
-
* @type {string}
|
2675
|
-
*/
|
2676
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2677
|
-
/**
|
2678
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2679
|
-
* @constant
|
2680
|
-
* @type {string}
|
2681
|
-
*/
|
2682
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2683
|
-
/**
|
2684
|
-
* Hook that allows to mutate the CM's edit view layout
|
2685
|
-
* @constant
|
2686
|
-
* @type {string}
|
2687
|
-
*/
|
2688
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2689
|
-
/**
|
2690
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2691
|
-
* @constant
|
2692
|
-
* @type {string}
|
2693
|
-
*/
|
2694
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2695
|
-
};
|
2696
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2697
|
-
endpoints: (builder) => ({
|
2698
|
-
getContentTypeConfiguration: builder.query({
|
2699
|
-
query: (uid) => ({
|
2700
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2701
|
-
method: "GET"
|
2702
|
-
}),
|
2703
|
-
transformResponse: (response) => response.data,
|
2704
|
-
providesTags: (_result, _error, uid) => [
|
2705
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2706
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
2707
|
-
]
|
2708
|
-
}),
|
2709
|
-
getAllContentTypeSettings: builder.query({
|
2710
|
-
query: () => "/content-manager/content-types-settings",
|
2711
|
-
transformResponse: (response) => response.data,
|
2712
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
2713
|
-
}),
|
2714
|
-
updateContentTypeConfiguration: builder.mutation({
|
2715
|
-
query: ({ uid, ...body }) => ({
|
2716
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2717
|
-
method: "PUT",
|
2718
|
-
data: body
|
2719
|
-
}),
|
2720
|
-
transformResponse: (response) => response.data,
|
2721
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
2722
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2723
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
2724
|
-
// Is this necessary?
|
2725
|
-
{ type: "InitialData" }
|
2726
|
-
]
|
2727
|
-
})
|
2728
|
-
})
|
2729
|
-
});
|
2730
|
-
const {
|
2731
|
-
useGetContentTypeConfigurationQuery,
|
2732
|
-
useGetAllContentTypeSettingsQuery,
|
2733
|
-
useUpdateContentTypeConfigurationMutation
|
2734
|
-
} = contentTypesApi;
|
2735
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
2736
|
-
const { type } = attribute;
|
2737
|
-
if (type === "relation") {
|
2738
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
2739
|
-
}
|
2740
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
2741
|
-
};
|
2742
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
2743
|
-
if (!mainFieldName) {
|
2744
|
-
return void 0;
|
2745
|
-
}
|
2746
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
2747
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
2748
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
2749
|
-
);
|
2750
|
-
return {
|
2751
|
-
name: mainFieldName,
|
2752
|
-
type: mainFieldType ?? "string"
|
2753
|
-
};
|
2754
|
-
};
|
2755
|
-
const DEFAULT_SETTINGS = {
|
2756
|
-
bulkable: false,
|
2757
|
-
filterable: false,
|
2758
|
-
searchable: false,
|
2759
|
-
pagination: false,
|
2760
|
-
defaultSortBy: "",
|
2761
|
-
defaultSortOrder: "asc",
|
2762
|
-
mainField: "id",
|
2763
|
-
pageSize: 10
|
2764
|
-
};
|
2765
|
-
const useDocumentLayout = (model) => {
|
2766
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
2767
|
-
const [{ query }] = strapiAdmin.useQueryParams();
|
2768
|
-
const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
2769
|
-
const { toggleNotification } = strapiAdmin.useNotification();
|
2770
|
-
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
2771
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
2772
|
-
const {
|
2773
|
-
data,
|
2774
|
-
isLoading: isLoadingConfigs,
|
2775
|
-
error,
|
2776
|
-
isFetching: isFetchingConfigs
|
2777
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2778
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2779
|
-
React__namespace.useEffect(() => {
|
2780
|
-
if (error) {
|
2781
|
-
toggleNotification({
|
2782
|
-
type: "danger",
|
2783
|
-
message: formatAPIError(error)
|
2784
|
-
});
|
2785
|
-
}
|
2786
|
-
}, [error, formatAPIError, toggleNotification]);
|
2787
|
-
const editLayout = React__namespace.useMemo(
|
2788
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2789
|
-
layout: [],
|
2790
|
-
components: {},
|
2791
|
-
metadatas: {},
|
2792
|
-
options: {},
|
2793
|
-
settings: DEFAULT_SETTINGS
|
2794
|
-
},
|
2795
|
-
[data, isLoading, schemas, schema, components]
|
2796
|
-
);
|
2797
|
-
const listLayout = React__namespace.useMemo(() => {
|
2798
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2799
|
-
layout: [],
|
2800
|
-
metadatas: {},
|
2801
|
-
options: {},
|
2802
|
-
settings: DEFAULT_SETTINGS
|
2803
|
-
};
|
2804
|
-
}, [data, isLoading, schemas, schema, components]);
|
2805
|
-
const { layout: edit } = React__namespace.useMemo(
|
2806
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2807
|
-
layout: editLayout,
|
2808
|
-
query
|
2809
|
-
}),
|
2810
|
-
[editLayout, query, runHookWaterfall]
|
2811
|
-
);
|
2812
|
-
return {
|
2813
|
-
error,
|
2814
|
-
isLoading,
|
2815
|
-
edit,
|
2816
|
-
list: listLayout
|
2817
|
-
};
|
2818
|
-
};
|
2819
|
-
const useDocLayout = () => {
|
2820
|
-
const { model } = useDoc();
|
2821
|
-
return useDocumentLayout(model);
|
2822
|
-
};
|
2823
|
-
const formatEditLayout = (data, {
|
2824
|
-
schemas,
|
2825
|
-
schema,
|
2826
|
-
components
|
2827
|
-
}) => {
|
2828
|
-
let currentPanelIndex = 0;
|
2829
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
2830
|
-
data.contentType.layouts.edit,
|
2831
|
-
schema?.attributes,
|
2832
|
-
data.contentType.metadatas,
|
2833
|
-
{ configurations: data.components, schemas: components },
|
2834
|
-
schemas
|
2835
|
-
).reduce((panels, row) => {
|
2836
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2837
|
-
panels.push([row]);
|
2838
|
-
currentPanelIndex += 2;
|
2839
|
-
} else {
|
2840
|
-
if (!panels[currentPanelIndex]) {
|
2841
|
-
panels.push([]);
|
2842
|
-
}
|
2843
|
-
panels[currentPanelIndex].push(row);
|
2844
|
-
}
|
2845
|
-
return panels;
|
2846
|
-
}, []);
|
2847
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
2848
|
-
(acc, [uid, configuration]) => {
|
2849
|
-
acc[uid] = {
|
2850
|
-
layout: convertEditLayoutToFieldLayouts(
|
2851
|
-
configuration.layouts.edit,
|
2852
|
-
components[uid].attributes,
|
2853
|
-
configuration.metadatas,
|
2854
|
-
{ configurations: data.components, schemas: components }
|
2855
|
-
),
|
2856
|
-
settings: {
|
2857
|
-
...configuration.settings,
|
2858
|
-
icon: components[uid].info.icon,
|
2859
|
-
displayName: components[uid].info.displayName
|
2860
|
-
}
|
2861
|
-
};
|
2862
|
-
return acc;
|
2863
|
-
},
|
2864
|
-
{}
|
2865
|
-
);
|
2866
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2867
|
-
(acc, [attribute, metadata]) => {
|
2868
|
-
return {
|
2869
|
-
...acc,
|
2870
|
-
[attribute]: metadata.edit
|
2871
|
-
};
|
2872
|
-
},
|
2873
|
-
{}
|
2874
|
-
);
|
2853
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2854
|
+
const EditTheModelAction = ({ model }) => {
|
2855
|
+
const navigate = reactRouterDom.useNavigate();
|
2856
|
+
const { formatMessage } = reactIntl.useIntl();
|
2875
2857
|
return {
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
2881
|
-
|
2858
|
+
label: formatMessage({
|
2859
|
+
id: "content-manager.link-to-ctb",
|
2860
|
+
defaultMessage: "Edit the model"
|
2861
|
+
}),
|
2862
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
|
2863
|
+
onClick: () => {
|
2864
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2882
2865
|
},
|
2883
|
-
|
2884
|
-
...schema?.options,
|
2885
|
-
...schema?.pluginOptions,
|
2886
|
-
...data.contentType.options
|
2887
|
-
}
|
2866
|
+
position: "header"
|
2888
2867
|
};
|
2889
2868
|
};
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
|
2869
|
+
EditTheModelAction.type = "edit-the-model";
|
2870
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2871
|
+
const navigate = reactRouterDom.useNavigate();
|
2872
|
+
const { formatMessage } = reactIntl.useIntl();
|
2873
|
+
const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
|
2874
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2875
|
+
const { delete: deleteAction } = useDocumentActions();
|
2876
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2877
|
+
const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
|
2878
|
+
const isLocalized = document?.locale != null;
|
2879
|
+
return {
|
2880
|
+
disabled: !canDelete || !document,
|
2881
|
+
label: formatMessage(
|
2882
|
+
{
|
2883
|
+
id: "content-manager.actions.delete.label",
|
2884
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2885
|
+
},
|
2886
|
+
{ isLocalized }
|
2887
|
+
),
|
2888
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
|
2889
|
+
dialog: {
|
2890
|
+
type: "dialog",
|
2891
|
+
title: formatMessage({
|
2892
|
+
id: "app.components.ConfirmDialog.title",
|
2893
|
+
defaultMessage: "Confirmation"
|
2894
|
+
}),
|
2895
|
+
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2896
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2897
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2898
|
+
id: "content-manager.actions.delete.dialog.body",
|
2899
|
+
defaultMessage: "Are you sure?"
|
2900
|
+
}) })
|
2901
|
+
] }),
|
2902
|
+
onConfirm: async () => {
|
2903
|
+
if (!listViewPathMatch) {
|
2904
|
+
setSubmitting(true);
|
2905
|
+
}
|
2906
|
+
try {
|
2907
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2908
|
+
console.error(
|
2909
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2910
|
+
);
|
2911
|
+
toggleNotification({
|
2912
|
+
message: formatMessage({
|
2913
|
+
id: "content-manager.actions.delete.error",
|
2914
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2915
|
+
}),
|
2916
|
+
type: "danger"
|
2917
|
+
});
|
2918
|
+
return;
|
2919
|
+
}
|
2920
|
+
const res = await deleteAction({
|
2921
|
+
documentId,
|
2922
|
+
model,
|
2923
|
+
collectionType,
|
2924
|
+
params: {
|
2925
|
+
locale: "*"
|
2926
|
+
}
|
2927
|
+
});
|
2928
|
+
if (!("error" in res)) {
|
2929
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2930
|
+
}
|
2931
|
+
} finally {
|
2932
|
+
if (!listViewPathMatch) {
|
2933
|
+
setSubmitting(false);
|
2934
|
+
}
|
2935
|
+
}
|
2896
2936
|
}
|
2897
|
-
const { edit: metadata } = metadatas[field.name];
|
2898
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2899
|
-
return {
|
2900
|
-
attribute,
|
2901
|
-
disabled: !metadata.editable,
|
2902
|
-
hint: metadata.description,
|
2903
|
-
label: metadata.label ?? "",
|
2904
|
-
name: field.name,
|
2905
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2906
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2907
|
-
schemas,
|
2908
|
-
components: components?.schemas ?? {}
|
2909
|
-
}),
|
2910
|
-
placeholder: metadata.placeholder ?? "",
|
2911
|
-
required: attribute.required ?? false,
|
2912
|
-
size: field.size,
|
2913
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2914
|
-
visible: metadata.visible ?? true,
|
2915
|
-
type: attribute.type
|
2916
|
-
};
|
2917
|
-
}).filter((field) => field !== null)
|
2918
|
-
);
|
2919
|
-
};
|
2920
|
-
const formatListLayout = (data, {
|
2921
|
-
schemas,
|
2922
|
-
schema,
|
2923
|
-
components
|
2924
|
-
}) => {
|
2925
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2926
|
-
(acc, [attribute, metadata]) => {
|
2927
|
-
return {
|
2928
|
-
...acc,
|
2929
|
-
[attribute]: metadata.list
|
2930
|
-
};
|
2931
2937
|
},
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2938
|
+
variant: "danger",
|
2939
|
+
position: ["header", "table-row"]
|
2940
|
+
};
|
2941
|
+
};
|
2942
|
+
DeleteAction$1.type = "delete";
|
2943
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2944
|
+
const Panels = () => {
|
2945
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2946
|
+
const [
|
2947
|
+
{
|
2948
|
+
query: { status }
|
2949
|
+
}
|
2950
|
+
] = strapiAdmin.useQueryParams({
|
2951
|
+
status: "draft"
|
2952
|
+
});
|
2953
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2954
|
+
const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
|
2955
|
+
const props = {
|
2956
|
+
activeTab: status,
|
2957
|
+
model,
|
2958
|
+
documentId: id,
|
2959
|
+
document: isCloning ? void 0 : document,
|
2960
|
+
meta: isCloning ? void 0 : meta,
|
2961
|
+
collectionType
|
2962
|
+
};
|
2963
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
2964
|
+
strapiAdmin.DescriptionComponentRenderer,
|
2965
|
+
{
|
2966
|
+
props,
|
2967
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2968
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
|
2949
2969
|
}
|
2970
|
+
) });
|
2971
|
+
};
|
2972
|
+
const ActionsPanel = () => {
|
2973
|
+
const { formatMessage } = reactIntl.useIntl();
|
2974
|
+
return {
|
2975
|
+
title: formatMessage({
|
2976
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2977
|
+
defaultMessage: "Entry"
|
2978
|
+
}),
|
2979
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
|
2950
2980
|
};
|
2951
2981
|
};
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2982
|
+
ActionsPanel.type = "actions";
|
2983
|
+
const ActionsPanelContent = () => {
|
2984
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2985
|
+
const [
|
2986
|
+
{
|
2987
|
+
query: { status = "draft" }
|
2957
2988
|
}
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2989
|
+
] = strapiAdmin.useQueryParams();
|
2990
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2991
|
+
const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2992
|
+
const props = {
|
2993
|
+
activeTab: status,
|
2994
|
+
model,
|
2995
|
+
documentId: id,
|
2996
|
+
document: isCloning ? void 0 : document,
|
2997
|
+
meta: isCloning ? void 0 : meta,
|
2998
|
+
collectionType
|
2999
|
+
};
|
3000
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
|
3001
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
3002
|
+
strapiAdmin.DescriptionComponentRenderer,
|
3003
|
+
{
|
3004
|
+
props,
|
3005
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3006
|
+
children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
|
3007
|
+
}
|
3008
|
+
),
|
3009
|
+
/* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3010
|
+
] });
|
2972
3011
|
};
|
3012
|
+
const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
|
3013
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
3014
|
+
designSystem.Flex,
|
3015
|
+
{
|
3016
|
+
ref,
|
3017
|
+
tag: "aside",
|
3018
|
+
"aria-labelledby": "additional-information",
|
3019
|
+
background: "neutral0",
|
3020
|
+
borderColor: "neutral150",
|
3021
|
+
hasRadius: true,
|
3022
|
+
paddingBottom: 4,
|
3023
|
+
paddingLeft: 4,
|
3024
|
+
paddingRight: 4,
|
3025
|
+
paddingTop: 4,
|
3026
|
+
shadow: "tableShadow",
|
3027
|
+
gap: 3,
|
3028
|
+
direction: "column",
|
3029
|
+
justifyContent: "stretch",
|
3030
|
+
alignItems: "flex-start",
|
3031
|
+
children: [
|
3032
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3033
|
+
children
|
3034
|
+
]
|
3035
|
+
}
|
3036
|
+
);
|
3037
|
+
});
|
2973
3038
|
const ConfirmBulkActionDialog = ({
|
2974
3039
|
onToggleDialog,
|
2975
3040
|
isOpen = false,
|
@@ -3966,7 +4031,7 @@ const index = {
|
|
3966
4031
|
app.router.addRoute({
|
3967
4032
|
path: "content-manager/*",
|
3968
4033
|
lazy: async () => {
|
3969
|
-
const { Layout } = await Promise.resolve().then(() => require("./layout-
|
4034
|
+
const { Layout } = await Promise.resolve().then(() => require("./layout-CfocPPPK.js"));
|
3970
4035
|
return {
|
3971
4036
|
Component: Layout
|
3972
4037
|
};
|
@@ -3983,7 +4048,7 @@ const index = {
|
|
3983
4048
|
async registerTrads({ locales }) {
|
3984
4049
|
const importedTrads = await Promise.all(
|
3985
4050
|
locales.map((locale) => {
|
3986
|
-
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => Promise.resolve().then(() => require("./ar-BUUWXIYu.js")), "./translations/ca.json": () => Promise.resolve().then(() => require("./ca-Cmk45QO6.js")), "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-CkJy6B2v.js")), "./translations/de.json": () => Promise.resolve().then(() => require("./de-CCEmbAah.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-
|
4051
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => Promise.resolve().then(() => require("./ar-BUUWXIYu.js")), "./translations/ca.json": () => Promise.resolve().then(() => require("./ca-Cmk45QO6.js")), "./translations/cs.json": () => Promise.resolve().then(() => require("./cs-CkJy6B2v.js")), "./translations/de.json": () => Promise.resolve().then(() => require("./de-CCEmbAah.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-Bm0D0IWz.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-EUonQTon.js")), "./translations/eu.json": () => Promise.resolve().then(() => require("./eu-VDH-3ovk.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-B7kGGg3E.js")), "./translations/gu.json": () => Promise.resolve().then(() => require("./gu-BRmF601H.js")), "./translations/hi.json": () => Promise.resolve().then(() => require("./hi-CCJBptSq.js")), "./translations/hu.json": () => Promise.resolve().then(() => require("./hu-sNV_yLYy.js")), "./translations/id.json": () => Promise.resolve().then(() => require("./id-B5Ser98A.js")), "./translations/it.json": () => Promise.resolve().then(() => require("./it-DkBIs7vD.js")), "./translations/ja.json": () => Promise.resolve().then(() => require("./ja-CcFe8diO.js")), "./translations/ko.json": () => Promise.resolve().then(() => require("./ko-woFZPmLk.js")), "./translations/ml.json": () => Promise.resolve().then(() => require("./ml-C2W8N8k1.js")), "./translations/ms.json": () => Promise.resolve().then(() => require("./ms-BuFotyP_.js")), "./translations/nl.json": () => Promise.resolve().then(() => require("./nl-bbEOHChV.js")), "./translations/pl.json": () => Promise.resolve().then(() => require("./pl-uzwG-hk7.js")), "./translations/pt-BR.json": () => Promise.resolve().then(() => require("./pt-BR-BiOz37D9.js")), "./translations/pt.json": () => Promise.resolve().then(() => require("./pt-CeXQuq50.js")), "./translations/ru.json": () => Promise.resolve().then(() => require("./ru-BT3ybNny.js")), "./translations/sa.json": () => Promise.resolve().then(() => require("./sa-CcvkYInH.js")), "./translations/sk.json": () => Promise.resolve().then(() => require("./sk-CvY09Xjv.js")), "./translations/sv.json": () => Promise.resolve().then(() => require("./sv-MYDuzgvT.js")), "./translations/th.json": () => Promise.resolve().then(() => require("./th-D9_GfAjc.js")), "./translations/tr.json": () => Promise.resolve().then(() => require("./tr-D9UH-O_R.js")), "./translations/uk.json": () => Promise.resolve().then(() => require("./uk-C8EiqJY7.js")), "./translations/vi.json": () => Promise.resolve().then(() => require("./vi-CJlYDheJ.js")), "./translations/zh-Hans.json": () => Promise.resolve().then(() => require("./zh-Hans-9kOncHGw.js")), "./translations/zh.json": () => Promise.resolve().then(() => require("./zh-CQQfszqR.js")) }), `./translations/${locale}.json`).then(({ default: data }) => {
|
3987
4052
|
return {
|
3988
4053
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3989
4054
|
locale
|
@@ -4029,6 +4094,7 @@ exports.getMainField = getMainField;
|
|
4029
4094
|
exports.getTranslation = getTranslation;
|
4030
4095
|
exports.index = index;
|
4031
4096
|
exports.setInitialData = setInitialData;
|
4097
|
+
exports.useContentManagerContext = useContentManagerContext;
|
4032
4098
|
exports.useContentTypeSchema = useContentTypeSchema;
|
4033
4099
|
exports.useDoc = useDoc;
|
4034
4100
|
exports.useDocLayout = useDocLayout;
|
@@ -4041,4 +4107,4 @@ exports.useGetAllDocumentsQuery = useGetAllDocumentsQuery;
|
|
4041
4107
|
exports.useGetContentTypeConfigurationQuery = useGetContentTypeConfigurationQuery;
|
4042
4108
|
exports.useGetInitialDataQuery = useGetInitialDataQuery;
|
4043
4109
|
exports.useUpdateContentTypeConfigurationMutation = useUpdateContentTypeConfigurationMutation;
|
4044
|
-
//# sourceMappingURL=index-
|
4110
|
+
//# sourceMappingURL=index-DFWNpb4M.js.map
|