@strapi/content-manager 0.0.0-experimental.d954d57341a6623992a0d211daaec8e245c3517d → 0.0.0-experimental.dd1d47ef78ef6cfec4ed62576108500bd9f13740
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/{ComponentConfigurationPage-gdUj_t-O.mjs → ComponentConfigurationPage-BpM_Hc7r.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-gdUj_t-O.mjs.map → ComponentConfigurationPage-BpM_Hc7r.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-WRPUXGd6.js → ComponentConfigurationPage-CL9CAMaL.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-WRPUXGd6.js.map → ComponentConfigurationPage-CL9CAMaL.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-C1vjMBgy.js → EditConfigurationPage-ILWo0h1e.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-C1vjMBgy.js.map → EditConfigurationPage-ILWo0h1e.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BwuIPOJG.mjs → EditConfigurationPage-_prbqpTM.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-BwuIPOJG.mjs.map → EditConfigurationPage-_prbqpTM.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-DbcGfyqK.js → EditViewPage-BqZvBN4s.js} +30 -9
- package/dist/_chunks/EditViewPage-BqZvBN4s.js.map +1 -0
- package/dist/_chunks/{EditViewPage-0MiFkXa8.mjs → EditViewPage-DAtscabN.mjs} +30 -9
- package/dist/_chunks/EditViewPage-DAtscabN.mjs.map +1 -0
- package/dist/_chunks/{Field-BG1xu38N.js → Field-CcoQiiz1.js} +520 -156
- package/dist/_chunks/Field-CcoQiiz1.js.map +1 -0
- package/dist/_chunks/{Field-BDMSCcy5.mjs → Field-D-mgn1tH.mjs} +518 -154
- package/dist/_chunks/Field-D-mgn1tH.mjs.map +1 -0
- package/dist/_chunks/{Form-CPVWavB8.mjs → Form-BxyeWiXW.mjs} +40 -18
- package/dist/_chunks/Form-BxyeWiXW.mjs.map +1 -0
- package/dist/_chunks/{Form-9BnFyUjy.js → Form-CmLbZDfi.js} +40 -18
- package/dist/_chunks/Form-CmLbZDfi.js.map +1 -0
- package/dist/_chunks/{History-BVpd8LP3.mjs → History-BOhLaq_g.mjs} +78 -56
- package/dist/_chunks/History-BOhLaq_g.mjs.map +1 -0
- package/dist/_chunks/{History-BWWxLt2Z.js → History-uECUbCZB.js} +77 -55
- package/dist/_chunks/History-uECUbCZB.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DozVMKcR.mjs → ListConfigurationPage-D0vQez6F.mjs} +21 -9
- package/dist/_chunks/ListConfigurationPage-D0vQez6F.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-6swzjdAZ.js → ListConfigurationPage-D_bBSFNW.js} +21 -9
- package/dist/_chunks/ListConfigurationPage-D_bBSFNW.js.map +1 -0
- package/dist/_chunks/{ListViewPage-BlzfjS2Q.js → ListViewPage-BkZ83b1A.js} +73 -44
- package/dist/_chunks/ListViewPage-BkZ83b1A.js.map +1 -0
- package/dist/_chunks/{ListViewPage-Ds0ulgfG.mjs → ListViewPage-ns-bmy5C.mjs} +71 -42
- package/dist/_chunks/ListViewPage-ns-bmy5C.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BH11kaKt.mjs → NoContentTypePage-BA5ZKMDR.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-BH11kaKt.mjs.map → NoContentTypePage-BA5ZKMDR.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-D2nCCWEl.js → NoContentTypePage-C1439s4s.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-D2nCCWEl.js.map → NoContentTypePage-C1439s4s.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BT2Tn0D_.mjs → NoPermissionsPage-B0GdMw1Q.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BT2Tn0D_.mjs.map → NoPermissionsPage-B0GdMw1Q.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DN_JlsU2.js → NoPermissionsPage-CPGwsVfb.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DN_JlsU2.js.map → NoPermissionsPage-CPGwsVfb.js.map} +1 -1
- package/dist/_chunks/{Relations-Dnag3fhV.mjs → Relations-BIGPMSW4.mjs} +73 -37
- package/dist/_chunks/Relations-BIGPMSW4.mjs.map +1 -0
- package/dist/_chunks/{Relations-CcgFTcWo.js → Relations-d-8Uef_-.js} +72 -36
- package/dist/_chunks/Relations-d-8Uef_-.js.map +1 -0
- package/dist/_chunks/{en-fbKQxLGn.js → en-Bdpa50w3.js} +22 -16
- package/dist/_chunks/{en-fbKQxLGn.js.map → en-Bdpa50w3.js.map} +1 -1
- package/dist/_chunks/{en-Ux26r5pl.mjs → en-CZw4xdPY.mjs} +22 -16
- package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-CZw4xdPY.mjs.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/{index-JNNNKUHs.mjs → index-3_WeHXYp.mjs} +1084 -663
- package/dist/_chunks/index-3_WeHXYp.mjs.map +1 -0
- package/dist/_chunks/{index-CWpLBSt0.js → index-BgaeYWIy.js} +1073 -651
- package/dist/_chunks/index-BgaeYWIy.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--iHdZzRk.js → layout-ByFyQRDH.js} +25 -12
- package/dist/_chunks/layout-ByFyQRDH.js.map +1 -0
- package/dist/_chunks/{layout-DC503LnF.mjs → layout-CrTxOnCy.mjs} +27 -14
- package/dist/_chunks/layout-CrTxOnCy.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-CTje5t-a.mjs → relations-BlpLgngh.mjs} +3 -7
- package/dist/_chunks/relations-BlpLgngh.mjs.map +1 -0
- package/dist/_chunks/{relations-BbHizA5K.js → relations-C5RSW926.js} +3 -7
- package/dist/_chunks/relations-C5RSW926.js.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/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 +32 -1
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
- 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 +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/constants.d.ts +1 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/preview/services/preview.d.ts +3 -0
- 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 -17
- 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 +551 -266
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +552 -267
- 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 +15 -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/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 +4 -4
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/preview/constants.d.ts +2 -0
- package/dist/server/src/preview/constants.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/index.d.ts +2 -0
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/preview.d.ts +13 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/index.d.ts +8 -0
- package/dist/server/src/preview/routes/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/preview.d.ts +4 -0
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
- package/dist/server/src/preview/services/index.d.ts +15 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +30 -0
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview.d.ts +12 -0
- package/dist/server/src/preview/services/preview.d.ts.map +1 -0
- package/dist/server/src/preview/utils.d.ts +18 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/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 +13 -13
- package/dist/_chunks/EditViewPage-0MiFkXa8.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-DbcGfyqK.js.map +0 -1
- package/dist/_chunks/Field-BDMSCcy5.mjs.map +0 -1
- package/dist/_chunks/Field-BG1xu38N.js.map +0 -1
- package/dist/_chunks/Form-9BnFyUjy.js.map +0 -1
- package/dist/_chunks/Form-CPVWavB8.mjs.map +0 -1
- package/dist/_chunks/History-BVpd8LP3.mjs.map +0 -1
- package/dist/_chunks/History-BWWxLt2Z.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-6swzjdAZ.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DozVMKcR.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BlzfjS2Q.js.map +0 -1
- package/dist/_chunks/ListViewPage-Ds0ulgfG.mjs.map +0 -1
- package/dist/_chunks/Relations-CcgFTcWo.js.map +0 -1
- package/dist/_chunks/Relations-Dnag3fhV.mjs.map +0 -1
- package/dist/_chunks/index-CWpLBSt0.js.map +0 -1
- package/dist/_chunks/index-JNNNKUHs.mjs.map +0 -1
- package/dist/_chunks/layout--iHdZzRk.js.map +0 -1
- package/dist/_chunks/layout-DC503LnF.mjs.map +0 -1
- package/dist/_chunks/relations-BbHizA5K.js.map +0 -1
- package/dist/_chunks/relations-CTje5t-a.mjs.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
@@ -1,17 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Link as Link$1, 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, useClipboard } from "@strapi/admin/strapi-admin";
|
7
4
|
import * as React from "react";
|
8
5
|
import { lazy } from "react";
|
9
|
-
import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, Radio, Status, SingleSelect, SingleSelectOption,
|
10
|
-
import
|
6
|
+
import { Button, Menu, VisuallyHidden, Flex, Typography, Dialog, Modal, 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";
|
11
10
|
import * as yup from "yup";
|
12
11
|
import { ValidationError } from "yup";
|
13
12
|
import pipe from "lodash/fp/pipe";
|
14
13
|
import { intervalToDuration, isPast } from "date-fns";
|
14
|
+
import { styled } from "styled-components";
|
15
|
+
import { stringify } from "qs";
|
15
16
|
import { createSlice, combineReducers } from "@reduxjs/toolkit";
|
16
17
|
const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
17
18
|
const v = glob[path];
|
@@ -49,42 +50,6 @@ const useInjectionZone = (area) => {
|
|
49
50
|
const [page, position] = area.split(".");
|
50
51
|
return contentManagerPlugin.getInjectedComponents(page, position);
|
51
52
|
};
|
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
53
|
const ID = "id";
|
89
54
|
const CREATED_BY_ATTRIBUTE_NAME = "createdBy";
|
90
55
|
const UPDATED_BY_ATTRIBUTE_NAME = "updatedBy";
|
@@ -136,6 +101,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
136
101
|
if (!slug) {
|
137
102
|
throw new Error("Cannot find the slug param in the URL");
|
138
103
|
}
|
104
|
+
const [{ rawQuery }] = useQueryParams();
|
139
105
|
const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
|
140
106
|
const contentTypePermissions = React.useMemo(() => {
|
141
107
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -146,7 +112,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
146
112
|
return { ...acc, [action]: [permission] };
|
147
113
|
}, {});
|
148
114
|
}, [slug, userPermissions]);
|
149
|
-
const { isLoading, allowedActions } = useRBAC(
|
115
|
+
const { isLoading, allowedActions } = useRBAC(
|
116
|
+
contentTypePermissions,
|
117
|
+
permissions ?? void 0,
|
118
|
+
// TODO: useRBAC context should be typed and built differently
|
119
|
+
// We are passing raw query as context to the hook so that it can
|
120
|
+
// rely on the locale provided from DocumentRBAC for its permission calculations.
|
121
|
+
rawQuery
|
122
|
+
);
|
150
123
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
151
124
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
152
125
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -194,10 +167,12 @@ const contentManagerApi = adminApi.enhanceEndpoints({
|
|
194
167
|
"Document",
|
195
168
|
"InitialData",
|
196
169
|
"HistoryVersion",
|
197
|
-
"Relations"
|
170
|
+
"Relations",
|
171
|
+
"UidAvailability"
|
198
172
|
]
|
199
173
|
});
|
200
174
|
const documentApi = contentManagerApi.injectEndpoints({
|
175
|
+
overrideExisting: true,
|
201
176
|
endpoints: (builder) => ({
|
202
177
|
autoCloneDocument: builder.mutation({
|
203
178
|
query: ({ model, sourceId, query }) => ({
|
@@ -207,7 +182,12 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
207
182
|
params: query
|
208
183
|
}
|
209
184
|
}),
|
210
|
-
invalidatesTags: (_result,
|
185
|
+
invalidatesTags: (_result, error, { model }) => {
|
186
|
+
if (error) {
|
187
|
+
return [];
|
188
|
+
}
|
189
|
+
return [{ type: "Document", id: `${model}_LIST` }];
|
190
|
+
}
|
211
191
|
}),
|
212
192
|
cloneDocument: builder.mutation({
|
213
193
|
query: ({ model, sourceId, data, params }) => ({
|
@@ -218,7 +198,10 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
218
198
|
params
|
219
199
|
}
|
220
200
|
}),
|
221
|
-
invalidatesTags: (_result, _error, { model }) => [
|
201
|
+
invalidatesTags: (_result, _error, { model }) => [
|
202
|
+
{ type: "Document", id: `${model}_LIST` },
|
203
|
+
{ type: "UidAvailability", id: model }
|
204
|
+
]
|
222
205
|
}),
|
223
206
|
/**
|
224
207
|
* Creates a new collection-type document. This should ONLY be used for collection-types.
|
@@ -235,7 +218,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
235
218
|
}),
|
236
219
|
invalidatesTags: (result, _error, { model }) => [
|
237
220
|
{ type: "Document", id: `${model}_LIST` },
|
238
|
-
"Relations"
|
221
|
+
"Relations",
|
222
|
+
{ type: "UidAvailability", id: model }
|
239
223
|
]
|
240
224
|
}),
|
241
225
|
deleteDocument: builder.mutation({
|
@@ -276,7 +260,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
276
260
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
277
261
|
},
|
278
262
|
{ type: "Document", id: `${model}_LIST` },
|
279
|
-
"Relations"
|
263
|
+
"Relations",
|
264
|
+
{ type: "UidAvailability", id: model }
|
280
265
|
];
|
281
266
|
}
|
282
267
|
}),
|
@@ -294,6 +279,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
294
279
|
}),
|
295
280
|
providesTags: (result, _error, arg) => {
|
296
281
|
return [
|
282
|
+
{ type: "Document", id: `ALL_LIST` },
|
297
283
|
{ type: "Document", id: `${arg.model}_LIST` },
|
298
284
|
...result?.results.map(({ documentId }) => ({
|
299
285
|
type: "Document",
|
@@ -332,6 +318,11 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
332
318
|
{
|
333
319
|
type: "Document",
|
334
320
|
id: collectionType !== SINGLE_TYPES ? `${model}_${result && "documentId" in result ? result.documentId : documentId}` : model
|
321
|
+
},
|
322
|
+
// Make it easy to invalidate all individual documents queries for a model
|
323
|
+
{
|
324
|
+
type: "Document",
|
325
|
+
id: `${model}_ALL_ITEMS`
|
335
326
|
}
|
336
327
|
];
|
337
328
|
}
|
@@ -395,8 +386,21 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
395
386
|
type: "Document",
|
396
387
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
397
388
|
},
|
398
|
-
"Relations"
|
389
|
+
"Relations",
|
390
|
+
{ type: "UidAvailability", id: model }
|
399
391
|
];
|
392
|
+
},
|
393
|
+
async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
|
394
|
+
const patchResult = dispatch(
|
395
|
+
documentApi.util.updateQueryData("getDocument", patch, (draft) => {
|
396
|
+
Object.assign(draft.data, data);
|
397
|
+
})
|
398
|
+
);
|
399
|
+
try {
|
400
|
+
await queryFulfilled;
|
401
|
+
} catch {
|
402
|
+
patchResult.undo();
|
403
|
+
}
|
400
404
|
}
|
401
405
|
}),
|
402
406
|
unpublishDocument: builder.mutation({
|
@@ -466,20 +470,39 @@ const buildValidParams = (query) => {
|
|
466
470
|
const isBaseQueryError = (error) => {
|
467
471
|
return error.name !== void 0;
|
468
472
|
};
|
469
|
-
const
|
473
|
+
const arrayValidator = (attribute, options) => ({
|
474
|
+
message: translatedErrors.required,
|
475
|
+
test(value) {
|
476
|
+
if (options.status === "draft") {
|
477
|
+
return true;
|
478
|
+
}
|
479
|
+
if (!attribute.required) {
|
480
|
+
return true;
|
481
|
+
}
|
482
|
+
if (!value) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
if (Array.isArray(value) && value.length === 0) {
|
486
|
+
return false;
|
487
|
+
}
|
488
|
+
return true;
|
489
|
+
}
|
490
|
+
});
|
491
|
+
const createYupSchema = (attributes = {}, components = {}, options = { status: null }) => {
|
470
492
|
const createModelSchema = (attributes2) => yup.object().shape(
|
471
493
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
472
494
|
if (DOCUMENT_META_FIELDS.includes(name)) {
|
473
495
|
return acc;
|
474
496
|
}
|
475
497
|
const validations = [
|
498
|
+
addNullableValidation,
|
476
499
|
addRequiredValidation,
|
477
500
|
addMinLengthValidation,
|
478
501
|
addMaxLengthValidation,
|
479
502
|
addMinValidation,
|
480
503
|
addMaxValidation,
|
481
504
|
addRegexValidation
|
482
|
-
].map((fn) => fn(attribute));
|
505
|
+
].map((fn) => fn(attribute, options));
|
483
506
|
const transformSchema = pipe(...validations);
|
484
507
|
switch (attribute.type) {
|
485
508
|
case "component": {
|
@@ -489,12 +512,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
489
512
|
...acc,
|
490
513
|
[name]: transformSchema(
|
491
514
|
yup.array().of(createModelSchema(attributes3).nullable(false))
|
492
|
-
)
|
515
|
+
).test(arrayValidator(attribute, options))
|
493
516
|
};
|
494
517
|
} else {
|
495
518
|
return {
|
496
519
|
...acc,
|
497
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
520
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
498
521
|
};
|
499
522
|
}
|
500
523
|
}
|
@@ -516,7 +539,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
516
539
|
}
|
517
540
|
)
|
518
541
|
)
|
519
|
-
)
|
542
|
+
).test(arrayValidator(attribute, options))
|
520
543
|
};
|
521
544
|
case "relation":
|
522
545
|
return {
|
@@ -528,7 +551,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
528
551
|
} else if (Array.isArray(value)) {
|
529
552
|
return yup.array().of(
|
530
553
|
yup.object().shape({
|
531
|
-
id: yup.
|
554
|
+
id: yup.number().required()
|
532
555
|
})
|
533
556
|
);
|
534
557
|
} else if (typeof value === "object") {
|
@@ -580,6 +603,14 @@ const createAttributeSchema = (attribute) => {
|
|
580
603
|
if (!value || typeof value === "string" && value.length === 0) {
|
581
604
|
return true;
|
582
605
|
}
|
606
|
+
if (typeof value === "object") {
|
607
|
+
try {
|
608
|
+
JSON.stringify(value);
|
609
|
+
return true;
|
610
|
+
} catch (err) {
|
611
|
+
return false;
|
612
|
+
}
|
613
|
+
}
|
583
614
|
try {
|
584
615
|
JSON.parse(value);
|
585
616
|
return true;
|
@@ -598,13 +629,7 @@ const createAttributeSchema = (attribute) => {
|
|
598
629
|
return yup.mixed();
|
599
630
|
}
|
600
631
|
};
|
601
|
-
const
|
602
|
-
if (attribute.required) {
|
603
|
-
return schema.required({
|
604
|
-
id: translatedErrors.required.id,
|
605
|
-
defaultMessage: "This field is required."
|
606
|
-
});
|
607
|
-
}
|
632
|
+
const nullableSchema = (schema) => {
|
608
633
|
return schema?.nullable ? schema.nullable() : (
|
609
634
|
// In some cases '.nullable' will not be available on the schema.
|
610
635
|
// e.g. when the schema has been built using yup.lazy (e.g. for relations).
|
@@ -612,7 +637,22 @@ const addRequiredValidation = (attribute) => (schema) => {
|
|
612
637
|
schema
|
613
638
|
);
|
614
639
|
};
|
615
|
-
const
|
640
|
+
const addNullableValidation = () => (schema) => {
|
641
|
+
return nullableSchema(schema);
|
642
|
+
};
|
643
|
+
const addRequiredValidation = (attribute, options) => (schema) => {
|
644
|
+
if (options.status === "draft" || !attribute.required) {
|
645
|
+
return schema;
|
646
|
+
}
|
647
|
+
if (attribute.required && "required" in schema) {
|
648
|
+
return schema.required(translatedErrors.required);
|
649
|
+
}
|
650
|
+
return schema;
|
651
|
+
};
|
652
|
+
const addMinLengthValidation = (attribute, options) => (schema) => {
|
653
|
+
if (options.status === "draft") {
|
654
|
+
return schema;
|
655
|
+
}
|
616
656
|
if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
|
617
657
|
return schema.min(attribute.minLength, {
|
618
658
|
...translatedErrors.minLength,
|
@@ -634,10 +674,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
634
674
|
}
|
635
675
|
return schema;
|
636
676
|
};
|
637
|
-
const addMinValidation = (attribute) => (schema) => {
|
638
|
-
if ("
|
677
|
+
const addMinValidation = (attribute, options) => (schema) => {
|
678
|
+
if (options.status === "draft") {
|
679
|
+
return schema;
|
680
|
+
}
|
681
|
+
if ("min" in attribute && "min" in schema) {
|
639
682
|
const min = toInteger(attribute.min);
|
640
|
-
if (
|
683
|
+
if (min) {
|
641
684
|
return schema.min(min, {
|
642
685
|
...translatedErrors.min,
|
643
686
|
values: {
|
@@ -755,16 +798,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
755
798
|
}, {});
|
756
799
|
return componentsByKey;
|
757
800
|
};
|
758
|
-
const
|
801
|
+
const HOOKS = {
|
802
|
+
/**
|
803
|
+
* Hook that allows to mutate the displayed headers of the list view table
|
804
|
+
* @constant
|
805
|
+
* @type {string}
|
806
|
+
*/
|
807
|
+
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
808
|
+
/**
|
809
|
+
* Hook that allows to mutate the CM's collection types links pre-set filters
|
810
|
+
* @constant
|
811
|
+
* @type {string}
|
812
|
+
*/
|
813
|
+
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
814
|
+
/**
|
815
|
+
* Hook that allows to mutate the CM's edit view layout
|
816
|
+
* @constant
|
817
|
+
* @type {string}
|
818
|
+
*/
|
819
|
+
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
820
|
+
/**
|
821
|
+
* Hook that allows to mutate the CM's single types links pre-set filters
|
822
|
+
* @constant
|
823
|
+
* @type {string}
|
824
|
+
*/
|
825
|
+
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
826
|
+
};
|
827
|
+
const contentTypesApi = contentManagerApi.injectEndpoints({
|
828
|
+
endpoints: (builder) => ({
|
829
|
+
getContentTypeConfiguration: builder.query({
|
830
|
+
query: (uid) => ({
|
831
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
832
|
+
method: "GET"
|
833
|
+
}),
|
834
|
+
transformResponse: (response) => response.data,
|
835
|
+
providesTags: (_result, _error, uid) => [
|
836
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
837
|
+
{ type: "ContentTypeSettings", id: "LIST" }
|
838
|
+
]
|
839
|
+
}),
|
840
|
+
getAllContentTypeSettings: builder.query({
|
841
|
+
query: () => "/content-manager/content-types-settings",
|
842
|
+
transformResponse: (response) => response.data,
|
843
|
+
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
844
|
+
}),
|
845
|
+
updateContentTypeConfiguration: builder.mutation({
|
846
|
+
query: ({ uid, ...body }) => ({
|
847
|
+
url: `/content-manager/content-types/${uid}/configuration`,
|
848
|
+
method: "PUT",
|
849
|
+
data: body
|
850
|
+
}),
|
851
|
+
transformResponse: (response) => response.data,
|
852
|
+
invalidatesTags: (_result, _error, { uid }) => [
|
853
|
+
{ type: "ContentTypesConfiguration", id: uid },
|
854
|
+
{ type: "ContentTypeSettings", id: "LIST" },
|
855
|
+
// Is this necessary?
|
856
|
+
{ type: "InitialData" }
|
857
|
+
]
|
858
|
+
})
|
859
|
+
})
|
860
|
+
});
|
861
|
+
const {
|
862
|
+
useGetContentTypeConfigurationQuery,
|
863
|
+
useGetAllContentTypeSettingsQuery,
|
864
|
+
useUpdateContentTypeConfigurationMutation
|
865
|
+
} = contentTypesApi;
|
866
|
+
const checkIfAttributeIsDisplayable = (attribute) => {
|
867
|
+
const { type } = attribute;
|
868
|
+
if (type === "relation") {
|
869
|
+
return !attribute.relation.toLowerCase().includes("morph");
|
870
|
+
}
|
871
|
+
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
872
|
+
};
|
873
|
+
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
874
|
+
if (!mainFieldName) {
|
875
|
+
return void 0;
|
876
|
+
}
|
877
|
+
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
878
|
+
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
879
|
+
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
880
|
+
);
|
881
|
+
return {
|
882
|
+
name: mainFieldName,
|
883
|
+
type: mainFieldType ?? "string"
|
884
|
+
};
|
885
|
+
};
|
886
|
+
const DEFAULT_SETTINGS = {
|
887
|
+
bulkable: false,
|
888
|
+
filterable: false,
|
889
|
+
searchable: false,
|
890
|
+
pagination: false,
|
891
|
+
defaultSortBy: "",
|
892
|
+
defaultSortOrder: "asc",
|
893
|
+
mainField: "id",
|
894
|
+
pageSize: 10
|
895
|
+
};
|
896
|
+
const useDocumentLayout = (model) => {
|
897
|
+
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
898
|
+
const [{ query }] = useQueryParams();
|
899
|
+
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
759
900
|
const { toggleNotification } = useNotification();
|
760
901
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
902
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
761
903
|
const {
|
762
|
-
|
763
|
-
isLoading:
|
764
|
-
|
765
|
-
|
766
|
-
} =
|
767
|
-
const
|
904
|
+
data,
|
905
|
+
isLoading: isLoadingConfigs,
|
906
|
+
error,
|
907
|
+
isFetching: isFetchingConfigs
|
908
|
+
} = useGetContentTypeConfigurationQuery(model);
|
909
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
768
910
|
React.useEffect(() => {
|
769
911
|
if (error) {
|
770
912
|
toggleNotification({
|
@@ -772,68 +914,322 @@ const useDocument = (args, opts) => {
|
|
772
914
|
message: formatAPIError(error)
|
773
915
|
});
|
774
916
|
}
|
775
|
-
}, [
|
776
|
-
const
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
(document) => {
|
784
|
-
if (!validationSchema) {
|
785
|
-
throw new Error(
|
786
|
-
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
787
|
-
);
|
788
|
-
}
|
789
|
-
try {
|
790
|
-
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
791
|
-
return null;
|
792
|
-
} catch (error2) {
|
793
|
-
if (error2 instanceof ValidationError) {
|
794
|
-
return getYupValidationErrors(error2);
|
795
|
-
}
|
796
|
-
throw error2;
|
797
|
-
}
|
917
|
+
}, [error, formatAPIError, toggleNotification]);
|
918
|
+
const editLayout = React.useMemo(
|
919
|
+
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
920
|
+
layout: [],
|
921
|
+
components: {},
|
922
|
+
metadatas: {},
|
923
|
+
options: {},
|
924
|
+
settings: DEFAULT_SETTINGS
|
798
925
|
},
|
799
|
-
[
|
926
|
+
[data, isLoading, schemas, schema, components]
|
927
|
+
);
|
928
|
+
const listLayout = React.useMemo(() => {
|
929
|
+
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
930
|
+
layout: [],
|
931
|
+
metadatas: {},
|
932
|
+
options: {},
|
933
|
+
settings: DEFAULT_SETTINGS
|
934
|
+
};
|
935
|
+
}, [data, isLoading, schemas, schema, components]);
|
936
|
+
const { layout: edit } = React.useMemo(
|
937
|
+
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
938
|
+
layout: editLayout,
|
939
|
+
query
|
940
|
+
}),
|
941
|
+
[editLayout, query, runHookWaterfall]
|
800
942
|
);
|
801
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
802
943
|
return {
|
803
|
-
|
804
|
-
document: data?.data,
|
805
|
-
meta: data?.meta,
|
944
|
+
error,
|
806
945
|
isLoading,
|
807
|
-
|
808
|
-
|
946
|
+
edit,
|
947
|
+
list: listLayout
|
809
948
|
};
|
810
949
|
};
|
811
|
-
const
|
812
|
-
const {
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
950
|
+
const useDocLayout = () => {
|
951
|
+
const { model } = useDoc();
|
952
|
+
return useDocumentLayout(model);
|
953
|
+
};
|
954
|
+
const formatEditLayout = (data, {
|
955
|
+
schemas,
|
956
|
+
schema,
|
957
|
+
components
|
958
|
+
}) => {
|
959
|
+
let currentPanelIndex = 0;
|
960
|
+
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
961
|
+
data.contentType.layouts.edit,
|
962
|
+
schema?.attributes,
|
963
|
+
data.contentType.metadatas,
|
964
|
+
{ configurations: data.components, schemas: components },
|
965
|
+
schemas
|
966
|
+
).reduce((panels, row) => {
|
967
|
+
if (row.some((field) => field.type === "dynamiczone")) {
|
968
|
+
panels.push([row]);
|
969
|
+
currentPanelIndex += 2;
|
970
|
+
} else {
|
971
|
+
if (!panels[currentPanelIndex]) {
|
972
|
+
panels.push([row]);
|
973
|
+
} else {
|
974
|
+
panels[currentPanelIndex].push(row);
|
975
|
+
}
|
976
|
+
}
|
977
|
+
return panels;
|
978
|
+
}, []);
|
979
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
980
|
+
(acc, [uid, configuration]) => {
|
981
|
+
acc[uid] = {
|
982
|
+
layout: convertEditLayoutToFieldLayouts(
|
983
|
+
configuration.layouts.edit,
|
984
|
+
components[uid].attributes,
|
985
|
+
configuration.metadatas,
|
986
|
+
{ configurations: data.components, schemas: components }
|
987
|
+
),
|
988
|
+
settings: {
|
989
|
+
...configuration.settings,
|
990
|
+
icon: components[uid].info.icon,
|
991
|
+
displayName: components[uid].info.displayName
|
992
|
+
}
|
993
|
+
};
|
994
|
+
return acc;
|
995
|
+
},
|
996
|
+
{}
|
997
|
+
);
|
998
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
999
|
+
(acc, [attribute, metadata]) => {
|
1000
|
+
return {
|
1001
|
+
...acc,
|
1002
|
+
[attribute]: metadata.edit
|
1003
|
+
};
|
1004
|
+
},
|
1005
|
+
{}
|
1006
|
+
);
|
1007
|
+
return {
|
1008
|
+
layout: panelledEditAttributes,
|
1009
|
+
components: componentEditAttributes,
|
1010
|
+
metadatas: editMetadatas,
|
1011
|
+
settings: {
|
1012
|
+
...data.contentType.settings,
|
1013
|
+
displayName: schema?.info.displayName
|
1014
|
+
},
|
1015
|
+
options: {
|
1016
|
+
...schema?.options,
|
1017
|
+
...schema?.pluginOptions,
|
1018
|
+
...data.contentType.options
|
1019
|
+
}
|
1020
|
+
};
|
1021
|
+
};
|
1022
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1023
|
+
return rows.map(
|
1024
|
+
(row) => row.map((field) => {
|
1025
|
+
const attribute = attributes[field.name];
|
1026
|
+
if (!attribute) {
|
1027
|
+
return null;
|
1028
|
+
}
|
1029
|
+
const { edit: metadata } = metadatas[field.name];
|
1030
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1031
|
+
return {
|
1032
|
+
attribute,
|
1033
|
+
disabled: !metadata.editable,
|
1034
|
+
hint: metadata.description,
|
1035
|
+
label: metadata.label ?? "",
|
1036
|
+
name: field.name,
|
1037
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1038
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1039
|
+
schemas,
|
1040
|
+
components: components?.schemas ?? {}
|
1041
|
+
}),
|
1042
|
+
placeholder: metadata.placeholder ?? "",
|
1043
|
+
required: attribute.required ?? false,
|
1044
|
+
size: field.size,
|
1045
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1046
|
+
visible: metadata.visible ?? true,
|
1047
|
+
type: attribute.type
|
1048
|
+
};
|
1049
|
+
}).filter((field) => field !== null)
|
1050
|
+
);
|
1051
|
+
};
|
1052
|
+
const formatListLayout = (data, {
|
1053
|
+
schemas,
|
1054
|
+
schema,
|
1055
|
+
components
|
1056
|
+
}) => {
|
1057
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1058
|
+
(acc, [attribute, metadata]) => {
|
1059
|
+
return {
|
1060
|
+
...acc,
|
1061
|
+
[attribute]: metadata.list
|
1062
|
+
};
|
1063
|
+
},
|
1064
|
+
{}
|
1065
|
+
);
|
1066
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1067
|
+
data.contentType.layouts.list,
|
1068
|
+
schema?.attributes,
|
1069
|
+
listMetadatas,
|
1070
|
+
{ configurations: data.components, schemas: components },
|
1071
|
+
schemas
|
1072
|
+
);
|
1073
|
+
return {
|
1074
|
+
layout: listAttributes,
|
1075
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1076
|
+
metadatas: listMetadatas,
|
1077
|
+
options: {
|
1078
|
+
...schema?.options,
|
1079
|
+
...schema?.pluginOptions,
|
1080
|
+
...data.contentType.options
|
1081
|
+
}
|
1082
|
+
};
|
1083
|
+
};
|
1084
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1085
|
+
return columns.map((name) => {
|
1086
|
+
const attribute = attributes[name];
|
1087
|
+
if (!attribute) {
|
1088
|
+
return null;
|
1089
|
+
}
|
1090
|
+
const metadata = metadatas[name];
|
1091
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1092
|
+
return {
|
1093
|
+
attribute,
|
1094
|
+
label: metadata.label ?? "",
|
1095
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1096
|
+
schemas,
|
1097
|
+
components: components?.schemas ?? {}
|
1098
|
+
}),
|
1099
|
+
name,
|
1100
|
+
searchable: metadata.searchable ?? true,
|
1101
|
+
sortable: metadata.sortable ?? true
|
1102
|
+
};
|
1103
|
+
}).filter((field) => field !== null);
|
1104
|
+
};
|
1105
|
+
const useDocument = (args, opts) => {
|
1106
|
+
const { toggleNotification } = useNotification();
|
1107
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1108
|
+
const {
|
1109
|
+
currentData: data,
|
1110
|
+
isLoading: isLoadingDocument,
|
1111
|
+
isFetching: isFetchingDocument,
|
1112
|
+
error
|
1113
|
+
} = useGetDocumentQuery(args, {
|
1114
|
+
...opts,
|
1115
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1116
|
+
});
|
1117
|
+
const {
|
1118
|
+
components,
|
1119
|
+
schema,
|
1120
|
+
schemas,
|
1121
|
+
isLoading: isLoadingSchema
|
1122
|
+
} = useContentTypeSchema(args.model);
|
1123
|
+
React.useEffect(() => {
|
1124
|
+
if (error) {
|
1125
|
+
toggleNotification({
|
1126
|
+
type: "danger",
|
1127
|
+
message: formatAPIError(error)
|
1128
|
+
});
|
1129
|
+
}
|
1130
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1131
|
+
const validationSchema = React.useMemo(() => {
|
1132
|
+
if (!schema) {
|
1133
|
+
return null;
|
1134
|
+
}
|
1135
|
+
return createYupSchema(schema.attributes, components);
|
1136
|
+
}, [schema, components]);
|
1137
|
+
const validate = React.useCallback(
|
1138
|
+
(document) => {
|
1139
|
+
if (!validationSchema) {
|
1140
|
+
throw new Error(
|
1141
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1142
|
+
);
|
1143
|
+
}
|
1144
|
+
try {
|
1145
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1146
|
+
return null;
|
1147
|
+
} catch (error2) {
|
1148
|
+
if (error2 instanceof ValidationError) {
|
1149
|
+
return getYupValidationErrors(error2);
|
1150
|
+
}
|
1151
|
+
throw error2;
|
1152
|
+
}
|
1153
|
+
},
|
1154
|
+
[validationSchema]
|
1155
|
+
);
|
1156
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1157
|
+
const hasError = !!error;
|
1158
|
+
return {
|
1159
|
+
components,
|
1160
|
+
document: data?.data,
|
1161
|
+
meta: data?.meta,
|
1162
|
+
isLoading,
|
1163
|
+
hasError,
|
1164
|
+
schema,
|
1165
|
+
schemas,
|
1166
|
+
validate
|
1167
|
+
};
|
1168
|
+
};
|
1169
|
+
const useDoc = () => {
|
1170
|
+
const { id, slug, collectionType, origin } = useParams();
|
1171
|
+
const [{ query }] = useQueryParams();
|
1172
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1173
|
+
if (!collectionType) {
|
1174
|
+
throw new Error("Could not find collectionType in url params");
|
1175
|
+
}
|
1176
|
+
if (!slug) {
|
1177
|
+
throw new Error("Could not find model in url params");
|
1178
|
+
}
|
1179
|
+
const document = useDocument(
|
1180
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1181
|
+
{
|
1182
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1183
|
+
}
|
1184
|
+
);
|
1185
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
821
1186
|
return {
|
822
1187
|
collectionType,
|
823
1188
|
model: slug,
|
824
|
-
id:
|
825
|
-
...
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
1189
|
+
id: returnId,
|
1190
|
+
...document
|
1191
|
+
};
|
1192
|
+
};
|
1193
|
+
const useContentManagerContext = () => {
|
1194
|
+
const {
|
1195
|
+
collectionType,
|
1196
|
+
model,
|
1197
|
+
id,
|
1198
|
+
components,
|
1199
|
+
isLoading: isLoadingDoc,
|
1200
|
+
schema,
|
1201
|
+
schemas
|
1202
|
+
} = useDoc();
|
1203
|
+
const layout = useDocumentLayout(model);
|
1204
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1205
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1206
|
+
const slug = model;
|
1207
|
+
const isCreatingEntry = id === "create";
|
1208
|
+
useContentTypeSchema();
|
1209
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1210
|
+
const error = layout.error;
|
1211
|
+
return {
|
1212
|
+
error,
|
1213
|
+
isLoading,
|
1214
|
+
// Base metadata
|
1215
|
+
model,
|
1216
|
+
collectionType,
|
1217
|
+
id,
|
1218
|
+
slug,
|
1219
|
+
isCreatingEntry,
|
1220
|
+
isSingleType,
|
1221
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1222
|
+
// All schema infos
|
1223
|
+
components,
|
1224
|
+
contentType: schema,
|
1225
|
+
contentTypes: schemas,
|
1226
|
+
// Form state
|
1227
|
+
form,
|
1228
|
+
// layout infos
|
1229
|
+
layout
|
831
1230
|
};
|
832
1231
|
};
|
833
1232
|
const prefixPluginTranslations = (trad, pluginId) => {
|
834
|
-
if (!pluginId) {
|
835
|
-
throw new TypeError("pluginId can't be empty");
|
836
|
-
}
|
837
1233
|
return Object.keys(trad).reduce((acc, current) => {
|
838
1234
|
acc[`${pluginId}.${current}`] = trad[current];
|
839
1235
|
return acc;
|
@@ -849,6 +1245,8 @@ const useDocumentActions = () => {
|
|
849
1245
|
const { formatMessage } = useIntl();
|
850
1246
|
const { trackUsage } = useTracking();
|
851
1247
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1248
|
+
const navigate = useNavigate();
|
1249
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
852
1250
|
const [deleteDocument] = useDeleteDocumentMutation();
|
853
1251
|
const _delete = React.useCallback(
|
854
1252
|
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
@@ -1163,6 +1561,7 @@ const useDocumentActions = () => {
|
|
1163
1561
|
defaultMessage: "Saved document"
|
1164
1562
|
})
|
1165
1563
|
});
|
1564
|
+
setCurrentStep("contentManager.success");
|
1166
1565
|
return res.data;
|
1167
1566
|
} catch (err) {
|
1168
1567
|
toggleNotification({
|
@@ -1184,7 +1583,6 @@ const useDocumentActions = () => {
|
|
1184
1583
|
sourceId
|
1185
1584
|
});
|
1186
1585
|
if ("error" in res) {
|
1187
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1188
1586
|
return { error: res.error };
|
1189
1587
|
}
|
1190
1588
|
toggleNotification({
|
@@ -1203,7 +1601,7 @@ const useDocumentActions = () => {
|
|
1203
1601
|
throw err;
|
1204
1602
|
}
|
1205
1603
|
},
|
1206
|
-
[autoCloneDocument,
|
1604
|
+
[autoCloneDocument, formatMessage, toggleNotification]
|
1207
1605
|
);
|
1208
1606
|
const [cloneDocument] = useCloneDocumentMutation();
|
1209
1607
|
const clone = React.useCallback(
|
@@ -1229,6 +1627,7 @@ const useDocumentActions = () => {
|
|
1229
1627
|
defaultMessage: "Cloned document"
|
1230
1628
|
})
|
1231
1629
|
});
|
1630
|
+
navigate(`../../${res.data.data.documentId}`, { relative: "path" });
|
1232
1631
|
return res.data;
|
1233
1632
|
} catch (err) {
|
1234
1633
|
toggleNotification({
|
@@ -1239,7 +1638,7 @@ const useDocumentActions = () => {
|
|
1239
1638
|
throw err;
|
1240
1639
|
}
|
1241
1640
|
},
|
1242
|
-
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
|
1641
|
+
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
|
1243
1642
|
);
|
1244
1643
|
const [getDoc] = useLazyGetDocumentQuery();
|
1245
1644
|
const getDocument = React.useCallback(
|
@@ -1265,7 +1664,7 @@ const useDocumentActions = () => {
|
|
1265
1664
|
};
|
1266
1665
|
};
|
1267
1666
|
const ProtectedHistoryPage = lazy(
|
1268
|
-
() => import("./History-
|
1667
|
+
() => import("./History-BOhLaq_g.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1269
1668
|
);
|
1270
1669
|
const routes$1 = [
|
1271
1670
|
{
|
@@ -1278,31 +1677,31 @@ const routes$1 = [
|
|
1278
1677
|
}
|
1279
1678
|
];
|
1280
1679
|
const ProtectedEditViewPage = lazy(
|
1281
|
-
() => import("./EditViewPage-
|
1680
|
+
() => import("./EditViewPage-DAtscabN.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1282
1681
|
);
|
1283
1682
|
const ProtectedListViewPage = lazy(
|
1284
|
-
() => import("./ListViewPage-
|
1683
|
+
() => import("./ListViewPage-ns-bmy5C.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1285
1684
|
);
|
1286
1685
|
const ProtectedListConfiguration = lazy(
|
1287
|
-
() => import("./ListConfigurationPage-
|
1686
|
+
() => import("./ListConfigurationPage-D0vQez6F.mjs").then((mod) => ({
|
1288
1687
|
default: mod.ProtectedListConfiguration
|
1289
1688
|
}))
|
1290
1689
|
);
|
1291
1690
|
const ProtectedEditConfigurationPage = lazy(
|
1292
|
-
() => import("./EditConfigurationPage-
|
1691
|
+
() => import("./EditConfigurationPage-_prbqpTM.mjs").then((mod) => ({
|
1293
1692
|
default: mod.ProtectedEditConfigurationPage
|
1294
1693
|
}))
|
1295
1694
|
);
|
1296
1695
|
const ProtectedComponentConfigurationPage = lazy(
|
1297
|
-
() => import("./ComponentConfigurationPage-
|
1696
|
+
() => import("./ComponentConfigurationPage-BpM_Hc7r.mjs").then((mod) => ({
|
1298
1697
|
default: mod.ProtectedComponentConfigurationPage
|
1299
1698
|
}))
|
1300
1699
|
);
|
1301
1700
|
const NoPermissions = lazy(
|
1302
|
-
() => import("./NoPermissionsPage-
|
1701
|
+
() => import("./NoPermissionsPage-B0GdMw1Q.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1303
1702
|
);
|
1304
1703
|
const NoContentType = lazy(
|
1305
|
-
() => import("./NoContentTypePage-
|
1704
|
+
() => import("./NoContentTypePage-BA5ZKMDR.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1306
1705
|
);
|
1307
1706
|
const CollectionTypePages = () => {
|
1308
1707
|
const { collectionType } = useParams();
|
@@ -1416,12 +1815,14 @@ const DocumentActionButton = (action) => {
|
|
1416
1815
|
/* @__PURE__ */ jsx(
|
1417
1816
|
Button,
|
1418
1817
|
{
|
1419
|
-
flex:
|
1818
|
+
flex: "auto",
|
1420
1819
|
startIcon: action.icon,
|
1421
1820
|
disabled: action.disabled,
|
1422
1821
|
onClick: handleClick(action),
|
1423
1822
|
justifyContent: "center",
|
1424
1823
|
variant: action.variant || "default",
|
1824
|
+
paddingTop: "7px",
|
1825
|
+
paddingBottom: "7px",
|
1425
1826
|
children: action.label
|
1426
1827
|
}
|
1427
1828
|
),
|
@@ -1429,7 +1830,7 @@ const DocumentActionButton = (action) => {
|
|
1429
1830
|
DocumentActionConfirmDialog,
|
1430
1831
|
{
|
1431
1832
|
...action.dialog,
|
1432
|
-
variant: action.variant,
|
1833
|
+
variant: action.dialog?.variant ?? action.variant,
|
1433
1834
|
isOpen: dialogId === action.id,
|
1434
1835
|
onClose: handleClose
|
1435
1836
|
}
|
@@ -1486,9 +1887,9 @@ const DocumentActionsMenu = ({
|
|
1486
1887
|
disabled: isDisabled,
|
1487
1888
|
size: "S",
|
1488
1889
|
endIcon: null,
|
1489
|
-
paddingTop: "
|
1490
|
-
paddingLeft: "
|
1491
|
-
paddingRight: "
|
1890
|
+
paddingTop: "4px",
|
1891
|
+
paddingLeft: "7px",
|
1892
|
+
paddingRight: "7px",
|
1492
1893
|
variant,
|
1493
1894
|
children: [
|
1494
1895
|
/* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
|
@@ -1499,7 +1900,7 @@ const DocumentActionsMenu = ({
|
|
1499
1900
|
]
|
1500
1901
|
}
|
1501
1902
|
),
|
1502
|
-
/* @__PURE__ */ jsxs(Menu.Content, {
|
1903
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1503
1904
|
actions2.map((action) => {
|
1504
1905
|
return /* @__PURE__ */ jsx(
|
1505
1906
|
Menu.Item,
|
@@ -1508,10 +1909,25 @@ const DocumentActionsMenu = ({
|
|
1508
1909
|
onSelect: handleClick(action),
|
1509
1910
|
display: "block",
|
1510
1911
|
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
|
1511
|
-
/* @__PURE__ */ jsxs(
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1912
|
+
/* @__PURE__ */ jsxs(
|
1913
|
+
Flex,
|
1914
|
+
{
|
1915
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1916
|
+
gap: 2,
|
1917
|
+
tag: "span",
|
1918
|
+
children: [
|
1919
|
+
/* @__PURE__ */ jsx(
|
1920
|
+
Flex,
|
1921
|
+
{
|
1922
|
+
tag: "span",
|
1923
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1924
|
+
children: action.icon
|
1925
|
+
}
|
1926
|
+
),
|
1927
|
+
action.label
|
1928
|
+
]
|
1929
|
+
}
|
1930
|
+
),
|
1515
1931
|
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
|
1516
1932
|
Flex,
|
1517
1933
|
{
|
@@ -1570,6 +1986,18 @@ const convertActionVariantToColor = (variant = "secondary") => {
|
|
1570
1986
|
return "primary600";
|
1571
1987
|
}
|
1572
1988
|
};
|
1989
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
1990
|
+
switch (variant) {
|
1991
|
+
case "danger":
|
1992
|
+
return "danger600";
|
1993
|
+
case "secondary":
|
1994
|
+
return "neutral500";
|
1995
|
+
case "success":
|
1996
|
+
return "success600";
|
1997
|
+
default:
|
1998
|
+
return "primary600";
|
1999
|
+
}
|
2000
|
+
};
|
1573
2001
|
const DocumentActionConfirmDialog = ({
|
1574
2002
|
onClose,
|
1575
2003
|
onCancel,
|
@@ -1596,11 +2024,11 @@ const DocumentActionConfirmDialog = ({
|
|
1596
2024
|
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
1597
2025
|
/* @__PURE__ */ jsx(Dialog.Body, { children: content }),
|
1598
2026
|
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
1599
|
-
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({
|
2027
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
1600
2028
|
id: "app.components.Button.cancel",
|
1601
2029
|
defaultMessage: "Cancel"
|
1602
2030
|
}) }) }),
|
1603
|
-
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, children: formatMessage({
|
2031
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
1604
2032
|
id: "app.components.Button.confirm",
|
1605
2033
|
defaultMessage: "Confirm"
|
1606
2034
|
}) })
|
@@ -1627,8 +2055,20 @@ const DocumentActionModal = ({
|
|
1627
2055
|
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
1628
2056
|
] }) });
|
1629
2057
|
};
|
1630
|
-
const
|
1631
|
-
|
2058
|
+
const transformData = (data) => {
|
2059
|
+
if (Array.isArray(data)) {
|
2060
|
+
return data.map(transformData);
|
2061
|
+
}
|
2062
|
+
if (typeof data === "object" && data !== null) {
|
2063
|
+
if ("apiData" in data) {
|
2064
|
+
return data.apiData;
|
2065
|
+
}
|
2066
|
+
return mapValues(transformData)(data);
|
2067
|
+
}
|
2068
|
+
return data;
|
2069
|
+
};
|
2070
|
+
const PublishAction$1 = ({
|
2071
|
+
activeTab,
|
1632
2072
|
documentId,
|
1633
2073
|
model,
|
1634
2074
|
collectionType,
|
@@ -1639,13 +2079,17 @@ const PublishAction$1 = ({
|
|
1639
2079
|
const navigate = useNavigate();
|
1640
2080
|
const { toggleNotification } = useNotification();
|
1641
2081
|
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
2082
|
+
const isListView = useMatch(LIST_PATH) !== null;
|
1642
2083
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
1643
2084
|
const { formatMessage } = useIntl();
|
1644
|
-
const { canPublish
|
1645
|
-
"PublishAction",
|
1646
|
-
({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
|
1647
|
-
);
|
2085
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1648
2086
|
const { publish } = useDocumentActions();
|
2087
|
+
const [
|
2088
|
+
countDraftRelations,
|
2089
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2090
|
+
] = useLazyGetDraftRelationCountQuery();
|
2091
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
|
2092
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
|
1649
2093
|
const [{ query, rawQuery }] = useQueryParams();
|
1650
2094
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1651
2095
|
const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
@@ -1654,10 +2098,105 @@ const PublishAction$1 = ({
|
|
1654
2098
|
const validate = useForm("PublishAction", (state) => state.validate);
|
1655
2099
|
const setErrors = useForm("PublishAction", (state) => state.setErrors);
|
1656
2100
|
const formValues = useForm("PublishAction", ({ values }) => values);
|
2101
|
+
React.useEffect(() => {
|
2102
|
+
if (isErrorDraftRelations) {
|
2103
|
+
toggleNotification({
|
2104
|
+
type: "danger",
|
2105
|
+
message: formatMessage({
|
2106
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2107
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2108
|
+
})
|
2109
|
+
});
|
2110
|
+
}
|
2111
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2112
|
+
React.useEffect(() => {
|
2113
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2114
|
+
const extractDraftRelations = (data) => {
|
2115
|
+
const relations = data.connect || [];
|
2116
|
+
relations.forEach((relation) => {
|
2117
|
+
if (relation.status === "draft") {
|
2118
|
+
localDraftRelations.add(relation.id);
|
2119
|
+
}
|
2120
|
+
});
|
2121
|
+
};
|
2122
|
+
const traverseAndExtract = (data) => {
|
2123
|
+
Object.entries(data).forEach(([key, value]) => {
|
2124
|
+
if (key === "connect" && Array.isArray(value)) {
|
2125
|
+
extractDraftRelations({ connect: value });
|
2126
|
+
} else if (typeof value === "object" && value !== null) {
|
2127
|
+
traverseAndExtract(value);
|
2128
|
+
}
|
2129
|
+
});
|
2130
|
+
};
|
2131
|
+
if (!documentId || modified) {
|
2132
|
+
traverseAndExtract(formValues);
|
2133
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2134
|
+
}
|
2135
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2136
|
+
React.useEffect(() => {
|
2137
|
+
if (!document || !document.documentId || isListView) {
|
2138
|
+
return;
|
2139
|
+
}
|
2140
|
+
const fetchDraftRelationsCount = async () => {
|
2141
|
+
const { data, error } = await countDraftRelations({
|
2142
|
+
collectionType,
|
2143
|
+
model,
|
2144
|
+
documentId,
|
2145
|
+
params
|
2146
|
+
});
|
2147
|
+
if (error) {
|
2148
|
+
throw error;
|
2149
|
+
}
|
2150
|
+
if (data) {
|
2151
|
+
setServerCountOfDraftRelations(data.data);
|
2152
|
+
}
|
2153
|
+
};
|
2154
|
+
fetchDraftRelationsCount();
|
2155
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
1657
2156
|
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1658
2157
|
if (!schema?.options?.draftAndPublish) {
|
1659
2158
|
return null;
|
1660
2159
|
}
|
2160
|
+
const performPublish = async () => {
|
2161
|
+
setSubmitting(true);
|
2162
|
+
try {
|
2163
|
+
const { errors } = await validate(true, {
|
2164
|
+
status: "published"
|
2165
|
+
});
|
2166
|
+
if (errors) {
|
2167
|
+
toggleNotification({
|
2168
|
+
type: "danger",
|
2169
|
+
message: formatMessage({
|
2170
|
+
id: "content-manager.validation.error",
|
2171
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2172
|
+
})
|
2173
|
+
});
|
2174
|
+
return;
|
2175
|
+
}
|
2176
|
+
const res = await publish(
|
2177
|
+
{
|
2178
|
+
collectionType,
|
2179
|
+
model,
|
2180
|
+
documentId,
|
2181
|
+
params
|
2182
|
+
},
|
2183
|
+
transformData(formValues)
|
2184
|
+
);
|
2185
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2186
|
+
navigate({
|
2187
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2188
|
+
search: rawQuery
|
2189
|
+
});
|
2190
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2191
|
+
setErrors(formatValidationErrors(res.error));
|
2192
|
+
}
|
2193
|
+
} finally {
|
2194
|
+
setSubmitting(false);
|
2195
|
+
}
|
2196
|
+
};
|
2197
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2198
|
+
const enableDraftRelationsCount = false;
|
2199
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
1661
2200
|
return {
|
1662
2201
|
/**
|
1663
2202
|
* Disabled when:
|
@@ -1667,49 +2206,36 @@ const PublishAction$1 = ({
|
|
1667
2206
|
* - the document is already published & not modified
|
1668
2207
|
* - the document is being created & not modified
|
1669
2208
|
* - the user doesn't have the permission to publish
|
1670
|
-
* - the user doesn't have the permission to create a new document
|
1671
|
-
* - the user doesn't have the permission to update the document
|
1672
2209
|
*/
|
1673
|
-
disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish
|
2210
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1674
2211
|
label: formatMessage({
|
1675
2212
|
id: "app.utils.publish",
|
1676
2213
|
defaultMessage: "Publish"
|
1677
2214
|
}),
|
1678
2215
|
onClick: async () => {
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
documentId,
|
1697
|
-
params
|
1698
|
-
},
|
1699
|
-
formValues
|
1700
|
-
);
|
1701
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1702
|
-
navigate({
|
1703
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1704
|
-
search: rawQuery
|
1705
|
-
});
|
1706
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1707
|
-
setErrors(formatValidationErrors(res.error));
|
2216
|
+
await performPublish();
|
2217
|
+
},
|
2218
|
+
dialog: hasDraftRelations ? {
|
2219
|
+
type: "dialog",
|
2220
|
+
variant: "danger",
|
2221
|
+
footer: null,
|
2222
|
+
title: formatMessage({
|
2223
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2224
|
+
defaultMessage: "Confirmation"
|
2225
|
+
}),
|
2226
|
+
content: formatMessage(
|
2227
|
+
{
|
2228
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2229
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2230
|
+
},
|
2231
|
+
{
|
2232
|
+
count: totalDraftRelations
|
1708
2233
|
}
|
1709
|
-
|
1710
|
-
|
2234
|
+
),
|
2235
|
+
onConfirm: async () => {
|
2236
|
+
await performPublish();
|
1711
2237
|
}
|
1712
|
-
}
|
2238
|
+
} : void 0
|
1713
2239
|
};
|
1714
2240
|
};
|
1715
2241
|
PublishAction$1.type = "publish";
|
@@ -1725,10 +2251,6 @@ const UpdateAction = ({
|
|
1725
2251
|
const cloneMatch = useMatch(CLONE_PATH);
|
1726
2252
|
const isCloning = cloneMatch !== null;
|
1727
2253
|
const { formatMessage } = useIntl();
|
1728
|
-
const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
|
1729
|
-
canCreate: canCreate2,
|
1730
|
-
canUpdate: canUpdate2
|
1731
|
-
}));
|
1732
2254
|
const { create, update, clone } = useDocumentActions();
|
1733
2255
|
const [{ query, rawQuery }] = useQueryParams();
|
1734
2256
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
@@ -1745,10 +2267,8 @@ const UpdateAction = ({
|
|
1745
2267
|
* - the form is submitting
|
1746
2268
|
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
1747
2269
|
* - the active tab is the published tab
|
1748
|
-
* - the user doesn't have the permission to create a new document
|
1749
|
-
* - the user doesn't have the permission to update the document
|
1750
2270
|
*/
|
1751
|
-
disabled: isSubmitting || !modified && !isCloning || activeTab === "published"
|
2271
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
1752
2272
|
label: formatMessage({
|
1753
2273
|
id: "content-manager.containers.Edit.save",
|
1754
2274
|
defaultMessage: "Save"
|
@@ -1756,7 +2276,9 @@ const UpdateAction = ({
|
|
1756
2276
|
onClick: async () => {
|
1757
2277
|
setSubmitting(true);
|
1758
2278
|
try {
|
1759
|
-
const { errors } = await validate(
|
2279
|
+
const { errors } = await validate(true, {
|
2280
|
+
status: "draft"
|
2281
|
+
});
|
1760
2282
|
if (errors) {
|
1761
2283
|
toggleNotification({
|
1762
2284
|
type: "danger",
|
@@ -1774,13 +2296,16 @@ const UpdateAction = ({
|
|
1774
2296
|
documentId: cloneMatch.params.origin,
|
1775
2297
|
params
|
1776
2298
|
},
|
1777
|
-
document
|
2299
|
+
transformData(document)
|
1778
2300
|
);
|
1779
2301
|
if ("data" in res) {
|
1780
|
-
navigate(
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
2302
|
+
navigate(
|
2303
|
+
{
|
2304
|
+
pathname: `../${res.data.documentId}`,
|
2305
|
+
search: rawQuery
|
2306
|
+
},
|
2307
|
+
{ relative: "path" }
|
2308
|
+
);
|
1784
2309
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1785
2310
|
setErrors(formatValidationErrors(res.error));
|
1786
2311
|
}
|
@@ -1792,7 +2317,7 @@ const UpdateAction = ({
|
|
1792
2317
|
documentId,
|
1793
2318
|
params
|
1794
2319
|
},
|
1795
|
-
document
|
2320
|
+
transformData(document)
|
1796
2321
|
);
|
1797
2322
|
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1798
2323
|
setErrors(formatValidationErrors(res.error));
|
@@ -1805,13 +2330,16 @@ const UpdateAction = ({
|
|
1805
2330
|
model,
|
1806
2331
|
params
|
1807
2332
|
},
|
1808
|
-
document
|
2333
|
+
transformData(document)
|
1809
2334
|
);
|
1810
2335
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1811
|
-
navigate(
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
2336
|
+
navigate(
|
2337
|
+
{
|
2338
|
+
pathname: `../${res.data.documentId}`,
|
2339
|
+
search: rawQuery
|
2340
|
+
},
|
2341
|
+
{ replace: true, relative: "path" }
|
2342
|
+
);
|
1815
2343
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1816
2344
|
setErrors(formatValidationErrors(res.error));
|
1817
2345
|
}
|
@@ -1855,7 +2383,7 @@ const UnpublishAction$1 = ({
|
|
1855
2383
|
id: "app.utils.unpublish",
|
1856
2384
|
defaultMessage: "Unpublish"
|
1857
2385
|
}),
|
1858
|
-
icon: /* @__PURE__ */ jsx(
|
2386
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
1859
2387
|
onClick: async () => {
|
1860
2388
|
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
1861
2389
|
if (!documentId) {
|
@@ -1967,7 +2495,7 @@ const DiscardAction = ({
|
|
1967
2495
|
id: "content-manager.actions.discard.label",
|
1968
2496
|
defaultMessage: "Discard changes"
|
1969
2497
|
}),
|
1970
|
-
icon: /* @__PURE__ */ jsx(
|
2498
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
1971
2499
|
position: ["panel", "table-row"],
|
1972
2500
|
variant: "danger",
|
1973
2501
|
dialog: {
|
@@ -1995,11 +2523,6 @@ const DiscardAction = ({
|
|
1995
2523
|
};
|
1996
2524
|
};
|
1997
2525
|
DiscardAction.type = "discard";
|
1998
|
-
const StyledCrossCircle = styled(CrossCircle)`
|
1999
|
-
path {
|
2000
|
-
fill: currentColor;
|
2001
|
-
}
|
2002
|
-
`;
|
2003
2526
|
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2004
2527
|
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2005
2528
|
const RelativeTime = React.forwardRef(
|
@@ -2047,7 +2570,7 @@ const getDisplayName = ({
|
|
2047
2570
|
};
|
2048
2571
|
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2049
2572
|
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2050
|
-
const statusVariant = status === "draft" ? "
|
2573
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2051
2574
|
return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2052
2575
|
};
|
2053
2576
|
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
@@ -2057,23 +2580,13 @@ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
|
2057
2580
|
id: "content-manager.containers.edit.title.new",
|
2058
2581
|
defaultMessage: "Create an entry"
|
2059
2582
|
}) : documentTitle;
|
2060
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop:
|
2583
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2061
2584
|
/* @__PURE__ */ jsx(BackButton, {}),
|
2062
|
-
/* @__PURE__ */ jsxs(
|
2063
|
-
|
2064
|
-
{
|
2065
|
-
|
2066
|
-
|
2067
|
-
paddingTop: 1,
|
2068
|
-
gap: "80px",
|
2069
|
-
alignItems: "flex-start",
|
2070
|
-
children: [
|
2071
|
-
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2072
|
-
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2073
|
-
]
|
2074
|
-
}
|
2075
|
-
),
|
2076
|
-
status ? /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
|
2585
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2586
|
+
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2587
|
+
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2588
|
+
] }),
|
2589
|
+
status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2077
2590
|
] });
|
2078
2591
|
};
|
2079
2592
|
const HeaderToolbar = () => {
|
@@ -2156,12 +2669,12 @@ const Information = ({ activeTab }) => {
|
|
2156
2669
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2157
2670
|
label: formatMessage({
|
2158
2671
|
id: "content-manager.containers.edit.information.last-published.label",
|
2159
|
-
defaultMessage: "
|
2672
|
+
defaultMessage: "Published"
|
2160
2673
|
}),
|
2161
2674
|
value: formatMessage(
|
2162
2675
|
{
|
2163
2676
|
id: "content-manager.containers.edit.information.last-published.value",
|
2164
|
-
defaultMessage: `
|
2677
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2165
2678
|
},
|
2166
2679
|
{
|
2167
2680
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2174,12 +2687,12 @@ const Information = ({ activeTab }) => {
|
|
2174
2687
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2175
2688
|
label: formatMessage({
|
2176
2689
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2177
|
-
defaultMessage: "
|
2690
|
+
defaultMessage: "Updated"
|
2178
2691
|
}),
|
2179
2692
|
value: formatMessage(
|
2180
2693
|
{
|
2181
2694
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2182
|
-
defaultMessage: `
|
2695
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2183
2696
|
},
|
2184
2697
|
{
|
2185
2698
|
time: /* @__PURE__ */ jsx(
|
@@ -2197,12 +2710,12 @@ const Information = ({ activeTab }) => {
|
|
2197
2710
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2198
2711
|
label: formatMessage({
|
2199
2712
|
id: "content-manager.containers.edit.information.document.label",
|
2200
|
-
defaultMessage: "
|
2713
|
+
defaultMessage: "Created"
|
2201
2714
|
}),
|
2202
2715
|
value: formatMessage(
|
2203
2716
|
{
|
2204
2717
|
id: "content-manager.containers.edit.information.document.value",
|
2205
|
-
defaultMessage: `
|
2718
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2206
2719
|
},
|
2207
2720
|
{
|
2208
2721
|
time: /* @__PURE__ */ jsx(
|
@@ -2240,25 +2753,77 @@ const Information = ({ activeTab }) => {
|
|
2240
2753
|
);
|
2241
2754
|
};
|
2242
2755
|
const HeaderActions = ({ actions: actions2 }) => {
|
2243
|
-
|
2244
|
-
|
2756
|
+
const [dialogId, setDialogId] = React.useState(null);
|
2757
|
+
const handleClick = (action) => async (e) => {
|
2758
|
+
if (!("options" in action)) {
|
2759
|
+
const { onClick = () => false, dialog, id } = action;
|
2760
|
+
const muteDialog = await onClick(e);
|
2761
|
+
if (dialog && !muteDialog) {
|
2762
|
+
e.preventDefault();
|
2763
|
+
setDialogId(id);
|
2764
|
+
}
|
2765
|
+
}
|
2766
|
+
};
|
2767
|
+
const handleClose = () => {
|
2768
|
+
setDialogId(null);
|
2769
|
+
};
|
2770
|
+
return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
|
2771
|
+
if (action.options) {
|
2245
2772
|
return /* @__PURE__ */ jsx(
|
2246
2773
|
SingleSelect,
|
2247
2774
|
{
|
2248
2775
|
size: "S",
|
2249
|
-
disabled: action.disabled,
|
2250
|
-
"aria-label": action.label,
|
2251
2776
|
onChange: action.onSelect,
|
2252
|
-
|
2777
|
+
"aria-label": action.label,
|
2778
|
+
...action,
|
2253
2779
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2254
2780
|
},
|
2255
2781
|
action.id
|
2256
2782
|
);
|
2257
2783
|
} else {
|
2258
|
-
|
2784
|
+
if (action.type === "icon") {
|
2785
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
2786
|
+
/* @__PURE__ */ jsx(
|
2787
|
+
IconButton,
|
2788
|
+
{
|
2789
|
+
disabled: action.disabled,
|
2790
|
+
label: action.label,
|
2791
|
+
size: "S",
|
2792
|
+
onClick: handleClick(action),
|
2793
|
+
children: action.icon
|
2794
|
+
}
|
2795
|
+
),
|
2796
|
+
action.dialog ? /* @__PURE__ */ jsx(
|
2797
|
+
HeaderActionDialog,
|
2798
|
+
{
|
2799
|
+
...action.dialog,
|
2800
|
+
isOpen: dialogId === action.id,
|
2801
|
+
onClose: handleClose
|
2802
|
+
}
|
2803
|
+
) : null
|
2804
|
+
] }, action.id);
|
2805
|
+
}
|
2259
2806
|
}
|
2260
2807
|
}) });
|
2261
2808
|
};
|
2809
|
+
const HeaderActionDialog = ({
|
2810
|
+
onClose,
|
2811
|
+
onCancel,
|
2812
|
+
title,
|
2813
|
+
content: Content,
|
2814
|
+
isOpen
|
2815
|
+
}) => {
|
2816
|
+
const handleClose = async () => {
|
2817
|
+
if (onCancel) {
|
2818
|
+
await onCancel();
|
2819
|
+
}
|
2820
|
+
onClose();
|
2821
|
+
};
|
2822
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2823
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2824
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
|
2825
|
+
] }) });
|
2826
|
+
};
|
2262
2827
|
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
2263
2828
|
const navigate = useNavigate();
|
2264
2829
|
const { formatMessage } = useIntl();
|
@@ -2299,12 +2864,16 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2299
2864
|
const { delete: deleteAction } = useDocumentActions();
|
2300
2865
|
const { toggleNotification } = useNotification();
|
2301
2866
|
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2867
|
+
const isLocalized = document?.locale != null;
|
2302
2868
|
return {
|
2303
2869
|
disabled: !canDelete || !document,
|
2304
|
-
label: formatMessage(
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2870
|
+
label: formatMessage(
|
2871
|
+
{
|
2872
|
+
id: "content-manager.actions.delete.label",
|
2873
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2874
|
+
},
|
2875
|
+
{ isLocalized }
|
2876
|
+
),
|
2308
2877
|
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2309
2878
|
dialog: {
|
2310
2879
|
type: "dialog",
|
@@ -2352,411 +2921,109 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2352
2921
|
if (!listViewPathMatch) {
|
2353
2922
|
setSubmitting(false);
|
2354
2923
|
}
|
2355
|
-
}
|
2356
|
-
}
|
2357
|
-
},
|
2358
|
-
variant: "danger",
|
2359
|
-
position: ["header", "table-row"]
|
2360
|
-
};
|
2361
|
-
};
|
2362
|
-
DeleteAction$1.type = "delete";
|
2363
|
-
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2364
|
-
const Panels = () => {
|
2365
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
2366
|
-
const [
|
2367
|
-
{
|
2368
|
-
query: { status }
|
2369
|
-
}
|
2370
|
-
] = useQueryParams({
|
2371
|
-
status: "draft"
|
2372
|
-
});
|
2373
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2374
|
-
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2375
|
-
const props = {
|
2376
|
-
activeTab: status,
|
2377
|
-
model,
|
2378
|
-
documentId: id,
|
2379
|
-
document: isCloning ? void 0 : document,
|
2380
|
-
meta: isCloning ? void 0 : meta,
|
2381
|
-
collectionType
|
2382
|
-
};
|
2383
|
-
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2384
|
-
DescriptionComponentRenderer,
|
2385
|
-
{
|
2386
|
-
props,
|
2387
|
-
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2388
|
-
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2389
|
-
}
|
2390
|
-
) });
|
2391
|
-
};
|
2392
|
-
const ActionsPanel = () => {
|
2393
|
-
const { formatMessage } = useIntl();
|
2394
|
-
return {
|
2395
|
-
title: formatMessage({
|
2396
|
-
id: "content-manager.containers.edit.panels.default.title",
|
2397
|
-
defaultMessage: "Document"
|
2398
|
-
}),
|
2399
|
-
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2400
|
-
};
|
2401
|
-
};
|
2402
|
-
ActionsPanel.type = "actions";
|
2403
|
-
const ActionsPanelContent = () => {
|
2404
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
2405
|
-
const [
|
2406
|
-
{
|
2407
|
-
query: { status = "draft" }
|
2408
|
-
}
|
2409
|
-
] = useQueryParams();
|
2410
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2411
|
-
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2412
|
-
const props = {
|
2413
|
-
activeTab: status,
|
2414
|
-
model,
|
2415
|
-
documentId: id,
|
2416
|
-
document: isCloning ? void 0 : document,
|
2417
|
-
meta: isCloning ? void 0 : meta,
|
2418
|
-
collectionType
|
2419
|
-
};
|
2420
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2421
|
-
/* @__PURE__ */ jsx(
|
2422
|
-
DescriptionComponentRenderer,
|
2423
|
-
{
|
2424
|
-
props,
|
2425
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2426
|
-
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2427
|
-
}
|
2428
|
-
),
|
2429
|
-
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2430
|
-
] });
|
2431
|
-
};
|
2432
|
-
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2433
|
-
return /* @__PURE__ */ jsxs(
|
2434
|
-
Flex,
|
2435
|
-
{
|
2436
|
-
ref,
|
2437
|
-
tag: "aside",
|
2438
|
-
"aria-labelledby": "additional-information",
|
2439
|
-
background: "neutral0",
|
2440
|
-
borderColor: "neutral150",
|
2441
|
-
hasRadius: true,
|
2442
|
-
paddingBottom: 4,
|
2443
|
-
paddingLeft: 4,
|
2444
|
-
paddingRight: 4,
|
2445
|
-
paddingTop: 4,
|
2446
|
-
shadow: "tableShadow",
|
2447
|
-
gap: 3,
|
2448
|
-
direction: "column",
|
2449
|
-
justifyContent: "stretch",
|
2450
|
-
alignItems: "flex-start",
|
2451
|
-
children: [
|
2452
|
-
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2453
|
-
children
|
2454
|
-
]
|
2455
|
-
}
|
2456
|
-
);
|
2457
|
-
});
|
2458
|
-
const HOOKS = {
|
2459
|
-
/**
|
2460
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2461
|
-
* @constant
|
2462
|
-
* @type {string}
|
2463
|
-
*/
|
2464
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2465
|
-
/**
|
2466
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2467
|
-
* @constant
|
2468
|
-
* @type {string}
|
2469
|
-
*/
|
2470
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2471
|
-
/**
|
2472
|
-
* Hook that allows to mutate the CM's edit view layout
|
2473
|
-
* @constant
|
2474
|
-
* @type {string}
|
2475
|
-
*/
|
2476
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2477
|
-
/**
|
2478
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2479
|
-
* @constant
|
2480
|
-
* @type {string}
|
2481
|
-
*/
|
2482
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2483
|
-
};
|
2484
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2485
|
-
endpoints: (builder) => ({
|
2486
|
-
getContentTypeConfiguration: builder.query({
|
2487
|
-
query: (uid) => ({
|
2488
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2489
|
-
method: "GET"
|
2490
|
-
}),
|
2491
|
-
transformResponse: (response) => response.data,
|
2492
|
-
providesTags: (_result, _error, uid) => [
|
2493
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2494
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
2495
|
-
]
|
2496
|
-
}),
|
2497
|
-
getAllContentTypeSettings: builder.query({
|
2498
|
-
query: () => "/content-manager/content-types-settings",
|
2499
|
-
transformResponse: (response) => response.data,
|
2500
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
2501
|
-
}),
|
2502
|
-
updateContentTypeConfiguration: builder.mutation({
|
2503
|
-
query: ({ uid, ...body }) => ({
|
2504
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2505
|
-
method: "PUT",
|
2506
|
-
data: body
|
2507
|
-
}),
|
2508
|
-
transformResponse: (response) => response.data,
|
2509
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
2510
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2511
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
2512
|
-
// Is this necessary?
|
2513
|
-
{ type: "InitialData" }
|
2514
|
-
]
|
2515
|
-
})
|
2516
|
-
})
|
2517
|
-
});
|
2518
|
-
const {
|
2519
|
-
useGetContentTypeConfigurationQuery,
|
2520
|
-
useGetAllContentTypeSettingsQuery,
|
2521
|
-
useUpdateContentTypeConfigurationMutation
|
2522
|
-
} = contentTypesApi;
|
2523
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
2524
|
-
const { type } = attribute;
|
2525
|
-
if (type === "relation") {
|
2526
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
2527
|
-
}
|
2528
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
2529
|
-
};
|
2530
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
2531
|
-
if (!mainFieldName) {
|
2532
|
-
return void 0;
|
2533
|
-
}
|
2534
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
2535
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
2536
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
2537
|
-
);
|
2538
|
-
return {
|
2539
|
-
name: mainFieldName,
|
2540
|
-
type: mainFieldType ?? "string"
|
2541
|
-
};
|
2542
|
-
};
|
2543
|
-
const DEFAULT_SETTINGS = {
|
2544
|
-
bulkable: false,
|
2545
|
-
filterable: false,
|
2546
|
-
searchable: false,
|
2547
|
-
pagination: false,
|
2548
|
-
defaultSortBy: "",
|
2549
|
-
defaultSortOrder: "asc",
|
2550
|
-
mainField: "id",
|
2551
|
-
pageSize: 10
|
2552
|
-
};
|
2553
|
-
const useDocumentLayout = (model) => {
|
2554
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
2555
|
-
const [{ query }] = useQueryParams();
|
2556
|
-
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
2557
|
-
const { toggleNotification } = useNotification();
|
2558
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
2559
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
2560
|
-
const {
|
2561
|
-
data,
|
2562
|
-
isLoading: isLoadingConfigs,
|
2563
|
-
error,
|
2564
|
-
isFetching: isFetchingConfigs
|
2565
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2566
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2567
|
-
React.useEffect(() => {
|
2568
|
-
if (error) {
|
2569
|
-
toggleNotification({
|
2570
|
-
type: "danger",
|
2571
|
-
message: formatAPIError(error)
|
2572
|
-
});
|
2573
|
-
}
|
2574
|
-
}, [error, formatAPIError, toggleNotification]);
|
2575
|
-
const editLayout = React.useMemo(
|
2576
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2577
|
-
layout: [],
|
2578
|
-
components: {},
|
2579
|
-
metadatas: {},
|
2580
|
-
options: {},
|
2581
|
-
settings: DEFAULT_SETTINGS
|
2582
|
-
},
|
2583
|
-
[data, isLoading, schemas, schema, components]
|
2584
|
-
);
|
2585
|
-
const listLayout = React.useMemo(() => {
|
2586
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2587
|
-
layout: [],
|
2588
|
-
metadatas: {},
|
2589
|
-
options: {},
|
2590
|
-
settings: DEFAULT_SETTINGS
|
2591
|
-
};
|
2592
|
-
}, [data, isLoading, schemas, schema, components]);
|
2593
|
-
const { layout: edit } = React.useMemo(
|
2594
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2595
|
-
layout: editLayout,
|
2596
|
-
query
|
2597
|
-
}),
|
2598
|
-
[editLayout, query, runHookWaterfall]
|
2599
|
-
);
|
2600
|
-
return {
|
2601
|
-
error,
|
2602
|
-
isLoading,
|
2603
|
-
edit,
|
2604
|
-
list: listLayout
|
2605
|
-
};
|
2606
|
-
};
|
2607
|
-
const useDocLayout = () => {
|
2608
|
-
const { model } = useDoc();
|
2609
|
-
return useDocumentLayout(model);
|
2610
|
-
};
|
2611
|
-
const formatEditLayout = (data, {
|
2612
|
-
schemas,
|
2613
|
-
schema,
|
2614
|
-
components
|
2615
|
-
}) => {
|
2616
|
-
let currentPanelIndex = 0;
|
2617
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
2618
|
-
data.contentType.layouts.edit,
|
2619
|
-
schema?.attributes,
|
2620
|
-
data.contentType.metadatas,
|
2621
|
-
{ configurations: data.components, schemas: components },
|
2622
|
-
schemas
|
2623
|
-
).reduce((panels, row) => {
|
2624
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2625
|
-
panels.push([row]);
|
2626
|
-
currentPanelIndex += 2;
|
2627
|
-
} else {
|
2628
|
-
if (!panels[currentPanelIndex]) {
|
2629
|
-
panels.push([]);
|
2630
|
-
}
|
2631
|
-
panels[currentPanelIndex].push(row);
|
2632
|
-
}
|
2633
|
-
return panels;
|
2634
|
-
}, []);
|
2635
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
2636
|
-
(acc, [uid, configuration]) => {
|
2637
|
-
acc[uid] = {
|
2638
|
-
layout: convertEditLayoutToFieldLayouts(
|
2639
|
-
configuration.layouts.edit,
|
2640
|
-
components[uid].attributes,
|
2641
|
-
configuration.metadatas
|
2642
|
-
),
|
2643
|
-
settings: {
|
2644
|
-
...configuration.settings,
|
2645
|
-
icon: components[uid].info.icon,
|
2646
|
-
displayName: components[uid].info.displayName
|
2647
|
-
}
|
2648
|
-
};
|
2649
|
-
return acc;
|
2650
|
-
},
|
2651
|
-
{}
|
2652
|
-
);
|
2653
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2654
|
-
(acc, [attribute, metadata]) => {
|
2655
|
-
return {
|
2656
|
-
...acc,
|
2657
|
-
[attribute]: metadata.edit
|
2658
|
-
};
|
2659
|
-
},
|
2660
|
-
{}
|
2661
|
-
);
|
2662
|
-
return {
|
2663
|
-
layout: panelledEditAttributes,
|
2664
|
-
components: componentEditAttributes,
|
2665
|
-
metadatas: editMetadatas,
|
2666
|
-
settings: {
|
2667
|
-
...data.contentType.settings,
|
2668
|
-
displayName: schema?.info.displayName
|
2924
|
+
}
|
2925
|
+
}
|
2669
2926
|
},
|
2670
|
-
|
2671
|
-
|
2672
|
-
...schema?.pluginOptions,
|
2673
|
-
...data.contentType.options
|
2674
|
-
}
|
2927
|
+
variant: "danger",
|
2928
|
+
position: ["header", "table-row"]
|
2675
2929
|
};
|
2676
2930
|
};
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2683
|
-
}
|
2684
|
-
|
2685
|
-
|
2686
|
-
|
2687
|
-
|
2688
|
-
|
2689
|
-
|
2690
|
-
|
2691
|
-
|
2692
|
-
|
2693
|
-
|
2694
|
-
|
2695
|
-
|
2696
|
-
|
2697
|
-
|
2698
|
-
|
2699
|
-
|
2700
|
-
|
2701
|
-
|
2702
|
-
|
2703
|
-
}
|
2704
|
-
}
|
2705
|
-
);
|
2931
|
+
DeleteAction$1.type = "delete";
|
2932
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2933
|
+
const Panels = () => {
|
2934
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2935
|
+
const [
|
2936
|
+
{
|
2937
|
+
query: { status }
|
2938
|
+
}
|
2939
|
+
] = useQueryParams({
|
2940
|
+
status: "draft"
|
2941
|
+
});
|
2942
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2943
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2944
|
+
const props = {
|
2945
|
+
activeTab: status,
|
2946
|
+
model,
|
2947
|
+
documentId: id,
|
2948
|
+
document: isCloning ? void 0 : document,
|
2949
|
+
meta: isCloning ? void 0 : meta,
|
2950
|
+
collectionType
|
2951
|
+
};
|
2952
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2953
|
+
DescriptionComponentRenderer,
|
2954
|
+
{
|
2955
|
+
props,
|
2956
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2957
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2958
|
+
}
|
2959
|
+
) });
|
2706
2960
|
};
|
2707
|
-
const
|
2708
|
-
|
2709
|
-
schema,
|
2710
|
-
components
|
2711
|
-
}) => {
|
2712
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2713
|
-
(acc, [attribute, metadata]) => {
|
2714
|
-
return {
|
2715
|
-
...acc,
|
2716
|
-
[attribute]: metadata.list
|
2717
|
-
};
|
2718
|
-
},
|
2719
|
-
{}
|
2720
|
-
);
|
2721
|
-
const listAttributes = convertListLayoutToFieldLayouts(
|
2722
|
-
data.contentType.layouts.list,
|
2723
|
-
schema?.attributes,
|
2724
|
-
listMetadatas,
|
2725
|
-
{ configurations: data.components, schemas: components },
|
2726
|
-
schemas
|
2727
|
-
);
|
2961
|
+
const ActionsPanel = () => {
|
2962
|
+
const { formatMessage } = useIntl();
|
2728
2963
|
return {
|
2729
|
-
|
2730
|
-
|
2731
|
-
|
2732
|
-
|
2733
|
-
|
2734
|
-
...schema?.pluginOptions,
|
2735
|
-
...data.contentType.options
|
2736
|
-
}
|
2964
|
+
title: formatMessage({
|
2965
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2966
|
+
defaultMessage: "Entry"
|
2967
|
+
}),
|
2968
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2737
2969
|
};
|
2738
2970
|
};
|
2739
|
-
|
2740
|
-
|
2741
|
-
|
2742
|
-
|
2743
|
-
|
2971
|
+
ActionsPanel.type = "actions";
|
2972
|
+
const ActionsPanelContent = () => {
|
2973
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2974
|
+
const [
|
2975
|
+
{
|
2976
|
+
query: { status = "draft" }
|
2744
2977
|
}
|
2745
|
-
|
2746
|
-
|
2747
|
-
|
2748
|
-
|
2749
|
-
|
2750
|
-
|
2751
|
-
|
2752
|
-
|
2753
|
-
|
2754
|
-
|
2755
|
-
|
2756
|
-
|
2757
|
-
|
2758
|
-
|
2978
|
+
] = useQueryParams();
|
2979
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2980
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2981
|
+
const props = {
|
2982
|
+
activeTab: status,
|
2983
|
+
model,
|
2984
|
+
documentId: id,
|
2985
|
+
document: isCloning ? void 0 : document,
|
2986
|
+
meta: isCloning ? void 0 : meta,
|
2987
|
+
collectionType
|
2988
|
+
};
|
2989
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2990
|
+
/* @__PURE__ */ jsx(
|
2991
|
+
DescriptionComponentRenderer,
|
2992
|
+
{
|
2993
|
+
props,
|
2994
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2995
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2996
|
+
}
|
2997
|
+
),
|
2998
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2999
|
+
] });
|
2759
3000
|
};
|
3001
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
3002
|
+
return /* @__PURE__ */ jsxs(
|
3003
|
+
Flex,
|
3004
|
+
{
|
3005
|
+
ref,
|
3006
|
+
tag: "aside",
|
3007
|
+
"aria-labelledby": "additional-information",
|
3008
|
+
background: "neutral0",
|
3009
|
+
borderColor: "neutral150",
|
3010
|
+
hasRadius: true,
|
3011
|
+
paddingBottom: 4,
|
3012
|
+
paddingLeft: 4,
|
3013
|
+
paddingRight: 4,
|
3014
|
+
paddingTop: 4,
|
3015
|
+
shadow: "tableShadow",
|
3016
|
+
gap: 3,
|
3017
|
+
direction: "column",
|
3018
|
+
justifyContent: "stretch",
|
3019
|
+
alignItems: "flex-start",
|
3020
|
+
children: [
|
3021
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
|
3022
|
+
children
|
3023
|
+
]
|
3024
|
+
}
|
3025
|
+
);
|
3026
|
+
});
|
2760
3027
|
const ConfirmBulkActionDialog = ({
|
2761
3028
|
onToggleDialog,
|
2762
3029
|
isOpen = false,
|
@@ -2764,7 +3031,7 @@ const ConfirmBulkActionDialog = ({
|
|
2764
3031
|
endAction
|
2765
3032
|
}) => {
|
2766
3033
|
const { formatMessage } = useIntl();
|
2767
|
-
return /* @__PURE__ */ jsx(Dialog.Root, {
|
3034
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2768
3035
|
/* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
|
2769
3036
|
id: "app.components.ConfirmDialog.title",
|
2770
3037
|
defaultMessage: "Confirmation"
|
@@ -2795,6 +3062,7 @@ const ConfirmDialogPublishAll = ({
|
|
2795
3062
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
|
2796
3063
|
const { model, schema } = useDoc();
|
2797
3064
|
const [{ query }] = useQueryParams();
|
3065
|
+
const enableDraftRelationsCount = false;
|
2798
3066
|
const {
|
2799
3067
|
data: countDraftRelations = 0,
|
2800
3068
|
isLoading,
|
@@ -2806,7 +3074,7 @@ const ConfirmDialogPublishAll = ({
|
|
2806
3074
|
locale: query?.plugins?.i18n?.locale
|
2807
3075
|
},
|
2808
3076
|
{
|
2809
|
-
skip:
|
3077
|
+
skip: !enableDraftRelationsCount
|
2810
3078
|
}
|
2811
3079
|
);
|
2812
3080
|
React.useEffect(() => {
|
@@ -2885,7 +3153,14 @@ const formatErrorMessages = (errors, parentKey, formatMessage) => {
|
|
2885
3153
|
)
|
2886
3154
|
);
|
2887
3155
|
} else {
|
2888
|
-
messages.push(
|
3156
|
+
messages.push(
|
3157
|
+
...formatErrorMessages(
|
3158
|
+
// @ts-expect-error TODO: check why value is not compatible with FormErrors
|
3159
|
+
value,
|
3160
|
+
currentKey,
|
3161
|
+
formatMessage
|
3162
|
+
)
|
3163
|
+
);
|
2889
3164
|
}
|
2890
3165
|
} else {
|
2891
3166
|
messages.push(
|
@@ -2984,7 +3259,7 @@ const SelectedEntriesTableContent = ({
|
|
2984
3259
|
status: row.status
|
2985
3260
|
}
|
2986
3261
|
) }),
|
2987
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
|
3262
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
|
2988
3263
|
IconButton,
|
2989
3264
|
{
|
2990
3265
|
tag: Link,
|
@@ -3007,9 +3282,10 @@ const SelectedEntriesTableContent = ({
|
|
3007
3282
|
),
|
3008
3283
|
target: "_blank",
|
3009
3284
|
marginLeft: "auto",
|
3010
|
-
|
3285
|
+
variant: "ghost",
|
3286
|
+
children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
|
3011
3287
|
}
|
3012
|
-
) })
|
3288
|
+
) }) })
|
3013
3289
|
] }, row.id)) })
|
3014
3290
|
] });
|
3015
3291
|
};
|
@@ -3046,7 +3322,13 @@ const SelectedEntriesModalContent = ({
|
|
3046
3322
|
);
|
3047
3323
|
const { rows, validationErrors } = React.useMemo(() => {
|
3048
3324
|
if (data.length > 0 && schema) {
|
3049
|
-
const validate = createYupSchema(
|
3325
|
+
const validate = createYupSchema(
|
3326
|
+
schema.attributes,
|
3327
|
+
components,
|
3328
|
+
// Since this is the "Publish" action, the validation
|
3329
|
+
// schema must enforce the rules for published entities
|
3330
|
+
{ status: "published" }
|
3331
|
+
);
|
3050
3332
|
const validationErrors2 = {};
|
3051
3333
|
const rows2 = data.map((entry) => {
|
3052
3334
|
try {
|
@@ -3396,7 +3678,7 @@ const TableActions = ({ document }) => {
|
|
3396
3678
|
DescriptionComponentRenderer,
|
3397
3679
|
{
|
3398
3680
|
props,
|
3399
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3681
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
|
3400
3682
|
children: (actions2) => {
|
3401
3683
|
const tableRowActions = actions2.filter((action) => {
|
3402
3684
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -3507,7 +3789,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
3507
3789
|
}),
|
3508
3790
|
content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
|
3509
3791
|
footer: ({ onClose }) => {
|
3510
|
-
return /* @__PURE__ */ jsxs(
|
3792
|
+
return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3511
3793
|
/* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
|
3512
3794
|
id: "cancel",
|
3513
3795
|
defaultMessage: "Cancel"
|
@@ -3548,8 +3830,7 @@ class ContentManagerPlugin {
|
|
3548
3830
|
documentActions = [
|
3549
3831
|
...DEFAULT_ACTIONS,
|
3550
3832
|
...DEFAULT_TABLE_ROW_ACTIONS,
|
3551
|
-
...DEFAULT_HEADER_ACTIONS
|
3552
|
-
HistoryAction
|
3833
|
+
...DEFAULT_HEADER_ACTIONS
|
3553
3834
|
];
|
3554
3835
|
editViewSidePanels = [ActionsPanel];
|
3555
3836
|
headerActions = [];
|
@@ -3638,6 +3919,52 @@ const getPrintableType = (value) => {
|
|
3638
3919
|
}
|
3639
3920
|
return nativeType;
|
3640
3921
|
};
|
3922
|
+
const HistoryAction = ({ model, document }) => {
|
3923
|
+
const { formatMessage } = useIntl();
|
3924
|
+
const [{ query }] = useQueryParams();
|
3925
|
+
const navigate = useNavigate();
|
3926
|
+
const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
|
3927
|
+
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
3928
|
+
return null;
|
3929
|
+
}
|
3930
|
+
return {
|
3931
|
+
icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
|
3932
|
+
label: formatMessage({
|
3933
|
+
id: "content-manager.history.document-action",
|
3934
|
+
defaultMessage: "Content History"
|
3935
|
+
}),
|
3936
|
+
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
3937
|
+
disabled: (
|
3938
|
+
/**
|
3939
|
+
* The user is creating a new document.
|
3940
|
+
* It hasn't been saved yet, so there's no history to go to
|
3941
|
+
*/
|
3942
|
+
!document || /**
|
3943
|
+
* The document has been created but the current dimension has never been saved.
|
3944
|
+
* For example, the user is creating a new locale in an existing document,
|
3945
|
+
* so there's no history for the document in that locale
|
3946
|
+
*/
|
3947
|
+
!document.id || /**
|
3948
|
+
* History is only available for content types created by the user.
|
3949
|
+
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
3950
|
+
* which start with `admin::` or `plugin::`
|
3951
|
+
*/
|
3952
|
+
!model.startsWith("api::")
|
3953
|
+
),
|
3954
|
+
position: "header"
|
3955
|
+
};
|
3956
|
+
};
|
3957
|
+
HistoryAction.type = "history";
|
3958
|
+
const historyAdmin = {
|
3959
|
+
bootstrap(app) {
|
3960
|
+
const { addDocumentAction } = app.getPlugin("content-manager").apis;
|
3961
|
+
addDocumentAction((actions2) => {
|
3962
|
+
const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
|
3963
|
+
actions2.splice(indexOfDeleteAction, 0, HistoryAction);
|
3964
|
+
return actions2;
|
3965
|
+
});
|
3966
|
+
}
|
3967
|
+
};
|
3641
3968
|
const initialState = {
|
3642
3969
|
collectionTypeLinks: [],
|
3643
3970
|
components: [],
|
@@ -3674,6 +4001,82 @@ const { setInitialData } = actions;
|
|
3674
4001
|
const reducer = combineReducers({
|
3675
4002
|
app: reducer$1
|
3676
4003
|
});
|
4004
|
+
const previewApi = contentManagerApi.injectEndpoints({
|
4005
|
+
endpoints: (builder) => ({
|
4006
|
+
getPreviewUrl: builder.query({
|
4007
|
+
query({ query, params }) {
|
4008
|
+
return {
|
4009
|
+
url: `/content-manager/preview/url/${params.contentType}`,
|
4010
|
+
method: "GET",
|
4011
|
+
config: {
|
4012
|
+
params: query
|
4013
|
+
}
|
4014
|
+
};
|
4015
|
+
}
|
4016
|
+
})
|
4017
|
+
})
|
4018
|
+
});
|
4019
|
+
const { useGetPreviewUrlQuery } = previewApi;
|
4020
|
+
const PreviewSidePanel = ({ model, documentId, document }) => {
|
4021
|
+
const { formatMessage } = useIntl();
|
4022
|
+
const { toggleNotification } = useNotification();
|
4023
|
+
const { copy } = useClipboard();
|
4024
|
+
const { data, error } = useGetPreviewUrlQuery({
|
4025
|
+
params: {
|
4026
|
+
contentType: model
|
4027
|
+
},
|
4028
|
+
query: {
|
4029
|
+
documentId,
|
4030
|
+
locale: document?.locale,
|
4031
|
+
status: document?.status
|
4032
|
+
}
|
4033
|
+
});
|
4034
|
+
if (!data?.data?.url || error) {
|
4035
|
+
return null;
|
4036
|
+
}
|
4037
|
+
const { url } = data.data;
|
4038
|
+
const handleCopyLink = () => {
|
4039
|
+
copy(url);
|
4040
|
+
toggleNotification({
|
4041
|
+
message: formatMessage({
|
4042
|
+
id: "content-manager.preview.copy.success",
|
4043
|
+
defaultMessage: "Copied preview link"
|
4044
|
+
}),
|
4045
|
+
type: "success"
|
4046
|
+
});
|
4047
|
+
};
|
4048
|
+
return {
|
4049
|
+
title: formatMessage({ id: "content-manager.preview.panel.title", defaultMessage: "Preview" }),
|
4050
|
+
content: /* @__PURE__ */ jsxs(Flex, { gap: 2, width: "100%", children: [
|
4051
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", tag: Link, to: url, target: "_blank", flex: "auto", children: formatMessage({
|
4052
|
+
id: "content-manager.preview.panel.button",
|
4053
|
+
defaultMessage: "Open preview"
|
4054
|
+
}) }),
|
4055
|
+
/* @__PURE__ */ jsx(
|
4056
|
+
IconButton,
|
4057
|
+
{
|
4058
|
+
type: "button",
|
4059
|
+
label: formatMessage({
|
4060
|
+
id: "preview.copy.label",
|
4061
|
+
defaultMessage: "Copy preview link"
|
4062
|
+
}),
|
4063
|
+
onClick: handleCopyLink,
|
4064
|
+
children: /* @__PURE__ */ jsx(Link$1, {})
|
4065
|
+
}
|
4066
|
+
)
|
4067
|
+
] })
|
4068
|
+
};
|
4069
|
+
};
|
4070
|
+
const FEATURE_ID = "preview";
|
4071
|
+
const previewAdmin = {
|
4072
|
+
bootstrap(app) {
|
4073
|
+
if (!window.strapi.future.isEnabled(FEATURE_ID)) {
|
4074
|
+
return;
|
4075
|
+
}
|
4076
|
+
const contentManagerPluginApis = app.getPlugin("content-manager").apis;
|
4077
|
+
contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
|
4078
|
+
}
|
4079
|
+
};
|
3677
4080
|
const index = {
|
3678
4081
|
register(app) {
|
3679
4082
|
const cm = new ContentManagerPlugin();
|
@@ -3688,15 +4091,32 @@ const index = {
|
|
3688
4091
|
defaultMessage: "Content Manager"
|
3689
4092
|
},
|
3690
4093
|
permissions: [],
|
3691
|
-
Component: () => import("./layout-DC503LnF.mjs").then((mod) => ({ default: mod.Layout })),
|
3692
4094
|
position: 1
|
3693
4095
|
});
|
4096
|
+
app.router.addRoute({
|
4097
|
+
path: "content-manager/*",
|
4098
|
+
lazy: async () => {
|
4099
|
+
const { Layout } = await import("./layout-CrTxOnCy.mjs");
|
4100
|
+
return {
|
4101
|
+
Component: Layout
|
4102
|
+
};
|
4103
|
+
},
|
4104
|
+
children: routes
|
4105
|
+
});
|
3694
4106
|
app.registerPlugin(cm.config);
|
3695
4107
|
},
|
4108
|
+
bootstrap(app) {
|
4109
|
+
if (typeof historyAdmin.bootstrap === "function") {
|
4110
|
+
historyAdmin.bootstrap(app);
|
4111
|
+
}
|
4112
|
+
if (typeof previewAdmin.bootstrap === "function") {
|
4113
|
+
previewAdmin.bootstrap(app);
|
4114
|
+
}
|
4115
|
+
},
|
3696
4116
|
async registerTrads({ locales }) {
|
3697
4117
|
const importedTrads = await Promise.all(
|
3698
4118
|
locales.map((locale) => {
|
3699
|
-
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-
|
4119
|
+
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-CZw4xdPY.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`).then(({ default: data }) => {
|
3700
4120
|
return {
|
3701
4121
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3702
4122
|
locale
|
@@ -3724,7 +4144,8 @@ export {
|
|
3724
4144
|
InjectionZone as I,
|
3725
4145
|
useDocument as J,
|
3726
4146
|
index as K,
|
3727
|
-
|
4147
|
+
useContentManagerContext as L,
|
4148
|
+
useDocumentActions as M,
|
3728
4149
|
Panels as P,
|
3729
4150
|
RelativeTime as R,
|
3730
4151
|
SINGLE_TYPES as S,
|
@@ -3742,11 +4163,11 @@ export {
|
|
3742
4163
|
PERMISSIONS as k,
|
3743
4164
|
DocumentRBAC as l,
|
3744
4165
|
DOCUMENT_META_FIELDS as m,
|
3745
|
-
|
3746
|
-
|
3747
|
-
|
3748
|
-
|
3749
|
-
|
4166
|
+
CLONE_PATH as n,
|
4167
|
+
useDocLayout as o,
|
4168
|
+
useGetContentTypeConfigurationQuery as p,
|
4169
|
+
CREATOR_FIELDS as q,
|
4170
|
+
getMainField as r,
|
3750
4171
|
setInitialData as s,
|
3751
4172
|
getDisplayName as t,
|
3752
4173
|
useContentTypeSchema as u,
|
@@ -3756,4 +4177,4 @@ export {
|
|
3756
4177
|
capitalise as y,
|
3757
4178
|
useUpdateContentTypeConfigurationMutation as z
|
3758
4179
|
};
|
3759
|
-
//# sourceMappingURL=index-
|
4180
|
+
//# sourceMappingURL=index-3_WeHXYp.mjs.map
|