@strapi/content-manager 0.0.0-experimental.6d27139261823fc4b18da9f3c10b271d5010dbf0 → 0.0.0-experimental.7273fc63f5c2c8aa9e100655b1776f3e0621e61a
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-DyDkPajU.js → ComponentConfigurationPage-D2_cVxXK.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js.map → ComponentConfigurationPage-D2_cVxXK.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs → ComponentConfigurationPage-suSMW3KC.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs.map → ComponentConfigurationPage-suSMW3KC.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs → EditConfigurationPage-CBscKbxt.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs.map → EditConfigurationPage-CBscKbxt.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DValmA0m.js → EditConfigurationPage-Z_VzHVH4.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-DValmA0m.js.map → EditConfigurationPage-Z_VzHVH4.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-DiNFdFqP.mjs → EditViewPage-D5Zhyw_q.mjs} +15 -5
- package/dist/_chunks/EditViewPage-D5Zhyw_q.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-Dk7Eaft4.js → EditViewPage-DzDDKiF5.js} +15 -5
- package/dist/_chunks/EditViewPage-DzDDKiF5.js.map +1 -0
- package/dist/_chunks/{Field-DH2OaqUP.js → Field-CZHNLm_m.js} +77 -43
- package/dist/_chunks/Field-CZHNLm_m.js.map +1 -0
- package/dist/_chunks/{Field-Dv_HTFTa.mjs → Field-FNlyAbcI.mjs} +73 -39
- package/dist/_chunks/Field-FNlyAbcI.mjs.map +1 -0
- package/dist/_chunks/{Form-B_dUDizM.js → Form-DqPHDLuK.js} +16 -8
- package/dist/_chunks/Form-DqPHDLuK.js.map +1 -0
- package/dist/_chunks/{Form-Dy6P4HgH.mjs → Form-Sq_OVNv-.mjs} +16 -8
- package/dist/_chunks/Form-Sq_OVNv-.mjs.map +1 -0
- package/dist/_chunks/{History-BT4w83Oa.js → History-B-ZiOAEg.js} +37 -40
- package/dist/_chunks/History-B-ZiOAEg.js.map +1 -0
- package/dist/_chunks/{History-DrwsD1Vc.mjs → History-DlL3k_OW.mjs} +38 -41
- package/dist/_chunks/History-DlL3k_OW.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js → ListConfigurationPage-Cc0hLAoS.js} +3 -3
- package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js.map → ListConfigurationPage-Cc0hLAoS.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs → ListConfigurationPage-xj3cSF5M.mjs} +3 -3
- package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs.map → ListConfigurationPage-xj3cSF5M.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-5a1vw-OK.mjs → ListViewPage-C9STpcYd.mjs} +36 -13
- package/dist/_chunks/ListViewPage-C9STpcYd.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-BvpwNur7.js → ListViewPage-D48T84aT.js} +40 -17
- package/dist/_chunks/ListViewPage-D48T84aT.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js → NoContentTypePage-BnUmUnXQ.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js.map → NoContentTypePage-BnUmUnXQ.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs → NoContentTypePage-DpV_ouD6.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs.map → NoContentTypePage-DpV_ouD6.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs → NoPermissionsPage-BeDixsE9.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs.map → NoPermissionsPage-BeDixsE9.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js → NoPermissionsPage-z-CpOFfh.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js.map → NoPermissionsPage-z-CpOFfh.js.map} +1 -1
- package/dist/_chunks/{Relations-C7fPyh5P.mjs → Relations-CTiimSAg.mjs} +72 -36
- package/dist/_chunks/Relations-CTiimSAg.mjs.map +1 -0
- package/dist/_chunks/{Relations-CznVF6LS.js → Relations-Cs5vJLAp.js} +71 -35
- package/dist/_chunks/Relations-Cs5vJLAp.js.map +1 -0
- package/dist/_chunks/{en-otD_UBJi.js → en-Bm0D0IWz.js} +12 -11
- package/dist/_chunks/{en-otD_UBJi.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-CbaIuYoB.mjs → en-DKV44jRb.mjs} +12 -11
- package/dist/_chunks/{en-CbaIuYoB.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-C6t7ywEg.js} +12 -2
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-C6t7ywEg.js.map} +1 -1
- package/dist/_chunks/{fr-CD9VFbPM.mjs → fr-DxrTDLl6.mjs} +12 -2
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr-DxrTDLl6.mjs.map} +1 -1
- package/dist/_chunks/{index-BJ6uTqLL.mjs → index-DUZzV11o.mjs} +1901 -1763
- package/dist/_chunks/index-DUZzV11o.mjs.map +1 -0
- package/dist/_chunks/{index-D9UmmBcM.js → index-dFQ_8EM3.js} +1898 -1759
- package/dist/_chunks/index-dFQ_8EM3.js.map +1 -0
- package/dist/_chunks/{layout-kfu5Wtix.js → layout-Bu-ET7w6.js} +5 -4
- package/dist/_chunks/{layout-kfu5Wtix.js.map → layout-Bu-ET7w6.js.map} +1 -1
- package/dist/_chunks/{layout-uomiIGbG.mjs → layout-C-eg7m9Y.mjs} +5 -4
- package/dist/_chunks/{layout-uomiIGbG.mjs.map → layout-C-eg7m9Y.mjs.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-DiDufGSA.mjs → relations-Cj61Oyt2.mjs} +3 -7
- package/dist/_chunks/relations-Cj61Oyt2.mjs.map +1 -0
- package/dist/_chunks/{relations-DKENrxko.js → relations-isLeDaA0.js} +3 -7
- package/dist/_chunks/relations-isLeDaA0.js.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- 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 +11 -11
- package/dist/admin/src/preview/constants.d.ts +1 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/services/documents.d.ts +3 -1
- package/dist/server/index.js +378 -162
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +378 -162
- 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/index.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +2 -3
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- 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/controllers/index.d.ts +2 -0
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/preview.d.ts +13 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
- package/dist/server/src/preview/controllers/validation/preview.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/dist/server/src/preview/routes/index.d.ts +8 -0
- package/dist/server/src/preview/routes/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/preview.d.ts +4 -0
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
- package/dist/server/src/preview/services/index.d.ts +15 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +30 -0
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview.d.ts +12 -0
- package/dist/server/src/preview/services/preview.d.ts.map +1 -0
- package/dist/server/src/preview/utils.d.ts +18 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/dist/shared/contracts/index.d.ts +1 -0
- package/dist/shared/contracts/index.d.ts.map +1 -1
- package/dist/shared/contracts/preview.d.ts +27 -0
- package/dist/shared/contracts/preview.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +4 -0
- package/dist/shared/index.mjs.map +1 -1
- package/package.json +13 -13
- package/dist/_chunks/EditViewPage-DiNFdFqP.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-Dk7Eaft4.js.map +0 -1
- package/dist/_chunks/Field-DH2OaqUP.js.map +0 -1
- package/dist/_chunks/Field-Dv_HTFTa.mjs.map +0 -1
- package/dist/_chunks/Form-B_dUDizM.js.map +0 -1
- package/dist/_chunks/Form-Dy6P4HgH.mjs.map +0 -1
- package/dist/_chunks/History-BT4w83Oa.js.map +0 -1
- package/dist/_chunks/History-DrwsD1Vc.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-5a1vw-OK.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BvpwNur7.js.map +0 -1
- package/dist/_chunks/Relations-C7fPyh5P.mjs.map +0 -1
- package/dist/_chunks/Relations-CznVF6LS.js.map +0 -1
- package/dist/_chunks/index-BJ6uTqLL.mjs.map +0 -1
- package/dist/_chunks/index-D9UmmBcM.js.map +0 -1
- package/dist/_chunks/relations-DKENrxko.js.map +0 -1
- package/dist/_chunks/relations-DiDufGSA.mjs.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
@@ -4,12 +4,13 @@ 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
|
-
const styledComponents = require("styled-components");
|
10
10
|
const yup = require("yup");
|
11
11
|
const pipe = require("lodash/fp/pipe");
|
12
12
|
const dateFns = require("date-fns");
|
13
|
+
const styledComponents = require("styled-components");
|
13
14
|
const qs = require("qs");
|
14
15
|
const toolkit = require("@reduxjs/toolkit");
|
15
16
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
@@ -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) : [];
|
@@ -283,7 +293,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
283
293
|
*/
|
284
294
|
getAllDocuments: builder.query({
|
285
295
|
query: ({ model, params }) => ({
|
286
|
-
url: `/content-manager/collection-types/${model}`,
|
296
|
+
url: `/content-manager/collection-types/${model}${params ? `?${params}` : ""}`,
|
287
297
|
method: "GET",
|
288
298
|
config: {
|
289
299
|
params
|
@@ -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,396 +936,437 @@ 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
|
-
|
925
|
-
|
926
|
-
});
|
927
|
-
return { error: res.error };
|
928
|
-
}
|
929
|
-
toggleNotification({
|
930
|
-
type: "success",
|
931
|
-
message: formatMessage({
|
932
|
-
id: getTranslation("success.record.delete"),
|
933
|
-
defaultMessage: "Deleted document"
|
934
|
-
})
|
935
|
-
});
|
936
|
-
trackUsage("didDeleteEntry", trackerProperty);
|
937
|
-
return res.data;
|
938
|
-
} catch (err) {
|
939
|
-
toggleNotification({
|
940
|
-
type: "danger",
|
941
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
942
|
-
});
|
943
|
-
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
944
|
-
throw err;
|
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([row]);
|
995
|
+
} else {
|
996
|
+
panels[currentPanelIndex].push(row);
|
945
997
|
}
|
946
|
-
}
|
947
|
-
|
948
|
-
);
|
949
|
-
const
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
message: formatAPIError(res.error)
|
963
|
-
});
|
964
|
-
return { error: res.error };
|
998
|
+
}
|
999
|
+
return panels;
|
1000
|
+
}, []);
|
1001
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
1002
|
+
(acc, [uid, configuration]) => {
|
1003
|
+
acc[uid] = {
|
1004
|
+
layout: convertEditLayoutToFieldLayouts(
|
1005
|
+
configuration.layouts.edit,
|
1006
|
+
components[uid].attributes,
|
1007
|
+
configuration.metadatas,
|
1008
|
+
{ configurations: data.components, schemas: components }
|
1009
|
+
),
|
1010
|
+
settings: {
|
1011
|
+
...configuration.settings,
|
1012
|
+
icon: components[uid].info.icon,
|
1013
|
+
displayName: components[uid].info.displayName
|
965
1014
|
}
|
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
|
-
}
|
1015
|
+
};
|
1016
|
+
return acc;
|
984
1017
|
},
|
985
|
-
|
1018
|
+
{}
|
986
1019
|
);
|
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
|
-
}
|
1020
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1021
|
+
(acc, [attribute, metadata]) => {
|
1022
|
+
return {
|
1023
|
+
...acc,
|
1024
|
+
[attribute]: metadata.edit
|
1025
|
+
};
|
1019
1026
|
},
|
1020
|
-
|
1027
|
+
{}
|
1021
1028
|
);
|
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
|
-
}
|
1029
|
+
return {
|
1030
|
+
layout: panelledEditAttributes,
|
1031
|
+
components: componentEditAttributes,
|
1032
|
+
metadatas: editMetadatas,
|
1033
|
+
settings: {
|
1034
|
+
...data.contentType.settings,
|
1035
|
+
displayName: schema?.info.displayName
|
1054
1036
|
},
|
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;
|
1037
|
+
options: {
|
1038
|
+
...schema?.options,
|
1039
|
+
...schema?.pluginOptions,
|
1040
|
+
...data.contentType.options
|
1041
|
+
}
|
1042
|
+
};
|
1043
|
+
};
|
1044
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1045
|
+
return rows.map(
|
1046
|
+
(row) => row.map((field) => {
|
1047
|
+
const attribute = attributes[field.name];
|
1048
|
+
if (!attribute) {
|
1049
|
+
return null;
|
1084
1050
|
}
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1051
|
+
const { edit: metadata } = metadatas[field.name];
|
1052
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1053
|
+
return {
|
1054
|
+
attribute,
|
1055
|
+
disabled: !metadata.editable,
|
1056
|
+
hint: metadata.description,
|
1057
|
+
label: metadata.label ?? "",
|
1058
|
+
name: field.name,
|
1059
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1060
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1061
|
+
schemas,
|
1062
|
+
components: components?.schemas ?? {}
|
1063
|
+
}),
|
1064
|
+
placeholder: metadata.placeholder ?? "",
|
1065
|
+
required: attribute.required ?? false,
|
1066
|
+
size: field.size,
|
1067
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1068
|
+
visible: metadata.visible ?? true,
|
1069
|
+
type: attribute.type
|
1070
|
+
};
|
1071
|
+
}).filter((field) => field !== null)
|
1093
1072
|
);
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1073
|
+
};
|
1074
|
+
const formatListLayout = (data, {
|
1075
|
+
schemas,
|
1076
|
+
schema,
|
1077
|
+
components
|
1078
|
+
}) => {
|
1079
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1080
|
+
(acc, [attribute, metadata]) => {
|
1081
|
+
return {
|
1082
|
+
...acc,
|
1083
|
+
[attribute]: metadata.list
|
1084
|
+
};
|
1085
|
+
},
|
1086
|
+
{}
|
1087
|
+
);
|
1088
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1089
|
+
data.contentType.layouts.list,
|
1090
|
+
schema?.attributes,
|
1091
|
+
listMetadatas,
|
1092
|
+
{ configurations: data.components, schemas: components },
|
1093
|
+
schemas
|
1094
|
+
);
|
1095
|
+
return {
|
1096
|
+
layout: listAttributes,
|
1097
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1098
|
+
metadatas: listMetadatas,
|
1099
|
+
options: {
|
1100
|
+
...schema?.options,
|
1101
|
+
...schema?.pluginOptions,
|
1102
|
+
...data.contentType.options
|
1103
|
+
}
|
1104
|
+
};
|
1105
|
+
};
|
1106
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1107
|
+
return columns.map((name) => {
|
1108
|
+
const attribute = attributes[name];
|
1109
|
+
if (!attribute) {
|
1110
|
+
return null;
|
1111
|
+
}
|
1112
|
+
const metadata = metadatas[name];
|
1113
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1114
|
+
return {
|
1115
|
+
attribute,
|
1116
|
+
label: metadata.label ?? "",
|
1117
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1118
|
+
schemas,
|
1119
|
+
components: components?.schemas ?? {}
|
1120
|
+
}),
|
1121
|
+
name,
|
1122
|
+
searchable: metadata.searchable ?? true,
|
1123
|
+
sortable: metadata.sortable ?? true
|
1124
|
+
};
|
1125
|
+
}).filter((field) => field !== null);
|
1126
|
+
};
|
1127
|
+
const useDocument = (args, opts) => {
|
1128
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
1129
|
+
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
1130
|
+
const {
|
1131
|
+
currentData: data,
|
1132
|
+
isLoading: isLoadingDocument,
|
1133
|
+
isFetching: isFetchingDocument,
|
1134
|
+
error
|
1135
|
+
} = useGetDocumentQuery(args, {
|
1136
|
+
...opts,
|
1137
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1138
|
+
});
|
1139
|
+
const {
|
1140
|
+
components,
|
1141
|
+
schema,
|
1142
|
+
schemas,
|
1143
|
+
isLoading: isLoadingSchema
|
1144
|
+
} = useContentTypeSchema(args.model);
|
1145
|
+
React__namespace.useEffect(() => {
|
1146
|
+
if (error) {
|
1147
|
+
toggleNotification({
|
1148
|
+
type: "danger",
|
1149
|
+
message: formatAPIError(error)
|
1150
|
+
});
|
1151
|
+
}
|
1152
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1153
|
+
const validationSchema = React__namespace.useMemo(() => {
|
1154
|
+
if (!schema) {
|
1155
|
+
return null;
|
1156
|
+
}
|
1157
|
+
return createYupSchema(schema.attributes, components);
|
1158
|
+
}, [schema, components]);
|
1159
|
+
const validate = React__namespace.useCallback(
|
1160
|
+
(document) => {
|
1161
|
+
if (!validationSchema) {
|
1162
|
+
throw new Error(
|
1163
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1164
|
+
);
|
1165
|
+
}
|
1166
|
+
try {
|
1167
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1168
|
+
return null;
|
1169
|
+
} catch (error2) {
|
1170
|
+
if (error2 instanceof yup.ValidationError) {
|
1171
|
+
return strapiAdmin.getYupValidationErrors(error2);
|
1110
1172
|
}
|
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;
|
1173
|
+
throw error2;
|
1127
1174
|
}
|
1128
1175
|
},
|
1129
|
-
[
|
1176
|
+
[validationSchema]
|
1130
1177
|
);
|
1131
|
-
const
|
1132
|
-
const
|
1133
|
-
|
1178
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1179
|
+
const hasError = !!error;
|
1180
|
+
return {
|
1181
|
+
components,
|
1182
|
+
document: data?.data,
|
1183
|
+
meta: data?.meta,
|
1184
|
+
isLoading,
|
1185
|
+
hasError,
|
1186
|
+
schema,
|
1187
|
+
schemas,
|
1188
|
+
validate
|
1189
|
+
};
|
1190
|
+
};
|
1191
|
+
const useDoc = () => {
|
1192
|
+
const { id, slug, collectionType, origin } = reactRouterDom.useParams();
|
1193
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
1194
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1195
|
+
if (!collectionType) {
|
1196
|
+
throw new Error("Could not find collectionType in url params");
|
1197
|
+
}
|
1198
|
+
if (!slug) {
|
1199
|
+
throw new Error("Could not find model in url params");
|
1200
|
+
}
|
1201
|
+
const document = useDocument(
|
1202
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1203
|
+
{
|
1204
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1205
|
+
}
|
1206
|
+
);
|
1207
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1208
|
+
return {
|
1209
|
+
collectionType,
|
1210
|
+
model: slug,
|
1211
|
+
id: returnId,
|
1212
|
+
...document
|
1213
|
+
};
|
1214
|
+
};
|
1215
|
+
const useContentManagerContext = () => {
|
1216
|
+
const {
|
1217
|
+
collectionType,
|
1218
|
+
model,
|
1219
|
+
id,
|
1220
|
+
components,
|
1221
|
+
isLoading: isLoadingDoc,
|
1222
|
+
schema,
|
1223
|
+
schemas
|
1224
|
+
} = useDoc();
|
1225
|
+
const layout = useDocumentLayout(model);
|
1226
|
+
const form = strapiAdmin.useForm("useContentManagerContext", (state) => state);
|
1227
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1228
|
+
const slug = model;
|
1229
|
+
const isCreatingEntry = id === "create";
|
1230
|
+
useContentTypeSchema();
|
1231
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1232
|
+
const error = layout.error;
|
1233
|
+
return {
|
1234
|
+
error,
|
1235
|
+
isLoading,
|
1236
|
+
// Base metadata
|
1237
|
+
model,
|
1238
|
+
collectionType,
|
1239
|
+
id,
|
1240
|
+
slug,
|
1241
|
+
isCreatingEntry,
|
1242
|
+
isSingleType,
|
1243
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1244
|
+
// All schema infos
|
1245
|
+
components,
|
1246
|
+
contentType: schema,
|
1247
|
+
contentTypes: schemas,
|
1248
|
+
// Form state
|
1249
|
+
form,
|
1250
|
+
// layout infos
|
1251
|
+
layout
|
1252
|
+
};
|
1253
|
+
};
|
1254
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
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:
|
1222
|
-
defaultMessage: "
|
1368
|
+
id: "content-manager.success.record.discard",
|
1369
|
+
defaultMessage: "Changes discarded"
|
1223
1370
|
})
|
1224
1371
|
});
|
1225
1372
|
return res.data;
|
@@ -1228,11 +1375,226 @@ const useDocumentActions = () => {
|
|
1228
1375
|
type: "danger",
|
1229
1376
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1230
1377
|
});
|
1231
|
-
trackUsage("didNotCreateEntry", { error: err, ...trackerProperty });
|
1232
1378
|
throw err;
|
1233
1379
|
}
|
1234
1380
|
},
|
1235
|
-
[
|
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"),
|
1583
|
+
defaultMessage: "Saved document"
|
1584
|
+
})
|
1585
|
+
});
|
1586
|
+
setCurrentStep("contentManager.success");
|
1587
|
+
return res.data;
|
1588
|
+
} catch (err) {
|
1589
|
+
toggleNotification({
|
1590
|
+
type: "danger",
|
1591
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1592
|
+
});
|
1593
|
+
trackUsage("didNotCreateEntry", { error: err, ...trackerProperty });
|
1594
|
+
throw err;
|
1595
|
+
}
|
1596
|
+
},
|
1597
|
+
[createDocument, formatAPIError, formatMessage, toggleNotification, trackUsage]
|
1236
1598
|
);
|
1237
1599
|
const [autoCloneDocument] = useAutoCloneDocumentMutation();
|
1238
1600
|
const autoClone = React__namespace.useCallback(
|
@@ -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-B-ZiOAEg.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-DzDDKiF5.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-D48T84aT.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-Cc0hLAoS.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-Z_VzHVH4.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-D2_cVxXK.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-z-CpOFfh.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-BnUmUnXQ.js")).then((mod) => ({ default: mod.NoContentType }))
|
1365
1727
|
);
|
1366
1728
|
const CollectionTypePages = () => {
|
1367
1729
|
const { collectionType } = reactRouterDom.useParams();
|
@@ -1418,1057 +1780,746 @@ const DocumentActions = ({ actions: actions2 }) => {
|
|
1418
1780
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
1419
1781
|
return positions.includes("panel");
|
1420
1782
|
});
|
1421
|
-
if (!primaryAction) {
|
1422
|
-
return null;
|
1423
|
-
}
|
1424
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
|
1425
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
1426
|
-
/* @__PURE__ */ jsxRuntime.jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
|
1427
|
-
restActions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
1428
|
-
DocumentActionsMenu,
|
1429
|
-
{
|
1430
|
-
actions: restActions,
|
1431
|
-
label: formatMessage({
|
1432
|
-
id: "content-manager.containers.edit.panels.default.more-actions",
|
1433
|
-
defaultMessage: "More document actions"
|
1434
|
-
})
|
1435
|
-
}
|
1436
|
-
) : null
|
1437
|
-
] }),
|
1438
|
-
secondaryAction ? /* @__PURE__ */ jsxRuntime.jsx(
|
1439
|
-
DocumentActionButton,
|
1440
|
-
{
|
1441
|
-
...secondaryAction,
|
1442
|
-
variant: secondaryAction.variant || "secondary"
|
1443
|
-
}
|
1444
|
-
) : null
|
1445
|
-
] });
|
1446
|
-
};
|
1447
|
-
const DocumentActionButton = (action) => {
|
1448
|
-
const [dialogId, setDialogId] = React__namespace.useState(null);
|
1449
|
-
const { toggleNotification } = strapiAdmin.useNotification();
|
1450
|
-
const handleClick = (action2) => async (e) => {
|
1451
|
-
const { onClick = () => false, dialog, id } = action2;
|
1452
|
-
const muteDialog = await onClick(e);
|
1453
|
-
if (dialog && !muteDialog) {
|
1454
|
-
switch (dialog.type) {
|
1455
|
-
case "notification":
|
1456
|
-
toggleNotification({
|
1457
|
-
title: dialog.title,
|
1458
|
-
message: dialog.content,
|
1459
|
-
type: dialog.status,
|
1460
|
-
timeout: dialog.timeout,
|
1461
|
-
onClose: dialog.onClose
|
1462
|
-
});
|
1463
|
-
break;
|
1464
|
-
case "dialog":
|
1465
|
-
case "modal":
|
1466
|
-
e.preventDefault();
|
1467
|
-
setDialogId(id);
|
1468
|
-
}
|
1469
|
-
}
|
1470
|
-
};
|
1471
|
-
const handleClose = () => {
|
1472
|
-
setDialogId(null);
|
1473
|
-
};
|
1474
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
1475
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
1476
|
-
designSystem.Button,
|
1477
|
-
{
|
1478
|
-
flex: "auto",
|
1479
|
-
startIcon: action.icon,
|
1480
|
-
disabled: action.disabled,
|
1481
|
-
onClick: handleClick(action),
|
1482
|
-
justifyContent: "center",
|
1483
|
-
variant: action.variant || "default",
|
1484
|
-
paddingTop: "7px",
|
1485
|
-
paddingBottom: "7px",
|
1486
|
-
children: action.label
|
1487
|
-
}
|
1488
|
-
),
|
1489
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1490
|
-
DocumentActionConfirmDialog,
|
1491
|
-
{
|
1492
|
-
...action.dialog,
|
1493
|
-
variant: action.dialog?.variant ?? action.variant,
|
1494
|
-
isOpen: dialogId === action.id,
|
1495
|
-
onClose: handleClose
|
1496
|
-
}
|
1497
|
-
) : null,
|
1498
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1499
|
-
DocumentActionModal,
|
1500
|
-
{
|
1501
|
-
...action.dialog,
|
1502
|
-
onModalClose: handleClose,
|
1503
|
-
isOpen: dialogId === action.id
|
1504
|
-
}
|
1505
|
-
) : null
|
1506
|
-
] });
|
1507
|
-
};
|
1508
|
-
const DocumentActionsMenu = ({
|
1509
|
-
actions: actions2,
|
1510
|
-
children,
|
1511
|
-
label,
|
1512
|
-
variant = "tertiary"
|
1513
|
-
}) => {
|
1514
|
-
const [isOpen, setIsOpen] = React__namespace.useState(false);
|
1515
|
-
const [dialogId, setDialogId] = React__namespace.useState(null);
|
1516
|
-
const { formatMessage } = reactIntl.useIntl();
|
1517
|
-
const { toggleNotification } = strapiAdmin.useNotification();
|
1518
|
-
const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
|
1519
|
-
const handleClick = (action) => async (e) => {
|
1520
|
-
const { onClick = () => false, dialog, id } = action;
|
1521
|
-
const muteDialog = await onClick(e);
|
1522
|
-
if (dialog && !muteDialog) {
|
1523
|
-
switch (dialog.type) {
|
1524
|
-
case "notification":
|
1525
|
-
toggleNotification({
|
1526
|
-
title: dialog.title,
|
1527
|
-
message: dialog.content,
|
1528
|
-
type: dialog.status,
|
1529
|
-
timeout: dialog.timeout,
|
1530
|
-
onClose: dialog.onClose
|
1531
|
-
});
|
1532
|
-
break;
|
1533
|
-
case "dialog":
|
1534
|
-
case "modal":
|
1535
|
-
setDialogId(id);
|
1536
|
-
}
|
1537
|
-
}
|
1538
|
-
};
|
1539
|
-
const handleClose = () => {
|
1540
|
-
setDialogId(null);
|
1541
|
-
setIsOpen(false);
|
1542
|
-
};
|
1543
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
|
1544
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
1545
|
-
designSystem.Menu.Trigger,
|
1546
|
-
{
|
1547
|
-
disabled: isDisabled,
|
1548
|
-
size: "S",
|
1549
|
-
endIcon: null,
|
1550
|
-
paddingTop: "4px",
|
1551
|
-
paddingLeft: "7px",
|
1552
|
-
paddingRight: "7px",
|
1553
|
-
variant,
|
1554
|
-
children: [
|
1555
|
-
/* @__PURE__ */ jsxRuntime.jsx(Icons.More, { "aria-hidden": true, focusable: false }),
|
1556
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: label || formatMessage({
|
1557
|
-
id: "content-manager.containers.edit.panels.default.more-actions",
|
1558
|
-
defaultMessage: "More document actions"
|
1559
|
-
}) })
|
1560
|
-
]
|
1561
|
-
}
|
1562
|
-
),
|
1563
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, { top: "4px", maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1564
|
-
actions2.map((action) => {
|
1565
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
1566
|
-
designSystem.Menu.Item,
|
1567
|
-
{
|
1568
|
-
disabled: action.disabled,
|
1569
|
-
onSelect: handleClick(action),
|
1570
|
-
display: "block",
|
1571
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", gap: 4, children: [
|
1572
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
1573
|
-
designSystem.Flex,
|
1574
|
-
{
|
1575
|
-
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1576
|
-
gap: 2,
|
1577
|
-
tag: "span",
|
1578
|
-
children: [
|
1579
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
1580
|
-
designSystem.Flex,
|
1581
|
-
{
|
1582
|
-
tag: "span",
|
1583
|
-
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1584
|
-
children: action.icon
|
1585
|
-
}
|
1586
|
-
),
|
1587
|
-
action.label
|
1588
|
-
]
|
1589
|
-
}
|
1590
|
-
),
|
1591
|
-
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsxRuntime.jsx(
|
1592
|
-
designSystem.Flex,
|
1593
|
-
{
|
1594
|
-
alignItems: "center",
|
1595
|
-
background: "alternative100",
|
1596
|
-
borderStyle: "solid",
|
1597
|
-
borderColor: "alternative200",
|
1598
|
-
borderWidth: "1px",
|
1599
|
-
height: 5,
|
1600
|
-
paddingLeft: 2,
|
1601
|
-
paddingRight: 2,
|
1602
|
-
hasRadius: true,
|
1603
|
-
color: "alternative600",
|
1604
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
|
1605
|
-
}
|
1606
|
-
)
|
1607
|
-
] })
|
1608
|
-
},
|
1609
|
-
action.id
|
1610
|
-
);
|
1611
|
-
}),
|
1612
|
-
children
|
1613
|
-
] }),
|
1614
|
-
actions2.map((action) => {
|
1615
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
|
1616
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1617
|
-
DocumentActionConfirmDialog,
|
1618
|
-
{
|
1619
|
-
...action.dialog,
|
1620
|
-
variant: action.variant,
|
1621
|
-
isOpen: dialogId === action.id,
|
1622
|
-
onClose: handleClose
|
1623
|
-
}
|
1624
|
-
) : null,
|
1625
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1626
|
-
DocumentActionModal,
|
1627
|
-
{
|
1628
|
-
...action.dialog,
|
1629
|
-
onModalClose: handleClose,
|
1630
|
-
isOpen: dialogId === action.id
|
1631
|
-
}
|
1632
|
-
) : null
|
1633
|
-
] }, action.id);
|
1634
|
-
})
|
1635
|
-
] });
|
1636
|
-
};
|
1637
|
-
const convertActionVariantToColor = (variant = "secondary") => {
|
1638
|
-
switch (variant) {
|
1639
|
-
case "danger":
|
1640
|
-
return "danger600";
|
1641
|
-
case "secondary":
|
1642
|
-
return void 0;
|
1643
|
-
case "success":
|
1644
|
-
return "success600";
|
1645
|
-
default:
|
1646
|
-
return "primary600";
|
1647
|
-
}
|
1648
|
-
};
|
1649
|
-
const convertActionVariantToIconColor = (variant = "secondary") => {
|
1650
|
-
switch (variant) {
|
1651
|
-
case "danger":
|
1652
|
-
return "danger600";
|
1653
|
-
case "secondary":
|
1654
|
-
return "neutral500";
|
1655
|
-
case "success":
|
1656
|
-
return "success600";
|
1657
|
-
default:
|
1658
|
-
return "primary600";
|
1659
|
-
}
|
1660
|
-
};
|
1661
|
-
const DocumentActionConfirmDialog = ({
|
1662
|
-
onClose,
|
1663
|
-
onCancel,
|
1664
|
-
onConfirm,
|
1665
|
-
title,
|
1666
|
-
content,
|
1667
|
-
isOpen,
|
1668
|
-
variant = "secondary"
|
1669
|
-
}) => {
|
1670
|
-
const { formatMessage } = reactIntl.useIntl();
|
1671
|
-
const handleClose = async () => {
|
1672
|
-
if (onCancel) {
|
1673
|
-
await onCancel();
|
1674
|
-
}
|
1675
|
-
onClose();
|
1676
|
-
};
|
1677
|
-
const handleConfirm = async () => {
|
1678
|
-
if (onConfirm) {
|
1679
|
-
await onConfirm();
|
1680
|
-
}
|
1681
|
-
onClose();
|
1682
|
-
};
|
1683
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
1684
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
|
1685
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: content }),
|
1686
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
|
1687
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({
|
1688
|
-
id: "app.components.Button.cancel",
|
1689
|
-
defaultMessage: "Cancel"
|
1690
|
-
}) }) }),
|
1691
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleConfirm, variant, children: formatMessage({
|
1692
|
-
id: "app.components.Button.confirm",
|
1693
|
-
defaultMessage: "Confirm"
|
1694
|
-
}) })
|
1695
|
-
] })
|
1696
|
-
] }) });
|
1697
|
-
};
|
1698
|
-
const DocumentActionModal = ({
|
1699
|
-
isOpen,
|
1700
|
-
title,
|
1701
|
-
onClose,
|
1702
|
-
footer: Footer,
|
1703
|
-
content: Content,
|
1704
|
-
onModalClose
|
1705
|
-
}) => {
|
1706
|
-
const handleClose = () => {
|
1707
|
-
if (onClose) {
|
1708
|
-
onClose();
|
1709
|
-
}
|
1710
|
-
onModalClose();
|
1711
|
-
};
|
1712
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
|
1713
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
|
1714
|
-
typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: Content }),
|
1715
|
-
typeof Footer === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Footer, { onClose: handleClose }) : Footer
|
1716
|
-
] }) });
|
1717
|
-
};
|
1718
|
-
const PublishAction$1 = ({
|
1719
|
-
activeTab,
|
1720
|
-
documentId,
|
1721
|
-
model,
|
1722
|
-
collectionType,
|
1723
|
-
meta,
|
1724
|
-
document
|
1725
|
-
}) => {
|
1726
|
-
const { schema } = useDoc();
|
1727
|
-
const navigate = reactRouterDom.useNavigate();
|
1728
|
-
const { toggleNotification } = strapiAdmin.useNotification();
|
1729
|
-
const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
|
1730
|
-
const isListView = reactRouterDom.useMatch(LIST_PATH) !== null;
|
1731
|
-
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
1732
|
-
const { formatMessage } = reactIntl.useIntl();
|
1733
|
-
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1734
|
-
const { publish } = useDocumentActions();
|
1735
|
-
const [
|
1736
|
-
countDraftRelations,
|
1737
|
-
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
1738
|
-
] = useLazyGetDraftRelationCountQuery();
|
1739
|
-
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React__namespace.useState(0);
|
1740
|
-
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React__namespace.useState(0);
|
1741
|
-
const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
|
1742
|
-
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
1743
|
-
const modified = strapiAdmin.useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
1744
|
-
const setSubmitting = strapiAdmin.useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
1745
|
-
const isSubmitting = strapiAdmin.useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
1746
|
-
const validate = strapiAdmin.useForm("PublishAction", (state) => state.validate);
|
1747
|
-
const setErrors = strapiAdmin.useForm("PublishAction", (state) => state.setErrors);
|
1748
|
-
const formValues = strapiAdmin.useForm("PublishAction", ({ values }) => values);
|
1749
|
-
React__namespace.useEffect(() => {
|
1750
|
-
if (isErrorDraftRelations) {
|
1751
|
-
toggleNotification({
|
1752
|
-
type: "danger",
|
1753
|
-
message: formatMessage({
|
1754
|
-
id: getTranslation("error.records.fetch-draft-relatons"),
|
1755
|
-
defaultMessage: "An error occurred while fetching draft relations on this document."
|
1756
|
-
})
|
1757
|
-
});
|
1758
|
-
}
|
1759
|
-
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
1760
|
-
React__namespace.useEffect(() => {
|
1761
|
-
const localDraftRelations = /* @__PURE__ */ new Set();
|
1762
|
-
const extractDraftRelations = (data) => {
|
1763
|
-
const relations = data.connect || [];
|
1764
|
-
relations.forEach((relation) => {
|
1765
|
-
if (relation.status === "draft") {
|
1766
|
-
localDraftRelations.add(relation.id);
|
1767
|
-
}
|
1768
|
-
});
|
1769
|
-
};
|
1770
|
-
const traverseAndExtract = (data) => {
|
1771
|
-
Object.entries(data).forEach(([key, value]) => {
|
1772
|
-
if (key === "connect" && Array.isArray(value)) {
|
1773
|
-
extractDraftRelations({ connect: value });
|
1774
|
-
} else if (typeof value === "object" && value !== null) {
|
1775
|
-
traverseAndExtract(value);
|
1776
|
-
}
|
1777
|
-
});
|
1778
|
-
};
|
1779
|
-
if (!documentId || modified) {
|
1780
|
-
traverseAndExtract(formValues);
|
1781
|
-
setLocalCountOfDraftRelations(localDraftRelations.size);
|
1782
|
-
}
|
1783
|
-
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
1784
|
-
React__namespace.useEffect(() => {
|
1785
|
-
if (documentId && !isListView) {
|
1786
|
-
const fetchDraftRelationsCount = async () => {
|
1787
|
-
const { data, error } = await countDraftRelations({
|
1788
|
-
collectionType,
|
1789
|
-
model,
|
1790
|
-
documentId,
|
1791
|
-
params
|
1792
|
-
});
|
1793
|
-
if (error) {
|
1794
|
-
throw error;
|
1795
|
-
}
|
1796
|
-
if (data) {
|
1797
|
-
setServerCountOfDraftRelations(data.data);
|
1798
|
-
}
|
1799
|
-
};
|
1800
|
-
fetchDraftRelationsCount();
|
1801
|
-
}
|
1802
|
-
}, [isListView, documentId, countDraftRelations, collectionType, model, params]);
|
1803
|
-
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1804
|
-
if (!schema?.options?.draftAndPublish) {
|
1783
|
+
if (!primaryAction) {
|
1805
1784
|
return null;
|
1806
1785
|
}
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
toggleNotification({
|
1813
|
-
type: "danger",
|
1814
|
-
message: formatMessage({
|
1815
|
-
id: "content-manager.validation.error",
|
1816
|
-
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
1817
|
-
})
|
1818
|
-
});
|
1819
|
-
return;
|
1820
|
-
}
|
1821
|
-
const res = await publish(
|
1822
|
-
{
|
1823
|
-
collectionType,
|
1824
|
-
model,
|
1825
|
-
documentId,
|
1826
|
-
params
|
1827
|
-
},
|
1828
|
-
formValues
|
1829
|
-
);
|
1830
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1831
|
-
navigate({
|
1832
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1833
|
-
search: rawQuery
|
1834
|
-
});
|
1835
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1836
|
-
setErrors(formatValidationErrors(res.error));
|
1837
|
-
}
|
1838
|
-
} finally {
|
1839
|
-
setSubmitting(false);
|
1840
|
-
}
|
1841
|
-
};
|
1842
|
-
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
1843
|
-
const enableDraftRelationsCount = false;
|
1844
|
-
const hasDraftRelations = enableDraftRelationsCount;
|
1845
|
-
return {
|
1846
|
-
/**
|
1847
|
-
* Disabled when:
|
1848
|
-
* - currently if you're cloning a document we don't support publish & clone at the same time.
|
1849
|
-
* - the form is submitting
|
1850
|
-
* - the active tab is the published tab
|
1851
|
-
* - the document is already published & not modified
|
1852
|
-
* - the document is being created & not modified
|
1853
|
-
* - the user doesn't have the permission to publish
|
1854
|
-
*/
|
1855
|
-
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1856
|
-
label: formatMessage({
|
1857
|
-
id: "app.utils.publish",
|
1858
|
-
defaultMessage: "Publish"
|
1859
|
-
}),
|
1860
|
-
onClick: async () => {
|
1861
|
-
await performPublish();
|
1862
|
-
},
|
1863
|
-
dialog: hasDraftRelations ? {
|
1864
|
-
type: "dialog",
|
1865
|
-
variant: "danger",
|
1866
|
-
footer: null,
|
1867
|
-
title: formatMessage({
|
1868
|
-
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
1869
|
-
defaultMessage: "Confirmation"
|
1870
|
-
}),
|
1871
|
-
content: formatMessage(
|
1872
|
-
{
|
1873
|
-
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
1874
|
-
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
1875
|
-
},
|
1786
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
|
1787
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
1788
|
+
/* @__PURE__ */ jsxRuntime.jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
|
1789
|
+
restActions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
|
1790
|
+
DocumentActionsMenu,
|
1876
1791
|
{
|
1877
|
-
|
1792
|
+
actions: restActions,
|
1793
|
+
label: formatMessage({
|
1794
|
+
id: "content-manager.containers.edit.panels.default.more-actions",
|
1795
|
+
defaultMessage: "More document actions"
|
1796
|
+
})
|
1878
1797
|
}
|
1879
|
-
)
|
1880
|
-
|
1881
|
-
|
1798
|
+
) : null
|
1799
|
+
] }),
|
1800
|
+
secondaryAction ? /* @__PURE__ */ jsxRuntime.jsx(
|
1801
|
+
DocumentActionButton,
|
1802
|
+
{
|
1803
|
+
...secondaryAction,
|
1804
|
+
variant: secondaryAction.variant || "secondary"
|
1882
1805
|
}
|
1883
|
-
|
1884
|
-
};
|
1806
|
+
) : null
|
1807
|
+
] });
|
1885
1808
|
};
|
1886
|
-
|
1887
|
-
const
|
1888
|
-
activeTab,
|
1889
|
-
documentId,
|
1890
|
-
model,
|
1891
|
-
collectionType
|
1892
|
-
}) => {
|
1893
|
-
const navigate = reactRouterDom.useNavigate();
|
1809
|
+
const DocumentActionButton = (action) => {
|
1810
|
+
const [dialogId, setDialogId] = React__namespace.useState(null);
|
1894
1811
|
const { toggleNotification } = strapiAdmin.useNotification();
|
1895
|
-
const
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
1914
|
-
* - the active tab is the published tab
|
1915
|
-
*/
|
1916
|
-
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
1917
|
-
label: formatMessage({
|
1918
|
-
id: "content-manager.containers.Edit.save",
|
1919
|
-
defaultMessage: "Save"
|
1920
|
-
}),
|
1921
|
-
onClick: async () => {
|
1922
|
-
setSubmitting(true);
|
1923
|
-
try {
|
1924
|
-
if (activeTab !== "draft") {
|
1925
|
-
const { errors } = await validate();
|
1926
|
-
if (errors) {
|
1927
|
-
toggleNotification({
|
1928
|
-
type: "danger",
|
1929
|
-
message: formatMessage({
|
1930
|
-
id: "content-manager.validation.error",
|
1931
|
-
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
1932
|
-
})
|
1933
|
-
});
|
1934
|
-
return;
|
1935
|
-
}
|
1936
|
-
}
|
1937
|
-
if (isCloning) {
|
1938
|
-
const res = await clone(
|
1939
|
-
{
|
1940
|
-
model,
|
1941
|
-
documentId: cloneMatch.params.origin,
|
1942
|
-
params
|
1943
|
-
},
|
1944
|
-
document
|
1945
|
-
);
|
1946
|
-
if ("data" in res) {
|
1947
|
-
navigate(
|
1948
|
-
{
|
1949
|
-
pathname: `../${res.data.documentId}`,
|
1950
|
-
search: rawQuery
|
1951
|
-
},
|
1952
|
-
{ relative: "path" }
|
1953
|
-
);
|
1954
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1955
|
-
setErrors(formatValidationErrors(res.error));
|
1956
|
-
}
|
1957
|
-
} else if (documentId || collectionType === SINGLE_TYPES) {
|
1958
|
-
const res = await update(
|
1959
|
-
{
|
1960
|
-
collectionType,
|
1961
|
-
model,
|
1962
|
-
documentId,
|
1963
|
-
params
|
1964
|
-
},
|
1965
|
-
document
|
1966
|
-
);
|
1967
|
-
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1968
|
-
setErrors(formatValidationErrors(res.error));
|
1969
|
-
} else {
|
1970
|
-
resetForm();
|
1971
|
-
}
|
1972
|
-
} else {
|
1973
|
-
const res = await create(
|
1974
|
-
{
|
1975
|
-
model,
|
1976
|
-
params
|
1977
|
-
},
|
1978
|
-
document
|
1979
|
-
);
|
1980
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1981
|
-
navigate(
|
1982
|
-
{
|
1983
|
-
pathname: `../${res.data.documentId}`,
|
1984
|
-
search: rawQuery
|
1985
|
-
},
|
1986
|
-
{ replace: true, relative: "path" }
|
1987
|
-
);
|
1988
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1989
|
-
setErrors(formatValidationErrors(res.error));
|
1990
|
-
}
|
1991
|
-
}
|
1992
|
-
} finally {
|
1993
|
-
setSubmitting(false);
|
1812
|
+
const handleClick = (action2) => async (e) => {
|
1813
|
+
const { onClick = () => false, dialog, id } = action2;
|
1814
|
+
const muteDialog = await onClick(e);
|
1815
|
+
if (dialog && !muteDialog) {
|
1816
|
+
switch (dialog.type) {
|
1817
|
+
case "notification":
|
1818
|
+
toggleNotification({
|
1819
|
+
title: dialog.title,
|
1820
|
+
message: dialog.content,
|
1821
|
+
type: dialog.status,
|
1822
|
+
timeout: dialog.timeout,
|
1823
|
+
onClose: dialog.onClose
|
1824
|
+
});
|
1825
|
+
break;
|
1826
|
+
case "dialog":
|
1827
|
+
case "modal":
|
1828
|
+
e.preventDefault();
|
1829
|
+
setDialogId(id);
|
1994
1830
|
}
|
1995
1831
|
}
|
1996
1832
|
};
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
1833
|
+
const handleClose = () => {
|
1834
|
+
setDialogId(null);
|
1835
|
+
};
|
1836
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
1837
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
1838
|
+
designSystem.Button,
|
1839
|
+
{
|
1840
|
+
flex: "auto",
|
1841
|
+
startIcon: action.icon,
|
1842
|
+
disabled: action.disabled,
|
1843
|
+
onClick: handleClick(action),
|
1844
|
+
justifyContent: "center",
|
1845
|
+
variant: action.variant || "default",
|
1846
|
+
paddingTop: "7px",
|
1847
|
+
paddingBottom: "7px",
|
1848
|
+
children: action.label
|
1849
|
+
}
|
1850
|
+
),
|
1851
|
+
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1852
|
+
DocumentActionConfirmDialog,
|
1853
|
+
{
|
1854
|
+
...action.dialog,
|
1855
|
+
variant: action.dialog?.variant ?? action.variant,
|
1856
|
+
isOpen: dialogId === action.id,
|
1857
|
+
onClose: handleClose
|
1858
|
+
}
|
1859
|
+
) : null,
|
1860
|
+
action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1861
|
+
DocumentActionModal,
|
1862
|
+
{
|
1863
|
+
...action.dialog,
|
1864
|
+
onModalClose: handleClose,
|
1865
|
+
isOpen: dialogId === action.id
|
1866
|
+
}
|
1867
|
+
) : null
|
1868
|
+
] });
|
1869
|
+
};
|
1870
|
+
const DocumentActionsMenu = ({
|
1871
|
+
actions: actions2,
|
1872
|
+
children,
|
1873
|
+
label,
|
1874
|
+
variant = "tertiary"
|
2009
1875
|
}) => {
|
1876
|
+
const [isOpen, setIsOpen] = React__namespace.useState(false);
|
1877
|
+
const [dialogId, setDialogId] = React__namespace.useState(null);
|
2010
1878
|
const { formatMessage } = reactIntl.useIntl();
|
2011
|
-
const { schema } = useDoc();
|
2012
|
-
const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
2013
|
-
const { unpublish } = useDocumentActions();
|
2014
|
-
const [{ query }] = strapiAdmin.useQueryParams();
|
2015
|
-
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
2016
1879
|
const { toggleNotification } = strapiAdmin.useNotification();
|
2017
|
-
const
|
2018
|
-
const
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
}
|
2025
|
-
return {
|
2026
|
-
disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
|
2027
|
-
label: formatMessage({
|
2028
|
-
id: "app.utils.unpublish",
|
2029
|
-
defaultMessage: "Unpublish"
|
2030
|
-
}),
|
2031
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(StyledCrossCircle, {}),
|
2032
|
-
onClick: async () => {
|
2033
|
-
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
2034
|
-
if (!documentId) {
|
2035
|
-
console.error(
|
2036
|
-
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2037
|
-
);
|
1880
|
+
const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
|
1881
|
+
const handleClick = (action) => async (e) => {
|
1882
|
+
const { onClick = () => false, dialog, id } = action;
|
1883
|
+
const muteDialog = await onClick(e);
|
1884
|
+
if (dialog && !muteDialog) {
|
1885
|
+
switch (dialog.type) {
|
1886
|
+
case "notification":
|
2038
1887
|
toggleNotification({
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
1888
|
+
title: dialog.title,
|
1889
|
+
message: dialog.content,
|
1890
|
+
type: dialog.status,
|
1891
|
+
timeout: dialog.timeout,
|
1892
|
+
onClose: dialog.onClose
|
2044
1893
|
});
|
2045
|
-
|
2046
|
-
|
1894
|
+
break;
|
1895
|
+
case "dialog":
|
1896
|
+
case "modal":
|
1897
|
+
setDialogId(id);
|
2047
1898
|
}
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
1899
|
+
}
|
1900
|
+
};
|
1901
|
+
const handleClose = () => {
|
1902
|
+
setDialogId(null);
|
1903
|
+
setIsOpen(false);
|
1904
|
+
};
|
1905
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
|
1906
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
1907
|
+
designSystem.Menu.Trigger,
|
1908
|
+
{
|
1909
|
+
disabled: isDisabled,
|
1910
|
+
size: "S",
|
1911
|
+
endIcon: null,
|
1912
|
+
paddingTop: "4px",
|
1913
|
+
paddingLeft: "7px",
|
1914
|
+
paddingRight: "7px",
|
1915
|
+
variant,
|
1916
|
+
children: [
|
1917
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.More, { "aria-hidden": true, focusable: false }),
|
1918
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: label || formatMessage({
|
1919
|
+
id: "content-manager.containers.edit.panels.default.more-actions",
|
1920
|
+
defaultMessage: "More document actions"
|
2067
1921
|
}) })
|
2068
|
-
]
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2076
|
-
defaultMessage: "Choose an option to unpublish the document."
|
2077
|
-
}),
|
2078
|
-
onValueChange: handleChange,
|
2079
|
-
children: [
|
2080
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2081
|
-
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2082
|
-
defaultMessage: "Keep draft"
|
2083
|
-
}) }),
|
2084
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2085
|
-
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2086
|
-
defaultMessage: "Replace draft"
|
2087
|
-
}) })
|
2088
|
-
]
|
2089
|
-
}
|
2090
|
-
)
|
2091
|
-
] }),
|
2092
|
-
onConfirm: async () => {
|
2093
|
-
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2094
|
-
console.error(
|
2095
|
-
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2096
|
-
);
|
2097
|
-
toggleNotification({
|
2098
|
-
message: formatMessage({
|
2099
|
-
id: "content-manager.actions.unpublish.error",
|
2100
|
-
defaultMessage: "An error occurred while trying to unpublish the document."
|
2101
|
-
}),
|
2102
|
-
type: "danger"
|
2103
|
-
});
|
2104
|
-
}
|
2105
|
-
await unpublish(
|
1922
|
+
]
|
1923
|
+
}
|
1924
|
+
),
|
1925
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1926
|
+
actions2.map((action) => {
|
1927
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
1928
|
+
designSystem.Menu.Item,
|
2106
1929
|
{
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
1930
|
+
disabled: action.disabled,
|
1931
|
+
onSelect: handleClick(action),
|
1932
|
+
display: "block",
|
1933
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", gap: 4, children: [
|
1934
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
1935
|
+
designSystem.Flex,
|
1936
|
+
{
|
1937
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1938
|
+
gap: 2,
|
1939
|
+
tag: "span",
|
1940
|
+
children: [
|
1941
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
1942
|
+
designSystem.Flex,
|
1943
|
+
{
|
1944
|
+
tag: "span",
|
1945
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1946
|
+
children: action.icon
|
1947
|
+
}
|
1948
|
+
),
|
1949
|
+
action.label
|
1950
|
+
]
|
1951
|
+
}
|
1952
|
+
),
|
1953
|
+
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsxRuntime.jsx(
|
1954
|
+
designSystem.Flex,
|
1955
|
+
{
|
1956
|
+
alignItems: "center",
|
1957
|
+
background: "alternative100",
|
1958
|
+
borderStyle: "solid",
|
1959
|
+
borderColor: "alternative200",
|
1960
|
+
borderWidth: "1px",
|
1961
|
+
height: 5,
|
1962
|
+
paddingLeft: 2,
|
1963
|
+
paddingRight: 2,
|
1964
|
+
hasRadius: true,
|
1965
|
+
color: "alternative600",
|
1966
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
|
1967
|
+
}
|
1968
|
+
)
|
1969
|
+
] })
|
2111
1970
|
},
|
2112
|
-
|
1971
|
+
action.id
|
2113
1972
|
);
|
2114
|
-
}
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
1973
|
+
}),
|
1974
|
+
children
|
1975
|
+
] }),
|
1976
|
+
actions2.map((action) => {
|
1977
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
|
1978
|
+
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1979
|
+
DocumentActionConfirmDialog,
|
1980
|
+
{
|
1981
|
+
...action.dialog,
|
1982
|
+
variant: action.variant,
|
1983
|
+
isOpen: dialogId === action.id,
|
1984
|
+
onClose: handleClose
|
1985
|
+
}
|
1986
|
+
) : null,
|
1987
|
+
action.dialog?.type === "modal" ? /* @__PURE__ */ jsxRuntime.jsx(
|
1988
|
+
DocumentActionModal,
|
1989
|
+
{
|
1990
|
+
...action.dialog,
|
1991
|
+
onModalClose: handleClose,
|
1992
|
+
isOpen: dialogId === action.id
|
1993
|
+
}
|
1994
|
+
) : null
|
1995
|
+
] }, action.id);
|
1996
|
+
})
|
1997
|
+
] });
|
1998
|
+
};
|
1999
|
+
const convertActionVariantToColor = (variant = "secondary") => {
|
2000
|
+
switch (variant) {
|
2001
|
+
case "danger":
|
2002
|
+
return "danger600";
|
2003
|
+
case "secondary":
|
2004
|
+
return void 0;
|
2005
|
+
case "success":
|
2006
|
+
return "success600";
|
2007
|
+
default:
|
2008
|
+
return "primary600";
|
2009
|
+
}
|
2010
|
+
};
|
2011
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
2012
|
+
switch (variant) {
|
2013
|
+
case "danger":
|
2014
|
+
return "danger600";
|
2015
|
+
case "secondary":
|
2016
|
+
return "neutral500";
|
2017
|
+
case "success":
|
2018
|
+
return "success600";
|
2019
|
+
default:
|
2020
|
+
return "primary600";
|
2021
|
+
}
|
2022
|
+
};
|
2023
|
+
const DocumentActionConfirmDialog = ({
|
2024
|
+
onClose,
|
2025
|
+
onCancel,
|
2026
|
+
onConfirm,
|
2027
|
+
title,
|
2028
|
+
content,
|
2029
|
+
isOpen,
|
2030
|
+
variant = "secondary"
|
2031
|
+
}) => {
|
2032
|
+
const { formatMessage } = reactIntl.useIntl();
|
2033
|
+
const handleClose = async () => {
|
2034
|
+
if (onCancel) {
|
2035
|
+
await onCancel();
|
2036
|
+
}
|
2037
|
+
onClose();
|
2038
|
+
};
|
2039
|
+
const handleConfirm = async () => {
|
2040
|
+
if (onConfirm) {
|
2041
|
+
await onConfirm();
|
2042
|
+
}
|
2043
|
+
onClose();
|
2118
2044
|
};
|
2045
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
2046
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
|
2047
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: content }),
|
2048
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
|
2049
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
2050
|
+
id: "app.components.Button.cancel",
|
2051
|
+
defaultMessage: "Cancel"
|
2052
|
+
}) }) }),
|
2053
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
2054
|
+
id: "app.components.Button.confirm",
|
2055
|
+
defaultMessage: "Confirm"
|
2056
|
+
}) })
|
2057
|
+
] })
|
2058
|
+
] }) });
|
2119
2059
|
};
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2060
|
+
const DocumentActionModal = ({
|
2061
|
+
isOpen,
|
2062
|
+
title,
|
2063
|
+
onClose,
|
2064
|
+
footer: Footer,
|
2065
|
+
content: Content,
|
2066
|
+
onModalClose
|
2127
2067
|
}) => {
|
2128
|
-
const
|
2129
|
-
|
2130
|
-
|
2131
|
-
const { discard } = useDocumentActions();
|
2132
|
-
const [{ query }] = strapiAdmin.useQueryParams();
|
2133
|
-
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
2134
|
-
if (!schema?.options?.draftAndPublish) {
|
2135
|
-
return null;
|
2136
|
-
}
|
2137
|
-
return {
|
2138
|
-
disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
|
2139
|
-
label: formatMessage({
|
2140
|
-
id: "content-manager.actions.discard.label",
|
2141
|
-
defaultMessage: "Discard changes"
|
2142
|
-
}),
|
2143
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(StyledCrossCircle, {}),
|
2144
|
-
position: ["panel", "table-row"],
|
2145
|
-
variant: "danger",
|
2146
|
-
dialog: {
|
2147
|
-
type: "dialog",
|
2148
|
-
title: formatMessage({
|
2149
|
-
id: "app.components.ConfirmDialog.title",
|
2150
|
-
defaultMessage: "Confirmation"
|
2151
|
-
}),
|
2152
|
-
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2153
|
-
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2154
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2155
|
-
id: "content-manager.actions.discard.dialog.body",
|
2156
|
-
defaultMessage: "Are you sure?"
|
2157
|
-
}) })
|
2158
|
-
] }),
|
2159
|
-
onConfirm: async () => {
|
2160
|
-
await discard({
|
2161
|
-
collectionType,
|
2162
|
-
model,
|
2163
|
-
documentId,
|
2164
|
-
params
|
2165
|
-
});
|
2166
|
-
}
|
2068
|
+
const handleClose = () => {
|
2069
|
+
if (onClose) {
|
2070
|
+
onClose();
|
2167
2071
|
}
|
2072
|
+
onModalClose();
|
2168
2073
|
};
|
2074
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { children: [
|
2075
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title }) }),
|
2076
|
+
typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Body, { children: Content }),
|
2077
|
+
typeof Footer === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Footer, { onClose: handleClose }) : Footer
|
2078
|
+
] }) });
|
2169
2079
|
};
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
fill: currentColor;
|
2174
|
-
}
|
2175
|
-
`;
|
2176
|
-
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2177
|
-
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2178
|
-
const RelativeTime = React__namespace.forwardRef(
|
2179
|
-
({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
|
2180
|
-
const { formatRelativeTime, formatDate, formatTime } = reactIntl.useIntl();
|
2181
|
-
const interval = dateFns.intervalToDuration({
|
2182
|
-
start: timestamp,
|
2183
|
-
end: Date.now()
|
2184
|
-
// see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
|
2185
|
-
});
|
2186
|
-
const unit = intervals.find((intervalUnit) => {
|
2187
|
-
return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
|
2188
|
-
});
|
2189
|
-
const relativeTime = dateFns.isPast(timestamp) ? -interval[unit] : interval[unit];
|
2190
|
-
const customInterval = customIntervals.find(
|
2191
|
-
(custom) => interval[custom.unit] < custom.threshold
|
2192
|
-
);
|
2193
|
-
const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
|
2194
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
2195
|
-
"time",
|
2196
|
-
{
|
2197
|
-
ref: forwardedRef,
|
2198
|
-
dateTime: timestamp.toISOString(),
|
2199
|
-
role: "time",
|
2200
|
-
title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
|
2201
|
-
...restProps,
|
2202
|
-
children: displayText
|
2203
|
-
}
|
2204
|
-
);
|
2205
|
-
}
|
2206
|
-
);
|
2207
|
-
const getDisplayName = ({
|
2208
|
-
firstname,
|
2209
|
-
lastname,
|
2210
|
-
username,
|
2211
|
-
email
|
2212
|
-
} = {}) => {
|
2213
|
-
if (username) {
|
2214
|
-
return username;
|
2080
|
+
const transformData = (data) => {
|
2081
|
+
if (Array.isArray(data)) {
|
2082
|
+
return data.map(transformData);
|
2215
2083
|
}
|
2216
|
-
if (
|
2217
|
-
|
2084
|
+
if (typeof data === "object" && data !== null) {
|
2085
|
+
if ("apiData" in data) {
|
2086
|
+
return data.apiData;
|
2087
|
+
}
|
2088
|
+
return mapValues__default.default(transformData)(data);
|
2218
2089
|
}
|
2219
|
-
return
|
2220
|
-
};
|
2221
|
-
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2222
|
-
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2223
|
-
const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
|
2224
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2090
|
+
return data;
|
2225
2091
|
};
|
2226
|
-
const
|
2227
|
-
|
2092
|
+
const PublishAction$1 = ({
|
2093
|
+
activeTab,
|
2094
|
+
documentId,
|
2095
|
+
model,
|
2096
|
+
collectionType,
|
2097
|
+
meta,
|
2098
|
+
document
|
2099
|
+
}) => {
|
2100
|
+
const { schema } = useDoc();
|
2101
|
+
const navigate = reactRouterDom.useNavigate();
|
2102
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2103
|
+
const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
|
2104
|
+
const isListView = reactRouterDom.useMatch(LIST_PATH) !== null;
|
2228
2105
|
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2229
|
-
const title = isCreating ? formatMessage({
|
2230
|
-
id: "content-manager.containers.edit.title.new",
|
2231
|
-
defaultMessage: "Create an entry"
|
2232
|
-
}) : documentTitle;
|
2233
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2234
|
-
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.BackButton, {}),
|
2235
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2236
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: title }),
|
2237
|
-
/* @__PURE__ */ jsxRuntime.jsx(HeaderToolbar, {})
|
2238
|
-
] }),
|
2239
|
-
status ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2240
|
-
] });
|
2241
|
-
};
|
2242
|
-
const HeaderToolbar = () => {
|
2243
2106
|
const { formatMessage } = reactIntl.useIntl();
|
2244
|
-
const
|
2107
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
2108
|
+
const { publish } = useDocumentActions();
|
2245
2109
|
const [
|
2246
|
-
|
2247
|
-
|
2110
|
+
countDraftRelations,
|
2111
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2112
|
+
] = useLazyGetDraftRelationCountQuery();
|
2113
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React__namespace.useState(0);
|
2114
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React__namespace.useState(0);
|
2115
|
+
const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
|
2116
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
2117
|
+
const modified = strapiAdmin.useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
2118
|
+
const setSubmitting = strapiAdmin.useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
2119
|
+
const isSubmitting = strapiAdmin.useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
2120
|
+
const validate = strapiAdmin.useForm("PublishAction", (state) => state.validate);
|
2121
|
+
const setErrors = strapiAdmin.useForm("PublishAction", (state) => state.setErrors);
|
2122
|
+
const formValues = strapiAdmin.useForm("PublishAction", ({ values }) => values);
|
2123
|
+
React__namespace.useEffect(() => {
|
2124
|
+
if (isErrorDraftRelations) {
|
2125
|
+
toggleNotification({
|
2126
|
+
type: "danger",
|
2127
|
+
message: formatMessage({
|
2128
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2129
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2130
|
+
})
|
2131
|
+
});
|
2248
2132
|
}
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
activeTab: status,
|
2258
|
-
model,
|
2259
|
-
documentId: id,
|
2260
|
-
document: isCloning ? void 0 : document,
|
2261
|
-
meta: isCloning ? void 0 : meta,
|
2262
|
-
collectionType
|
2263
|
-
},
|
2264
|
-
descriptions: plugins["content-manager"].apis.getHeaderActions(),
|
2265
|
-
children: (actions2) => {
|
2266
|
-
if (actions2.length > 0) {
|
2267
|
-
return /* @__PURE__ */ jsxRuntime.jsx(HeaderActions, { actions: actions2 });
|
2268
|
-
} else {
|
2269
|
-
return null;
|
2270
|
-
}
|
2133
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2134
|
+
React__namespace.useEffect(() => {
|
2135
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2136
|
+
const extractDraftRelations = (data) => {
|
2137
|
+
const relations = data.connect || [];
|
2138
|
+
relations.forEach((relation) => {
|
2139
|
+
if (relation.status === "draft") {
|
2140
|
+
localDraftRelations.add(relation.id);
|
2271
2141
|
}
|
2272
|
-
}
|
2273
|
-
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2279
|
-
|
2280
|
-
documentId: id,
|
2281
|
-
document: isCloning ? void 0 : document,
|
2282
|
-
meta: isCloning ? void 0 : meta,
|
2283
|
-
collectionType
|
2284
|
-
},
|
2285
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2286
|
-
children: (actions2) => {
|
2287
|
-
const headerActions = actions2.filter((action) => {
|
2288
|
-
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
2289
|
-
return positions.includes("header");
|
2290
|
-
});
|
2291
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
2292
|
-
DocumentActionsMenu,
|
2293
|
-
{
|
2294
|
-
actions: headerActions,
|
2295
|
-
label: formatMessage({
|
2296
|
-
id: "content-manager.containers.edit.header.more-actions",
|
2297
|
-
defaultMessage: "More actions"
|
2298
|
-
}),
|
2299
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(Information, { activeTab: status })
|
2300
|
-
}
|
2301
|
-
);
|
2142
|
+
});
|
2143
|
+
};
|
2144
|
+
const traverseAndExtract = (data) => {
|
2145
|
+
Object.entries(data).forEach(([key, value]) => {
|
2146
|
+
if (key === "connect" && Array.isArray(value)) {
|
2147
|
+
extractDraftRelations({ connect: value });
|
2148
|
+
} else if (typeof value === "object" && value !== null) {
|
2149
|
+
traverseAndExtract(value);
|
2302
2150
|
}
|
2151
|
+
});
|
2152
|
+
};
|
2153
|
+
if (!documentId || modified) {
|
2154
|
+
traverseAndExtract(formValues);
|
2155
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2156
|
+
}
|
2157
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2158
|
+
React__namespace.useEffect(() => {
|
2159
|
+
if (!document || !document.documentId || isListView) {
|
2160
|
+
return;
|
2161
|
+
}
|
2162
|
+
const fetchDraftRelationsCount = async () => {
|
2163
|
+
const { data, error } = await countDraftRelations({
|
2164
|
+
collectionType,
|
2165
|
+
model,
|
2166
|
+
documentId,
|
2167
|
+
params
|
2168
|
+
});
|
2169
|
+
if (error) {
|
2170
|
+
throw error;
|
2303
2171
|
}
|
2304
|
-
|
2305
|
-
|
2306
|
-
}
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2172
|
+
if (data) {
|
2173
|
+
setServerCountOfDraftRelations(data.data);
|
2174
|
+
}
|
2175
|
+
};
|
2176
|
+
fetchDraftRelationsCount();
|
2177
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
2178
|
+
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
2179
|
+
if (!schema?.options?.draftAndPublish) {
|
2311
2180
|
return null;
|
2312
2181
|
}
|
2313
|
-
const
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2182
|
+
const performPublish = async () => {
|
2183
|
+
setSubmitting(true);
|
2184
|
+
try {
|
2185
|
+
const { errors } = await validate(true, {
|
2186
|
+
status: "published"
|
2187
|
+
});
|
2188
|
+
if (errors) {
|
2189
|
+
toggleNotification({
|
2190
|
+
type: "danger",
|
2191
|
+
message: formatMessage({
|
2192
|
+
id: "content-manager.validation.error",
|
2193
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2194
|
+
})
|
2195
|
+
});
|
2196
|
+
return;
|
2197
|
+
}
|
2198
|
+
const res = await publish(
|
2325
2199
|
{
|
2326
|
-
|
2327
|
-
|
2200
|
+
collectionType,
|
2201
|
+
model,
|
2202
|
+
documentId,
|
2203
|
+
params
|
2328
2204
|
},
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2205
|
+
transformData(formValues)
|
2206
|
+
);
|
2207
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2208
|
+
navigate({
|
2209
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2210
|
+
search: rawQuery
|
2211
|
+
});
|
2212
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2213
|
+
setErrors(formatValidationErrors(res.error));
|
2214
|
+
}
|
2215
|
+
} finally {
|
2216
|
+
setSubmitting(false);
|
2217
|
+
}
|
2218
|
+
};
|
2219
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2220
|
+
const enableDraftRelationsCount = false;
|
2221
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
2222
|
+
return {
|
2223
|
+
/**
|
2224
|
+
* Disabled when:
|
2225
|
+
* - currently if you're cloning a document we don't support publish & clone at the same time.
|
2226
|
+
* - the form is submitting
|
2227
|
+
* - the active tab is the published tab
|
2228
|
+
* - the document is already published & not modified
|
2229
|
+
* - the document is being created & not modified
|
2230
|
+
* - the user doesn't have the permission to publish
|
2231
|
+
*/
|
2232
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
2233
|
+
label: formatMessage({
|
2234
|
+
id: "app.utils.publish",
|
2235
|
+
defaultMessage: "Publish"
|
2236
|
+
}),
|
2237
|
+
onClick: async () => {
|
2238
|
+
await performPublish();
|
2335
2239
|
},
|
2336
|
-
{
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2240
|
+
dialog: hasDraftRelations ? {
|
2241
|
+
type: "dialog",
|
2242
|
+
variant: "danger",
|
2243
|
+
footer: null,
|
2244
|
+
title: formatMessage({
|
2245
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2246
|
+
defaultMessage: "Confirmation"
|
2341
2247
|
}),
|
2342
|
-
|
2248
|
+
content: formatMessage(
|
2343
2249
|
{
|
2344
|
-
id:
|
2345
|
-
defaultMessage:
|
2250
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2251
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2346
2252
|
},
|
2347
2253
|
{
|
2348
|
-
|
2349
|
-
RelativeTime,
|
2350
|
-
{
|
2351
|
-
timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
|
2352
|
-
}
|
2353
|
-
),
|
2354
|
-
isAnonymous: !updator,
|
2355
|
-
author: updator
|
2254
|
+
count: totalDraftRelations
|
2356
2255
|
}
|
2357
|
-
)
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2256
|
+
),
|
2257
|
+
onConfirm: async () => {
|
2258
|
+
await performPublish();
|
2259
|
+
}
|
2260
|
+
} : void 0
|
2261
|
+
};
|
2262
|
+
};
|
2263
|
+
PublishAction$1.type = "publish";
|
2264
|
+
const UpdateAction = ({
|
2265
|
+
activeTab,
|
2266
|
+
documentId,
|
2267
|
+
model,
|
2268
|
+
collectionType
|
2269
|
+
}) => {
|
2270
|
+
const navigate = reactRouterDom.useNavigate();
|
2271
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2272
|
+
const { _unstableFormatValidationErrors: formatValidationErrors } = strapiAdmin.useAPIErrorHandler();
|
2273
|
+
const cloneMatch = reactRouterDom.useMatch(CLONE_PATH);
|
2274
|
+
const isCloning = cloneMatch !== null;
|
2275
|
+
const { formatMessage } = reactIntl.useIntl();
|
2276
|
+
const { create, update, clone } = useDocumentActions();
|
2277
|
+
const [{ query, rawQuery }] = strapiAdmin.useQueryParams();
|
2278
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
2279
|
+
const isSubmitting = strapiAdmin.useForm("UpdateAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
2280
|
+
const modified = strapiAdmin.useForm("UpdateAction", ({ modified: modified2 }) => modified2);
|
2281
|
+
const setSubmitting = strapiAdmin.useForm("UpdateAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
2282
|
+
const document = strapiAdmin.useForm("UpdateAction", ({ values }) => values);
|
2283
|
+
const validate = strapiAdmin.useForm("UpdateAction", (state) => state.validate);
|
2284
|
+
const setErrors = strapiAdmin.useForm("UpdateAction", (state) => state.setErrors);
|
2285
|
+
const resetForm = strapiAdmin.useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
|
2286
|
+
return {
|
2287
|
+
/**
|
2288
|
+
* Disabled when:
|
2289
|
+
* - the form is submitting
|
2290
|
+
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
2291
|
+
* - the active tab is the published tab
|
2292
|
+
*/
|
2293
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
2294
|
+
label: formatMessage({
|
2295
|
+
id: "content-manager.containers.Edit.save",
|
2296
|
+
defaultMessage: "Save"
|
2297
|
+
}),
|
2298
|
+
onClick: async () => {
|
2299
|
+
setSubmitting(true);
|
2300
|
+
try {
|
2301
|
+
const { errors } = await validate(true, {
|
2302
|
+
status: "draft"
|
2303
|
+
});
|
2304
|
+
if (errors) {
|
2305
|
+
toggleNotification({
|
2306
|
+
type: "danger",
|
2307
|
+
message: formatMessage({
|
2308
|
+
id: "content-manager.validation.error",
|
2309
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2310
|
+
})
|
2311
|
+
});
|
2312
|
+
return;
|
2379
2313
|
}
|
2380
|
-
|
2381
|
-
|
2382
|
-
|
2383
|
-
|
2384
|
-
|
2385
|
-
|
2386
|
-
|
2387
|
-
|
2388
|
-
|
2389
|
-
|
2390
|
-
|
2391
|
-
|
2392
|
-
|
2393
|
-
|
2394
|
-
|
2395
|
-
|
2396
|
-
|
2397
|
-
|
2398
|
-
|
2399
|
-
|
2400
|
-
|
2401
|
-
|
2314
|
+
if (isCloning) {
|
2315
|
+
const res = await clone(
|
2316
|
+
{
|
2317
|
+
model,
|
2318
|
+
documentId: cloneMatch.params.origin,
|
2319
|
+
params
|
2320
|
+
},
|
2321
|
+
transformData(document)
|
2322
|
+
);
|
2323
|
+
if ("data" in res) {
|
2324
|
+
navigate(
|
2325
|
+
{
|
2326
|
+
pathname: `../${res.data.documentId}`,
|
2327
|
+
search: rawQuery
|
2328
|
+
},
|
2329
|
+
{ relative: "path" }
|
2330
|
+
);
|
2331
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2332
|
+
setErrors(formatValidationErrors(res.error));
|
2333
|
+
}
|
2334
|
+
} else if (documentId || collectionType === SINGLE_TYPES) {
|
2335
|
+
const res = await update(
|
2336
|
+
{
|
2337
|
+
collectionType,
|
2338
|
+
model,
|
2339
|
+
documentId,
|
2340
|
+
params
|
2341
|
+
},
|
2342
|
+
transformData(document)
|
2343
|
+
);
|
2344
|
+
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2345
|
+
setErrors(formatValidationErrors(res.error));
|
2346
|
+
} else {
|
2347
|
+
resetForm();
|
2348
|
+
}
|
2349
|
+
} else {
|
2350
|
+
const res = await create(
|
2351
|
+
{
|
2352
|
+
model,
|
2353
|
+
params
|
2354
|
+
},
|
2355
|
+
transformData(document)
|
2356
|
+
);
|
2357
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2358
|
+
navigate(
|
2359
|
+
{
|
2360
|
+
pathname: `../${res.data.documentId}`,
|
2361
|
+
search: rawQuery
|
2362
|
+
},
|
2363
|
+
{ replace: true, relative: "path" }
|
2364
|
+
);
|
2365
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2366
|
+
setErrors(formatValidationErrors(res.error));
|
2367
|
+
}
|
2368
|
+
}
|
2369
|
+
} finally {
|
2370
|
+
setSubmitting(false);
|
2371
|
+
}
|
2402
2372
|
}
|
2403
|
-
|
2373
|
+
};
|
2404
2374
|
};
|
2405
|
-
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2409
|
-
designSystem.SingleSelect,
|
2410
|
-
{
|
2411
|
-
size: "S",
|
2412
|
-
disabled: action.disabled,
|
2413
|
-
"aria-label": action.label,
|
2414
|
-
onChange: action.onSelect,
|
2415
|
-
value: action.value,
|
2416
|
-
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
|
2417
|
-
},
|
2418
|
-
action.id
|
2419
|
-
);
|
2420
|
-
} else {
|
2421
|
-
return null;
|
2422
|
-
}
|
2423
|
-
}) });
|
2375
|
+
UpdateAction.type = "update";
|
2376
|
+
const UNPUBLISH_DRAFT_OPTIONS = {
|
2377
|
+
KEEP: "keep",
|
2378
|
+
DISCARD: "discard"
|
2424
2379
|
};
|
2425
|
-
const
|
2426
|
-
|
2380
|
+
const UnpublishAction$1 = ({
|
2381
|
+
activeTab,
|
2382
|
+
documentId,
|
2383
|
+
model,
|
2384
|
+
collectionType,
|
2385
|
+
document
|
2386
|
+
}) => {
|
2427
2387
|
const { formatMessage } = reactIntl.useIntl();
|
2428
|
-
|
2429
|
-
|
2430
|
-
|
2431
|
-
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2388
|
+
const { schema } = useDoc();
|
2389
|
+
const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
2390
|
+
const { unpublish } = useDocumentActions();
|
2391
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
2392
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
2393
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2394
|
+
const [shouldKeepDraft, setShouldKeepDraft] = React__namespace.useState(true);
|
2395
|
+
const isDocumentModified = document?.status === "modified";
|
2396
|
+
const handleChange = (value) => {
|
2397
|
+
setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
2438
2398
|
};
|
2439
|
-
|
2440
|
-
|
2441
|
-
|
2442
|
-
const navigate = reactRouterDom.useNavigate();
|
2443
|
-
const { formatMessage } = reactIntl.useIntl();
|
2399
|
+
if (!schema?.options?.draftAndPublish) {
|
2400
|
+
return null;
|
2401
|
+
}
|
2444
2402
|
return {
|
2403
|
+
disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
|
2445
2404
|
label: formatMessage({
|
2446
|
-
id: "
|
2447
|
-
defaultMessage: "
|
2405
|
+
id: "app.utils.unpublish",
|
2406
|
+
defaultMessage: "Unpublish"
|
2448
2407
|
}),
|
2449
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.
|
2450
|
-
onClick: () => {
|
2451
|
-
|
2408
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {}),
|
2409
|
+
onClick: async () => {
|
2410
|
+
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
2411
|
+
if (!documentId) {
|
2412
|
+
console.error(
|
2413
|
+
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2414
|
+
);
|
2415
|
+
toggleNotification({
|
2416
|
+
message: formatMessage({
|
2417
|
+
id: "content-manager.actions.unpublish.error",
|
2418
|
+
defaultMessage: "An error occurred while trying to unpublish the document."
|
2419
|
+
}),
|
2420
|
+
type: "danger"
|
2421
|
+
});
|
2422
|
+
}
|
2423
|
+
return;
|
2424
|
+
}
|
2425
|
+
await unpublish({
|
2426
|
+
collectionType,
|
2427
|
+
model,
|
2428
|
+
documentId,
|
2429
|
+
params
|
2430
|
+
});
|
2452
2431
|
},
|
2453
|
-
|
2432
|
+
dialog: isDocumentModified ? {
|
2433
|
+
type: "dialog",
|
2434
|
+
title: formatMessage({
|
2435
|
+
id: "app.components.ConfirmDialog.title",
|
2436
|
+
defaultMessage: "Confirmation"
|
2437
|
+
}),
|
2438
|
+
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", direction: "column", gap: 6, children: [
|
2439
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", direction: "column", gap: 2, children: [
|
2440
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2441
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2442
|
+
id: "content-manager.actions.unpublish.dialog.body",
|
2443
|
+
defaultMessage: "Are you sure?"
|
2444
|
+
}) })
|
2445
|
+
] }),
|
2446
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
2447
|
+
designSystem.Radio.Group,
|
2448
|
+
{
|
2449
|
+
defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
|
2450
|
+
name: "discard-options",
|
2451
|
+
"aria-label": formatMessage({
|
2452
|
+
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2453
|
+
defaultMessage: "Choose an option to unpublish the document."
|
2454
|
+
}),
|
2455
|
+
onValueChange: handleChange,
|
2456
|
+
children: [
|
2457
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2458
|
+
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2459
|
+
defaultMessage: "Keep draft"
|
2460
|
+
}) }),
|
2461
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2462
|
+
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2463
|
+
defaultMessage: "Replace draft"
|
2464
|
+
}) })
|
2465
|
+
]
|
2466
|
+
}
|
2467
|
+
)
|
2468
|
+
] }),
|
2469
|
+
onConfirm: async () => {
|
2470
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2471
|
+
console.error(
|
2472
|
+
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2473
|
+
);
|
2474
|
+
toggleNotification({
|
2475
|
+
message: formatMessage({
|
2476
|
+
id: "content-manager.actions.unpublish.error",
|
2477
|
+
defaultMessage: "An error occurred while trying to unpublish the document."
|
2478
|
+
}),
|
2479
|
+
type: "danger"
|
2480
|
+
});
|
2481
|
+
}
|
2482
|
+
await unpublish(
|
2483
|
+
{
|
2484
|
+
collectionType,
|
2485
|
+
model,
|
2486
|
+
documentId,
|
2487
|
+
params
|
2488
|
+
},
|
2489
|
+
!shouldKeepDraft
|
2490
|
+
);
|
2491
|
+
}
|
2492
|
+
} : void 0,
|
2493
|
+
variant: "danger",
|
2494
|
+
position: ["panel", "table-row"]
|
2454
2495
|
};
|
2455
2496
|
};
|
2456
|
-
|
2457
|
-
const
|
2458
|
-
|
2497
|
+
UnpublishAction$1.type = "unpublish";
|
2498
|
+
const DiscardAction = ({
|
2499
|
+
activeTab,
|
2500
|
+
documentId,
|
2501
|
+
model,
|
2502
|
+
collectionType,
|
2503
|
+
document
|
2504
|
+
}) => {
|
2459
2505
|
const { formatMessage } = reactIntl.useIntl();
|
2460
|
-
const
|
2461
|
-
const
|
2462
|
-
const {
|
2463
|
-
const {
|
2464
|
-
const
|
2506
|
+
const { schema } = useDoc();
|
2507
|
+
const canUpdate = useDocumentRBAC("DiscardAction", ({ canUpdate: canUpdate2 }) => canUpdate2);
|
2508
|
+
const { discard } = useDocumentActions();
|
2509
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
2510
|
+
const params = React__namespace.useMemo(() => buildValidParams(query), [query]);
|
2511
|
+
if (!schema?.options?.draftAndPublish) {
|
2512
|
+
return null;
|
2513
|
+
}
|
2465
2514
|
return {
|
2466
|
-
disabled: !
|
2515
|
+
disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
|
2467
2516
|
label: formatMessage({
|
2468
|
-
id: "content-manager.actions.
|
2469
|
-
defaultMessage: "
|
2517
|
+
id: "content-manager.actions.discard.label",
|
2518
|
+
defaultMessage: "Discard changes"
|
2470
2519
|
}),
|
2471
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.
|
2520
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {}),
|
2521
|
+
position: ["panel", "table-row"],
|
2522
|
+
variant: "danger",
|
2472
2523
|
dialog: {
|
2473
2524
|
type: "dialog",
|
2474
2525
|
title: formatMessage({
|
@@ -2478,92 +2529,90 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2478
2529
|
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2479
2530
|
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2480
2531
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2481
|
-
id: "content-manager.actions.
|
2532
|
+
id: "content-manager.actions.discard.dialog.body",
|
2482
2533
|
defaultMessage: "Are you sure?"
|
2483
2534
|
}) })
|
2484
2535
|
] }),
|
2485
2536
|
onConfirm: async () => {
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2537
|
+
await discard({
|
2538
|
+
collectionType,
|
2539
|
+
model,
|
2540
|
+
documentId,
|
2541
|
+
params
|
2542
|
+
});
|
2543
|
+
}
|
2544
|
+
}
|
2545
|
+
};
|
2546
|
+
};
|
2547
|
+
DiscardAction.type = "discard";
|
2548
|
+
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2549
|
+
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2550
|
+
const RelativeTime = React__namespace.forwardRef(
|
2551
|
+
({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
|
2552
|
+
const { formatRelativeTime, formatDate, formatTime } = reactIntl.useIntl();
|
2553
|
+
const interval = dateFns.intervalToDuration({
|
2554
|
+
start: timestamp,
|
2555
|
+
end: Date.now()
|
2556
|
+
// see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
|
2557
|
+
});
|
2558
|
+
const unit = intervals.find((intervalUnit) => {
|
2559
|
+
return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
|
2560
|
+
});
|
2561
|
+
const relativeTime = dateFns.isPast(timestamp) ? -interval[unit] : interval[unit];
|
2562
|
+
const customInterval = customIntervals.find(
|
2563
|
+
(custom) => interval[custom.unit] < custom.threshold
|
2564
|
+
);
|
2565
|
+
const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
|
2566
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
2567
|
+
"time",
|
2568
|
+
{
|
2569
|
+
ref: forwardedRef,
|
2570
|
+
dateTime: timestamp.toISOString(),
|
2571
|
+
role: "time",
|
2572
|
+
title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
|
2573
|
+
...restProps,
|
2574
|
+
children: displayText
|
2519
2575
|
}
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2576
|
+
);
|
2577
|
+
}
|
2578
|
+
);
|
2579
|
+
const getDisplayName = ({
|
2580
|
+
firstname,
|
2581
|
+
lastname,
|
2582
|
+
username,
|
2583
|
+
email
|
2584
|
+
} = {}) => {
|
2585
|
+
if (username) {
|
2586
|
+
return username;
|
2587
|
+
}
|
2588
|
+
if (firstname) {
|
2589
|
+
return `${firstname} ${lastname ?? ""}`.trim();
|
2590
|
+
}
|
2591
|
+
return email ?? "";
|
2524
2592
|
};
|
2525
|
-
|
2526
|
-
const
|
2527
|
-
const
|
2528
|
-
|
2529
|
-
const [
|
2530
|
-
{
|
2531
|
-
query: { status }
|
2532
|
-
}
|
2533
|
-
] = strapiAdmin.useQueryParams({
|
2534
|
-
status: "draft"
|
2535
|
-
});
|
2536
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2537
|
-
const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
|
2538
|
-
const props = {
|
2539
|
-
activeTab: status,
|
2540
|
-
model,
|
2541
|
-
documentId: id,
|
2542
|
-
document: isCloning ? void 0 : document,
|
2543
|
-
meta: isCloning ? void 0 : meta,
|
2544
|
-
collectionType
|
2545
|
-
};
|
2546
|
-
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
2547
|
-
strapiAdmin.DescriptionComponentRenderer,
|
2548
|
-
{
|
2549
|
-
props,
|
2550
|
-
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2551
|
-
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
|
2552
|
-
}
|
2553
|
-
) });
|
2593
|
+
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2594
|
+
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2595
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2596
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2554
2597
|
};
|
2555
|
-
const
|
2598
|
+
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
2556
2599
|
const { formatMessage } = reactIntl.useIntl();
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2560
|
-
|
2561
|
-
|
2562
|
-
|
2563
|
-
|
2600
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2601
|
+
const title = isCreating ? formatMessage({
|
2602
|
+
id: "content-manager.containers.edit.title.new",
|
2603
|
+
defaultMessage: "Create an entry"
|
2604
|
+
}) : documentTitle;
|
2605
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2606
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.BackButton, {}),
|
2607
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2608
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", tag: "h1", children: title }),
|
2609
|
+
/* @__PURE__ */ jsxRuntime.jsx(HeaderToolbar, {})
|
2610
|
+
] }),
|
2611
|
+
status ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 1, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2612
|
+
] });
|
2564
2613
|
};
|
2565
|
-
|
2566
|
-
const
|
2614
|
+
const HeaderToolbar = () => {
|
2615
|
+
const { formatMessage } = reactIntl.useIntl();
|
2567
2616
|
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2568
2617
|
const [
|
2569
2618
|
{
|
@@ -2571,355 +2620,432 @@ const ActionsPanelContent = () => {
|
|
2571
2620
|
}
|
2572
2621
|
] = strapiAdmin.useQueryParams();
|
2573
2622
|
const { model, id, document, meta, collectionType } = useDoc();
|
2574
|
-
const plugins = strapiAdmin.useStrapiApp("
|
2575
|
-
|
2576
|
-
activeTab: status,
|
2577
|
-
model,
|
2578
|
-
documentId: id,
|
2579
|
-
document: isCloning ? void 0 : document,
|
2580
|
-
meta: isCloning ? void 0 : meta,
|
2581
|
-
collectionType
|
2582
|
-
};
|
2583
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2623
|
+
const plugins = strapiAdmin.useStrapiApp("HeaderToolbar", (state) => state.plugins);
|
2624
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
2584
2625
|
/* @__PURE__ */ jsxRuntime.jsx(
|
2585
2626
|
strapiAdmin.DescriptionComponentRenderer,
|
2586
2627
|
{
|
2587
|
-
props
|
2588
|
-
|
2589
|
-
|
2628
|
+
props: {
|
2629
|
+
activeTab: status,
|
2630
|
+
model,
|
2631
|
+
documentId: id,
|
2632
|
+
document: isCloning ? void 0 : document,
|
2633
|
+
meta: isCloning ? void 0 : meta,
|
2634
|
+
collectionType
|
2635
|
+
},
|
2636
|
+
descriptions: plugins["content-manager"].apis.getHeaderActions(),
|
2637
|
+
children: (actions2) => {
|
2638
|
+
if (actions2.length > 0) {
|
2639
|
+
return /* @__PURE__ */ jsxRuntime.jsx(HeaderActions, { actions: actions2 });
|
2640
|
+
} else {
|
2641
|
+
return null;
|
2642
|
+
}
|
2643
|
+
}
|
2590
2644
|
}
|
2591
2645
|
),
|
2592
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
2646
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
2647
|
+
strapiAdmin.DescriptionComponentRenderer,
|
2648
|
+
{
|
2649
|
+
props: {
|
2650
|
+
activeTab: status,
|
2651
|
+
model,
|
2652
|
+
documentId: id,
|
2653
|
+
document: isCloning ? void 0 : document,
|
2654
|
+
meta: isCloning ? void 0 : meta,
|
2655
|
+
collectionType
|
2656
|
+
},
|
2657
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2658
|
+
children: (actions2) => {
|
2659
|
+
const headerActions = actions2.filter((action) => {
|
2660
|
+
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
2661
|
+
return positions.includes("header");
|
2662
|
+
});
|
2663
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
2664
|
+
DocumentActionsMenu,
|
2665
|
+
{
|
2666
|
+
actions: headerActions,
|
2667
|
+
label: formatMessage({
|
2668
|
+
id: "content-manager.containers.edit.header.more-actions",
|
2669
|
+
defaultMessage: "More actions"
|
2670
|
+
}),
|
2671
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Information, { activeTab: status })
|
2672
|
+
}
|
2673
|
+
);
|
2674
|
+
}
|
2675
|
+
}
|
2676
|
+
)
|
2593
2677
|
] });
|
2594
2678
|
};
|
2595
|
-
const
|
2596
|
-
|
2597
|
-
|
2679
|
+
const Information = ({ activeTab }) => {
|
2680
|
+
const { formatMessage } = reactIntl.useIntl();
|
2681
|
+
const { document, meta } = useDoc();
|
2682
|
+
if (!document || !document.id) {
|
2683
|
+
return null;
|
2684
|
+
}
|
2685
|
+
const createAndUpdateDocument = activeTab === "draft" ? document : meta?.availableStatus.find((status) => status.publishedAt === null);
|
2686
|
+
const publishDocument = activeTab === "published" ? document : meta?.availableStatus.find((status) => status.publishedAt !== null);
|
2687
|
+
const creator = createAndUpdateDocument?.[CREATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[CREATED_BY_ATTRIBUTE_NAME]) : null;
|
2688
|
+
const updator = createAndUpdateDocument?.[UPDATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[UPDATED_BY_ATTRIBUTE_NAME]) : null;
|
2689
|
+
const information = [
|
2598
2690
|
{
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
borderColor: "neutral150",
|
2604
|
-
hasRadius: true,
|
2605
|
-
paddingBottom: 4,
|
2606
|
-
paddingLeft: 4,
|
2607
|
-
paddingRight: 4,
|
2608
|
-
paddingTop: 4,
|
2609
|
-
shadow: "tableShadow",
|
2610
|
-
gap: 3,
|
2611
|
-
direction: "column",
|
2612
|
-
justifyContent: "stretch",
|
2613
|
-
alignItems: "flex-start",
|
2614
|
-
children: [
|
2615
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2616
|
-
children
|
2617
|
-
]
|
2618
|
-
}
|
2619
|
-
);
|
2620
|
-
});
|
2621
|
-
const HOOKS = {
|
2622
|
-
/**
|
2623
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2624
|
-
* @constant
|
2625
|
-
* @type {string}
|
2626
|
-
*/
|
2627
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2628
|
-
/**
|
2629
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2630
|
-
* @constant
|
2631
|
-
* @type {string}
|
2632
|
-
*/
|
2633
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2634
|
-
/**
|
2635
|
-
* Hook that allows to mutate the CM's edit view layout
|
2636
|
-
* @constant
|
2637
|
-
* @type {string}
|
2638
|
-
*/
|
2639
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2640
|
-
/**
|
2641
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2642
|
-
* @constant
|
2643
|
-
* @type {string}
|
2644
|
-
*/
|
2645
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2646
|
-
};
|
2647
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2648
|
-
endpoints: (builder) => ({
|
2649
|
-
getContentTypeConfiguration: builder.query({
|
2650
|
-
query: (uid) => ({
|
2651
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2652
|
-
method: "GET"
|
2691
|
+
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2692
|
+
label: formatMessage({
|
2693
|
+
id: "content-manager.containers.edit.information.last-published.label",
|
2694
|
+
defaultMessage: "Published"
|
2653
2695
|
}),
|
2654
|
-
|
2655
|
-
|
2656
|
-
|
2657
|
-
|
2658
|
-
|
2659
|
-
|
2660
|
-
|
2661
|
-
|
2662
|
-
|
2663
|
-
|
2664
|
-
|
2665
|
-
|
2666
|
-
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2696
|
+
value: formatMessage(
|
2697
|
+
{
|
2698
|
+
id: "content-manager.containers.edit.information.last-published.value",
|
2699
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2700
|
+
},
|
2701
|
+
{
|
2702
|
+
time: /* @__PURE__ */ jsxRuntime.jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
2703
|
+
isAnonymous: !publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME],
|
2704
|
+
author: publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME] ? getDisplayName(publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME]) : null
|
2705
|
+
}
|
2706
|
+
)
|
2707
|
+
},
|
2708
|
+
{
|
2709
|
+
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2710
|
+
label: formatMessage({
|
2711
|
+
id: "content-manager.containers.edit.information.last-draft.label",
|
2712
|
+
defaultMessage: "Updated"
|
2713
|
+
}),
|
2714
|
+
value: formatMessage(
|
2715
|
+
{
|
2716
|
+
id: "content-manager.containers.edit.information.last-draft.value",
|
2717
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2718
|
+
},
|
2719
|
+
{
|
2720
|
+
time: /* @__PURE__ */ jsxRuntime.jsx(
|
2721
|
+
RelativeTime,
|
2722
|
+
{
|
2723
|
+
timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
|
2724
|
+
}
|
2725
|
+
),
|
2726
|
+
isAnonymous: !updator,
|
2727
|
+
author: updator
|
2728
|
+
}
|
2729
|
+
)
|
2730
|
+
},
|
2731
|
+
{
|
2732
|
+
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2733
|
+
label: formatMessage({
|
2734
|
+
id: "content-manager.containers.edit.information.document.label",
|
2735
|
+
defaultMessage: "Created"
|
2670
2736
|
}),
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2674
|
-
|
2675
|
-
|
2676
|
-
{
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
2685
|
-
}
|
2686
|
-
|
2687
|
-
|
2688
|
-
|
2689
|
-
|
2690
|
-
|
2691
|
-
|
2692
|
-
|
2693
|
-
|
2694
|
-
|
2695
|
-
|
2696
|
-
|
2697
|
-
|
2698
|
-
|
2699
|
-
|
2737
|
+
value: formatMessage(
|
2738
|
+
{
|
2739
|
+
id: "content-manager.containers.edit.information.document.value",
|
2740
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2741
|
+
},
|
2742
|
+
{
|
2743
|
+
time: /* @__PURE__ */ jsxRuntime.jsx(
|
2744
|
+
RelativeTime,
|
2745
|
+
{
|
2746
|
+
timestamp: new Date(createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME])
|
2747
|
+
}
|
2748
|
+
),
|
2749
|
+
isAnonymous: !creator,
|
2750
|
+
author: creator
|
2751
|
+
}
|
2752
|
+
)
|
2753
|
+
}
|
2754
|
+
].filter((info) => info.isDisplayed);
|
2755
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
2756
|
+
designSystem.Flex,
|
2757
|
+
{
|
2758
|
+
borderWidth: "1px 0 0 0",
|
2759
|
+
borderStyle: "solid",
|
2760
|
+
borderColor: "neutral150",
|
2761
|
+
direction: "column",
|
2762
|
+
marginTop: 2,
|
2763
|
+
tag: "dl",
|
2764
|
+
padding: 5,
|
2765
|
+
gap: 3,
|
2766
|
+
alignItems: "flex-start",
|
2767
|
+
marginLeft: "-0.4rem",
|
2768
|
+
marginRight: "-0.4rem",
|
2769
|
+
width: "calc(100% + 8px)",
|
2770
|
+
children: information.map((info) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, direction: "column", alignItems: "flex-start", children: [
|
2771
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
|
2772
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "dd", variant: "pi", textColor: "neutral600", children: info.value })
|
2773
|
+
] }, info.label))
|
2774
|
+
}
|
2700
2775
|
);
|
2701
|
-
return {
|
2702
|
-
name: mainFieldName,
|
2703
|
-
type: mainFieldType ?? "string"
|
2704
|
-
};
|
2705
|
-
};
|
2706
|
-
const DEFAULT_SETTINGS = {
|
2707
|
-
bulkable: false,
|
2708
|
-
filterable: false,
|
2709
|
-
searchable: false,
|
2710
|
-
pagination: false,
|
2711
|
-
defaultSortBy: "",
|
2712
|
-
defaultSortOrder: "asc",
|
2713
|
-
mainField: "id",
|
2714
|
-
pageSize: 10
|
2715
2776
|
};
|
2716
|
-
const
|
2717
|
-
const
|
2718
|
-
const
|
2719
|
-
|
2720
|
-
|
2721
|
-
|
2722
|
-
|
2723
|
-
|
2724
|
-
|
2725
|
-
|
2726
|
-
error,
|
2727
|
-
isFetching: isFetchingConfigs
|
2728
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2729
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2730
|
-
React__namespace.useEffect(() => {
|
2731
|
-
if (error) {
|
2732
|
-
toggleNotification({
|
2733
|
-
type: "danger",
|
2734
|
-
message: formatAPIError(error)
|
2735
|
-
});
|
2777
|
+
const HeaderActions = ({ actions: actions2 }) => {
|
2778
|
+
const [dialogId, setDialogId] = React__namespace.useState(null);
|
2779
|
+
const handleClick = (action) => async (e) => {
|
2780
|
+
if (!("options" in action)) {
|
2781
|
+
const { onClick = () => false, dialog, id } = action;
|
2782
|
+
const muteDialog = await onClick(e);
|
2783
|
+
if (dialog && !muteDialog) {
|
2784
|
+
e.preventDefault();
|
2785
|
+
setDialogId(id);
|
2786
|
+
}
|
2736
2787
|
}
|
2737
|
-
}, [error, formatAPIError, toggleNotification]);
|
2738
|
-
const editLayout = React__namespace.useMemo(
|
2739
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2740
|
-
layout: [],
|
2741
|
-
components: {},
|
2742
|
-
metadatas: {},
|
2743
|
-
options: {},
|
2744
|
-
settings: DEFAULT_SETTINGS
|
2745
|
-
},
|
2746
|
-
[data, isLoading, schemas, schema, components]
|
2747
|
-
);
|
2748
|
-
const listLayout = React__namespace.useMemo(() => {
|
2749
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2750
|
-
layout: [],
|
2751
|
-
metadatas: {},
|
2752
|
-
options: {},
|
2753
|
-
settings: DEFAULT_SETTINGS
|
2754
|
-
};
|
2755
|
-
}, [data, isLoading, schemas, schema, components]);
|
2756
|
-
const { layout: edit } = React__namespace.useMemo(
|
2757
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2758
|
-
layout: editLayout,
|
2759
|
-
query
|
2760
|
-
}),
|
2761
|
-
[editLayout, query, runHookWaterfall]
|
2762
|
-
);
|
2763
|
-
return {
|
2764
|
-
error,
|
2765
|
-
isLoading,
|
2766
|
-
edit,
|
2767
|
-
list: listLayout
|
2768
2788
|
};
|
2769
|
-
|
2770
|
-
|
2771
|
-
|
2772
|
-
return
|
2773
|
-
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2780
|
-
|
2781
|
-
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2785
|
-
schemas
|
2786
|
-
).reduce((panels, row) => {
|
2787
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2788
|
-
panels.push([row]);
|
2789
|
-
currentPanelIndex += 2;
|
2789
|
+
const handleClose = () => {
|
2790
|
+
setDialogId(null);
|
2791
|
+
};
|
2792
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 1, children: actions2.map((action) => {
|
2793
|
+
if (action.options) {
|
2794
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
2795
|
+
designSystem.SingleSelect,
|
2796
|
+
{
|
2797
|
+
size: "S",
|
2798
|
+
onChange: action.onSelect,
|
2799
|
+
"aria-label": action.label,
|
2800
|
+
...action,
|
2801
|
+
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { ...option, children: label }, option.value))
|
2802
|
+
},
|
2803
|
+
action.id
|
2804
|
+
);
|
2790
2805
|
} else {
|
2791
|
-
if (
|
2792
|
-
|
2806
|
+
if (action.type === "icon") {
|
2807
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(React__namespace.Fragment, { children: [
|
2808
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
2809
|
+
designSystem.IconButton,
|
2810
|
+
{
|
2811
|
+
disabled: action.disabled,
|
2812
|
+
label: action.label,
|
2813
|
+
size: "S",
|
2814
|
+
onClick: handleClick(action),
|
2815
|
+
children: action.icon
|
2816
|
+
}
|
2817
|
+
),
|
2818
|
+
action.dialog ? /* @__PURE__ */ jsxRuntime.jsx(
|
2819
|
+
HeaderActionDialog,
|
2820
|
+
{
|
2821
|
+
...action.dialog,
|
2822
|
+
isOpen: dialogId === action.id,
|
2823
|
+
onClose: handleClose
|
2824
|
+
}
|
2825
|
+
) : null
|
2826
|
+
] }, action.id);
|
2793
2827
|
}
|
2794
|
-
panels[currentPanelIndex].push(row);
|
2795
2828
|
}
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2801
|
-
|
2802
|
-
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
|
2811
|
-
|
2812
|
-
|
2813
|
-
}
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
|
2821
|
-
|
2829
|
+
}) });
|
2830
|
+
};
|
2831
|
+
const HeaderActionDialog = ({
|
2832
|
+
onClose,
|
2833
|
+
onCancel,
|
2834
|
+
title,
|
2835
|
+
content: Content,
|
2836
|
+
isOpen
|
2837
|
+
}) => {
|
2838
|
+
const handleClose = async () => {
|
2839
|
+
if (onCancel) {
|
2840
|
+
await onCancel();
|
2841
|
+
}
|
2842
|
+
onClose();
|
2843
|
+
};
|
2844
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
|
2845
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: title }),
|
2846
|
+
typeof Content === "function" ? /* @__PURE__ */ jsxRuntime.jsx(Content, { onClose: handleClose }) : Content
|
2847
|
+
] }) });
|
2848
|
+
};
|
2849
|
+
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
2850
|
+
const navigate = reactRouterDom.useNavigate();
|
2851
|
+
const { formatMessage } = reactIntl.useIntl();
|
2852
|
+
return {
|
2853
|
+
label: formatMessage({
|
2854
|
+
id: "app.links.configure-view",
|
2855
|
+
defaultMessage: "Configure the view"
|
2856
|
+
}),
|
2857
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.ListPlus, {}),
|
2858
|
+
onClick: () => {
|
2859
|
+
navigate(`../${collectionType}/${model}/configurations/edit`);
|
2822
2860
|
},
|
2823
|
-
|
2824
|
-
|
2861
|
+
position: "header"
|
2862
|
+
};
|
2863
|
+
};
|
2864
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2865
|
+
const EditTheModelAction = ({ model }) => {
|
2866
|
+
const navigate = reactRouterDom.useNavigate();
|
2867
|
+
const { formatMessage } = reactIntl.useIntl();
|
2825
2868
|
return {
|
2826
|
-
|
2827
|
-
|
2828
|
-
|
2829
|
-
|
2830
|
-
|
2831
|
-
|
2869
|
+
label: formatMessage({
|
2870
|
+
id: "content-manager.link-to-ctb",
|
2871
|
+
defaultMessage: "Edit the model"
|
2872
|
+
}),
|
2873
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Pencil, {}),
|
2874
|
+
onClick: () => {
|
2875
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2832
2876
|
},
|
2833
|
-
|
2834
|
-
...schema?.options,
|
2835
|
-
...schema?.pluginOptions,
|
2836
|
-
...data.contentType.options
|
2837
|
-
}
|
2877
|
+
position: "header"
|
2838
2878
|
};
|
2839
2879
|
};
|
2840
|
-
|
2841
|
-
|
2842
|
-
|
2843
|
-
|
2844
|
-
|
2845
|
-
|
2880
|
+
EditTheModelAction.type = "edit-the-model";
|
2881
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2882
|
+
const navigate = reactRouterDom.useNavigate();
|
2883
|
+
const { formatMessage } = reactIntl.useIntl();
|
2884
|
+
const listViewPathMatch = reactRouterDom.useMatch(LIST_PATH);
|
2885
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2886
|
+
const { delete: deleteAction } = useDocumentActions();
|
2887
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
2888
|
+
const setSubmitting = strapiAdmin.useForm("DeleteAction", (state) => state.setSubmitting);
|
2889
|
+
const isLocalized = document?.locale != null;
|
2890
|
+
return {
|
2891
|
+
disabled: !canDelete || !document,
|
2892
|
+
label: formatMessage(
|
2893
|
+
{
|
2894
|
+
id: "content-manager.actions.delete.label",
|
2895
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2896
|
+
},
|
2897
|
+
{ isLocalized }
|
2898
|
+
),
|
2899
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(Icons.Trash, {}),
|
2900
|
+
dialog: {
|
2901
|
+
type: "dialog",
|
2902
|
+
title: formatMessage({
|
2903
|
+
id: "app.components.ConfirmDialog.title",
|
2904
|
+
defaultMessage: "Confirmation"
|
2905
|
+
}),
|
2906
|
+
content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
2907
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2908
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2909
|
+
id: "content-manager.actions.delete.dialog.body",
|
2910
|
+
defaultMessage: "Are you sure?"
|
2911
|
+
}) })
|
2912
|
+
] }),
|
2913
|
+
onConfirm: async () => {
|
2914
|
+
if (!listViewPathMatch) {
|
2915
|
+
setSubmitting(true);
|
2916
|
+
}
|
2917
|
+
try {
|
2918
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2919
|
+
console.error(
|
2920
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2921
|
+
);
|
2922
|
+
toggleNotification({
|
2923
|
+
message: formatMessage({
|
2924
|
+
id: "content-manager.actions.delete.error",
|
2925
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2926
|
+
}),
|
2927
|
+
type: "danger"
|
2928
|
+
});
|
2929
|
+
return;
|
2930
|
+
}
|
2931
|
+
const res = await deleteAction({
|
2932
|
+
documentId,
|
2933
|
+
model,
|
2934
|
+
collectionType,
|
2935
|
+
params: {
|
2936
|
+
locale: "*"
|
2937
|
+
}
|
2938
|
+
});
|
2939
|
+
if (!("error" in res)) {
|
2940
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2941
|
+
}
|
2942
|
+
} finally {
|
2943
|
+
if (!listViewPathMatch) {
|
2944
|
+
setSubmitting(false);
|
2945
|
+
}
|
2946
|
+
}
|
2846
2947
|
}
|
2847
|
-
const { edit: metadata } = metadatas[field.name];
|
2848
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2849
|
-
return {
|
2850
|
-
attribute,
|
2851
|
-
disabled: !metadata.editable,
|
2852
|
-
hint: metadata.description,
|
2853
|
-
label: metadata.label ?? "",
|
2854
|
-
name: field.name,
|
2855
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2856
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2857
|
-
schemas,
|
2858
|
-
components: components?.schemas ?? {}
|
2859
|
-
}),
|
2860
|
-
placeholder: metadata.placeholder ?? "",
|
2861
|
-
required: attribute.required ?? false,
|
2862
|
-
size: field.size,
|
2863
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2864
|
-
visible: metadata.visible ?? true,
|
2865
|
-
type: attribute.type
|
2866
|
-
};
|
2867
|
-
}).filter((field) => field !== null)
|
2868
|
-
);
|
2869
|
-
};
|
2870
|
-
const formatListLayout = (data, {
|
2871
|
-
schemas,
|
2872
|
-
schema,
|
2873
|
-
components
|
2874
|
-
}) => {
|
2875
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2876
|
-
(acc, [attribute, metadata]) => {
|
2877
|
-
return {
|
2878
|
-
...acc,
|
2879
|
-
[attribute]: metadata.list
|
2880
|
-
};
|
2881
2948
|
},
|
2882
|
-
|
2883
|
-
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
|
2896
|
-
|
2897
|
-
|
2898
|
-
|
2949
|
+
variant: "danger",
|
2950
|
+
position: ["header", "table-row"]
|
2951
|
+
};
|
2952
|
+
};
|
2953
|
+
DeleteAction$1.type = "delete";
|
2954
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2955
|
+
const Panels = () => {
|
2956
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2957
|
+
const [
|
2958
|
+
{
|
2959
|
+
query: { status }
|
2960
|
+
}
|
2961
|
+
] = strapiAdmin.useQueryParams({
|
2962
|
+
status: "draft"
|
2963
|
+
});
|
2964
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2965
|
+
const plugins = strapiAdmin.useStrapiApp("Panels", (state) => state.plugins);
|
2966
|
+
const props = {
|
2967
|
+
activeTab: status,
|
2968
|
+
model,
|
2969
|
+
documentId: id,
|
2970
|
+
document: isCloning ? void 0 : document,
|
2971
|
+
meta: isCloning ? void 0 : meta,
|
2972
|
+
collectionType
|
2973
|
+
};
|
2974
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
2975
|
+
strapiAdmin.DescriptionComponentRenderer,
|
2976
|
+
{
|
2977
|
+
props,
|
2978
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2979
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsxRuntime.jsx(Panel, { ...description, children: content }, id2))
|
2899
2980
|
}
|
2981
|
+
) });
|
2982
|
+
};
|
2983
|
+
const ActionsPanel = () => {
|
2984
|
+
const { formatMessage } = reactIntl.useIntl();
|
2985
|
+
return {
|
2986
|
+
title: formatMessage({
|
2987
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2988
|
+
defaultMessage: "Entry"
|
2989
|
+
}),
|
2990
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(ActionsPanelContent, {})
|
2900
2991
|
};
|
2901
2992
|
};
|
2902
|
-
|
2903
|
-
|
2904
|
-
|
2905
|
-
|
2906
|
-
|
2993
|
+
ActionsPanel.type = "actions";
|
2994
|
+
const ActionsPanelContent = () => {
|
2995
|
+
const isCloning = reactRouterDom.useMatch(CLONE_PATH) !== null;
|
2996
|
+
const [
|
2997
|
+
{
|
2998
|
+
query: { status = "draft" }
|
2907
2999
|
}
|
2908
|
-
|
2909
|
-
|
2910
|
-
|
2911
|
-
|
2912
|
-
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
2920
|
-
|
2921
|
-
|
3000
|
+
] = strapiAdmin.useQueryParams();
|
3001
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
3002
|
+
const plugins = strapiAdmin.useStrapiApp("ActionsPanel", (state) => state.plugins);
|
3003
|
+
const props = {
|
3004
|
+
activeTab: status,
|
3005
|
+
model,
|
3006
|
+
documentId: id,
|
3007
|
+
document: isCloning ? void 0 : document,
|
3008
|
+
meta: isCloning ? void 0 : meta,
|
3009
|
+
collectionType
|
3010
|
+
};
|
3011
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, width: "100%", children: [
|
3012
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
3013
|
+
strapiAdmin.DescriptionComponentRenderer,
|
3014
|
+
{
|
3015
|
+
props,
|
3016
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3017
|
+
children: (actions2) => /* @__PURE__ */ jsxRuntime.jsx(DocumentActions, { actions: actions2 })
|
3018
|
+
}
|
3019
|
+
),
|
3020
|
+
/* @__PURE__ */ jsxRuntime.jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3021
|
+
] });
|
2922
3022
|
};
|
3023
|
+
const Panel = React__namespace.forwardRef(({ children, title }, ref) => {
|
3024
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
3025
|
+
designSystem.Flex,
|
3026
|
+
{
|
3027
|
+
ref,
|
3028
|
+
tag: "aside",
|
3029
|
+
"aria-labelledby": "additional-information",
|
3030
|
+
background: "neutral0",
|
3031
|
+
borderColor: "neutral150",
|
3032
|
+
hasRadius: true,
|
3033
|
+
paddingBottom: 4,
|
3034
|
+
paddingLeft: 4,
|
3035
|
+
paddingRight: 4,
|
3036
|
+
paddingTop: 4,
|
3037
|
+
shadow: "tableShadow",
|
3038
|
+
gap: 3,
|
3039
|
+
direction: "column",
|
3040
|
+
justifyContent: "stretch",
|
3041
|
+
alignItems: "flex-start",
|
3042
|
+
children: [
|
3043
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
|
3044
|
+
children
|
3045
|
+
]
|
3046
|
+
}
|
3047
|
+
);
|
3048
|
+
});
|
2923
3049
|
const ConfirmBulkActionDialog = ({
|
2924
3050
|
onToggleDialog,
|
2925
3051
|
isOpen = false,
|
@@ -3897,6 +4023,15 @@ const { setInitialData } = actions;
|
|
3897
4023
|
const reducer = toolkit.combineReducers({
|
3898
4024
|
app: reducer$1
|
3899
4025
|
});
|
4026
|
+
const FEATURE_ID = "preview";
|
4027
|
+
const previewAdmin = {
|
4028
|
+
bootstrap(app) {
|
4029
|
+
if (!window.strapi.future.isEnabled(FEATURE_ID)) {
|
4030
|
+
return {};
|
4031
|
+
}
|
4032
|
+
console.log("Bootstrapping preview admin");
|
4033
|
+
}
|
4034
|
+
};
|
3900
4035
|
const index = {
|
3901
4036
|
register(app) {
|
3902
4037
|
const cm = new ContentManagerPlugin();
|
@@ -3916,7 +4051,7 @@ const index = {
|
|
3916
4051
|
app.router.addRoute({
|
3917
4052
|
path: "content-manager/*",
|
3918
4053
|
lazy: async () => {
|
3919
|
-
const { Layout } = await Promise.resolve().then(() => require("./layout-
|
4054
|
+
const { Layout } = await Promise.resolve().then(() => require("./layout-Bu-ET7w6.js"));
|
3920
4055
|
return {
|
3921
4056
|
Component: Layout
|
3922
4057
|
};
|
@@ -3929,11 +4064,14 @@ const index = {
|
|
3929
4064
|
if (typeof historyAdmin.bootstrap === "function") {
|
3930
4065
|
historyAdmin.bootstrap(app);
|
3931
4066
|
}
|
4067
|
+
if (typeof previewAdmin.bootstrap === "function") {
|
4068
|
+
previewAdmin.bootstrap(app);
|
4069
|
+
}
|
3932
4070
|
},
|
3933
4071
|
async registerTrads({ locales }) {
|
3934
4072
|
const importedTrads = await Promise.all(
|
3935
4073
|
locales.map((locale) => {
|
3936
|
-
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-
|
4074
|
+
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-C6t7ywEg.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 }) => {
|
3937
4075
|
return {
|
3938
4076
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3939
4077
|
locale
|
@@ -3979,6 +4117,7 @@ exports.getMainField = getMainField;
|
|
3979
4117
|
exports.getTranslation = getTranslation;
|
3980
4118
|
exports.index = index;
|
3981
4119
|
exports.setInitialData = setInitialData;
|
4120
|
+
exports.useContentManagerContext = useContentManagerContext;
|
3982
4121
|
exports.useContentTypeSchema = useContentTypeSchema;
|
3983
4122
|
exports.useDoc = useDoc;
|
3984
4123
|
exports.useDocLayout = useDocLayout;
|
@@ -3991,4 +4130,4 @@ exports.useGetAllDocumentsQuery = useGetAllDocumentsQuery;
|
|
3991
4130
|
exports.useGetContentTypeConfigurationQuery = useGetContentTypeConfigurationQuery;
|
3992
4131
|
exports.useGetInitialDataQuery = useGetInitialDataQuery;
|
3993
4132
|
exports.useUpdateContentTypeConfigurationMutation = useUpdateContentTypeConfigurationMutation;
|
3994
|
-
//# sourceMappingURL=index-
|
4133
|
+
//# sourceMappingURL=index-dFQ_8EM3.js.map
|