@strapi/content-manager 0.0.0-experimental.44c735643fa8b4286750c2dca43f185bb30b7760 → 0.0.0-experimental.4d2127dc461470cbc28e8244c9c2776429a3c8a2
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-BlAzljQ6.js → ComponentConfigurationPage-BEGp0IOV.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BlAzljQ6.js.map → ComponentConfigurationPage-BEGp0IOV.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-Ccwb19Qj.mjs → ComponentConfigurationPage-DUXYqQwA.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-Ccwb19Qj.mjs.map → ComponentConfigurationPage-DUXYqQwA.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BPoOzhCM.js → EditConfigurationPage-BFAn2GH9.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BPoOzhCM.js.map → EditConfigurationPage-BFAn2GH9.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-C19b_9RL.mjs → EditConfigurationPage-D7PzCWYW.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-C19b_9RL.mjs.map → EditConfigurationPage-D7PzCWYW.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-D9xH8HYD.js → EditViewPage-CB017yCP.js} +15 -5
- package/dist/_chunks/EditViewPage-CB017yCP.js.map +1 -0
- package/dist/_chunks/{EditViewPage-nmrHNiJ9.mjs → EditViewPage-DmKviP3U.mjs} +15 -5
- package/dist/_chunks/EditViewPage-DmKviP3U.mjs.map +1 -0
- package/dist/_chunks/{Field-BB_pHo6D.js → Field-ByXbOZL6.js} +69 -25
- package/dist/_chunks/Field-ByXbOZL6.js.map +1 -0
- package/dist/_chunks/{Field--kmlJuSb.mjs → Field-DztIyw14.mjs} +69 -25
- package/dist/_chunks/Field-DztIyw14.mjs.map +1 -0
- package/dist/_chunks/{Form-CUtOiC4S.mjs → Form-D993gfLL.mjs} +3 -3
- package/dist/_chunks/Form-D993gfLL.mjs.map +1 -0
- package/dist/_chunks/{Form-iwbkoaAF.js → Form-WgML3Oqo.js} +3 -3
- package/dist/_chunks/Form-WgML3Oqo.js.map +1 -0
- package/dist/_chunks/{History-guuZF4lR.js → History-BmxGh1cB.js} +24 -11
- package/dist/_chunks/History-BmxGh1cB.js.map +1 -0
- package/dist/_chunks/{History-BKR3KyU3.mjs → History-GcW_hfMD.mjs} +25 -12
- package/dist/_chunks/History-GcW_hfMD.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-Cu26t5sE.js → ListConfigurationPage-16rxMcAO.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-Cu26t5sE.js.map → ListConfigurationPage-16rxMcAO.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-B_O3hiLT.mjs → ListConfigurationPage-kBho1y__.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-B_O3hiLT.mjs.map → ListConfigurationPage-kBho1y__.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-B4sTBfu6.mjs → ListViewPage-6rg02vWk.mjs} +16 -5
- package/dist/_chunks/{ListViewPage-B4sTBfu6.mjs.map → ListViewPage-6rg02vWk.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-DWqqGno8.js → ListViewPage-BXqw44Ja.js} +16 -5
- package/dist/_chunks/ListViewPage-BXqw44Ja.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Daktt4t9.mjs → NoContentTypePage-BVtZUY-U.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Daktt4t9.mjs.map → NoContentTypePage-BVtZUY-U.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-TTkwA8uk.js → NoContentTypePage-DYfH0OD-.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-TTkwA8uk.js.map → NoContentTypePage-DYfH0OD-.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-D8_k39Q0.js → NoPermissionsPage-ClDJKdA9.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-D8_k39Q0.js.map → NoPermissionsPage-ClDJKdA9.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CBUXY2Pt.mjs → NoPermissionsPage-D9R6cWCY.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CBUXY2Pt.mjs.map → NoPermissionsPage-D9R6cWCY.mjs.map} +1 -1
- package/dist/_chunks/{Relations-DjvmZ_XQ.js → Relations-CvsqEtYj.js} +32 -23
- package/dist/_chunks/Relations-CvsqEtYj.js.map +1 -0
- package/dist/_chunks/{Relations-HKmXF7eO.mjs → Relations-uEN7K10I.mjs} +32 -23
- package/dist/_chunks/Relations-uEN7K10I.mjs.map +1 -0
- package/dist/_chunks/{en-BVzUkPxZ.js → en-Bm0D0IWz.js} +8 -8
- package/dist/_chunks/{en-BVzUkPxZ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-CPTj6CjC.mjs → en-DKV44jRb.mjs} +8 -8
- package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-CB1AN26E.mjs → index-BHBrXMdZ.mjs} +940 -863
- package/dist/_chunks/index-BHBrXMdZ.mjs.map +1 -0
- package/dist/_chunks/{index-jDJgW_Lf.js → index-BrzMjag-.js} +938 -861
- package/dist/_chunks/index-BrzMjag-.js.map +1 -0
- package/dist/_chunks/{layout-D6A3K-ut.js → layout-Dwmw0D0e.js} +3 -3
- package/dist/_chunks/{layout-D6A3K-ut.js.map → layout-Dwmw0D0e.js.map} +1 -1
- package/dist/_chunks/{layout-BCzDsMgN.mjs → layout-TDRwTVM6.mjs} +3 -3
- package/dist/_chunks/{layout-BCzDsMgN.mjs.map → layout-TDRwTVM6.mjs.map} +1 -1
- package/dist/_chunks/{relations-B5Jnw32V.mjs → relations-41Z1upHL.mjs} +2 -2
- package/dist/_chunks/{relations-B5Jnw32V.mjs.map → relations-41Z1upHL.mjs.map} +1 -1
- package/dist/_chunks/{relations-C10QoukP.js → relations-CIcMvUXZ.js} +2 -2
- package/dist/_chunks/{relations-C10QoukP.js.map → relations-CIcMvUXZ.js.map} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/Header.d.ts +1 -0
- package/dist/admin/src/preview/constants.d.ts +1 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/server/index.js +45 -18
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +45 -18
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/preview/constants.d.ts +2 -0
- package/dist/server/src/preview/constants.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/package.json +11 -11
- package/dist/_chunks/EditViewPage-D9xH8HYD.js.map +0 -1
- package/dist/_chunks/EditViewPage-nmrHNiJ9.mjs.map +0 -1
- package/dist/_chunks/Field--kmlJuSb.mjs.map +0 -1
- package/dist/_chunks/Field-BB_pHo6D.js.map +0 -1
- package/dist/_chunks/Form-CUtOiC4S.mjs.map +0 -1
- package/dist/_chunks/Form-iwbkoaAF.js.map +0 -1
- package/dist/_chunks/History-BKR3KyU3.mjs.map +0 -1
- package/dist/_chunks/History-guuZF4lR.js.map +0 -1
- package/dist/_chunks/ListViewPage-DWqqGno8.js.map +0 -1
- package/dist/_chunks/Relations-DjvmZ_XQ.js.map +0 -1
- package/dist/_chunks/Relations-HKmXF7eO.mjs.map +0 -1
- package/dist/_chunks/index-CB1AN26E.mjs.map +0 -1
- package/dist/_chunks/index-jDJgW_Lf.js.map +0 -1
- package/strapi-server.js +0 -3
@@ -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) : [];
|
@@ -283,7 +291,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
283
291
|
*/
|
284
292
|
getAllDocuments: builder.query({
|
285
293
|
query: ({ model, params }) => ({
|
286
|
-
url: `/content-manager/collection-types/${model}`,
|
294
|
+
url: `/content-manager/collection-types/${model}${params ? `?${params}` : ""}`,
|
287
295
|
method: "GET",
|
288
296
|
config: {
|
289
297
|
params
|
@@ -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,656 @@ 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
|
-
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;
|
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([]);
|
945
993
|
}
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
const
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
});
|
964
|
-
return { error: res.error };
|
994
|
+
panels[currentPanelIndex].push(row);
|
995
|
+
}
|
996
|
+
return panels;
|
997
|
+
}, []);
|
998
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
999
|
+
(acc, [uid, configuration]) => {
|
1000
|
+
acc[uid] = {
|
1001
|
+
layout: convertEditLayoutToFieldLayouts(
|
1002
|
+
configuration.layouts.edit,
|
1003
|
+
components[uid].attributes,
|
1004
|
+
configuration.metadatas,
|
1005
|
+
{ configurations: data.components, schemas: components }
|
1006
|
+
),
|
1007
|
+
settings: {
|
1008
|
+
...configuration.settings,
|
1009
|
+
icon: components[uid].info.icon,
|
1010
|
+
displayName: components[uid].info.displayName
|
965
1011
|
}
|
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
|
-
}
|
1012
|
+
};
|
1013
|
+
return acc;
|
984
1014
|
},
|
985
|
-
|
1015
|
+
{}
|
986
1016
|
);
|
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
|
-
}
|
1017
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1018
|
+
(acc, [attribute, metadata]) => {
|
1019
|
+
return {
|
1020
|
+
...acc,
|
1021
|
+
[attribute]: metadata.edit
|
1022
|
+
};
|
1019
1023
|
},
|
1020
|
-
|
1024
|
+
{}
|
1021
1025
|
);
|
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
|
-
}
|
1026
|
+
return {
|
1027
|
+
layout: panelledEditAttributes,
|
1028
|
+
components: componentEditAttributes,
|
1029
|
+
metadatas: editMetadatas,
|
1030
|
+
settings: {
|
1031
|
+
...data.contentType.settings,
|
1032
|
+
displayName: schema?.info.displayName
|
1054
1033
|
},
|
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;
|
1034
|
+
options: {
|
1035
|
+
...schema?.options,
|
1036
|
+
...schema?.pluginOptions,
|
1037
|
+
...data.contentType.options
|
1038
|
+
}
|
1039
|
+
};
|
1040
|
+
};
|
1041
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1042
|
+
return rows.map(
|
1043
|
+
(row) => row.map((field) => {
|
1044
|
+
const attribute = attributes[field.name];
|
1045
|
+
if (!attribute) {
|
1046
|
+
return null;
|
1084
1047
|
}
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1048
|
+
const { edit: metadata } = metadatas[field.name];
|
1049
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1050
|
+
return {
|
1051
|
+
attribute,
|
1052
|
+
disabled: !metadata.editable,
|
1053
|
+
hint: metadata.description,
|
1054
|
+
label: metadata.label ?? "",
|
1055
|
+
name: field.name,
|
1056
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1057
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1058
|
+
schemas,
|
1059
|
+
components: components?.schemas ?? {}
|
1060
|
+
}),
|
1061
|
+
placeholder: metadata.placeholder ?? "",
|
1062
|
+
required: attribute.required ?? false,
|
1063
|
+
size: field.size,
|
1064
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1065
|
+
visible: metadata.visible ?? true,
|
1066
|
+
type: attribute.type
|
1067
|
+
};
|
1068
|
+
}).filter((field) => field !== null)
|
1093
1069
|
);
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1070
|
+
};
|
1071
|
+
const formatListLayout = (data, {
|
1072
|
+
schemas,
|
1073
|
+
schema,
|
1074
|
+
components
|
1075
|
+
}) => {
|
1076
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1077
|
+
(acc, [attribute, metadata]) => {
|
1078
|
+
return {
|
1079
|
+
...acc,
|
1080
|
+
[attribute]: metadata.list
|
1081
|
+
};
|
1082
|
+
},
|
1083
|
+
{}
|
1084
|
+
);
|
1085
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1086
|
+
data.contentType.layouts.list,
|
1087
|
+
schema?.attributes,
|
1088
|
+
listMetadatas,
|
1089
|
+
{ configurations: data.components, schemas: components },
|
1090
|
+
schemas
|
1091
|
+
);
|
1092
|
+
return {
|
1093
|
+
layout: listAttributes,
|
1094
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1095
|
+
metadatas: listMetadatas,
|
1096
|
+
options: {
|
1097
|
+
...schema?.options,
|
1098
|
+
...schema?.pluginOptions,
|
1099
|
+
...data.contentType.options
|
1100
|
+
}
|
1101
|
+
};
|
1102
|
+
};
|
1103
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1104
|
+
return columns.map((name) => {
|
1105
|
+
const attribute = attributes[name];
|
1106
|
+
if (!attribute) {
|
1107
|
+
return null;
|
1108
|
+
}
|
1109
|
+
const metadata = metadatas[name];
|
1110
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1111
|
+
return {
|
1112
|
+
attribute,
|
1113
|
+
label: metadata.label ?? "",
|
1114
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1115
|
+
schemas,
|
1116
|
+
components: components?.schemas ?? {}
|
1117
|
+
}),
|
1118
|
+
name,
|
1119
|
+
searchable: metadata.searchable ?? true,
|
1120
|
+
sortable: metadata.sortable ?? true
|
1121
|
+
};
|
1122
|
+
}).filter((field) => field !== null);
|
1123
|
+
};
|
1124
|
+
const useDocument = (args, opts) => {
|
1125
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1126
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1127
|
+
const {
|
1128
|
+
currentData: data,
|
1129
|
+
isLoading: isLoadingDocument,
|
1130
|
+
isFetching: isFetchingDocument,
|
1131
|
+
error
|
1132
|
+
} = useGetDocumentQuery(args, {
|
1133
|
+
...opts,
|
1134
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1135
|
+
});
|
1136
|
+
const {
|
1137
|
+
components,
|
1138
|
+
schema,
|
1139
|
+
schemas,
|
1140
|
+
isLoading: isLoadingSchema
|
1141
|
+
} = useContentTypeSchema(args.model);
|
1142
|
+
React__namespace.useEffect(() => {
|
1143
|
+
if (error) {
|
1144
|
+
toggleNotification({
|
1145
|
+
type: "danger",
|
1146
|
+
message: formatAPIError(error)
|
1147
|
+
});
|
1148
|
+
}
|
1149
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1150
|
+
const validationSchema = React__namespace.useMemo(() => {
|
1151
|
+
if (!schema) {
|
1152
|
+
return null;
|
1153
|
+
}
|
1154
|
+
return createYupSchema(schema.attributes, components);
|
1155
|
+
}, [schema, components]);
|
1156
|
+
const validate = React__namespace.useCallback(
|
1157
|
+
(document) => {
|
1158
|
+
if (!validationSchema) {
|
1159
|
+
throw new Error(
|
1160
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1161
|
+
);
|
1162
|
+
}
|
1163
|
+
try {
|
1164
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1165
|
+
return null;
|
1166
|
+
} catch (error2) {
|
1167
|
+
if (error2 instanceof yup.ValidationError) {
|
1168
|
+
return strapiAdmin.getYupValidationErrors(error2);
|
1110
1169
|
}
|
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;
|
1170
|
+
throw error2;
|
1127
1171
|
}
|
1128
1172
|
},
|
1129
|
-
[
|
1173
|
+
[validationSchema]
|
1130
1174
|
);
|
1131
|
-
const
|
1132
|
-
const
|
1133
|
-
|
1175
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1176
|
+
const hasError = !!error;
|
1177
|
+
return {
|
1178
|
+
components,
|
1179
|
+
document: data?.data,
|
1180
|
+
meta: data?.meta,
|
1181
|
+
isLoading,
|
1182
|
+
hasError,
|
1183
|
+
schema,
|
1184
|
+
schemas,
|
1185
|
+
validate
|
1186
|
+
};
|
1187
|
+
};
|
1188
|
+
const useDoc = () => {
|
1189
|
+
const { id, slug, collectionType, origin } = reactRouterDom.useParams();
|
1190
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
1191
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1192
|
+
if (!collectionType) {
|
1193
|
+
throw new Error("Could not find collectionType in url params");
|
1194
|
+
}
|
1195
|
+
if (!slug) {
|
1196
|
+
throw new Error("Could not find model in url params");
|
1197
|
+
}
|
1198
|
+
const document = useDocument(
|
1199
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1200
|
+
{
|
1201
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1202
|
+
}
|
1203
|
+
);
|
1204
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1205
|
+
return {
|
1206
|
+
collectionType,
|
1207
|
+
model: slug,
|
1208
|
+
id: returnId,
|
1209
|
+
...document
|
1210
|
+
};
|
1211
|
+
};
|
1212
|
+
const useContentManagerContext = () => {
|
1213
|
+
const {
|
1214
|
+
collectionType,
|
1215
|
+
model,
|
1216
|
+
id,
|
1217
|
+
components,
|
1218
|
+
isLoading: isLoadingDoc,
|
1219
|
+
schema,
|
1220
|
+
schemas
|
1221
|
+
} = useDoc();
|
1222
|
+
const layout = useDocumentLayout(model);
|
1223
|
+
const form = strapiAdmin.useForm("useContentManagerContext", (state) => state);
|
1224
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1225
|
+
const slug = model;
|
1226
|
+
const isCreatingEntry = id === "create";
|
1227
|
+
useContentTypeSchema();
|
1228
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1229
|
+
const error = layout.error;
|
1230
|
+
return {
|
1231
|
+
error,
|
1232
|
+
isLoading,
|
1233
|
+
// Base metadata
|
1234
|
+
model,
|
1235
|
+
collectionType,
|
1236
|
+
id,
|
1237
|
+
slug,
|
1238
|
+
isCreatingEntry,
|
1239
|
+
isSingleType,
|
1240
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1241
|
+
// All schema infos
|
1242
|
+
components,
|
1243
|
+
contentType: schema,
|
1244
|
+
contentTypes: schemas,
|
1245
|
+
// Form state
|
1246
|
+
form,
|
1247
|
+
// layout infos
|
1248
|
+
layout
|
1249
|
+
};
|
1250
|
+
};
|
1251
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1252
|
+
if (!pluginId) {
|
1253
|
+
throw new TypeError("pluginId can't be empty");
|
1254
|
+
}
|
1255
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1256
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1257
|
+
return acc;
|
1258
|
+
}, {});
|
1259
|
+
};
|
1260
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1261
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1262
|
+
id: "notification.error",
|
1263
|
+
defaultMessage: "An error occurred, please try again"
|
1264
|
+
};
|
1265
|
+
const useDocumentActions = () => {
|
1266
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1267
|
+
const { formatMessage } = reactIntl.useIntl();
|
1268
|
+
const { trackUsage } = strapiAdmin.useTracking();
|
1269
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1270
|
+
const navigate = reactRouterDom.useNavigate();
|
1271
|
+
const setCurrentStep = strapiAdmin.useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1272
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1273
|
+
const _delete = React__namespace.useCallback(
|
1274
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1134
1275
|
try {
|
1135
|
-
trackUsage("
|
1136
|
-
const res = await
|
1276
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1277
|
+
const res = await deleteDocument({
|
1137
1278
|
collectionType,
|
1138
1279
|
model,
|
1139
1280
|
documentId,
|
1140
|
-
params
|
1141
|
-
data: {
|
1142
|
-
discardDraft
|
1143
|
-
}
|
1281
|
+
params
|
1144
1282
|
});
|
1145
1283
|
if ("error" in res) {
|
1146
|
-
toggleNotification({
|
1284
|
+
toggleNotification({
|
1285
|
+
type: "danger",
|
1286
|
+
message: formatAPIError(res.error)
|
1287
|
+
});
|
1147
1288
|
return { error: res.error };
|
1148
1289
|
}
|
1149
|
-
trackUsage("didUnpublishEntry");
|
1150
1290
|
toggleNotification({
|
1151
1291
|
type: "success",
|
1152
1292
|
message: formatMessage({
|
1153
|
-
id: getTranslation("success.record.
|
1154
|
-
defaultMessage: "
|
1293
|
+
id: getTranslation("success.record.delete"),
|
1294
|
+
defaultMessage: "Deleted document"
|
1155
1295
|
})
|
1156
1296
|
});
|
1297
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1157
1298
|
return res.data;
|
1158
1299
|
} catch (err) {
|
1159
1300
|
toggleNotification({
|
1160
1301
|
type: "danger",
|
1161
1302
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1162
1303
|
});
|
1304
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1163
1305
|
throw err;
|
1164
1306
|
}
|
1165
1307
|
},
|
1166
|
-
[trackUsage,
|
1308
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1167
1309
|
);
|
1168
|
-
const [
|
1169
|
-
const
|
1310
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1311
|
+
const deleteMany = React__namespace.useCallback(
|
1170
1312
|
async ({ model, documentIds, params }) => {
|
1171
1313
|
try {
|
1172
|
-
trackUsage("
|
1173
|
-
const res = await
|
1314
|
+
trackUsage("willBulkDeleteEntries");
|
1315
|
+
const res = await deleteManyDocuments({
|
1174
1316
|
model,
|
1175
1317
|
documentIds,
|
1176
1318
|
params
|
1177
1319
|
});
|
1178
1320
|
if ("error" in res) {
|
1179
|
-
toggleNotification({
|
1321
|
+
toggleNotification({
|
1322
|
+
type: "danger",
|
1323
|
+
message: formatAPIError(res.error)
|
1324
|
+
});
|
1180
1325
|
return { error: res.error };
|
1181
1326
|
}
|
1182
|
-
trackUsage("didBulkUnpublishEntries");
|
1183
1327
|
toggleNotification({
|
1184
1328
|
type: "success",
|
1185
1329
|
title: formatMessage({
|
1186
|
-
id: getTranslation("success.records.
|
1187
|
-
defaultMessage: "Successfully
|
1330
|
+
id: getTranslation("success.records.delete"),
|
1331
|
+
defaultMessage: "Successfully deleted."
|
1188
1332
|
}),
|
1189
1333
|
message: ""
|
1190
1334
|
});
|
1335
|
+
trackUsage("didBulkDeleteEntries");
|
1191
1336
|
return res.data;
|
1192
1337
|
} catch (err) {
|
1193
1338
|
toggleNotification({
|
1194
1339
|
type: "danger",
|
1195
1340
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1196
1341
|
});
|
1197
|
-
trackUsage("
|
1342
|
+
trackUsage("didNotBulkDeleteEntries");
|
1198
1343
|
throw err;
|
1199
1344
|
}
|
1200
1345
|
},
|
1201
|
-
[trackUsage,
|
1346
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1202
1347
|
);
|
1203
|
-
const [
|
1204
|
-
const
|
1205
|
-
async ({ model, params }
|
1348
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1349
|
+
const discard = React__namespace.useCallback(
|
1350
|
+
async ({ collectionType, model, documentId, params }) => {
|
1206
1351
|
try {
|
1207
|
-
const res = await
|
1352
|
+
const res = await discardDocument({
|
1353
|
+
collectionType,
|
1208
1354
|
model,
|
1209
|
-
|
1355
|
+
documentId,
|
1210
1356
|
params
|
1211
1357
|
});
|
1212
1358
|
if ("error" in res) {
|
1213
|
-
toggleNotification({
|
1214
|
-
|
1359
|
+
toggleNotification({
|
1360
|
+
type: "danger",
|
1361
|
+
message: formatAPIError(res.error)
|
1362
|
+
});
|
1215
1363
|
return { error: res.error };
|
1216
1364
|
}
|
1217
|
-
trackUsage("didCreateEntry", trackerProperty);
|
1218
1365
|
toggleNotification({
|
1219
1366
|
type: "success",
|
1220
1367
|
message: formatMessage({
|
1221
|
-
id:
|
1368
|
+
id: "content-manager.success.record.discard",
|
1369
|
+
defaultMessage: "Changes discarded"
|
1370
|
+
})
|
1371
|
+
});
|
1372
|
+
return res.data;
|
1373
|
+
} catch (err) {
|
1374
|
+
toggleNotification({
|
1375
|
+
type: "danger",
|
1376
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1377
|
+
});
|
1378
|
+
throw err;
|
1379
|
+
}
|
1380
|
+
},
|
1381
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1382
|
+
);
|
1383
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1384
|
+
const publish = React__namespace.useCallback(
|
1385
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1386
|
+
try {
|
1387
|
+
trackUsage("willPublishEntry");
|
1388
|
+
const res = await publishDocument({
|
1389
|
+
collectionType,
|
1390
|
+
model,
|
1391
|
+
documentId,
|
1392
|
+
data,
|
1393
|
+
params
|
1394
|
+
});
|
1395
|
+
if ("error" in res) {
|
1396
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1397
|
+
return { error: res.error };
|
1398
|
+
}
|
1399
|
+
trackUsage("didPublishEntry");
|
1400
|
+
toggleNotification({
|
1401
|
+
type: "success",
|
1402
|
+
message: formatMessage({
|
1403
|
+
id: getTranslation("success.record.publish"),
|
1404
|
+
defaultMessage: "Published document"
|
1405
|
+
})
|
1406
|
+
});
|
1407
|
+
return res.data;
|
1408
|
+
} catch (err) {
|
1409
|
+
toggleNotification({
|
1410
|
+
type: "danger",
|
1411
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1412
|
+
});
|
1413
|
+
throw err;
|
1414
|
+
}
|
1415
|
+
},
|
1416
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1417
|
+
);
|
1418
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1419
|
+
const publishMany = React__namespace.useCallback(
|
1420
|
+
async ({ model, documentIds, params }) => {
|
1421
|
+
try {
|
1422
|
+
const res = await publishManyDocuments({
|
1423
|
+
model,
|
1424
|
+
documentIds,
|
1425
|
+
params
|
1426
|
+
});
|
1427
|
+
if ("error" in res) {
|
1428
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1429
|
+
return { error: res.error };
|
1430
|
+
}
|
1431
|
+
toggleNotification({
|
1432
|
+
type: "success",
|
1433
|
+
message: formatMessage({
|
1434
|
+
id: getTranslation("success.record.publish"),
|
1435
|
+
defaultMessage: "Published document"
|
1436
|
+
})
|
1437
|
+
});
|
1438
|
+
return res.data;
|
1439
|
+
} catch (err) {
|
1440
|
+
toggleNotification({
|
1441
|
+
type: "danger",
|
1442
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1443
|
+
});
|
1444
|
+
throw err;
|
1445
|
+
}
|
1446
|
+
},
|
1447
|
+
[
|
1448
|
+
// trackUsage,
|
1449
|
+
publishManyDocuments,
|
1450
|
+
toggleNotification,
|
1451
|
+
formatMessage,
|
1452
|
+
formatAPIError
|
1453
|
+
]
|
1454
|
+
);
|
1455
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1456
|
+
const update = React__namespace.useCallback(
|
1457
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1458
|
+
try {
|
1459
|
+
trackUsage("willEditEntry", trackerProperty);
|
1460
|
+
const res = await updateDocument({
|
1461
|
+
collectionType,
|
1462
|
+
model,
|
1463
|
+
documentId,
|
1464
|
+
data,
|
1465
|
+
params
|
1466
|
+
});
|
1467
|
+
if ("error" in res) {
|
1468
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1469
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1470
|
+
return { error: res.error };
|
1471
|
+
}
|
1472
|
+
trackUsage("didEditEntry", trackerProperty);
|
1473
|
+
toggleNotification({
|
1474
|
+
type: "success",
|
1475
|
+
message: formatMessage({
|
1476
|
+
id: getTranslation("success.record.save"),
|
1477
|
+
defaultMessage: "Saved document"
|
1478
|
+
})
|
1479
|
+
});
|
1480
|
+
return res.data;
|
1481
|
+
} catch (err) {
|
1482
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1483
|
+
toggleNotification({
|
1484
|
+
type: "danger",
|
1485
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1486
|
+
});
|
1487
|
+
throw err;
|
1488
|
+
}
|
1489
|
+
},
|
1490
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1491
|
+
);
|
1492
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1493
|
+
const unpublish = React__namespace.useCallback(
|
1494
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1495
|
+
try {
|
1496
|
+
trackUsage("willUnpublishEntry");
|
1497
|
+
const res = await unpublishDocument({
|
1498
|
+
collectionType,
|
1499
|
+
model,
|
1500
|
+
documentId,
|
1501
|
+
params,
|
1502
|
+
data: {
|
1503
|
+
discardDraft
|
1504
|
+
}
|
1505
|
+
});
|
1506
|
+
if ("error" in res) {
|
1507
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1508
|
+
return { error: res.error };
|
1509
|
+
}
|
1510
|
+
trackUsage("didUnpublishEntry");
|
1511
|
+
toggleNotification({
|
1512
|
+
type: "success",
|
1513
|
+
message: formatMessage({
|
1514
|
+
id: getTranslation("success.record.unpublish"),
|
1515
|
+
defaultMessage: "Unpublished document"
|
1516
|
+
})
|
1517
|
+
});
|
1518
|
+
return res.data;
|
1519
|
+
} catch (err) {
|
1520
|
+
toggleNotification({
|
1521
|
+
type: "danger",
|
1522
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1523
|
+
});
|
1524
|
+
throw err;
|
1525
|
+
}
|
1526
|
+
},
|
1527
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1528
|
+
);
|
1529
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1530
|
+
const unpublishMany = React__namespace.useCallback(
|
1531
|
+
async ({ model, documentIds, params }) => {
|
1532
|
+
try {
|
1533
|
+
trackUsage("willBulkUnpublishEntries");
|
1534
|
+
const res = await unpublishManyDocuments({
|
1535
|
+
model,
|
1536
|
+
documentIds,
|
1537
|
+
params
|
1538
|
+
});
|
1539
|
+
if ("error" in res) {
|
1540
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1541
|
+
return { error: res.error };
|
1542
|
+
}
|
1543
|
+
trackUsage("didBulkUnpublishEntries");
|
1544
|
+
toggleNotification({
|
1545
|
+
type: "success",
|
1546
|
+
title: formatMessage({
|
1547
|
+
id: getTranslation("success.records.unpublish"),
|
1548
|
+
defaultMessage: "Successfully unpublished."
|
1549
|
+
}),
|
1550
|
+
message: ""
|
1551
|
+
});
|
1552
|
+
return res.data;
|
1553
|
+
} catch (err) {
|
1554
|
+
toggleNotification({
|
1555
|
+
type: "danger",
|
1556
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1557
|
+
});
|
1558
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1559
|
+
throw err;
|
1560
|
+
}
|
1561
|
+
},
|
1562
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1563
|
+
);
|
1564
|
+
const [createDocument] = useCreateDocumentMutation();
|
1565
|
+
const create = React__namespace.useCallback(
|
1566
|
+
async ({ model, params }, data, trackerProperty) => {
|
1567
|
+
try {
|
1568
|
+
const res = await createDocument({
|
1569
|
+
model,
|
1570
|
+
data,
|
1571
|
+
params
|
1572
|
+
});
|
1573
|
+
if ("error" in res) {
|
1574
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1575
|
+
trackUsage("didNotCreateEntry", { error: res.error, ...trackerProperty });
|
1576
|
+
return { error: res.error };
|
1577
|
+
}
|
1578
|
+
trackUsage("didCreateEntry", trackerProperty);
|
1579
|
+
toggleNotification({
|
1580
|
+
type: "success",
|
1581
|
+
message: formatMessage({
|
1582
|
+
id: getTranslation("success.record.save"),
|
1222
1583
|
defaultMessage: "Saved document"
|
1223
1584
|
})
|
1224
1585
|
});
|
1586
|
+
setCurrentStep("contentManager.success");
|
1225
1587
|
return res.data;
|
1226
1588
|
} catch (err) {
|
1227
1589
|
toggleNotification({
|
@@ -1324,7 +1686,7 @@ const useDocumentActions = () => {
|
|
1324
1686
|
};
|
1325
1687
|
};
|
1326
1688
|
const ProtectedHistoryPage = React.lazy(
|
1327
|
-
() => Promise.resolve().then(() => require("./History-
|
1689
|
+
() => Promise.resolve().then(() => require("./History-BmxGh1cB.js")).then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1328
1690
|
);
|
1329
1691
|
const routes$1 = [
|
1330
1692
|
{
|
@@ -1337,31 +1699,31 @@ const routes$1 = [
|
|
1337
1699
|
}
|
1338
1700
|
];
|
1339
1701
|
const ProtectedEditViewPage = React.lazy(
|
1340
|
-
() => Promise.resolve().then(() => require("./EditViewPage-
|
1702
|
+
() => Promise.resolve().then(() => require("./EditViewPage-CB017yCP.js")).then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1341
1703
|
);
|
1342
1704
|
const ProtectedListViewPage = React.lazy(
|
1343
|
-
() => Promise.resolve().then(() => require("./ListViewPage-
|
1705
|
+
() => Promise.resolve().then(() => require("./ListViewPage-BXqw44Ja.js")).then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1344
1706
|
);
|
1345
1707
|
const ProtectedListConfiguration = React.lazy(
|
1346
|
-
() => Promise.resolve().then(() => require("./ListConfigurationPage-
|
1708
|
+
() => Promise.resolve().then(() => require("./ListConfigurationPage-16rxMcAO.js")).then((mod) => ({
|
1347
1709
|
default: mod.ProtectedListConfiguration
|
1348
1710
|
}))
|
1349
1711
|
);
|
1350
1712
|
const ProtectedEditConfigurationPage = React.lazy(
|
1351
|
-
() => Promise.resolve().then(() => require("./EditConfigurationPage-
|
1713
|
+
() => Promise.resolve().then(() => require("./EditConfigurationPage-BFAn2GH9.js")).then((mod) => ({
|
1352
1714
|
default: mod.ProtectedEditConfigurationPage
|
1353
1715
|
}))
|
1354
1716
|
);
|
1355
1717
|
const ProtectedComponentConfigurationPage = React.lazy(
|
1356
|
-
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-
|
1718
|
+
() => Promise.resolve().then(() => require("./ComponentConfigurationPage-BEGp0IOV.js")).then((mod) => ({
|
1357
1719
|
default: mod.ProtectedComponentConfigurationPage
|
1358
1720
|
}))
|
1359
1721
|
);
|
1360
1722
|
const NoPermissions = React.lazy(
|
1361
|
-
() => Promise.resolve().then(() => require("./NoPermissionsPage-
|
1723
|
+
() => Promise.resolve().then(() => require("./NoPermissionsPage-ClDJKdA9.js")).then((mod) => ({ default: mod.NoPermissions }))
|
1362
1724
|
);
|
1363
1725
|
const NoContentType = React.lazy(
|
1364
|
-
() => Promise.resolve().then(() => require("./NoContentTypePage-
|
1726
|
+
() => Promise.resolve().then(() => require("./NoContentTypePage-DYfH0OD-.js")).then((mod) => ({ default: mod.NoContentType }))
|
1365
1727
|
);
|
1366
1728
|
const CollectionTypePages = () => {
|
1367
1729
|
const { collectionType } = reactRouterDom.useParams();
|
@@ -1560,7 +1922,7 @@ const DocumentActionsMenu = ({
|
|
1560
1922
|
]
|
1561
1923
|
}
|
1562
1924
|
),
|
1563
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, {
|
1925
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1564
1926
|
actions2.map((action) => {
|
1565
1927
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
1566
1928
|
designSystem.Menu.Item,
|
@@ -1808,7 +2170,9 @@ const PublishAction$1 = ({
|
|
1808
2170
|
const performPublish = async () => {
|
1809
2171
|
setSubmitting(true);
|
1810
2172
|
try {
|
1811
|
-
const { errors } = await validate(
|
2173
|
+
const { errors } = await validate(true, {
|
2174
|
+
status: "published"
|
2175
|
+
});
|
1812
2176
|
if (errors) {
|
1813
2177
|
toggleNotification({
|
1814
2178
|
type: "danger",
|
@@ -1922,18 +2286,18 @@ const UpdateAction = ({
|
|
1922
2286
|
onClick: async () => {
|
1923
2287
|
setSubmitting(true);
|
1924
2288
|
try {
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
})
|
1935
|
-
|
1936
|
-
|
2289
|
+
const { errors } = await validate(true, {
|
2290
|
+
status: "draft"
|
2291
|
+
});
|
2292
|
+
if (errors) {
|
2293
|
+
toggleNotification({
|
2294
|
+
type: "danger",
|
2295
|
+
message: formatMessage({
|
2296
|
+
id: "content-manager.validation.error",
|
2297
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2298
|
+
})
|
2299
|
+
});
|
2300
|
+
return;
|
1937
2301
|
}
|
1938
2302
|
if (isCloning) {
|
1939
2303
|
const res = await clone(
|
@@ -2315,12 +2679,12 @@ const Information = ({ activeTab }) => {
|
|
2315
2679
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2316
2680
|
label: formatMessage({
|
2317
2681
|
id: "content-manager.containers.edit.information.last-published.label",
|
2318
|
-
defaultMessage: "
|
2682
|
+
defaultMessage: "Published"
|
2319
2683
|
}),
|
2320
2684
|
value: formatMessage(
|
2321
2685
|
{
|
2322
2686
|
id: "content-manager.containers.edit.information.last-published.value",
|
2323
|
-
defaultMessage: `
|
2687
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2324
2688
|
},
|
2325
2689
|
{
|
2326
2690
|
time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2333,12 +2697,12 @@ const Information = ({ activeTab }) => {
|
|
2333
2697
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2334
2698
|
label: formatMessage({
|
2335
2699
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2336
|
-
defaultMessage: "
|
2700
|
+
defaultMessage: "Updated"
|
2337
2701
|
}),
|
2338
2702
|
value: formatMessage(
|
2339
2703
|
{
|
2340
2704
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2341
|
-
defaultMessage: `
|
2705
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2342
2706
|
},
|
2343
2707
|
{
|
2344
2708
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2356,12 +2720,12 @@ const Information = ({ activeTab }) => {
|
|
2356
2720
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2357
2721
|
label: formatMessage({
|
2358
2722
|
id: "content-manager.containers.edit.information.document.label",
|
2359
|
-
defaultMessage: "
|
2723
|
+
defaultMessage: "Created"
|
2360
2724
|
}),
|
2361
2725
|
value: formatMessage(
|
2362
2726
|
{
|
2363
2727
|
id: "content-manager.containers.edit.information.document.value",
|
2364
|
-
defaultMessage: `
|
2728
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2365
2729
|
},
|
2366
2730
|
{
|
2367
2731
|
time: /* @__PURE__ */ jsxRuntime.jsx(
|
@@ -2419,10 +2783,9 @@ const HeaderActions = ({ actions: actions2 }) => {
|
|
2419
2783
|
designSystem.SingleSelect,
|
2420
2784
|
{
|
2421
2785
|
size: "S",
|
2422
|
-
disabled: action.disabled,
|
2423
|
-
"aria-label": action.label,
|
2424
2786
|
onChange: action.onSelect,
|
2425
|
-
|
2787
|
+
"aria-label": action.label,
|
2788
|
+
...action,
|
2426
2789
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
|
2427
2790
|
},
|
2428
2791
|
action.id
|
@@ -2491,485 +2854,186 @@ const EditTheModelAction = ({ model }) => {
|
|
2491
2854
|
const navigate = reactRouterDom.useNavigate();
|
2492
2855
|
const { formatMessage } = reactIntl.useIntl();
|
2493
2856
|
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
|
-
);
|
2875
|
-
return {
|
2876
|
-
layout: panelledEditAttributes,
|
2877
|
-
components: componentEditAttributes,
|
2878
|
-
metadatas: editMetadatas,
|
2879
|
-
settings: {
|
2880
|
-
...data.contentType.settings,
|
2881
|
-
displayName: schema?.info.displayName
|
2857
|
+
label: formatMessage({
|
2858
|
+
id: "content-manager.link-to-ctb",
|
2859
|
+
defaultMessage: "Edit the model"
|
2860
|
+
}),
|
2861
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
|
2862
|
+
onClick: () => {
|
2863
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2882
2864
|
},
|
2883
|
-
|
2884
|
-
...schema?.options,
|
2885
|
-
...schema?.pluginOptions,
|
2886
|
-
...data.contentType.options
|
2887
|
-
}
|
2865
|
+
position: "header"
|
2888
2866
|
};
|
2889
2867
|
};
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
|
2868
|
+
EditTheModelAction.type = "edit-the-model";
|
2869
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2870
|
+
const navigate = reactRouterDom.useNavigate();
|
2871
|
+
const { formatMessage } = reactIntl.useIntl();
|
2872
|
+
const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
|
2873
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2874
|
+
const { delete: deleteAction } = useDocumentActions();
|
2875
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2876
|
+
const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
|
2877
|
+
const isLocalized = document?.locale != null;
|
2878
|
+
return {
|
2879
|
+
disabled: !canDelete || !document,
|
2880
|
+
label: formatMessage(
|
2881
|
+
{
|
2882
|
+
id: "content-manager.actions.delete.label",
|
2883
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2884
|
+
},
|
2885
|
+
{ isLocalized }
|
2886
|
+
),
|
2887
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
|
2888
|
+
dialog: {
|
2889
|
+
type: "dialog",
|
2890
|
+
title: formatMessage({
|
2891
|
+
id: "app.components.ConfirmDialog.title",
|
2892
|
+
defaultMessage: "Confirmation"
|
2893
|
+
}),
|
2894
|
+
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2895
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2896
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2897
|
+
id: "content-manager.actions.delete.dialog.body",
|
2898
|
+
defaultMessage: "Are you sure?"
|
2899
|
+
}) })
|
2900
|
+
] }),
|
2901
|
+
onConfirm: async () => {
|
2902
|
+
if (!listViewPathMatch) {
|
2903
|
+
setSubmitting(true);
|
2904
|
+
}
|
2905
|
+
try {
|
2906
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2907
|
+
console.error(
|
2908
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2909
|
+
);
|
2910
|
+
toggleNotification({
|
2911
|
+
message: formatMessage({
|
2912
|
+
id: "content-manager.actions.delete.error",
|
2913
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2914
|
+
}),
|
2915
|
+
type: "danger"
|
2916
|
+
});
|
2917
|
+
return;
|
2918
|
+
}
|
2919
|
+
const res = await deleteAction({
|
2920
|
+
documentId,
|
2921
|
+
model,
|
2922
|
+
collectionType,
|
2923
|
+
params: {
|
2924
|
+
locale: "*"
|
2925
|
+
}
|
2926
|
+
});
|
2927
|
+
if (!("error" in res)) {
|
2928
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2929
|
+
}
|
2930
|
+
} finally {
|
2931
|
+
if (!listViewPathMatch) {
|
2932
|
+
setSubmitting(false);
|
2933
|
+
}
|
2934
|
+
}
|
2896
2935
|
}
|
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
2936
|
},
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
|
2944
|
-
|
2945
|
-
|
2946
|
-
|
2947
|
-
|
2948
|
-
|
2937
|
+
variant: "danger",
|
2938
|
+
position: ["header", "table-row"]
|
2939
|
+
};
|
2940
|
+
};
|
2941
|
+
DeleteAction$1.type = "delete";
|
2942
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2943
|
+
const Panels = () => {
|
2944
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2945
|
+
const [
|
2946
|
+
{
|
2947
|
+
query: { status }
|
2948
|
+
}
|
2949
|
+
] = strapiAdmin.useQueryParams({
|
2950
|
+
status: "draft"
|
2951
|
+
});
|
2952
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2953
|
+
const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
|
2954
|
+
const props = {
|
2955
|
+
activeTab: status,
|
2956
|
+
model,
|
2957
|
+
documentId: id,
|
2958
|
+
document: isCloning ? void 0 : document,
|
2959
|
+
meta: isCloning ? void 0 : meta,
|
2960
|
+
collectionType
|
2961
|
+
};
|
2962
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
2963
|
+
strapiAdmin.DescriptionComponentRenderer,
|
2964
|
+
{
|
2965
|
+
props,
|
2966
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2967
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
|
2949
2968
|
}
|
2969
|
+
) });
|
2970
|
+
};
|
2971
|
+
const ActionsPanel = () => {
|
2972
|
+
const { formatMessage } = reactIntl.useIntl();
|
2973
|
+
return {
|
2974
|
+
title: formatMessage({
|
2975
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2976
|
+
defaultMessage: "Entry"
|
2977
|
+
}),
|
2978
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
|
2950
2979
|
};
|
2951
2980
|
};
|
2952
|
-
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2981
|
+
ActionsPanel.type = "actions";
|
2982
|
+
const ActionsPanelContent = () => {
|
2983
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2984
|
+
const [
|
2985
|
+
{
|
2986
|
+
query: { status = "draft" }
|
2957
2987
|
}
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2988
|
+
] = strapiAdmin.useQueryParams();
|
2989
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2990
|
+
const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2991
|
+
const props = {
|
2992
|
+
activeTab: status,
|
2993
|
+
model,
|
2994
|
+
documentId: id,
|
2995
|
+
document: isCloning ? void 0 : document,
|
2996
|
+
meta: isCloning ? void 0 : meta,
|
2997
|
+
collectionType
|
2998
|
+
};
|
2999
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
|
3000
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
3001
|
+
strapiAdmin.DescriptionComponentRenderer,
|
3002
|
+
{
|
3003
|
+
props,
|
3004
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3005
|
+
children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
|
3006
|
+
}
|
3007
|
+
),
|
3008
|
+
/* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3009
|
+
] });
|
2972
3010
|
};
|
3011
|
+
const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
|
3012
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
3013
|
+
designSystem.Flex,
|
3014
|
+
{
|
3015
|
+
ref,
|
3016
|
+
tag: "aside",
|
3017
|
+
"aria-labelledby": "additional-information",
|
3018
|
+
background: "neutral0",
|
3019
|
+
borderColor: "neutral150",
|
3020
|
+
hasRadius: true,
|
3021
|
+
paddingBottom: 4,
|
3022
|
+
paddingLeft: 4,
|
3023
|
+
paddingRight: 4,
|
3024
|
+
paddingTop: 4,
|
3025
|
+
shadow: "tableShadow",
|
3026
|
+
gap: 3,
|
3027
|
+
direction: "column",
|
3028
|
+
justifyContent: "stretch",
|
3029
|
+
alignItems: "flex-start",
|
3030
|
+
children: [
|
3031
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
|
3032
|
+
children
|
3033
|
+
]
|
3034
|
+
}
|
3035
|
+
);
|
3036
|
+
});
|
2973
3037
|
const ConfirmBulkActionDialog = ({
|
2974
3038
|
onToggleDialog,
|
2975
3039
|
isOpen = false,
|
@@ -3947,6 +4011,15 @@ const { setInitialData } = actions;
|
|
3947
4011
|
const reducer = toolkit.combineReducers({
|
3948
4012
|
app: reducer$1
|
3949
4013
|
});
|
4014
|
+
const FEATURE_ID = "preview";
|
4015
|
+
const previewAdmin = {
|
4016
|
+
bootstrap(app) {
|
4017
|
+
if (!window.strapi.future.isEnabled(FEATURE_ID)) {
|
4018
|
+
return {};
|
4019
|
+
}
|
4020
|
+
console.log("Bootstrapping preview admin");
|
4021
|
+
}
|
4022
|
+
};
|
3950
4023
|
const index = {
|
3951
4024
|
register(app) {
|
3952
4025
|
const cm = new ContentManagerPlugin();
|
@@ -3966,7 +4039,7 @@ const index = {
|
|
3966
4039
|
app.router.addRoute({
|
3967
4040
|
path: "content-manager/*",
|
3968
4041
|
lazy: async () => {
|
3969
|
-
const { Layout } = await Promise.resolve().then(() => require("./layout-
|
4042
|
+
const { Layout } = await Promise.resolve().then(() => require("./layout-Dwmw0D0e.js"));
|
3970
4043
|
return {
|
3971
4044
|
Component: Layout
|
3972
4045
|
};
|
@@ -3979,11 +4052,14 @@ const index = {
|
|
3979
4052
|
if (typeof historyAdmin.bootstrap === "function") {
|
3980
4053
|
historyAdmin.bootstrap(app);
|
3981
4054
|
}
|
4055
|
+
if (typeof previewAdmin.bootstrap === "function") {
|
4056
|
+
previewAdmin.bootstrap(app);
|
4057
|
+
}
|
3982
4058
|
},
|
3983
4059
|
async registerTrads({ locales }) {
|
3984
4060
|
const importedTrads = await Promise.all(
|
3985
4061
|
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-
|
4062
|
+
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
4063
|
return {
|
3988
4064
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3989
4065
|
locale
|
@@ -4029,6 +4105,7 @@ exports.getMainField = getMainField;
|
|
4029
4105
|
exports.getTranslation = getTranslation;
|
4030
4106
|
exports.index = index;
|
4031
4107
|
exports.setInitialData = setInitialData;
|
4108
|
+
exports.useContentManagerContext = useContentManagerContext;
|
4032
4109
|
exports.useContentTypeSchema = useContentTypeSchema;
|
4033
4110
|
exports.useDoc = useDoc;
|
4034
4111
|
exports.useDocLayout = useDocLayout;
|
@@ -4041,4 +4118,4 @@ exports.useGetAllDocumentsQuery = useGetAllDocumentsQuery;
|
|
4041
4118
|
exports.useGetContentTypeConfigurationQuery = useGetContentTypeConfigurationQuery;
|
4042
4119
|
exports.useGetInitialDataQuery = useGetInitialDataQuery;
|
4043
4120
|
exports.useUpdateContentTypeConfigurationMutation = useUpdateContentTypeConfigurationMutation;
|
4044
|
-
//# sourceMappingURL=index-
|
4121
|
+
//# sourceMappingURL=index-BrzMjag-.js.map
|