@strapi/content-manager 0.0.0-experimental.826f263c58b6886b849d3f03b81f7a530bc51c91 → 0.0.0-experimental.8e52d29d243dccc7c24beb53412cf1c9c0b36d11
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-DJcn1DrO.js → ComponentConfigurationPage--MCP7Aew.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js.map → ComponentConfigurationPage--MCP7Aew.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs → ComponentConfigurationPage-DT41asyM.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs.map → ComponentConfigurationPage-DT41asyM.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs → EditConfigurationPage-DznPxn9p.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs.map → EditConfigurationPage-DznPxn9p.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js → EditConfigurationPage-qgnNvv_u.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js.map → EditConfigurationPage-qgnNvv_u.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-DvaV7U9b.mjs → EditViewPage-B_k7z288.mjs} +72 -50
- package/dist/_chunks/EditViewPage-B_k7z288.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-CoQEnFlC.js → EditViewPage-Bb4S7p8c.js} +70 -48
- package/dist/_chunks/EditViewPage-Bb4S7p8c.js.map +1 -0
- package/dist/_chunks/{Field-ZdrmmQ4Y.js → Field-ByR1mllE.js} +582 -230
- package/dist/_chunks/Field-ByR1mllE.js.map +1 -0
- package/dist/_chunks/{Field-Cz_J9551.mjs → Field-DmwbE0TL.mjs} +580 -228
- package/dist/_chunks/Field-DmwbE0TL.mjs.map +1 -0
- package/dist/_chunks/{Form-Bpig5rch.js → Form-BpeyAyS1.js} +52 -34
- package/dist/_chunks/Form-BpeyAyS1.js.map +1 -0
- package/dist/_chunks/{Form-Dxmihyw8.mjs → Form-Dvt5eouJ.mjs} +54 -36
- package/dist/_chunks/Form-Dvt5eouJ.mjs.map +1 -0
- package/dist/_chunks/{History-BZP8n7KT.mjs → History-CAERKpYl.mjs} +171 -77
- package/dist/_chunks/History-CAERKpYl.mjs.map +1 -0
- package/dist/_chunks/{History-BfX6XmZK.js → History-d-IgDGPl.js} +170 -76
- package/dist/_chunks/History-d-IgDGPl.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DxKuVkKz.mjs → ListConfigurationPage-CVVT45M8.mjs} +59 -49
- package/dist/_chunks/ListConfigurationPage-CVVT45M8.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-B3CXj8PY.js → ListConfigurationPage-DSX98CYb.js} +58 -47
- package/dist/_chunks/ListConfigurationPage-DSX98CYb.js.map +1 -0
- package/dist/_chunks/{ListViewPage-Bk9VO__I.js → ListViewPage-C9gPPp-V.js} +117 -105
- package/dist/_chunks/ListViewPage-C9gPPp-V.js.map +1 -0
- package/dist/_chunks/{ListViewPage-D5D3tVPq.mjs → ListViewPage-Q4g6kHDl.mjs} +115 -103
- package/dist/_chunks/ListViewPage-Q4g6kHDl.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs → NoContentTypePage-BY4YRGs0.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs.map → NoContentTypePage-BY4YRGs0.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js → NoContentTypePage-D09gppmy.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js.map → NoContentTypePage-D09gppmy.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js → NoPermissionsPage-32WgThJG.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js.map → NoPermissionsPage-32WgThJG.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs → NoPermissionsPage-CyM16RKL.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs.map → NoPermissionsPage-CyM16RKL.mjs.map} +1 -1
- package/dist/_chunks/Preview-C2WFq4S8.mjs +267 -0
- package/dist/_chunks/Preview-C2WFq4S8.mjs.map +1 -0
- package/dist/_chunks/Preview-PpV3g9wJ.js +286 -0
- package/dist/_chunks/Preview-PpV3g9wJ.js.map +1 -0
- package/dist/_chunks/{Relations-BOYZmuWy.mjs → Relations-B_Yn9xGB.mjs} +73 -37
- package/dist/_chunks/Relations-B_Yn9xGB.mjs.map +1 -0
- package/dist/_chunks/{Relations-B6B3A3mb.js → Relations-mWaebC5t.js} +72 -36
- package/dist/_chunks/Relations-mWaebC5t.js.map +1 -0
- package/dist/_chunks/{en-BN1bvFK7.js → en-CHOp_xJv.js} +30 -16
- package/dist/_chunks/{en-BN1bvFK7.js.map → en-CHOp_xJv.js.map} +1 -1
- package/dist/_chunks/{en-Dzv55oQw.mjs → en-D_BMf0hT.mjs} +30 -16
- package/dist/_chunks/{en-Dzv55oQw.mjs.map → en-D_BMf0hT.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-VHviNMeW.mjs → index-CbytGVdz.mjs} +1154 -887
- package/dist/_chunks/index-CbytGVdz.mjs.map +1 -0
- package/dist/_chunks/{index-DzN3kBgx.js → index-iun2i4xv.js} +1133 -865
- package/dist/_chunks/index-iun2i4xv.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-CPn1PM6x.mjs → layout-Btu_cMRF.mjs} +41 -23
- package/dist/_chunks/layout-Btu_cMRF.mjs.map +1 -0
- package/dist/_chunks/{layout-b91XRlD2.js → layout-CkaP4K5_.js} +39 -21
- package/dist/_chunks/layout-CkaP4K5_.js.map +1 -0
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-BsqxS6tR.mjs → relations-Cn5re8ia.mjs} +6 -7
- package/dist/_chunks/relations-Cn5re8ia.mjs.map +1 -0
- package/dist/_chunks/{relations-CA7IYmcP.js → relations-O_v9g0v_.js} +6 -7
- package/dist/_chunks/relations-O_v9g0v_.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 +8 -7
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
- package/dist/admin/src/history/index.d.ts +3 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
- 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 +6 -58
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
- package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- 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/pages/Preview.d.ts +11 -0
- package/dist/admin/src/preview/routes.d.ts +3 -0
- package/dist/admin/src/preview/services/preview.d.ts +3 -0
- package/dist/admin/src/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 -263
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +552 -264
- 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-CoQEnFlC.js.map +0 -1
- package/dist/_chunks/EditViewPage-DvaV7U9b.mjs.map +0 -1
- package/dist/_chunks/Field-Cz_J9551.mjs.map +0 -1
- package/dist/_chunks/Field-ZdrmmQ4Y.js.map +0 -1
- package/dist/_chunks/Form-Bpig5rch.js.map +0 -1
- package/dist/_chunks/Form-Dxmihyw8.mjs.map +0 -1
- package/dist/_chunks/History-BZP8n7KT.mjs.map +0 -1
- package/dist/_chunks/History-BfX6XmZK.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-B3CXj8PY.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DxKuVkKz.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-Bk9VO__I.js.map +0 -1
- package/dist/_chunks/ListViewPage-D5D3tVPq.mjs.map +0 -1
- package/dist/_chunks/Relations-B6B3A3mb.js.map +0 -1
- package/dist/_chunks/Relations-BOYZmuWy.mjs.map +0 -1
- package/dist/_chunks/index-DzN3kBgx.js.map +0 -1
- package/dist/_chunks/index-VHviNMeW.mjs.map +0 -1
- package/dist/_chunks/layout-CPn1PM6x.mjs.map +0 -1
- package/dist/_chunks/layout-b91XRlD2.js.map +0 -1
- package/dist/_chunks/relations-BsqxS6tR.mjs.map +0 -1
- package/dist/_chunks/relations-CA7IYmcP.js.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
@@ -1,17 +1,18 @@
|
|
1
|
-
import {
|
1
|
+
import { More, Cross, WarningCircle, ListPlus, Pencil, Trash, Check, CrossCircle, CheckCircle, ArrowsCounterClockwise, ChevronRight, Duplicate, ClockCounterClockwise, Feather } from "@strapi/icons";
|
2
2
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
3
|
-
import { useStrapiApp,
|
4
|
-
import { stringify } from "qs";
|
5
|
-
import { useIntl } from "react-intl";
|
6
|
-
import { useNavigate, useParams, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
|
3
|
+
import { useStrapiApp, createContext, useQueryParams, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors, useForm, useTracking, useGuidedTour, BackButton, DescriptionComponentRenderer, useTable, Table } from "@strapi/admin/strapi-admin";
|
7
4
|
import * as React from "react";
|
8
5
|
import { lazy } from "react";
|
9
|
-
import { Menu, VisuallyHidden, Flex, Typography, Dialog,
|
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) => {
|
@@ -927,12 +1325,13 @@ const useDocumentActions = () => {
|
|
927
1325
|
);
|
928
1326
|
const [discardDocument] = useDiscardDocumentMutation();
|
929
1327
|
const discard = React.useCallback(
|
930
|
-
async ({ collectionType, model, documentId }) => {
|
1328
|
+
async ({ collectionType, model, documentId, params }) => {
|
931
1329
|
try {
|
932
1330
|
const res = await discardDocument({
|
933
1331
|
collectionType,
|
934
1332
|
model,
|
935
|
-
documentId
|
1333
|
+
documentId,
|
1334
|
+
params
|
936
1335
|
});
|
937
1336
|
if ("error" in res) {
|
938
1337
|
toggleNotification({
|
@@ -1162,6 +1561,7 @@ const useDocumentActions = () => {
|
|
1162
1561
|
defaultMessage: "Saved document"
|
1163
1562
|
})
|
1164
1563
|
});
|
1564
|
+
setCurrentStep("contentManager.success");
|
1165
1565
|
return res.data;
|
1166
1566
|
} catch (err) {
|
1167
1567
|
toggleNotification({
|
@@ -1183,7 +1583,6 @@ const useDocumentActions = () => {
|
|
1183
1583
|
sourceId
|
1184
1584
|
});
|
1185
1585
|
if ("error" in res) {
|
1186
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1187
1586
|
return { error: res.error };
|
1188
1587
|
}
|
1189
1588
|
toggleNotification({
|
@@ -1202,7 +1601,7 @@ const useDocumentActions = () => {
|
|
1202
1601
|
throw err;
|
1203
1602
|
}
|
1204
1603
|
},
|
1205
|
-
[autoCloneDocument,
|
1604
|
+
[autoCloneDocument, formatMessage, toggleNotification]
|
1206
1605
|
);
|
1207
1606
|
const [cloneDocument] = useCloneDocumentMutation();
|
1208
1607
|
const clone = React.useCallback(
|
@@ -1228,6 +1627,7 @@ const useDocumentActions = () => {
|
|
1228
1627
|
defaultMessage: "Cloned document"
|
1229
1628
|
})
|
1230
1629
|
});
|
1630
|
+
navigate(`../../${res.data.data.documentId}`, { relative: "path" });
|
1231
1631
|
return res.data;
|
1232
1632
|
} catch (err) {
|
1233
1633
|
toggleNotification({
|
@@ -1238,7 +1638,7 @@ const useDocumentActions = () => {
|
|
1238
1638
|
throw err;
|
1239
1639
|
}
|
1240
1640
|
},
|
1241
|
-
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
|
1641
|
+
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
|
1242
1642
|
);
|
1243
1643
|
const [getDoc] = useLazyGetDocumentQuery();
|
1244
1644
|
const getDocument = React.useCallback(
|
@@ -1263,10 +1663,10 @@ const useDocumentActions = () => {
|
|
1263
1663
|
update
|
1264
1664
|
};
|
1265
1665
|
};
|
1266
|
-
const ProtectedHistoryPage = lazy(
|
1267
|
-
() => import("./History-
|
1666
|
+
const ProtectedHistoryPage = React.lazy(
|
1667
|
+
() => import("./History-CAERKpYl.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1268
1668
|
);
|
1269
|
-
const routes$
|
1669
|
+
const routes$2 = [
|
1270
1670
|
{
|
1271
1671
|
path: ":collectionType/:slug/:id/history",
|
1272
1672
|
Component: ProtectedHistoryPage
|
@@ -1276,32 +1676,45 @@ const routes$1 = [
|
|
1276
1676
|
Component: ProtectedHistoryPage
|
1277
1677
|
}
|
1278
1678
|
];
|
1679
|
+
const ProtectedPreviewPage = React.lazy(
|
1680
|
+
() => import("./Preview-C2WFq4S8.mjs").then((mod) => ({ default: mod.ProtectedPreviewPage }))
|
1681
|
+
);
|
1682
|
+
const routes$1 = [
|
1683
|
+
{
|
1684
|
+
path: ":collectionType/:slug/:id/preview",
|
1685
|
+
Component: ProtectedPreviewPage
|
1686
|
+
},
|
1687
|
+
{
|
1688
|
+
path: ":collectionType/:slug/preview",
|
1689
|
+
Component: ProtectedPreviewPage
|
1690
|
+
}
|
1691
|
+
];
|
1279
1692
|
const ProtectedEditViewPage = lazy(
|
1280
|
-
() => import("./EditViewPage-
|
1693
|
+
() => import("./EditViewPage-B_k7z288.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1281
1694
|
);
|
1282
1695
|
const ProtectedListViewPage = lazy(
|
1283
|
-
() => import("./ListViewPage-
|
1696
|
+
() => import("./ListViewPage-Q4g6kHDl.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1284
1697
|
);
|
1285
1698
|
const ProtectedListConfiguration = lazy(
|
1286
|
-
() => import("./ListConfigurationPage-
|
1699
|
+
() => import("./ListConfigurationPage-CVVT45M8.mjs").then((mod) => ({
|
1287
1700
|
default: mod.ProtectedListConfiguration
|
1288
1701
|
}))
|
1289
1702
|
);
|
1290
1703
|
const ProtectedEditConfigurationPage = lazy(
|
1291
|
-
() => import("./EditConfigurationPage-
|
1704
|
+
() => import("./EditConfigurationPage-DznPxn9p.mjs").then((mod) => ({
|
1292
1705
|
default: mod.ProtectedEditConfigurationPage
|
1293
1706
|
}))
|
1294
1707
|
);
|
1295
1708
|
const ProtectedComponentConfigurationPage = lazy(
|
1296
|
-
() => import("./ComponentConfigurationPage-
|
1709
|
+
() => import("./ComponentConfigurationPage-DT41asyM.mjs").then((mod) => ({
|
1297
1710
|
default: mod.ProtectedComponentConfigurationPage
|
1298
1711
|
}))
|
1299
1712
|
);
|
1300
1713
|
const NoPermissions = lazy(
|
1301
|
-
() => import("./NoPermissionsPage-
|
1714
|
+
() => import("./NoPermissionsPage-CyM16RKL.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1302
1715
|
);
|
1303
1716
|
const NoContentType = lazy(
|
1304
|
-
() => import("./NoContentTypePage-
|
1717
|
+
() => import("./NoContentTypePage-BY4YRGs0.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1305
1718
|
);
|
1306
1719
|
const CollectionTypePages = () => {
|
1307
1720
|
const { collectionType } = useParams();
|
@@ -1347,6 +1760,7 @@ const routes = [
|
|
1347
1760
|
path: "no-content-types",
|
1348
1761
|
Component: NoContentType
|
1349
1762
|
},
|
1763
|
+
...routes$2,
|
1350
1764
|
...routes$1
|
1351
1765
|
];
|
1352
1766
|
const DocumentActions = ({ actions: actions2 }) => {
|
@@ -1415,12 +1829,14 @@ const DocumentActionButton = (action) => {
|
|
1415
1829
|
/* @__PURE__ */ jsx(
|
1416
1830
|
Button,
|
1417
1831
|
{
|
1418
|
-
flex:
|
1832
|
+
flex: "auto",
|
1419
1833
|
startIcon: action.icon,
|
1420
1834
|
disabled: action.disabled,
|
1421
1835
|
onClick: handleClick(action),
|
1422
1836
|
justifyContent: "center",
|
1423
1837
|
variant: action.variant || "default",
|
1838
|
+
paddingTop: "7px",
|
1839
|
+
paddingBottom: "7px",
|
1424
1840
|
children: action.label
|
1425
1841
|
}
|
1426
1842
|
),
|
@@ -1428,7 +1844,7 @@ const DocumentActionButton = (action) => {
|
|
1428
1844
|
DocumentActionConfirmDialog,
|
1429
1845
|
{
|
1430
1846
|
...action.dialog,
|
1431
|
-
variant: action.variant,
|
1847
|
+
variant: action.dialog?.variant ?? action.variant,
|
1432
1848
|
isOpen: dialogId === action.id,
|
1433
1849
|
onClose: handleClose
|
1434
1850
|
}
|
@@ -1485,9 +1901,9 @@ const DocumentActionsMenu = ({
|
|
1485
1901
|
disabled: isDisabled,
|
1486
1902
|
size: "S",
|
1487
1903
|
endIcon: null,
|
1488
|
-
paddingTop: "
|
1489
|
-
paddingLeft: "
|
1490
|
-
paddingRight: "
|
1904
|
+
paddingTop: "4px",
|
1905
|
+
paddingLeft: "7px",
|
1906
|
+
paddingRight: "7px",
|
1491
1907
|
variant,
|
1492
1908
|
children: [
|
1493
1909
|
/* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
|
@@ -1498,7 +1914,7 @@ const DocumentActionsMenu = ({
|
|
1498
1914
|
]
|
1499
1915
|
}
|
1500
1916
|
),
|
1501
|
-
/* @__PURE__ */ jsxs(Menu.Content, {
|
1917
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1502
1918
|
actions2.map((action) => {
|
1503
1919
|
return /* @__PURE__ */ jsx(
|
1504
1920
|
Menu.Item,
|
@@ -1507,10 +1923,25 @@ const DocumentActionsMenu = ({
|
|
1507
1923
|
onSelect: handleClick(action),
|
1508
1924
|
display: "block",
|
1509
1925
|
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
|
1510
|
-
/* @__PURE__ */ jsxs(
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1926
|
+
/* @__PURE__ */ jsxs(
|
1927
|
+
Flex,
|
1928
|
+
{
|
1929
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1930
|
+
gap: 2,
|
1931
|
+
tag: "span",
|
1932
|
+
children: [
|
1933
|
+
/* @__PURE__ */ jsx(
|
1934
|
+
Flex,
|
1935
|
+
{
|
1936
|
+
tag: "span",
|
1937
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1938
|
+
children: action.icon
|
1939
|
+
}
|
1940
|
+
),
|
1941
|
+
action.label
|
1942
|
+
]
|
1943
|
+
}
|
1944
|
+
),
|
1514
1945
|
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
|
1515
1946
|
Flex,
|
1516
1947
|
{
|
@@ -1569,7 +2000,19 @@ const convertActionVariantToColor = (variant = "secondary") => {
|
|
1569
2000
|
return "primary600";
|
1570
2001
|
}
|
1571
2002
|
};
|
1572
|
-
const
|
2003
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
2004
|
+
switch (variant) {
|
2005
|
+
case "danger":
|
2006
|
+
return "danger600";
|
2007
|
+
case "secondary":
|
2008
|
+
return "neutral500";
|
2009
|
+
case "success":
|
2010
|
+
return "success600";
|
2011
|
+
default:
|
2012
|
+
return "primary600";
|
2013
|
+
}
|
2014
|
+
};
|
2015
|
+
const DocumentActionConfirmDialog = ({
|
1573
2016
|
onClose,
|
1574
2017
|
onCancel,
|
1575
2018
|
onConfirm,
|
@@ -1591,22 +2034,20 @@ const DocumentActionConfirmDialog = ({
|
|
1591
2034
|
}
|
1592
2035
|
onClose();
|
1593
2036
|
};
|
1594
|
-
return /* @__PURE__ */
|
1595
|
-
/* @__PURE__ */ jsx(
|
1596
|
-
/* @__PURE__ */ jsx(
|
1597
|
-
|
1598
|
-
{
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
)
|
1609
|
-
] });
|
2037
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2038
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2039
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: content }),
|
2040
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
2041
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
2042
|
+
id: "app.components.Button.cancel",
|
2043
|
+
defaultMessage: "Cancel"
|
2044
|
+
}) }) }),
|
2045
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
2046
|
+
id: "app.components.Button.confirm",
|
2047
|
+
defaultMessage: "Confirm"
|
2048
|
+
}) })
|
2049
|
+
] })
|
2050
|
+
] }) });
|
1610
2051
|
};
|
1611
2052
|
const DocumentActionModal = ({
|
1612
2053
|
isOpen,
|
@@ -1616,34 +2057,29 @@ const DocumentActionModal = ({
|
|
1616
2057
|
content: Content,
|
1617
2058
|
onModalClose
|
1618
2059
|
}) => {
|
1619
|
-
const id = React.useId();
|
1620
|
-
if (!isOpen) {
|
1621
|
-
return null;
|
1622
|
-
}
|
1623
2060
|
const handleClose = () => {
|
1624
2061
|
if (onClose) {
|
1625
2062
|
onClose();
|
1626
2063
|
}
|
1627
2064
|
onModalClose();
|
1628
2065
|
};
|
1629
|
-
return /* @__PURE__ */
|
1630
|
-
/* @__PURE__ */ jsx(
|
1631
|
-
|
1632
|
-
/* @__PURE__ */ jsx(
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
] });
|
2066
|
+
return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
2067
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
|
2068
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
|
2069
|
+
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
2070
|
+
] }) });
|
2071
|
+
};
|
2072
|
+
const transformData = (data) => {
|
2073
|
+
if (Array.isArray(data)) {
|
2074
|
+
return data.map(transformData);
|
2075
|
+
}
|
2076
|
+
if (typeof data === "object" && data !== null) {
|
2077
|
+
if ("apiData" in data) {
|
2078
|
+
return data.apiData;
|
2079
|
+
}
|
2080
|
+
return mapValues(transformData)(data);
|
2081
|
+
}
|
2082
|
+
return data;
|
1647
2083
|
};
|
1648
2084
|
const PublishAction$1 = ({
|
1649
2085
|
activeTab,
|
@@ -1657,13 +2093,17 @@ const PublishAction$1 = ({
|
|
1657
2093
|
const navigate = useNavigate();
|
1658
2094
|
const { toggleNotification } = useNotification();
|
1659
2095
|
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
2096
|
+
const isListView = useMatch(LIST_PATH) !== null;
|
1660
2097
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
1661
2098
|
const { formatMessage } = useIntl();
|
1662
|
-
const { canPublish
|
1663
|
-
"PublishAction",
|
1664
|
-
({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
|
1665
|
-
);
|
2099
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1666
2100
|
const { publish } = useDocumentActions();
|
2101
|
+
const [
|
2102
|
+
countDraftRelations,
|
2103
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2104
|
+
] = useLazyGetDraftRelationCountQuery();
|
2105
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
|
2106
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
|
1667
2107
|
const [{ query, rawQuery }] = useQueryParams();
|
1668
2108
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1669
2109
|
const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
@@ -1672,10 +2112,105 @@ const PublishAction$1 = ({
|
|
1672
2112
|
const validate = useForm("PublishAction", (state) => state.validate);
|
1673
2113
|
const setErrors = useForm("PublishAction", (state) => state.setErrors);
|
1674
2114
|
const formValues = useForm("PublishAction", ({ values }) => values);
|
2115
|
+
React.useEffect(() => {
|
2116
|
+
if (isErrorDraftRelations) {
|
2117
|
+
toggleNotification({
|
2118
|
+
type: "danger",
|
2119
|
+
message: formatMessage({
|
2120
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2121
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2122
|
+
})
|
2123
|
+
});
|
2124
|
+
}
|
2125
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2126
|
+
React.useEffect(() => {
|
2127
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2128
|
+
const extractDraftRelations = (data) => {
|
2129
|
+
const relations = data.connect || [];
|
2130
|
+
relations.forEach((relation) => {
|
2131
|
+
if (relation.status === "draft") {
|
2132
|
+
localDraftRelations.add(relation.id);
|
2133
|
+
}
|
2134
|
+
});
|
2135
|
+
};
|
2136
|
+
const traverseAndExtract = (data) => {
|
2137
|
+
Object.entries(data).forEach(([key, value]) => {
|
2138
|
+
if (key === "connect" && Array.isArray(value)) {
|
2139
|
+
extractDraftRelations({ connect: value });
|
2140
|
+
} else if (typeof value === "object" && value !== null) {
|
2141
|
+
traverseAndExtract(value);
|
2142
|
+
}
|
2143
|
+
});
|
2144
|
+
};
|
2145
|
+
if (!documentId || modified) {
|
2146
|
+
traverseAndExtract(formValues);
|
2147
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2148
|
+
}
|
2149
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2150
|
+
React.useEffect(() => {
|
2151
|
+
if (!document || !document.documentId || isListView) {
|
2152
|
+
return;
|
2153
|
+
}
|
2154
|
+
const fetchDraftRelationsCount = async () => {
|
2155
|
+
const { data, error } = await countDraftRelations({
|
2156
|
+
collectionType,
|
2157
|
+
model,
|
2158
|
+
documentId,
|
2159
|
+
params
|
2160
|
+
});
|
2161
|
+
if (error) {
|
2162
|
+
throw error;
|
2163
|
+
}
|
2164
|
+
if (data) {
|
2165
|
+
setServerCountOfDraftRelations(data.data);
|
2166
|
+
}
|
2167
|
+
};
|
2168
|
+
fetchDraftRelationsCount();
|
2169
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
1675
2170
|
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1676
2171
|
if (!schema?.options?.draftAndPublish) {
|
1677
2172
|
return null;
|
1678
2173
|
}
|
2174
|
+
const performPublish = async () => {
|
2175
|
+
setSubmitting(true);
|
2176
|
+
try {
|
2177
|
+
const { errors } = await validate(true, {
|
2178
|
+
status: "published"
|
2179
|
+
});
|
2180
|
+
if (errors) {
|
2181
|
+
toggleNotification({
|
2182
|
+
type: "danger",
|
2183
|
+
message: formatMessage({
|
2184
|
+
id: "content-manager.validation.error",
|
2185
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2186
|
+
})
|
2187
|
+
});
|
2188
|
+
return;
|
2189
|
+
}
|
2190
|
+
const res = await publish(
|
2191
|
+
{
|
2192
|
+
collectionType,
|
2193
|
+
model,
|
2194
|
+
documentId,
|
2195
|
+
params
|
2196
|
+
},
|
2197
|
+
transformData(formValues)
|
2198
|
+
);
|
2199
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2200
|
+
navigate({
|
2201
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2202
|
+
search: rawQuery
|
2203
|
+
});
|
2204
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2205
|
+
setErrors(formatValidationErrors(res.error));
|
2206
|
+
}
|
2207
|
+
} finally {
|
2208
|
+
setSubmitting(false);
|
2209
|
+
}
|
2210
|
+
};
|
2211
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2212
|
+
const enableDraftRelationsCount = false;
|
2213
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
1679
2214
|
return {
|
1680
2215
|
/**
|
1681
2216
|
* Disabled when:
|
@@ -1685,49 +2220,36 @@ const PublishAction$1 = ({
|
|
1685
2220
|
* - the document is already published & not modified
|
1686
2221
|
* - the document is being created & not modified
|
1687
2222
|
* - the user doesn't have the permission to publish
|
1688
|
-
* - the user doesn't have the permission to create a new document
|
1689
|
-
* - the user doesn't have the permission to update the document
|
1690
2223
|
*/
|
1691
|
-
disabled: isCloning || isSubmitting || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish
|
2224
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1692
2225
|
label: formatMessage({
|
1693
2226
|
id: "app.utils.publish",
|
1694
2227
|
defaultMessage: "Publish"
|
1695
2228
|
}),
|
1696
2229
|
onClick: async () => {
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
documentId,
|
1715
|
-
params
|
1716
|
-
},
|
1717
|
-
formValues
|
1718
|
-
);
|
1719
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1720
|
-
navigate({
|
1721
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1722
|
-
search: rawQuery
|
1723
|
-
});
|
1724
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1725
|
-
setErrors(formatValidationErrors(res.error));
|
2230
|
+
await performPublish();
|
2231
|
+
},
|
2232
|
+
dialog: hasDraftRelations ? {
|
2233
|
+
type: "dialog",
|
2234
|
+
variant: "danger",
|
2235
|
+
footer: null,
|
2236
|
+
title: formatMessage({
|
2237
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2238
|
+
defaultMessage: "Confirmation"
|
2239
|
+
}),
|
2240
|
+
content: formatMessage(
|
2241
|
+
{
|
2242
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2243
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2244
|
+
},
|
2245
|
+
{
|
2246
|
+
count: totalDraftRelations
|
1726
2247
|
}
|
1727
|
-
|
1728
|
-
|
2248
|
+
),
|
2249
|
+
onConfirm: async () => {
|
2250
|
+
await performPublish();
|
1729
2251
|
}
|
1730
|
-
}
|
2252
|
+
} : void 0
|
1731
2253
|
};
|
1732
2254
|
};
|
1733
2255
|
PublishAction$1.type = "publish";
|
@@ -1743,10 +2265,6 @@ const UpdateAction = ({
|
|
1743
2265
|
const cloneMatch = useMatch(CLONE_PATH);
|
1744
2266
|
const isCloning = cloneMatch !== null;
|
1745
2267
|
const { formatMessage } = useIntl();
|
1746
|
-
const { canCreate, canUpdate } = useDocumentRBAC("UpdateAction", ({ canCreate: canCreate2, canUpdate: canUpdate2 }) => ({
|
1747
|
-
canCreate: canCreate2,
|
1748
|
-
canUpdate: canUpdate2
|
1749
|
-
}));
|
1750
2268
|
const { create, update, clone } = useDocumentActions();
|
1751
2269
|
const [{ query, rawQuery }] = useQueryParams();
|
1752
2270
|
const params = React.useMemo(() => buildValidParams(query), [query]);
|
@@ -1763,10 +2281,8 @@ const UpdateAction = ({
|
|
1763
2281
|
* - the form is submitting
|
1764
2282
|
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
1765
2283
|
* - the active tab is the published tab
|
1766
|
-
* - the user doesn't have the permission to create a new document
|
1767
|
-
* - the user doesn't have the permission to update the document
|
1768
2284
|
*/
|
1769
|
-
disabled: isSubmitting || !modified && !isCloning || activeTab === "published"
|
2285
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
1770
2286
|
label: formatMessage({
|
1771
2287
|
id: "content-manager.containers.Edit.save",
|
1772
2288
|
defaultMessage: "Save"
|
@@ -1774,7 +2290,9 @@ const UpdateAction = ({
|
|
1774
2290
|
onClick: async () => {
|
1775
2291
|
setSubmitting(true);
|
1776
2292
|
try {
|
1777
|
-
const { errors } = await validate(
|
2293
|
+
const { errors } = await validate(true, {
|
2294
|
+
status: "draft"
|
2295
|
+
});
|
1778
2296
|
if (errors) {
|
1779
2297
|
toggleNotification({
|
1780
2298
|
type: "danger",
|
@@ -1792,13 +2310,16 @@ const UpdateAction = ({
|
|
1792
2310
|
documentId: cloneMatch.params.origin,
|
1793
2311
|
params
|
1794
2312
|
},
|
1795
|
-
document
|
2313
|
+
transformData(document)
|
1796
2314
|
);
|
1797
2315
|
if ("data" in res) {
|
1798
|
-
navigate(
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
2316
|
+
navigate(
|
2317
|
+
{
|
2318
|
+
pathname: `../${res.data.documentId}`,
|
2319
|
+
search: rawQuery
|
2320
|
+
},
|
2321
|
+
{ relative: "path" }
|
2322
|
+
);
|
1802
2323
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1803
2324
|
setErrors(formatValidationErrors(res.error));
|
1804
2325
|
}
|
@@ -1810,7 +2331,7 @@ const UpdateAction = ({
|
|
1810
2331
|
documentId,
|
1811
2332
|
params
|
1812
2333
|
},
|
1813
|
-
document
|
2334
|
+
transformData(document)
|
1814
2335
|
);
|
1815
2336
|
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1816
2337
|
setErrors(formatValidationErrors(res.error));
|
@@ -1823,13 +2344,16 @@ const UpdateAction = ({
|
|
1823
2344
|
model,
|
1824
2345
|
params
|
1825
2346
|
},
|
1826
|
-
document
|
2347
|
+
transformData(document)
|
1827
2348
|
);
|
1828
2349
|
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1829
|
-
navigate(
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
2350
|
+
navigate(
|
2351
|
+
{
|
2352
|
+
pathname: `../${res.data.documentId}`,
|
2353
|
+
search: rawQuery
|
2354
|
+
},
|
2355
|
+
{ replace: true, relative: "path" }
|
2356
|
+
);
|
1833
2357
|
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1834
2358
|
setErrors(formatValidationErrors(res.error));
|
1835
2359
|
}
|
@@ -1861,10 +2385,8 @@ const UnpublishAction$1 = ({
|
|
1861
2385
|
const { toggleNotification } = useNotification();
|
1862
2386
|
const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
|
1863
2387
|
const isDocumentModified = document?.status === "modified";
|
1864
|
-
const handleChange = (
|
1865
|
-
|
1866
|
-
setShouldKeepDraft(e.target.value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1867
|
-
}
|
2388
|
+
const handleChange = (value) => {
|
2389
|
+
setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
1868
2390
|
};
|
1869
2391
|
if (!schema?.options?.draftAndPublish) {
|
1870
2392
|
return null;
|
@@ -1875,7 +2397,7 @@ const UnpublishAction$1 = ({
|
|
1875
2397
|
id: "app.utils.unpublish",
|
1876
2398
|
defaultMessage: "Unpublish"
|
1877
2399
|
}),
|
1878
|
-
icon: /* @__PURE__ */ jsx(
|
2400
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
1879
2401
|
onClick: async () => {
|
1880
2402
|
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
1881
2403
|
if (!documentId) {
|
@@ -1914,40 +2436,24 @@ const UnpublishAction$1 = ({
|
|
1914
2436
|
}) })
|
1915
2437
|
] }),
|
1916
2438
|
/* @__PURE__ */ jsxs(
|
1917
|
-
|
2439
|
+
Radio.Group,
|
1918
2440
|
{
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
2441
|
+
defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
|
2442
|
+
name: "discard-options",
|
2443
|
+
"aria-label": formatMessage({
|
2444
|
+
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2445
|
+
defaultMessage: "Choose an option to unpublish the document."
|
2446
|
+
}),
|
2447
|
+
onValueChange: handleChange,
|
1925
2448
|
children: [
|
1926
|
-
/* @__PURE__ */ jsx(
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
1935
|
-
defaultMessage: "Keep draft"
|
1936
|
-
})
|
1937
|
-
}
|
1938
|
-
),
|
1939
|
-
/* @__PURE__ */ jsx(
|
1940
|
-
Radio,
|
1941
|
-
{
|
1942
|
-
checked: !shouldKeepDraft,
|
1943
|
-
value: UNPUBLISH_DRAFT_OPTIONS.DISCARD,
|
1944
|
-
name: "discard-options",
|
1945
|
-
children: formatMessage({
|
1946
|
-
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
1947
|
-
defaultMessage: "Replace draft"
|
1948
|
-
})
|
1949
|
-
}
|
1950
|
-
)
|
2449
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2450
|
+
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2451
|
+
defaultMessage: "Keep draft"
|
2452
|
+
}) }),
|
2453
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2454
|
+
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2455
|
+
defaultMessage: "Replace draft"
|
2456
|
+
}) })
|
1951
2457
|
]
|
1952
2458
|
}
|
1953
2459
|
)
|
@@ -2003,7 +2509,7 @@ const DiscardAction = ({
|
|
2003
2509
|
id: "content-manager.actions.discard.label",
|
2004
2510
|
defaultMessage: "Discard changes"
|
2005
2511
|
}),
|
2006
|
-
icon: /* @__PURE__ */ jsx(
|
2512
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
2007
2513
|
position: ["panel", "table-row"],
|
2008
2514
|
variant: "danger",
|
2009
2515
|
dialog: {
|
@@ -2031,11 +2537,6 @@ const DiscardAction = ({
|
|
2031
2537
|
};
|
2032
2538
|
};
|
2033
2539
|
DiscardAction.type = "discard";
|
2034
|
-
const StyledCrossCircle = styled(CrossCircle)`
|
2035
|
-
path {
|
2036
|
-
fill: currentColor;
|
2037
|
-
}
|
2038
|
-
`;
|
2039
2540
|
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2040
2541
|
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2041
2542
|
const RelativeTime = React.forwardRef(
|
@@ -2083,8 +2584,12 @@ const getDisplayName = ({
|
|
2083
2584
|
};
|
2084
2585
|
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2085
2586
|
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2086
|
-
const statusVariant = status === "draft" ? "
|
2087
|
-
|
2587
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2588
|
+
const { formatMessage } = useIntl();
|
2589
|
+
return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: formatMessage({
|
2590
|
+
id: `content-manager.containers.List.${status}`,
|
2591
|
+
defaultMessage: capitalise(status)
|
2592
|
+
}) }) });
|
2088
2593
|
};
|
2089
2594
|
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
2090
2595
|
const { formatMessage } = useIntl();
|
@@ -2093,23 +2598,13 @@ const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
|
2093
2598
|
id: "content-manager.containers.edit.title.new",
|
2094
2599
|
defaultMessage: "Create an entry"
|
2095
2600
|
}) : documentTitle;
|
2096
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop:
|
2601
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2097
2602
|
/* @__PURE__ */ jsx(BackButton, {}),
|
2098
|
-
/* @__PURE__ */ jsxs(
|
2099
|
-
|
2100
|
-
{
|
2101
|
-
|
2102
|
-
|
2103
|
-
paddingTop: 1,
|
2104
|
-
gap: "80px",
|
2105
|
-
alignItems: "flex-start",
|
2106
|
-
children: [
|
2107
|
-
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2108
|
-
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2109
|
-
]
|
2110
|
-
}
|
2111
|
-
),
|
2112
|
-
status ? /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) : null
|
2603
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2604
|
+
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2605
|
+
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2606
|
+
] }),
|
2607
|
+
status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2113
2608
|
] });
|
2114
2609
|
};
|
2115
2610
|
const HeaderToolbar = () => {
|
@@ -2192,12 +2687,12 @@ const Information = ({ activeTab }) => {
|
|
2192
2687
|
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2193
2688
|
label: formatMessage({
|
2194
2689
|
id: "content-manager.containers.edit.information.last-published.label",
|
2195
|
-
defaultMessage: "
|
2690
|
+
defaultMessage: "Published"
|
2196
2691
|
}),
|
2197
2692
|
value: formatMessage(
|
2198
2693
|
{
|
2199
2694
|
id: "content-manager.containers.edit.information.last-published.value",
|
2200
|
-
defaultMessage: `
|
2695
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2201
2696
|
},
|
2202
2697
|
{
|
2203
2698
|
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
@@ -2210,12 +2705,12 @@ const Information = ({ activeTab }) => {
|
|
2210
2705
|
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2211
2706
|
label: formatMessage({
|
2212
2707
|
id: "content-manager.containers.edit.information.last-draft.label",
|
2213
|
-
defaultMessage: "
|
2708
|
+
defaultMessage: "Updated"
|
2214
2709
|
}),
|
2215
2710
|
value: formatMessage(
|
2216
2711
|
{
|
2217
2712
|
id: "content-manager.containers.edit.information.last-draft.value",
|
2218
|
-
defaultMessage: `
|
2713
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2219
2714
|
},
|
2220
2715
|
{
|
2221
2716
|
time: /* @__PURE__ */ jsx(
|
@@ -2233,12 +2728,12 @@ const Information = ({ activeTab }) => {
|
|
2233
2728
|
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2234
2729
|
label: formatMessage({
|
2235
2730
|
id: "content-manager.containers.edit.information.document.label",
|
2236
|
-
defaultMessage: "
|
2731
|
+
defaultMessage: "Created"
|
2237
2732
|
}),
|
2238
2733
|
value: formatMessage(
|
2239
2734
|
{
|
2240
2735
|
id: "content-manager.containers.edit.information.document.value",
|
2241
|
-
defaultMessage: `
|
2736
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2242
2737
|
},
|
2243
2738
|
{
|
2244
2739
|
time: /* @__PURE__ */ jsx(
|
@@ -2276,25 +2771,77 @@ const Information = ({ activeTab }) => {
|
|
2276
2771
|
);
|
2277
2772
|
};
|
2278
2773
|
const HeaderActions = ({ actions: actions2 }) => {
|
2279
|
-
|
2280
|
-
|
2774
|
+
const [dialogId, setDialogId] = React.useState(null);
|
2775
|
+
const handleClick = (action) => async (e) => {
|
2776
|
+
if (!("options" in action)) {
|
2777
|
+
const { onClick = () => false, dialog, id } = action;
|
2778
|
+
const muteDialog = await onClick(e);
|
2779
|
+
if (dialog && !muteDialog) {
|
2780
|
+
e.preventDefault();
|
2781
|
+
setDialogId(id);
|
2782
|
+
}
|
2783
|
+
}
|
2784
|
+
};
|
2785
|
+
const handleClose = () => {
|
2786
|
+
setDialogId(null);
|
2787
|
+
};
|
2788
|
+
return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
|
2789
|
+
if (action.options) {
|
2281
2790
|
return /* @__PURE__ */ jsx(
|
2282
2791
|
SingleSelect,
|
2283
2792
|
{
|
2284
2793
|
size: "S",
|
2285
|
-
disabled: action.disabled,
|
2286
|
-
"aria-label": action.label,
|
2287
2794
|
onChange: action.onSelect,
|
2288
|
-
|
2795
|
+
"aria-label": action.label,
|
2796
|
+
...action,
|
2289
2797
|
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2290
2798
|
},
|
2291
2799
|
action.id
|
2292
2800
|
);
|
2293
2801
|
} else {
|
2294
|
-
|
2802
|
+
if (action.type === "icon") {
|
2803
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
2804
|
+
/* @__PURE__ */ jsx(
|
2805
|
+
IconButton,
|
2806
|
+
{
|
2807
|
+
disabled: action.disabled,
|
2808
|
+
label: action.label,
|
2809
|
+
size: "S",
|
2810
|
+
onClick: handleClick(action),
|
2811
|
+
children: action.icon
|
2812
|
+
}
|
2813
|
+
),
|
2814
|
+
action.dialog ? /* @__PURE__ */ jsx(
|
2815
|
+
HeaderActionDialog,
|
2816
|
+
{
|
2817
|
+
...action.dialog,
|
2818
|
+
isOpen: dialogId === action.id,
|
2819
|
+
onClose: handleClose
|
2820
|
+
}
|
2821
|
+
) : null
|
2822
|
+
] }, action.id);
|
2823
|
+
}
|
2295
2824
|
}
|
2296
2825
|
}) });
|
2297
2826
|
};
|
2827
|
+
const HeaderActionDialog = ({
|
2828
|
+
onClose,
|
2829
|
+
onCancel,
|
2830
|
+
title,
|
2831
|
+
content: Content,
|
2832
|
+
isOpen
|
2833
|
+
}) => {
|
2834
|
+
const handleClose = async () => {
|
2835
|
+
if (onCancel) {
|
2836
|
+
await onCancel();
|
2837
|
+
}
|
2838
|
+
onClose();
|
2839
|
+
};
|
2840
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2841
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2842
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
|
2843
|
+
] }) });
|
2844
|
+
};
|
2298
2845
|
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
2299
2846
|
const navigate = useNavigate();
|
2300
2847
|
const { formatMessage } = useIntl();
|
@@ -2335,12 +2882,16 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2335
2882
|
const { delete: deleteAction } = useDocumentActions();
|
2336
2883
|
const { toggleNotification } = useNotification();
|
2337
2884
|
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2885
|
+
const isLocalized = document?.locale != null;
|
2338
2886
|
return {
|
2339
2887
|
disabled: !canDelete || !document,
|
2340
|
-
label: formatMessage(
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2888
|
+
label: formatMessage(
|
2889
|
+
{
|
2890
|
+
id: "content-manager.actions.delete.label",
|
2891
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2892
|
+
},
|
2893
|
+
{ isLocalized }
|
2894
|
+
),
|
2344
2895
|
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2345
2896
|
dialog: {
|
2346
2897
|
type: "dialog",
|
@@ -2430,7 +2981,7 @@ const ActionsPanel = () => {
|
|
2430
2981
|
return {
|
2431
2982
|
title: formatMessage({
|
2432
2983
|
id: "content-manager.containers.edit.panels.default.title",
|
2433
|
-
defaultMessage: "
|
2984
|
+
defaultMessage: "Entry"
|
2434
2985
|
}),
|
2435
2986
|
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2436
2987
|
};
|
@@ -2449,350 +3000,48 @@ const ActionsPanelContent = () => {
|
|
2449
3000
|
activeTab: status,
|
2450
3001
|
model,
|
2451
3002
|
documentId: id,
|
2452
|
-
document: isCloning ? void 0 : document,
|
2453
|
-
meta: isCloning ? void 0 : meta,
|
2454
|
-
collectionType
|
2455
|
-
};
|
2456
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2457
|
-
/* @__PURE__ */ jsx(
|
2458
|
-
DescriptionComponentRenderer,
|
2459
|
-
{
|
2460
|
-
props,
|
2461
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2462
|
-
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2463
|
-
}
|
2464
|
-
),
|
2465
|
-
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
2466
|
-
] });
|
2467
|
-
};
|
2468
|
-
const Panel = React.forwardRef(({ children, title }, ref) => {
|
2469
|
-
return /* @__PURE__ */ jsxs(
|
2470
|
-
Flex,
|
2471
|
-
{
|
2472
|
-
ref,
|
2473
|
-
tag: "aside",
|
2474
|
-
"aria-labelledby": "additional-information",
|
2475
|
-
background: "neutral0",
|
2476
|
-
borderColor: "neutral150",
|
2477
|
-
hasRadius: true,
|
2478
|
-
paddingBottom: 4,
|
2479
|
-
paddingLeft: 4,
|
2480
|
-
paddingRight: 4,
|
2481
|
-
paddingTop: 4,
|
2482
|
-
shadow: "tableShadow",
|
2483
|
-
gap: 3,
|
2484
|
-
direction: "column",
|
2485
|
-
justifyContent: "stretch",
|
2486
|
-
alignItems: "flex-start",
|
2487
|
-
children: [
|
2488
|
-
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2489
|
-
children
|
2490
|
-
]
|
2491
|
-
}
|
2492
|
-
);
|
2493
|
-
});
|
2494
|
-
const HOOKS = {
|
2495
|
-
/**
|
2496
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2497
|
-
* @constant
|
2498
|
-
* @type {string}
|
2499
|
-
*/
|
2500
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2501
|
-
/**
|
2502
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2503
|
-
* @constant
|
2504
|
-
* @type {string}
|
2505
|
-
*/
|
2506
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2507
|
-
/**
|
2508
|
-
* Hook that allows to mutate the CM's edit view layout
|
2509
|
-
* @constant
|
2510
|
-
* @type {string}
|
2511
|
-
*/
|
2512
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2513
|
-
/**
|
2514
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2515
|
-
* @constant
|
2516
|
-
* @type {string}
|
2517
|
-
*/
|
2518
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2519
|
-
};
|
2520
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2521
|
-
endpoints: (builder) => ({
|
2522
|
-
getContentTypeConfiguration: builder.query({
|
2523
|
-
query: (uid) => ({
|
2524
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2525
|
-
method: "GET"
|
2526
|
-
}),
|
2527
|
-
transformResponse: (response) => response.data,
|
2528
|
-
providesTags: (_result, _error, uid) => [
|
2529
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2530
|
-
{ type: "ContentTypeSettings", id: "LIST" }
|
2531
|
-
]
|
2532
|
-
}),
|
2533
|
-
getAllContentTypeSettings: builder.query({
|
2534
|
-
query: () => "/content-manager/content-types-settings",
|
2535
|
-
transformResponse: (response) => response.data,
|
2536
|
-
providesTags: [{ type: "ContentTypeSettings", id: "LIST" }]
|
2537
|
-
}),
|
2538
|
-
updateContentTypeConfiguration: builder.mutation({
|
2539
|
-
query: ({ uid, ...body }) => ({
|
2540
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2541
|
-
method: "PUT",
|
2542
|
-
data: body
|
2543
|
-
}),
|
2544
|
-
transformResponse: (response) => response.data,
|
2545
|
-
invalidatesTags: (_result, _error, { uid }) => [
|
2546
|
-
{ type: "ContentTypesConfiguration", id: uid },
|
2547
|
-
{ type: "ContentTypeSettings", id: "LIST" },
|
2548
|
-
// Is this necessary?
|
2549
|
-
{ type: "InitialData" }
|
2550
|
-
]
|
2551
|
-
})
|
2552
|
-
})
|
2553
|
-
});
|
2554
|
-
const {
|
2555
|
-
useGetContentTypeConfigurationQuery,
|
2556
|
-
useGetAllContentTypeSettingsQuery,
|
2557
|
-
useUpdateContentTypeConfigurationMutation
|
2558
|
-
} = contentTypesApi;
|
2559
|
-
const checkIfAttributeIsDisplayable = (attribute) => {
|
2560
|
-
const { type } = attribute;
|
2561
|
-
if (type === "relation") {
|
2562
|
-
return !attribute.relation.toLowerCase().includes("morph");
|
2563
|
-
}
|
2564
|
-
return !["json", "dynamiczone", "richtext", "password", "blocks"].includes(type) && !!type;
|
2565
|
-
};
|
2566
|
-
const getMainField = (attribute, mainFieldName, { schemas, components }) => {
|
2567
|
-
if (!mainFieldName) {
|
2568
|
-
return void 0;
|
2569
|
-
}
|
2570
|
-
const mainFieldType = attribute.type === "component" ? components[attribute.component].attributes[mainFieldName].type : (
|
2571
|
-
// @ts-expect-error – `targetModel` does exist on the attribute for a relation.
|
2572
|
-
schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName].type
|
2573
|
-
);
|
2574
|
-
return {
|
2575
|
-
name: mainFieldName,
|
2576
|
-
type: mainFieldType ?? "string"
|
2577
|
-
};
|
2578
|
-
};
|
2579
|
-
const DEFAULT_SETTINGS = {
|
2580
|
-
bulkable: false,
|
2581
|
-
filterable: false,
|
2582
|
-
searchable: false,
|
2583
|
-
pagination: false,
|
2584
|
-
defaultSortBy: "",
|
2585
|
-
defaultSortOrder: "asc",
|
2586
|
-
mainField: "id",
|
2587
|
-
pageSize: 10
|
2588
|
-
};
|
2589
|
-
const useDocumentLayout = (model) => {
|
2590
|
-
const { schema, components } = useDocument({ model, collectionType: "" }, { skip: true });
|
2591
|
-
const [{ query }] = useQueryParams();
|
2592
|
-
const runHookWaterfall = useStrapiApp("useDocumentLayout", (state) => state.runHookWaterfall);
|
2593
|
-
const { toggleNotification } = useNotification();
|
2594
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
2595
|
-
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
2596
|
-
const {
|
2597
|
-
data,
|
2598
|
-
isLoading: isLoadingConfigs,
|
2599
|
-
error,
|
2600
|
-
isFetching: isFetchingConfigs
|
2601
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2602
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2603
|
-
React.useEffect(() => {
|
2604
|
-
if (error) {
|
2605
|
-
toggleNotification({
|
2606
|
-
type: "danger",
|
2607
|
-
message: formatAPIError(error)
|
2608
|
-
});
|
2609
|
-
}
|
2610
|
-
}, [error, formatAPIError, toggleNotification]);
|
2611
|
-
const editLayout = React.useMemo(
|
2612
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2613
|
-
layout: [],
|
2614
|
-
components: {},
|
2615
|
-
metadatas: {},
|
2616
|
-
options: {},
|
2617
|
-
settings: DEFAULT_SETTINGS
|
2618
|
-
},
|
2619
|
-
[data, isLoading, schemas, schema, components]
|
2620
|
-
);
|
2621
|
-
const listLayout = React.useMemo(() => {
|
2622
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2623
|
-
layout: [],
|
2624
|
-
metadatas: {},
|
2625
|
-
options: {},
|
2626
|
-
settings: DEFAULT_SETTINGS
|
2627
|
-
};
|
2628
|
-
}, [data, isLoading, schemas, schema, components]);
|
2629
|
-
const { layout: edit } = React.useMemo(
|
2630
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2631
|
-
layout: editLayout,
|
2632
|
-
query
|
2633
|
-
}),
|
2634
|
-
[editLayout, query, runHookWaterfall]
|
2635
|
-
);
|
2636
|
-
return {
|
2637
|
-
error,
|
2638
|
-
isLoading,
|
2639
|
-
edit,
|
2640
|
-
list: listLayout
|
2641
|
-
};
|
2642
|
-
};
|
2643
|
-
const useDocLayout = () => {
|
2644
|
-
const { model } = useDoc();
|
2645
|
-
return useDocumentLayout(model);
|
2646
|
-
};
|
2647
|
-
const formatEditLayout = (data, {
|
2648
|
-
schemas,
|
2649
|
-
schema,
|
2650
|
-
components
|
2651
|
-
}) => {
|
2652
|
-
let currentPanelIndex = 0;
|
2653
|
-
const panelledEditAttributes = convertEditLayoutToFieldLayouts(
|
2654
|
-
data.contentType.layouts.edit,
|
2655
|
-
schema?.attributes,
|
2656
|
-
data.contentType.metadatas,
|
2657
|
-
{ configurations: data.components, schemas: components },
|
2658
|
-
schemas
|
2659
|
-
).reduce((panels, row) => {
|
2660
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2661
|
-
panels.push([row]);
|
2662
|
-
currentPanelIndex += 2;
|
2663
|
-
} else {
|
2664
|
-
if (!panels[currentPanelIndex]) {
|
2665
|
-
panels.push([]);
|
2666
|
-
}
|
2667
|
-
panels[currentPanelIndex].push(row);
|
2668
|
-
}
|
2669
|
-
return panels;
|
2670
|
-
}, []);
|
2671
|
-
const componentEditAttributes = Object.entries(data.components).reduce(
|
2672
|
-
(acc, [uid, configuration]) => {
|
2673
|
-
acc[uid] = {
|
2674
|
-
layout: convertEditLayoutToFieldLayouts(
|
2675
|
-
configuration.layouts.edit,
|
2676
|
-
components[uid].attributes,
|
2677
|
-
configuration.metadatas
|
2678
|
-
),
|
2679
|
-
settings: {
|
2680
|
-
...configuration.settings,
|
2681
|
-
icon: components[uid].info.icon,
|
2682
|
-
displayName: components[uid].info.displayName
|
2683
|
-
}
|
2684
|
-
};
|
2685
|
-
return acc;
|
2686
|
-
},
|
2687
|
-
{}
|
2688
|
-
);
|
2689
|
-
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2690
|
-
(acc, [attribute, metadata]) => {
|
2691
|
-
return {
|
2692
|
-
...acc,
|
2693
|
-
[attribute]: metadata.edit
|
2694
|
-
};
|
2695
|
-
},
|
2696
|
-
{}
|
2697
|
-
);
|
2698
|
-
return {
|
2699
|
-
layout: panelledEditAttributes,
|
2700
|
-
components: componentEditAttributes,
|
2701
|
-
metadatas: editMetadatas,
|
2702
|
-
settings: {
|
2703
|
-
...data.contentType.settings,
|
2704
|
-
displayName: schema?.info.displayName
|
2705
|
-
},
|
2706
|
-
options: {
|
2707
|
-
...schema?.options,
|
2708
|
-
...schema?.pluginOptions,
|
2709
|
-
...data.contentType.options
|
2710
|
-
}
|
2711
|
-
};
|
2712
|
-
};
|
2713
|
-
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
2714
|
-
return rows.map(
|
2715
|
-
(row) => row.map((field) => {
|
2716
|
-
const attribute = attributes[field.name];
|
2717
|
-
if (!attribute) {
|
2718
|
-
return null;
|
2719
|
-
}
|
2720
|
-
const { edit: metadata } = metadatas[field.name];
|
2721
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2722
|
-
return {
|
2723
|
-
attribute,
|
2724
|
-
disabled: !metadata.editable,
|
2725
|
-
hint: metadata.description,
|
2726
|
-
label: metadata.label ?? "",
|
2727
|
-
name: field.name,
|
2728
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2729
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2730
|
-
schemas,
|
2731
|
-
components: components?.schemas ?? {}
|
2732
|
-
}),
|
2733
|
-
placeholder: metadata.placeholder ?? "",
|
2734
|
-
required: attribute.required ?? false,
|
2735
|
-
size: field.size,
|
2736
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2737
|
-
visible: metadata.visible ?? true,
|
2738
|
-
type: attribute.type
|
2739
|
-
};
|
2740
|
-
}).filter((field) => field !== null)
|
2741
|
-
);
|
2742
|
-
};
|
2743
|
-
const formatListLayout = (data, {
|
2744
|
-
schemas,
|
2745
|
-
schema,
|
2746
|
-
components
|
2747
|
-
}) => {
|
2748
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2749
|
-
(acc, [attribute, metadata]) => {
|
2750
|
-
return {
|
2751
|
-
...acc,
|
2752
|
-
[attribute]: metadata.list
|
2753
|
-
};
|
2754
|
-
},
|
2755
|
-
{}
|
2756
|
-
);
|
2757
|
-
const listAttributes = convertListLayoutToFieldLayouts(
|
2758
|
-
data.contentType.layouts.list,
|
2759
|
-
schema?.attributes,
|
2760
|
-
listMetadatas,
|
2761
|
-
{ configurations: data.components, schemas: components },
|
2762
|
-
schemas
|
2763
|
-
);
|
2764
|
-
return {
|
2765
|
-
layout: listAttributes,
|
2766
|
-
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
2767
|
-
metadatas: listMetadatas,
|
2768
|
-
options: {
|
2769
|
-
...schema?.options,
|
2770
|
-
...schema?.pluginOptions,
|
2771
|
-
...data.contentType.options
|
2772
|
-
}
|
2773
|
-
};
|
2774
|
-
};
|
2775
|
-
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
2776
|
-
return columns.map((name) => {
|
2777
|
-
const attribute = attributes[name];
|
2778
|
-
if (!attribute) {
|
2779
|
-
return null;
|
2780
|
-
}
|
2781
|
-
const metadata = metadatas[name];
|
2782
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2783
|
-
return {
|
2784
|
-
attribute,
|
2785
|
-
label: metadata.label ?? "",
|
2786
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2787
|
-
schemas,
|
2788
|
-
components: components?.schemas ?? {}
|
2789
|
-
}),
|
2790
|
-
name,
|
2791
|
-
searchable: metadata.searchable ?? true,
|
2792
|
-
sortable: metadata.sortable ?? true
|
2793
|
-
};
|
2794
|
-
}).filter((field) => field !== null);
|
3003
|
+
document: isCloning ? void 0 : document,
|
3004
|
+
meta: isCloning ? void 0 : meta,
|
3005
|
+
collectionType
|
3006
|
+
};
|
3007
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
3008
|
+
/* @__PURE__ */ jsx(
|
3009
|
+
DescriptionComponentRenderer,
|
3010
|
+
{
|
3011
|
+
props,
|
3012
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3013
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
3014
|
+
}
|
3015
|
+
),
|
3016
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3017
|
+
] });
|
2795
3018
|
};
|
3019
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
3020
|
+
return /* @__PURE__ */ jsxs(
|
3021
|
+
Flex,
|
3022
|
+
{
|
3023
|
+
ref,
|
3024
|
+
tag: "aside",
|
3025
|
+
"aria-labelledby": "additional-information",
|
3026
|
+
background: "neutral0",
|
3027
|
+
borderColor: "neutral150",
|
3028
|
+
hasRadius: true,
|
3029
|
+
paddingBottom: 4,
|
3030
|
+
paddingLeft: 4,
|
3031
|
+
paddingRight: 4,
|
3032
|
+
paddingTop: 4,
|
3033
|
+
shadow: "tableShadow",
|
3034
|
+
gap: 3,
|
3035
|
+
direction: "column",
|
3036
|
+
justifyContent: "stretch",
|
3037
|
+
alignItems: "flex-start",
|
3038
|
+
children: [
|
3039
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", textColor: "neutral600", children: title }),
|
3040
|
+
children
|
3041
|
+
]
|
3042
|
+
}
|
3043
|
+
);
|
3044
|
+
});
|
2796
3045
|
const ConfirmBulkActionDialog = ({
|
2797
3046
|
onToggleDialog,
|
2798
3047
|
isOpen = false,
|
@@ -2800,30 +3049,23 @@ const ConfirmBulkActionDialog = ({
|
|
2800
3049
|
endAction
|
2801
3050
|
}) => {
|
2802
3051
|
const { formatMessage } = useIntl();
|
2803
|
-
return /* @__PURE__ */ jsxs(
|
2804
|
-
Dialog,
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
|
2811
|
-
|
2812
|
-
|
2813
|
-
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
}) }),
|
2821
|
-
endAction
|
2822
|
-
}
|
2823
|
-
)
|
2824
|
-
]
|
2825
|
-
}
|
2826
|
-
);
|
3052
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
3053
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: formatMessage({
|
3054
|
+
id: "app.components.ConfirmDialog.title",
|
3055
|
+
defaultMessage: "Confirmation"
|
3056
|
+
}) }),
|
3057
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3058
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3059
|
+
dialogBody
|
3060
|
+
] }) }),
|
3061
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
3062
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { fullWidth: true, onClick: onToggleDialog, variant: "tertiary", children: formatMessage({
|
3063
|
+
id: "app.components.Button.cancel",
|
3064
|
+
defaultMessage: "Cancel"
|
3065
|
+
}) }) }),
|
3066
|
+
endAction
|
3067
|
+
] })
|
3068
|
+
] }) });
|
2827
3069
|
};
|
2828
3070
|
const BoldChunk$1 = (chunks) => /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: chunks });
|
2829
3071
|
const ConfirmDialogPublishAll = ({
|
@@ -2838,6 +3080,7 @@ const ConfirmDialogPublishAll = ({
|
|
2838
3080
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
|
2839
3081
|
const { model, schema } = useDoc();
|
2840
3082
|
const [{ query }] = useQueryParams();
|
3083
|
+
const enableDraftRelationsCount = false;
|
2841
3084
|
const {
|
2842
3085
|
data: countDraftRelations = 0,
|
2843
3086
|
isLoading,
|
@@ -2849,7 +3092,7 @@ const ConfirmDialogPublishAll = ({
|
|
2849
3092
|
locale: query?.plugins?.i18n?.locale
|
2850
3093
|
},
|
2851
3094
|
{
|
2852
|
-
skip:
|
3095
|
+
skip: !enableDraftRelationsCount
|
2853
3096
|
}
|
2854
3097
|
);
|
2855
3098
|
React.useEffect(() => {
|
@@ -2928,16 +3171,30 @@ const formatErrorMessages = (errors, parentKey, formatMessage) => {
|
|
2928
3171
|
)
|
2929
3172
|
);
|
2930
3173
|
} else {
|
2931
|
-
messages.push(
|
3174
|
+
messages.push(
|
3175
|
+
...formatErrorMessages(
|
3176
|
+
// @ts-expect-error TODO: check why value is not compatible with FormErrors
|
3177
|
+
value,
|
3178
|
+
currentKey,
|
3179
|
+
formatMessage
|
3180
|
+
)
|
3181
|
+
);
|
2932
3182
|
}
|
3183
|
+
} else {
|
3184
|
+
messages.push(
|
3185
|
+
formatMessage(
|
3186
|
+
{
|
3187
|
+
id: `${value}.withField`,
|
3188
|
+
defaultMessage: value
|
3189
|
+
},
|
3190
|
+
{ field: currentKey }
|
3191
|
+
)
|
3192
|
+
);
|
2933
3193
|
}
|
2934
3194
|
});
|
2935
3195
|
return messages;
|
2936
3196
|
};
|
2937
|
-
const EntryValidationText = ({
|
2938
|
-
validationErrors,
|
2939
|
-
isPublished = false
|
2940
|
-
}) => {
|
3197
|
+
const EntryValidationText = ({ validationErrors, status }) => {
|
2941
3198
|
const { formatMessage } = useIntl();
|
2942
3199
|
if (validationErrors) {
|
2943
3200
|
const validationErrorsMessages = formatErrorMessages(validationErrors, "", formatMessage).join(
|
@@ -2948,7 +3205,7 @@ const EntryValidationText = ({
|
|
2948
3205
|
/* @__PURE__ */ jsx(Tooltip, { description: validationErrorsMessages, children: /* @__PURE__ */ jsx(TypographyMaxWidth, { textColor: "danger600", variant: "omega", fontWeight: "semiBold", ellipsis: true, children: validationErrorsMessages }) })
|
2949
3206
|
] });
|
2950
3207
|
}
|
2951
|
-
if (
|
3208
|
+
if (status === "published") {
|
2952
3209
|
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
2953
3210
|
/* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
|
2954
3211
|
/* @__PURE__ */ jsx(Typography, { textColor: "success600", fontWeight: "bold", children: formatMessage({
|
@@ -2957,6 +3214,15 @@ const EntryValidationText = ({
|
|
2957
3214
|
}) })
|
2958
3215
|
] });
|
2959
3216
|
}
|
3217
|
+
if (status === "modified") {
|
3218
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3219
|
+
/* @__PURE__ */ jsx(ArrowsCounterClockwise, { fill: "alternative600" }),
|
3220
|
+
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
3221
|
+
id: "content-manager.bulk-publish.modified",
|
3222
|
+
defaultMessage: "Ready to publish changes"
|
3223
|
+
}) })
|
3224
|
+
] });
|
3225
|
+
}
|
2960
3226
|
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
2961
3227
|
/* @__PURE__ */ jsx(CheckCircle, { fill: "success600" }),
|
2962
3228
|
/* @__PURE__ */ jsx(Typography, { children: formatMessage({
|
@@ -3008,10 +3274,10 @@ const SelectedEntriesTableContent = ({
|
|
3008
3274
|
EntryValidationText,
|
3009
3275
|
{
|
3010
3276
|
validationErrors: validationErrors[row.documentId],
|
3011
|
-
|
3277
|
+
status: row.status
|
3012
3278
|
}
|
3013
3279
|
) }),
|
3014
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
|
3280
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
|
3015
3281
|
IconButton,
|
3016
3282
|
{
|
3017
3283
|
tag: Link,
|
@@ -3034,9 +3300,10 @@ const SelectedEntriesTableContent = ({
|
|
3034
3300
|
),
|
3035
3301
|
target: "_blank",
|
3036
3302
|
marginLeft: "auto",
|
3037
|
-
|
3303
|
+
variant: "ghost",
|
3304
|
+
children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
|
3038
3305
|
}
|
3039
|
-
) })
|
3306
|
+
) }) })
|
3040
3307
|
] }, row.id)) })
|
3041
3308
|
] });
|
3042
3309
|
};
|
@@ -3073,7 +3340,13 @@ const SelectedEntriesModalContent = ({
|
|
3073
3340
|
);
|
3074
3341
|
const { rows, validationErrors } = React.useMemo(() => {
|
3075
3342
|
if (data.length > 0 && schema) {
|
3076
|
-
const validate = createYupSchema(
|
3343
|
+
const validate = createYupSchema(
|
3344
|
+
schema.attributes,
|
3345
|
+
components,
|
3346
|
+
// Since this is the "Publish" action, the validation
|
3347
|
+
// schema must enforce the rules for published entities
|
3348
|
+
{ status: "published" }
|
3349
|
+
);
|
3077
3350
|
const validationErrors2 = {};
|
3078
3351
|
const rows2 = data.map((entry) => {
|
3079
3352
|
try {
|
@@ -3149,7 +3422,7 @@ const SelectedEntriesModalContent = ({
|
|
3149
3422
|
);
|
3150
3423
|
};
|
3151
3424
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
3152
|
-
/* @__PURE__ */ jsxs(
|
3425
|
+
/* @__PURE__ */ jsxs(Modal.Body, { children: [
|
3153
3426
|
/* @__PURE__ */ jsx(Typography, { children: getFormattedCountMessage() }),
|
3154
3427
|
/* @__PURE__ */ jsx(Box, { marginTop: 5, children: /* @__PURE__ */ jsx(
|
3155
3428
|
SelectedEntriesTableContent,
|
@@ -3161,27 +3434,24 @@ const SelectedEntriesModalContent = ({
|
|
3161
3434
|
}
|
3162
3435
|
) })
|
3163
3436
|
] }),
|
3164
|
-
/* @__PURE__ */
|
3165
|
-
|
3166
|
-
|
3167
|
-
|
3168
|
-
|
3169
|
-
|
3170
|
-
}) }),
|
3171
|
-
|
3172
|
-
|
3173
|
-
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3182
|
-
] })
|
3183
|
-
}
|
3184
|
-
),
|
3437
|
+
/* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3438
|
+
/* @__PURE__ */ jsx(Button, { onClick: toggleModal, variant: "tertiary", children: formatMessage({
|
3439
|
+
id: "app.components.Button.cancel",
|
3440
|
+
defaultMessage: "Cancel"
|
3441
|
+
}) }),
|
3442
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
3443
|
+
/* @__PURE__ */ jsx(Button, { onClick: refetch, variant: "tertiary", loading: isFetching, children: formatMessage({ id: "app.utils.refresh", defaultMessage: "Refresh" }) }),
|
3444
|
+
/* @__PURE__ */ jsx(
|
3445
|
+
Button,
|
3446
|
+
{
|
3447
|
+
onClick: toggleDialog,
|
3448
|
+
disabled: selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntriesPublished === selectedEntries.length || isLoading,
|
3449
|
+
loading: isSubmittingForm,
|
3450
|
+
children: formatMessage({ id: "app.utils.publish", defaultMessage: "Publish" })
|
3451
|
+
}
|
3452
|
+
)
|
3453
|
+
] })
|
3454
|
+
] }),
|
3185
3455
|
/* @__PURE__ */ jsx(
|
3186
3456
|
ConfirmDialogPublishAll,
|
3187
3457
|
{
|
@@ -3246,143 +3516,10 @@ const BulkActionsRenderer = () => {
|
|
3246
3516
|
documents: selectedRows
|
3247
3517
|
},
|
3248
3518
|
descriptions: plugins["content-manager"].apis.getBulkActions(),
|
3249
|
-
children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(
|
3519
|
+
children: (actions2) => actions2.map((action) => /* @__PURE__ */ jsx(DocumentActionButton, { ...action }, action.id))
|
3250
3520
|
}
|
3251
3521
|
) });
|
3252
3522
|
};
|
3253
|
-
const BulkActionAction = (action) => {
|
3254
|
-
const [dialogId, setDialogId] = React.useState(null);
|
3255
|
-
const { toggleNotification } = useNotification();
|
3256
|
-
const handleClick = (action2) => (e) => {
|
3257
|
-
const { onClick, dialog, id } = action2;
|
3258
|
-
if (onClick) {
|
3259
|
-
onClick(e);
|
3260
|
-
}
|
3261
|
-
if (dialog) {
|
3262
|
-
switch (dialog.type) {
|
3263
|
-
case "notification":
|
3264
|
-
toggleNotification({
|
3265
|
-
title: dialog.title,
|
3266
|
-
message: dialog.content,
|
3267
|
-
type: dialog.status,
|
3268
|
-
timeout: dialog.timeout,
|
3269
|
-
onClose: dialog.onClose
|
3270
|
-
});
|
3271
|
-
break;
|
3272
|
-
case "dialog":
|
3273
|
-
case "modal": {
|
3274
|
-
e.preventDefault();
|
3275
|
-
setDialogId(id);
|
3276
|
-
}
|
3277
|
-
}
|
3278
|
-
}
|
3279
|
-
};
|
3280
|
-
const handleClose = () => {
|
3281
|
-
setDialogId(null);
|
3282
|
-
if (action.dialog?.type === "modal" && action.dialog?.onClose) {
|
3283
|
-
action.dialog.onClose();
|
3284
|
-
}
|
3285
|
-
};
|
3286
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
3287
|
-
/* @__PURE__ */ jsx(
|
3288
|
-
Button,
|
3289
|
-
{
|
3290
|
-
disabled: action.disabled,
|
3291
|
-
startIcon: action.icon,
|
3292
|
-
variant: action.variant,
|
3293
|
-
onClick: handleClick(action),
|
3294
|
-
children: action.label
|
3295
|
-
}
|
3296
|
-
),
|
3297
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
|
3298
|
-
BulkActionConfirmDialog,
|
3299
|
-
{
|
3300
|
-
...action.dialog,
|
3301
|
-
variant: action.variant,
|
3302
|
-
isOpen: dialogId === action.id,
|
3303
|
-
onClose: handleClose
|
3304
|
-
}
|
3305
|
-
) : null,
|
3306
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
|
3307
|
-
BulkActionModal,
|
3308
|
-
{
|
3309
|
-
...action.dialog,
|
3310
|
-
onModalClose: handleClose,
|
3311
|
-
isOpen: dialogId === action.id
|
3312
|
-
}
|
3313
|
-
) : null
|
3314
|
-
] });
|
3315
|
-
};
|
3316
|
-
const BulkActionConfirmDialog = ({
|
3317
|
-
onClose,
|
3318
|
-
onCancel,
|
3319
|
-
onConfirm,
|
3320
|
-
title,
|
3321
|
-
content,
|
3322
|
-
confirmButton,
|
3323
|
-
isOpen,
|
3324
|
-
variant = "secondary"
|
3325
|
-
}) => {
|
3326
|
-
const { formatMessage } = useIntl();
|
3327
|
-
const handleClose = async () => {
|
3328
|
-
if (onCancel) {
|
3329
|
-
await onCancel();
|
3330
|
-
}
|
3331
|
-
onClose();
|
3332
|
-
};
|
3333
|
-
const handleConfirm = async () => {
|
3334
|
-
if (onConfirm) {
|
3335
|
-
await onConfirm();
|
3336
|
-
}
|
3337
|
-
onClose();
|
3338
|
-
};
|
3339
|
-
return /* @__PURE__ */ jsxs(Dialog, { isOpen, title, onClose: handleClose, children: [
|
3340
|
-
/* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: content }),
|
3341
|
-
/* @__PURE__ */ jsx(
|
3342
|
-
DialogFooter,
|
3343
|
-
{
|
3344
|
-
startAction: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", children: formatMessage({
|
3345
|
-
id: "app.components.Button.cancel",
|
3346
|
-
defaultMessage: "Cancel"
|
3347
|
-
}) }),
|
3348
|
-
endAction: /* @__PURE__ */ jsx(
|
3349
|
-
Button,
|
3350
|
-
{
|
3351
|
-
onClick: handleConfirm,
|
3352
|
-
variant: variant === "danger-light" ? variant : "secondary",
|
3353
|
-
startIcon: variant === "danger-light" ? /* @__PURE__ */ jsx(Trash, {}) : /* @__PURE__ */ jsx(Check, {}),
|
3354
|
-
children: confirmButton ? confirmButton : formatMessage({
|
3355
|
-
id: "app.components.Button.confirm",
|
3356
|
-
defaultMessage: "Confirm"
|
3357
|
-
})
|
3358
|
-
}
|
3359
|
-
)
|
3360
|
-
}
|
3361
|
-
)
|
3362
|
-
] });
|
3363
|
-
};
|
3364
|
-
const BulkActionModal = ({
|
3365
|
-
isOpen,
|
3366
|
-
title,
|
3367
|
-
onClose,
|
3368
|
-
content: Content,
|
3369
|
-
onModalClose
|
3370
|
-
}) => {
|
3371
|
-
const id = React.useId();
|
3372
|
-
if (!isOpen) {
|
3373
|
-
return null;
|
3374
|
-
}
|
3375
|
-
const handleClose = () => {
|
3376
|
-
if (onClose) {
|
3377
|
-
onClose();
|
3378
|
-
}
|
3379
|
-
onModalClose();
|
3380
|
-
};
|
3381
|
-
return /* @__PURE__ */ jsxs(ModalLayout, { borderRadius: "4px", overflow: "hidden", onClose: handleClose, labelledBy: id, children: [
|
3382
|
-
/* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", textColor: "neutral800", tag: "h2", id, children: title }) }),
|
3383
|
-
/* @__PURE__ */ jsx(Content, { onClose: handleClose })
|
3384
|
-
] });
|
3385
|
-
};
|
3386
3523
|
const DeleteAction = ({ documents, model }) => {
|
3387
3524
|
const { formatMessage } = useIntl();
|
3388
3525
|
const { schema: contentType } = useDoc();
|
@@ -3415,6 +3552,7 @@ const DeleteAction = ({ documents, model }) => {
|
|
3415
3552
|
defaultMessage: "Confirmation"
|
3416
3553
|
}),
|
3417
3554
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3555
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3418
3556
|
/* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
3419
3557
|
id: "popUpWarning.bodyMessage.contentType.delete.all",
|
3420
3558
|
defaultMessage: "Are you sure you want to delete these entries?"
|
@@ -3451,7 +3589,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
3451
3589
|
selectRow([]);
|
3452
3590
|
}
|
3453
3591
|
};
|
3454
|
-
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published");
|
3592
|
+
const showUnpublishButton = hasDraftAndPublishEnabled && hasPublishPermission && documents.some((entry) => entry.status === "published" || entry.status === "modified");
|
3455
3593
|
if (!showUnpublishButton)
|
3456
3594
|
return null;
|
3457
3595
|
return {
|
@@ -3464,6 +3602,7 @@ const UnpublishAction = ({ documents, model }) => {
|
|
3464
3602
|
defaultMessage: "Confirmation"
|
3465
3603
|
}),
|
3466
3604
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
3605
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }) }),
|
3467
3606
|
/* @__PURE__ */ jsx(Typography, { id: "confirm-description", textAlign: "center", children: formatMessage({
|
3468
3607
|
id: "popUpWarning.bodyMessage.contentType.unpublish.all",
|
3469
3608
|
defaultMessage: "Are you sure you want to unpublish these entries?"
|
@@ -3557,7 +3696,7 @@ const TableActions = ({ document }) => {
|
|
3557
3696
|
DescriptionComponentRenderer,
|
3558
3697
|
{
|
3559
3698
|
props,
|
3560
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3699
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
|
3561
3700
|
children: (actions2) => {
|
3562
3701
|
const tableRowActions = actions2.filter((action) => {
|
3563
3702
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -3668,7 +3807,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
3668
3807
|
}),
|
3669
3808
|
content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
|
3670
3809
|
footer: ({ onClose }) => {
|
3671
|
-
return /* @__PURE__ */ jsxs(
|
3810
|
+
return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3672
3811
|
/* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
|
3673
3812
|
id: "cancel",
|
3674
3813
|
defaultMessage: "Cancel"
|
@@ -3709,8 +3848,7 @@ class ContentManagerPlugin {
|
|
3709
3848
|
documentActions = [
|
3710
3849
|
...DEFAULT_ACTIONS,
|
3711
3850
|
...DEFAULT_TABLE_ROW_ACTIONS,
|
3712
|
-
...DEFAULT_HEADER_ACTIONS
|
3713
|
-
HistoryAction
|
3851
|
+
...DEFAULT_HEADER_ACTIONS
|
3714
3852
|
];
|
3715
3853
|
editViewSidePanels = [ActionsPanel];
|
3716
3854
|
headerActions = [];
|
@@ -3799,6 +3937,52 @@ const getPrintableType = (value) => {
|
|
3799
3937
|
}
|
3800
3938
|
return nativeType;
|
3801
3939
|
};
|
3940
|
+
const HistoryAction = ({ model, document }) => {
|
3941
|
+
const { formatMessage } = useIntl();
|
3942
|
+
const [{ query }] = useQueryParams();
|
3943
|
+
const navigate = useNavigate();
|
3944
|
+
const pluginsQueryParams = stringify({ plugins: query.plugins }, { encode: false });
|
3945
|
+
if (!window.strapi.features.isEnabled("cms-content-history")) {
|
3946
|
+
return null;
|
3947
|
+
}
|
3948
|
+
return {
|
3949
|
+
icon: /* @__PURE__ */ jsx(ClockCounterClockwise, {}),
|
3950
|
+
label: formatMessage({
|
3951
|
+
id: "content-manager.history.document-action",
|
3952
|
+
defaultMessage: "Content History"
|
3953
|
+
}),
|
3954
|
+
onClick: () => navigate({ pathname: "history", search: pluginsQueryParams }),
|
3955
|
+
disabled: (
|
3956
|
+
/**
|
3957
|
+
* The user is creating a new document.
|
3958
|
+
* It hasn't been saved yet, so there's no history to go to
|
3959
|
+
*/
|
3960
|
+
!document || /**
|
3961
|
+
* The document has been created but the current dimension has never been saved.
|
3962
|
+
* For example, the user is creating a new locale in an existing document,
|
3963
|
+
* so there's no history for the document in that locale
|
3964
|
+
*/
|
3965
|
+
!document.id || /**
|
3966
|
+
* History is only available for content types created by the user.
|
3967
|
+
* These have the `api::` prefix, as opposed to the ones created by Strapi or plugins,
|
3968
|
+
* which start with `admin::` or `plugin::`
|
3969
|
+
*/
|
3970
|
+
!model.startsWith("api::")
|
3971
|
+
),
|
3972
|
+
position: "header"
|
3973
|
+
};
|
3974
|
+
};
|
3975
|
+
HistoryAction.type = "history";
|
3976
|
+
const historyAdmin = {
|
3977
|
+
bootstrap(app) {
|
3978
|
+
const { addDocumentAction } = app.getPlugin("content-manager").apis;
|
3979
|
+
addDocumentAction((actions2) => {
|
3980
|
+
const indexOfDeleteAction = actions2.findIndex((action) => action.type === "delete");
|
3981
|
+
actions2.splice(indexOfDeleteAction, 0, HistoryAction);
|
3982
|
+
return actions2;
|
3983
|
+
});
|
3984
|
+
}
|
3985
|
+
};
|
3802
3986
|
const initialState = {
|
3803
3987
|
collectionTypeLinks: [],
|
3804
3988
|
components: [],
|
@@ -3835,6 +4019,70 @@ const { setInitialData } = actions;
|
|
3835
4019
|
const reducer = combineReducers({
|
3836
4020
|
app: reducer$1
|
3837
4021
|
});
|
4022
|
+
const previewApi = contentManagerApi.injectEndpoints({
|
4023
|
+
endpoints: (builder) => ({
|
4024
|
+
getPreviewUrl: builder.query({
|
4025
|
+
query({ query, params }) {
|
4026
|
+
return {
|
4027
|
+
url: `/content-manager/preview/url/${params.contentType}`,
|
4028
|
+
method: "GET",
|
4029
|
+
config: {
|
4030
|
+
params: query
|
4031
|
+
}
|
4032
|
+
};
|
4033
|
+
}
|
4034
|
+
})
|
4035
|
+
})
|
4036
|
+
});
|
4037
|
+
const { useGetPreviewUrlQuery } = previewApi;
|
4038
|
+
const PreviewSidePanel = ({ model, documentId, document }) => {
|
4039
|
+
const { formatMessage } = useIntl();
|
4040
|
+
const { trackUsage } = useTracking();
|
4041
|
+
const [{ query }] = useQueryParams();
|
4042
|
+
const { data, error } = useGetPreviewUrlQuery({
|
4043
|
+
params: {
|
4044
|
+
contentType: model
|
4045
|
+
},
|
4046
|
+
query: {
|
4047
|
+
documentId,
|
4048
|
+
locale: document?.locale,
|
4049
|
+
status: document?.status
|
4050
|
+
}
|
4051
|
+
});
|
4052
|
+
if (!data?.data?.url || error) {
|
4053
|
+
return null;
|
4054
|
+
}
|
4055
|
+
const handleClick = () => {
|
4056
|
+
trackUsage("willOpenPreview");
|
4057
|
+
};
|
4058
|
+
return {
|
4059
|
+
title: formatMessage({ id: "content-manager.preview.panel.title", defaultMessage: "Preview" }),
|
4060
|
+
content: /* @__PURE__ */ jsx(Flex, { gap: 2, width: "100%", children: /* @__PURE__ */ jsx(
|
4061
|
+
Button,
|
4062
|
+
{
|
4063
|
+
variant: "tertiary",
|
4064
|
+
tag: Link,
|
4065
|
+
to: { pathname: "preview", search: stringify(query, { encode: false }) },
|
4066
|
+
onClick: handleClick,
|
4067
|
+
flex: "auto",
|
4068
|
+
children: formatMessage({
|
4069
|
+
id: "content-manager.preview.panel.button",
|
4070
|
+
defaultMessage: "Open preview"
|
4071
|
+
})
|
4072
|
+
}
|
4073
|
+
) })
|
4074
|
+
};
|
4075
|
+
};
|
4076
|
+
const FEATURE_ID = "preview";
|
4077
|
+
const previewAdmin = {
|
4078
|
+
bootstrap(app) {
|
4079
|
+
if (!window.strapi.future.isEnabled(FEATURE_ID)) {
|
4080
|
+
return;
|
4081
|
+
}
|
4082
|
+
const contentManagerPluginApis = app.getPlugin("content-manager").apis;
|
4083
|
+
contentManagerPluginApis.addEditViewSidePanel([PreviewSidePanel]);
|
4084
|
+
}
|
4085
|
+
};
|
3838
4086
|
const index = {
|
3839
4087
|
register(app) {
|
3840
4088
|
const cm = new ContentManagerPlugin();
|
@@ -3849,15 +4097,32 @@ const index = {
|
|
3849
4097
|
defaultMessage: "Content Manager"
|
3850
4098
|
},
|
3851
4099
|
permissions: [],
|
3852
|
-
Component: () => import("./layout-CPn1PM6x.mjs").then((mod) => ({ default: mod.Layout })),
|
3853
4100
|
position: 1
|
3854
4101
|
});
|
4102
|
+
app.router.addRoute({
|
4103
|
+
path: "content-manager/*",
|
4104
|
+
lazy: async () => {
|
4105
|
+
const { Layout } = await import("./layout-Btu_cMRF.mjs");
|
4106
|
+
return {
|
4107
|
+
Component: Layout
|
4108
|
+
};
|
4109
|
+
},
|
4110
|
+
children: routes
|
4111
|
+
});
|
3855
4112
|
app.registerPlugin(cm.config);
|
3856
4113
|
},
|
4114
|
+
bootstrap(app) {
|
4115
|
+
if (typeof historyAdmin.bootstrap === "function") {
|
4116
|
+
historyAdmin.bootstrap(app);
|
4117
|
+
}
|
4118
|
+
if (typeof previewAdmin.bootstrap === "function") {
|
4119
|
+
previewAdmin.bootstrap(app);
|
4120
|
+
}
|
4121
|
+
},
|
3857
4122
|
async registerTrads({ locales }) {
|
3858
4123
|
const importedTrads = await Promise.all(
|
3859
4124
|
locales.map((locale) => {
|
3860
|
-
return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/ar.json": () => import("./ar-CCEVvqGG.mjs"), "./translations/ca.json": () => import("./ca-5U32ON2v.mjs"), "./translations/cs.json": () => import("./cs-CM2aBUar.mjs"), "./translations/de.json": () => import("./de-C72KDNOl.mjs"), "./translations/en.json": () => import("./en-
|
4125
|
+
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-D_BMf0hT.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 }) => {
|
3861
4126
|
return {
|
3862
4127
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3863
4128
|
locale
|
@@ -3884,37 +4149,39 @@ export {
|
|
3884
4149
|
HOOKS as H,
|
3885
4150
|
InjectionZone as I,
|
3886
4151
|
useDocument as J,
|
3887
|
-
|
3888
|
-
|
4152
|
+
useGetPreviewUrlQuery as K,
|
4153
|
+
index as L,
|
4154
|
+
useContentManagerContext as M,
|
4155
|
+
useDocumentActions as N,
|
3889
4156
|
Panels as P,
|
3890
4157
|
RelativeTime as R,
|
3891
4158
|
SINGLE_TYPES as S,
|
3892
4159
|
TableActions as T,
|
3893
|
-
|
3894
|
-
|
3895
|
-
|
3896
|
-
|
3897
|
-
|
3898
|
-
|
4160
|
+
useGetInitialDataQuery as a,
|
4161
|
+
useGetAllContentTypeSettingsQuery as b,
|
4162
|
+
useDoc as c,
|
4163
|
+
buildValidParams as d,
|
4164
|
+
contentManagerApi as e,
|
4165
|
+
useDocumentRBAC as f,
|
3899
4166
|
getTranslation as g,
|
3900
|
-
|
3901
|
-
|
3902
|
-
|
3903
|
-
|
3904
|
-
|
3905
|
-
|
3906
|
-
|
3907
|
-
|
3908
|
-
|
3909
|
-
|
3910
|
-
|
4167
|
+
useDocumentLayout as h,
|
4168
|
+
createYupSchema as i,
|
4169
|
+
Header as j,
|
4170
|
+
PERMISSIONS as k,
|
4171
|
+
DocumentRBAC as l,
|
4172
|
+
DOCUMENT_META_FIELDS as m,
|
4173
|
+
CLONE_PATH as n,
|
4174
|
+
useDocLayout as o,
|
4175
|
+
useGetContentTypeConfigurationQuery as p,
|
4176
|
+
CREATOR_FIELDS as q,
|
4177
|
+
getMainField as r,
|
3911
4178
|
setInitialData as s,
|
3912
4179
|
getDisplayName as t,
|
3913
|
-
|
4180
|
+
useContentTypeSchema as u,
|
3914
4181
|
checkIfAttributeIsDisplayable as v,
|
3915
4182
|
useGetAllDocumentsQuery as w,
|
3916
4183
|
convertListLayoutToFieldLayouts as x,
|
3917
4184
|
capitalise as y,
|
3918
4185
|
useUpdateContentTypeConfigurationMutation as z
|
3919
4186
|
};
|
3920
|
-
//# sourceMappingURL=index-
|
4187
|
+
//# sourceMappingURL=index-CbytGVdz.mjs.map
|