@strapi/content-manager 0.0.0-experimental.afa3b513b8f95459043f33fb94f4bac03af1474f → 0.0.0-experimental.bb39175992a5cd205a7e3f2e13a96aa31eba2cff
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 +33 -15
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +33 -15
- 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
@@ -4,6 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const strapiAdmin = require("@strapi/admin/strapi-admin");
|
5
5
|
const React = require("react");
|
6
6
|
const designSystem = require("@strapi/design-system");
|
7
|
+
const mapValues = require("lodash/fp/mapValues");
|
7
8
|
const reactIntl = require("react-intl");
|
8
9
|
const reactRouterDom = require("react-router-dom");
|
9
10
|
const yup = require("yup");
|
@@ -32,6 +33,7 @@ function _interopNamespace(e) {
|
|
32
33
|
return Object.freeze(n);
|
33
34
|
}
|
34
35
|
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
36
|
+
const mapValues__default = /* @__PURE__ */ _interopDefault(mapValues);
|
35
37
|
const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
|
36
38
|
const pipe__default = /* @__PURE__ */ _interopDefault(pipe);
|
37
39
|
const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
@@ -121,6 +123,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
121
123
|
if (!slug) {
|
122
124
|
throw new Error("Cannot find the slug param in the URL");
|
123
125
|
}
|
126
|
+
const [{ rawQuery }] = strapiAdmin.useQueryParams();
|
124
127
|
const userPermissions = strapiAdmin.useAuth("DocumentRBAC", (state) => state.permissions);
|
125
128
|
const contentTypePermissions = React__namespace.useMemo(() => {
|
126
129
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -131,7 +134,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
131
134
|
return { ...acc, [action]: [permission] };
|
132
135
|
}, {});
|
133
136
|
}, [slug, userPermissions]);
|
134
|
-
const { isLoading, allowedActions } = strapiAdmin.useRBAC(
|
137
|
+
const { isLoading, allowedActions } = strapiAdmin.useRBAC(
|
138
|
+
contentTypePermissions,
|
139
|
+
permissions ?? void 0,
|
140
|
+
// TODO: useRBAC context should be typed and built differently
|
141
|
+
// We are passing raw query as context to the hook so that it can
|
142
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
143
|
+
rawQuery
|
144
|
+
);
|
135
145
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
136
146
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
137
147
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -482,6 +492,24 @@ const buildValidParams = (query) => {
|
|
482
492
|
const isBaseQueryError = (error) => {
|
483
493
|
return error.name !== void 0;
|
484
494
|
};
|
495
|
+
const arrayValidator = (attribute, options) => ({
|
496
|
+
message: strapiAdmin.translatedErrors.required,
|
497
|
+
test(value) {
|
498
|
+
if (options.status === "draft") {
|
499
|
+
return true;
|
500
|
+
}
|
501
|
+
if (!attribute.required) {
|
502
|
+
return true;
|
503
|
+
}
|
504
|
+
if (!value) {
|
505
|
+
return false;
|
506
|
+
}
|
507
|
+
if (Array.isArray(value) && value.length === 0) {
|
508
|
+
return false;
|
509
|
+
}
|
510
|
+
return true;
|
511
|
+
}
|
512
|
+
});
|
485
513
|
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
486
514
|
const createModelSchema = (attributes2) => yup__namespace.object().shape(
|
487
515
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
@@ -489,6 +517,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
489
517
|
return acc;
|
490
518
|
}
|
491
519
|
const validations = [
|
520
|
+
addNullableValidation,
|
492
521
|
addRequiredValidation,
|
493
522
|
addMinLengthValidation,
|
494
523
|
addMaxLengthValidation,
|
@@ -505,12 +534,12 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
505
534
|
...acc,
|
506
535
|
[name]: transformSchema(
|
507
536
|
yup__namespace.array().of(createModelSchema(attributes3).nullable(false))
|
508
|
-
)
|
537
|
+
).test(arrayValidator(attribute, options))
|
509
538
|
};
|
510
539
|
} else {
|
511
540
|
return {
|
512
541
|
...acc,
|
513
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
542
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
514
543
|
};
|
515
544
|
}
|
516
545
|
}
|
@@ -532,7 +561,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
532
561
|
}
|
533
562
|
)
|
534
563
|
)
|
535
|
-
)
|
564
|
+
).test(arrayValidator(attribute, options))
|
536
565
|
};
|
537
566
|
case "relation":
|
538
567
|
return {
|
@@ -544,7 +573,7 @@ const createYupSchema = (attributes = {}, components = {}, options = { status: n
|
|
544
573
|
} else if (Array.isArray(value)) {
|
545
574
|
return yup__namespace.array().of(
|
546
575
|
yup__namespace.object().shape({
|
547
|
-
id: yup__namespace.
|
576
|
+
id: yup__namespace.number().required()
|
548
577
|
})
|
549
578
|
);
|
550
579
|
} else if (typeof value === "object") {
|
@@ -630,17 +659,17 @@ const nullableSchema = (schema) => {
|
|
630
659
|
schema
|
631
660
|
);
|
632
661
|
};
|
662
|
+
const addNullableValidation = () => (schema) => {
|
663
|
+
return nullableSchema(schema);
|
664
|
+
};
|
633
665
|
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);
|
666
|
+
if (options.status === "draft" || !attribute.required) {
|
667
|
+
return schema;
|
639
668
|
}
|
640
|
-
if (attribute.required &&
|
669
|
+
if (attribute.required && "required" in schema) {
|
641
670
|
return schema.required(strapiAdmin.translatedErrors.required);
|
642
671
|
}
|
643
|
-
return
|
672
|
+
return schema;
|
644
673
|
};
|
645
674
|
const addMinLengthValidation = (attribute, options) => (schema) => {
|
646
675
|
if (options.status === "draft") {
|
@@ -668,31 +697,12 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
668
697
|
return schema;
|
669
698
|
};
|
670
699
|
const addMinValidation = (attribute, options) => (schema) => {
|
671
|
-
if ("
|
700
|
+
if (options.status === "draft") {
|
701
|
+
return schema;
|
702
|
+
}
|
703
|
+
if ("min" in attribute && "min" in schema) {
|
672
704
|
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) {
|
705
|
+
if (min) {
|
696
706
|
return schema.min(min, {
|
697
707
|
...strapiAdmin.translatedErrors.min,
|
698
708
|
values: {
|
@@ -810,19 +820,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
810
820
|
}, {});
|
811
821
|
return componentsByKey;
|
812
822
|
};
|
813
|
-
const
|
823
|
+
const HOOKS = {
|
824
|
+
/**
|
825
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
826
|
+
* @constant
|
827
|
+
* @type {string}
|
828
|
+
*/
|
829
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
830
|
+
/**
|
831
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
832
|
+
* @constant
|
833
|
+
* @type {string}
|
834
|
+
*/
|
835
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
836
|
+
/**
|
837
|
+
* Hook that allows to mutate the CM's edit view layout
|
838
|
+
* @constant
|
839
|
+
* @type {string}
|
840
|
+
*/
|
841
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
842
|
+
/**
|
843
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
844
|
+
* @constant
|
845
|
+
* @type {string}
|
846
|
+
*/
|
847
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
848
|
+
};
|
849
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
850
|
+
endpoints: (builder) => ({
|
851
|
+
getContentTypeConfiguration: builder.query({
|
852
|
+
query: (uid) => ({
|
853
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
854
|
+
method: "GET"
|
855
|
+
}),
|
856
|
+
transformResponse: (response) => response.data,
|
857
|
+
providesTags: (_result, _error, uid) => [
|
858
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
859
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
860
|
+
]
|
861
|
+
}),
|
862
|
+
getAllContentTypeSettings: builder.query({
|
863
|
+
query: () => "/content-manager/content-types-settings",
|
864
|
+
transformResponse: (response) => response.data,
|
865
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
866
|
+
}),
|
867
|
+
updateContentTypeConfiguration: builder.mutation({
|
868
|
+
query: ({ uid, ...body }) => ({
|
869
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
870
|
+
method: "PUT",
|
871
|
+
data: body
|
872
|
+
}),
|
873
|
+
transformResponse: (response) => response.data,
|
874
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
875
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
876
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
877
|
+
// Is this necessary?
|
878
|
+
{ type: "InitialData" }
|
879
|
+
]
|
880
|
+
})
|
881
|
+
})
|
882
|
+
});
|
883
|
+
const {
|
884
|
+
useGetContentTypeConfigurationQuery,
|
885
|
+
useGetAllContentTypeSettingsQuery,
|
886
|
+
useUpdateContentTypeConfigurationMutation
|
887
|
+
} = contentTypesApi;
|
888
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
889
|
+
const { type } = attribute;
|
890
|
+
if (type === "relation") {
|
891
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
892
|
+
}
|
893
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
894
|
+
};
|
895
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
896
|
+
if (!mainFieldName) {
|
897
|
+
return void 0;
|
898
|
+
}
|
899
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
900
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
901
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
902
|
+
);
|
903
|
+
return {
|
904
|
+
name: mainFieldName,
|
905
|
+
type: mainFieldType ?? "string"
|
906
|
+
};
|
907
|
+
};
|
908
|
+
const DEFAULT_SETTINGS = {
|
909
|
+
bulkable: false,
|
910
|
+
filterable: false,
|
911
|
+
searchable: false,
|
912
|
+
pagination: false,
|
913
|
+
defaultSortBy: "",
|
914
|
+
defaultSortOrder: "asc",
|
915
|
+
mainField: "id",
|
916
|
+
pageSize: 10
|
917
|
+
};
|
918
|
+
const useDocumentLayout = (model) => {
|
919
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
920
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
921
|
+
const runHookWaterfall = strapiAdmin.useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
814
922
|
const { toggleNotification } = strapiAdmin.useNotification();
|
815
923
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
924
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
816
925
|
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);
|
926
|
+
data,
|
927
|
+
isLoading: isLoadingConfigs,
|
928
|
+
error,
|
929
|
+
isFetching: isFetchingConfigs
|
930
|
+
} = useGetContentTypeConfigurationQuery(model);
|
931
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
826
932
|
React__namespace.useEffect(() => {
|
827
933
|
if (error) {
|
828
934
|
toggleNotification({
|
@@ -830,398 +936,656 @@ const useDocument = (args, opts) => {
|
|
830
936
|
message: formatAPIError(error)
|
831
937
|
});
|
832
938
|
}
|
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
|
-
}
|
939
|
+
}, [error, formatAPIError, toggleNotification]);
|
940
|
+
const editLayout = React__namespace.useMemo(
|
941
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
942
|
+
layout: [],
|
943
|
+
components: {},
|
944
|
+
metadatas: {},
|
945
|
+
options: {},
|
946
|
+
settings: DEFAULT_SETTINGS
|
856
947
|
},
|
857
|
-
[
|
948
|
+
[data, isLoading, schemas, schema, components]
|
949
|
+
);
|
950
|
+
const listLayout = React__namespace.useMemo(() => {
|
951
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
952
|
+
layout: [],
|
953
|
+
metadatas: {},
|
954
|
+
options: {},
|
955
|
+
settings: DEFAULT_SETTINGS
|
956
|
+
};
|
957
|
+
}, [data, isLoading, schemas, schema, components]);
|
958
|
+
const { layout: edit } = React__namespace.useMemo(
|
959
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
960
|
+
layout: editLayout,
|
961
|
+
query
|
962
|
+
}),
|
963
|
+
[editLayout, query, runHookWaterfall]
|
858
964
|
);
|
859
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
860
965
|
return {
|
861
|
-
|
862
|
-
document: data?.data,
|
863
|
-
meta: data?.meta,
|
966
|
+
error,
|
864
967
|
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
|
-
)
|
968
|
+
edit,
|
969
|
+
list: listLayout
|
889
970
|
};
|
890
971
|
};
|
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"
|
972
|
+
const useDocLayout = () => {
|
973
|
+
const { model } = useDoc();
|
974
|
+
return useDocumentLayout(model);
|
904
975
|
};
|
905
|
-
const
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
const
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
type: "danger",
|
925
|
-
message: formatAPIError(res.error)
|
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;
|
976
|
+
const formatEditLayout = (data, {
|
977
|
+
schemas,
|
978
|
+
schema,
|
979
|
+
components
|
980
|
+
}) => {
|
981
|
+
let currentPanelIndex = 0;
|
982
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
983
|
+
data.contentType.layouts.edit,
|
984
|
+
schema?.attributes,
|
985
|
+
data.contentType.metadatas,
|
986
|
+
{ configurations: data.components, schemas: components },
|
987
|
+
schemas
|
988
|
+
).reduce((panels, row) => {
|
989
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
990
|
+
panels.push([row]);
|
991
|
+
currentPanelIndex += 2;
|
992
|
+
} else {
|
993
|
+
if (!panels[currentPanelIndex]) {
|
994
|
+
panels.push([]);
|
945
995
|
}
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
const
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
});
|
964
|
-
return { error: res.error };
|
996
|
+
panels[currentPanelIndex].push(row);
|
997
|
+
}
|
998
|
+
return panels;
|
999
|
+
}, []);
|
1000
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
1001
|
+
(acc, [uid, configuration]) => {
|
1002
|
+
acc[uid] = {
|
1003
|
+
layout: convertEditLayoutToFieldLayouts(
|
1004
|
+
configuration.layouts.edit,
|
1005
|
+
components[uid].attributes,
|
1006
|
+
configuration.metadatas,
|
1007
|
+
{ configurations: data.components, schemas: components }
|
1008
|
+
),
|
1009
|
+
settings: {
|
1010
|
+
...configuration.settings,
|
1011
|
+
icon: components[uid].info.icon,
|
1012
|
+
displayName: components[uid].info.displayName
|
965
1013
|
}
|
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
|
-
}
|
1014
|
+
};
|
1015
|
+
return acc;
|
984
1016
|
},
|
985
|
-
|
1017
|
+
{}
|
986
1018
|
);
|
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
|
-
}
|
1019
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1020
|
+
(acc, [attribute, metadata]) => {
|
1021
|
+
return {
|
1022
|
+
...acc,
|
1023
|
+
[attribute]: metadata.edit
|
1024
|
+
};
|
1019
1025
|
},
|
1020
|
-
|
1026
|
+
{}
|
1021
1027
|
);
|
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
|
-
}
|
1028
|
+
return {
|
1029
|
+
layout: panelledEditAttributes,
|
1030
|
+
components: componentEditAttributes,
|
1031
|
+
metadatas: editMetadatas,
|
1032
|
+
settings: {
|
1033
|
+
...data.contentType.settings,
|
1034
|
+
displayName: schema?.info.displayName
|
1054
1035
|
},
|
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;
|
1036
|
+
options: {
|
1037
|
+
...schema?.options,
|
1038
|
+
...schema?.pluginOptions,
|
1039
|
+
...data.contentType.options
|
1040
|
+
}
|
1041
|
+
};
|
1042
|
+
};
|
1043
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1044
|
+
return rows.map(
|
1045
|
+
(row) => row.map((field) => {
|
1046
|
+
const attribute = attributes[field.name];
|
1047
|
+
if (!attribute) {
|
1048
|
+
return null;
|
1084
1049
|
}
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1050
|
+
const { edit: metadata } = metadatas[field.name];
|
1051
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1052
|
+
return {
|
1053
|
+
attribute,
|
1054
|
+
disabled: !metadata.editable,
|
1055
|
+
hint: metadata.description,
|
1056
|
+
label: metadata.label ?? "",
|
1057
|
+
name: field.name,
|
1058
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1059
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1060
|
+
schemas,
|
1061
|
+
components: components?.schemas ?? {}
|
1062
|
+
}),
|
1063
|
+
placeholder: metadata.placeholder ?? "",
|
1064
|
+
required: attribute.required ?? false,
|
1065
|
+
size: field.size,
|
1066
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1067
|
+
visible: metadata.visible ?? true,
|
1068
|
+
type: attribute.type
|
1069
|
+
};
|
1070
|
+
}).filter((field) => field !== null)
|
1093
1071
|
);
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1072
|
+
};
|
1073
|
+
const formatListLayout = (data, {
|
1074
|
+
schemas,
|
1075
|
+
schema,
|
1076
|
+
components
|
1077
|
+
}) => {
|
1078
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1079
|
+
(acc, [attribute, metadata]) => {
|
1080
|
+
return {
|
1081
|
+
...acc,
|
1082
|
+
[attribute]: metadata.list
|
1083
|
+
};
|
1084
|
+
},
|
1085
|
+
{}
|
1086
|
+
);
|
1087
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1088
|
+
data.contentType.layouts.list,
|
1089
|
+
schema?.attributes,
|
1090
|
+
listMetadatas,
|
1091
|
+
{ configurations: data.components, schemas: components },
|
1092
|
+
schemas
|
1093
|
+
);
|
1094
|
+
return {
|
1095
|
+
layout: listAttributes,
|
1096
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1097
|
+
metadatas: listMetadatas,
|
1098
|
+
options: {
|
1099
|
+
...schema?.options,
|
1100
|
+
...schema?.pluginOptions,
|
1101
|
+
...data.contentType.options
|
1102
|
+
}
|
1103
|
+
};
|
1104
|
+
};
|
1105
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1106
|
+
return columns.map((name) => {
|
1107
|
+
const attribute = attributes[name];
|
1108
|
+
if (!attribute) {
|
1109
|
+
return null;
|
1110
|
+
}
|
1111
|
+
const metadata = metadatas[name];
|
1112
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1113
|
+
return {
|
1114
|
+
attribute,
|
1115
|
+
label: metadata.label ?? "",
|
1116
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1117
|
+
schemas,
|
1118
|
+
components: components?.schemas ?? {}
|
1119
|
+
}),
|
1120
|
+
name,
|
1121
|
+
searchable: metadata.searchable ?? true,
|
1122
|
+
sortable: metadata.sortable ?? true
|
1123
|
+
};
|
1124
|
+
}).filter((field) => field !== null);
|
1125
|
+
};
|
1126
|
+
const useDocument = (args, opts) => {
|
1127
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1128
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1129
|
+
const {
|
1130
|
+
currentData: data,
|
1131
|
+
isLoading: isLoadingDocument,
|
1132
|
+
isFetching: isFetchingDocument,
|
1133
|
+
error
|
1134
|
+
} = useGetDocumentQuery(args, {
|
1135
|
+
...opts,
|
1136
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1137
|
+
});
|
1138
|
+
const {
|
1139
|
+
components,
|
1140
|
+
schema,
|
1141
|
+
schemas,
|
1142
|
+
isLoading: isLoadingSchema
|
1143
|
+
} = useContentTypeSchema(args.model);
|
1144
|
+
React__namespace.useEffect(() => {
|
1145
|
+
if (error) {
|
1146
|
+
toggleNotification({
|
1147
|
+
type: "danger",
|
1148
|
+
message: formatAPIError(error)
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1152
|
+
const validationSchema = React__namespace.useMemo(() => {
|
1153
|
+
if (!schema) {
|
1154
|
+
return null;
|
1155
|
+
}
|
1156
|
+
return createYupSchema(schema.attributes, components);
|
1157
|
+
}, [schema, components]);
|
1158
|
+
const validate = React__namespace.useCallback(
|
1159
|
+
(document) => {
|
1160
|
+
if (!validationSchema) {
|
1161
|
+
throw new Error(
|
1162
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1163
|
+
);
|
1164
|
+
}
|
1165
|
+
try {
|
1166
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1167
|
+
return null;
|
1168
|
+
} catch (error2) {
|
1169
|
+
if (error2 instanceof yup.ValidationError) {
|
1170
|
+
return strapiAdmin.getYupValidationErrors(error2);
|
1110
1171
|
}
|
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;
|
1172
|
+
throw error2;
|
1127
1173
|
}
|
1128
1174
|
},
|
1129
|
-
[
|
1175
|
+
[validationSchema]
|
1130
1176
|
);
|
1131
|
-
const
|
1132
|
-
const
|
1133
|
-
|
1177
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1178
|
+
const hasError = !!error;
|
1179
|
+
return {
|
1180
|
+
components,
|
1181
|
+
document: data?.data,
|
1182
|
+
meta: data?.meta,
|
1183
|
+
isLoading,
|
1184
|
+
hasError,
|
1185
|
+
schema,
|
1186
|
+
schemas,
|
1187
|
+
validate
|
1188
|
+
};
|
1189
|
+
};
|
1190
|
+
const useDoc = () => {
|
1191
|
+
const { id, slug, collectionType, origin } = reactRouterDom.useParams();
|
1192
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
1193
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1194
|
+
if (!collectionType) {
|
1195
|
+
throw new Error("Could not find collectionType in url params");
|
1196
|
+
}
|
1197
|
+
if (!slug) {
|
1198
|
+
throw new Error("Could not find model in url params");
|
1199
|
+
}
|
1200
|
+
const document = useDocument(
|
1201
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1202
|
+
{
|
1203
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1204
|
+
}
|
1205
|
+
);
|
1206
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1207
|
+
return {
|
1208
|
+
collectionType,
|
1209
|
+
model: slug,
|
1210
|
+
id: returnId,
|
1211
|
+
...document
|
1212
|
+
};
|
1213
|
+
};
|
1214
|
+
const useContentManagerContext = () => {
|
1215
|
+
const {
|
1216
|
+
collectionType,
|
1217
|
+
model,
|
1218
|
+
id,
|
1219
|
+
components,
|
1220
|
+
isLoading: isLoadingDoc,
|
1221
|
+
schema,
|
1222
|
+
schemas
|
1223
|
+
} = useDoc();
|
1224
|
+
const layout = useDocumentLayout(model);
|
1225
|
+
const form = strapiAdmin.useForm("useContentManagerContext", (state) => state);
|
1226
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1227
|
+
const slug = model;
|
1228
|
+
const isCreatingEntry = id === "create";
|
1229
|
+
useContentTypeSchema();
|
1230
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1231
|
+
const error = layout.error;
|
1232
|
+
return {
|
1233
|
+
error,
|
1234
|
+
isLoading,
|
1235
|
+
// Base metadata
|
1236
|
+
model,
|
1237
|
+
collectionType,
|
1238
|
+
id,
|
1239
|
+
slug,
|
1240
|
+
isCreatingEntry,
|
1241
|
+
isSingleType,
|
1242
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1243
|
+
// All schema infos
|
1244
|
+
components,
|
1245
|
+
contentType: schema,
|
1246
|
+
contentTypes: schemas,
|
1247
|
+
// Form state
|
1248
|
+
form,
|
1249
|
+
// layout infos
|
1250
|
+
layout
|
1251
|
+
};
|
1252
|
+
};
|
1253
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1254
|
+
if (!pluginId) {
|
1255
|
+
throw new TypeError("pluginId can't be empty");
|
1256
|
+
}
|
1257
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1258
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1259
|
+
return acc;
|
1260
|
+
}, {});
|
1261
|
+
};
|
1262
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1263
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1264
|
+
id: "notification.error",
|
1265
|
+
defaultMessage: "An error occurred, please try again"
|
1266
|
+
};
|
1267
|
+
const useDocumentActions = () => {
|
1268
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1269
|
+
const { formatMessage } = reactIntl.useIntl();
|
1270
|
+
const { trackUsage } = strapiAdmin.useTracking();
|
1271
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1272
|
+
const navigate = reactRouterDom.useNavigate();
|
1273
|
+
const setCurrentStep = strapiAdmin.useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1274
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1275
|
+
const _delete = React__namespace.useCallback(
|
1276
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1134
1277
|
try {
|
1135
|
-
trackUsage("
|
1136
|
-
const res = await
|
1278
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1279
|
+
const res = await deleteDocument({
|
1137
1280
|
collectionType,
|
1138
1281
|
model,
|
1139
1282
|
documentId,
|
1140
|
-
params
|
1141
|
-
data: {
|
1142
|
-
discardDraft
|
1143
|
-
}
|
1283
|
+
params
|
1144
1284
|
});
|
1145
1285
|
if ("error" in res) {
|
1146
|
-
toggleNotification({
|
1286
|
+
toggleNotification({
|
1287
|
+
type: "danger",
|
1288
|
+
message: formatAPIError(res.error)
|
1289
|
+
});
|
1147
1290
|
return { error: res.error };
|
1148
1291
|
}
|
1149
|
-
trackUsage("didUnpublishEntry");
|
1150
1292
|
toggleNotification({
|
1151
1293
|
type: "success",
|
1152
1294
|
message: formatMessage({
|
1153
|
-
id: getTranslation("success.record.
|
1154
|
-
defaultMessage: "
|
1295
|
+
id: getTranslation("success.record.delete"),
|
1296
|
+
defaultMessage: "Deleted document"
|
1155
1297
|
})
|
1156
1298
|
});
|
1299
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1157
1300
|
return res.data;
|
1158
1301
|
} catch (err) {
|
1159
1302
|
toggleNotification({
|
1160
1303
|
type: "danger",
|
1161
1304
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1162
1305
|
});
|
1306
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1163
1307
|
throw err;
|
1164
1308
|
}
|
1165
1309
|
},
|
1166
|
-
[trackUsage,
|
1310
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1167
1311
|
);
|
1168
|
-
const [
|
1169
|
-
const
|
1312
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1313
|
+
const deleteMany = React__namespace.useCallback(
|
1170
1314
|
async ({ model, documentIds, params }) => {
|
1171
1315
|
try {
|
1172
|
-
trackUsage("
|
1173
|
-
const res = await
|
1316
|
+
trackUsage("willBulkDeleteEntries");
|
1317
|
+
const res = await deleteManyDocuments({
|
1174
1318
|
model,
|
1175
1319
|
documentIds,
|
1176
1320
|
params
|
1177
1321
|
});
|
1178
1322
|
if ("error" in res) {
|
1179
|
-
toggleNotification({
|
1323
|
+
toggleNotification({
|
1324
|
+
type: "danger",
|
1325
|
+
message: formatAPIError(res.error)
|
1326
|
+
});
|
1180
1327
|
return { error: res.error };
|
1181
1328
|
}
|
1182
|
-
trackUsage("didBulkUnpublishEntries");
|
1183
1329
|
toggleNotification({
|
1184
1330
|
type: "success",
|
1185
1331
|
title: formatMessage({
|
1186
|
-
id: getTranslation("success.records.
|
1187
|
-
defaultMessage: "Successfully
|
1332
|
+
id: getTranslation("success.records.delete"),
|
1333
|
+
defaultMessage: "Successfully deleted."
|
1188
1334
|
}),
|
1189
1335
|
message: ""
|
1190
1336
|
});
|
1337
|
+
trackUsage("didBulkDeleteEntries");
|
1191
1338
|
return res.data;
|
1192
1339
|
} catch (err) {
|
1193
1340
|
toggleNotification({
|
1194
1341
|
type: "danger",
|
1195
1342
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1196
1343
|
});
|
1197
|
-
trackUsage("
|
1344
|
+
trackUsage("didNotBulkDeleteEntries");
|
1198
1345
|
throw err;
|
1199
1346
|
}
|
1200
1347
|
},
|
1201
|
-
[trackUsage,
|
1348
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1202
1349
|
);
|
1203
|
-
const [
|
1204
|
-
const
|
1205
|
-
async ({ model, params }
|
1350
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1351
|
+
const discard = React__namespace.useCallback(
|
1352
|
+
async ({ collectionType, model, documentId, params }) => {
|
1206
1353
|
try {
|
1207
|
-
const res = await
|
1354
|
+
const res = await discardDocument({
|
1355
|
+
collectionType,
|
1208
1356
|
model,
|
1209
|
-
|
1357
|
+
documentId,
|
1210
1358
|
params
|
1211
1359
|
});
|
1212
1360
|
if ("error" in res) {
|
1213
|
-
toggleNotification({
|
1214
|
-
|
1361
|
+
toggleNotification({
|
1362
|
+
type: "danger",
|
1363
|
+
message: formatAPIError(res.error)
|
1364
|
+
});
|
1215
1365
|
return { error: res.error };
|
1216
1366
|
}
|
1217
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1218
1367
|
toggleNotification({
|
1219
1368
|
type: "success",
|
1220
1369
|
message: formatMessage({
|
1221
|
-
id:
|
1222
|
-
defaultMessage: "
|
1370
|
+
id: "content-manager.success.record.discard",
|
1371
|
+
defaultMessage: "Changes discarded"
|
1372
|
+
})
|
1373
|
+
});
|
1374
|
+
return res.data;
|
1375
|
+
} catch (err) {
|
1376
|
+
toggleNotification({
|
1377
|
+
type: "danger",
|
1378
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1379
|
+
});
|
1380
|
+
throw err;
|
1381
|
+
}
|
1382
|
+
},
|
1383
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1384
|
+
);
|
1385
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1386
|
+
const publish = React__namespace.useCallback(
|
1387
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1388
|
+
try {
|
1389
|
+
trackUsage("willPublishEntry");
|
1390
|
+
const res = await publishDocument({
|
1391
|
+
collectionType,
|
1392
|
+
model,
|
1393
|
+
documentId,
|
1394
|
+
data,
|
1395
|
+
params
|
1396
|
+
});
|
1397
|
+
if ("error" in res) {
|
1398
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1399
|
+
return { error: res.error };
|
1400
|
+
}
|
1401
|
+
trackUsage("didPublishEntry");
|
1402
|
+
toggleNotification({
|
1403
|
+
type: "success",
|
1404
|
+
message: formatMessage({
|
1405
|
+
id: getTranslation("success.record.publish"),
|
1406
|
+
defaultMessage: "Published document"
|
1407
|
+
})
|
1408
|
+
});
|
1409
|
+
return res.data;
|
1410
|
+
} catch (err) {
|
1411
|
+
toggleNotification({
|
1412
|
+
type: "danger",
|
1413
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1414
|
+
});
|
1415
|
+
throw err;
|
1416
|
+
}
|
1417
|
+
},
|
1418
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1419
|
+
);
|
1420
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1421
|
+
const publishMany = React__namespace.useCallback(
|
1422
|
+
async ({ model, documentIds, params }) => {
|
1423
|
+
try {
|
1424
|
+
const res = await publishManyDocuments({
|
1425
|
+
model,
|
1426
|
+
documentIds,
|
1427
|
+
params
|
1428
|
+
});
|
1429
|
+
if ("error" in res) {
|
1430
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1431
|
+
return { error: res.error };
|
1432
|
+
}
|
1433
|
+
toggleNotification({
|
1434
|
+
type: "success",
|
1435
|
+
message: formatMessage({
|
1436
|
+
id: getTranslation("success.record.publish"),
|
1437
|
+
defaultMessage: "Published document"
|
1438
|
+
})
|
1439
|
+
});
|
1440
|
+
return res.data;
|
1441
|
+
} catch (err) {
|
1442
|
+
toggleNotification({
|
1443
|
+
type: "danger",
|
1444
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1445
|
+
});
|
1446
|
+
throw err;
|
1447
|
+
}
|
1448
|
+
},
|
1449
|
+
[
|
1450
|
+
// trackUsage,
|
1451
|
+
publishManyDocuments,
|
1452
|
+
toggleNotification,
|
1453
|
+
formatMessage,
|
1454
|
+
formatAPIError
|
1455
|
+
]
|
1456
|
+
);
|
1457
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1458
|
+
const update = React__namespace.useCallback(
|
1459
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1460
|
+
try {
|
1461
|
+
trackUsage("willEditEntry", trackerProperty);
|
1462
|
+
const res = await updateDocument({
|
1463
|
+
collectionType,
|
1464
|
+
model,
|
1465
|
+
documentId,
|
1466
|
+
data,
|
1467
|
+
params
|
1468
|
+
});
|
1469
|
+
if ("error" in res) {
|
1470
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1471
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1472
|
+
return { error: res.error };
|
1473
|
+
}
|
1474
|
+
trackUsage("didEditEntry", trackerProperty);
|
1475
|
+
toggleNotification({
|
1476
|
+
type: "success",
|
1477
|
+
message: formatMessage({
|
1478
|
+
id: getTranslation("success.record.save"),
|
1479
|
+
defaultMessage: "Saved document"
|
1480
|
+
})
|
1481
|
+
});
|
1482
|
+
return res.data;
|
1483
|
+
} catch (err) {
|
1484
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1485
|
+
toggleNotification({
|
1486
|
+
type: "danger",
|
1487
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1488
|
+
});
|
1489
|
+
throw err;
|
1490
|
+
}
|
1491
|
+
},
|
1492
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1493
|
+
);
|
1494
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1495
|
+
const unpublish = React__namespace.useCallback(
|
1496
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1497
|
+
try {
|
1498
|
+
trackUsage("willUnpublishEntry");
|
1499
|
+
const res = await unpublishDocument({
|
1500
|
+
collectionType,
|
1501
|
+
model,
|
1502
|
+
documentId,
|
1503
|
+
params,
|
1504
|
+
data: {
|
1505
|
+
discardDraft
|
1506
|
+
}
|
1507
|
+
});
|
1508
|
+
if ("error" in res) {
|
1509
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1510
|
+
return { error: res.error };
|
1511
|
+
}
|
1512
|
+
trackUsage("didUnpublishEntry");
|
1513
|
+
toggleNotification({
|
1514
|
+
type: "success",
|
1515
|
+
message: formatMessage({
|
1516
|
+
id: getTranslation("success.record.unpublish"),
|
1517
|
+
defaultMessage: "Unpublished document"
|
1518
|
+
})
|
1519
|
+
});
|
1520
|
+
return res.data;
|
1521
|
+
} catch (err) {
|
1522
|
+
toggleNotification({
|
1523
|
+
type: "danger",
|
1524
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1525
|
+
});
|
1526
|
+
throw err;
|
1527
|
+
}
|
1528
|
+
},
|
1529
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1530
|
+
);
|
1531
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1532
|
+
const unpublishMany = React__namespace.useCallback(
|
1533
|
+
async ({ model, documentIds, params }) => {
|
1534
|
+
try {
|
1535
|
+
trackUsage("willBulkUnpublishEntries");
|
1536
|
+
const res = await unpublishManyDocuments({
|
1537
|
+
model,
|
1538
|
+
documentIds,
|
1539
|
+
params
|
1540
|
+
});
|
1541
|
+
if ("error" in res) {
|
1542
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1543
|
+
return { error: res.error };
|
1544
|
+
}
|
1545
|
+
trackUsage("didBulkUnpublishEntries");
|
1546
|
+
toggleNotification({
|
1547
|
+
type: "success",
|
1548
|
+
title: formatMessage({
|
1549
|
+
id: getTranslation("success.records.unpublish"),
|
1550
|
+
defaultMessage: "Successfully unpublished."
|
1551
|
+
}),
|
1552
|
+
message: ""
|
1553
|
+
});
|
1554
|
+
return res.data;
|
1555
|
+
} catch (err) {
|
1556
|
+
toggleNotification({
|
1557
|
+
type: "danger",
|
1558
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1559
|
+
});
|
1560
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1561
|
+
throw err;
|
1562
|
+
}
|
1563
|
+
},
|
1564
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1565
|
+
);
|
1566
|
+
const [createDocument] = useCreateDocumentMutation();
|
1567
|
+
const create = React__namespace.useCallback(
|
1568
|
+
async ({ model, params }, data, trackerProperty) => {
|
1569
|
+
try {
|
1570
|
+
const res = await createDocument({
|
1571
|
+
model,
|
1572
|
+
data,
|
1573
|
+
params
|
1574
|
+
});
|
1575
|
+
if ("error" in res) {
|
1576
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1577
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1578
|
+
return { error: res.error };
|
1579
|
+
}
|
1580
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1581
|
+
toggleNotification({
|
1582
|
+
type: "success",
|
1583
|
+
message: formatMessage({
|
1584
|
+
id: getTranslation("success.record.save"),
|
1585
|
+
defaultMessage: "Saved document"
|
1223
1586
|
})
|
1224
1587
|
});
|
1588
|
+
setCurrentStep("contentManager.success");
|
1225
1589
|
return res.data;
|
1226
1590
|
} catch (err) {
|
1227
1591
|
toggleNotification({
|
@@ -1324,7 +1688,7 @@ const useDocumentActions = () => {
|
|
1324
1688
|
};
|
1325
1689
|
};
|
1326
1690
|
const ProtectedHistoryPage = React.lazy(
|
1327
|
-
() => Promise.resolve().then(() => require("./History-
|
1691
|
+
() => Promise.resolve().then(() => require("./History-CTFvy6XH.js")).then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1328
1692
|
);
|
1329
1693
|
const routes$1 = [
|
1330
1694
|
{
|
@@ -1337,31 +1701,31 @@ const routes$1 = [
|
|
1337
1701
|
}
|
1338
1702
|
];
|
1339
1703
|
const ProtectedEditViewPage = React.lazy(
|
1340
|
-
() => Promise.resolve().then(() => require("./EditViewPage-
|
1704
|
+
() => Promise.resolve().then(() => require("./EditViewPage-CqHMM0P0.js")).then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1341
1705
|
);
|
1342
1706
|
const ProtectedListViewPage = React.lazy(
|
1343
|
-
() => Promise.resolve().then(() => require("./ListViewPage-
|
1707
|
+
() => Promise.resolve().then(() => require("./ListViewPage-D0fpPYKp.js")).then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1344
1708
|
);
|
1345
1709
|
const ProtectedListConfiguration = React.lazy(
|
1346
|
-
() => Promise.resolve().then(() => require("./ListConfigurationPage-
|
1710
|
+
() => Promise.resolve().then(() => require("./ListConfigurationPage-CDzlMBz_.js")).then((mod) => ({
|
1347
1711
|
default: mod.ProtectedListConfiguration
|
1348
1712
|
}))
|
1349
1713
|
);
|
1350
1714
|
const ProtectedEditConfigurationPage = React.lazy(
|
1351
|
-
() => Promise.resolve().then(() => require("./EditConfigurationPage-
|
1715
|
+
() => Promise.resolve().then(() => require("./EditConfigurationPage-Ce4bIm4n.js")).then((mod) => ({
|
1352
1716
|
default: mod.ProtectedEditConfigurationPage
|
1353
1717
|
}))
|
1354
1718
|
);
|
1355
1719
|
const ProtectedComponentConfigurationPage = React.lazy(
|
1356
|
-
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-
|
1720
|
+
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-CQDCxI8x.js")).then((mod) => ({
|
1357
1721
|
default: mod.ProtectedComponentConfigurationPage
|
1358
1722
|
}))
|
1359
1723
|
);
|
1360
1724
|
const NoPermissions = React.lazy(
|
1361
|
-
() => Promise.resolve().then(() => require("./NoPermissionsPage-
|
1725
|
+
() => Promise.resolve().then(() => require("./NoPermissionsPage-BoI2rU68.js")).then((mod) => ({ default: mod.NoPermissions }))
|
1362
1726
|
);
|
1363
1727
|
const NoContentType = React.lazy(
|
1364
|
-
() => Promise.resolve().then(() => require("./NoContentTypePage-
|
1728
|
+
() => Promise.resolve().then(() => require("./NoContentTypePage-DTzkSAV5.js")).then((mod) => ({ default: mod.NoContentType }))
|
1365
1729
|
);
|
1366
1730
|
const CollectionTypePages = () => {
|
1367
1731
|
const { collectionType } = reactRouterDom.useParams();
|
@@ -1715,6 +2079,18 @@ const DocumentActionModal = ({
|
|
1715
2079
|
typeof Footer === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Footer, { onClose: handleClose }) : Footer
|
1716
2080
|
] }) });
|
1717
2081
|
};
|
2082
|
+
const transformData = (data) => {
|
2083
|
+
if (Array.isArray(data)) {
|
2084
|
+
return data.map(transformData);
|
2085
|
+
}
|
2086
|
+
if (typeof data === "object" && data !== null) {
|
2087
|
+
if ("apiData" in data) {
|
2088
|
+
return data.apiData;
|
2089
|
+
}
|
2090
|
+
return mapValues__default.default(transformData)(data);
|
2091
|
+
}
|
2092
|
+
return data;
|
2093
|
+
};
|
1718
2094
|
const PublishAction$1 = ({
|
1719
2095
|
activeTab,
|
1720
2096
|
documentId,
|
@@ -1808,7 +2184,9 @@ const PublishAction$1 = ({
|
|
1808
2184
|
const performPublish = async () => {
|
1809
2185
|
setSubmitting(true);
|
1810
2186
|
try {
|
1811
|
-
const { errors } = await validate(
|
2187
|
+
const { errors } = await validate(true, {
|
2188
|
+
status: "published"
|
2189
|
+
});
|
1812
2190
|
if (errors) {
|
1813
2191
|
toggleNotification({
|
1814
2192
|
type: "danger",
|
@@ -1826,7 +2204,7 @@ const PublishAction$1 = ({
|
|
1826
2204
|
documentId,
|
1827
2205
|
params
|
1828
2206
|
},
|
1829
|
-
formValues
|
2207
|
+
transformData(formValues)
|
1830
2208
|
);
|
1831
2209
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1832
2210
|
navigate({
|
@@ -1922,18 +2300,18 @@ const UpdateAction = ({
|
|
1922
2300
|
onClick: async () => {
|
1923
2301
|
setSubmitting(true);
|
1924
2302
|
try {
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
})
|
1935
|
-
|
1936
|
-
|
2303
|
+
const { errors } = await validate(true, {
|
2304
|
+
status: "draft"
|
2305
|
+
});
|
2306
|
+
if (errors) {
|
2307
|
+
toggleNotification({
|
2308
|
+
type: "danger",
|
2309
|
+
message: formatMessage({
|
2310
|
+
id: "content-manager.validation.error",
|
2311
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2312
|
+
})
|
2313
|
+
});
|
2314
|
+
return;
|
1937
2315
|
}
|
1938
2316
|
if (isCloning) {
|
1939
2317
|
const res = await clone(
|
@@ -1942,7 +2320,7 @@ const UpdateAction = ({
|
|
1942
2320
|
documentId: cloneMatch.params.origin,
|
1943
2321
|
params
|
1944
2322
|
},
|
1945
|
-
document
|
2323
|
+
transformData(document)
|
1946
2324
|
);
|
1947
2325
|
if ("data" in res) {
|
1948
2326
|
navigate(
|
@@ -1963,7 +2341,7 @@ const UpdateAction = ({
|
|
1963
2341
|
documentId,
|
1964
2342
|
params
|
1965
2343
|
},
|
1966
|
-
document
|
2344
|
+
transformData(document)
|
1967
2345
|
);
|
1968
2346
|
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1969
2347
|
setErrors(formatValidationErrors(res.error));
|
@@ -1976,7 +2354,7 @@ const UpdateAction = ({
|
|
1976
2354
|
model,
|
1977
2355
|
params
|
1978
2356
|
},
|
1979
|
-
document
|
2357
|
+
transformData(document)
|
1980
2358
|
);
|
1981
2359
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1982
2360
|
navigate(
|
@@ -2315,12 +2693,12 @@ const Information = ({ activeTab }) => {
|
|
2315
2693
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2316
2694
|
label: formatMessage({
|
2317
2695
|
id: "content-manager.containers.edit.information.last-published.label",
|
2318
|
-
defaultMessage: "
|
2696
|
+
defaultMessage: "Published"
|
2319
2697
|
}),
|
2320
2698
|
value: formatMessage(
|
2321
2699
|
{
|
2322
2700
|
id: "content-manager.containers.edit.information.last-published.value",
|
2323
|
-
defaultMessage: `
|
2701
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2324
2702
|
},
|
2325
2703
|
{
|
2326
2704
|
time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2333,12 +2711,12 @@ const Information = ({ activeTab }) => {
|
|
2333
2711
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2334
2712
|
label: formatMessage({
|
2335
2713
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2336
|
-
defaultMessage: "
|
2714
|
+
defaultMessage: "Updated"
|
2337
2715
|
}),
|
2338
2716
|
value: formatMessage(
|
2339
2717
|
{
|
2340
2718
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2341
|
-
defaultMessage: `
|
2719
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2342
2720
|
},
|
2343
2721
|
{
|
2344
2722
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2356,12 +2734,12 @@ const Information = ({ activeTab }) => {
|
|
2356
2734
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2357
2735
|
label: formatMessage({
|
2358
2736
|
id: "content-manager.containers.edit.information.document.label",
|
2359
|
-
defaultMessage: "
|
2737
|
+
defaultMessage: "Created"
|
2360
2738
|
}),
|
2361
2739
|
value: formatMessage(
|
2362
2740
|
{
|
2363
2741
|
id: "content-manager.containers.edit.information.document.value",
|
2364
|
-
defaultMessage: `
|
2742
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2365
2743
|
},
|
2366
2744
|
{
|
2367
2745
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2419,10 +2797,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2419
2797
|
designSystem.SingleSelect,
|
2420
2798
|
{
|
2421
2799
|
size: "S",
|
2422
|
-
disabled: action.disabled,
|
2423
|
-
"aria-label": action.label,
|
2424
2800
|
onChange: action.onSelect,
|
2425
|
-
|
2801
|
+
"aria-label": action.label,
|
2802
|
+
...action,
|
2426
2803
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
|
2427
2804
|
},
|
2428
2805
|
action.id
|
@@ -2486,490 +2863,191 @@ const ConfigureTheViewAction = ({ collectionType, model }) => {
|
|
2486
2863
|
position: "header"
|
2487
2864
|
};
|
2488
2865
|
};
|
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
|
-
);
|
2866
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2867
|
+
const EditTheModelAction = ({ model }) => {
|
2868
|
+
const navigate = reactRouterDom.useNavigate();
|
2869
|
+
const { formatMessage } = reactIntl.useIntl();
|
2875
2870
|
return {
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
2881
|
-
|
2871
|
+
label: formatMessage({
|
2872
|
+
id: "content-manager.link-to-ctb",
|
2873
|
+
defaultMessage: "Edit the model"
|
2874
|
+
}),
|
2875
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
|
2876
|
+
onClick: () => {
|
2877
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2882
2878
|
},
|
2883
|
-
|
2884
|
-
...schema?.options,
|
2885
|
-
...schema?.pluginOptions,
|
2886
|
-
...data.contentType.options
|
2887
|
-
}
|
2879
|
+
position: "header"
|
2888
2880
|
};
|
2889
2881
|
};
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
|
2882
|
+
EditTheModelAction.type = "edit-the-model";
|
2883
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2884
|
+
const navigate = reactRouterDom.useNavigate();
|
2885
|
+
const { formatMessage } = reactIntl.useIntl();
|
2886
|
+
const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
|
2887
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2888
|
+
const { delete: deleteAction } = useDocumentActions();
|
2889
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2890
|
+
const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
|
2891
|
+
const isLocalized = document?.locale != null;
|
2892
|
+
return {
|
2893
|
+
disabled: !canDelete || !document,
|
2894
|
+
label: formatMessage(
|
2895
|
+
{
|
2896
|
+
id: "content-manager.actions.delete.label",
|
2897
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2898
|
+
},
|
2899
|
+
{ isLocalized }
|
2900
|
+
),
|
2901
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
|
2902
|
+
dialog: {
|
2903
|
+
type: "dialog",
|
2904
|
+
title: formatMessage({
|
2905
|
+
id: "app.components.ConfirmDialog.title",
|
2906
|
+
defaultMessage: "Confirmation"
|
2907
|
+
}),
|
2908
|
+
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2909
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2910
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2911
|
+
id: "content-manager.actions.delete.dialog.body",
|
2912
|
+
defaultMessage: "Are you sure?"
|
2913
|
+
}) })
|
2914
|
+
] }),
|
2915
|
+
onConfirm: async () => {
|
2916
|
+
if (!listViewPathMatch) {
|
2917
|
+
setSubmitting(true);
|
2918
|
+
}
|
2919
|
+
try {
|
2920
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2921
|
+
console.error(
|
2922
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2923
|
+
);
|
2924
|
+
toggleNotification({
|
2925
|
+
message: formatMessage({
|
2926
|
+
id: "content-manager.actions.delete.error",
|
2927
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2928
|
+
}),
|
2929
|
+
type: "danger"
|
2930
|
+
});
|
2931
|
+
return;
|
2932
|
+
}
|
2933
|
+
const res = await deleteAction({
|
2934
|
+
documentId,
|
2935
|
+
model,
|
2936
|
+
collectionType,
|
2937
|
+
params: {
|
2938
|
+
locale: "*"
|
2939
|
+
}
|
2940
|
+
});
|
2941
|
+
if (!("error" in res)) {
|
2942
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2943
|
+
}
|
2944
|
+
} finally {
|
2945
|
+
if (!listViewPathMatch) {
|
2946
|
+
setSubmitting(false);
|
2947
|
+
}
|
2948
|
+
}
|
2896
2949
|
}
|
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
2950
|
},
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2951
|
+
variant: "danger",
|
2952
|
+
position: ["header", "table-row"]
|
2953
|
+
};
|
2954
|
+
};
|
2955
|
+
DeleteAction$1.type = "delete";
|
2956
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2957
|
+
const Panels = () => {
|
2958
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2959
|
+
const [
|
2960
|
+
{
|
2961
|
+
query: { status }
|
2962
|
+
}
|
2963
|
+
] = strapiAdmin.useQueryParams({
|
2964
|
+
status: "draft"
|
2965
|
+
});
|
2966
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2967
|
+
const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
|
2968
|
+
const props = {
|
2969
|
+
activeTab: status,
|
2970
|
+
model,
|
2971
|
+
documentId: id,
|
2972
|
+
document: isCloning ? void 0 : document,
|
2973
|
+
meta: isCloning ? void 0 : meta,
|
2974
|
+
collectionType
|
2975
|
+
};
|
2976
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
2977
|
+
strapiAdmin.DescriptionComponentRenderer,
|
2978
|
+
{
|
2979
|
+
props,
|
2980
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2981
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
|
2949
2982
|
}
|
2983
|
+
) });
|
2984
|
+
};
|
2985
|
+
const ActionsPanel = () => {
|
2986
|
+
const { formatMessage } = reactIntl.useIntl();
|
2987
|
+
return {
|
2988
|
+
title: formatMessage({
|
2989
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2990
|
+
defaultMessage: "Entry"
|
2991
|
+
}),
|
2992
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
|
2950
2993
|
};
|
2951
2994
|
};
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2995
|
+
ActionsPanel.type = "actions";
|
2996
|
+
const ActionsPanelContent = () => {
|
2997
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2998
|
+
const [
|
2999
|
+
{
|
3000
|
+
query: { status = "draft" }
|
2957
3001
|
}
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
3002
|
+
] = strapiAdmin.useQueryParams();
|
3003
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
3004
|
+
const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
|
3005
|
+
const props = {
|
3006
|
+
activeTab: status,
|
3007
|
+
model,
|
3008
|
+
documentId: id,
|
3009
|
+
document: isCloning ? void 0 : document,
|
3010
|
+
meta: isCloning ? void 0 : meta,
|
3011
|
+
collectionType
|
3012
|
+
};
|
3013
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
|
3014
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
3015
|
+
strapiAdmin.DescriptionComponentRenderer,
|
3016
|
+
{
|
3017
|
+
props,
|
3018
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3019
|
+
children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
|
3020
|
+
}
|
3021
|
+
),
|
3022
|
+
/* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3023
|
+
] });
|
2972
3024
|
};
|
3025
|
+
const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
|
3026
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
3027
|
+
designSystem.Flex,
|
3028
|
+
{
|
3029
|
+
ref,
|
3030
|
+
tag: "aside",
|
3031
|
+
"aria-labelledby": "additional-information",
|
3032
|
+
background: "neutral0",
|
3033
|
+
borderColor: "neutral150",
|
3034
|
+
hasRadius: true,
|
3035
|
+
paddingBottom: 4,
|
3036
|
+
paddingLeft: 4,
|
3037
|
+
paddingRight: 4,
|
3038
|
+
paddingTop: 4,
|
3039
|
+
shadow: "tableShadow",
|
3040
|
+
gap: 3,
|
3041
|
+
direction: "column",
|
3042
|
+
justifyContent: "stretch",
|
3043
|
+
alignItems: "flex-start",
|
3044
|
+
children: [
|
3045
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3046
|
+
children
|
3047
|
+
]
|
3048
|
+
}
|
3049
|
+
);
|
3050
|
+
});
|
2973
3051
|
const ConfirmBulkActionDialog = ({
|
2974
3052
|
onToggleDialog,
|
2975
3053
|
isOpen = false,
|
@@ -3966,7 +4044,7 @@ const index = {
|
|
3966
4044
|
app.router.addRoute({
|
3967
4045
|
path: "content-manager/*",
|
3968
4046
|
lazy: async () => {
|
3969
|
-
const { Layout } = await Promise.resolve().then(() => require("./layout-
|
4047
|
+
const { Layout } = await Promise.resolve().then(() => require("./layout-B4aCAdTt.js"));
|
3970
4048
|
return {
|
3971
4049
|
Component: Layout
|
3972
4050
|
};
|
@@ -3983,7 +4061,7 @@ const index = {
|
|
3983
4061
|
async registerTrads({ locales }) {
|
3984
4062
|
const importedTrads = await Promise.all(
|
3985
4063
|
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-
|
4064
|
+
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
4065
|
return {
|
3988
4066
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3989
4067
|
locale
|
@@ -4029,6 +4107,7 @@ exports.getMainField = getMainField;
|
|
4029
4107
|
exports.getTranslation = getTranslation;
|
4030
4108
|
exports.index = index;
|
4031
4109
|
exports.setInitialData = setInitialData;
|
4110
|
+
exports.useContentManagerContext = useContentManagerContext;
|
4032
4111
|
exports.useContentTypeSchema = useContentTypeSchema;
|
4033
4112
|
exports.useDoc = useDoc;
|
4034
4113
|
exports.useDocLayout = useDocLayout;
|
@@ -4041,4 +4120,4 @@ exports.useGetAllDocumentsQuery = useGetAllDocumentsQuery;
|
|
4041
4120
|
exports.useGetContentTypeConfigurationQuery = useGetContentTypeConfigurationQuery;
|
4042
4121
|
exports.useGetInitialDataQuery = useGetInitialDataQuery;
|
4043
4122
|
exports.useUpdateContentTypeConfigurationMutation = useUpdateContentTypeConfigurationMutation;
|
4044
|
-
//# sourceMappingURL=index-
|
4123
|
+
//# sourceMappingURL=index-BsMu2oVP.js.map
|