@strapi/content-manager 0.0.0-experimental.826f263c58b6886b849d3f03b81f7a530bc51c91 → 0.0.0-experimental.82afe56cecefd0078d534e25909834ecf5fdd404
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/LICENSE +18 -3
- package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -1
- package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js → ComponentConfigurationPage-DMxUlNOo.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js.map → ComponentConfigurationPage-DMxUlNOo.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs → ComponentConfigurationPage-baEkO-OV.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs.map → ComponentConfigurationPage-baEkO-OV.mjs.map} +1 -1
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
- package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js → EditConfigurationPage-CXxV7mKn.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js.map → EditConfigurationPage-CXxV7mKn.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs → EditConfigurationPage-YR8-4VCS.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs.map → EditConfigurationPage-YR8-4VCS.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CoQEnFlC.js → EditViewPage-BfR6jAR6.js} +71 -84
- package/dist/_chunks/EditViewPage-BfR6jAR6.js.map +1 -0
- package/dist/_chunks/EditViewPage-DFF7c27p.mjs +191 -0
- package/dist/_chunks/EditViewPage-DFF7c27p.mjs.map +1 -0
- package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
- package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
- package/dist/_chunks/{Form-Bpig5rch.js → Form-CjcMRP5A.js} +55 -38
- package/dist/_chunks/Form-CjcMRP5A.js.map +1 -0
- package/dist/_chunks/{Form-Dxmihyw8.mjs → Form-MSOSfGGN.mjs} +55 -37
- package/dist/_chunks/Form-MSOSfGGN.mjs.map +1 -0
- package/dist/_chunks/{History-BfX6XmZK.js → History-BgZ7gVuF.js} +208 -138
- package/dist/_chunks/History-BgZ7gVuF.js.map +1 -0
- package/dist/_chunks/{History-BZP8n7KT.mjs → History-WOQNVho-.mjs} +201 -130
- package/dist/_chunks/History-WOQNVho-.mjs.map +1 -0
- package/dist/_chunks/{Field-Cz_J9551.mjs → Input-BkKwZ6Qt.mjs} +1757 -1383
- package/dist/_chunks/Input-BkKwZ6Qt.mjs.map +1 -0
- package/dist/_chunks/{Field-ZdrmmQ4Y.js → Input-BwOibhc3.js} +1748 -1374
- package/dist/_chunks/Input-BwOibhc3.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DxKuVkKz.mjs → ListConfigurationPage-BeXfr6uW.mjs} +63 -52
- package/dist/_chunks/ListConfigurationPage-BeXfr6uW.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-B3CXj8PY.js → ListConfigurationPage-DnJ3nbwL.js} +62 -51
- package/dist/_chunks/ListConfigurationPage-DnJ3nbwL.js.map +1 -0
- package/dist/_chunks/{ListViewPage-Bk9VO__I.js → ListViewPage-CJFDudKl.js} +155 -129
- package/dist/_chunks/ListViewPage-CJFDudKl.js.map +1 -0
- package/dist/_chunks/{ListViewPage-D5D3tVPq.mjs → ListViewPage-VK2v44Q1.mjs} +156 -129
- package/dist/_chunks/ListViewPage-VK2v44Q1.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs → NoContentTypePage-T8ttty6K.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs.map → NoContentTypePage-T8ttty6K.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js → NoContentTypePage-en2PwWgI.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js.map → NoContentTypePage-en2PwWgI.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js → NoPermissionsPage-CcjILry3.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js.map → NoPermissionsPage-CcjILry3.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs → NoPermissionsPage-CokBHhhy.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs.map → NoPermissionsPage-CokBHhhy.mjs.map} +1 -1
- package/dist/_chunks/Preview-BF81YhRj.mjs +287 -0
- package/dist/_chunks/Preview-BF81YhRj.mjs.map +1 -0
- package/dist/_chunks/Preview-DgzAuzWQ.js +305 -0
- package/dist/_chunks/Preview-DgzAuzWQ.js.map +1 -0
- package/dist/_chunks/{Relations-B6B3A3mb.js → Relations-1O-JcM4t.js} +76 -43
- package/dist/_chunks/Relations-1O-JcM4t.js.map +1 -0
- package/dist/_chunks/{Relations-BOYZmuWy.mjs → Relations-BncdhGCd.mjs} +76 -42
- package/dist/_chunks/Relations-BncdhGCd.mjs.map +1 -0
- package/dist/_chunks/{en-Dzv55oQw.mjs → en-BZaUty0m.mjs} +41 -18
- package/dist/_chunks/{en-Dzv55oQw.mjs.map → en-BZaUty0m.mjs.map} +1 -1
- package/dist/_chunks/{en-BN1bvFK7.js → en-CzCnBk4S.js} +41 -18
- package/dist/_chunks/{en-BN1bvFK7.js.map → en-CzCnBk4S.js.map} +1 -1
- package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
- package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
- package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
- package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
- package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
- package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
- package/dist/_chunks/{index-VHviNMeW.mjs → index-DiluOUp6.mjs} +1469 -966
- package/dist/_chunks/index-DiluOUp6.mjs.map +1 -0
- package/dist/_chunks/{index-DzN3kBgx.js → index-EXJvmn4t.js} +1439 -936
- package/dist/_chunks/index-EXJvmn4t.js.map +1 -0
- package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
- package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
- package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
- package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
- package/dist/_chunks/{layout-b91XRlD2.js → layout-4TbKVax8.js} +41 -24
- package/dist/_chunks/layout-4TbKVax8.js.map +1 -0
- package/dist/_chunks/{layout-CPn1PM6x.mjs → layout-mSwsYzxv.mjs} +42 -24
- package/dist/_chunks/layout-mSwsYzxv.mjs.map +1 -0
- 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-BsqxS6tR.mjs → relations--YOvQBqv.mjs} +6 -7
- package/dist/_chunks/relations--YOvQBqv.mjs.map +1 -0
- package/dist/_chunks/{relations-CA7IYmcP.js → relations-Ai6Izh7h.js} +6 -7
- package/dist/_chunks/relations-Ai6Izh7h.js.map +1 -0
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
- package/dist/_chunks/usePrev-CZGy2Vjf.mjs +29 -0
- package/dist/_chunks/usePrev-CZGy2Vjf.mjs.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → usePrev-D5J_2fEu.js} +14 -1
- package/dist/_chunks/usePrev-D5J_2fEu.js.map +1 -0
- package/dist/admin/index.js +3 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +10 -8
- package/dist/admin/src/content-manager.d.ts +3 -2
- package/dist/admin/src/exports.d.ts +2 -1
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
- package/dist/admin/src/history/index.d.ts +3 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +49 -1
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +9 -4
- package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +3 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +5 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +4 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +4 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
- package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +27 -0
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/pages/EditView/utils/data.d.ts +1 -0
- package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
- package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
- package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
- package/dist/admin/src/preview/routes.d.ts +3 -0
- package/dist/admin/src/preview/services/preview.d.ts +3 -0
- package/dist/admin/src/router.d.ts +1 -1
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -20
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +765 -434
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +766 -434
- 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/uid.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +16 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/history/controllers/history-version.d.ts +1 -1
- package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts +3 -3
- 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 +8 -12
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +7 -6
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- 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 +16 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +32 -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 +19 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +12 -10
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +7 -6
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts +2 -2
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- 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 +17 -16
- package/dist/_chunks/EditViewPage-CoQEnFlC.js.map +0 -1
- package/dist/_chunks/EditViewPage-DvaV7U9b.mjs +0 -203
- package/dist/_chunks/EditViewPage-DvaV7U9b.mjs.map +0 -1
- package/dist/_chunks/Field-Cz_J9551.mjs.map +0 -1
- package/dist/_chunks/Field-ZdrmmQ4Y.js.map +0 -1
- package/dist/_chunks/Form-Bpig5rch.js.map +0 -1
- package/dist/_chunks/Form-Dxmihyw8.mjs.map +0 -1
- package/dist/_chunks/History-BZP8n7KT.mjs.map +0 -1
- package/dist/_chunks/History-BfX6XmZK.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-B3CXj8PY.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DxKuVkKz.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-Bk9VO__I.js.map +0 -1
- package/dist/_chunks/ListViewPage-D5D3tVPq.mjs.map +0 -1
- package/dist/_chunks/Relations-B6B3A3mb.js.map +0 -1
- package/dist/_chunks/Relations-BOYZmuWy.mjs.map +0 -1
- package/dist/_chunks/index-DzN3kBgx.js.map +0 -1
- package/dist/_chunks/index-VHviNMeW.mjs.map +0 -1
- package/dist/_chunks/layout-CPn1PM6x.mjs.map +0 -1
- package/dist/_chunks/layout-b91XRlD2.js.map +0 -1
- package/dist/_chunks/relations-BsqxS6tR.mjs.map +0 -1
- package/dist/_chunks/relations-CA7IYmcP.js.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
@@ -1,25 +1,34 @@
|
|
1
|
-
import {
|
1
|
+
import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
|
2
2
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
3
|
-
import { useStrapiApp,
|
4
|
-
import { stringify } from "qs";
|
5
|
-
import { useIntl } from "react-intl";
|
6
|
-
import { useNavigate, useParams, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
|
3
|
+
import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
|
7
4
|
import * as React from "react";
|
8
5
|
import { lazy } from "react";
|
9
|
-
import { Menu, VisuallyHidden, Flex,
|
6
|
+
import { Menu, Button, VisuallyHidden, Flex, Dialog, Modal, Typography, Radio, Status, Box, SingleSelect, SingleSelectOption, IconButton, Loader, Tooltip, LinkButton } from "@strapi/design-system";
|
7
|
+
import mapValues from "lodash/fp/mapValues";
|
8
|
+
import { useIntl } from "react-intl";
|
9
|
+
import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
|
10
10
|
import { styled } from "styled-components";
|
11
11
|
import * as yup from "yup";
|
12
12
|
import { ValidationError } from "yup";
|
13
|
+
import { generateNKeysBetween } from "fractional-indexing";
|
13
14
|
import pipe from "lodash/fp/pipe";
|
15
|
+
import { stringify } from "qs";
|
14
16
|
import { intervalToDuration, isPast } from "date-fns";
|
15
17
|
import { createSlice, combineReducers } from "@reduxjs/toolkit";
|
16
|
-
const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
18
|
+
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
17
19
|
const v = glob[path];
|
18
20
|
if (v) {
|
19
21
|
return typeof v === "function" ? v() : Promise.resolve(v);
|
20
22
|
}
|
21
23
|
return new Promise((_, reject) => {
|
22
|
-
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
24
|
+
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
25
|
+
reject.bind(
|
26
|
+
null,
|
27
|
+
new Error(
|
28
|
+
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
|
29
|
+
)
|
30
|
+
)
|
31
|
+
);
|
23
32
|
});
|
24
33
|
};
|
25
34
|
const PLUGIN_ID = "content-manager";
|
@@ -49,42 +58,6 @@ const useInjectionZone = (area) => {
|
|
49
58
|
const [page, position] = area.split(".");
|
50
59
|
return contentManagerPlugin.getInjectedComponents(page, position);
|
51
60
|
};
|
52
|
-
const HistoryAction = ({ model, document }) => {
|
53
|
-
const { formatMessage } = useIntl();
|
54
|
-
const [{ query }] = useQueryParams();
|
55
|
-
const navigate = useNavigate();
|
56
|
-
const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
|
57
|
-
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
58
|
-
return null;
|
59
|
-
}
|
60
|
-
return {
|
61
|
-
icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
|
62
|
-
label: formatMessage({
|
63
|
-
id: "content-manager.history.document-action",
|
64
|
-
defaultMessage: "Content History"
|
65
|
-
}),
|
66
|
-
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
67
|
-
disabled: (
|
68
|
-
/**
|
69
|
-
* The user is creating a new document.
|
70
|
-
* It hasn't been saved yet, so there's no history to go to
|
71
|
-
*/
|
72
|
-
!document || /**
|
73
|
-
* The document has been created but the current dimension has never been saved.
|
74
|
-
* For example, the user is creating a new locale in an existing document,
|
75
|
-
* so there's no history for the document in that locale
|
76
|
-
*/
|
77
|
-
!document.id || /**
|
78
|
-
* History is only available for content types created by the user.
|
79
|
-
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
80
|
-
* which start with `admin::` or `plugin::`
|
81
|
-
*/
|
82
|
-
!model.startsWith("api::")
|
83
|
-
),
|
84
|
-
position: "header"
|
85
|
-
};
|
86
|
-
};
|
87
|
-
HistoryAction.type = "history";
|
88
61
|
const ID = "id";
|
89
62
|
const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
|
90
63
|
const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
|
@@ -136,6 +109,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
136
109
|
if (!slug) {
|
137
110
|
throw new Error("Cannot find the slug param in the URL");
|
138
111
|
}
|
112
|
+
const [{ rawQuery }] = useQueryParams();
|
139
113
|
const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
|
140
114
|
const contentTypePermissions = React.useMemo(() => {
|
141
115
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -146,7 +120,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
146
120
|
return { ...acc, [action]: [permission] };
|
147
121
|
}, {});
|
148
122
|
}, [slug, userPermissions]);
|
149
|
-
const { isLoading, allowedActions } = useRBAC(
|
123
|
+
const { isLoading, allowedActions } = useRBAC(
|
124
|
+
contentTypePermissions,
|
125
|
+
permissions ?? void 0,
|
126
|
+
// TODO: useRBAC context should be typed and built differently
|
127
|
+
// We are passing raw query as context to the hook so that it can
|
128
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
129
|
+
rawQuery
|
130
|
+
);
|
150
131
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
151
132
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
152
133
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -186,6 +167,113 @@ const extractAndDedupeFields = (permissions = []) => permissions.flatMap((permis
|
|
186
167
|
(field, index2, arr) => arr.indexOf(field) === index2 && typeof field === "string"
|
187
168
|
);
|
188
169
|
const removeNumericalStrings = (arr) => arr.filter((item) => isNaN(Number(item)));
|
170
|
+
const BLOCK_LIST_ATTRIBUTE_KEYS = ["__component", "__temp_key__"];
|
171
|
+
const traverseData = (predicate, transform) => (schema, components = {}) => (data = {}) => {
|
172
|
+
const traverse = (datum, attributes) => {
|
173
|
+
return Object.entries(datum).reduce((acc, [key, value]) => {
|
174
|
+
const attribute = attributes[key];
|
175
|
+
if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === void 0) {
|
176
|
+
acc[key] = value;
|
177
|
+
return acc;
|
178
|
+
}
|
179
|
+
if (attribute.type === "component") {
|
180
|
+
if (attribute.repeatable) {
|
181
|
+
const componentValue = predicate(attribute, value) ? transform(value, attribute) : value;
|
182
|
+
acc[key] = componentValue.map(
|
183
|
+
(componentData) => traverse(componentData, components[attribute.component]?.attributes ?? {})
|
184
|
+
);
|
185
|
+
} else {
|
186
|
+
const componentValue = predicate(attribute, value) ? transform(value, attribute) : value;
|
187
|
+
acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});
|
188
|
+
}
|
189
|
+
} else if (attribute.type === "dynamiczone") {
|
190
|
+
const dynamicZoneValue = predicate(attribute, value) ? transform(value, attribute) : value;
|
191
|
+
acc[key] = dynamicZoneValue.map(
|
192
|
+
(componentData) => traverse(componentData, components[componentData.__component]?.attributes ?? {})
|
193
|
+
);
|
194
|
+
} else if (predicate(attribute, value)) {
|
195
|
+
acc[key] = transform(value, attribute);
|
196
|
+
} else {
|
197
|
+
acc[key] = value;
|
198
|
+
}
|
199
|
+
return acc;
|
200
|
+
}, {});
|
201
|
+
};
|
202
|
+
return traverse(data, schema.attributes);
|
203
|
+
};
|
204
|
+
const removeProhibitedFields = (prohibitedFields) => traverseData(
|
205
|
+
(attribute) => prohibitedFields.includes(attribute.type),
|
206
|
+
() => ""
|
207
|
+
);
|
208
|
+
const prepareRelations = traverseData(
|
209
|
+
(attribute) => attribute.type === "relation",
|
210
|
+
() => ({
|
211
|
+
connect: [],
|
212
|
+
disconnect: []
|
213
|
+
})
|
214
|
+
);
|
215
|
+
const prepareTempKeys = traverseData(
|
216
|
+
(attribute) => attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone",
|
217
|
+
(data) => {
|
218
|
+
if (Array.isArray(data) && data.length > 0) {
|
219
|
+
const keys = generateNKeysBetween(void 0, void 0, data.length);
|
220
|
+
return data.map((datum, index2) => ({
|
221
|
+
...datum,
|
222
|
+
__temp_key__: keys[index2]
|
223
|
+
}));
|
224
|
+
}
|
225
|
+
return data;
|
226
|
+
}
|
227
|
+
);
|
228
|
+
const removeFieldsThatDontExistOnSchema = (schema) => (data) => {
|
229
|
+
const schemaKeys = Object.keys(schema.attributes);
|
230
|
+
const dataKeys = Object.keys(data);
|
231
|
+
const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));
|
232
|
+
const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {
|
233
|
+
delete acc[key];
|
234
|
+
return acc;
|
235
|
+
}, structuredClone(data));
|
236
|
+
return revisedData;
|
237
|
+
};
|
238
|
+
const removeNullValues = (data) => {
|
239
|
+
return Object.entries(data).reduce((acc, [key, value]) => {
|
240
|
+
if (value === null) {
|
241
|
+
return acc;
|
242
|
+
}
|
243
|
+
acc[key] = value;
|
244
|
+
return acc;
|
245
|
+
}, {});
|
246
|
+
};
|
247
|
+
const transformDocument = (schema, components = {}) => (document) => {
|
248
|
+
const transformations = pipe(
|
249
|
+
removeFieldsThatDontExistOnSchema(schema),
|
250
|
+
removeProhibitedFields(["password"])(schema, components),
|
251
|
+
removeNullValues,
|
252
|
+
prepareRelations(schema, components),
|
253
|
+
prepareTempKeys(schema, components)
|
254
|
+
);
|
255
|
+
return transformations(document);
|
256
|
+
};
|
257
|
+
const createDefaultForm = (contentType, components = {}) => {
|
258
|
+
const traverseSchema = (attributes) => {
|
259
|
+
return Object.entries(attributes).reduce((acc, [key, attribute]) => {
|
260
|
+
if ("default" in attribute) {
|
261
|
+
acc[key] = attribute.default;
|
262
|
+
} else if (attribute.type === "component" && attribute.required) {
|
263
|
+
const defaultComponentForm = traverseSchema(components[attribute.component].attributes);
|
264
|
+
if (attribute.repeatable) {
|
265
|
+
acc[key] = attribute.min ? [...Array(attribute.min).fill(defaultComponentForm)] : [];
|
266
|
+
} else {
|
267
|
+
acc[key] = defaultComponentForm;
|
268
|
+
}
|
269
|
+
} else if (attribute.type === "dynamiczone" && attribute.required) {
|
270
|
+
acc[key] = [];
|
271
|
+
}
|
272
|
+
return acc;
|
273
|
+
}, {});
|
274
|
+
};
|
275
|
+
return traverseSchema(contentType.attributes);
|
276
|
+
};
|
189
277
|
const contentManagerApi = adminApi.enhanceEndpoints({
|
190
278
|
addTagTypes: [
|
191
279
|
"ComponentConfiguration",
|
@@ -194,10 +282,13 @@ const contentManagerApi = adminApi.enhanceEndpoints({
|
|
194
282
|
"Document",
|
195
283
|
"InitialData",
|
196
284
|
"HistoryVersion",
|
197
|
-
"Relations"
|
285
|
+
"Relations",
|
286
|
+
"UidAvailability",
|
287
|
+
"RecentDocumentList"
|
198
288
|
]
|
199
289
|
});
|
200
290
|
const documentApi = contentManagerApi.injectEndpoints({
|
291
|
+
overrideExisting: true,
|
201
292
|
endpoints: (builder) => ({
|
202
293
|
autoCloneDocument: builder.mutation({
|
203
294
|
query: ({ model, sourceId, query }) => ({
|
@@ -207,7 +298,12 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
207
298
|
params: query
|
208
299
|
}
|
209
300
|
}),
|
210
|
-
invalidatesTags: (_result,
|
301
|
+
invalidatesTags: (_result, error, { model }) => {
|
302
|
+
if (error) {
|
303
|
+
return [];
|
304
|
+
}
|
305
|
+
return [{ type: "Document", id: `${model}_LIST` }, "RecentDocumentList"];
|
306
|
+
}
|
211
307
|
}),
|
212
308
|
cloneDocument: builder.mutation({
|
213
309
|
query: ({ model, sourceId, data, params }) => ({
|
@@ -218,7 +314,11 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
218
314
|
params
|
219
315
|
}
|
220
316
|
}),
|
221
|
-
invalidatesTags: (_result, _error, { model }) => [
|
317
|
+
invalidatesTags: (_result, _error, { model }) => [
|
318
|
+
{ type: "Document", id: `${model}_LIST` },
|
319
|
+
{ type: "UidAvailability", id: model },
|
320
|
+
"RecentDocumentList"
|
321
|
+
]
|
222
322
|
}),
|
223
323
|
/**
|
224
324
|
* Creates a new collection-type document. This should ONLY be used for collection-types.
|
@@ -235,8 +335,22 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
235
335
|
}),
|
236
336
|
invalidatesTags: (result, _error, { model }) => [
|
237
337
|
{ type: "Document", id: `${model}_LIST` },
|
238
|
-
"Relations"
|
239
|
-
|
338
|
+
"Relations",
|
339
|
+
{ type: "UidAvailability", id: model },
|
340
|
+
"RecentDocumentList"
|
341
|
+
],
|
342
|
+
transformResponse: (response, meta, arg) => {
|
343
|
+
if (!("data" in response) && arg.model === "plugin::users-permissions.user") {
|
344
|
+
return {
|
345
|
+
data: response,
|
346
|
+
meta: {
|
347
|
+
availableStatus: [],
|
348
|
+
availableLocales: []
|
349
|
+
}
|
350
|
+
};
|
351
|
+
}
|
352
|
+
return response;
|
353
|
+
}
|
240
354
|
}),
|
241
355
|
deleteDocument: builder.mutation({
|
242
356
|
query: ({ collectionType, model, documentId, params }) => ({
|
@@ -247,7 +361,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
247
361
|
}
|
248
362
|
}),
|
249
363
|
invalidatesTags: (_result, _error, { collectionType, model }) => [
|
250
|
-
{ type: "Document", id: collectionType !== SINGLE_TYPES ? `${model}_LIST` : model }
|
364
|
+
{ type: "Document", id: collectionType !== SINGLE_TYPES ? `${model}_LIST` : model },
|
365
|
+
"RecentDocumentList"
|
251
366
|
]
|
252
367
|
}),
|
253
368
|
deleteManyDocuments: builder.mutation({
|
@@ -259,7 +374,10 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
259
374
|
params
|
260
375
|
}
|
261
376
|
}),
|
262
|
-
invalidatesTags: (_res, _error, { model }) => [
|
377
|
+
invalidatesTags: (_res, _error, { model }) => [
|
378
|
+
{ type: "Document", id: `${model}_LIST` },
|
379
|
+
"RecentDocumentList"
|
380
|
+
]
|
263
381
|
}),
|
264
382
|
discardDocument: builder.mutation({
|
265
383
|
query: ({ collectionType, model, documentId, params }) => ({
|
@@ -276,7 +394,9 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
276
394
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
277
395
|
},
|
278
396
|
{ type: "Document", id: `${model}_LIST` },
|
279
|
-
"Relations"
|
397
|
+
"Relations",
|
398
|
+
{ type: "UidAvailability", id: model },
|
399
|
+
"RecentDocumentList"
|
280
400
|
];
|
281
401
|
}
|
282
402
|
}),
|
@@ -289,11 +409,12 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
289
409
|
url: `/content-manager/collection-types/${model}`,
|
290
410
|
method: "GET",
|
291
411
|
config: {
|
292
|
-
params
|
412
|
+
params: stringify(params, { encode: true })
|
293
413
|
}
|
294
414
|
}),
|
295
415
|
providesTags: (result, _error, arg) => {
|
296
416
|
return [
|
417
|
+
{ type: "Document", id: `ALL_LIST` },
|
297
418
|
{ type: "Document", id: `${arg.model}_LIST` },
|
298
419
|
...result?.results.map(({ documentId }) => ({
|
299
420
|
type: "Document",
|
@@ -332,6 +453,11 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
332
453
|
{
|
333
454
|
type: "Document",
|
334
455
|
id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
|
456
|
+
},
|
457
|
+
// Make it easy to invalidate all individual documents queries for a model
|
458
|
+
{
|
459
|
+
type: "Document",
|
460
|
+
id: `${model}_ALL_ITEMS`
|
335
461
|
}
|
336
462
|
];
|
337
463
|
}
|
@@ -365,7 +491,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
365
491
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
366
492
|
},
|
367
493
|
{ type: "Document", id: `${model}_LIST` },
|
368
|
-
"Relations"
|
494
|
+
"Relations",
|
495
|
+
"RecentDocumentList"
|
369
496
|
];
|
370
497
|
}
|
371
498
|
}),
|
@@ -395,8 +522,23 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
395
522
|
type: "Document",
|
396
523
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
397
524
|
},
|
398
|
-
"Relations"
|
525
|
+
"Relations",
|
526
|
+
{ type: "UidAvailability", id: model },
|
527
|
+
"RecentDocumentList",
|
528
|
+
"RecentDocumentList"
|
399
529
|
];
|
530
|
+
},
|
531
|
+
async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
|
532
|
+
const patchResult = dispatch(
|
533
|
+
documentApi.util.updateQueryData("getDocument", patch, (draft) => {
|
534
|
+
Object.assign(draft.data, data);
|
535
|
+
})
|
536
|
+
);
|
537
|
+
try {
|
538
|
+
await queryFulfilled;
|
539
|
+
} catch {
|
540
|
+
patchResult.undo();
|
541
|
+
}
|
400
542
|
}
|
401
543
|
}),
|
402
544
|
unpublishDocument: builder.mutation({
|
@@ -413,7 +555,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
413
555
|
{
|
414
556
|
type: "Document",
|
415
557
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
416
|
-
}
|
558
|
+
},
|
559
|
+
"RecentDocumentList"
|
417
560
|
];
|
418
561
|
}
|
419
562
|
}),
|
@@ -426,7 +569,10 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
426
569
|
params
|
427
570
|
}
|
428
571
|
}),
|
429
|
-
invalidatesTags: (_res, _error, { model, documentIds }) =>
|
572
|
+
invalidatesTags: (_res, _error, { model, documentIds }) => [
|
573
|
+
...documentIds.map((id) => ({ type: "Document", id: `${model}_${id}` })),
|
574
|
+
"RecentDocumentList"
|
575
|
+
]
|
430
576
|
})
|
431
577
|
})
|
432
578
|
});
|
@@ -449,8 +595,7 @@ const {
|
|
449
595
|
useUnpublishManyDocumentsMutation
|
450
596
|
} = documentApi;
|
451
597
|
const buildValidParams = (query) => {
|
452
|
-
if (!query)
|
453
|
-
return query;
|
598
|
+
if (!query) return query;
|
454
599
|
const { plugins: _, ...validQueryParams } = {
|
455
600
|
...query,
|
456
601
|
...Object.values(query?.plugins ?? {}).reduce(
|
@@ -458,28 +603,44 @@ const buildValidParams = (query) => {
|
|
458
603
|
{}
|
459
604
|
)
|
460
605
|
};
|
461
|
-
if ("_q" in validQueryParams) {
|
462
|
-
validQueryParams._q = encodeURIComponent(validQueryParams._q);
|
463
|
-
}
|
464
606
|
return validQueryParams;
|
465
607
|
};
|
466
608
|
const isBaseQueryError = (error) => {
|
467
609
|
return error.name !== void 0;
|
468
610
|
};
|
469
|
-
const
|
611
|
+
const arrayValidator = (attribute, options) => ({
|
612
|
+
message: translatedErrors.required,
|
613
|
+
test(value) {
|
614
|
+
if (options.status === "draft") {
|
615
|
+
return true;
|
616
|
+
}
|
617
|
+
if (!attribute.required) {
|
618
|
+
return true;
|
619
|
+
}
|
620
|
+
if (!value) {
|
621
|
+
return false;
|
622
|
+
}
|
623
|
+
if (Array.isArray(value) && value.length === 0) {
|
624
|
+
return false;
|
625
|
+
}
|
626
|
+
return true;
|
627
|
+
}
|
628
|
+
});
|
629
|
+
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
470
630
|
const createModelSchema = (attributes2) => yup.object().shape(
|
471
631
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
472
632
|
if (DOCUMENT_META_FIELDS.includes(name)) {
|
473
633
|
return acc;
|
474
634
|
}
|
475
635
|
const validations = [
|
636
|
+
addNullableValidation,
|
476
637
|
addRequiredValidation,
|
477
638
|
addMinLengthValidation,
|
478
639
|
addMaxLengthValidation,
|
479
640
|
addMinValidation,
|
480
641
|
addMaxValidation,
|
481
642
|
addRegexValidation
|
482
|
-
].map((fn) => fn(attribute));
|
643
|
+
].map((fn) => fn(attribute, options));
|
483
644
|
const transformSchema = pipe(...validations);
|
484
645
|
switch (attribute.type) {
|
485
646
|
case "component": {
|
@@ -489,12 +650,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
489
650
|
...acc,
|
490
651
|
[name]: transformSchema(
|
491
652
|
yup.array().of(createModelSchema(attributes3).nullable(false))
|
492
|
-
)
|
653
|
+
).test(arrayValidator(attribute, options))
|
493
654
|
};
|
494
655
|
} else {
|
495
656
|
return {
|
496
657
|
...acc,
|
497
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
658
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
498
659
|
};
|
499
660
|
}
|
500
661
|
}
|
@@ -516,7 +677,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
516
677
|
}
|
517
678
|
)
|
518
679
|
)
|
519
|
-
)
|
680
|
+
).test(arrayValidator(attribute, options))
|
520
681
|
};
|
521
682
|
case "relation":
|
522
683
|
return {
|
@@ -528,7 +689,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
528
689
|
} else if (Array.isArray(value)) {
|
529
690
|
return yup.array().of(
|
530
691
|
yup.object().shape({
|
531
|
-
id: yup.
|
692
|
+
id: yup.number().required()
|
532
693
|
})
|
533
694
|
);
|
534
695
|
} else if (typeof value === "object") {
|
@@ -580,6 +741,14 @@ const createAttributeSchema = (attribute) => {
|
|
580
741
|
if (!value || typeof value === "string" && value.length === 0) {
|
581
742
|
return true;
|
582
743
|
}
|
744
|
+
if (typeof value === "object") {
|
745
|
+
try {
|
746
|
+
JSON.stringify(value);
|
747
|
+
return true;
|
748
|
+
} catch (err) {
|
749
|
+
return false;
|
750
|
+
}
|
751
|
+
}
|
583
752
|
try {
|
584
753
|
JSON.parse(value);
|
585
754
|
return true;
|
@@ -598,13 +767,7 @@ const createAttributeSchema = (attribute) => {
|
|
598
767
|
return yup.mixed();
|
599
768
|
}
|
600
769
|
};
|
601
|
-
const
|
602
|
-
if (attribute.required) {
|
603
|
-
return schema.required({
|
604
|
-
id: translatedErrors.required.id,
|
605
|
-
defaultMessage: "This field is required."
|
606
|
-
});
|
607
|
-
}
|
770
|
+
const nullableSchema = (schema) => {
|
608
771
|
return schema?.nullable ? schema.nullable() : (
|
609
772
|
// In some cases '.nullable' will not be available on the schema.
|
610
773
|
// e.g. when the schema has been built using yup.lazy (e.g. for relations).
|
@@ -612,7 +775,22 @@ const addRequiredValidation = (attribute) => (schema) => {
|
|
612
775
|
schema
|
613
776
|
);
|
614
777
|
};
|
615
|
-
const
|
778
|
+
const addNullableValidation = () => (schema) => {
|
779
|
+
return nullableSchema(schema);
|
780
|
+
};
|
781
|
+
const addRequiredValidation = (attribute, options) => (schema) => {
|
782
|
+
if (options.status === "draft" || !attribute.required) {
|
783
|
+
return schema;
|
784
|
+
}
|
785
|
+
if (attribute.required && "required" in schema) {
|
786
|
+
return schema.required(translatedErrors.required);
|
787
|
+
}
|
788
|
+
return schema;
|
789
|
+
};
|
790
|
+
const addMinLengthValidation = (attribute, options) => (schema) => {
|
791
|
+
if (options.status === "draft") {
|
792
|
+
return schema;
|
793
|
+
}
|
616
794
|
if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
|
617
795
|
return schema.min(attribute.minLength, {
|
618
796
|
...translatedErrors.minLength,
|
@@ -634,10 +812,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
634
812
|
}
|
635
813
|
return schema;
|
636
814
|
};
|
637
|
-
const addMinValidation = (attribute) => (schema) => {
|
638
|
-
if ("
|
815
|
+
const addMinValidation = (attribute, options) => (schema) => {
|
816
|
+
if (options.status === "draft") {
|
817
|
+
return schema;
|
818
|
+
}
|
819
|
+
if ("min" in attribute && "min" in schema) {
|
639
820
|
const min = toInteger(attribute.min);
|
640
|
-
if (
|
821
|
+
if (min) {
|
641
822
|
return schema.min(min, {
|
642
823
|
...translatedErrors.min,
|
643
824
|
values: {
|
@@ -755,16 +936,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
755
936
|
}, {});
|
756
937
|
return componentsByKey;
|
757
938
|
};
|
758
|
-
const
|
939
|
+
const HOOKS = {
|
940
|
+
/**
|
941
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
942
|
+
* @constant
|
943
|
+
* @type {string}
|
944
|
+
*/
|
945
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
946
|
+
/**
|
947
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
948
|
+
* @constant
|
949
|
+
* @type {string}
|
950
|
+
*/
|
951
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
952
|
+
/**
|
953
|
+
* Hook that allows to mutate the CM's edit view layout
|
954
|
+
* @constant
|
955
|
+
* @type {string}
|
956
|
+
*/
|
957
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
958
|
+
/**
|
959
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
960
|
+
* @constant
|
961
|
+
* @type {string}
|
962
|
+
*/
|
963
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
964
|
+
};
|
965
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
966
|
+
endpoints: (builder) => ({
|
967
|
+
getContentTypeConfiguration: builder.query({
|
968
|
+
query: (uid) => ({
|
969
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
970
|
+
method: "GET"
|
971
|
+
}),
|
972
|
+
transformResponse: (response) => response.data,
|
973
|
+
providesTags: (_result, _error, uid) => [
|
974
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
975
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
976
|
+
]
|
977
|
+
}),
|
978
|
+
getAllContentTypeSettings: builder.query({
|
979
|
+
query: () => "/content-manager/content-types-settings",
|
980
|
+
transformResponse: (response) => response.data,
|
981
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
982
|
+
}),
|
983
|
+
updateContentTypeConfiguration: builder.mutation({
|
984
|
+
query: ({ uid, ...body }) => ({
|
985
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
986
|
+
method: "PUT",
|
987
|
+
data: body
|
988
|
+
}),
|
989
|
+
transformResponse: (response) => response.data,
|
990
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
991
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
992
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
993
|
+
// Is this necessary?
|
994
|
+
{ type: "InitialData" }
|
995
|
+
]
|
996
|
+
})
|
997
|
+
})
|
998
|
+
});
|
999
|
+
const {
|
1000
|
+
useGetContentTypeConfigurationQuery,
|
1001
|
+
useGetAllContentTypeSettingsQuery,
|
1002
|
+
useUpdateContentTypeConfigurationMutation
|
1003
|
+
} = contentTypesApi;
|
1004
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
1005
|
+
const { type } = attribute;
|
1006
|
+
if (type === "relation") {
|
1007
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
1008
|
+
}
|
1009
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
1010
|
+
};
|
1011
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
1012
|
+
if (!mainFieldName) {
|
1013
|
+
return void 0;
|
1014
|
+
}
|
1015
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
1016
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
1017
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
1018
|
+
);
|
1019
|
+
return {
|
1020
|
+
name: mainFieldName,
|
1021
|
+
type: mainFieldType ?? "string"
|
1022
|
+
};
|
1023
|
+
};
|
1024
|
+
const DEFAULT_SETTINGS = {
|
1025
|
+
bulkable: false,
|
1026
|
+
filterable: false,
|
1027
|
+
searchable: false,
|
1028
|
+
pagination: false,
|
1029
|
+
defaultSortBy: "",
|
1030
|
+
defaultSortOrder: "asc",
|
1031
|
+
mainField: "id",
|
1032
|
+
pageSize: 10
|
1033
|
+
};
|
1034
|
+
const useDocumentLayout = (model) => {
|
1035
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
1036
|
+
const [{ query }] = useQueryParams();
|
1037
|
+
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
759
1038
|
const { toggleNotification } = useNotification();
|
760
1039
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1040
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
761
1041
|
const {
|
762
|
-
|
763
|
-
isLoading:
|
764
|
-
|
765
|
-
|
766
|
-
} =
|
767
|
-
const
|
1042
|
+
data,
|
1043
|
+
isLoading: isLoadingConfigs,
|
1044
|
+
error,
|
1045
|
+
isFetching: isFetchingConfigs
|
1046
|
+
} = useGetContentTypeConfigurationQuery(model);
|
1047
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
768
1048
|
React.useEffect(() => {
|
769
1049
|
if (error) {
|
770
1050
|
toggleNotification({
|
@@ -772,40 +1052,284 @@ const useDocument = (args, opts) => {
|
|
772
1052
|
message: formatAPIError(error)
|
773
1053
|
});
|
774
1054
|
}
|
775
|
-
}, [
|
776
|
-
const
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
1055
|
+
}, [error, formatAPIError, toggleNotification]);
|
1056
|
+
const editLayout = React.useMemo(
|
1057
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
1058
|
+
layout: [],
|
1059
|
+
components: {},
|
1060
|
+
metadatas: {},
|
1061
|
+
options: {},
|
1062
|
+
settings: DEFAULT_SETTINGS
|
1063
|
+
},
|
1064
|
+
[data, isLoading, schemas, schema, components]
|
1065
|
+
);
|
1066
|
+
const listLayout = React.useMemo(() => {
|
1067
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
1068
|
+
layout: [],
|
1069
|
+
metadatas: {},
|
1070
|
+
options: {},
|
1071
|
+
settings: DEFAULT_SETTINGS
|
1072
|
+
};
|
1073
|
+
}, [data, isLoading, schemas, schema, components]);
|
1074
|
+
const { layout: edit } = React.useMemo(
|
1075
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
1076
|
+
layout: editLayout,
|
1077
|
+
query
|
1078
|
+
}),
|
1079
|
+
[editLayout, query, runHookWaterfall]
|
1080
|
+
);
|
1081
|
+
return {
|
1082
|
+
error,
|
1083
|
+
isLoading,
|
1084
|
+
edit,
|
1085
|
+
list: listLayout
|
1086
|
+
};
|
1087
|
+
};
|
1088
|
+
const useDocLayout = () => {
|
1089
|
+
const { model } = useDoc();
|
1090
|
+
return useDocumentLayout(model);
|
1091
|
+
};
|
1092
|
+
const formatEditLayout = (data, {
|
1093
|
+
schemas,
|
1094
|
+
schema,
|
1095
|
+
components
|
1096
|
+
}) => {
|
1097
|
+
let currentPanelIndex = 0;
|
1098
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
1099
|
+
data.contentType.layouts.edit,
|
1100
|
+
schema?.attributes,
|
1101
|
+
data.contentType.metadatas,
|
1102
|
+
{ configurations: data.components, schemas: components },
|
1103
|
+
schemas
|
1104
|
+
).reduce((panels, row) => {
|
1105
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
1106
|
+
panels.push([row]);
|
1107
|
+
currentPanelIndex += 2;
|
1108
|
+
} else {
|
1109
|
+
if (!panels[currentPanelIndex]) {
|
1110
|
+
panels.push([row]);
|
1111
|
+
} else {
|
1112
|
+
panels[currentPanelIndex].push(row);
|
1113
|
+
}
|
1114
|
+
}
|
1115
|
+
return panels;
|
1116
|
+
}, []);
|
1117
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
1118
|
+
(acc, [uid, configuration]) => {
|
1119
|
+
acc[uid] = {
|
1120
|
+
layout: convertEditLayoutToFieldLayouts(
|
1121
|
+
configuration.layouts.edit,
|
1122
|
+
components[uid].attributes,
|
1123
|
+
configuration.metadatas,
|
1124
|
+
{ configurations: data.components, schemas: components }
|
1125
|
+
),
|
1126
|
+
settings: {
|
1127
|
+
...configuration.settings,
|
1128
|
+
icon: components[uid].info.icon,
|
1129
|
+
displayName: components[uid].info.displayName
|
1130
|
+
}
|
1131
|
+
};
|
1132
|
+
return acc;
|
1133
|
+
},
|
1134
|
+
{}
|
1135
|
+
);
|
1136
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1137
|
+
(acc, [attribute, metadata]) => {
|
1138
|
+
return {
|
1139
|
+
...acc,
|
1140
|
+
[attribute]: metadata.edit
|
1141
|
+
};
|
1142
|
+
},
|
1143
|
+
{}
|
1144
|
+
);
|
1145
|
+
return {
|
1146
|
+
layout: panelledEditAttributes,
|
1147
|
+
components: componentEditAttributes,
|
1148
|
+
metadatas: editMetadatas,
|
1149
|
+
settings: {
|
1150
|
+
...data.contentType.settings,
|
1151
|
+
displayName: schema?.info.displayName
|
1152
|
+
},
|
1153
|
+
options: {
|
1154
|
+
...schema?.options,
|
1155
|
+
...schema?.pluginOptions,
|
1156
|
+
...data.contentType.options
|
1157
|
+
}
|
1158
|
+
};
|
1159
|
+
};
|
1160
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1161
|
+
return rows.map(
|
1162
|
+
(row) => row.map((field) => {
|
1163
|
+
const attribute = attributes[field.name];
|
1164
|
+
if (!attribute) {
|
1165
|
+
return null;
|
1166
|
+
}
|
1167
|
+
const { edit: metadata } = metadatas[field.name];
|
1168
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1169
|
+
return {
|
1170
|
+
attribute,
|
1171
|
+
disabled: !metadata.editable,
|
1172
|
+
hint: metadata.description,
|
1173
|
+
label: metadata.label ?? "",
|
1174
|
+
name: field.name,
|
1175
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1176
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1177
|
+
schemas,
|
1178
|
+
components: components?.schemas ?? {}
|
1179
|
+
}),
|
1180
|
+
placeholder: metadata.placeholder ?? "",
|
1181
|
+
required: attribute.required ?? false,
|
1182
|
+
size: field.size,
|
1183
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1184
|
+
visible: metadata.visible ?? true,
|
1185
|
+
type: attribute.type
|
1186
|
+
};
|
1187
|
+
}).filter((field) => field !== null)
|
1188
|
+
);
|
1189
|
+
};
|
1190
|
+
const formatListLayout = (data, {
|
1191
|
+
schemas,
|
1192
|
+
schema,
|
1193
|
+
components
|
1194
|
+
}) => {
|
1195
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1196
|
+
(acc, [attribute, metadata]) => {
|
1197
|
+
return {
|
1198
|
+
...acc,
|
1199
|
+
[attribute]: metadata.list
|
1200
|
+
};
|
1201
|
+
},
|
1202
|
+
{}
|
1203
|
+
);
|
1204
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1205
|
+
data.contentType.layouts.list,
|
1206
|
+
schema?.attributes,
|
1207
|
+
listMetadatas,
|
1208
|
+
{ configurations: data.components, schemas: components },
|
1209
|
+
schemas
|
1210
|
+
);
|
1211
|
+
return {
|
1212
|
+
layout: listAttributes,
|
1213
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1214
|
+
metadatas: listMetadatas,
|
1215
|
+
options: {
|
1216
|
+
...schema?.options,
|
1217
|
+
...schema?.pluginOptions,
|
1218
|
+
...data.contentType.options
|
1219
|
+
}
|
1220
|
+
};
|
1221
|
+
};
|
1222
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1223
|
+
return columns.map((name) => {
|
1224
|
+
const attribute = attributes[name];
|
1225
|
+
if (!attribute) {
|
1226
|
+
return null;
|
1227
|
+
}
|
1228
|
+
const metadata = metadatas[name];
|
1229
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1230
|
+
return {
|
1231
|
+
attribute,
|
1232
|
+
label: metadata.label ?? "",
|
1233
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1234
|
+
schemas,
|
1235
|
+
components: components?.schemas ?? {}
|
1236
|
+
}),
|
1237
|
+
name,
|
1238
|
+
searchable: metadata.searchable ?? true,
|
1239
|
+
sortable: metadata.sortable ?? true
|
1240
|
+
};
|
1241
|
+
}).filter((field) => field !== null);
|
1242
|
+
};
|
1243
|
+
const useDocument = (args, opts) => {
|
1244
|
+
const { toggleNotification } = useNotification();
|
1245
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1246
|
+
const { formatMessage } = useIntl();
|
1247
|
+
const {
|
1248
|
+
currentData: data,
|
1249
|
+
isLoading: isLoadingDocument,
|
1250
|
+
isFetching: isFetchingDocument,
|
1251
|
+
error
|
1252
|
+
} = useGetDocumentQuery(args, {
|
1253
|
+
...opts,
|
1254
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1255
|
+
});
|
1256
|
+
const document = data?.data;
|
1257
|
+
const meta = data?.meta;
|
1258
|
+
const {
|
1259
|
+
components,
|
1260
|
+
schema,
|
1261
|
+
schemas,
|
1262
|
+
isLoading: isLoadingSchema
|
1263
|
+
} = useContentTypeSchema(args.model);
|
1264
|
+
const isSingleType = schema?.kind === "singleType";
|
1265
|
+
const getTitle = (mainField) => {
|
1266
|
+
if (mainField !== "id" && document?.[mainField]) {
|
1267
|
+
return document[mainField];
|
1268
|
+
}
|
1269
|
+
if (isSingleType && schema?.info.displayName) {
|
1270
|
+
return schema.info.displayName;
|
1271
|
+
}
|
1272
|
+
return formatMessage({
|
1273
|
+
id: "content-manager.containers.untitled",
|
1274
|
+
defaultMessage: "Untitled"
|
1275
|
+
});
|
1276
|
+
};
|
1277
|
+
React.useEffect(() => {
|
1278
|
+
if (error) {
|
1279
|
+
toggleNotification({
|
1280
|
+
type: "danger",
|
1281
|
+
message: formatAPIError(error)
|
1282
|
+
});
|
1283
|
+
}
|
1284
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1285
|
+
const validationSchema = React.useMemo(() => {
|
1286
|
+
if (!schema) {
|
1287
|
+
return null;
|
1288
|
+
}
|
1289
|
+
return createYupSchema(schema.attributes, components);
|
1290
|
+
}, [schema, components]);
|
1291
|
+
const validate = React.useCallback(
|
1292
|
+
(document2) => {
|
1293
|
+
if (!validationSchema) {
|
1294
|
+
throw new Error(
|
1295
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1296
|
+
);
|
1297
|
+
}
|
1298
|
+
try {
|
1299
|
+
validationSchema.validateSync(document2, { abortEarly: false, strict: true });
|
1300
|
+
return null;
|
1301
|
+
} catch (error2) {
|
1302
|
+
if (error2 instanceof ValidationError) {
|
1303
|
+
return getYupValidationErrors(error2);
|
1304
|
+
}
|
796
1305
|
throw error2;
|
797
1306
|
}
|
798
1307
|
},
|
799
1308
|
[validationSchema]
|
800
1309
|
);
|
1310
|
+
const getInitialFormValues = React.useCallback(
|
1311
|
+
(isCreatingDocument = false) => {
|
1312
|
+
if (!document && !isCreatingDocument && !isSingleType || !schema) {
|
1313
|
+
return void 0;
|
1314
|
+
}
|
1315
|
+
const form = document?.id ? document : createDefaultForm(schema, components);
|
1316
|
+
return transformDocument(schema, components)(form);
|
1317
|
+
},
|
1318
|
+
[document, isSingleType, schema, components]
|
1319
|
+
);
|
801
1320
|
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1321
|
+
const hasError = !!error;
|
802
1322
|
return {
|
803
1323
|
components,
|
804
|
-
document
|
805
|
-
meta
|
1324
|
+
document,
|
1325
|
+
meta,
|
806
1326
|
isLoading,
|
1327
|
+
hasError,
|
807
1328
|
schema,
|
808
|
-
|
1329
|
+
schemas,
|
1330
|
+
validate,
|
1331
|
+
getTitle,
|
1332
|
+
getInitialFormValues
|
809
1333
|
};
|
810
1334
|
};
|
811
1335
|
const useDoc = () => {
|
@@ -818,22 +1342,60 @@ const useDoc = () => {
|
|
818
1342
|
if (!slug) {
|
819
1343
|
throw new Error("Could not find model in url params");
|
820
1344
|
}
|
1345
|
+
const document = useDocument(
|
1346
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1347
|
+
{
|
1348
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1349
|
+
}
|
1350
|
+
);
|
1351
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
821
1352
|
return {
|
822
1353
|
collectionType,
|
823
1354
|
model: slug,
|
824
|
-
id:
|
825
|
-
...
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
1355
|
+
id: returnId,
|
1356
|
+
...document
|
1357
|
+
};
|
1358
|
+
};
|
1359
|
+
const useContentManagerContext = () => {
|
1360
|
+
const {
|
1361
|
+
collectionType,
|
1362
|
+
model,
|
1363
|
+
id,
|
1364
|
+
components,
|
1365
|
+
isLoading: isLoadingDoc,
|
1366
|
+
schema,
|
1367
|
+
schemas
|
1368
|
+
} = useDoc();
|
1369
|
+
const layout = useDocumentLayout(model);
|
1370
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1371
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1372
|
+
const slug = model;
|
1373
|
+
const isCreatingEntry = id === "create";
|
1374
|
+
useContentTypeSchema();
|
1375
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1376
|
+
const error = layout.error;
|
1377
|
+
return {
|
1378
|
+
error,
|
1379
|
+
isLoading,
|
1380
|
+
// Base metadata
|
1381
|
+
model,
|
1382
|
+
collectionType,
|
1383
|
+
id,
|
1384
|
+
slug,
|
1385
|
+
isCreatingEntry,
|
1386
|
+
isSingleType,
|
1387
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1388
|
+
// All schema infos
|
1389
|
+
components,
|
1390
|
+
contentType: schema,
|
1391
|
+
contentTypes: schemas,
|
1392
|
+
// Form state
|
1393
|
+
form,
|
1394
|
+
// layout infos
|
1395
|
+
layout
|
831
1396
|
};
|
832
1397
|
};
|
833
1398
|
const prefixPluginTranslations = (trad, pluginId) => {
|
834
|
-
if (!pluginId) {
|
835
|
-
throw new TypeError("pluginId can't be empty");
|
836
|
-
}
|
837
1399
|
return Object.keys(trad).reduce((acc, current) => {
|
838
1400
|
acc[`${pluginId}.${current}`] = trad[current];
|
839
1401
|
return acc;
|
@@ -849,6 +1411,8 @@ const useDocumentActions = () => {
|
|
849
1411
|
const { formatMessage } = useIntl();
|
850
1412
|
const { trackUsage } = useTracking();
|
851
1413
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1414
|
+
const navigate = useNavigate();
|
1415
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
852
1416
|
const [deleteDocument] = useDeleteDocumentMutation();
|
853
1417
|
const _delete = React.useCallback(
|
854
1418
|
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
@@ -927,12 +1491,13 @@ const useDocumentActions = () => {
|
|
927
1491
|
);
|
928
1492
|
const [discardDocument] = useDiscardDocumentMutation();
|
929
1493
|
const discard = React.useCallback(
|
930
|
-
async ({ collectionType, model, documentId }) => {
|
1494
|
+
async ({ collectionType, model, documentId, params }) => {
|
931
1495
|
try {
|
932
1496
|
const res = await discardDocument({
|
933
1497
|
collectionType,
|
934
1498
|
model,
|
935
|
-
documentId
|
1499
|
+
documentId,
|
1500
|
+
params
|
936
1501
|
});
|
937
1502
|
if ("error" in res) {
|
938
1503
|
toggleNotification({
|
@@ -1162,6 +1727,7 @@ const useDocumentActions = () => {
|
|
1162
1727
|
defaultMessage: "Saved document"
|
1163
1728
|
})
|
1164
1729
|
});
|
1730
|
+
setCurrentStep("contentManager.success");
|
1165
1731
|
return res.data;
|
1166
1732
|
} catch (err) {
|
1167
1733
|
toggleNotification({
|
@@ -1183,7 +1749,6 @@ const useDocumentActions = () => {
|
|
1183
1749
|
sourceId
|
1184
1750
|
});
|
1185
1751
|
if ("error" in res) {
|
1186
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1187
1752
|
return { error: res.error };
|
1188
1753
|
}
|
1189
1754
|
toggleNotification({
|
@@ -1202,7 +1767,7 @@ const useDocumentActions = () => {
|
|
1202
1767
|
throw err;
|
1203
1768
|
}
|
1204
1769
|
},
|
1205
|
-
[autoCloneDocument,
|
1770
|
+
[autoCloneDocument, formatMessage, toggleNotification]
|
1206
1771
|
);
|
1207
1772
|
const [cloneDocument] = useCloneDocumentMutation();
|
1208
1773
|
const clone = React.useCallback(
|
@@ -1228,6 +1793,7 @@ const useDocumentActions = () => {
|
|
1228
1793
|
defaultMessage: "Cloned document"
|
1229
1794
|
})
|
1230
1795
|
});
|
1796
|
+
navigate(`../../${res.data.data.documentId}`, { relative: "path" });
|
1231
1797
|
return res.data;
|
1232
1798
|
} catch (err) {
|
1233
1799
|
toggleNotification({
|
@@ -1238,7 +1804,7 @@ const useDocumentActions = () => {
|
|
1238
1804
|
throw err;
|
1239
1805
|
}
|
1240
1806
|
},
|
1241
|
-
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
|
1807
|
+
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
|
1242
1808
|
);
|
1243
1809
|
const [getDoc] = useLazyGetDocumentQuery();
|
1244
1810
|
const getDocument = React.useCallback(
|
@@ -1263,10 +1829,10 @@ const useDocumentActions = () => {
|
|
1263
1829
|
update
|
1264
1830
|
};
|
1265
1831
|
};
|
1266
|
-
const ProtectedHistoryPage = lazy(
|
1267
|
-
() => import("./History-
|
1832
|
+
const ProtectedHistoryPage = React.lazy(
|
1833
|
+
() => import("./History-WOQNVho-.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1268
1834
|
);
|
1269
|
-
const routes$
|
1835
|
+
const routes$2 = [
|
1270
1836
|
{
|
1271
1837
|
path: ":collectionType/:slug/:id/history",
|
1272
1838
|
Component: ProtectedHistoryPage
|
@@ -1276,32 +1842,45 @@ const routes$1 = [
|
|
1276
1842
|
Component: ProtectedHistoryPage
|
1277
1843
|
}
|
1278
1844
|
];
|
1845
|
+
const ProtectedPreviewPage = React.lazy(
|
1846
|
+
() => import("./Preview-BF81YhRj.mjs").then((mod) => ({ default: mod.ProtectedPreviewPage }))
|
1847
|
+
);
|
1848
|
+
const routes$1 = [
|
1849
|
+
{
|
1850
|
+
path: ":collectionType/:slug/:id/preview",
|
1851
|
+
Component: ProtectedPreviewPage
|
1852
|
+
},
|
1853
|
+
{
|
1854
|
+
path: ":collectionType/:slug/preview",
|
1855
|
+
Component: ProtectedPreviewPage
|
1856
|
+
}
|
1857
|
+
];
|
1279
1858
|
const ProtectedEditViewPage = lazy(
|
1280
|
-
() => import("./EditViewPage-
|
1859
|
+
() => import("./EditViewPage-DFF7c27p.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1281
1860
|
);
|
1282
1861
|
const ProtectedListViewPage = lazy(
|
1283
|
-
() => import("./ListViewPage-
|
1862
|
+
() => import("./ListViewPage-VK2v44Q1.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1284
1863
|
);
|
1285
1864
|
const ProtectedListConfiguration = lazy(
|
1286
|
-
() => import("./ListConfigurationPage-
|
1865
|
+
() => import("./ListConfigurationPage-BeXfr6uW.mjs").then((mod) => ({
|
1287
1866
|
default: mod.ProtectedListConfiguration
|
1288
1867
|
}))
|
1289
1868
|
);
|
1290
1869
|
const ProtectedEditConfigurationPage = lazy(
|
1291
|
-
() => import("./EditConfigurationPage-
|
1870
|
+
() => import("./EditConfigurationPage-YR8-4VCS.mjs").then((mod) => ({
|
1292
1871
|
default: mod.ProtectedEditConfigurationPage
|
1293
1872
|
}))
|
1294
1873
|
);
|
1295
1874
|
const ProtectedComponentConfigurationPage = lazy(
|
1296
|
-
() => import("./ComponentConfigurationPage-
|
1875
|
+
() => import("./ComponentConfigurationPage-baEkO-OV.mjs").then((mod) => ({
|
1297
1876
|
default: mod.ProtectedComponentConfigurationPage
|
1298
1877
|
}))
|
1299
1878
|
);
|
1300
1879
|
const NoPermissions = lazy(
|
1301
|
-
() => import("./NoPermissionsPage-
|
1880
|
+
() => import("./NoPermissionsPage-CokBHhhy.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1302
1881
|
);
|
1303
1882
|
const NoContentType = lazy(
|
1304
|
-
() => import("./NoContentTypePage-
|
1883
|
+
() => import("./NoContentTypePage-T8ttty6K.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1305
1884
|
);
|
1306
1885
|
const CollectionTypePages = () => {
|
1307
1886
|
const { collectionType } = useParams();
|
@@ -1313,7 +1892,7 @@ const CollectionTypePages = () => {
|
|
1313
1892
|
const CLONE_RELATIVE_PATH = ":collectionType/:slug/clone/:origin";
|
1314
1893
|
const CLONE_PATH = `/content-manager/${CLONE_RELATIVE_PATH}`;
|
1315
1894
|
const LIST_RELATIVE_PATH = ":collectionType/:slug";
|
1316
|
-
const LIST_PATH = `/content-manager
|
1895
|
+
const LIST_PATH = `/content-manager/collection-types/:slug`;
|
1317
1896
|
const routes = [
|
1318
1897
|
{
|
1319
1898
|
path: LIST_RELATIVE_PATH,
|
@@ -1347,6 +1926,7 @@ const routes = [
|
|
1347
1926
|
path: "no-content-types",
|
1348
1927
|
Component: NoContentType
|
1349
1928
|
},
|
1929
|
+
...routes$2,
|
1350
1930
|
...routes$1
|
1351
1931
|
];
|
1352
1932
|
const DocumentActions = ({ actions: actions2 }) => {
|
@@ -1415,12 +1995,14 @@ const DocumentActionButton = (action) => {
|
|
1415
1995
|
/* @__PURE__ */ jsx(
|
1416
1996
|
Button,
|
1417
1997
|
{
|
1418
|
-
flex:
|
1998
|
+
flex: "auto",
|
1419
1999
|
startIcon: action.icon,
|
1420
2000
|
disabled: action.disabled,
|
1421
2001
|
onClick: handleClick(action),
|
1422
2002
|
justifyContent: "center",
|
1423
2003
|
variant: action.variant || "default",
|
2004
|
+
paddingTop: "7px",
|
2005
|
+
paddingBottom: "7px",
|
1424
2006
|
children: action.label
|
1425
2007
|
}
|
1426
2008
|
),
|
@@ -1428,7 +2010,7 @@ const DocumentActionButton = (action) => {
|
|
1428
2010
|
DocumentActionConfirmDialog,
|
1429
2011
|
{
|
1430
2012
|
...action.dialog,
|
1431
|
-
variant: action.variant,
|
2013
|
+
variant: action.dialog?.variant ?? action.variant,
|
1432
2014
|
isOpen: dialogId === action.id,
|
1433
2015
|
onClose: handleClose
|
1434
2016
|
}
|
@@ -1443,6 +2025,11 @@ const DocumentActionButton = (action) => {
|
|
1443
2025
|
) : null
|
1444
2026
|
] });
|
1445
2027
|
};
|
2028
|
+
const MenuItem = styled(Menu.Item)`
|
2029
|
+
&:hover {
|
2030
|
+
background: ${({ theme, isVariantDanger, isDisabled }) => isVariantDanger && !isDisabled ? theme.colors.danger100 : "neutral"};
|
2031
|
+
}
|
2032
|
+
`;
|
1446
2033
|
const DocumentActionsMenu = ({
|
1447
2034
|
actions: actions2,
|
1448
2035
|
children,
|
@@ -1485,9 +2072,9 @@ const DocumentActionsMenu = ({
|
|
1485
2072
|
disabled: isDisabled,
|
1486
2073
|
size: "S",
|
1487
2074
|
endIcon: null,
|
1488
|
-
paddingTop: "
|
1489
|
-
paddingLeft: "
|
1490
|
-
paddingRight: "
|
2075
|
+
paddingTop: "4px",
|
2076
|
+
paddingLeft: "7px",
|
2077
|
+
paddingRight: "7px",
|
1491
2078
|
variant,
|
1492
2079
|
children: [
|
1493
2080
|
/* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
|
@@ -1498,36 +2085,35 @@ const DocumentActionsMenu = ({
|
|
1498
2085
|
]
|
1499
2086
|
}
|
1500
2087
|
),
|
1501
|
-
/* @__PURE__ */ jsxs(Menu.Content, {
|
2088
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1502
2089
|
actions2.map((action) => {
|
1503
2090
|
return /* @__PURE__ */ jsx(
|
1504
|
-
|
2091
|
+
MenuItem,
|
1505
2092
|
{
|
1506
2093
|
disabled: action.disabled,
|
1507
2094
|
onSelect: handleClick(action),
|
1508
2095
|
display: "block",
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
] })
|
2096
|
+
isVariantDanger: action.variant === "danger",
|
2097
|
+
isDisabled: action.disabled,
|
2098
|
+
children: /* @__PURE__ */ jsx(Flex, { justifyContent: "space-between", gap: 4, children: /* @__PURE__ */ jsxs(
|
2099
|
+
Flex,
|
2100
|
+
{
|
2101
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
2102
|
+
gap: 2,
|
2103
|
+
tag: "span",
|
2104
|
+
children: [
|
2105
|
+
/* @__PURE__ */ jsx(
|
2106
|
+
Flex,
|
2107
|
+
{
|
2108
|
+
tag: "span",
|
2109
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
2110
|
+
children: action.icon
|
2111
|
+
}
|
2112
|
+
),
|
2113
|
+
action.label
|
2114
|
+
]
|
2115
|
+
}
|
2116
|
+
) })
|
1531
2117
|
},
|
1532
2118
|
action.id
|
1533
2119
|
);
|
@@ -1569,6 +2155,18 @@ const convertActionVariantToColor = (variant = "secondary") => {
|
|
1569
2155
|
return "primary600";
|
1570
2156
|
}
|
1571
2157
|
};
|
2158
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
2159
|
+
switch (variant) {
|
2160
|
+
case "danger":
|
2161
|
+
return "danger600";
|
2162
|
+
case "secondary":
|
2163
|
+
return "neutral500";
|
2164
|
+
case "success":
|
2165
|
+
return "success600";
|
2166
|
+
default:
|
2167
|
+
return "primary600";
|
2168
|
+
}
|
2169
|
+
};
|
1572
2170
|
const DocumentActionConfirmDialog = ({
|
1573
2171
|
onClose,
|
1574
2172
|
onCancel,
|
@@ -1591,22 +2189,20 @@ const DocumentActionConfirmDialog = ({
|
|
1591
2189
|
}
|
1592
2190
|
onClose();
|
1593
2191
|
};
|
1594
|
-
return /* @__PURE__ */
|
1595
|
-
/* @__PURE__ */ jsx(
|
1596
|
-
/* @__PURE__ */ jsx(
|
1597
|
-
|
1598
|
-
{
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
)
|
1609
|
-
] });
|
2192
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2193
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2194
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: content }),
|
2195
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
2196
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
2197
|
+
id: "app.components.Button.cancel",
|
2198
|
+
defaultMessage: "Cancel"
|
2199
|
+
}) }) }),
|
2200
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
2201
|
+
id: "app.components.Button.confirm",
|
2202
|
+
defaultMessage: "Confirm"
|
2203
|
+
}) })
|
2204
|
+
] })
|
2205
|
+
] }) });
|
1610
2206
|
};
|
1611
2207
|
const DocumentActionModal = ({
|
1612
2208
|
isOpen,
|
@@ -1616,34 +2212,29 @@ const DocumentActionModal = ({
|
|
1616
2212
|
content: Content,
|
1617
2213
|
onModalClose
|
1618
2214
|
}) => {
|
1619
|
-
const id = React.useId();
|
1620
|
-
if (!isOpen) {
|
1621
|
-
return null;
|
1622
|
-
}
|
1623
2215
|
const handleClose = () => {
|
1624
2216
|
if (onClose) {
|
1625
2217
|
onClose();
|
1626
2218
|
}
|
1627
2219
|
onModalClose();
|
1628
2220
|
};
|
1629
|
-
return /* @__PURE__ */
|
1630
|
-
/* @__PURE__ */ jsx(
|
1631
|
-
|
1632
|
-
/* @__PURE__ */ jsx(
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
] });
|
2221
|
+
return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
2222
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
|
2223
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
|
2224
|
+
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
2225
|
+
] }) });
|
2226
|
+
};
|
2227
|
+
const transformData = (data) => {
|
2228
|
+
if (Array.isArray(data)) {
|
2229
|
+
return data.map(transformData);
|
2230
|
+
}
|
2231
|
+
if (typeof data === "object" && data !== null) {
|
2232
|
+
if ("apiData" in data) {
|
2233
|
+
return data.apiData;
|
2234
|
+
}
|
2235
|
+
return mapValues(transformData)(data);
|
2236
|
+
}
|
2237
|
+
return data;
|
1647
2238
|
};
|
1648
2239
|
const PublishAction$1 = ({
|
1649
2240
|
activeTab,
|
@@ -1657,13 +2248,18 @@ const PublishAction$1 = ({
|
|
1657
2248
|
const navigate = useNavigate();
|
1658
2249
|
const { toggleNotification } = useNotification();
|
1659
2250
|
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
2251
|
+
const isListView = useMatch(LIST_PATH) !== null;
|
1660
2252
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
2253
|
+
const { id } = useParams();
|
1661
2254
|
const { formatMessage } = useIntl();
|
1662
|
-
const { canPublish
|
1663
|
-
"PublishAction",
|
1664
|
-
({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
|
1665
|
-
);
|
2255
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1666
2256
|
const { publish } = useDocumentActions();
|
2257
|
+
const [
|
2258
|
+
countDraftRelations,
|
2259
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2260
|
+
] = useLazyGetDraftRelationCountQuery();
|
2261
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
|
2262
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
|
1667
2263
|
const [{ query, rawQuery }] = useQueryParams();
|
1668
2264
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1669
2265
|
const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
@@ -1672,10 +2268,107 @@ const PublishAction$1 = ({
|
|
1672
2268
|
const validate = useForm("PublishAction", (state) => state.validate);
|
1673
2269
|
const setErrors = useForm("PublishAction", (state) => state.setErrors);
|
1674
2270
|
const formValues = useForm("PublishAction", ({ values }) => values);
|
2271
|
+
React.useEffect(() => {
|
2272
|
+
if (isErrorDraftRelations) {
|
2273
|
+
toggleNotification({
|
2274
|
+
type: "danger",
|
2275
|
+
message: formatMessage({
|
2276
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2277
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2278
|
+
})
|
2279
|
+
});
|
2280
|
+
}
|
2281
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2282
|
+
React.useEffect(() => {
|
2283
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2284
|
+
const extractDraftRelations = (data) => {
|
2285
|
+
const relations = data.connect || [];
|
2286
|
+
relations.forEach((relation) => {
|
2287
|
+
if (relation.status === "draft") {
|
2288
|
+
localDraftRelations.add(relation.id);
|
2289
|
+
}
|
2290
|
+
});
|
2291
|
+
};
|
2292
|
+
const traverseAndExtract = (data) => {
|
2293
|
+
Object.entries(data).forEach(([key, value]) => {
|
2294
|
+
if (key === "connect" && Array.isArray(value)) {
|
2295
|
+
extractDraftRelations({ connect: value });
|
2296
|
+
} else if (typeof value === "object" && value !== null) {
|
2297
|
+
traverseAndExtract(value);
|
2298
|
+
}
|
2299
|
+
});
|
2300
|
+
};
|
2301
|
+
if (!documentId || modified) {
|
2302
|
+
traverseAndExtract(formValues);
|
2303
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2304
|
+
}
|
2305
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2306
|
+
React.useEffect(() => {
|
2307
|
+
if (!document || !document.documentId || isListView) {
|
2308
|
+
return;
|
2309
|
+
}
|
2310
|
+
const fetchDraftRelationsCount = async () => {
|
2311
|
+
const { data, error } = await countDraftRelations({
|
2312
|
+
collectionType,
|
2313
|
+
model,
|
2314
|
+
documentId,
|
2315
|
+
params
|
2316
|
+
});
|
2317
|
+
if (error) {
|
2318
|
+
throw error;
|
2319
|
+
}
|
2320
|
+
if (data) {
|
2321
|
+
setServerCountOfDraftRelations(data.data);
|
2322
|
+
}
|
2323
|
+
};
|
2324
|
+
fetchDraftRelationsCount();
|
2325
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
1675
2326
|
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1676
2327
|
if (!schema?.options?.draftAndPublish) {
|
1677
2328
|
return null;
|
1678
2329
|
}
|
2330
|
+
const performPublish = async () => {
|
2331
|
+
setSubmitting(true);
|
2332
|
+
try {
|
2333
|
+
const { errors } = await validate(true, {
|
2334
|
+
status: "published"
|
2335
|
+
});
|
2336
|
+
if (errors) {
|
2337
|
+
toggleNotification({
|
2338
|
+
type: "danger",
|
2339
|
+
message: formatMessage({
|
2340
|
+
id: "content-manager.validation.error",
|
2341
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2342
|
+
})
|
2343
|
+
});
|
2344
|
+
return;
|
2345
|
+
}
|
2346
|
+
const res = await publish(
|
2347
|
+
{
|
2348
|
+
collectionType,
|
2349
|
+
model,
|
2350
|
+
documentId,
|
2351
|
+
params
|
2352
|
+
},
|
2353
|
+
transformData(formValues)
|
2354
|
+
);
|
2355
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2356
|
+
if (id === "create") {
|
2357
|
+
navigate({
|
2358
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2359
|
+
search: rawQuery
|
2360
|
+
});
|
2361
|
+
}
|
2362
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2363
|
+
setErrors(formatValidationErrors(res.error));
|
2364
|
+
}
|
2365
|
+
} finally {
|
2366
|
+
setSubmitting(false);
|
2367
|
+
}
|
2368
|
+
};
|
2369
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2370
|
+
const enableDraftRelationsCount = false;
|
2371
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
1679
2372
|
return {
|
1680
2373
|
/**
|
1681
2374
|
* Disabled when:
|
@@ -1685,52 +2378,40 @@ const PublishAction$1 = ({
|
|
1685
2378
|
* - the document is already published & not modified
|
1686
2379
|
* - the document is being created & not modified
|
1687
2380
|
* - the user doesn't have the permission to publish
|
1688
|
-
* - the user doesn't have the permission to create a new document
|
1689
|
-
* - the user doesn't have the permission to update the document
|
1690
2381
|
*/
|
1691
|
-
disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish
|
2382
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1692
2383
|
label: formatMessage({
|
1693
2384
|
id: "app.utils.publish",
|
1694
2385
|
defaultMessage: "Publish"
|
1695
2386
|
}),
|
1696
2387
|
onClick: async () => {
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
documentId,
|
1715
|
-
params
|
1716
|
-
},
|
1717
|
-
formValues
|
1718
|
-
);
|
1719
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1720
|
-
navigate({
|
1721
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1722
|
-
search: rawQuery
|
1723
|
-
});
|
1724
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1725
|
-
setErrors(formatValidationErrors(res.error));
|
2388
|
+
await performPublish();
|
2389
|
+
},
|
2390
|
+
dialog: hasDraftRelations ? {
|
2391
|
+
type: "dialog",
|
2392
|
+
variant: "danger",
|
2393
|
+
footer: null,
|
2394
|
+
title: formatMessage({
|
2395
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2396
|
+
defaultMessage: "Confirmation"
|
2397
|
+
}),
|
2398
|
+
content: formatMessage(
|
2399
|
+
{
|
2400
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2401
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2402
|
+
},
|
2403
|
+
{
|
2404
|
+
count: totalDraftRelations
|
1726
2405
|
}
|
1727
|
-
|
1728
|
-
|
2406
|
+
),
|
2407
|
+
onConfirm: async () => {
|
2408
|
+
await performPublish();
|
1729
2409
|
}
|
1730
|
-
}
|
2410
|
+
} : void 0
|
1731
2411
|
};
|
1732
2412
|
};
|
1733
2413
|
PublishAction$1.type = "publish";
|
2414
|
+
PublishAction$1.position = "panel";
|
1734
2415
|
const UpdateAction = ({
|
1735
2416
|
activeTab,
|
1736
2417
|
documentId,
|
@@ -1743,10 +2424,6 @@ const UpdateAction = ({
|
|
1743
2424
|
const cloneMatch = useMatch(CLONE_PATH);
|
1744
2425
|
const isCloning = cloneMatch !== null;
|
1745
2426
|
const { formatMessage } = useIntl();
|
1746
|
-
const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
|
1747
|
-
canCreate: canCreate2,
|
1748
|
-
canUpdate: canUpdate2
|
1749
|
-
}));
|
1750
2427
|
const { create, update, clone } = useDocumentActions();
|
1751
2428
|
const [{ query, rawQuery }] = useQueryParams();
|
1752
2429
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
@@ -1757,90 +2434,134 @@ const UpdateAction = ({
|
|
1757
2434
|
const validate = useForm("UpdateAction", (state) => state.validate);
|
1758
2435
|
const setErrors = useForm("UpdateAction", (state) => state.setErrors);
|
1759
2436
|
const resetForm = useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
}
|
1786
|
-
|
1787
|
-
|
1788
|
-
if (
|
1789
|
-
|
2437
|
+
const handleUpdate = React.useCallback(async () => {
|
2438
|
+
setSubmitting(true);
|
2439
|
+
try {
|
2440
|
+
if (!modified) {
|
2441
|
+
return;
|
2442
|
+
}
|
2443
|
+
const { errors } = await validate(true, {
|
2444
|
+
status: "draft"
|
2445
|
+
});
|
2446
|
+
if (errors) {
|
2447
|
+
toggleNotification({
|
2448
|
+
type: "danger",
|
2449
|
+
message: formatMessage({
|
2450
|
+
id: "content-manager.validation.error",
|
2451
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2452
|
+
})
|
2453
|
+
});
|
2454
|
+
return;
|
2455
|
+
}
|
2456
|
+
if (isCloning) {
|
2457
|
+
const res = await clone(
|
2458
|
+
{
|
2459
|
+
model,
|
2460
|
+
documentId: cloneMatch.params.origin,
|
2461
|
+
params
|
2462
|
+
},
|
2463
|
+
transformData(document)
|
2464
|
+
);
|
2465
|
+
if ("data" in res) {
|
2466
|
+
navigate(
|
1790
2467
|
{
|
1791
|
-
|
1792
|
-
documentId: cloneMatch.params.origin,
|
1793
|
-
params
|
1794
|
-
},
|
1795
|
-
document
|
1796
|
-
);
|
1797
|
-
if ("data" in res) {
|
1798
|
-
navigate({
|
1799
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2468
|
+
pathname: `../${res.data.documentId}`,
|
1800
2469
|
search: rawQuery
|
1801
|
-
});
|
1802
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1803
|
-
setErrors(formatValidationErrors(res.error));
|
1804
|
-
}
|
1805
|
-
} else if (documentId || collectionType === SINGLE_TYPES) {
|
1806
|
-
const res = await update(
|
1807
|
-
{
|
1808
|
-
collectionType,
|
1809
|
-
model,
|
1810
|
-
documentId,
|
1811
|
-
params
|
1812
2470
|
},
|
1813
|
-
|
2471
|
+
{ relative: "path" }
|
1814
2472
|
);
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
2473
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2474
|
+
setErrors(formatValidationErrors(res.error));
|
2475
|
+
}
|
2476
|
+
} else if (documentId || collectionType === SINGLE_TYPES) {
|
2477
|
+
const res = await update(
|
2478
|
+
{
|
2479
|
+
collectionType,
|
2480
|
+
model,
|
2481
|
+
documentId,
|
2482
|
+
params
|
2483
|
+
},
|
2484
|
+
transformData(document)
|
2485
|
+
);
|
2486
|
+
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2487
|
+
setErrors(formatValidationErrors(res.error));
|
1820
2488
|
} else {
|
1821
|
-
|
2489
|
+
resetForm();
|
2490
|
+
}
|
2491
|
+
} else {
|
2492
|
+
const res = await create(
|
2493
|
+
{
|
2494
|
+
model,
|
2495
|
+
params
|
2496
|
+
},
|
2497
|
+
transformData(document)
|
2498
|
+
);
|
2499
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2500
|
+
navigate(
|
1822
2501
|
{
|
1823
|
-
|
1824
|
-
|
2502
|
+
pathname: `../${res.data.documentId}`,
|
2503
|
+
search: rawQuery
|
1825
2504
|
},
|
1826
|
-
|
2505
|
+
{ replace: true, relative: "path" }
|
1827
2506
|
);
|
1828
|
-
|
1829
|
-
|
1830
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1831
|
-
search: rawQuery
|
1832
|
-
});
|
1833
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1834
|
-
setErrors(formatValidationErrors(res.error));
|
1835
|
-
}
|
2507
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2508
|
+
setErrors(formatValidationErrors(res.error));
|
1836
2509
|
}
|
1837
|
-
} finally {
|
1838
|
-
setSubmitting(false);
|
1839
2510
|
}
|
2511
|
+
} finally {
|
2512
|
+
setSubmitting(false);
|
1840
2513
|
}
|
2514
|
+
}, [
|
2515
|
+
clone,
|
2516
|
+
cloneMatch?.params.origin,
|
2517
|
+
collectionType,
|
2518
|
+
create,
|
2519
|
+
document,
|
2520
|
+
documentId,
|
2521
|
+
formatMessage,
|
2522
|
+
formatValidationErrors,
|
2523
|
+
isCloning,
|
2524
|
+
model,
|
2525
|
+
modified,
|
2526
|
+
navigate,
|
2527
|
+
params,
|
2528
|
+
rawQuery,
|
2529
|
+
resetForm,
|
2530
|
+
setErrors,
|
2531
|
+
setSubmitting,
|
2532
|
+
toggleNotification,
|
2533
|
+
update,
|
2534
|
+
validate
|
2535
|
+
]);
|
2536
|
+
React.useEffect(() => {
|
2537
|
+
const handleKeyDown = (e) => {
|
2538
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
2539
|
+
e.preventDefault();
|
2540
|
+
handleUpdate();
|
2541
|
+
}
|
2542
|
+
};
|
2543
|
+
window.addEventListener("keydown", handleKeyDown);
|
2544
|
+
return () => {
|
2545
|
+
window.removeEventListener("keydown", handleKeyDown);
|
2546
|
+
};
|
2547
|
+
}, [handleUpdate]);
|
2548
|
+
return {
|
2549
|
+
/**
|
2550
|
+
* Disabled when:
|
2551
|
+
* - the form is submitting
|
2552
|
+
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
2553
|
+
* - the active tab is the published tab
|
2554
|
+
*/
|
2555
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
2556
|
+
label: formatMessage({
|
2557
|
+
id: "global.save",
|
2558
|
+
defaultMessage: "Save"
|
2559
|
+
}),
|
2560
|
+
onClick: handleUpdate
|
1841
2561
|
};
|
1842
2562
|
};
|
1843
2563
|
UpdateAction.type = "update";
|
2564
|
+
UpdateAction.position = "panel";
|
1844
2565
|
const UNPUBLISH_DRAFT_OPTIONS = {
|
1845
2566
|
KEEP: "keep",
|
1846
2567
|
DISCARD: "discard"
|
@@ -1861,10 +2582,8 @@ const UnpublishAction$1 = ({
|
|
1861
2582
|
const { toggleNotification } = useNotification();
|
1862
2583
|
const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
|
1863
2584
|
const isDocumentModified = document?.status === "modified";
|
1864
|
-
const handleChange = (
|
1865
|
-
|
1866
|
-
setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1867
|
-
}
|
2585
|
+
const handleChange = (value) => {
|
2586
|
+
setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1868
2587
|
};
|
1869
2588
|
if (!schema?.options?.draftAndPublish) {
|
1870
2589
|
return null;
|
@@ -1875,7 +2594,7 @@ const UnpublishAction$1 = ({
|
|
1875
2594
|
id: "app.utils.unpublish",
|
1876
2595
|
defaultMessage: "Unpublish"
|
1877
2596
|
}),
|
1878
|
-
icon: /* @__PURE__ */ jsx(
|
2597
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
1879
2598
|
onClick: async () => {
|
1880
2599
|
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
1881
2600
|
if (!documentId) {
|
@@ -1914,40 +2633,24 @@ const UnpublishAction$1 = ({
|
|
1914
2633
|
}) })
|
1915
2634
|
] }),
|
1916
2635
|
/* @__PURE__ */ jsxs(
|
1917
|
-
|
2636
|
+
Radio.Group,
|
1918
2637
|
{
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
2638
|
+
defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
|
2639
|
+
name: "discard-options",
|
2640
|
+
"aria-label": formatMessage({
|
2641
|
+
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2642
|
+
defaultMessage: "Choose an option to unpublish the document."
|
2643
|
+
}),
|
2644
|
+
onValueChange: handleChange,
|
1925
2645
|
children: [
|
1926
|
-
/* @__PURE__ */ jsx(
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
1935
|
-
defaultMessage: "Keep draft"
|
1936
|
-
})
|
1937
|
-
}
|
1938
|
-
),
|
1939
|
-
/* @__PURE__ */ jsx(
|
1940
|
-
Radio,
|
1941
|
-
{
|
1942
|
-
checked: !shouldKeepDraft,
|
1943
|
-
value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
|
1944
|
-
name: "discard-options",
|
1945
|
-
children: formatMessage({
|
1946
|
-
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
1947
|
-
defaultMessage: "Replace draft"
|
1948
|
-
})
|
1949
|
-
}
|
1950
|
-
)
|
2646
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2647
|
+
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2648
|
+
defaultMessage: "Keep draft"
|
2649
|
+
}) }),
|
2650
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2651
|
+
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2652
|
+
defaultMessage: "Replace draft"
|
2653
|
+
}) })
|
1951
2654
|
]
|
1952
2655
|
}
|
1953
2656
|
)
|
@@ -1981,6 +2684,7 @@ const UnpublishAction$1 = ({
|
|
1981
2684
|
};
|
1982
2685
|
};
|
1983
2686
|
UnpublishAction$1.type = "unpublish";
|
2687
|
+
UnpublishAction$1.position = "panel";
|
1984
2688
|
const DiscardAction = ({
|
1985
2689
|
activeTab,
|
1986
2690
|
documentId,
|
@@ -2003,7 +2707,7 @@ const DiscardAction = ({
|
|
2003
2707
|
id: "content-manager.actions.discard.label",
|
2004
2708
|
defaultMessage: "Discard changes"
|
2005
2709
|
}),
|
2006
|
-
icon: /* @__PURE__ */ jsx(
|
2710
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
2007
2711
|
position: ["panel", "table-row"],
|
2008
2712
|
variant: "danger",
|
2009
2713
|
dialog: {
|
@@ -2031,11 +2735,7 @@ const DiscardAction = ({
|
|
2031
2735
|
};
|
2032
2736
|
};
|
2033
2737
|
DiscardAction.type = "discard";
|
2034
|
-
|
2035
|
-
path {
|
2036
|
-
fill: currentColor;
|
2037
|
-
}
|
2038
|
-
`;
|
2738
|
+
DiscardAction.position = "panel";
|
2039
2739
|
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2040
2740
|
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2041
2741
|
const RelativeTime = React.forwardRef(
|
@@ -2048,7 +2748,7 @@ const RelativeTime = React.forwardRef(
|
|
2048
2748
|
});
|
2049
2749
|
const unit = intervals.find((intervalUnit) => {
|
2050
2750
|
return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
|
2051
|
-
});
|
2751
|
+
}) ?? "seconds";
|
2052
2752
|
const relativeTime = isPast(timestamp) ? -interval[unit] : interval[unit];
|
2053
2753
|
const customInterval = customIntervals.find(
|
2054
2754
|
(custom) => interval[custom.unit] < custom.threshold
|
@@ -2082,34 +2782,34 @@ const getDisplayName = ({
|
|
2082
2782
|
return email ?? "";
|
2083
2783
|
};
|
2084
2784
|
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2085
|
-
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2086
|
-
const statusVariant = status === "draft" ? "
|
2087
|
-
|
2785
|
+
const DocumentStatus = ({ status = "draft", size = "S", ...restProps }) => {
|
2786
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2787
|
+
const { formatMessage } = useIntl();
|
2788
|
+
return /* @__PURE__ */ jsx(Status, { ...restProps, size, variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: formatMessage({
|
2789
|
+
id: `content-manager.containers.List.${status}`,
|
2790
|
+
defaultMessage: capitalise(status)
|
2791
|
+
}) }) });
|
2088
2792
|
};
|
2089
2793
|
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
2090
2794
|
const { formatMessage } = useIntl();
|
2091
2795
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
2796
|
+
const params = useParams();
|
2092
2797
|
const title = isCreating ? formatMessage({
|
2093
2798
|
id: "content-manager.containers.edit.title.new",
|
2094
2799
|
defaultMessage: "Create an entry"
|
2095
2800
|
}) : documentTitle;
|
2096
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop:
|
2097
|
-
/* @__PURE__ */ jsx(
|
2098
|
-
|
2099
|
-
Flex,
|
2801
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2802
|
+
/* @__PURE__ */ jsx(
|
2803
|
+
BackButton,
|
2100
2804
|
{
|
2101
|
-
|
2102
|
-
justifyContent: "space-between",
|
2103
|
-
paddingTop: 1,
|
2104
|
-
gap: "80px",
|
2105
|
-
alignItems: "flex-start",
|
2106
|
-
children: [
|
2107
|
-
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2108
|
-
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2109
|
-
]
|
2805
|
+
fallback: params.collectionType === SINGLE_TYPES ? void 0 : `../${COLLECTION_TYPES}/${params.slug}`
|
2110
2806
|
}
|
2111
2807
|
),
|
2112
|
-
|
2808
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2809
|
+
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2810
|
+
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2811
|
+
] }),
|
2812
|
+
status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2113
2813
|
] });
|
2114
2814
|
};
|
2115
2815
|
const HeaderToolbar = () => {
|
@@ -2155,7 +2855,7 @@ const HeaderToolbar = () => {
|
|
2155
2855
|
meta: isCloning ? void 0 : meta,
|
2156
2856
|
collectionType
|
2157
2857
|
},
|
2158
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2858
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions("header"),
|
2159
2859
|
children: (actions2) => {
|
2160
2860
|
const headerActions = actions2.filter((action) => {
|
2161
2861
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -2192,12 +2892,12 @@ const Information = ({ activeTab }) => {
|
|
2192
2892
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2193
2893
|
label: formatMessage({
|
2194
2894
|
id: "content-manager.containers.edit.information.last-published.label",
|
2195
|
-
defaultMessage: "
|
2895
|
+
defaultMessage: "Published"
|
2196
2896
|
}),
|
2197
2897
|
value: formatMessage(
|
2198
2898
|
{
|
2199
2899
|
id: "content-manager.containers.edit.information.last-published.value",
|
2200
|
-
defaultMessage: `
|
2900
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2201
2901
|
},
|
2202
2902
|
{
|
2203
2903
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2210,12 +2910,12 @@ const Information = ({ activeTab }) => {
|
|
2210
2910
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2211
2911
|
label: formatMessage({
|
2212
2912
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2213
|
-
defaultMessage: "
|
2913
|
+
defaultMessage: "Updated"
|
2214
2914
|
}),
|
2215
2915
|
value: formatMessage(
|
2216
2916
|
{
|
2217
2917
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2218
|
-
defaultMessage: `
|
2918
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2219
2919
|
},
|
2220
2920
|
{
|
2221
2921
|
time: /* @__PURE__ */ jsx(
|
@@ -2233,12 +2933,12 @@ const Information = ({ activeTab }) => {
|
|
2233
2933
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2234
2934
|
label: formatMessage({
|
2235
2935
|
id: "content-manager.containers.edit.information.document.label",
|
2236
|
-
defaultMessage: "
|
2936
|
+
defaultMessage: "Created"
|
2237
2937
|
}),
|
2238
2938
|
value: formatMessage(
|
2239
2939
|
{
|
2240
2940
|
id: "content-manager.containers.edit.information.document.value",
|
2241
|
-
defaultMessage: `
|
2941
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2242
2942
|
},
|
2243
2943
|
{
|
2244
2944
|
time: /* @__PURE__ */ jsx(
|
@@ -2276,41 +2976,94 @@ const Information = ({ activeTab }) => {
|
|
2276
2976
|
);
|
2277
2977
|
};
|
2278
2978
|
const HeaderActions = ({ actions: actions2 }) => {
|
2279
|
-
|
2280
|
-
|
2979
|
+
const [dialogId, setDialogId] = React.useState(null);
|
2980
|
+
const handleClick = (action) => async (e) => {
|
2981
|
+
if (!("options" in action)) {
|
2982
|
+
const { onClick = () => false, dialog, id } = action;
|
2983
|
+
const muteDialog = await onClick(e);
|
2984
|
+
if (dialog && !muteDialog) {
|
2985
|
+
e.preventDefault();
|
2986
|
+
setDialogId(id);
|
2987
|
+
}
|
2988
|
+
}
|
2989
|
+
};
|
2990
|
+
const handleClose = () => {
|
2991
|
+
setDialogId(null);
|
2992
|
+
};
|
2993
|
+
return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
|
2994
|
+
if (action.options) {
|
2281
2995
|
return /* @__PURE__ */ jsx(
|
2282
2996
|
SingleSelect,
|
2283
2997
|
{
|
2284
2998
|
size: "S",
|
2285
|
-
disabled: action.disabled,
|
2286
|
-
"aria-label": action.label,
|
2287
2999
|
onChange: action.onSelect,
|
2288
|
-
|
3000
|
+
"aria-label": action.label,
|
3001
|
+
...action,
|
2289
3002
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2290
3003
|
},
|
2291
3004
|
action.id
|
2292
3005
|
);
|
2293
3006
|
} else {
|
2294
|
-
|
3007
|
+
if (action.type === "icon") {
|
3008
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
3009
|
+
/* @__PURE__ */ jsx(
|
3010
|
+
IconButton,
|
3011
|
+
{
|
3012
|
+
disabled: action.disabled,
|
3013
|
+
label: action.label,
|
3014
|
+
size: "S",
|
3015
|
+
onClick: handleClick(action),
|
3016
|
+
children: action.icon
|
3017
|
+
}
|
3018
|
+
),
|
3019
|
+
action.dialog ? /* @__PURE__ */ jsx(
|
3020
|
+
HeaderActionDialog,
|
3021
|
+
{
|
3022
|
+
...action.dialog,
|
3023
|
+
isOpen: dialogId === action.id,
|
3024
|
+
onClose: handleClose
|
3025
|
+
}
|
3026
|
+
) : null
|
3027
|
+
] }, action.id);
|
3028
|
+
}
|
2295
3029
|
}
|
2296
3030
|
}) });
|
2297
3031
|
};
|
2298
|
-
const
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
3032
|
+
const HeaderActionDialog = ({
|
3033
|
+
onClose,
|
3034
|
+
onCancel,
|
3035
|
+
title,
|
3036
|
+
content: Content,
|
3037
|
+
isOpen
|
3038
|
+
}) => {
|
3039
|
+
const handleClose = async () => {
|
3040
|
+
if (onCancel) {
|
3041
|
+
await onCancel();
|
3042
|
+
}
|
3043
|
+
onClose();
|
3044
|
+
};
|
3045
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
3046
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
3047
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
|
3048
|
+
] }) });
|
3049
|
+
};
|
3050
|
+
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
3051
|
+
const navigate = useNavigate();
|
3052
|
+
const { formatMessage } = useIntl();
|
3053
|
+
return {
|
3054
|
+
label: formatMessage({
|
3055
|
+
id: "app.links.configure-view",
|
3056
|
+
defaultMessage: "Configure the view"
|
3057
|
+
}),
|
3058
|
+
icon: /* @__PURE__ */ jsx(ListPlus, {}),
|
3059
|
+
onClick: () => {
|
2308
3060
|
navigate(`../${collectionType}/${model}/configurations/edit`);
|
2309
3061
|
},
|
2310
3062
|
position: "header"
|
2311
3063
|
};
|
2312
3064
|
};
|
2313
3065
|
ConfigureTheViewAction.type = "configure-the-view";
|
3066
|
+
ConfigureTheViewAction.position = "header";
|
2314
3067
|
const EditTheModelAction = ({ model }) => {
|
2315
3068
|
const navigate = useNavigate();
|
2316
3069
|
const { formatMessage } = useIntl();
|
@@ -2327,6 +3080,7 @@ const EditTheModelAction = ({ model }) => {
|
|
2327
3080
|
};
|
2328
3081
|
};
|
2329
3082
|
EditTheModelAction.type = "edit-the-model";
|
3083
|
+
EditTheModelAction.position = "header";
|
2330
3084
|
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2331
3085
|
const navigate = useNavigate();
|
2332
3086
|
const { formatMessage } = useIntl();
|
@@ -2335,12 +3089,16 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2335
3089
|
const { delete: deleteAction } = useDocumentActions();
|
2336
3090
|
const { toggleNotification } = useNotification();
|
2337
3091
|
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
3092
|
+
const isLocalized = document?.locale != null;
|
2338
3093
|
return {
|
2339
3094
|
disabled: !canDelete || !document,
|
2340
|
-
label: formatMessage(
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
3095
|
+
label: formatMessage(
|
3096
|
+
{
|
3097
|
+
id: "content-manager.actions.delete.label",
|
3098
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
3099
|
+
},
|
3100
|
+
{ isLocalized }
|
3101
|
+
),
|
2344
3102
|
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2345
3103
|
dialog: {
|
2346
3104
|
type: "dialog",
|
@@ -2396,6 +3154,7 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2396
3154
|
};
|
2397
3155
|
};
|
2398
3156
|
DeleteAction$1.type = "delete";
|
3157
|
+
DeleteAction$1.position = ["header", "table-row"];
|
2399
3158
|
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2400
3159
|
const Panels = () => {
|
2401
3160
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
@@ -2430,7 +3189,7 @@ const ActionsPanel = () => {
|
|
2430
3189
|
return {
|
2431
3190
|
title: formatMessage({
|
2432
3191
|
id: "content-manager.containers.edit.panels.default.title",
|
2433
|
-
defaultMessage: "
|
3192
|
+
defaultMessage: "Entry"
|
2434
3193
|
}),
|
2435
3194
|
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2436
3195
|
};
|
@@ -2458,7 +3217,7 @@ const ActionsPanelContent = () => {
|
|
2458
3217
|
DescriptionComponentRenderer,
|
2459
3218
|
{
|
2460
3219
|
props,
|
2461
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3220
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions("panel"),
|
2462
3221
|
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2463
3222
|
}
|
2464
3223
|
),
|
@@ -2485,314 +3244,12 @@ const Panel = React.forwardRef(({ children, title }, ref) => {
|
|
2485
3244
|
justifyContent: "stretch",
|
2486
3245
|
alignItems: "flex-start",
|
2487
3246
|
children: [
|
2488
|
-
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3247
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
|
2489
3248
|
children
|
2490
3249
|
]
|
2491
3250
|
}
|
2492
|
-
);
|
2493
|
-
});
|
2494
|
-
const HOOKS = {
|
2495
|
-
/**
|
2496
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2497
|
-
* @constant
|
2498
|
-
* @type {string}
|
2499
|
-
*/
|
2500
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2501
|
-
/**
|
2502
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2503
|
-
* @constant
|
2504
|
-
* @type {string}
|
2505
|
-
*/
|
2506
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2507
|
-
/**
|
2508
|
-
* Hook that allows to mutate the CM's edit view layout
|
2509
|
-
* @constant
|
2510
|
-
* @type {string}
|
2511
|
-
*/
|
2512
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2513
|
-
/**
|
2514
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2515
|
-
* @constant
|
2516
|
-
* @type {string}
|
2517
|
-
*/
|
2518
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2519
|
-
};
|
2520
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2521
|
-
endpoints: (builder) => ({
|
2522
|
-
getContentTypeConfiguration: builder.query({
|
2523
|
-
query: (uid) => ({
|
2524
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2525
|
-
method: "GET"
|
2526
|
-
}),
|
2527
|
-
transformResponse: (response) => response.data,
|
2528
|
-
providesTags: (_result, _error, uid) => [
|
2529
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2530
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
2531
|
-
]
|
2532
|
-
}),
|
2533
|
-
getAllContentTypeSettings: builder.query({
|
2534
|
-
query: () => "/content-manager/content-types-settings",
|
2535
|
-
transformResponse: (response) => response.data,
|
2536
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
2537
|
-
}),
|
2538
|
-
updateContentTypeConfiguration: builder.mutation({
|
2539
|
-
query: ({ uid, ...body }) => ({
|
2540
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2541
|
-
method: "PUT",
|
2542
|
-
data: body
|
2543
|
-
}),
|
2544
|
-
transformResponse: (response) => response.data,
|
2545
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
2546
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2547
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
2548
|
-
// Is this necessary?
|
2549
|
-
{ type: "InitialData" }
|
2550
|
-
]
|
2551
|
-
})
|
2552
|
-
})
|
2553
|
-
});
|
2554
|
-
const {
|
2555
|
-
useGetContentTypeConfigurationQuery,
|
2556
|
-
useGetAllContentTypeSettingsQuery,
|
2557
|
-
useUpdateContentTypeConfigurationMutation
|
2558
|
-
} = contentTypesApi;
|
2559
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
2560
|
-
const { type } = attribute;
|
2561
|
-
if (type === "relation") {
|
2562
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
2563
|
-
}
|
2564
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
2565
|
-
};
|
2566
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
2567
|
-
if (!mainFieldName) {
|
2568
|
-
return void 0;
|
2569
|
-
}
|
2570
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
2571
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
2572
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
2573
|
-
);
|
2574
|
-
return {
|
2575
|
-
name: mainFieldName,
|
2576
|
-
type: mainFieldType ?? "string"
|
2577
|
-
};
|
2578
|
-
};
|
2579
|
-
const DEFAULT_SETTINGS = {
|
2580
|
-
bulkable: false,
|
2581
|
-
filterable: false,
|
2582
|
-
searchable: false,
|
2583
|
-
pagination: false,
|
2584
|
-
defaultSortBy: "",
|
2585
|
-
defaultSortOrder: "asc",
|
2586
|
-
mainField: "id",
|
2587
|
-
pageSize: 10
|
2588
|
-
};
|
2589
|
-
const useDocumentLayout = (model) => {
|
2590
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
2591
|
-
const [{ query }] = useQueryParams();
|
2592
|
-
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
2593
|
-
const { toggleNotification } = useNotification();
|
2594
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
2595
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
2596
|
-
const {
|
2597
|
-
data,
|
2598
|
-
isLoading: isLoadingConfigs,
|
2599
|
-
error,
|
2600
|
-
isFetching: isFetchingConfigs
|
2601
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2602
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2603
|
-
React.useEffect(() => {
|
2604
|
-
if (error) {
|
2605
|
-
toggleNotification({
|
2606
|
-
type: "danger",
|
2607
|
-
message: formatAPIError(error)
|
2608
|
-
});
|
2609
|
-
}
|
2610
|
-
}, [error, formatAPIError, toggleNotification]);
|
2611
|
-
const editLayout = React.useMemo(
|
2612
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2613
|
-
layout: [],
|
2614
|
-
components: {},
|
2615
|
-
metadatas: {},
|
2616
|
-
options: {},
|
2617
|
-
settings: DEFAULT_SETTINGS
|
2618
|
-
},
|
2619
|
-
[data, isLoading, schemas, schema, components]
|
2620
|
-
);
|
2621
|
-
const listLayout = React.useMemo(() => {
|
2622
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2623
|
-
layout: [],
|
2624
|
-
metadatas: {},
|
2625
|
-
options: {},
|
2626
|
-
settings: DEFAULT_SETTINGS
|
2627
|
-
};
|
2628
|
-
}, [data, isLoading, schemas, schema, components]);
|
2629
|
-
const { layout: edit } = React.useMemo(
|
2630
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2631
|
-
layout: editLayout,
|
2632
|
-
query
|
2633
|
-
}),
|
2634
|
-
[editLayout, query, runHookWaterfall]
|
2635
|
-
);
|
2636
|
-
return {
|
2637
|
-
error,
|
2638
|
-
isLoading,
|
2639
|
-
edit,
|
2640
|
-
list: listLayout
|
2641
|
-
};
|
2642
|
-
};
|
2643
|
-
const useDocLayout = () => {
|
2644
|
-
const { model } = useDoc();
|
2645
|
-
return useDocumentLayout(model);
|
2646
|
-
};
|
2647
|
-
const formatEditLayout = (data, {
|
2648
|
-
schemas,
|
2649
|
-
schema,
|
2650
|
-
components
|
2651
|
-
}) => {
|
2652
|
-
let currentPanelIndex = 0;
|
2653
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
2654
|
-
data.contentType.layouts.edit,
|
2655
|
-
schema?.attributes,
|
2656
|
-
data.contentType.metadatas,
|
2657
|
-
{ configurations: data.components, schemas: components },
|
2658
|
-
schemas
|
2659
|
-
).reduce((panels, row) => {
|
2660
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2661
|
-
panels.push([row]);
|
2662
|
-
currentPanelIndex += 2;
|
2663
|
-
} else {
|
2664
|
-
if (!panels[currentPanelIndex]) {
|
2665
|
-
panels.push([]);
|
2666
|
-
}
|
2667
|
-
panels[currentPanelIndex].push(row);
|
2668
|
-
}
|
2669
|
-
return panels;
|
2670
|
-
}, []);
|
2671
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
2672
|
-
(acc, [uid, configuration]) => {
|
2673
|
-
acc[uid] = {
|
2674
|
-
layout: convertEditLayoutToFieldLayouts(
|
2675
|
-
configuration.layouts.edit,
|
2676
|
-
components[uid].attributes,
|
2677
|
-
configuration.metadatas
|
2678
|
-
),
|
2679
|
-
settings: {
|
2680
|
-
...configuration.settings,
|
2681
|
-
icon: components[uid].info.icon,
|
2682
|
-
displayName: components[uid].info.displayName
|
2683
|
-
}
|
2684
|
-
};
|
2685
|
-
return acc;
|
2686
|
-
},
|
2687
|
-
{}
|
2688
|
-
);
|
2689
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2690
|
-
(acc, [attribute, metadata]) => {
|
2691
|
-
return {
|
2692
|
-
...acc,
|
2693
|
-
[attribute]: metadata.edit
|
2694
|
-
};
|
2695
|
-
},
|
2696
|
-
{}
|
2697
|
-
);
|
2698
|
-
return {
|
2699
|
-
layout: panelledEditAttributes,
|
2700
|
-
components: componentEditAttributes,
|
2701
|
-
metadatas: editMetadatas,
|
2702
|
-
settings: {
|
2703
|
-
...data.contentType.settings,
|
2704
|
-
displayName: schema?.info.displayName
|
2705
|
-
},
|
2706
|
-
options: {
|
2707
|
-
...schema?.options,
|
2708
|
-
...schema?.pluginOptions,
|
2709
|
-
...data.contentType.options
|
2710
|
-
}
|
2711
|
-
};
|
2712
|
-
};
|
2713
|
-
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
2714
|
-
return rows.map(
|
2715
|
-
(row) => row.map((field) => {
|
2716
|
-
const attribute = attributes[field.name];
|
2717
|
-
if (!attribute) {
|
2718
|
-
return null;
|
2719
|
-
}
|
2720
|
-
const { edit: metadata } = metadatas[field.name];
|
2721
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2722
|
-
return {
|
2723
|
-
attribute,
|
2724
|
-
disabled: !metadata.editable,
|
2725
|
-
hint: metadata.description,
|
2726
|
-
label: metadata.label ?? "",
|
2727
|
-
name: field.name,
|
2728
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2729
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2730
|
-
schemas,
|
2731
|
-
components: components?.schemas ?? {}
|
2732
|
-
}),
|
2733
|
-
placeholder: metadata.placeholder ?? "",
|
2734
|
-
required: attribute.required ?? false,
|
2735
|
-
size: field.size,
|
2736
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2737
|
-
visible: metadata.visible ?? true,
|
2738
|
-
type: attribute.type
|
2739
|
-
};
|
2740
|
-
}).filter((field) => field !== null)
|
2741
|
-
);
|
2742
|
-
};
|
2743
|
-
const formatListLayout = (data, {
|
2744
|
-
schemas,
|
2745
|
-
schema,
|
2746
|
-
components
|
2747
|
-
}) => {
|
2748
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2749
|
-
(acc, [attribute, metadata]) => {
|
2750
|
-
return {
|
2751
|
-
...acc,
|
2752
|
-
[attribute]: metadata.list
|
2753
|
-
};
|
2754
|
-
},
|
2755
|
-
{}
|
2756
|
-
);
|
2757
|
-
const listAttributes = convertListLayoutToFieldLayouts(
|
2758
|
-
data.contentType.layouts.list,
|
2759
|
-
schema?.attributes,
|
2760
|
-
listMetadatas,
|
2761
|
-
{ configurations: data.components, schemas: components },
|
2762
|
-
schemas
|
2763
|
-
);
|
2764
|
-
return {
|
2765
|
-
layout: listAttributes,
|
2766
|
-
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
2767
|
-
metadatas: listMetadatas,
|
2768
|
-
options: {
|
2769
|
-
...schema?.options,
|
2770
|
-
...schema?.pluginOptions,
|
2771
|
-
...data.contentType.options
|
2772
|
-
}
|
2773
|
-
};
|
2774
|
-
};
|
2775
|
-
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
2776
|
-
return columns.map((name) => {
|
2777
|
-
const attribute = attributes[name];
|
2778
|
-
if (!attribute) {
|
2779
|
-
return null;
|
2780
|
-
}
|
2781
|
-
const metadata = metadatas[name];
|
2782
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2783
|
-
return {
|
2784
|
-
attribute,
|
2785
|
-
label: metadata.label ?? "",
|
2786
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2787
|
-
schemas,
|
2788
|
-
components: components?.schemas ?? {}
|
2789
|
-
}),
|
2790
|
-
name,
|
2791
|
-
searchable: metadata.searchable ?? true,
|
2792
|
-
sortable: metadata.sortable ?? true
|
2793
|
-
};
|
2794
|
-
}).filter((field) => field !== null);
|
2795
|
-
};
|
3251
|
+
);
|
3252
|
+
});
|
2796
3253
|
const ConfirmBulkActionDialog = ({
|
2797
3254
|
onToggleDialog,
|
2798
3255
|
isOpen = false,
|
@@ -2800,30 +3257,23 @@ const ConfirmBulkActionDialog = ({
|
|
2800
3257
|
endAction
|
2801
3258
|
}) => {
|
2802
3259
|
const { formatMessage } = useIntl();
|
2803
|
-
return /* @__PURE__ */ jsxs(
|
2804
|
-
Dialog,
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
|
2811
|
-
|
2812
|
-
|
2813
|
-
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
}) }),
|
2821
|
-
endAction
|
2822
|
-
}
|
2823
|
-
)
|
2824
|
-
]
|
2825
|
-
}
|
2826
|
-
);
|
3260
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
3261
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
|
3262
|
+
id: "app.components.ConfirmDialog.title",
|
3263
|
+
defaultMessage: "Confirmation"
|
3264
|
+
}) }),
|
3265
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3266
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3267
|
+
dialogBody
|
3268
|
+
] }) }),
|
3269
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
3270
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
|
3271
|
+
id: "app.components.Button.cancel",
|
3272
|
+
defaultMessage: "Cancel"
|
3273
|
+
}) }) }),
|
3274
|
+
endAction
|
3275
|
+
] })
|
3276
|
+
] }) });
|
2827
3277
|
};
|
2828
3278
|
const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
|
2829
3279
|
const ConfirmDialogPublishAll = ({
|
@@ -2838,6 +3288,7 @@ const ConfirmDialogPublishAll = ({
|
|
2838
3288
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
|
2839
3289
|
const { model, schema } = useDoc();
|
2840
3290
|
const [{ query }] = useQueryParams();
|
3291
|
+
const enableDraftRelationsCount = false;
|
2841
3292
|
const {
|
2842
3293
|
data: countDraftRelations = 0,
|
2843
3294
|
isLoading,
|
@@ -2849,7 +3300,7 @@ const ConfirmDialogPublishAll = ({
|
|
2849
3300
|
locale: query?.plugins?.i18n?.locale
|
2850
3301
|
},
|
2851
3302
|
{
|
2852
|
-
skip:
|
3303
|
+
skip: !enableDraftRelationsCount
|
2853
3304
|
}
|
2854
3305
|
);
|
2855
3306
|
React.useEffect(() => {
|
@@ -2928,16 +3379,30 @@ const formatErrorMessages = (errors, parentKey, formatMessage) => {
|
|
2928
3379
|
)
|
2929
3380
|
);
|
2930
3381
|
} else {
|
2931
|
-
messages.push(
|
3382
|
+
messages.push(
|
3383
|
+
...formatErrorMessages(
|
3384
|
+
// @ts-expect-error TODO: check why value is not compatible with FormErrors
|
3385
|
+
value,
|
3386
|
+
currentKey,
|
3387
|
+
formatMessage
|
3388
|
+
)
|
3389
|
+
);
|
2932
3390
|
}
|
3391
|
+
} else {
|
3392
|
+
messages.push(
|
3393
|
+
formatMessage(
|
3394
|
+
{
|
3395
|
+
id: `${value}.withField`,
|
3396
|
+
defaultMessage: value
|
3397
|
+
},
|
3398
|
+
{ field: currentKey }
|
3399
|
+
)
|
3400
|
+
);
|
2933
3401
|
}
|
2934
3402
|
});
|
2935
3403
|
return messages;
|
2936
3404
|
};
|
2937
|
-
const EntryValidationText = ({
|
2938
|
-
validationErrors,
|
2939
|
-
isPublished = false
|
2940
|
-
}) => {
|
3405
|
+
const EntryValidationText = ({ validationErrors, status }) => {
|
2941
3406
|
const { formatMessage } = useIntl();
|
2942
3407
|
if (validationErrors) {
|
2943
3408
|
const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
|
@@ -2948,7 +3413,7 @@ const EntryValidationText = ({
|
|
2948
3413
|
/* @__PURE__ */ jsx(Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
|
2949
3414
|
] });
|
2950
3415
|
}
|
2951
|
-
if (
|
3416
|
+
if (status === "published") {
|
2952
3417
|
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
2953
3418
|
/* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
|
2954
3419
|
/* @__PURE__ */ jsx(Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
|
@@ -2957,6 +3422,15 @@ const EntryValidationText = ({
|
|
2957
3422
|
}) })
|
2958
3423
|
] });
|
2959
3424
|
}
|
3425
|
+
if (status === "modified") {
|
3426
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3427
|
+
/* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
|
3428
|
+
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
3429
|
+
id: "content-manager.bulk-publish.modified",
|
3430
|
+
defaultMessage: "Ready to publish changes"
|
3431
|
+
}) })
|
3432
|
+
] });
|
3433
|
+
}
|
2960
3434
|
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
2961
3435
|
/* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
|
2962
3436
|
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
@@ -3008,10 +3482,10 @@ const SelectedEntriesTableContent = ({
|
|
3008
3482
|
EntryValidationText,
|
3009
3483
|
{
|
3010
3484
|
validationErrors: validationErrors[row.documentId],
|
3011
|
-
|
3485
|
+
status: row.status
|
3012
3486
|
}
|
3013
3487
|
) }),
|
3014
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
|
3488
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
|
3015
3489
|
IconButton,
|
3016
3490
|
{
|
3017
3491
|
tag: Link,
|
@@ -3020,23 +3494,16 @@ const SelectedEntriesTableContent = ({
|
|
3020
3494
|
search: row.locale && `?plugins[i18n][locale]=${row.locale}`
|
3021
3495
|
},
|
3022
3496
|
state: { from: pathname },
|
3023
|
-
label: formatMessage(
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
{
|
3028
|
-
id: "content-manager.components.ListViewHelperPluginTable.row-line",
|
3029
|
-
defaultMessage: "item line {number}"
|
3030
|
-
},
|
3031
|
-
{ number: index2 + 1 }
|
3032
|
-
)
|
3033
|
-
}
|
3034
|
-
),
|
3497
|
+
label: formatMessage({
|
3498
|
+
id: "content-manager.bulk-publish.edit",
|
3499
|
+
defaultMessage: "Edit"
|
3500
|
+
}),
|
3035
3501
|
target: "_blank",
|
3036
3502
|
marginLeft: "auto",
|
3037
|
-
|
3503
|
+
variant: "ghost",
|
3504
|
+
children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
|
3038
3505
|
}
|
3039
|
-
) })
|
3506
|
+
) }) })
|
3040
3507
|
] }, row.id)) })
|
3041
3508
|
] });
|
3042
3509
|
};
|
@@ -3073,7 +3540,13 @@ const SelectedEntriesModalContent = ({
|
|
3073
3540
|
);
|
3074
3541
|
const { rows, validationErrors } = React.useMemo(() => {
|
3075
3542
|
if (data.length > 0 && schema) {
|
3076
|
-
const validate = createYupSchema(
|
3543
|
+
const validate = createYupSchema(
|
3544
|
+
schema.attributes,
|
3545
|
+
components,
|
3546
|
+
// Since this is the "Publish" action, the validation
|
3547
|
+
// schema must enforce the rules for published entities
|
3548
|
+
{ status: "published" }
|
3549
|
+
);
|
3077
3550
|
const validationErrors2 = {};
|
3078
3551
|
const rows2 = data.map((entry) => {
|
3079
3552
|
try {
|
@@ -3149,7 +3622,7 @@ const SelectedEntriesModalContent = ({
|
|
3149
3622
|
);
|
3150
3623
|
};
|
3151
3624
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
3152
|
-
/* @__PURE__ */ jsxs(
|
3625
|
+
/* @__PURE__ */ jsxs(Modal.Body, { children: [
|
3153
3626
|
/* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
|
3154
3627
|
/* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
|
3155
3628
|
SelectedEntriesTableContent,
|
@@ -3161,27 +3634,24 @@ const SelectedEntriesModalContent = ({
|
|
3161
3634
|
}
|
3162
3635
|
) })
|
3163
3636
|
] }),
|
3164
|
-
/* @__PURE__ */
|
3165
|
-
|
3166
|
-
|
3167
|
-
|
3168
|
-
|
3169
|
-
|
3170
|
-
}) }),
|
3171
|
-
|
3172
|
-
|
3173
|
-
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3182
|
-
] })
|
3183
|
-
}
|
3184
|
-
),
|
3637
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3638
|
+
/* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
|
3639
|
+
id: "app.components.Button.cancel",
|
3640
|
+
defaultMessage: "Cancel"
|
3641
|
+
}) }),
|
3642
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3643
|
+
/* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
|
3644
|
+
/* @__PURE__ */ jsx(
|
3645
|
+
Button,
|
3646
|
+
{
|
3647
|
+
onClick: toggleDialog,
|
3648
|
+
disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
|
3649
|
+
loading: isSubmittingForm,
|
3650
|
+
children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
|
3651
|
+
}
|
3652
|
+
)
|
3653
|
+
] })
|
3654
|
+
] }),
|
3185
3655
|
/* @__PURE__ */ jsx(
|
3186
3656
|
ConfirmDialogPublishAll,
|
3187
3657
|
{
|
@@ -3201,8 +3671,7 @@ const PublishAction = ({ documents, model }) => {
|
|
3201
3671
|
const refetchList = () => {
|
3202
3672
|
contentManagerApi.util.invalidateTags([{ type: "Document", id: `${model}_LIST` }]);
|
3203
3673
|
};
|
3204
|
-
if (!showPublishButton)
|
3205
|
-
return null;
|
3674
|
+
if (!showPublishButton) return null;
|
3206
3675
|
return {
|
3207
3676
|
actionType: "publish",
|
3208
3677
|
variant: "tertiary",
|
@@ -3246,143 +3715,10 @@ const BulkActionsRenderer = () => {
|
|
3246
3715
|
documents: selectedRows
|
3247
3716
|
},
|
3248
3717
|
descriptions: plugins["content-manager"].apis.getBulkActions(),
|
3249
|
-
children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(
|
3718
|
+
children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
|
3250
3719
|
}
|
3251
3720
|
) });
|
3252
3721
|
};
|
3253
|
-
const BulkActionAction = (action) => {
|
3254
|
-
const [dialogId, setDialogId] = React.useState(null);
|
3255
|
-
const { toggleNotification } = useNotification();
|
3256
|
-
const handleClick = (action2) => (e) => {
|
3257
|
-
const { onClick, dialog, id } = action2;
|
3258
|
-
if (onClick) {
|
3259
|
-
onClick(e);
|
3260
|
-
}
|
3261
|
-
if (dialog) {
|
3262
|
-
switch (dialog.type) {
|
3263
|
-
case "notification":
|
3264
|
-
toggleNotification({
|
3265
|
-
title: dialog.title,
|
3266
|
-
message: dialog.content,
|
3267
|
-
type: dialog.status,
|
3268
|
-
timeout: dialog.timeout,
|
3269
|
-
onClose: dialog.onClose
|
3270
|
-
});
|
3271
|
-
break;
|
3272
|
-
case "dialog":
|
3273
|
-
case "modal": {
|
3274
|
-
e.preventDefault();
|
3275
|
-
setDialogId(id);
|
3276
|
-
}
|
3277
|
-
}
|
3278
|
-
}
|
3279
|
-
};
|
3280
|
-
const handleClose = () => {
|
3281
|
-
setDialogId(null);
|
3282
|
-
if (action.dialog?.type === "modal" && action.dialog?.onClose) {
|
3283
|
-
action.dialog.onClose();
|
3284
|
-
}
|
3285
|
-
};
|
3286
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
3287
|
-
/* @__PURE__ */ jsx(
|
3288
|
-
Button,
|
3289
|
-
{
|
3290
|
-
disabled: action.disabled,
|
3291
|
-
startIcon: action.icon,
|
3292
|
-
variant: action.variant,
|
3293
|
-
onClick: handleClick(action),
|
3294
|
-
children: action.label
|
3295
|
-
}
|
3296
|
-
),
|
3297
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
|
3298
|
-
BulkActionConfirmDialog,
|
3299
|
-
{
|
3300
|
-
...action.dialog,
|
3301
|
-
variant: action.variant,
|
3302
|
-
isOpen: dialogId === action.id,
|
3303
|
-
onClose: handleClose
|
3304
|
-
}
|
3305
|
-
) : null,
|
3306
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
|
3307
|
-
BulkActionModal,
|
3308
|
-
{
|
3309
|
-
...action.dialog,
|
3310
|
-
onModalClose: handleClose,
|
3311
|
-
isOpen: dialogId === action.id
|
3312
|
-
}
|
3313
|
-
) : null
|
3314
|
-
] });
|
3315
|
-
};
|
3316
|
-
const BulkActionConfirmDialog = ({
|
3317
|
-
onClose,
|
3318
|
-
onCancel,
|
3319
|
-
onConfirm,
|
3320
|
-
title,
|
3321
|
-
content,
|
3322
|
-
confirmButton,
|
3323
|
-
isOpen,
|
3324
|
-
variant = "secondary"
|
3325
|
-
}) => {
|
3326
|
-
const { formatMessage } = useIntl();
|
3327
|
-
const handleClose = async () => {
|
3328
|
-
if (onCancel) {
|
3329
|
-
await onCancel();
|
3330
|
-
}
|
3331
|
-
onClose();
|
3332
|
-
};
|
3333
|
-
const handleConfirm = async () => {
|
3334
|
-
if (onConfirm) {
|
3335
|
-
await onConfirm();
|
3336
|
-
}
|
3337
|
-
onClose();
|
3338
|
-
};
|
3339
|
-
return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
|
3340
|
-
/* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: content }),
|
3341
|
-
/* @__PURE__ */ jsx(
|
3342
|
-
DialogFooter,
|
3343
|
-
{
|
3344
|
-
startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
|
3345
|
-
id: "app.components.Button.cancel",
|
3346
|
-
defaultMessage: "Cancel"
|
3347
|
-
}) }),
|
3348
|
-
endAction: /* @__PURE__ */ jsx(
|
3349
|
-
Button,
|
3350
|
-
{
|
3351
|
-
onClick: handleConfirm,
|
3352
|
-
variant: variant === "danger-light" ? variant : "secondary",
|
3353
|
-
startIcon: variant === "danger-light" ? /* @__PURE__ */ jsx(Trash, {}) : /* @__PURE__ */ jsx(Check, {}),
|
3354
|
-
children: confirmButton ? confirmButton : formatMessage({
|
3355
|
-
id: "app.components.Button.confirm",
|
3356
|
-
defaultMessage: "Confirm"
|
3357
|
-
})
|
3358
|
-
}
|
3359
|
-
)
|
3360
|
-
}
|
3361
|
-
)
|
3362
|
-
] });
|
3363
|
-
};
|
3364
|
-
const BulkActionModal = ({
|
3365
|
-
isOpen,
|
3366
|
-
title,
|
3367
|
-
onClose,
|
3368
|
-
content: Content,
|
3369
|
-
onModalClose
|
3370
|
-
}) => {
|
3371
|
-
const id = React.useId();
|
3372
|
-
if (!isOpen) {
|
3373
|
-
return null;
|
3374
|
-
}
|
3375
|
-
const handleClose = () => {
|
3376
|
-
if (onClose) {
|
3377
|
-
onClose();
|
3378
|
-
}
|
3379
|
-
onModalClose();
|
3380
|
-
};
|
3381
|
-
return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
|
3382
|
-
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id, children: title }) }),
|
3383
|
-
/* @__PURE__ */ jsx(Content, { onClose: handleClose })
|
3384
|
-
] });
|
3385
|
-
};
|
3386
3722
|
const DeleteAction = ({ documents, model }) => {
|
3387
3723
|
const { formatMessage } = useIntl();
|
3388
3724
|
const { schema: contentType } = useDoc();
|
@@ -3403,8 +3739,7 @@ const DeleteAction = ({ documents, model }) => {
|
|
3403
3739
|
selectRow([]);
|
3404
3740
|
}
|
3405
3741
|
};
|
3406
|
-
if (!hasDeletePermission)
|
3407
|
-
return null;
|
3742
|
+
if (!hasDeletePermission) return null;
|
3408
3743
|
return {
|
3409
3744
|
variant: "danger-light",
|
3410
3745
|
label: formatMessage({ id: "global.delete", defaultMessage: "Delete" }),
|
@@ -3415,6 +3750,7 @@ const DeleteAction = ({ documents, model }) => {
|
|
3415
3750
|
defaultMessage: "Confirmation"
|
3416
3751
|
}),
|
3417
3752
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3753
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3418
3754
|
/* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
3419
3755
|
id: "popUpWarning.bodyMessage.contentType.delete.all",
|
3420
3756
|
defaultMessage: "Are you sure you want to delete these entries?"
|
@@ -3451,9 +3787,8 @@ const UnpublishAction = ({ documents, model }) => {
|
|
3451
3787
|
selectRow([]);
|
3452
3788
|
}
|
3453
3789
|
};
|
3454
|
-
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published");
|
3455
|
-
if (!showUnpublishButton)
|
3456
|
-
return null;
|
3790
|
+
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
|
3791
|
+
if (!showUnpublishButton) return null;
|
3457
3792
|
return {
|
3458
3793
|
variant: "tertiary",
|
3459
3794
|
label: formatMessage({ id: "app.utils.unpublish", defaultMessage: "Unpublish" }),
|
@@ -3464,6 +3799,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
3464
3799
|
defaultMessage: "Confirmation"
|
3465
3800
|
}),
|
3466
3801
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3802
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3467
3803
|
/* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
3468
3804
|
id: "popUpWarning.bodyMessage.contentType.unpublish.all",
|
3469
3805
|
defaultMessage: "Are you sure you want to unpublish these entries?"
|
@@ -3557,7 +3893,7 @@ const TableActions = ({ document }) => {
|
|
3557
3893
|
DescriptionComponentRenderer,
|
3558
3894
|
{
|
3559
3895
|
props,
|
3560
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3896
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions("table-row").filter((action) => action.name !== "PublishAction"),
|
3561
3897
|
children: (actions2) => {
|
3562
3898
|
const tableRowActions = actions2.filter((action) => {
|
3563
3899
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -3616,6 +3952,7 @@ const EditAction = ({ documentId }) => {
|
|
3616
3952
|
};
|
3617
3953
|
};
|
3618
3954
|
EditAction.type = "edit";
|
3955
|
+
EditAction.position = "table-row";
|
3619
3956
|
const StyledPencil = styled(Pencil)`
|
3620
3957
|
path {
|
3621
3958
|
fill: currentColor;
|
@@ -3668,7 +4005,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
3668
4005
|
}),
|
3669
4006
|
content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
|
3670
4007
|
footer: ({ onClose }) => {
|
3671
|
-
return /* @__PURE__ */ jsxs(
|
4008
|
+
return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3672
4009
|
/* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
|
3673
4010
|
id: "cancel",
|
3674
4011
|
defaultMessage: "Cancel"
|
@@ -3692,6 +4029,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
3692
4029
|
};
|
3693
4030
|
};
|
3694
4031
|
CloneAction.type = "clone";
|
4032
|
+
CloneAction.position = "table-row";
|
3695
4033
|
const StyledDuplicate = styled(Duplicate)`
|
3696
4034
|
path {
|
3697
4035
|
fill: currentColor;
|
@@ -3709,8 +4047,7 @@ class ContentManagerPlugin {
|
|
3709
4047
|
documentActions = [
|
3710
4048
|
...DEFAULT_ACTIONS,
|
3711
4049
|
...DEFAULT_TABLE_ROW_ACTIONS,
|
3712
|
-
...DEFAULT_HEADER_ACTIONS
|
3713
|
-
HistoryAction
|
4050
|
+
...DEFAULT_HEADER_ACTIONS
|
3714
4051
|
];
|
3715
4052
|
editViewSidePanels = [ActionsPanel];
|
3716
4053
|
headerActions = [];
|
@@ -3779,7 +4116,14 @@ class ContentManagerPlugin {
|
|
3779
4116
|
addDocumentHeaderAction: this.addDocumentHeaderAction.bind(this),
|
3780
4117
|
addEditViewSidePanel: this.addEditViewSidePanel.bind(this),
|
3781
4118
|
getBulkActions: () => this.bulkActions,
|
3782
|
-
getDocumentActions: () =>
|
4119
|
+
getDocumentActions: (position) => {
|
4120
|
+
if (position) {
|
4121
|
+
return this.documentActions.filter(
|
4122
|
+
(action) => action.position == void 0 || [action.position].flat().includes(position)
|
4123
|
+
);
|
4124
|
+
}
|
4125
|
+
return this.documentActions;
|
4126
|
+
},
|
3783
4127
|
getEditViewSidePanels: () => this.editViewSidePanels,
|
3784
4128
|
getHeaderActions: () => this.headerActions
|
3785
4129
|
}
|
@@ -3789,16 +4133,71 @@ class ContentManagerPlugin {
|
|
3789
4133
|
const getPrintableType = (value) => {
|
3790
4134
|
const nativeType = typeof value;
|
3791
4135
|
if (nativeType === "object") {
|
3792
|
-
if (value === null)
|
3793
|
-
|
3794
|
-
if (Array.isArray(value))
|
3795
|
-
return "array";
|
4136
|
+
if (value === null) return "null";
|
4137
|
+
if (Array.isArray(value)) return "array";
|
3796
4138
|
if (value instanceof Object && value.constructor.name !== "Object") {
|
3797
4139
|
return value.constructor.name;
|
3798
4140
|
}
|
3799
4141
|
}
|
3800
4142
|
return nativeType;
|
3801
4143
|
};
|
4144
|
+
const HistoryAction = ({ model, document }) => {
|
4145
|
+
const { formatMessage } = useIntl();
|
4146
|
+
const [{ query }] = useQueryParams();
|
4147
|
+
const navigate = useNavigate();
|
4148
|
+
const { trackUsage } = useTracking();
|
4149
|
+
const { pathname } = useLocation();
|
4150
|
+
const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
|
4151
|
+
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
4152
|
+
return null;
|
4153
|
+
}
|
4154
|
+
const handleOnClick = () => {
|
4155
|
+
const destination = { pathname: "history", search: pluginsQueryParams };
|
4156
|
+
trackUsage("willNavigate", {
|
4157
|
+
from: pathname,
|
4158
|
+
to: `${pathname}/${destination.pathname}`
|
4159
|
+
});
|
4160
|
+
navigate(destination);
|
4161
|
+
};
|
4162
|
+
return {
|
4163
|
+
icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
|
4164
|
+
label: formatMessage({
|
4165
|
+
id: "content-manager.history.document-action",
|
4166
|
+
defaultMessage: "Content History"
|
4167
|
+
}),
|
4168
|
+
onClick: handleOnClick,
|
4169
|
+
disabled: (
|
4170
|
+
/**
|
4171
|
+
* The user is creating a new document.
|
4172
|
+
* It hasn't been saved yet, so there's no history to go to
|
4173
|
+
*/
|
4174
|
+
!document || /**
|
4175
|
+
* The document has been created but the current dimension has never been saved.
|
4176
|
+
* For example, the user is creating a new locale in an existing document,
|
4177
|
+
* so there's no history for the document in that locale
|
4178
|
+
*/
|
4179
|
+
!document.id || /**
|
4180
|
+
* History is only available for content types created by the user.
|
4181
|
+
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
4182
|
+
* which start with `admin::` or `plugin::`
|
4183
|
+
*/
|
4184
|
+
!model.startsWith("api::")
|
4185
|
+
),
|
4186
|
+
position: "header"
|
4187
|
+
};
|
4188
|
+
};
|
4189
|
+
HistoryAction.type = "history";
|
4190
|
+
HistoryAction.position = "header";
|
4191
|
+
const historyAdmin = {
|
4192
|
+
bootstrap(app) {
|
4193
|
+
const { addDocumentAction } = app.getPlugin("content-manager").apis;
|
4194
|
+
addDocumentAction((actions2) => {
|
4195
|
+
const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
|
4196
|
+
actions2.splice(indexOfDeleteAction, 0, HistoryAction);
|
4197
|
+
return actions2;
|
4198
|
+
});
|
4199
|
+
}
|
4200
|
+
};
|
3802
4201
|
const initialState = {
|
3803
4202
|
collectionTypeLinks: [],
|
3804
4203
|
components: [],
|
@@ -3835,6 +4234,88 @@ const { setInitialData } = actions;
|
|
3835
4234
|
const reducer = combineReducers({
|
3836
4235
|
app: reducer$1
|
3837
4236
|
});
|
4237
|
+
const previewApi = contentManagerApi.injectEndpoints({
|
4238
|
+
endpoints: (builder) => ({
|
4239
|
+
getPreviewUrl: builder.query({
|
4240
|
+
query({ query, params }) {
|
4241
|
+
return {
|
4242
|
+
url: `/content-manager/preview/url/${params.contentType}`,
|
4243
|
+
method: "GET",
|
4244
|
+
config: {
|
4245
|
+
params: query
|
4246
|
+
}
|
4247
|
+
};
|
4248
|
+
}
|
4249
|
+
})
|
4250
|
+
})
|
4251
|
+
});
|
4252
|
+
const { useGetPreviewUrlQuery } = previewApi;
|
4253
|
+
const ConditionalTooltip = ({ isShown, label, children }) => {
|
4254
|
+
if (isShown) {
|
4255
|
+
return /* @__PURE__ */ jsx(Tooltip, { label, children });
|
4256
|
+
}
|
4257
|
+
return children;
|
4258
|
+
};
|
4259
|
+
const PreviewSidePanel = ({ model, documentId, document }) => {
|
4260
|
+
const { formatMessage } = useIntl();
|
4261
|
+
const { trackUsage } = useTracking();
|
4262
|
+
const { pathname } = useLocation();
|
4263
|
+
const [{ query }] = useQueryParams();
|
4264
|
+
const isModified = useForm("PreviewSidePanel", (state) => state.modified);
|
4265
|
+
const { data, error } = useGetPreviewUrlQuery({
|
4266
|
+
params: {
|
4267
|
+
contentType: model
|
4268
|
+
},
|
4269
|
+
query: {
|
4270
|
+
documentId,
|
4271
|
+
locale: document?.locale,
|
4272
|
+
status: document?.status
|
4273
|
+
}
|
4274
|
+
});
|
4275
|
+
if (!data?.data?.url || error) {
|
4276
|
+
return null;
|
4277
|
+
}
|
4278
|
+
const trackNavigation = () => {
|
4279
|
+
const destinationPathname = pathname.replace(/\/$/, "") + "/preview";
|
4280
|
+
trackUsage("willNavigate", { from: pathname, to: destinationPathname });
|
4281
|
+
};
|
4282
|
+
return {
|
4283
|
+
title: formatMessage({ id: "content-manager.preview.panel.title", defaultMessage: "Preview" }),
|
4284
|
+
content: /* @__PURE__ */ jsx(
|
4285
|
+
ConditionalTooltip,
|
4286
|
+
{
|
4287
|
+
label: formatMessage({
|
4288
|
+
id: "content-manager.preview.panel.button-disabled-tooltip",
|
4289
|
+
defaultMessage: "Please save to open the preview"
|
4290
|
+
}),
|
4291
|
+
isShown: isModified,
|
4292
|
+
children: /* @__PURE__ */ jsx(Box, { cursor: "not-allowed", width: "100%", children: /* @__PURE__ */ jsx(
|
4293
|
+
Button,
|
4294
|
+
{
|
4295
|
+
variant: "tertiary",
|
4296
|
+
tag: Link,
|
4297
|
+
to: { pathname: "preview", search: stringify(query, { encode: false }) },
|
4298
|
+
onClick: trackNavigation,
|
4299
|
+
width: "100%",
|
4300
|
+
disabled: isModified,
|
4301
|
+
pointerEvents: isModified ? "none" : void 0,
|
4302
|
+
tabIndex: isModified ? -1 : void 0,
|
4303
|
+
children: formatMessage({
|
4304
|
+
id: "content-manager.preview.panel.button",
|
4305
|
+
defaultMessage: "Open preview"
|
4306
|
+
})
|
4307
|
+
}
|
4308
|
+
) })
|
4309
|
+
}
|
4310
|
+
)
|
4311
|
+
};
|
4312
|
+
};
|
4313
|
+
const previewAdmin = {
|
4314
|
+
bootstrap(app) {
|
4315
|
+
const contentManagerPluginApis = app.getPlugin("content-manager").apis;
|
4316
|
+
contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
|
4317
|
+
}
|
4318
|
+
};
|
3838
4319
|
const index = {
|
3839
4320
|
register(app) {
|
3840
4321
|
const cm = new ContentManagerPlugin();
|
@@ -3849,15 +4330,32 @@ const index = {
|
|
3849
4330
|
defaultMessage: "Content Manager"
|
3850
4331
|
},
|
3851
4332
|
permissions: [],
|
3852
|
-
Component: () => import("./layout-CPn1PM6x.mjs").then((mod) => ({ default: mod.Layout })),
|
3853
4333
|
position: 1
|
3854
4334
|
});
|
4335
|
+
app.router.addRoute({
|
4336
|
+
path: "content-manager/*",
|
4337
|
+
lazy: async () => {
|
4338
|
+
const { Layout } = await import("./layout-mSwsYzxv.mjs");
|
4339
|
+
return {
|
4340
|
+
Component: Layout
|
4341
|
+
};
|
4342
|
+
},
|
4343
|
+
children: routes
|
4344
|
+
});
|
3855
4345
|
app.registerPlugin(cm.config);
|
3856
4346
|
},
|
4347
|
+
bootstrap(app) {
|
4348
|
+
if (typeof historyAdmin.bootstrap === "function") {
|
4349
|
+
historyAdmin.bootstrap(app);
|
4350
|
+
}
|
4351
|
+
if (typeof previewAdmin.bootstrap === "function") {
|
4352
|
+
previewAdmin.bootstrap(app);
|
4353
|
+
}
|
4354
|
+
},
|
3857
4355
|
async registerTrads({ locales }) {
|
3858
4356
|
const importedTrads = await Promise.all(
|
3859
4357
|
locales.map((locale) => {
|
3860
|
-
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-
|
4358
|
+
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-BZaUty0m.mjs"), "./translations/es.json": () => import("./es-D34tqjMw.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr--pg5jUbt.mjs"), "./translations/gu.json": () => import("./gu-CNpaMDpH.mjs"), "./translations/hi.json": () => import("./hi-Dwvd04m3.mjs"), "./translations/hu.json": () => import("./hu-CeYvaaO0.mjs"), "./translations/id.json": () => import("./id-BtwA9WJT.mjs"), "./translations/it.json": () => import("./it-BrVPqaf1.mjs"), "./translations/ja.json": () => import("./ja-BHqhDq4V.mjs"), "./translations/ko.json": () => import("./ko-HVQRlfUI.mjs"), "./translations/ml.json": () => import("./ml-BihZwQit.mjs"), "./translations/ms.json": () => import("./ms-m_WjyWx7.mjs"), "./translations/nl.json": () => import("./nl-D4R9gHx5.mjs"), "./translations/pl.json": () => import("./pl-sbx9mSt_.mjs"), "./translations/pt-BR.json": () => import("./pt-BR-C71iDxnh.mjs"), "./translations/pt.json": () => import("./pt-BsaFvS8-.mjs"), "./translations/ru.json": () => import("./ru-BE6A4Exp.mjs"), "./translations/sa.json": () => import("./sa-Dag0k-Z8.mjs"), "./translations/sk.json": () => import("./sk-BFg-R8qJ.mjs"), "./translations/sv.json": () => import("./sv-CUnfWGsh.mjs"), "./translations/th.json": () => import("./th-BqbI8lIT.mjs"), "./translations/tr.json": () => import("./tr-CgeK3wJM.mjs"), "./translations/uk.json": () => import("./uk-CR-zDhAY.mjs"), "./translations/vi.json": () => import("./vi-DUXIk_fw.mjs"), "./translations/zh-Hans.json": () => import("./zh-Hans-BPQcRIyH.mjs"), "./translations/zh.json": () => import("./zh-BWZspA60.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => {
|
3861
4359
|
return {
|
3862
4360
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3863
4361
|
locale
|
@@ -3874,47 +4372,52 @@ const index = {
|
|
3874
4372
|
}
|
3875
4373
|
};
|
3876
4374
|
export {
|
3877
|
-
|
4375
|
+
useUpdateContentTypeConfigurationMutation as A,
|
3878
4376
|
BulkActionsRenderer as B,
|
3879
4377
|
COLLECTION_TYPES as C,
|
3880
4378
|
DocumentStatus as D,
|
3881
|
-
|
3882
|
-
|
3883
|
-
|
4379
|
+
ATTRIBUTE_TYPES_THAT_CANNOT_BE_MAIN_FIELD as E,
|
4380
|
+
extractContentTypeComponents as F,
|
4381
|
+
DEFAULT_SETTINGS as G,
|
3884
4382
|
HOOKS as H,
|
3885
4383
|
InjectionZone as I,
|
3886
|
-
|
3887
|
-
|
3888
|
-
|
4384
|
+
convertEditLayoutToFieldLayouts as J,
|
4385
|
+
removeFieldsThatDontExistOnSchema as K,
|
4386
|
+
prepareTempKeys as L,
|
4387
|
+
useDocument as M,
|
4388
|
+
useGetPreviewUrlQuery as N,
|
4389
|
+
index as O,
|
3889
4390
|
Panels as P,
|
4391
|
+
useContentManagerContext as Q,
|
3890
4392
|
RelativeTime as R,
|
3891
4393
|
SINGLE_TYPES as S,
|
3892
4394
|
TableActions as T,
|
3893
|
-
|
3894
|
-
|
3895
|
-
|
3896
|
-
|
3897
|
-
|
3898
|
-
|
4395
|
+
useDocumentActions as U,
|
4396
|
+
useGetInitialDataQuery as a,
|
4397
|
+
useGetAllContentTypeSettingsQuery as b,
|
4398
|
+
useDoc as c,
|
4399
|
+
buildValidParams as d,
|
4400
|
+
contentManagerApi as e,
|
4401
|
+
useDocumentRBAC as f,
|
3899
4402
|
getTranslation as g,
|
3900
|
-
|
3901
|
-
|
3902
|
-
|
3903
|
-
|
3904
|
-
|
4403
|
+
useDocumentLayout as h,
|
4404
|
+
createYupSchema as i,
|
4405
|
+
Header as j,
|
4406
|
+
PERMISSIONS as k,
|
4407
|
+
DocumentRBAC as l,
|
3905
4408
|
useDocLayout as m,
|
3906
|
-
|
3907
|
-
|
3908
|
-
|
3909
|
-
|
3910
|
-
|
4409
|
+
createDefaultForm as n,
|
4410
|
+
CLONE_PATH as o,
|
4411
|
+
useGetContentTypeConfigurationQuery as p,
|
4412
|
+
CREATOR_FIELDS as q,
|
4413
|
+
getMainField as r,
|
3911
4414
|
setInitialData as s,
|
3912
|
-
|
3913
|
-
|
3914
|
-
|
3915
|
-
|
3916
|
-
|
3917
|
-
|
3918
|
-
|
3919
|
-
};
|
3920
|
-
//# sourceMappingURL=index-
|
4415
|
+
transformDocument as t,
|
4416
|
+
useContentTypeSchema as u,
|
4417
|
+
getDisplayName as v,
|
4418
|
+
checkIfAttributeIsDisplayable as w,
|
4419
|
+
useGetAllDocumentsQuery as x,
|
4420
|
+
convertListLayoutToFieldLayouts as y,
|
4421
|
+
capitalise as z
|
4422
|
+
};
|
4423
|
+
//# sourceMappingURL=index-DiluOUp6.mjs.map
|