@strapi/content-manager 0.0.0-experimental.abc → 0.0.0-experimental.b1d7921ddb1b36c84b58a3946e1dc9dbda91b2dc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-KXSuLnQD.js → ComponentConfigurationPage-CQDCxI8x.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-KXSuLnQD.js.map → ComponentConfigurationPage-CQDCxI8x.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-B3yDbeU1.mjs → ComponentConfigurationPage-jmWwucg_.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-B3yDbeU1.mjs.map → ComponentConfigurationPage-jmWwucg_.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BQ17--5R.js → EditConfigurationPage-Ce4bIm4n.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BQ17--5R.js.map → EditConfigurationPage-Ce4bIm4n.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-D7PrLO8j.mjs → EditConfigurationPage-W07CEdm2.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-D7PrLO8j.mjs.map → EditConfigurationPage-W07CEdm2.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-BgjdnGz2.js → EditViewPage-CqHMM0P0.js} +15 -5
- package/dist/_chunks/EditViewPage-CqHMM0P0.js.map +1 -0
- package/dist/_chunks/{EditViewPage-B7VgwJaG.mjs → EditViewPage-al5OO1NR.mjs} +15 -5
- package/dist/_chunks/EditViewPage-al5OO1NR.mjs.map +1 -0
- package/dist/_chunks/{Field-CdK7ZLmv.js → Field-DSOUlTCm.js} +100 -87
- package/dist/_chunks/Field-DSOUlTCm.js.map +1 -0
- package/dist/_chunks/{Field-tHCw4lGA.mjs → Field-EeG6NQ7x.mjs} +97 -84
- package/dist/_chunks/Field-EeG6NQ7x.mjs.map +1 -0
- package/dist/_chunks/{Form-BJxdTv3Q.mjs → Form-BAo9ANb_.mjs} +16 -8
- package/dist/_chunks/Form-BAo9ANb_.mjs.map +1 -0
- package/dist/_chunks/{Form-C_0KTVvV.js → Form-DAEfHKzm.js} +16 -8
- package/dist/_chunks/Form-DAEfHKzm.js.map +1 -0
- package/dist/_chunks/{History-DR2txJLE.mjs → History-BpLIu67W.mjs} +24 -11
- package/dist/_chunks/History-BpLIu67W.mjs.map +1 -0
- package/dist/_chunks/{History-nuEzM5qm.js → History-CTFvy6XH.js} +23 -10
- package/dist/_chunks/History-CTFvy6XH.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CnB86Psm.js → ListConfigurationPage-CDzlMBz_.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-CnB86Psm.js.map → ListConfigurationPage-CDzlMBz_.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-voFVtXu6.mjs → ListConfigurationPage-DOqj5f8Y.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-voFVtXu6.mjs.map → ListConfigurationPage-DOqj5f8Y.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-B_GaWgRH.mjs → ListViewPage-BbXYNI0v.mjs} +40 -36
- package/dist/_chunks/ListViewPage-BbXYNI0v.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-SXIXm-RM.js → ListViewPage-D0fpPYKp.js} +43 -39
- package/dist/_chunks/ListViewPage-D0fpPYKp.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BzsQ3hLZ.js → NoContentTypePage-DTzkSAV5.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BzsQ3hLZ.js.map → NoContentTypePage-DTzkSAV5.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-CYiGpsbj.mjs → NoContentTypePage-w2Q0VVOT.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CYiGpsbj.mjs.map → NoContentTypePage-w2Q0VVOT.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-IGkId4C5.js → NoPermissionsPage-BoI2rU68.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-IGkId4C5.js.map → NoPermissionsPage-BoI2rU68.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-B5baIHal.mjs → NoPermissionsPage-Km0Vk5Wp.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-B5baIHal.mjs.map → NoPermissionsPage-Km0Vk5Wp.mjs.map} +1 -1
- package/dist/_chunks/{Relations-CIYDdKU-.mjs → Relations-C_bpmSuQ.mjs} +50 -28
- package/dist/_chunks/Relations-C_bpmSuQ.mjs.map +1 -0
- package/dist/_chunks/{Relations-Dhuurpx2.js → Relations-D6Nz5ksc.js} +50 -28
- package/dist/_chunks/Relations-D6Nz5ksc.js.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-CdT0kHZ8.js → index-BsMu2oVP.js} +1907 -1762
- package/dist/_chunks/index-BsMu2oVP.js.map +1 -0
- package/dist/_chunks/{index-C9TJPyni.mjs → index-DcQ6xogO.mjs} +1926 -1782
- package/dist/_chunks/index-DcQ6xogO.mjs.map +1 -0
- package/dist/_chunks/{layout-C6dxWYT7.js → layout-B4aCAdTt.js} +5 -4
- package/dist/_chunks/{layout-C6dxWYT7.js.map → layout-B4aCAdTt.js.map} +1 -1
- package/dist/_chunks/{layout-BNqvLR_b.mjs → layout-BavJ6v4B.mjs} +5 -4
- package/dist/_chunks/{layout-BNqvLR_b.mjs.map → layout-BavJ6v4B.mjs.map} +1 -1
- package/dist/_chunks/{relations-CkKqKw65.mjs → relations-DMG453Od.mjs} +2 -2
- package/dist/_chunks/{relations-CkKqKw65.mjs.map → relations-DMG453Od.mjs.map} +1 -1
- package/dist/_chunks/{relations-DtFaDnP1.js → relations-Lrm9nz_m.js} +2 -2
- package/dist/_chunks/{relations-DtFaDnP1.js.map → relations-Lrm9nz_m.js.map} +1 -1
- 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 +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- 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/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +0 -32
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- 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 +117 -53
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +117 -53
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +1 -0
- 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/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/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/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/package.json +12 -12
- package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +0 -1
- package/dist/_chunks/Field-CdK7ZLmv.js.map +0 -1
- package/dist/_chunks/Field-tHCw4lGA.mjs.map +0 -1
- package/dist/_chunks/Form-BJxdTv3Q.mjs.map +0 -1
- package/dist/_chunks/Form-C_0KTVvV.js.map +0 -1
- package/dist/_chunks/History-DR2txJLE.mjs.map +0 -1
- package/dist/_chunks/History-nuEzM5qm.js.map +0 -1
- package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +0 -1
- package/dist/_chunks/Relations-CIYDdKU-.mjs.map +0 -1
- package/dist/_chunks/Relations-Dhuurpx2.js.map +0 -1
- package/dist/_chunks/index-C9TJPyni.mjs.map +0 -1
- package/dist/_chunks/index-CdT0kHZ8.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,16 +1,17 @@
|
|
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, createContext, useAuth, useRBAC, Page, adminApi, translatedErrors, useNotification, useAPIErrorHandler, getYupValidationErrors,
|
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";
|
4
4
|
import * as React from "react";
|
5
5
|
import { lazy } from "react";
|
6
|
-
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";
|
7
8
|
import { useIntl } from "react-intl";
|
8
|
-
import { useParams,
|
9
|
-
import { styled } from "styled-components";
|
9
|
+
import { useParams, useNavigate, Navigate, useMatch, useLocation, Link, NavLink } from "react-router-dom";
|
10
10
|
import * as yup from "yup";
|
11
11
|
import { ValidationError } from "yup";
|
12
12
|
import pipe from "lodash/fp/pipe";
|
13
13
|
import { intervalToDuration, isPast } from "date-fns";
|
14
|
+
import { styled } from "styled-components";
|
14
15
|
import { stringify } from "qs";
|
15
16
|
import { createSlice, combineReducers } from "@reduxjs/toolkit";
|
16
17
|
const __variableDynamicImportRuntimeHelper = (glob, path) => {
|
@@ -100,6 +101,7 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
100
101
|
if (!slug) {
|
101
102
|
throw new Error("Cannot find the slug param in the URL");
|
102
103
|
}
|
104
|
+
const [{ rawQuery }] = useQueryParams();
|
103
105
|
const userPermissions = useAuth("DocumentRBAC", (state) => state.permissions);
|
104
106
|
const contentTypePermissions = React.useMemo(() => {
|
105
107
|
const contentTypePermissions2 = userPermissions.filter(
|
@@ -110,7 +112,14 @@ const DocumentRBAC = ({ children, permissions }) => {
|
|
110
112
|
return { ...acc, [action]: [permission] };
|
111
113
|
}, {});
|
112
114
|
}, [slug, userPermissions]);
|
113
|
-
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
|
+
);
|
114
123
|
const canCreateFields = !isLoading && allowedActions.canCreate ? extractAndDedupeFields(contentTypePermissions.create) : [];
|
115
124
|
const canReadFields = !isLoading && allowedActions.canRead ? extractAndDedupeFields(contentTypePermissions.read) : [];
|
116
125
|
const canUpdateFields = !isLoading && allowedActions.canUpdate ? extractAndDedupeFields(contentTypePermissions.update) : [];
|
@@ -158,7 +167,8 @@ const contentManagerApi = adminApi.enhanceEndpoints({
|
|
158
167
|
"Document",
|
159
168
|
"InitialData",
|
160
169
|
"HistoryVersion",
|
161
|
-
"Relations"
|
170
|
+
"Relations",
|
171
|
+
"UidAvailability"
|
162
172
|
]
|
163
173
|
});
|
164
174
|
const documentApi = contentManagerApi.injectEndpoints({
|
@@ -188,7 +198,10 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
188
198
|
params
|
189
199
|
}
|
190
200
|
}),
|
191
|
-
invalidatesTags: (_result, _error, { model }) => [
|
201
|
+
invalidatesTags: (_result, _error, { model }) => [
|
202
|
+
{ type: "Document", id: `${model}_LIST` },
|
203
|
+
{ type: "UidAvailability", id: model }
|
204
|
+
]
|
192
205
|
}),
|
193
206
|
/**
|
194
207
|
* Creates a new collection-type document. This should ONLY be used for collection-types.
|
@@ -205,7 +218,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
205
218
|
}),
|
206
219
|
invalidatesTags: (result, _error, { model }) => [
|
207
220
|
{ type: "Document", id: `${model}_LIST` },
|
208
|
-
"Relations"
|
221
|
+
"Relations",
|
222
|
+
{ type: "UidAvailability", id: model }
|
209
223
|
]
|
210
224
|
}),
|
211
225
|
deleteDocument: builder.mutation({
|
@@ -246,7 +260,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
246
260
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
247
261
|
},
|
248
262
|
{ type: "Document", id: `${model}_LIST` },
|
249
|
-
"Relations"
|
263
|
+
"Relations",
|
264
|
+
{ type: "UidAvailability", id: model }
|
250
265
|
];
|
251
266
|
}
|
252
267
|
}),
|
@@ -371,7 +386,8 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|
371
386
|
type: "Document",
|
372
387
|
id: collectionType !== SINGLE_TYPES ? `${model}_${documentId}` : model
|
373
388
|
},
|
374
|
-
"Relations"
|
389
|
+
"Relations",
|
390
|
+
{ type: "UidAvailability", id: model }
|
375
391
|
];
|
376
392
|
},
|
377
393
|
async onQueryStarted({ data, ...patch }, { dispatch, queryFulfilled }) {
|
@@ -454,20 +470,39 @@ const buildValidParams = (query) => {
|
|
454
470
|
const isBaseQueryError = (error) => {
|
455
471
|
return error.name !== void 0;
|
456
472
|
};
|
457
|
-
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 }) => {
|
458
492
|
const createModelSchema = (attributes2) => yup.object().shape(
|
459
493
|
Object.entries(attributes2).reduce((acc, [name, attribute]) => {
|
460
494
|
if (DOCUMENT_META_FIELDS.includes(name)) {
|
461
495
|
return acc;
|
462
496
|
}
|
463
497
|
const validations = [
|
498
|
+
addNullableValidation,
|
464
499
|
addRequiredValidation,
|
465
500
|
addMinLengthValidation,
|
466
501
|
addMaxLengthValidation,
|
467
502
|
addMinValidation,
|
468
503
|
addMaxValidation,
|
469
504
|
addRegexValidation
|
470
|
-
].map((fn) => fn(attribute));
|
505
|
+
].map((fn) => fn(attribute, options));
|
471
506
|
const transformSchema = pipe(...validations);
|
472
507
|
switch (attribute.type) {
|
473
508
|
case "component": {
|
@@ -477,12 +512,12 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
477
512
|
...acc,
|
478
513
|
[name]: transformSchema(
|
479
514
|
yup.array().of(createModelSchema(attributes3).nullable(false))
|
480
|
-
)
|
515
|
+
).test(arrayValidator(attribute, options))
|
481
516
|
};
|
482
517
|
} else {
|
483
518
|
return {
|
484
519
|
...acc,
|
485
|
-
[name]: transformSchema(createModelSchema(attributes3))
|
520
|
+
[name]: transformSchema(createModelSchema(attributes3).nullable())
|
486
521
|
};
|
487
522
|
}
|
488
523
|
}
|
@@ -504,7 +539,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
504
539
|
}
|
505
540
|
)
|
506
541
|
)
|
507
|
-
)
|
542
|
+
).test(arrayValidator(attribute, options))
|
508
543
|
};
|
509
544
|
case "relation":
|
510
545
|
return {
|
@@ -516,7 +551,7 @@ const createYupSchema = (attributes = {}, components = {}) => {
|
|
516
551
|
} else if (Array.isArray(value)) {
|
517
552
|
return yup.array().of(
|
518
553
|
yup.object().shape({
|
519
|
-
id: yup.
|
554
|
+
id: yup.number().required()
|
520
555
|
})
|
521
556
|
);
|
522
557
|
} else if (typeof value === "object") {
|
@@ -594,13 +629,7 @@ const createAttributeSchema = (attribute) => {
|
|
594
629
|
return yup.mixed();
|
595
630
|
}
|
596
631
|
};
|
597
|
-
const
|
598
|
-
if ((attribute.type === "component" && attribute.repeatable || attribute.type === "dynamiczone") && attribute.required && "min" in schema) {
|
599
|
-
return schema.min(1, translatedErrors.required);
|
600
|
-
}
|
601
|
-
if (attribute.required && attribute.type !== "relation") {
|
602
|
-
return schema.required(translatedErrors.required);
|
603
|
-
}
|
632
|
+
const nullableSchema = (schema) => {
|
604
633
|
return schema?.nullable ? schema.nullable() : (
|
605
634
|
// In some cases '.nullable' will not be available on the schema.
|
606
635
|
// e.g. when the schema has been built using yup.lazy (e.g. for relations).
|
@@ -608,7 +637,22 @@ const addRequiredValidation = (attribute) => (schema) => {
|
|
608
637
|
schema
|
609
638
|
);
|
610
639
|
};
|
611
|
-
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
|
+
}
|
612
656
|
if ("minLength" in attribute && attribute.minLength && Number.isInteger(attribute.minLength) && "min" in schema) {
|
613
657
|
return schema.min(attribute.minLength, {
|
614
658
|
...translatedErrors.minLength,
|
@@ -630,32 +674,13 @@ const addMaxLengthValidation = (attribute) => (schema) => {
|
|
630
674
|
}
|
631
675
|
return schema;
|
632
676
|
};
|
633
|
-
const addMinValidation = (attribute) => (schema) => {
|
634
|
-
if ("
|
677
|
+
const addMinValidation = (attribute, options) => (schema) => {
|
678
|
+
if (options.status === "draft") {
|
679
|
+
return schema;
|
680
|
+
}
|
681
|
+
if ("min" in attribute && "min" in schema) {
|
635
682
|
const min = toInteger(attribute.min);
|
636
|
-
if (
|
637
|
-
if (!attribute.required && "test" in schema && min) {
|
638
|
-
return schema.test(
|
639
|
-
"custom-min",
|
640
|
-
{
|
641
|
-
...translatedErrors.min,
|
642
|
-
values: {
|
643
|
-
min: attribute.min
|
644
|
-
}
|
645
|
-
},
|
646
|
-
(value) => {
|
647
|
-
if (!value) {
|
648
|
-
return true;
|
649
|
-
}
|
650
|
-
if (Array.isArray(value) && value.length === 0) {
|
651
|
-
return true;
|
652
|
-
}
|
653
|
-
return value.length >= min;
|
654
|
-
}
|
655
|
-
);
|
656
|
-
}
|
657
|
-
}
|
658
|
-
if ("min" in schema && min) {
|
683
|
+
if (min) {
|
659
684
|
return schema.min(min, {
|
660
685
|
...translatedErrors.min,
|
661
686
|
values: {
|
@@ -773,19 +798,115 @@ const extractContentTypeComponents = (attributes = {}, allComponents = {}) => {
|
|
773
798
|
}, {});
|
774
799
|
return componentsByKey;
|
775
800
|
};
|
776
|
-
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);
|
777
900
|
const { toggleNotification } = useNotification();
|
778
901
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
902
|
+
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
779
903
|
const {
|
780
|
-
|
781
|
-
isLoading:
|
782
|
-
|
783
|
-
|
784
|
-
} =
|
785
|
-
|
786
|
-
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
787
|
-
});
|
788
|
-
const { components, schema, isLoading: isLoadingSchema } = useContentTypeSchema(args.model);
|
904
|
+
data,
|
905
|
+
isLoading: isLoadingConfigs,
|
906
|
+
error,
|
907
|
+
isFetching: isFetchingConfigs
|
908
|
+
} = useGetContentTypeConfigurationQuery(model);
|
909
|
+
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
789
910
|
React.useEffect(() => {
|
790
911
|
if (error) {
|
791
912
|
toggleNotification({
|
@@ -793,362 +914,440 @@ const useDocument = (args, opts) => {
|
|
793
914
|
message: formatAPIError(error)
|
794
915
|
});
|
795
916
|
}
|
796
|
-
}, [
|
797
|
-
const
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
(document) => {
|
805
|
-
if (!validationSchema) {
|
806
|
-
throw new Error(
|
807
|
-
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
808
|
-
);
|
809
|
-
}
|
810
|
-
try {
|
811
|
-
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
812
|
-
return null;
|
813
|
-
} catch (error2) {
|
814
|
-
if (error2 instanceof ValidationError) {
|
815
|
-
return getYupValidationErrors(error2);
|
816
|
-
}
|
817
|
-
throw error2;
|
818
|
-
}
|
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
|
819
925
|
},
|
820
|
-
[
|
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]
|
821
942
|
);
|
822
|
-
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
823
943
|
return {
|
824
|
-
|
825
|
-
document: data?.data,
|
826
|
-
meta: data?.meta,
|
944
|
+
error,
|
827
945
|
isLoading,
|
828
|
-
|
829
|
-
|
830
|
-
};
|
831
|
-
};
|
832
|
-
const useDoc = () => {
|
833
|
-
const { id, slug, collectionType, origin } = useParams();
|
834
|
-
const [{ query }] = useQueryParams();
|
835
|
-
const params = React.useMemo(() => buildValidParams(query), [query]);
|
836
|
-
if (!collectionType) {
|
837
|
-
throw new Error("Could not find collectionType in url params");
|
838
|
-
}
|
839
|
-
if (!slug) {
|
840
|
-
throw new Error("Could not find model in url params");
|
841
|
-
}
|
842
|
-
return {
|
843
|
-
collectionType,
|
844
|
-
model: slug,
|
845
|
-
id: origin || id === "create" ? void 0 : id,
|
846
|
-
...useDocument(
|
847
|
-
{ documentId: origin || id, model: slug, collectionType, params },
|
848
|
-
{
|
849
|
-
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
850
|
-
}
|
851
|
-
)
|
946
|
+
edit,
|
947
|
+
list: listLayout
|
852
948
|
};
|
853
949
|
};
|
854
|
-
const
|
855
|
-
|
856
|
-
|
857
|
-
}
|
858
|
-
return Object.keys(trad).reduce((acc, current) => {
|
859
|
-
acc[`${pluginId}.${current}`] = trad[current];
|
860
|
-
return acc;
|
861
|
-
}, {});
|
862
|
-
};
|
863
|
-
const getTranslation = (id) => `content-manager.${id}`;
|
864
|
-
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
865
|
-
id: "notification.error",
|
866
|
-
defaultMessage: "An error occurred, please try again"
|
950
|
+
const useDocLayout = () => {
|
951
|
+
const { model } = useDoc();
|
952
|
+
return useDocumentLayout(model);
|
867
953
|
};
|
868
|
-
const
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
const
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
message: formatAPIError(res.error)
|
888
|
-
});
|
889
|
-
return { error: res.error };
|
890
|
-
}
|
891
|
-
toggleNotification({
|
892
|
-
type: "success",
|
893
|
-
message: formatMessage({
|
894
|
-
id: getTranslation("success.record.delete"),
|
895
|
-
defaultMessage: "Deleted document"
|
896
|
-
})
|
897
|
-
});
|
898
|
-
trackUsage("didDeleteEntry", trackerProperty);
|
899
|
-
return res.data;
|
900
|
-
} catch (err) {
|
901
|
-
toggleNotification({
|
902
|
-
type: "danger",
|
903
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
904
|
-
});
|
905
|
-
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
906
|
-
throw err;
|
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([]);
|
907
973
|
}
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
const
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
});
|
926
|
-
return { error: res.error };
|
974
|
+
panels[currentPanelIndex].push(row);
|
975
|
+
}
|
976
|
+
return panels;
|
977
|
+
}, []);
|
978
|
+
const componentEditAttributes = Object.entries(data.components).reduce(
|
979
|
+
(acc, [uid, configuration]) => {
|
980
|
+
acc[uid] = {
|
981
|
+
layout: convertEditLayoutToFieldLayouts(
|
982
|
+
configuration.layouts.edit,
|
983
|
+
components[uid].attributes,
|
984
|
+
configuration.metadatas,
|
985
|
+
{ configurations: data.components, schemas: components }
|
986
|
+
),
|
987
|
+
settings: {
|
988
|
+
...configuration.settings,
|
989
|
+
icon: components[uid].info.icon,
|
990
|
+
displayName: components[uid].info.displayName
|
927
991
|
}
|
928
|
-
|
929
|
-
|
930
|
-
title: formatMessage({
|
931
|
-
id: getTranslation("success.records.delete"),
|
932
|
-
defaultMessage: "Successfully deleted."
|
933
|
-
}),
|
934
|
-
message: ""
|
935
|
-
});
|
936
|
-
trackUsage("didBulkDeleteEntries");
|
937
|
-
return res.data;
|
938
|
-
} catch (err) {
|
939
|
-
toggleNotification({
|
940
|
-
type: "danger",
|
941
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
942
|
-
});
|
943
|
-
trackUsage("didNotBulkDeleteEntries");
|
944
|
-
throw err;
|
945
|
-
}
|
992
|
+
};
|
993
|
+
return acc;
|
946
994
|
},
|
947
|
-
|
995
|
+
{}
|
948
996
|
);
|
949
|
-
const
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
model,
|
956
|
-
documentId,
|
957
|
-
params
|
958
|
-
});
|
959
|
-
if ("error" in res) {
|
960
|
-
toggleNotification({
|
961
|
-
type: "danger",
|
962
|
-
message: formatAPIError(res.error)
|
963
|
-
});
|
964
|
-
return { error: res.error };
|
965
|
-
}
|
966
|
-
toggleNotification({
|
967
|
-
type: "success",
|
968
|
-
message: formatMessage({
|
969
|
-
id: "content-manager.success.record.discard",
|
970
|
-
defaultMessage: "Changes discarded"
|
971
|
-
})
|
972
|
-
});
|
973
|
-
return res.data;
|
974
|
-
} catch (err) {
|
975
|
-
toggleNotification({
|
976
|
-
type: "danger",
|
977
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
978
|
-
});
|
979
|
-
throw err;
|
980
|
-
}
|
997
|
+
const editMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
998
|
+
(acc, [attribute, metadata]) => {
|
999
|
+
return {
|
1000
|
+
...acc,
|
1001
|
+
[attribute]: metadata.edit
|
1002
|
+
};
|
981
1003
|
},
|
982
|
-
|
1004
|
+
{}
|
983
1005
|
);
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
model,
|
992
|
-
documentId,
|
993
|
-
data,
|
994
|
-
params
|
995
|
-
});
|
996
|
-
if ("error" in res) {
|
997
|
-
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
998
|
-
return { error: res.error };
|
999
|
-
}
|
1000
|
-
trackUsage("didPublishEntry");
|
1001
|
-
toggleNotification({
|
1002
|
-
type: "success",
|
1003
|
-
message: formatMessage({
|
1004
|
-
id: getTranslation("success.record.publish"),
|
1005
|
-
defaultMessage: "Published document"
|
1006
|
-
})
|
1007
|
-
});
|
1008
|
-
return res.data;
|
1009
|
-
} catch (err) {
|
1010
|
-
toggleNotification({
|
1011
|
-
type: "danger",
|
1012
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1013
|
-
});
|
1014
|
-
throw err;
|
1015
|
-
}
|
1006
|
+
return {
|
1007
|
+
layout: panelledEditAttributes,
|
1008
|
+
components: componentEditAttributes,
|
1009
|
+
metadatas: editMetadatas,
|
1010
|
+
settings: {
|
1011
|
+
...data.contentType.settings,
|
1012
|
+
displayName: schema?.info.displayName
|
1016
1013
|
},
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
return { error: res.error };
|
1031
|
-
}
|
1032
|
-
toggleNotification({
|
1033
|
-
type: "success",
|
1034
|
-
message: formatMessage({
|
1035
|
-
id: getTranslation("success.record.publish"),
|
1036
|
-
defaultMessage: "Published document"
|
1037
|
-
})
|
1038
|
-
});
|
1039
|
-
return res.data;
|
1040
|
-
} catch (err) {
|
1041
|
-
toggleNotification({
|
1042
|
-
type: "danger",
|
1043
|
-
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1044
|
-
});
|
1045
|
-
throw err;
|
1014
|
+
options: {
|
1015
|
+
...schema?.options,
|
1016
|
+
...schema?.pluginOptions,
|
1017
|
+
...data.contentType.options
|
1018
|
+
}
|
1019
|
+
};
|
1020
|
+
};
|
1021
|
+
const convertEditLayoutToFieldLayouts = (rows, attributes = {}, metadatas, components, schemas = []) => {
|
1022
|
+
return rows.map(
|
1023
|
+
(row) => row.map((field) => {
|
1024
|
+
const attribute = attributes[field.name];
|
1025
|
+
if (!attribute) {
|
1026
|
+
return null;
|
1046
1027
|
}
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1028
|
+
const { edit: metadata } = metadatas[field.name];
|
1029
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1030
|
+
return {
|
1031
|
+
attribute,
|
1032
|
+
disabled: !metadata.editable,
|
1033
|
+
hint: metadata.description,
|
1034
|
+
label: metadata.label ?? "",
|
1035
|
+
name: field.name,
|
1036
|
+
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
1037
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1038
|
+
schemas,
|
1039
|
+
components: components?.schemas ?? {}
|
1040
|
+
}),
|
1041
|
+
placeholder: metadata.placeholder ?? "",
|
1042
|
+
required: attribute.required ?? false,
|
1043
|
+
size: field.size,
|
1044
|
+
unique: "unique" in attribute ? attribute.unique : false,
|
1045
|
+
visible: metadata.visible ?? true,
|
1046
|
+
type: attribute.type
|
1047
|
+
};
|
1048
|
+
}).filter((field) => field !== null)
|
1055
1049
|
);
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1050
|
+
};
|
1051
|
+
const formatListLayout = (data, {
|
1052
|
+
schemas,
|
1053
|
+
schema,
|
1054
|
+
components
|
1055
|
+
}) => {
|
1056
|
+
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
1057
|
+
(acc, [attribute, metadata]) => {
|
1058
|
+
return {
|
1059
|
+
...acc,
|
1060
|
+
[attribute]: metadata.list
|
1061
|
+
};
|
1062
|
+
},
|
1063
|
+
{}
|
1064
|
+
);
|
1065
|
+
const listAttributes = convertListLayoutToFieldLayouts(
|
1066
|
+
data.contentType.layouts.list,
|
1067
|
+
schema?.attributes,
|
1068
|
+
listMetadatas,
|
1069
|
+
{ configurations: data.components, schemas: components },
|
1070
|
+
schemas
|
1071
|
+
);
|
1072
|
+
return {
|
1073
|
+
layout: listAttributes,
|
1074
|
+
settings: { ...data.contentType.settings, displayName: schema?.info.displayName },
|
1075
|
+
metadatas: listMetadatas,
|
1076
|
+
options: {
|
1077
|
+
...schema?.options,
|
1078
|
+
...schema?.pluginOptions,
|
1079
|
+
...data.contentType.options
|
1080
|
+
}
|
1081
|
+
};
|
1082
|
+
};
|
1083
|
+
const convertListLayoutToFieldLayouts = (columns, attributes = {}, metadatas, components, schemas = []) => {
|
1084
|
+
return columns.map((name) => {
|
1085
|
+
const attribute = attributes[name];
|
1086
|
+
if (!attribute) {
|
1087
|
+
return null;
|
1088
|
+
}
|
1089
|
+
const metadata = metadatas[name];
|
1090
|
+
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
1091
|
+
return {
|
1092
|
+
attribute,
|
1093
|
+
label: metadata.label ?? "",
|
1094
|
+
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
1095
|
+
schemas,
|
1096
|
+
components: components?.schemas ?? {}
|
1097
|
+
}),
|
1098
|
+
name,
|
1099
|
+
searchable: metadata.searchable ?? true,
|
1100
|
+
sortable: metadata.sortable ?? true
|
1101
|
+
};
|
1102
|
+
}).filter((field) => field !== null);
|
1103
|
+
};
|
1104
|
+
const useDocument = (args, opts) => {
|
1105
|
+
const { toggleNotification } = useNotification();
|
1106
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1107
|
+
const {
|
1108
|
+
currentData: data,
|
1109
|
+
isLoading: isLoadingDocument,
|
1110
|
+
isFetching: isFetchingDocument,
|
1111
|
+
error
|
1112
|
+
} = useGetDocumentQuery(args, {
|
1113
|
+
...opts,
|
1114
|
+
skip: !args.documentId && args.collectionType !== SINGLE_TYPES || opts?.skip
|
1115
|
+
});
|
1116
|
+
const {
|
1117
|
+
components,
|
1118
|
+
schema,
|
1119
|
+
schemas,
|
1120
|
+
isLoading: isLoadingSchema
|
1121
|
+
} = useContentTypeSchema(args.model);
|
1122
|
+
React.useEffect(() => {
|
1123
|
+
if (error) {
|
1124
|
+
toggleNotification({
|
1125
|
+
type: "danger",
|
1126
|
+
message: formatAPIError(error)
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
}, [toggleNotification, error, formatAPIError, args.collectionType]);
|
1130
|
+
const validationSchema = React.useMemo(() => {
|
1131
|
+
if (!schema) {
|
1132
|
+
return null;
|
1133
|
+
}
|
1134
|
+
return createYupSchema(schema.attributes, components);
|
1135
|
+
}, [schema, components]);
|
1136
|
+
const validate = React.useCallback(
|
1137
|
+
(document) => {
|
1138
|
+
if (!validationSchema) {
|
1139
|
+
throw new Error(
|
1140
|
+
"There is no validation schema generated, this is likely due to the schema not being loaded yet."
|
1141
|
+
);
|
1142
|
+
}
|
1143
|
+
try {
|
1144
|
+
validationSchema.validateSync(document, { abortEarly: false, strict: true });
|
1145
|
+
return null;
|
1146
|
+
} catch (error2) {
|
1147
|
+
if (error2 instanceof ValidationError) {
|
1148
|
+
return getYupValidationErrors(error2);
|
1149
|
+
}
|
1150
|
+
throw error2;
|
1151
|
+
}
|
1152
|
+
},
|
1153
|
+
[validationSchema]
|
1154
|
+
);
|
1155
|
+
const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;
|
1156
|
+
const hasError = !!error;
|
1157
|
+
return {
|
1158
|
+
components,
|
1159
|
+
document: data?.data,
|
1160
|
+
meta: data?.meta,
|
1161
|
+
isLoading,
|
1162
|
+
hasError,
|
1163
|
+
schema,
|
1164
|
+
schemas,
|
1165
|
+
validate
|
1166
|
+
};
|
1167
|
+
};
|
1168
|
+
const useDoc = () => {
|
1169
|
+
const { id, slug, collectionType, origin } = useParams();
|
1170
|
+
const [{ query }] = useQueryParams();
|
1171
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1172
|
+
if (!collectionType) {
|
1173
|
+
throw new Error("Could not find collectionType in url params");
|
1174
|
+
}
|
1175
|
+
if (!slug) {
|
1176
|
+
throw new Error("Could not find model in url params");
|
1177
|
+
}
|
1178
|
+
const document = useDocument(
|
1179
|
+
{ documentId: origin || id, model: slug, collectionType, params },
|
1180
|
+
{
|
1181
|
+
skip: id === "create" || !origin && !id && collectionType !== SINGLE_TYPES
|
1182
|
+
}
|
1183
|
+
);
|
1184
|
+
const returnId = origin || id === "create" ? void 0 : id;
|
1185
|
+
return {
|
1186
|
+
collectionType,
|
1187
|
+
model: slug,
|
1188
|
+
id: returnId,
|
1189
|
+
...document
|
1190
|
+
};
|
1191
|
+
};
|
1192
|
+
const useContentManagerContext = () => {
|
1193
|
+
const {
|
1194
|
+
collectionType,
|
1195
|
+
model,
|
1196
|
+
id,
|
1197
|
+
components,
|
1198
|
+
isLoading: isLoadingDoc,
|
1199
|
+
schema,
|
1200
|
+
schemas
|
1201
|
+
} = useDoc();
|
1202
|
+
const layout = useDocumentLayout(model);
|
1203
|
+
const form = useForm("useContentManagerContext", (state) => state);
|
1204
|
+
const isSingleType = collectionType === SINGLE_TYPES;
|
1205
|
+
const slug = model;
|
1206
|
+
const isCreatingEntry = id === "create";
|
1207
|
+
useContentTypeSchema();
|
1208
|
+
const isLoading = isLoadingDoc || layout.isLoading;
|
1209
|
+
const error = layout.error;
|
1210
|
+
return {
|
1211
|
+
error,
|
1212
|
+
isLoading,
|
1213
|
+
// Base metadata
|
1214
|
+
model,
|
1215
|
+
collectionType,
|
1216
|
+
id,
|
1217
|
+
slug,
|
1218
|
+
isCreatingEntry,
|
1219
|
+
isSingleType,
|
1220
|
+
hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,
|
1221
|
+
// All schema infos
|
1222
|
+
components,
|
1223
|
+
contentType: schema,
|
1224
|
+
contentTypes: schemas,
|
1225
|
+
// Form state
|
1226
|
+
form,
|
1227
|
+
// layout infos
|
1228
|
+
layout
|
1229
|
+
};
|
1230
|
+
};
|
1231
|
+
const prefixPluginTranslations = (trad, pluginId) => {
|
1232
|
+
if (!pluginId) {
|
1233
|
+
throw new TypeError("pluginId can't be empty");
|
1234
|
+
}
|
1235
|
+
return Object.keys(trad).reduce((acc, current) => {
|
1236
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
1237
|
+
return acc;
|
1238
|
+
}, {});
|
1239
|
+
};
|
1240
|
+
const getTranslation = (id) => `content-manager.${id}`;
|
1241
|
+
const DEFAULT_UNEXPECTED_ERROR_MSG = {
|
1242
|
+
id: "notification.error",
|
1243
|
+
defaultMessage: "An error occurred, please try again"
|
1244
|
+
};
|
1245
|
+
const useDocumentActions = () => {
|
1246
|
+
const { toggleNotification } = useNotification();
|
1247
|
+
const { formatMessage } = useIntl();
|
1248
|
+
const { trackUsage } = useTracking();
|
1249
|
+
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
1250
|
+
const navigate = useNavigate();
|
1251
|
+
const setCurrentStep = useGuidedTour("useDocumentActions", (state) => state.setCurrentStep);
|
1252
|
+
const [deleteDocument] = useDeleteDocumentMutation();
|
1253
|
+
const _delete = React.useCallback(
|
1254
|
+
async ({ collectionType, model, documentId, params }, trackerProperty) => {
|
1255
|
+
try {
|
1256
|
+
trackUsage("willDeleteEntry", trackerProperty);
|
1257
|
+
const res = await deleteDocument({
|
1062
1258
|
collectionType,
|
1063
1259
|
model,
|
1064
1260
|
documentId,
|
1065
|
-
data,
|
1066
1261
|
params
|
1067
1262
|
});
|
1068
1263
|
if ("error" in res) {
|
1069
|
-
toggleNotification({
|
1070
|
-
|
1264
|
+
toggleNotification({
|
1265
|
+
type: "danger",
|
1266
|
+
message: formatAPIError(res.error)
|
1267
|
+
});
|
1071
1268
|
return { error: res.error };
|
1072
1269
|
}
|
1073
|
-
trackUsage("didEditEntry", trackerProperty);
|
1074
1270
|
toggleNotification({
|
1075
1271
|
type: "success",
|
1076
1272
|
message: formatMessage({
|
1077
|
-
id: getTranslation("success.record.
|
1078
|
-
defaultMessage: "
|
1273
|
+
id: getTranslation("success.record.delete"),
|
1274
|
+
defaultMessage: "Deleted document"
|
1079
1275
|
})
|
1080
1276
|
});
|
1277
|
+
trackUsage("didDeleteEntry", trackerProperty);
|
1081
1278
|
return res.data;
|
1082
1279
|
} catch (err) {
|
1083
|
-
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1084
1280
|
toggleNotification({
|
1085
1281
|
type: "danger",
|
1086
1282
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1087
1283
|
});
|
1284
|
+
trackUsage("didNotDeleteEntry", { error: err, ...trackerProperty });
|
1088
1285
|
throw err;
|
1089
1286
|
}
|
1090
1287
|
},
|
1091
|
-
[trackUsage,
|
1288
|
+
[trackUsage, deleteDocument, toggleNotification, formatMessage, formatAPIError]
|
1092
1289
|
);
|
1093
|
-
const [
|
1094
|
-
const
|
1095
|
-
async ({
|
1290
|
+
const [deleteManyDocuments] = useDeleteManyDocumentsMutation();
|
1291
|
+
const deleteMany = React.useCallback(
|
1292
|
+
async ({ model, documentIds, params }) => {
|
1096
1293
|
try {
|
1097
|
-
trackUsage("
|
1098
|
-
const res = await
|
1099
|
-
collectionType,
|
1294
|
+
trackUsage("willBulkDeleteEntries");
|
1295
|
+
const res = await deleteManyDocuments({
|
1100
1296
|
model,
|
1101
|
-
|
1102
|
-
params
|
1103
|
-
data: {
|
1104
|
-
discardDraft
|
1105
|
-
}
|
1297
|
+
documentIds,
|
1298
|
+
params
|
1106
1299
|
});
|
1107
1300
|
if ("error" in res) {
|
1108
|
-
toggleNotification({
|
1301
|
+
toggleNotification({
|
1302
|
+
type: "danger",
|
1303
|
+
message: formatAPIError(res.error)
|
1304
|
+
});
|
1109
1305
|
return { error: res.error };
|
1110
1306
|
}
|
1111
|
-
trackUsage("didUnpublishEntry");
|
1112
1307
|
toggleNotification({
|
1113
1308
|
type: "success",
|
1114
|
-
|
1115
|
-
id: getTranslation("success.
|
1116
|
-
defaultMessage: "
|
1117
|
-
})
|
1309
|
+
title: formatMessage({
|
1310
|
+
id: getTranslation("success.records.delete"),
|
1311
|
+
defaultMessage: "Successfully deleted."
|
1312
|
+
}),
|
1313
|
+
message: ""
|
1118
1314
|
});
|
1315
|
+
trackUsage("didBulkDeleteEntries");
|
1119
1316
|
return res.data;
|
1120
1317
|
} catch (err) {
|
1121
1318
|
toggleNotification({
|
1122
1319
|
type: "danger",
|
1123
1320
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1124
1321
|
});
|
1322
|
+
trackUsage("didNotBulkDeleteEntries");
|
1125
1323
|
throw err;
|
1126
1324
|
}
|
1127
1325
|
},
|
1128
|
-
[trackUsage,
|
1326
|
+
[trackUsage, deleteManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1129
1327
|
);
|
1130
|
-
const [
|
1131
|
-
const
|
1132
|
-
async ({ model,
|
1328
|
+
const [discardDocument] = useDiscardDocumentMutation();
|
1329
|
+
const discard = React.useCallback(
|
1330
|
+
async ({ collectionType, model, documentId, params }) => {
|
1133
1331
|
try {
|
1134
|
-
|
1135
|
-
|
1332
|
+
const res = await discardDocument({
|
1333
|
+
collectionType,
|
1136
1334
|
model,
|
1137
|
-
|
1335
|
+
documentId,
|
1138
1336
|
params
|
1139
1337
|
});
|
1140
1338
|
if ("error" in res) {
|
1141
|
-
toggleNotification({
|
1339
|
+
toggleNotification({
|
1340
|
+
type: "danger",
|
1341
|
+
message: formatAPIError(res.error)
|
1342
|
+
});
|
1142
1343
|
return { error: res.error };
|
1143
1344
|
}
|
1144
|
-
trackUsage("didBulkUnpublishEntries");
|
1145
1345
|
toggleNotification({
|
1146
1346
|
type: "success",
|
1147
|
-
|
1148
|
-
id:
|
1149
|
-
defaultMessage: "
|
1150
|
-
})
|
1151
|
-
message: ""
|
1347
|
+
message: formatMessage({
|
1348
|
+
id: "content-manager.success.record.discard",
|
1349
|
+
defaultMessage: "Changes discarded"
|
1350
|
+
})
|
1152
1351
|
});
|
1153
1352
|
return res.data;
|
1154
1353
|
} catch (err) {
|
@@ -1156,13 +1355,193 @@ const useDocumentActions = () => {
|
|
1156
1355
|
type: "danger",
|
1157
1356
|
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1158
1357
|
});
|
1159
|
-
trackUsage("didNotBulkUnpublishEntries");
|
1160
1358
|
throw err;
|
1161
1359
|
}
|
1162
1360
|
},
|
1163
|
-
[
|
1361
|
+
[discardDocument, formatAPIError, formatMessage, toggleNotification]
|
1164
1362
|
);
|
1165
|
-
const [
|
1363
|
+
const [publishDocument] = usePublishDocumentMutation();
|
1364
|
+
const publish = React.useCallback(
|
1365
|
+
async ({ collectionType, model, documentId, params }, data) => {
|
1366
|
+
try {
|
1367
|
+
trackUsage("willPublishEntry");
|
1368
|
+
const res = await publishDocument({
|
1369
|
+
collectionType,
|
1370
|
+
model,
|
1371
|
+
documentId,
|
1372
|
+
data,
|
1373
|
+
params
|
1374
|
+
});
|
1375
|
+
if ("error" in res) {
|
1376
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1377
|
+
return { error: res.error };
|
1378
|
+
}
|
1379
|
+
trackUsage("didPublishEntry");
|
1380
|
+
toggleNotification({
|
1381
|
+
type: "success",
|
1382
|
+
message: formatMessage({
|
1383
|
+
id: getTranslation("success.record.publish"),
|
1384
|
+
defaultMessage: "Published document"
|
1385
|
+
})
|
1386
|
+
});
|
1387
|
+
return res.data;
|
1388
|
+
} catch (err) {
|
1389
|
+
toggleNotification({
|
1390
|
+
type: "danger",
|
1391
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1392
|
+
});
|
1393
|
+
throw err;
|
1394
|
+
}
|
1395
|
+
},
|
1396
|
+
[trackUsage, publishDocument, toggleNotification, formatMessage, formatAPIError]
|
1397
|
+
);
|
1398
|
+
const [publishManyDocuments] = usePublishManyDocumentsMutation();
|
1399
|
+
const publishMany = React.useCallback(
|
1400
|
+
async ({ model, documentIds, params }) => {
|
1401
|
+
try {
|
1402
|
+
const res = await publishManyDocuments({
|
1403
|
+
model,
|
1404
|
+
documentIds,
|
1405
|
+
params
|
1406
|
+
});
|
1407
|
+
if ("error" in res) {
|
1408
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1409
|
+
return { error: res.error };
|
1410
|
+
}
|
1411
|
+
toggleNotification({
|
1412
|
+
type: "success",
|
1413
|
+
message: formatMessage({
|
1414
|
+
id: getTranslation("success.record.publish"),
|
1415
|
+
defaultMessage: "Published document"
|
1416
|
+
})
|
1417
|
+
});
|
1418
|
+
return res.data;
|
1419
|
+
} catch (err) {
|
1420
|
+
toggleNotification({
|
1421
|
+
type: "danger",
|
1422
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1423
|
+
});
|
1424
|
+
throw err;
|
1425
|
+
}
|
1426
|
+
},
|
1427
|
+
[
|
1428
|
+
// trackUsage,
|
1429
|
+
publishManyDocuments,
|
1430
|
+
toggleNotification,
|
1431
|
+
formatMessage,
|
1432
|
+
formatAPIError
|
1433
|
+
]
|
1434
|
+
);
|
1435
|
+
const [updateDocument] = useUpdateDocumentMutation();
|
1436
|
+
const update = React.useCallback(
|
1437
|
+
async ({ collectionType, model, documentId, params }, data, trackerProperty) => {
|
1438
|
+
try {
|
1439
|
+
trackUsage("willEditEntry", trackerProperty);
|
1440
|
+
const res = await updateDocument({
|
1441
|
+
collectionType,
|
1442
|
+
model,
|
1443
|
+
documentId,
|
1444
|
+
data,
|
1445
|
+
params
|
1446
|
+
});
|
1447
|
+
if ("error" in res) {
|
1448
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1449
|
+
trackUsage("didNotEditEntry", { error: res.error, ...trackerProperty });
|
1450
|
+
return { error: res.error };
|
1451
|
+
}
|
1452
|
+
trackUsage("didEditEntry", trackerProperty);
|
1453
|
+
toggleNotification({
|
1454
|
+
type: "success",
|
1455
|
+
message: formatMessage({
|
1456
|
+
id: getTranslation("success.record.save"),
|
1457
|
+
defaultMessage: "Saved document"
|
1458
|
+
})
|
1459
|
+
});
|
1460
|
+
return res.data;
|
1461
|
+
} catch (err) {
|
1462
|
+
trackUsage("didNotEditEntry", { error: err, ...trackerProperty });
|
1463
|
+
toggleNotification({
|
1464
|
+
type: "danger",
|
1465
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1466
|
+
});
|
1467
|
+
throw err;
|
1468
|
+
}
|
1469
|
+
},
|
1470
|
+
[trackUsage, updateDocument, toggleNotification, formatMessage, formatAPIError]
|
1471
|
+
);
|
1472
|
+
const [unpublishDocument] = useUnpublishDocumentMutation();
|
1473
|
+
const unpublish = React.useCallback(
|
1474
|
+
async ({ collectionType, model, documentId, params }, discardDraft = false) => {
|
1475
|
+
try {
|
1476
|
+
trackUsage("willUnpublishEntry");
|
1477
|
+
const res = await unpublishDocument({
|
1478
|
+
collectionType,
|
1479
|
+
model,
|
1480
|
+
documentId,
|
1481
|
+
params,
|
1482
|
+
data: {
|
1483
|
+
discardDraft
|
1484
|
+
}
|
1485
|
+
});
|
1486
|
+
if ("error" in res) {
|
1487
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1488
|
+
return { error: res.error };
|
1489
|
+
}
|
1490
|
+
trackUsage("didUnpublishEntry");
|
1491
|
+
toggleNotification({
|
1492
|
+
type: "success",
|
1493
|
+
message: formatMessage({
|
1494
|
+
id: getTranslation("success.record.unpublish"),
|
1495
|
+
defaultMessage: "Unpublished document"
|
1496
|
+
})
|
1497
|
+
});
|
1498
|
+
return res.data;
|
1499
|
+
} catch (err) {
|
1500
|
+
toggleNotification({
|
1501
|
+
type: "danger",
|
1502
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1503
|
+
});
|
1504
|
+
throw err;
|
1505
|
+
}
|
1506
|
+
},
|
1507
|
+
[trackUsage, unpublishDocument, toggleNotification, formatMessage, formatAPIError]
|
1508
|
+
);
|
1509
|
+
const [unpublishManyDocuments] = useUnpublishManyDocumentsMutation();
|
1510
|
+
const unpublishMany = React.useCallback(
|
1511
|
+
async ({ model, documentIds, params }) => {
|
1512
|
+
try {
|
1513
|
+
trackUsage("willBulkUnpublishEntries");
|
1514
|
+
const res = await unpublishManyDocuments({
|
1515
|
+
model,
|
1516
|
+
documentIds,
|
1517
|
+
params
|
1518
|
+
});
|
1519
|
+
if ("error" in res) {
|
1520
|
+
toggleNotification({ type: "danger", message: formatAPIError(res.error) });
|
1521
|
+
return { error: res.error };
|
1522
|
+
}
|
1523
|
+
trackUsage("didBulkUnpublishEntries");
|
1524
|
+
toggleNotification({
|
1525
|
+
type: "success",
|
1526
|
+
title: formatMessage({
|
1527
|
+
id: getTranslation("success.records.unpublish"),
|
1528
|
+
defaultMessage: "Successfully unpublished."
|
1529
|
+
}),
|
1530
|
+
message: ""
|
1531
|
+
});
|
1532
|
+
return res.data;
|
1533
|
+
} catch (err) {
|
1534
|
+
toggleNotification({
|
1535
|
+
type: "danger",
|
1536
|
+
message: formatMessage(DEFAULT_UNEXPECTED_ERROR_MSG)
|
1537
|
+
});
|
1538
|
+
trackUsage("didNotBulkUnpublishEntries");
|
1539
|
+
throw err;
|
1540
|
+
}
|
1541
|
+
},
|
1542
|
+
[trackUsage, unpublishManyDocuments, toggleNotification, formatMessage, formatAPIError]
|
1543
|
+
);
|
1544
|
+
const [createDocument] = useCreateDocumentMutation();
|
1166
1545
|
const create = React.useCallback(
|
1167
1546
|
async ({ model, params }, data, trackerProperty) => {
|
1168
1547
|
try {
|
@@ -1184,6 +1563,7 @@ const useDocumentActions = () => {
|
|
1184
1563
|
defaultMessage: "Saved document"
|
1185
1564
|
})
|
1186
1565
|
});
|
1566
|
+
setCurrentStep("contentManager.success");
|
1187
1567
|
return res.data;
|
1188
1568
|
} catch (err) {
|
1189
1569
|
toggleNotification({
|
@@ -1223,7 +1603,7 @@ const useDocumentActions = () => {
|
|
1223
1603
|
throw err;
|
1224
1604
|
}
|
1225
1605
|
},
|
1226
|
-
[autoCloneDocument,
|
1606
|
+
[autoCloneDocument, formatMessage, toggleNotification]
|
1227
1607
|
);
|
1228
1608
|
const [cloneDocument] = useCloneDocumentMutation();
|
1229
1609
|
const clone = React.useCallback(
|
@@ -1249,6 +1629,7 @@ const useDocumentActions = () => {
|
|
1249
1629
|
defaultMessage: "Cloned document"
|
1250
1630
|
})
|
1251
1631
|
});
|
1632
|
+
navigate(`../../${res.data.data.documentId}`, { relative: "path" });
|
1252
1633
|
return res.data;
|
1253
1634
|
} catch (err) {
|
1254
1635
|
toggleNotification({
|
@@ -1259,7 +1640,7 @@ const useDocumentActions = () => {
|
|
1259
1640
|
throw err;
|
1260
1641
|
}
|
1261
1642
|
},
|
1262
|
-
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError]
|
1643
|
+
[cloneDocument, trackUsage, toggleNotification, formatMessage, formatAPIError, navigate]
|
1263
1644
|
);
|
1264
1645
|
const [getDoc] = useLazyGetDocumentQuery();
|
1265
1646
|
const getDocument = React.useCallback(
|
@@ -1285,7 +1666,7 @@ const useDocumentActions = () => {
|
|
1285
1666
|
};
|
1286
1667
|
};
|
1287
1668
|
const ProtectedHistoryPage = lazy(
|
1288
|
-
() => import("./History-
|
1669
|
+
() => import("./History-BpLIu67W.mjs").then((mod) => ({ default: mod.ProtectedHistoryPage }))
|
1289
1670
|
);
|
1290
1671
|
const routes$1 = [
|
1291
1672
|
{
|
@@ -1298,31 +1679,31 @@ const routes$1 = [
|
|
1298
1679
|
}
|
1299
1680
|
];
|
1300
1681
|
const ProtectedEditViewPage = lazy(
|
1301
|
-
() => import("./EditViewPage-
|
1682
|
+
() => import("./EditViewPage-al5OO1NR.mjs").then((mod) => ({ default: mod.ProtectedEditViewPage }))
|
1302
1683
|
);
|
1303
1684
|
const ProtectedListViewPage = lazy(
|
1304
|
-
() => import("./ListViewPage-
|
1685
|
+
() => import("./ListViewPage-BbXYNI0v.mjs").then((mod) => ({ default: mod.ProtectedListViewPage }))
|
1305
1686
|
);
|
1306
1687
|
const ProtectedListConfiguration = lazy(
|
1307
|
-
() => import("./ListConfigurationPage-
|
1688
|
+
() => import("./ListConfigurationPage-DOqj5f8Y.mjs").then((mod) => ({
|
1308
1689
|
default: mod.ProtectedListConfiguration
|
1309
1690
|
}))
|
1310
1691
|
);
|
1311
1692
|
const ProtectedEditConfigurationPage = lazy(
|
1312
|
-
() => import("./EditConfigurationPage-
|
1693
|
+
() => import("./EditConfigurationPage-W07CEdm2.mjs").then((mod) => ({
|
1313
1694
|
default: mod.ProtectedEditConfigurationPage
|
1314
1695
|
}))
|
1315
1696
|
);
|
1316
1697
|
const ProtectedComponentConfigurationPage = lazy(
|
1317
|
-
() => import("./ComponentConfigurationPage-
|
1698
|
+
() => import("./ComponentConfigurationPage-jmWwucg_.mjs").then((mod) => ({
|
1318
1699
|
default: mod.ProtectedComponentConfigurationPage
|
1319
1700
|
}))
|
1320
1701
|
);
|
1321
1702
|
const NoPermissions = lazy(
|
1322
|
-
() => import("./NoPermissionsPage-
|
1703
|
+
() => import("./NoPermissionsPage-Km0Vk5Wp.mjs").then((mod) => ({ default: mod.NoPermissions }))
|
1323
1704
|
);
|
1324
1705
|
const NoContentType = lazy(
|
1325
|
-
() => import("./NoContentTypePage-
|
1706
|
+
() => import("./NoContentTypePage-w2Q0VVOT.mjs").then((mod) => ({ default: mod.NoContentType }))
|
1326
1707
|
);
|
1327
1708
|
const CollectionTypePages = () => {
|
1328
1709
|
const { collectionType } = useParams();
|
@@ -1382,1065 +1763,743 @@ const DocumentActions = ({ actions: actions2 }) => {
|
|
1382
1763
|
if (!primaryAction) {
|
1383
1764
|
return null;
|
1384
1765
|
}
|
1385
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
|
1386
|
-
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
1387
|
-
/* @__PURE__ */ jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
|
1388
|
-
restActions.length > 0 ? /* @__PURE__ */ jsx(
|
1389
|
-
DocumentActionsMenu,
|
1390
|
-
{
|
1391
|
-
actions: restActions,
|
1392
|
-
label: formatMessage({
|
1393
|
-
id: "content-manager.containers.edit.panels.default.more-actions",
|
1394
|
-
defaultMessage: "More document actions"
|
1395
|
-
})
|
1396
|
-
}
|
1397
|
-
) : null
|
1398
|
-
] }),
|
1399
|
-
secondaryAction ? /* @__PURE__ */ jsx(
|
1400
|
-
DocumentActionButton,
|
1401
|
-
{
|
1402
|
-
...secondaryAction,
|
1403
|
-
variant: secondaryAction.variant || "secondary"
|
1404
|
-
}
|
1405
|
-
) : null
|
1406
|
-
] });
|
1407
|
-
};
|
1408
|
-
const DocumentActionButton = (action) => {
|
1409
|
-
const [dialogId, setDialogId] = React.useState(null);
|
1410
|
-
const { toggleNotification } = useNotification();
|
1411
|
-
const handleClick = (action2) => async (e) => {
|
1412
|
-
const { onClick = () => false, dialog, id } = action2;
|
1413
|
-
const muteDialog = await onClick(e);
|
1414
|
-
if (dialog && !muteDialog) {
|
1415
|
-
switch (dialog.type) {
|
1416
|
-
case "notification":
|
1417
|
-
toggleNotification({
|
1418
|
-
title: dialog.title,
|
1419
|
-
message: dialog.content,
|
1420
|
-
type: dialog.status,
|
1421
|
-
timeout: dialog.timeout,
|
1422
|
-
onClose: dialog.onClose
|
1423
|
-
});
|
1424
|
-
break;
|
1425
|
-
case "dialog":
|
1426
|
-
case "modal":
|
1427
|
-
e.preventDefault();
|
1428
|
-
setDialogId(id);
|
1429
|
-
}
|
1430
|
-
}
|
1431
|
-
};
|
1432
|
-
const handleClose = () => {
|
1433
|
-
setDialogId(null);
|
1434
|
-
};
|
1435
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
1436
|
-
/* @__PURE__ */ jsx(
|
1437
|
-
Button,
|
1438
|
-
{
|
1439
|
-
flex: "auto",
|
1440
|
-
startIcon: action.icon,
|
1441
|
-
disabled: action.disabled,
|
1442
|
-
onClick: handleClick(action),
|
1443
|
-
justifyContent: "center",
|
1444
|
-
variant: action.variant || "default",
|
1445
|
-
paddingTop: "7px",
|
1446
|
-
paddingBottom: "7px",
|
1447
|
-
children: action.label
|
1448
|
-
}
|
1449
|
-
),
|
1450
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
|
1451
|
-
DocumentActionConfirmDialog,
|
1452
|
-
{
|
1453
|
-
...action.dialog,
|
1454
|
-
variant: action.dialog?.variant ?? action.variant,
|
1455
|
-
isOpen: dialogId === action.id,
|
1456
|
-
onClose: handleClose
|
1457
|
-
}
|
1458
|
-
) : null,
|
1459
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
|
1460
|
-
DocumentActionModal,
|
1461
|
-
{
|
1462
|
-
...action.dialog,
|
1463
|
-
onModalClose: handleClose,
|
1464
|
-
isOpen: dialogId === action.id
|
1465
|
-
}
|
1466
|
-
) : null
|
1467
|
-
] });
|
1468
|
-
};
|
1469
|
-
const DocumentActionsMenu = ({
|
1470
|
-
actions: actions2,
|
1471
|
-
children,
|
1472
|
-
label,
|
1473
|
-
variant = "tertiary"
|
1474
|
-
}) => {
|
1475
|
-
const [isOpen, setIsOpen] = React.useState(false);
|
1476
|
-
const [dialogId, setDialogId] = React.useState(null);
|
1477
|
-
const { formatMessage } = useIntl();
|
1478
|
-
const { toggleNotification } = useNotification();
|
1479
|
-
const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
|
1480
|
-
const handleClick = (action) => async (e) => {
|
1481
|
-
const { onClick = () => false, dialog, id } = action;
|
1482
|
-
const muteDialog = await onClick(e);
|
1483
|
-
if (dialog && !muteDialog) {
|
1484
|
-
switch (dialog.type) {
|
1485
|
-
case "notification":
|
1486
|
-
toggleNotification({
|
1487
|
-
title: dialog.title,
|
1488
|
-
message: dialog.content,
|
1489
|
-
type: dialog.status,
|
1490
|
-
timeout: dialog.timeout,
|
1491
|
-
onClose: dialog.onClose
|
1492
|
-
});
|
1493
|
-
break;
|
1494
|
-
case "dialog":
|
1495
|
-
case "modal":
|
1496
|
-
setDialogId(id);
|
1497
|
-
}
|
1498
|
-
}
|
1499
|
-
};
|
1500
|
-
const handleClose = () => {
|
1501
|
-
setDialogId(null);
|
1502
|
-
setIsOpen(false);
|
1503
|
-
};
|
1504
|
-
return /* @__PURE__ */ jsxs(Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
|
1505
|
-
/* @__PURE__ */ jsxs(
|
1506
|
-
StyledMoreButton,
|
1507
|
-
{
|
1508
|
-
disabled: isDisabled,
|
1509
|
-
size: "S",
|
1510
|
-
endIcon: null,
|
1511
|
-
paddingTop: "4px",
|
1512
|
-
paddingLeft: "7px",
|
1513
|
-
paddingRight: "7px",
|
1514
|
-
variant,
|
1515
|
-
children: [
|
1516
|
-
/* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
|
1517
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: label || formatMessage({
|
1518
|
-
id: "content-manager.containers.edit.panels.default.more-actions",
|
1519
|
-
defaultMessage: "More document actions"
|
1520
|
-
}) })
|
1521
|
-
]
|
1522
|
-
}
|
1523
|
-
),
|
1524
|
-
/* @__PURE__ */ jsxs(Menu.Content, { top: "4px", maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1525
|
-
actions2.map((action) => {
|
1526
|
-
return /* @__PURE__ */ jsx(
|
1527
|
-
Menu.Item,
|
1528
|
-
{
|
1529
|
-
disabled: action.disabled,
|
1530
|
-
onSelect: handleClick(action),
|
1531
|
-
display: "block",
|
1532
|
-
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
|
1533
|
-
/* @__PURE__ */ jsxs(
|
1534
|
-
Flex,
|
1535
|
-
{
|
1536
|
-
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1537
|
-
gap: 2,
|
1538
|
-
tag: "span",
|
1539
|
-
children: [
|
1540
|
-
/* @__PURE__ */ jsx(
|
1541
|
-
Flex,
|
1542
|
-
{
|
1543
|
-
tag: "span",
|
1544
|
-
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1545
|
-
children: action.icon
|
1546
|
-
}
|
1547
|
-
),
|
1548
|
-
action.label
|
1549
|
-
]
|
1550
|
-
}
|
1551
|
-
),
|
1552
|
-
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
|
1553
|
-
Flex,
|
1554
|
-
{
|
1555
|
-
alignItems: "center",
|
1556
|
-
background: "alternative100",
|
1557
|
-
borderStyle: "solid",
|
1558
|
-
borderColor: "alternative200",
|
1559
|
-
borderWidth: "1px",
|
1560
|
-
height: 5,
|
1561
|
-
paddingLeft: 2,
|
1562
|
-
paddingRight: 2,
|
1563
|
-
hasRadius: true,
|
1564
|
-
color: "alternative600",
|
1565
|
-
children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
|
1566
|
-
}
|
1567
|
-
)
|
1568
|
-
] })
|
1569
|
-
},
|
1570
|
-
action.id
|
1571
|
-
);
|
1572
|
-
}),
|
1573
|
-
children
|
1574
|
-
] }),
|
1575
|
-
actions2.map((action) => {
|
1576
|
-
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
1577
|
-
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
|
1578
|
-
DocumentActionConfirmDialog,
|
1579
|
-
{
|
1580
|
-
...action.dialog,
|
1581
|
-
variant: action.variant,
|
1582
|
-
isOpen: dialogId === action.id,
|
1583
|
-
onClose: handleClose
|
1584
|
-
}
|
1585
|
-
) : null,
|
1586
|
-
action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
|
1587
|
-
DocumentActionModal,
|
1588
|
-
{
|
1589
|
-
...action.dialog,
|
1590
|
-
onModalClose: handleClose,
|
1591
|
-
isOpen: dialogId === action.id
|
1592
|
-
}
|
1593
|
-
) : null
|
1594
|
-
] }, action.id);
|
1595
|
-
})
|
1596
|
-
] });
|
1597
|
-
};
|
1598
|
-
const convertActionVariantToColor = (variant = "secondary") => {
|
1599
|
-
switch (variant) {
|
1600
|
-
case "danger":
|
1601
|
-
return "danger600";
|
1602
|
-
case "secondary":
|
1603
|
-
return void 0;
|
1604
|
-
case "success":
|
1605
|
-
return "success600";
|
1606
|
-
default:
|
1607
|
-
return "primary600";
|
1608
|
-
}
|
1609
|
-
};
|
1610
|
-
const convertActionVariantToIconColor = (variant = "secondary") => {
|
1611
|
-
switch (variant) {
|
1612
|
-
case "danger":
|
1613
|
-
return "danger600";
|
1614
|
-
case "secondary":
|
1615
|
-
return "neutral500";
|
1616
|
-
case "success":
|
1617
|
-
return "success600";
|
1618
|
-
default:
|
1619
|
-
return "primary600";
|
1620
|
-
}
|
1621
|
-
};
|
1622
|
-
const StyledMoreButton = styled(Menu.Trigger)`
|
1623
|
-
& > span {
|
1624
|
-
display: flex;
|
1625
|
-
}
|
1626
|
-
`;
|
1627
|
-
const DocumentActionConfirmDialog = ({
|
1628
|
-
onClose,
|
1629
|
-
onCancel,
|
1630
|
-
onConfirm,
|
1631
|
-
title,
|
1632
|
-
content,
|
1633
|
-
isOpen,
|
1634
|
-
variant = "secondary"
|
1635
|
-
}) => {
|
1636
|
-
const { formatMessage } = useIntl();
|
1637
|
-
const handleClose = async () => {
|
1638
|
-
if (onCancel) {
|
1639
|
-
await onCancel();
|
1640
|
-
}
|
1641
|
-
onClose();
|
1642
|
-
};
|
1643
|
-
const handleConfirm = async () => {
|
1644
|
-
if (onConfirm) {
|
1645
|
-
await onConfirm();
|
1646
|
-
}
|
1647
|
-
onClose();
|
1648
|
-
};
|
1649
|
-
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
1650
|
-
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
1651
|
-
/* @__PURE__ */ jsx(Dialog.Body, { children: content }),
|
1652
|
-
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
1653
|
-
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: formatMessage({
|
1654
|
-
id: "app.components.Button.cancel",
|
1655
|
-
defaultMessage: "Cancel"
|
1656
|
-
}) }) }),
|
1657
|
-
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, children: formatMessage({
|
1658
|
-
id: "app.components.Button.confirm",
|
1659
|
-
defaultMessage: "Confirm"
|
1660
|
-
}) })
|
1661
|
-
] })
|
1662
|
-
] }) });
|
1663
|
-
};
|
1664
|
-
const DocumentActionModal = ({
|
1665
|
-
isOpen,
|
1666
|
-
title,
|
1667
|
-
onClose,
|
1668
|
-
footer: Footer,
|
1669
|
-
content: Content,
|
1670
|
-
onModalClose
|
1671
|
-
}) => {
|
1672
|
-
const handleClose = () => {
|
1673
|
-
if (onClose) {
|
1674
|
-
onClose();
|
1675
|
-
}
|
1676
|
-
onModalClose();
|
1677
|
-
};
|
1678
|
-
return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
1679
|
-
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
|
1680
|
-
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
|
1681
|
-
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
1682
|
-
] }) });
|
1683
|
-
};
|
1684
|
-
const PublishAction$1 = ({
|
1685
|
-
activeTab,
|
1686
|
-
documentId,
|
1687
|
-
model,
|
1688
|
-
collectionType,
|
1689
|
-
meta,
|
1690
|
-
document
|
1691
|
-
}) => {
|
1692
|
-
const { schema } = useDoc();
|
1693
|
-
const navigate = useNavigate();
|
1694
|
-
const { toggleNotification } = useNotification();
|
1695
|
-
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
1696
|
-
const isCloning = useMatch(CLONE_PATH) !== null;
|
1697
|
-
const { formatMessage } = useIntl();
|
1698
|
-
const { canPublish, canCreate, canUpdate } = useDocumentRBAC(
|
1699
|
-
"PublishAction",
|
1700
|
-
({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 }) => ({ canPublish: canPublish2, canCreate: canCreate2, canUpdate: canUpdate2 })
|
1701
|
-
);
|
1702
|
-
const { publish } = useDocumentActions();
|
1703
|
-
const [
|
1704
|
-
countDraftRelations,
|
1705
|
-
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
1706
|
-
] = useLazyGetDraftRelationCountQuery();
|
1707
|
-
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
|
1708
|
-
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
|
1709
|
-
const [{ query, rawQuery }] = useQueryParams();
|
1710
|
-
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1711
|
-
const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
1712
|
-
const setSubmitting = useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
1713
|
-
const isSubmitting = useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
1714
|
-
const validate = useForm("PublishAction", (state) => state.validate);
|
1715
|
-
const setErrors = useForm("PublishAction", (state) => state.setErrors);
|
1716
|
-
const formValues = useForm("PublishAction", ({ values }) => values);
|
1717
|
-
React.useEffect(() => {
|
1718
|
-
if (isErrorDraftRelations) {
|
1719
|
-
toggleNotification({
|
1720
|
-
type: "danger",
|
1721
|
-
message: formatMessage({
|
1722
|
-
id: getTranslation("error.records.fetch-draft-relatons"),
|
1723
|
-
defaultMessage: "An error occurred while fetching draft relations on this document."
|
1724
|
-
})
|
1725
|
-
});
|
1726
|
-
}
|
1727
|
-
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
1728
|
-
React.useEffect(() => {
|
1729
|
-
const localDraftRelations = /* @__PURE__ */ new Set();
|
1730
|
-
const extractDraftRelations = (data) => {
|
1731
|
-
const relations = data.connect || [];
|
1732
|
-
relations.forEach((relation) => {
|
1733
|
-
if (relation.status === "draft") {
|
1734
|
-
localDraftRelations.add(relation.id);
|
1735
|
-
}
|
1736
|
-
});
|
1737
|
-
};
|
1738
|
-
const traverseAndExtract = (data) => {
|
1739
|
-
Object.entries(data).forEach(([key, value]) => {
|
1740
|
-
if (key === "connect" && Array.isArray(value)) {
|
1741
|
-
extractDraftRelations({ connect: value });
|
1742
|
-
} else if (typeof value === "object" && value !== null) {
|
1743
|
-
traverseAndExtract(value);
|
1744
|
-
}
|
1745
|
-
});
|
1746
|
-
};
|
1747
|
-
if (!documentId || modified) {
|
1748
|
-
traverseAndExtract(formValues);
|
1749
|
-
setLocalCountOfDraftRelations(localDraftRelations.size);
|
1750
|
-
}
|
1751
|
-
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
1752
|
-
React.useEffect(() => {
|
1753
|
-
if (documentId) {
|
1754
|
-
const fetchDraftRelationsCount = async () => {
|
1755
|
-
const { data, error } = await countDraftRelations({
|
1756
|
-
collectionType,
|
1757
|
-
model,
|
1758
|
-
documentId,
|
1759
|
-
params
|
1760
|
-
});
|
1761
|
-
if (error) {
|
1762
|
-
throw error;
|
1763
|
-
}
|
1764
|
-
if (data) {
|
1765
|
-
setServerCountOfDraftRelations(data.data);
|
1766
|
-
}
|
1767
|
-
};
|
1768
|
-
fetchDraftRelationsCount();
|
1769
|
-
}
|
1770
|
-
}, [documentId, countDraftRelations, collectionType, model, params]);
|
1771
|
-
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
1772
|
-
if (!schema?.options?.draftAndPublish) {
|
1773
|
-
return null;
|
1774
|
-
}
|
1775
|
-
const performPublish = async () => {
|
1776
|
-
setSubmitting(true);
|
1777
|
-
try {
|
1778
|
-
const { errors } = await validate();
|
1779
|
-
if (errors) {
|
1780
|
-
toggleNotification({
|
1781
|
-
type: "danger",
|
1782
|
-
message: formatMessage({
|
1783
|
-
id: "content-manager.validation.error",
|
1784
|
-
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
1785
|
-
})
|
1786
|
-
});
|
1787
|
-
return;
|
1788
|
-
}
|
1789
|
-
const res = await publish(
|
1790
|
-
{
|
1791
|
-
collectionType,
|
1792
|
-
model,
|
1793
|
-
documentId,
|
1794
|
-
params
|
1795
|
-
},
|
1796
|
-
formValues
|
1797
|
-
);
|
1798
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1799
|
-
navigate({
|
1800
|
-
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
1801
|
-
search: rawQuery
|
1802
|
-
});
|
1803
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1804
|
-
setErrors(formatValidationErrors(res.error));
|
1805
|
-
}
|
1806
|
-
} finally {
|
1807
|
-
setSubmitting(false);
|
1808
|
-
}
|
1809
|
-
};
|
1810
|
-
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
1811
|
-
const hasDraftRelations = totalDraftRelations > 0;
|
1812
|
-
return {
|
1813
|
-
/**
|
1814
|
-
* Disabled when:
|
1815
|
-
* - currently if you're cloning a document we don't support publish & clone at the same time.
|
1816
|
-
* - the form is submitting
|
1817
|
-
* - the active tab is the published tab
|
1818
|
-
* - the document is already published & not modified
|
1819
|
-
* - the document is being created & not modified
|
1820
|
-
* - the user doesn't have the permission to publish
|
1821
|
-
*/
|
1822
|
-
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
1823
|
-
label: formatMessage({
|
1824
|
-
id: "app.utils.publish",
|
1825
|
-
defaultMessage: "Publish"
|
1826
|
-
}),
|
1827
|
-
onClick: async () => {
|
1828
|
-
if (hasDraftRelations) {
|
1829
|
-
return;
|
1830
|
-
}
|
1831
|
-
await performPublish();
|
1832
|
-
},
|
1833
|
-
dialog: hasDraftRelations ? {
|
1834
|
-
type: "dialog",
|
1835
|
-
variant: "danger",
|
1836
|
-
footer: null,
|
1837
|
-
title: formatMessage({
|
1838
|
-
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
1839
|
-
defaultMessage: "Confirmation"
|
1840
|
-
}),
|
1841
|
-
content: formatMessage(
|
1842
|
-
{
|
1843
|
-
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
1844
|
-
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
1845
|
-
},
|
1766
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, alignItems: "stretch", width: "100%", children: [
|
1767
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
1768
|
+
/* @__PURE__ */ jsx(DocumentActionButton, { ...primaryAction, variant: primaryAction.variant || "default" }),
|
1769
|
+
restActions.length > 0 ? /* @__PURE__ */ jsx(
|
1770
|
+
DocumentActionsMenu,
|
1846
1771
|
{
|
1847
|
-
|
1772
|
+
actions: restActions,
|
1773
|
+
label: formatMessage({
|
1774
|
+
id: "content-manager.containers.edit.panels.default.more-actions",
|
1775
|
+
defaultMessage: "More document actions"
|
1776
|
+
})
|
1848
1777
|
}
|
1849
|
-
)
|
1850
|
-
|
1851
|
-
|
1778
|
+
) : null
|
1779
|
+
] }),
|
1780
|
+
secondaryAction ? /* @__PURE__ */ jsx(
|
1781
|
+
DocumentActionButton,
|
1782
|
+
{
|
1783
|
+
...secondaryAction,
|
1784
|
+
variant: secondaryAction.variant || "secondary"
|
1852
1785
|
}
|
1853
|
-
|
1854
|
-
};
|
1786
|
+
) : null
|
1787
|
+
] });
|
1855
1788
|
};
|
1856
|
-
|
1857
|
-
const
|
1858
|
-
activeTab,
|
1859
|
-
documentId,
|
1860
|
-
model,
|
1861
|
-
collectionType
|
1862
|
-
}) => {
|
1863
|
-
const navigate = useNavigate();
|
1789
|
+
const DocumentActionButton = (action) => {
|
1790
|
+
const [dialogId, setDialogId] = React.useState(null);
|
1864
1791
|
const { toggleNotification } = useNotification();
|
1865
|
-
const
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
canUpdate: canUpdate2
|
1872
|
-
}));
|
1873
|
-
const { create, update, clone } = useDocumentActions();
|
1874
|
-
const [{ query, rawQuery }] = useQueryParams();
|
1875
|
-
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1876
|
-
const isSubmitting = useForm("UpdateAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
1877
|
-
const modified = useForm("UpdateAction", ({ modified: modified2 }) => modified2);
|
1878
|
-
const setSubmitting = useForm("UpdateAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
1879
|
-
const document = useForm("UpdateAction", ({ values }) => values);
|
1880
|
-
const validate = useForm("UpdateAction", (state) => state.validate);
|
1881
|
-
const setErrors = useForm("UpdateAction", (state) => state.setErrors);
|
1882
|
-
const resetForm = useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
|
1883
|
-
return {
|
1884
|
-
/**
|
1885
|
-
* Disabled when:
|
1886
|
-
* - the form is submitting
|
1887
|
-
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
1888
|
-
* - the active tab is the published tab
|
1889
|
-
*/
|
1890
|
-
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
1891
|
-
label: formatMessage({
|
1892
|
-
id: "content-manager.containers.Edit.save",
|
1893
|
-
defaultMessage: "Save"
|
1894
|
-
}),
|
1895
|
-
onClick: async () => {
|
1896
|
-
setSubmitting(true);
|
1897
|
-
try {
|
1898
|
-
const { errors } = await validate();
|
1899
|
-
if (errors) {
|
1792
|
+
const handleClick = (action2) => async (e) => {
|
1793
|
+
const { onClick = () => false, dialog, id } = action2;
|
1794
|
+
const muteDialog = await onClick(e);
|
1795
|
+
if (dialog && !muteDialog) {
|
1796
|
+
switch (dialog.type) {
|
1797
|
+
case "notification":
|
1900
1798
|
toggleNotification({
|
1901
|
-
|
1902
|
-
message:
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1799
|
+
title: dialog.title,
|
1800
|
+
message: dialog.content,
|
1801
|
+
type: dialog.status,
|
1802
|
+
timeout: dialog.timeout,
|
1803
|
+
onClose: dialog.onClose
|
1906
1804
|
});
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
model,
|
1913
|
-
documentId: cloneMatch.params.origin,
|
1914
|
-
params
|
1915
|
-
},
|
1916
|
-
document
|
1917
|
-
);
|
1918
|
-
if ("data" in res) {
|
1919
|
-
navigate(
|
1920
|
-
{
|
1921
|
-
pathname: `../${res.data.documentId}`,
|
1922
|
-
search: rawQuery
|
1923
|
-
},
|
1924
|
-
{ relative: "path" }
|
1925
|
-
);
|
1926
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1927
|
-
setErrors(formatValidationErrors(res.error));
|
1928
|
-
}
|
1929
|
-
} else if (documentId || collectionType === SINGLE_TYPES) {
|
1930
|
-
const res = await update(
|
1931
|
-
{
|
1932
|
-
collectionType,
|
1933
|
-
model,
|
1934
|
-
documentId,
|
1935
|
-
params
|
1936
|
-
},
|
1937
|
-
document
|
1938
|
-
);
|
1939
|
-
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1940
|
-
setErrors(formatValidationErrors(res.error));
|
1941
|
-
} else {
|
1942
|
-
resetForm();
|
1943
|
-
}
|
1944
|
-
} else {
|
1945
|
-
const res = await create(
|
1946
|
-
{
|
1947
|
-
model,
|
1948
|
-
params
|
1949
|
-
},
|
1950
|
-
document
|
1951
|
-
);
|
1952
|
-
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
1953
|
-
navigate(
|
1954
|
-
{
|
1955
|
-
pathname: `../${res.data.documentId}`,
|
1956
|
-
search: rawQuery
|
1957
|
-
},
|
1958
|
-
{ replace: true, relative: "path" }
|
1959
|
-
);
|
1960
|
-
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
1961
|
-
setErrors(formatValidationErrors(res.error));
|
1962
|
-
}
|
1963
|
-
}
|
1964
|
-
} finally {
|
1965
|
-
setSubmitting(false);
|
1805
|
+
break;
|
1806
|
+
case "dialog":
|
1807
|
+
case "modal":
|
1808
|
+
e.preventDefault();
|
1809
|
+
setDialogId(id);
|
1966
1810
|
}
|
1967
1811
|
}
|
1968
1812
|
};
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1813
|
+
const handleClose = () => {
|
1814
|
+
setDialogId(null);
|
1815
|
+
};
|
1816
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
1817
|
+
/* @__PURE__ */ jsx(
|
1818
|
+
Button,
|
1819
|
+
{
|
1820
|
+
flex: "auto",
|
1821
|
+
startIcon: action.icon,
|
1822
|
+
disabled: action.disabled,
|
1823
|
+
onClick: handleClick(action),
|
1824
|
+
justifyContent: "center",
|
1825
|
+
variant: action.variant || "default",
|
1826
|
+
paddingTop: "7px",
|
1827
|
+
paddingBottom: "7px",
|
1828
|
+
children: action.label
|
1829
|
+
}
|
1830
|
+
),
|
1831
|
+
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
|
1832
|
+
DocumentActionConfirmDialog,
|
1833
|
+
{
|
1834
|
+
...action.dialog,
|
1835
|
+
variant: action.dialog?.variant ?? action.variant,
|
1836
|
+
isOpen: dialogId === action.id,
|
1837
|
+
onClose: handleClose
|
1838
|
+
}
|
1839
|
+
) : null,
|
1840
|
+
action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
|
1841
|
+
DocumentActionModal,
|
1842
|
+
{
|
1843
|
+
...action.dialog,
|
1844
|
+
onModalClose: handleClose,
|
1845
|
+
isOpen: dialogId === action.id
|
1846
|
+
}
|
1847
|
+
) : null
|
1848
|
+
] });
|
1849
|
+
};
|
1850
|
+
const DocumentActionsMenu = ({
|
1851
|
+
actions: actions2,
|
1852
|
+
children,
|
1853
|
+
label,
|
1854
|
+
variant = "tertiary"
|
1981
1855
|
}) => {
|
1856
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
1857
|
+
const [dialogId, setDialogId] = React.useState(null);
|
1982
1858
|
const { formatMessage } = useIntl();
|
1983
|
-
const { schema } = useDoc();
|
1984
|
-
const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
1985
|
-
const { unpublish } = useDocumentActions();
|
1986
|
-
const [{ query }] = useQueryParams();
|
1987
|
-
const params = React.useMemo(() => buildValidParams(query), [query]);
|
1988
1859
|
const { toggleNotification } = useNotification();
|
1989
|
-
const
|
1990
|
-
const
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
}
|
1997
|
-
return {
|
1998
|
-
disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
|
1999
|
-
label: formatMessage({
|
2000
|
-
id: "app.utils.unpublish",
|
2001
|
-
defaultMessage: "Unpublish"
|
2002
|
-
}),
|
2003
|
-
icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
|
2004
|
-
onClick: async () => {
|
2005
|
-
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
2006
|
-
if (!documentId) {
|
2007
|
-
console.error(
|
2008
|
-
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2009
|
-
);
|
1860
|
+
const isDisabled = actions2.every((action) => action.disabled) || actions2.length === 0;
|
1861
|
+
const handleClick = (action) => async (e) => {
|
1862
|
+
const { onClick = () => false, dialog, id } = action;
|
1863
|
+
const muteDialog = await onClick(e);
|
1864
|
+
if (dialog && !muteDialog) {
|
1865
|
+
switch (dialog.type) {
|
1866
|
+
case "notification":
|
2010
1867
|
toggleNotification({
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
1868
|
+
title: dialog.title,
|
1869
|
+
message: dialog.content,
|
1870
|
+
type: dialog.status,
|
1871
|
+
timeout: dialog.timeout,
|
1872
|
+
onClose: dialog.onClose
|
2016
1873
|
});
|
2017
|
-
|
2018
|
-
|
1874
|
+
break;
|
1875
|
+
case "dialog":
|
1876
|
+
case "modal":
|
1877
|
+
setDialogId(id);
|
2019
1878
|
}
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
1879
|
+
}
|
1880
|
+
};
|
1881
|
+
const handleClose = () => {
|
1882
|
+
setDialogId(null);
|
1883
|
+
setIsOpen(false);
|
1884
|
+
};
|
1885
|
+
return /* @__PURE__ */ jsxs(Menu.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
|
1886
|
+
/* @__PURE__ */ jsxs(
|
1887
|
+
Menu.Trigger,
|
1888
|
+
{
|
1889
|
+
disabled: isDisabled,
|
1890
|
+
size: "S",
|
1891
|
+
endIcon: null,
|
1892
|
+
paddingTop: "4px",
|
1893
|
+
paddingLeft: "7px",
|
1894
|
+
paddingRight: "7px",
|
1895
|
+
variant,
|
1896
|
+
children: [
|
1897
|
+
/* @__PURE__ */ jsx(More, { "aria-hidden": true, focusable: false }),
|
1898
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: label || formatMessage({
|
1899
|
+
id: "content-manager.containers.edit.panels.default.more-actions",
|
1900
|
+
defaultMessage: "More document actions"
|
2039
1901
|
}) })
|
2040
|
-
]
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2048
|
-
defaultMessage: "Choose an option to unpublish the document."
|
2049
|
-
}),
|
2050
|
-
onValueChange: handleChange,
|
2051
|
-
children: [
|
2052
|
-
/* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2053
|
-
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2054
|
-
defaultMessage: "Keep draft"
|
2055
|
-
}) }),
|
2056
|
-
/* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2057
|
-
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2058
|
-
defaultMessage: "Replace draft"
|
2059
|
-
}) })
|
2060
|
-
]
|
2061
|
-
}
|
2062
|
-
)
|
2063
|
-
] }),
|
2064
|
-
onConfirm: async () => {
|
2065
|
-
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2066
|
-
console.error(
|
2067
|
-
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2068
|
-
);
|
2069
|
-
toggleNotification({
|
2070
|
-
message: formatMessage({
|
2071
|
-
id: "content-manager.actions.unpublish.error",
|
2072
|
-
defaultMessage: "An error occurred while trying to unpublish the document."
|
2073
|
-
}),
|
2074
|
-
type: "danger"
|
2075
|
-
});
|
2076
|
-
}
|
2077
|
-
await unpublish(
|
1902
|
+
]
|
1903
|
+
}
|
1904
|
+
),
|
1905
|
+
/* @__PURE__ */ jsxs(Menu.Content, { maxHeight: void 0, popoverPlacement: "bottom-end", children: [
|
1906
|
+
actions2.map((action) => {
|
1907
|
+
return /* @__PURE__ */ jsx(
|
1908
|
+
Menu.Item,
|
2078
1909
|
{
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
1910
|
+
disabled: action.disabled,
|
1911
|
+
onSelect: handleClick(action),
|
1912
|
+
display: "block",
|
1913
|
+
children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", gap: 4, children: [
|
1914
|
+
/* @__PURE__ */ jsxs(
|
1915
|
+
Flex,
|
1916
|
+
{
|
1917
|
+
color: !action.disabled ? convertActionVariantToColor(action.variant) : "inherit",
|
1918
|
+
gap: 2,
|
1919
|
+
tag: "span",
|
1920
|
+
children: [
|
1921
|
+
/* @__PURE__ */ jsx(
|
1922
|
+
Flex,
|
1923
|
+
{
|
1924
|
+
tag: "span",
|
1925
|
+
color: !action.disabled ? convertActionVariantToIconColor(action.variant) : "inherit",
|
1926
|
+
children: action.icon
|
1927
|
+
}
|
1928
|
+
),
|
1929
|
+
action.label
|
1930
|
+
]
|
1931
|
+
}
|
1932
|
+
),
|
1933
|
+
action.id.startsWith("HistoryAction") && /* @__PURE__ */ jsx(
|
1934
|
+
Flex,
|
1935
|
+
{
|
1936
|
+
alignItems: "center",
|
1937
|
+
background: "alternative100",
|
1938
|
+
borderStyle: "solid",
|
1939
|
+
borderColor: "alternative200",
|
1940
|
+
borderWidth: "1px",
|
1941
|
+
height: 5,
|
1942
|
+
paddingLeft: 2,
|
1943
|
+
paddingRight: 2,
|
1944
|
+
hasRadius: true,
|
1945
|
+
color: "alternative600",
|
1946
|
+
children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", fontWeight: "bold", lineHeight: 1, children: formatMessage({ id: "global.new", defaultMessage: "New" }) })
|
1947
|
+
}
|
1948
|
+
)
|
1949
|
+
] })
|
2083
1950
|
},
|
2084
|
-
|
1951
|
+
action.id
|
2085
1952
|
);
|
2086
|
-
}
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
1953
|
+
}),
|
1954
|
+
children
|
1955
|
+
] }),
|
1956
|
+
actions2.map((action) => {
|
1957
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
1958
|
+
action.dialog?.type === "dialog" ? /* @__PURE__ */ jsx(
|
1959
|
+
DocumentActionConfirmDialog,
|
1960
|
+
{
|
1961
|
+
...action.dialog,
|
1962
|
+
variant: action.variant,
|
1963
|
+
isOpen: dialogId === action.id,
|
1964
|
+
onClose: handleClose
|
1965
|
+
}
|
1966
|
+
) : null,
|
1967
|
+
action.dialog?.type === "modal" ? /* @__PURE__ */ jsx(
|
1968
|
+
DocumentActionModal,
|
1969
|
+
{
|
1970
|
+
...action.dialog,
|
1971
|
+
onModalClose: handleClose,
|
1972
|
+
isOpen: dialogId === action.id
|
1973
|
+
}
|
1974
|
+
) : null
|
1975
|
+
] }, action.id);
|
1976
|
+
})
|
1977
|
+
] });
|
1978
|
+
};
|
1979
|
+
const convertActionVariantToColor = (variant = "secondary") => {
|
1980
|
+
switch (variant) {
|
1981
|
+
case "danger":
|
1982
|
+
return "danger600";
|
1983
|
+
case "secondary":
|
1984
|
+
return void 0;
|
1985
|
+
case "success":
|
1986
|
+
return "success600";
|
1987
|
+
default:
|
1988
|
+
return "primary600";
|
1989
|
+
}
|
1990
|
+
};
|
1991
|
+
const convertActionVariantToIconColor = (variant = "secondary") => {
|
1992
|
+
switch (variant) {
|
1993
|
+
case "danger":
|
1994
|
+
return "danger600";
|
1995
|
+
case "secondary":
|
1996
|
+
return "neutral500";
|
1997
|
+
case "success":
|
1998
|
+
return "success600";
|
1999
|
+
default:
|
2000
|
+
return "primary600";
|
2001
|
+
}
|
2002
|
+
};
|
2003
|
+
const DocumentActionConfirmDialog = ({
|
2004
|
+
onClose,
|
2005
|
+
onCancel,
|
2006
|
+
onConfirm,
|
2007
|
+
title,
|
2008
|
+
content,
|
2009
|
+
isOpen,
|
2010
|
+
variant = "secondary"
|
2011
|
+
}) => {
|
2012
|
+
const { formatMessage } = useIntl();
|
2013
|
+
const handleClose = async () => {
|
2014
|
+
if (onCancel) {
|
2015
|
+
await onCancel();
|
2016
|
+
}
|
2017
|
+
onClose();
|
2090
2018
|
};
|
2019
|
+
const handleConfirm = async () => {
|
2020
|
+
if (onConfirm) {
|
2021
|
+
await onConfirm();
|
2022
|
+
}
|
2023
|
+
onClose();
|
2024
|
+
};
|
2025
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2026
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2027
|
+
/* @__PURE__ */ jsx(Dialog.Body, { children: content }),
|
2028
|
+
/* @__PURE__ */ jsxs(Dialog.Footer, { children: [
|
2029
|
+
/* @__PURE__ */ jsx(Dialog.Cancel, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", fullWidth: true, children: formatMessage({
|
2030
|
+
id: "app.components.Button.cancel",
|
2031
|
+
defaultMessage: "Cancel"
|
2032
|
+
}) }) }),
|
2033
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleConfirm, variant, fullWidth: true, children: formatMessage({
|
2034
|
+
id: "app.components.Button.confirm",
|
2035
|
+
defaultMessage: "Confirm"
|
2036
|
+
}) })
|
2037
|
+
] })
|
2038
|
+
] }) });
|
2091
2039
|
};
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2040
|
+
const DocumentActionModal = ({
|
2041
|
+
isOpen,
|
2042
|
+
title,
|
2043
|
+
onClose,
|
2044
|
+
footer: Footer,
|
2045
|
+
content: Content,
|
2046
|
+
onModalClose
|
2099
2047
|
}) => {
|
2100
|
-
const
|
2101
|
-
|
2102
|
-
|
2103
|
-
const { discard } = useDocumentActions();
|
2104
|
-
const [{ query }] = useQueryParams();
|
2105
|
-
const params = React.useMemo(() => buildValidParams(query), [query]);
|
2106
|
-
if (!schema?.options?.draftAndPublish) {
|
2107
|
-
return null;
|
2108
|
-
}
|
2109
|
-
return {
|
2110
|
-
disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
|
2111
|
-
label: formatMessage({
|
2112
|
-
id: "content-manager.actions.discard.label",
|
2113
|
-
defaultMessage: "Discard changes"
|
2114
|
-
}),
|
2115
|
-
icon: /* @__PURE__ */ jsx(StyledCrossCircle, {}),
|
2116
|
-
position: ["panel", "table-row"],
|
2117
|
-
variant: "danger",
|
2118
|
-
dialog: {
|
2119
|
-
type: "dialog",
|
2120
|
-
title: formatMessage({
|
2121
|
-
id: "app.components.ConfirmDialog.title",
|
2122
|
-
defaultMessage: "Confirmation"
|
2123
|
-
}),
|
2124
|
-
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2125
|
-
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2126
|
-
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2127
|
-
id: "content-manager.actions.discard.dialog.body",
|
2128
|
-
defaultMessage: "Are you sure?"
|
2129
|
-
}) })
|
2130
|
-
] }),
|
2131
|
-
onConfirm: async () => {
|
2132
|
-
await discard({
|
2133
|
-
collectionType,
|
2134
|
-
model,
|
2135
|
-
documentId,
|
2136
|
-
params
|
2137
|
-
});
|
2138
|
-
}
|
2048
|
+
const handleClose = () => {
|
2049
|
+
if (onClose) {
|
2050
|
+
onClose();
|
2139
2051
|
}
|
2052
|
+
onModalClose();
|
2140
2053
|
};
|
2054
|
+
return /* @__PURE__ */ jsx(Modal.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Modal.Content, { children: [
|
2055
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsx(Modal.Title, { children: title }) }),
|
2056
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : /* @__PURE__ */ jsx(Modal.Body, { children: Content }),
|
2057
|
+
typeof Footer === "function" ? /* @__PURE__ */ jsx(Footer, { onClose: handleClose }) : Footer
|
2058
|
+
] }) });
|
2141
2059
|
};
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
fill: currentColor;
|
2146
|
-
}
|
2147
|
-
`;
|
2148
|
-
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2149
|
-
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2150
|
-
const RelativeTime = React.forwardRef(
|
2151
|
-
({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
|
2152
|
-
const { formatRelativeTime, formatDate, formatTime } = useIntl();
|
2153
|
-
const interval = intervalToDuration({
|
2154
|
-
start: timestamp,
|
2155
|
-
end: Date.now()
|
2156
|
-
// see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
|
2157
|
-
});
|
2158
|
-
const unit = intervals.find((intervalUnit) => {
|
2159
|
-
return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
|
2160
|
-
});
|
2161
|
-
const relativeTime = isPast(timestamp) ? -interval[unit] : interval[unit];
|
2162
|
-
const customInterval = customIntervals.find(
|
2163
|
-
(custom) => interval[custom.unit] < custom.threshold
|
2164
|
-
);
|
2165
|
-
const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
|
2166
|
-
return /* @__PURE__ */ jsx(
|
2167
|
-
"time",
|
2168
|
-
{
|
2169
|
-
ref: forwardedRef,
|
2170
|
-
dateTime: timestamp.toISOString(),
|
2171
|
-
role: "time",
|
2172
|
-
title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
|
2173
|
-
...restProps,
|
2174
|
-
children: displayText
|
2175
|
-
}
|
2176
|
-
);
|
2177
|
-
}
|
2178
|
-
);
|
2179
|
-
const getDisplayName = ({
|
2180
|
-
firstname,
|
2181
|
-
lastname,
|
2182
|
-
username,
|
2183
|
-
email
|
2184
|
-
} = {}) => {
|
2185
|
-
if (username) {
|
2186
|
-
return username;
|
2060
|
+
const transformData = (data) => {
|
2061
|
+
if (Array.isArray(data)) {
|
2062
|
+
return data.map(transformData);
|
2187
2063
|
}
|
2188
|
-
if (
|
2189
|
-
|
2064
|
+
if (typeof data === "object" && data !== null) {
|
2065
|
+
if ("apiData" in data) {
|
2066
|
+
return data.apiData;
|
2067
|
+
}
|
2068
|
+
return mapValues(transformData)(data);
|
2190
2069
|
}
|
2191
|
-
return
|
2192
|
-
};
|
2193
|
-
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2194
|
-
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2195
|
-
const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
|
2196
|
-
return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2070
|
+
return data;
|
2197
2071
|
};
|
2198
|
-
const
|
2199
|
-
|
2072
|
+
const PublishAction$1 = ({
|
2073
|
+
activeTab,
|
2074
|
+
documentId,
|
2075
|
+
model,
|
2076
|
+
collectionType,
|
2077
|
+
meta,
|
2078
|
+
document
|
2079
|
+
}) => {
|
2080
|
+
const { schema } = useDoc();
|
2081
|
+
const navigate = useNavigate();
|
2082
|
+
const { toggleNotification } = useNotification();
|
2083
|
+
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
2084
|
+
const isListView = useMatch(LIST_PATH) !== null;
|
2200
2085
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
2201
|
-
const title = isCreating ? formatMessage({
|
2202
|
-
id: "content-manager.containers.edit.title.new",
|
2203
|
-
defaultMessage: "Create an entry"
|
2204
|
-
}) : documentTitle;
|
2205
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2206
|
-
/* @__PURE__ */ jsx(BackButton, {}),
|
2207
|
-
/* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2208
|
-
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2209
|
-
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2210
|
-
] }),
|
2211
|
-
status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2212
|
-
] });
|
2213
|
-
};
|
2214
|
-
const HeaderToolbar = () => {
|
2215
2086
|
const { formatMessage } = useIntl();
|
2216
|
-
const
|
2087
|
+
const canPublish = useDocumentRBAC("PublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
2088
|
+
const { publish } = useDocumentActions();
|
2217
2089
|
const [
|
2218
|
-
|
2219
|
-
|
2090
|
+
countDraftRelations,
|
2091
|
+
{ isLoading: isLoadingDraftRelations, isError: isErrorDraftRelations }
|
2092
|
+
] = useLazyGetDraftRelationCountQuery();
|
2093
|
+
const [localCountOfDraftRelations, setLocalCountOfDraftRelations] = React.useState(0);
|
2094
|
+
const [serverCountOfDraftRelations, setServerCountOfDraftRelations] = React.useState(0);
|
2095
|
+
const [{ query, rawQuery }] = useQueryParams();
|
2096
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
2097
|
+
const modified = useForm("PublishAction", ({ modified: modified2 }) => modified2);
|
2098
|
+
const setSubmitting = useForm("PublishAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
2099
|
+
const isSubmitting = useForm("PublishAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
2100
|
+
const validate = useForm("PublishAction", (state) => state.validate);
|
2101
|
+
const setErrors = useForm("PublishAction", (state) => state.setErrors);
|
2102
|
+
const formValues = useForm("PublishAction", ({ values }) => values);
|
2103
|
+
React.useEffect(() => {
|
2104
|
+
if (isErrorDraftRelations) {
|
2105
|
+
toggleNotification({
|
2106
|
+
type: "danger",
|
2107
|
+
message: formatMessage({
|
2108
|
+
id: getTranslation("error.records.fetch-draft-relatons"),
|
2109
|
+
defaultMessage: "An error occurred while fetching draft relations on this document."
|
2110
|
+
})
|
2111
|
+
});
|
2220
2112
|
}
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
activeTab: status,
|
2230
|
-
model,
|
2231
|
-
documentId: id,
|
2232
|
-
document: isCloning ? void 0 : document,
|
2233
|
-
meta: isCloning ? void 0 : meta,
|
2234
|
-
collectionType
|
2235
|
-
},
|
2236
|
-
descriptions: plugins["content-manager"].apis.getHeaderActions(),
|
2237
|
-
children: (actions2) => {
|
2238
|
-
if (actions2.length > 0) {
|
2239
|
-
return /* @__PURE__ */ jsx(HeaderActions, { actions: actions2 });
|
2240
|
-
} else {
|
2241
|
-
return null;
|
2242
|
-
}
|
2113
|
+
}, [isErrorDraftRelations, toggleNotification, formatMessage]);
|
2114
|
+
React.useEffect(() => {
|
2115
|
+
const localDraftRelations = /* @__PURE__ */ new Set();
|
2116
|
+
const extractDraftRelations = (data) => {
|
2117
|
+
const relations = data.connect || [];
|
2118
|
+
relations.forEach((relation) => {
|
2119
|
+
if (relation.status === "draft") {
|
2120
|
+
localDraftRelations.add(relation.id);
|
2243
2121
|
}
|
2244
|
-
}
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
documentId: id,
|
2253
|
-
document: isCloning ? void 0 : document,
|
2254
|
-
meta: isCloning ? void 0 : meta,
|
2255
|
-
collectionType
|
2256
|
-
},
|
2257
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2258
|
-
children: (actions2) => {
|
2259
|
-
const headerActions = actions2.filter((action) => {
|
2260
|
-
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
2261
|
-
return positions.includes("header");
|
2262
|
-
});
|
2263
|
-
return /* @__PURE__ */ jsx(
|
2264
|
-
DocumentActionsMenu,
|
2265
|
-
{
|
2266
|
-
actions: headerActions,
|
2267
|
-
label: formatMessage({
|
2268
|
-
id: "content-manager.containers.edit.header.more-actions",
|
2269
|
-
defaultMessage: "More actions"
|
2270
|
-
}),
|
2271
|
-
children: /* @__PURE__ */ jsx(Information, { activeTab: status })
|
2272
|
-
}
|
2273
|
-
);
|
2122
|
+
});
|
2123
|
+
};
|
2124
|
+
const traverseAndExtract = (data) => {
|
2125
|
+
Object.entries(data).forEach(([key, value]) => {
|
2126
|
+
if (key === "connect" && Array.isArray(value)) {
|
2127
|
+
extractDraftRelations({ connect: value });
|
2128
|
+
} else if (typeof value === "object" && value !== null) {
|
2129
|
+
traverseAndExtract(value);
|
2274
2130
|
}
|
2131
|
+
});
|
2132
|
+
};
|
2133
|
+
if (!documentId || modified) {
|
2134
|
+
traverseAndExtract(formValues);
|
2135
|
+
setLocalCountOfDraftRelations(localDraftRelations.size);
|
2136
|
+
}
|
2137
|
+
}, [documentId, modified, formValues, setLocalCountOfDraftRelations]);
|
2138
|
+
React.useEffect(() => {
|
2139
|
+
if (!document || !document.documentId || isListView) {
|
2140
|
+
return;
|
2141
|
+
}
|
2142
|
+
const fetchDraftRelationsCount = async () => {
|
2143
|
+
const { data, error } = await countDraftRelations({
|
2144
|
+
collectionType,
|
2145
|
+
model,
|
2146
|
+
documentId,
|
2147
|
+
params
|
2148
|
+
});
|
2149
|
+
if (error) {
|
2150
|
+
throw error;
|
2275
2151
|
}
|
2276
|
-
|
2277
|
-
|
2278
|
-
}
|
2279
|
-
|
2280
|
-
|
2281
|
-
|
2282
|
-
|
2152
|
+
if (data) {
|
2153
|
+
setServerCountOfDraftRelations(data.data);
|
2154
|
+
}
|
2155
|
+
};
|
2156
|
+
fetchDraftRelationsCount();
|
2157
|
+
}, [isListView, document, documentId, countDraftRelations, collectionType, model, params]);
|
2158
|
+
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc) => doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== "modified";
|
2159
|
+
if (!schema?.options?.draftAndPublish) {
|
2283
2160
|
return null;
|
2284
2161
|
}
|
2285
|
-
const
|
2286
|
-
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
2296
|
-
|
2162
|
+
const performPublish = async () => {
|
2163
|
+
setSubmitting(true);
|
2164
|
+
try {
|
2165
|
+
const { errors } = await validate(true, {
|
2166
|
+
status: "published"
|
2167
|
+
});
|
2168
|
+
if (errors) {
|
2169
|
+
toggleNotification({
|
2170
|
+
type: "danger",
|
2171
|
+
message: formatMessage({
|
2172
|
+
id: "content-manager.validation.error",
|
2173
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2174
|
+
})
|
2175
|
+
});
|
2176
|
+
return;
|
2177
|
+
}
|
2178
|
+
const res = await publish(
|
2297
2179
|
{
|
2298
|
-
|
2299
|
-
|
2180
|
+
collectionType,
|
2181
|
+
model,
|
2182
|
+
documentId,
|
2183
|
+
params
|
2300
2184
|
},
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2185
|
+
transformData(formValues)
|
2186
|
+
);
|
2187
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2188
|
+
navigate({
|
2189
|
+
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
2190
|
+
search: rawQuery
|
2191
|
+
});
|
2192
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2193
|
+
setErrors(formatValidationErrors(res.error));
|
2194
|
+
}
|
2195
|
+
} finally {
|
2196
|
+
setSubmitting(false);
|
2197
|
+
}
|
2198
|
+
};
|
2199
|
+
const totalDraftRelations = localCountOfDraftRelations + serverCountOfDraftRelations;
|
2200
|
+
const enableDraftRelationsCount = false;
|
2201
|
+
const hasDraftRelations = enableDraftRelationsCount;
|
2202
|
+
return {
|
2203
|
+
/**
|
2204
|
+
* Disabled when:
|
2205
|
+
* - currently if you're cloning a document we don't support publish & clone at the same time.
|
2206
|
+
* - the form is submitting
|
2207
|
+
* - the active tab is the published tab
|
2208
|
+
* - the document is already published & not modified
|
2209
|
+
* - the document is being created & not modified
|
2210
|
+
* - the user doesn't have the permission to publish
|
2211
|
+
*/
|
2212
|
+
disabled: isCloning || isSubmitting || isLoadingDraftRelations || activeTab === "published" || !modified && isDocumentPublished || !modified && !document?.documentId || !canPublish,
|
2213
|
+
label: formatMessage({
|
2214
|
+
id: "app.utils.publish",
|
2215
|
+
defaultMessage: "Publish"
|
2216
|
+
}),
|
2217
|
+
onClick: async () => {
|
2218
|
+
await performPublish();
|
2307
2219
|
},
|
2308
|
-
{
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2220
|
+
dialog: hasDraftRelations ? {
|
2221
|
+
type: "dialog",
|
2222
|
+
variant: "danger",
|
2223
|
+
footer: null,
|
2224
|
+
title: formatMessage({
|
2225
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.title`),
|
2226
|
+
defaultMessage: "Confirmation"
|
2313
2227
|
}),
|
2314
|
-
|
2228
|
+
content: formatMessage(
|
2315
2229
|
{
|
2316
|
-
id:
|
2317
|
-
defaultMessage:
|
2230
|
+
id: getTranslation(`popUpwarning.warning.bulk-has-draft-relations.message`),
|
2231
|
+
defaultMessage: "This entry is related to {count, plural, one {# draft entry} other {# draft entries}}. Publishing it could leave broken links in your app."
|
2318
2232
|
},
|
2319
2233
|
{
|
2320
|
-
|
2321
|
-
RelativeTime,
|
2322
|
-
{
|
2323
|
-
timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
|
2324
|
-
}
|
2325
|
-
),
|
2326
|
-
isAnonymous: !updator,
|
2327
|
-
author: updator
|
2234
|
+
count: totalDraftRelations
|
2328
2235
|
}
|
2329
|
-
)
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2347
|
-
|
2348
|
-
|
2349
|
-
|
2350
|
-
|
2236
|
+
),
|
2237
|
+
onConfirm: async () => {
|
2238
|
+
await performPublish();
|
2239
|
+
}
|
2240
|
+
} : void 0
|
2241
|
+
};
|
2242
|
+
};
|
2243
|
+
PublishAction$1.type = "publish";
|
2244
|
+
const UpdateAction = ({
|
2245
|
+
activeTab,
|
2246
|
+
documentId,
|
2247
|
+
model,
|
2248
|
+
collectionType
|
2249
|
+
}) => {
|
2250
|
+
const navigate = useNavigate();
|
2251
|
+
const { toggleNotification } = useNotification();
|
2252
|
+
const { _unstableFormatValidationErrors: formatValidationErrors } = useAPIErrorHandler();
|
2253
|
+
const cloneMatch = useMatch(CLONE_PATH);
|
2254
|
+
const isCloning = cloneMatch !== null;
|
2255
|
+
const { formatMessage } = useIntl();
|
2256
|
+
const { create, update, clone } = useDocumentActions();
|
2257
|
+
const [{ query, rawQuery }] = useQueryParams();
|
2258
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
2259
|
+
const isSubmitting = useForm("UpdateAction", ({ isSubmitting: isSubmitting2 }) => isSubmitting2);
|
2260
|
+
const modified = useForm("UpdateAction", ({ modified: modified2 }) => modified2);
|
2261
|
+
const setSubmitting = useForm("UpdateAction", ({ setSubmitting: setSubmitting2 }) => setSubmitting2);
|
2262
|
+
const document = useForm("UpdateAction", ({ values }) => values);
|
2263
|
+
const validate = useForm("UpdateAction", (state) => state.validate);
|
2264
|
+
const setErrors = useForm("UpdateAction", (state) => state.setErrors);
|
2265
|
+
const resetForm = useForm("PublishAction", ({ resetForm: resetForm2 }) => resetForm2);
|
2266
|
+
return {
|
2267
|
+
/**
|
2268
|
+
* Disabled when:
|
2269
|
+
* - the form is submitting
|
2270
|
+
* - the document is not modified & we're not cloning (you can save a clone entity straight away)
|
2271
|
+
* - the active tab is the published tab
|
2272
|
+
*/
|
2273
|
+
disabled: isSubmitting || !modified && !isCloning || activeTab === "published",
|
2274
|
+
label: formatMessage({
|
2275
|
+
id: "content-manager.containers.Edit.save",
|
2276
|
+
defaultMessage: "Save"
|
2277
|
+
}),
|
2278
|
+
onClick: async () => {
|
2279
|
+
setSubmitting(true);
|
2280
|
+
try {
|
2281
|
+
const { errors } = await validate(true, {
|
2282
|
+
status: "draft"
|
2283
|
+
});
|
2284
|
+
if (errors) {
|
2285
|
+
toggleNotification({
|
2286
|
+
type: "danger",
|
2287
|
+
message: formatMessage({
|
2288
|
+
id: "content-manager.validation.error",
|
2289
|
+
defaultMessage: "There are validation errors in your document. Please fix them before saving."
|
2290
|
+
})
|
2291
|
+
});
|
2292
|
+
return;
|
2351
2293
|
}
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2364
|
-
|
2365
|
-
|
2366
|
-
|
2367
|
-
|
2368
|
-
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2294
|
+
if (isCloning) {
|
2295
|
+
const res = await clone(
|
2296
|
+
{
|
2297
|
+
model,
|
2298
|
+
documentId: cloneMatch.params.origin,
|
2299
|
+
params
|
2300
|
+
},
|
2301
|
+
transformData(document)
|
2302
|
+
);
|
2303
|
+
if ("data" in res) {
|
2304
|
+
navigate(
|
2305
|
+
{
|
2306
|
+
pathname: `../${res.data.documentId}`,
|
2307
|
+
search: rawQuery
|
2308
|
+
},
|
2309
|
+
{ relative: "path" }
|
2310
|
+
);
|
2311
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2312
|
+
setErrors(formatValidationErrors(res.error));
|
2313
|
+
}
|
2314
|
+
} else if (documentId || collectionType === SINGLE_TYPES) {
|
2315
|
+
const res = await update(
|
2316
|
+
{
|
2317
|
+
collectionType,
|
2318
|
+
model,
|
2319
|
+
documentId,
|
2320
|
+
params
|
2321
|
+
},
|
2322
|
+
transformData(document)
|
2323
|
+
);
|
2324
|
+
if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2325
|
+
setErrors(formatValidationErrors(res.error));
|
2326
|
+
} else {
|
2327
|
+
resetForm();
|
2328
|
+
}
|
2329
|
+
} else {
|
2330
|
+
const res = await create(
|
2331
|
+
{
|
2332
|
+
model,
|
2333
|
+
params
|
2334
|
+
},
|
2335
|
+
transformData(document)
|
2336
|
+
);
|
2337
|
+
if ("data" in res && collectionType !== SINGLE_TYPES) {
|
2338
|
+
navigate(
|
2339
|
+
{
|
2340
|
+
pathname: `../${res.data.documentId}`,
|
2341
|
+
search: rawQuery
|
2342
|
+
},
|
2343
|
+
{ replace: true, relative: "path" }
|
2344
|
+
);
|
2345
|
+
} else if ("error" in res && isBaseQueryError(res.error) && res.error.name === "ValidationError") {
|
2346
|
+
setErrors(formatValidationErrors(res.error));
|
2347
|
+
}
|
2348
|
+
}
|
2349
|
+
} finally {
|
2350
|
+
setSubmitting(false);
|
2351
|
+
}
|
2374
2352
|
}
|
2375
|
-
|
2353
|
+
};
|
2376
2354
|
};
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2380
|
-
|
2381
|
-
SingleSelect,
|
2382
|
-
{
|
2383
|
-
size: "S",
|
2384
|
-
disabled: action.disabled,
|
2385
|
-
"aria-label": action.label,
|
2386
|
-
onChange: action.onSelect,
|
2387
|
-
value: action.value,
|
2388
|
-
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2389
|
-
},
|
2390
|
-
action.id
|
2391
|
-
);
|
2392
|
-
} else {
|
2393
|
-
return null;
|
2394
|
-
}
|
2395
|
-
}) });
|
2355
|
+
UpdateAction.type = "update";
|
2356
|
+
const UNPUBLISH_DRAFT_OPTIONS = {
|
2357
|
+
KEEP: "keep",
|
2358
|
+
DISCARD: "discard"
|
2396
2359
|
};
|
2397
|
-
const
|
2398
|
-
|
2360
|
+
const UnpublishAction$1 = ({
|
2361
|
+
activeTab,
|
2362
|
+
documentId,
|
2363
|
+
model,
|
2364
|
+
collectionType,
|
2365
|
+
document
|
2366
|
+
}) => {
|
2399
2367
|
const { formatMessage } = useIntl();
|
2400
|
-
|
2401
|
-
|
2402
|
-
|
2403
|
-
|
2404
|
-
|
2405
|
-
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2409
|
-
|
2368
|
+
const { schema } = useDoc();
|
2369
|
+
const canPublish = useDocumentRBAC("UnpublishAction", ({ canPublish: canPublish2 }) => canPublish2);
|
2370
|
+
const { unpublish } = useDocumentActions();
|
2371
|
+
const [{ query }] = useQueryParams();
|
2372
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
2373
|
+
const { toggleNotification } = useNotification();
|
2374
|
+
const [shouldKeepDraft, setShouldKeepDraft] = React.useState(true);
|
2375
|
+
const isDocumentModified = document?.status === "modified";
|
2376
|
+
const handleChange = (value) => {
|
2377
|
+
setShouldKeepDraft(value === UNPUBLISH_DRAFT_OPTIONS.KEEP);
|
2410
2378
|
};
|
2411
|
-
|
2412
|
-
|
2413
|
-
|
2414
|
-
const navigate = useNavigate();
|
2415
|
-
const { formatMessage } = useIntl();
|
2379
|
+
if (!schema?.options?.draftAndPublish) {
|
2380
|
+
return null;
|
2381
|
+
}
|
2416
2382
|
return {
|
2383
|
+
disabled: !canPublish || activeTab === "published" || document?.status !== "published" && document?.status !== "modified",
|
2417
2384
|
label: formatMessage({
|
2418
|
-
id: "
|
2419
|
-
defaultMessage: "
|
2385
|
+
id: "app.utils.unpublish",
|
2386
|
+
defaultMessage: "Unpublish"
|
2420
2387
|
}),
|
2421
|
-
icon: /* @__PURE__ */ jsx(
|
2422
|
-
onClick: () => {
|
2423
|
-
|
2388
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
2389
|
+
onClick: async () => {
|
2390
|
+
if (!documentId && collectionType !== SINGLE_TYPES || isDocumentModified) {
|
2391
|
+
if (!documentId) {
|
2392
|
+
console.error(
|
2393
|
+
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2394
|
+
);
|
2395
|
+
toggleNotification({
|
2396
|
+
message: formatMessage({
|
2397
|
+
id: "content-manager.actions.unpublish.error",
|
2398
|
+
defaultMessage: "An error occurred while trying to unpublish the document."
|
2399
|
+
}),
|
2400
|
+
type: "danger"
|
2401
|
+
});
|
2402
|
+
}
|
2403
|
+
return;
|
2404
|
+
}
|
2405
|
+
await unpublish({
|
2406
|
+
collectionType,
|
2407
|
+
model,
|
2408
|
+
documentId,
|
2409
|
+
params
|
2410
|
+
});
|
2424
2411
|
},
|
2425
|
-
|
2412
|
+
dialog: isDocumentModified ? {
|
2413
|
+
type: "dialog",
|
2414
|
+
title: formatMessage({
|
2415
|
+
id: "app.components.ConfirmDialog.title",
|
2416
|
+
defaultMessage: "Confirmation"
|
2417
|
+
}),
|
2418
|
+
content: /* @__PURE__ */ jsxs(Flex, { alignItems: "flex-start", direction: "column", gap: 6, children: [
|
2419
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", direction: "column", gap: 2, children: [
|
2420
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2421
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2422
|
+
id: "content-manager.actions.unpublish.dialog.body",
|
2423
|
+
defaultMessage: "Are you sure?"
|
2424
|
+
}) })
|
2425
|
+
] }),
|
2426
|
+
/* @__PURE__ */ jsxs(
|
2427
|
+
Radio.Group,
|
2428
|
+
{
|
2429
|
+
defaultValue: UNPUBLISH_DRAFT_OPTIONS.KEEP,
|
2430
|
+
name: "discard-options",
|
2431
|
+
"aria-label": formatMessage({
|
2432
|
+
id: "content-manager.actions.unpublish.dialog.radio-label",
|
2433
|
+
defaultMessage: "Choose an option to unpublish the document."
|
2434
|
+
}),
|
2435
|
+
onValueChange: handleChange,
|
2436
|
+
children: [
|
2437
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.KEEP, children: formatMessage({
|
2438
|
+
id: "content-manager.actions.unpublish.dialog.option.keep-draft",
|
2439
|
+
defaultMessage: "Keep draft"
|
2440
|
+
}) }),
|
2441
|
+
/* @__PURE__ */ jsx(Radio.Item, { checked: !shouldKeepDraft, value: UNPUBLISH_DRAFT_OPTIONS.DISCARD, children: formatMessage({
|
2442
|
+
id: "content-manager.actions.unpublish.dialog.option.replace-draft",
|
2443
|
+
defaultMessage: "Replace draft"
|
2444
|
+
}) })
|
2445
|
+
]
|
2446
|
+
}
|
2447
|
+
)
|
2448
|
+
] }),
|
2449
|
+
onConfirm: async () => {
|
2450
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2451
|
+
console.error(
|
2452
|
+
"You're trying to unpublish a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2453
|
+
);
|
2454
|
+
toggleNotification({
|
2455
|
+
message: formatMessage({
|
2456
|
+
id: "content-manager.actions.unpublish.error",
|
2457
|
+
defaultMessage: "An error occurred while trying to unpublish the document."
|
2458
|
+
}),
|
2459
|
+
type: "danger"
|
2460
|
+
});
|
2461
|
+
}
|
2462
|
+
await unpublish(
|
2463
|
+
{
|
2464
|
+
collectionType,
|
2465
|
+
model,
|
2466
|
+
documentId,
|
2467
|
+
params
|
2468
|
+
},
|
2469
|
+
!shouldKeepDraft
|
2470
|
+
);
|
2471
|
+
}
|
2472
|
+
} : void 0,
|
2473
|
+
variant: "danger",
|
2474
|
+
position: ["panel", "table-row"]
|
2426
2475
|
};
|
2427
2476
|
};
|
2428
|
-
|
2429
|
-
const
|
2430
|
-
|
2477
|
+
UnpublishAction$1.type = "unpublish";
|
2478
|
+
const DiscardAction = ({
|
2479
|
+
activeTab,
|
2480
|
+
documentId,
|
2481
|
+
model,
|
2482
|
+
collectionType,
|
2483
|
+
document
|
2484
|
+
}) => {
|
2431
2485
|
const { formatMessage } = useIntl();
|
2432
|
-
const
|
2433
|
-
const
|
2434
|
-
const {
|
2435
|
-
const {
|
2436
|
-
const
|
2486
|
+
const { schema } = useDoc();
|
2487
|
+
const canUpdate = useDocumentRBAC("DiscardAction", ({ canUpdate: canUpdate2 }) => canUpdate2);
|
2488
|
+
const { discard } = useDocumentActions();
|
2489
|
+
const [{ query }] = useQueryParams();
|
2490
|
+
const params = React.useMemo(() => buildValidParams(query), [query]);
|
2491
|
+
if (!schema?.options?.draftAndPublish) {
|
2492
|
+
return null;
|
2493
|
+
}
|
2437
2494
|
return {
|
2438
|
-
disabled: !
|
2495
|
+
disabled: !canUpdate || activeTab === "published" || document?.status !== "modified",
|
2439
2496
|
label: formatMessage({
|
2440
|
-
id: "content-manager.actions.
|
2441
|
-
defaultMessage: "
|
2497
|
+
id: "content-manager.actions.discard.label",
|
2498
|
+
defaultMessage: "Discard changes"
|
2442
2499
|
}),
|
2443
|
-
icon: /* @__PURE__ */ jsx(
|
2500
|
+
icon: /* @__PURE__ */ jsx(Cross, {}),
|
2501
|
+
position: ["panel", "table-row"],
|
2502
|
+
variant: "danger",
|
2444
2503
|
dialog: {
|
2445
2504
|
type: "dialog",
|
2446
2505
|
title: formatMessage({
|
@@ -2450,92 +2509,90 @@ const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
|
2450
2509
|
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2451
2510
|
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2452
2511
|
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2453
|
-
id: "content-manager.actions.
|
2512
|
+
id: "content-manager.actions.discard.dialog.body",
|
2454
2513
|
defaultMessage: "Are you sure?"
|
2455
2514
|
}) })
|
2456
2515
|
] }),
|
2457
2516
|
onConfirm: async () => {
|
2458
|
-
|
2459
|
-
|
2460
|
-
|
2461
|
-
|
2462
|
-
|
2463
|
-
|
2464
|
-
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2517
|
+
await discard({
|
2518
|
+
collectionType,
|
2519
|
+
model,
|
2520
|
+
documentId,
|
2521
|
+
params
|
2522
|
+
});
|
2523
|
+
}
|
2524
|
+
}
|
2525
|
+
};
|
2526
|
+
};
|
2527
|
+
DiscardAction.type = "discard";
|
2528
|
+
const DEFAULT_ACTIONS = [PublishAction$1, UpdateAction, UnpublishAction$1, DiscardAction];
|
2529
|
+
const intervals = ["years", "months", "days", "hours", "minutes", "seconds"];
|
2530
|
+
const RelativeTime = React.forwardRef(
|
2531
|
+
({ timestamp, customIntervals = [], ...restProps }, forwardedRef) => {
|
2532
|
+
const { formatRelativeTime, formatDate, formatTime } = useIntl();
|
2533
|
+
const interval = intervalToDuration({
|
2534
|
+
start: timestamp,
|
2535
|
+
end: Date.now()
|
2536
|
+
// see https://github.com/date-fns/date-fns/issues/2891 – No idea why it's all partial it returns it every time.
|
2537
|
+
});
|
2538
|
+
const unit = intervals.find((intervalUnit) => {
|
2539
|
+
return interval[intervalUnit] > 0 && Object.keys(interval).includes(intervalUnit);
|
2540
|
+
});
|
2541
|
+
const relativeTime = isPast(timestamp) ? -interval[unit] : interval[unit];
|
2542
|
+
const customInterval = customIntervals.find(
|
2543
|
+
(custom) => interval[custom.unit] < custom.threshold
|
2544
|
+
);
|
2545
|
+
const displayText = customInterval ? customInterval.text : formatRelativeTime(relativeTime, unit, { numeric: "auto" });
|
2546
|
+
return /* @__PURE__ */ jsx(
|
2547
|
+
"time",
|
2548
|
+
{
|
2549
|
+
ref: forwardedRef,
|
2550
|
+
dateTime: timestamp.toISOString(),
|
2551
|
+
role: "time",
|
2552
|
+
title: `${formatDate(timestamp)} ${formatTime(timestamp)}`,
|
2553
|
+
...restProps,
|
2554
|
+
children: displayText
|
2491
2555
|
}
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2556
|
+
);
|
2557
|
+
}
|
2558
|
+
);
|
2559
|
+
const getDisplayName = ({
|
2560
|
+
firstname,
|
2561
|
+
lastname,
|
2562
|
+
username,
|
2563
|
+
email
|
2564
|
+
} = {}) => {
|
2565
|
+
if (username) {
|
2566
|
+
return username;
|
2567
|
+
}
|
2568
|
+
if (firstname) {
|
2569
|
+
return `${firstname} ${lastname ?? ""}`.trim();
|
2570
|
+
}
|
2571
|
+
return email ?? "";
|
2496
2572
|
};
|
2497
|
-
|
2498
|
-
const
|
2499
|
-
const
|
2500
|
-
|
2501
|
-
const [
|
2502
|
-
{
|
2503
|
-
query: { status }
|
2504
|
-
}
|
2505
|
-
] = useQueryParams({
|
2506
|
-
status: "draft"
|
2507
|
-
});
|
2508
|
-
const { model, id, document, meta, collectionType } = useDoc();
|
2509
|
-
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2510
|
-
const props = {
|
2511
|
-
activeTab: status,
|
2512
|
-
model,
|
2513
|
-
documentId: id,
|
2514
|
-
document: isCloning ? void 0 : document,
|
2515
|
-
meta: isCloning ? void 0 : meta,
|
2516
|
-
collectionType
|
2517
|
-
};
|
2518
|
-
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2519
|
-
DescriptionComponentRenderer,
|
2520
|
-
{
|
2521
|
-
props,
|
2522
|
-
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2523
|
-
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2524
|
-
}
|
2525
|
-
) });
|
2573
|
+
const capitalise = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
2574
|
+
const DocumentStatus = ({ status = "draft", ...restProps }) => {
|
2575
|
+
const statusVariant = status === "draft" ? "secondary" : status === "published" ? "success" : "alternative";
|
2576
|
+
return /* @__PURE__ */ jsx(Status, { ...restProps, showBullet: false, size: "S", variant: statusVariant, children: /* @__PURE__ */ jsx(Typography, { tag: "span", variant: "omega", fontWeight: "bold", children: capitalise(status) }) });
|
2526
2577
|
};
|
2527
|
-
const
|
2578
|
+
const Header = ({ isCreating, status, title: documentTitle = "Untitled" }) => {
|
2528
2579
|
const { formatMessage } = useIntl();
|
2529
|
-
|
2530
|
-
|
2531
|
-
|
2532
|
-
|
2533
|
-
|
2534
|
-
|
2535
|
-
|
2580
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2581
|
+
const title = isCreating ? formatMessage({
|
2582
|
+
id: "content-manager.containers.edit.title.new",
|
2583
|
+
defaultMessage: "Create an entry"
|
2584
|
+
}) : documentTitle;
|
2585
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", paddingTop: 6, paddingBottom: 4, gap: 2, children: [
|
2586
|
+
/* @__PURE__ */ jsx(BackButton, {}),
|
2587
|
+
/* @__PURE__ */ jsxs(Flex, { width: "100%", justifyContent: "space-between", gap: "80px", alignItems: "flex-start", children: [
|
2588
|
+
/* @__PURE__ */ jsx(Typography, { variant: "alpha", tag: "h1", children: title }),
|
2589
|
+
/* @__PURE__ */ jsx(HeaderToolbar, {})
|
2590
|
+
] }),
|
2591
|
+
status ? /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(DocumentStatus, { status: isCloning ? "draft" : status }) }) : null
|
2592
|
+
] });
|
2536
2593
|
};
|
2537
|
-
|
2538
|
-
const
|
2594
|
+
const HeaderToolbar = () => {
|
2595
|
+
const { formatMessage } = useIntl();
|
2539
2596
|
const isCloning = useMatch(CLONE_PATH) !== null;
|
2540
2597
|
const [
|
2541
2598
|
{
|
@@ -2543,355 +2600,432 @@ const ActionsPanelContent = () => {
|
|
2543
2600
|
}
|
2544
2601
|
] = useQueryParams();
|
2545
2602
|
const { model, id, document, meta, collectionType } = useDoc();
|
2546
|
-
const plugins = useStrapiApp("
|
2547
|
-
|
2548
|
-
activeTab: status,
|
2549
|
-
model,
|
2550
|
-
documentId: id,
|
2551
|
-
document: isCloning ? void 0 : document,
|
2552
|
-
meta: isCloning ? void 0 : meta,
|
2553
|
-
collectionType
|
2554
|
-
};
|
2555
|
-
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2603
|
+
const plugins = useStrapiApp("HeaderToolbar", (state) => state.plugins);
|
2604
|
+
return /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
2556
2605
|
/* @__PURE__ */ jsx(
|
2557
2606
|
DescriptionComponentRenderer,
|
2558
2607
|
{
|
2559
|
-
props
|
2560
|
-
|
2561
|
-
|
2608
|
+
props: {
|
2609
|
+
activeTab: status,
|
2610
|
+
model,
|
2611
|
+
documentId: id,
|
2612
|
+
document: isCloning ? void 0 : document,
|
2613
|
+
meta: isCloning ? void 0 : meta,
|
2614
|
+
collectionType
|
2615
|
+
},
|
2616
|
+
descriptions: plugins["content-manager"].apis.getHeaderActions(),
|
2617
|
+
children: (actions2) => {
|
2618
|
+
if (actions2.length > 0) {
|
2619
|
+
return /* @__PURE__ */ jsx(HeaderActions, { actions: actions2 });
|
2620
|
+
} else {
|
2621
|
+
return null;
|
2622
|
+
}
|
2623
|
+
}
|
2562
2624
|
}
|
2563
2625
|
),
|
2564
|
-
/* @__PURE__ */ jsx(
|
2626
|
+
/* @__PURE__ */ jsx(
|
2627
|
+
DescriptionComponentRenderer,
|
2628
|
+
{
|
2629
|
+
props: {
|
2630
|
+
activeTab: status,
|
2631
|
+
model,
|
2632
|
+
documentId: id,
|
2633
|
+
document: isCloning ? void 0 : document,
|
2634
|
+
meta: isCloning ? void 0 : meta,
|
2635
|
+
collectionType
|
2636
|
+
},
|
2637
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2638
|
+
children: (actions2) => {
|
2639
|
+
const headerActions = actions2.filter((action) => {
|
2640
|
+
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
2641
|
+
return positions.includes("header");
|
2642
|
+
});
|
2643
|
+
return /* @__PURE__ */ jsx(
|
2644
|
+
DocumentActionsMenu,
|
2645
|
+
{
|
2646
|
+
actions: headerActions,
|
2647
|
+
label: formatMessage({
|
2648
|
+
id: "content-manager.containers.edit.header.more-actions",
|
2649
|
+
defaultMessage: "More actions"
|
2650
|
+
}),
|
2651
|
+
children: /* @__PURE__ */ jsx(Information, { activeTab: status })
|
2652
|
+
}
|
2653
|
+
);
|
2654
|
+
}
|
2655
|
+
}
|
2656
|
+
)
|
2565
2657
|
] });
|
2566
2658
|
};
|
2567
|
-
const
|
2568
|
-
|
2569
|
-
|
2659
|
+
const Information = ({ activeTab }) => {
|
2660
|
+
const { formatMessage } = useIntl();
|
2661
|
+
const { document, meta } = useDoc();
|
2662
|
+
if (!document || !document.id) {
|
2663
|
+
return null;
|
2664
|
+
}
|
2665
|
+
const createAndUpdateDocument = activeTab === "draft" ? document : meta?.availableStatus.find((status) => status.publishedAt === null);
|
2666
|
+
const publishDocument = activeTab === "published" ? document : meta?.availableStatus.find((status) => status.publishedAt !== null);
|
2667
|
+
const creator = createAndUpdateDocument?.[CREATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[CREATED_BY_ATTRIBUTE_NAME]) : null;
|
2668
|
+
const updator = createAndUpdateDocument?.[UPDATED_BY_ATTRIBUTE_NAME] ? getDisplayName(createAndUpdateDocument[UPDATED_BY_ATTRIBUTE_NAME]) : null;
|
2669
|
+
const information = [
|
2570
2670
|
{
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
borderColor: "neutral150",
|
2576
|
-
hasRadius: true,
|
2577
|
-
paddingBottom: 4,
|
2578
|
-
paddingLeft: 4,
|
2579
|
-
paddingRight: 4,
|
2580
|
-
paddingTop: 4,
|
2581
|
-
shadow: "tableShadow",
|
2582
|
-
gap: 3,
|
2583
|
-
direction: "column",
|
2584
|
-
justifyContent: "stretch",
|
2585
|
-
alignItems: "flex-start",
|
2586
|
-
children: [
|
2587
|
-
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
2588
|
-
children
|
2589
|
-
]
|
2590
|
-
}
|
2591
|
-
);
|
2592
|
-
});
|
2593
|
-
const HOOKS = {
|
2594
|
-
/**
|
2595
|
-
* Hook that allows to mutate the displayed headers of the list view table
|
2596
|
-
* @constant
|
2597
|
-
* @type {string}
|
2598
|
-
*/
|
2599
|
-
INJECT_COLUMN_IN_TABLE: "Admin/CM/pages/ListView/inject-column-in-table",
|
2600
|
-
/**
|
2601
|
-
* Hook that allows to mutate the CM's collection types links pre-set filters
|
2602
|
-
* @constant
|
2603
|
-
* @type {string}
|
2604
|
-
*/
|
2605
|
-
MUTATE_COLLECTION_TYPES_LINKS: "Admin/CM/pages/App/mutate-collection-types-links",
|
2606
|
-
/**
|
2607
|
-
* Hook that allows to mutate the CM's edit view layout
|
2608
|
-
* @constant
|
2609
|
-
* @type {string}
|
2610
|
-
*/
|
2611
|
-
MUTATE_EDIT_VIEW_LAYOUT: "Admin/CM/pages/EditView/mutate-edit-view-layout",
|
2612
|
-
/**
|
2613
|
-
* Hook that allows to mutate the CM's single types links pre-set filters
|
2614
|
-
* @constant
|
2615
|
-
* @type {string}
|
2616
|
-
*/
|
2617
|
-
MUTATE_SINGLE_TYPES_LINKS: "Admin/CM/pages/App/mutate-single-types-links"
|
2618
|
-
};
|
2619
|
-
const contentTypesApi = contentManagerApi.injectEndpoints({
|
2620
|
-
endpoints: (builder) => ({
|
2621
|
-
getContentTypeConfiguration: builder.query({
|
2622
|
-
query: (uid) => ({
|
2623
|
-
url: `/content-manager/content-types/${uid}/configuration`,
|
2624
|
-
method: "GET"
|
2671
|
+
isDisplayed: !!publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME],
|
2672
|
+
label: formatMessage({
|
2673
|
+
id: "content-manager.containers.edit.information.last-published.label",
|
2674
|
+
defaultMessage: "Published"
|
2625
2675
|
}),
|
2626
|
-
|
2627
|
-
|
2628
|
-
|
2629
|
-
|
2630
|
-
|
2631
|
-
|
2632
|
-
|
2633
|
-
|
2634
|
-
|
2635
|
-
|
2636
|
-
|
2637
|
-
|
2638
|
-
|
2639
|
-
|
2640
|
-
|
2641
|
-
|
2676
|
+
value: formatMessage(
|
2677
|
+
{
|
2678
|
+
id: "content-manager.containers.edit.information.last-published.value",
|
2679
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2680
|
+
},
|
2681
|
+
{
|
2682
|
+
time: /* @__PURE__ */ jsx(RelativeTime, { timestamp: new Date(publishDocument?.[PUBLISHED_AT_ATTRIBUTE_NAME]) }),
|
2683
|
+
isAnonymous: !publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME],
|
2684
|
+
author: publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME] ? getDisplayName(publishDocument?.[PUBLISHED_BY_ATTRIBUTE_NAME]) : null
|
2685
|
+
}
|
2686
|
+
)
|
2687
|
+
},
|
2688
|
+
{
|
2689
|
+
isDisplayed: !!createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME],
|
2690
|
+
label: formatMessage({
|
2691
|
+
id: "content-manager.containers.edit.information.last-draft.label",
|
2692
|
+
defaultMessage: "Updated"
|
2693
|
+
}),
|
2694
|
+
value: formatMessage(
|
2695
|
+
{
|
2696
|
+
id: "content-manager.containers.edit.information.last-draft.value",
|
2697
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2698
|
+
},
|
2699
|
+
{
|
2700
|
+
time: /* @__PURE__ */ jsx(
|
2701
|
+
RelativeTime,
|
2702
|
+
{
|
2703
|
+
timestamp: new Date(createAndUpdateDocument?.[UPDATED_AT_ATTRIBUTE_NAME])
|
2704
|
+
}
|
2705
|
+
),
|
2706
|
+
isAnonymous: !updator,
|
2707
|
+
author: updator
|
2708
|
+
}
|
2709
|
+
)
|
2710
|
+
},
|
2711
|
+
{
|
2712
|
+
isDisplayed: !!createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME],
|
2713
|
+
label: formatMessage({
|
2714
|
+
id: "content-manager.containers.edit.information.document.label",
|
2715
|
+
defaultMessage: "Created"
|
2642
2716
|
}),
|
2643
|
-
|
2644
|
-
|
2645
|
-
|
2646
|
-
|
2647
|
-
|
2648
|
-
{
|
2649
|
-
|
2650
|
-
|
2651
|
-
|
2652
|
-
|
2653
|
-
|
2654
|
-
|
2655
|
-
|
2656
|
-
|
2657
|
-
}
|
2658
|
-
|
2659
|
-
|
2660
|
-
|
2661
|
-
|
2662
|
-
|
2663
|
-
|
2664
|
-
|
2665
|
-
|
2666
|
-
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2717
|
+
value: formatMessage(
|
2718
|
+
{
|
2719
|
+
id: "content-manager.containers.edit.information.document.value",
|
2720
|
+
defaultMessage: `{time}{isAnonymous, select, true {} other { by {author}}}`
|
2721
|
+
},
|
2722
|
+
{
|
2723
|
+
time: /* @__PURE__ */ jsx(
|
2724
|
+
RelativeTime,
|
2725
|
+
{
|
2726
|
+
timestamp: new Date(createAndUpdateDocument?.[CREATED_AT_ATTRIBUTE_NAME])
|
2727
|
+
}
|
2728
|
+
),
|
2729
|
+
isAnonymous: !creator,
|
2730
|
+
author: creator
|
2731
|
+
}
|
2732
|
+
)
|
2733
|
+
}
|
2734
|
+
].filter((info) => info.isDisplayed);
|
2735
|
+
return /* @__PURE__ */ jsx(
|
2736
|
+
Flex,
|
2737
|
+
{
|
2738
|
+
borderWidth: "1px 0 0 0",
|
2739
|
+
borderStyle: "solid",
|
2740
|
+
borderColor: "neutral150",
|
2741
|
+
direction: "column",
|
2742
|
+
marginTop: 2,
|
2743
|
+
tag: "dl",
|
2744
|
+
padding: 5,
|
2745
|
+
gap: 3,
|
2746
|
+
alignItems: "flex-start",
|
2747
|
+
marginLeft: "-0.4rem",
|
2748
|
+
marginRight: "-0.4rem",
|
2749
|
+
width: "calc(100% + 8px)",
|
2750
|
+
children: information.map((info) => /* @__PURE__ */ jsxs(Flex, { gap: 1, direction: "column", alignItems: "flex-start", children: [
|
2751
|
+
/* @__PURE__ */ jsx(Typography, { tag: "dt", variant: "pi", fontWeight: "bold", children: info.label }),
|
2752
|
+
/* @__PURE__ */ jsx(Typography, { tag: "dd", variant: "pi", textColor: "neutral600", children: info.value })
|
2753
|
+
] }, info.label))
|
2754
|
+
}
|
2672
2755
|
);
|
2673
|
-
return {
|
2674
|
-
name: mainFieldName,
|
2675
|
-
type: mainFieldType ?? "string"
|
2676
|
-
};
|
2677
|
-
};
|
2678
|
-
const DEFAULT_SETTINGS = {
|
2679
|
-
bulkable: false,
|
2680
|
-
filterable: false,
|
2681
|
-
searchable: false,
|
2682
|
-
pagination: false,
|
2683
|
-
defaultSortBy: "",
|
2684
|
-
defaultSortOrder: "asc",
|
2685
|
-
mainField: "id",
|
2686
|
-
pageSize: 10
|
2687
2756
|
};
|
2688
|
-
const
|
2689
|
-
const
|
2690
|
-
const
|
2691
|
-
|
2692
|
-
|
2693
|
-
|
2694
|
-
|
2695
|
-
|
2696
|
-
|
2697
|
-
|
2698
|
-
error,
|
2699
|
-
isFetching: isFetchingConfigs
|
2700
|
-
} = useGetContentTypeConfigurationQuery(model);
|
2701
|
-
const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;
|
2702
|
-
React.useEffect(() => {
|
2703
|
-
if (error) {
|
2704
|
-
toggleNotification({
|
2705
|
-
type: "danger",
|
2706
|
-
message: formatAPIError(error)
|
2707
|
-
});
|
2757
|
+
const HeaderActions = ({ actions: actions2 }) => {
|
2758
|
+
const [dialogId, setDialogId] = React.useState(null);
|
2759
|
+
const handleClick = (action) => async (e) => {
|
2760
|
+
if (!("options" in action)) {
|
2761
|
+
const { onClick = () => false, dialog, id } = action;
|
2762
|
+
const muteDialog = await onClick(e);
|
2763
|
+
if (dialog && !muteDialog) {
|
2764
|
+
e.preventDefault();
|
2765
|
+
setDialogId(id);
|
2766
|
+
}
|
2708
2767
|
}
|
2709
|
-
}, [error, formatAPIError, toggleNotification]);
|
2710
|
-
const editLayout = React.useMemo(
|
2711
|
-
() => data && !isLoading ? formatEditLayout(data, { schemas, schema, components }) : {
|
2712
|
-
layout: [],
|
2713
|
-
components: {},
|
2714
|
-
metadatas: {},
|
2715
|
-
options: {},
|
2716
|
-
settings: DEFAULT_SETTINGS
|
2717
|
-
},
|
2718
|
-
[data, isLoading, schemas, schema, components]
|
2719
|
-
);
|
2720
|
-
const listLayout = React.useMemo(() => {
|
2721
|
-
return data && !isLoading ? formatListLayout(data, { schemas, schema, components }) : {
|
2722
|
-
layout: [],
|
2723
|
-
metadatas: {},
|
2724
|
-
options: {},
|
2725
|
-
settings: DEFAULT_SETTINGS
|
2726
|
-
};
|
2727
|
-
}, [data, isLoading, schemas, schema, components]);
|
2728
|
-
const { layout: edit } = React.useMemo(
|
2729
|
-
() => runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
2730
|
-
layout: editLayout,
|
2731
|
-
query
|
2732
|
-
}),
|
2733
|
-
[editLayout, query, runHookWaterfall]
|
2734
|
-
);
|
2735
|
-
return {
|
2736
|
-
error,
|
2737
|
-
isLoading,
|
2738
|
-
edit,
|
2739
|
-
list: listLayout
|
2740
2768
|
};
|
2741
|
-
|
2742
|
-
|
2743
|
-
|
2744
|
-
return
|
2745
|
-
|
2746
|
-
|
2747
|
-
|
2748
|
-
|
2749
|
-
|
2750
|
-
|
2751
|
-
|
2752
|
-
|
2753
|
-
|
2754
|
-
|
2755
|
-
|
2756
|
-
|
2757
|
-
schemas
|
2758
|
-
).reduce((panels, row) => {
|
2759
|
-
if (row.some((field) => field.type === "dynamiczone")) {
|
2760
|
-
panels.push([row]);
|
2761
|
-
currentPanelIndex += 2;
|
2769
|
+
const handleClose = () => {
|
2770
|
+
setDialogId(null);
|
2771
|
+
};
|
2772
|
+
return /* @__PURE__ */ jsx(Flex, { gap: 1, children: actions2.map((action) => {
|
2773
|
+
if (action.options) {
|
2774
|
+
return /* @__PURE__ */ jsx(
|
2775
|
+
SingleSelect,
|
2776
|
+
{
|
2777
|
+
size: "S",
|
2778
|
+
onChange: action.onSelect,
|
2779
|
+
"aria-label": action.label,
|
2780
|
+
...action,
|
2781
|
+
children: action.options.map(({ label, ...option }) => /* @__PURE__ */ jsx(SingleSelectOption, { ...option, children: label }, option.value))
|
2782
|
+
},
|
2783
|
+
action.id
|
2784
|
+
);
|
2762
2785
|
} else {
|
2763
|
-
if (
|
2764
|
-
|
2786
|
+
if (action.type === "icon") {
|
2787
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
2788
|
+
/* @__PURE__ */ jsx(
|
2789
|
+
IconButton,
|
2790
|
+
{
|
2791
|
+
disabled: action.disabled,
|
2792
|
+
label: action.label,
|
2793
|
+
size: "S",
|
2794
|
+
onClick: handleClick(action),
|
2795
|
+
children: action.icon
|
2796
|
+
}
|
2797
|
+
),
|
2798
|
+
action.dialog ? /* @__PURE__ */ jsx(
|
2799
|
+
HeaderActionDialog,
|
2800
|
+
{
|
2801
|
+
...action.dialog,
|
2802
|
+
isOpen: dialogId === action.id,
|
2803
|
+
onClose: handleClose
|
2804
|
+
}
|
2805
|
+
) : null
|
2806
|
+
] }, action.id);
|
2765
2807
|
}
|
2766
|
-
panels[currentPanelIndex].push(row);
|
2767
2808
|
}
|
2768
|
-
|
2769
|
-
|
2770
|
-
|
2771
|
-
|
2772
|
-
|
2773
|
-
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2780
|
-
|
2781
|
-
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2785
|
-
}
|
2786
|
-
|
2787
|
-
|
2788
|
-
|
2789
|
-
|
2790
|
-
|
2791
|
-
|
2792
|
-
|
2793
|
-
|
2809
|
+
}) });
|
2810
|
+
};
|
2811
|
+
const HeaderActionDialog = ({
|
2812
|
+
onClose,
|
2813
|
+
onCancel,
|
2814
|
+
title,
|
2815
|
+
content: Content,
|
2816
|
+
isOpen
|
2817
|
+
}) => {
|
2818
|
+
const handleClose = async () => {
|
2819
|
+
if (onCancel) {
|
2820
|
+
await onCancel();
|
2821
|
+
}
|
2822
|
+
onClose();
|
2823
|
+
};
|
2824
|
+
return /* @__PURE__ */ jsx(Dialog.Root, { open: isOpen, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Dialog.Content, { children: [
|
2825
|
+
/* @__PURE__ */ jsx(Dialog.Header, { children: title }),
|
2826
|
+
typeof Content === "function" ? /* @__PURE__ */ jsx(Content, { onClose: handleClose }) : Content
|
2827
|
+
] }) });
|
2828
|
+
};
|
2829
|
+
const ConfigureTheViewAction = ({ collectionType, model }) => {
|
2830
|
+
const navigate = useNavigate();
|
2831
|
+
const { formatMessage } = useIntl();
|
2832
|
+
return {
|
2833
|
+
label: formatMessage({
|
2834
|
+
id: "app.links.configure-view",
|
2835
|
+
defaultMessage: "Configure the view"
|
2836
|
+
}),
|
2837
|
+
icon: /* @__PURE__ */ jsx(ListPlus, {}),
|
2838
|
+
onClick: () => {
|
2839
|
+
navigate(`../${collectionType}/${model}/configurations/edit`);
|
2794
2840
|
},
|
2795
|
-
|
2796
|
-
|
2841
|
+
position: "header"
|
2842
|
+
};
|
2843
|
+
};
|
2844
|
+
ConfigureTheViewAction.type = "configure-the-view";
|
2845
|
+
const EditTheModelAction = ({ model }) => {
|
2846
|
+
const navigate = useNavigate();
|
2847
|
+
const { formatMessage } = useIntl();
|
2797
2848
|
return {
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2801
|
-
|
2802
|
-
|
2803
|
-
|
2849
|
+
label: formatMessage({
|
2850
|
+
id: "content-manager.link-to-ctb",
|
2851
|
+
defaultMessage: "Edit the model"
|
2852
|
+
}),
|
2853
|
+
icon: /* @__PURE__ */ jsx(Pencil, {}),
|
2854
|
+
onClick: () => {
|
2855
|
+
navigate(`/plugins/content-type-builder/content-types/${model}`);
|
2804
2856
|
},
|
2805
|
-
|
2806
|
-
...schema?.options,
|
2807
|
-
...schema?.pluginOptions,
|
2808
|
-
...data.contentType.options
|
2809
|
-
}
|
2857
|
+
position: "header"
|
2810
2858
|
};
|
2811
2859
|
};
|
2812
|
-
|
2813
|
-
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2860
|
+
EditTheModelAction.type = "edit-the-model";
|
2861
|
+
const DeleteAction$1 = ({ documentId, model, collectionType, document }) => {
|
2862
|
+
const navigate = useNavigate();
|
2863
|
+
const { formatMessage } = useIntl();
|
2864
|
+
const listViewPathMatch = useMatch(LIST_PATH);
|
2865
|
+
const canDelete = useDocumentRBAC("DeleteAction", (state) => state.canDelete);
|
2866
|
+
const { delete: deleteAction } = useDocumentActions();
|
2867
|
+
const { toggleNotification } = useNotification();
|
2868
|
+
const setSubmitting = useForm("DeleteAction", (state) => state.setSubmitting);
|
2869
|
+
const isLocalized = document?.locale != null;
|
2870
|
+
return {
|
2871
|
+
disabled: !canDelete || !document,
|
2872
|
+
label: formatMessage(
|
2873
|
+
{
|
2874
|
+
id: "content-manager.actions.delete.label",
|
2875
|
+
defaultMessage: "Delete entry{isLocalized, select, true { (all locales)} other {}}"
|
2876
|
+
},
|
2877
|
+
{ isLocalized }
|
2878
|
+
),
|
2879
|
+
icon: /* @__PURE__ */ jsx(Trash, {}),
|
2880
|
+
dialog: {
|
2881
|
+
type: "dialog",
|
2882
|
+
title: formatMessage({
|
2883
|
+
id: "app.components.ConfirmDialog.title",
|
2884
|
+
defaultMessage: "Confirmation"
|
2885
|
+
}),
|
2886
|
+
content: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
2887
|
+
/* @__PURE__ */ jsx(WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
|
2888
|
+
/* @__PURE__ */ jsx(Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
|
2889
|
+
id: "content-manager.actions.delete.dialog.body",
|
2890
|
+
defaultMessage: "Are you sure?"
|
2891
|
+
}) })
|
2892
|
+
] }),
|
2893
|
+
onConfirm: async () => {
|
2894
|
+
if (!listViewPathMatch) {
|
2895
|
+
setSubmitting(true);
|
2896
|
+
}
|
2897
|
+
try {
|
2898
|
+
if (!documentId && collectionType !== SINGLE_TYPES) {
|
2899
|
+
console.error(
|
2900
|
+
"You're trying to delete a document without an id, this is likely a bug with Strapi. Please open an issue."
|
2901
|
+
);
|
2902
|
+
toggleNotification({
|
2903
|
+
message: formatMessage({
|
2904
|
+
id: "content-manager.actions.delete.error",
|
2905
|
+
defaultMessage: "An error occurred while trying to delete the document."
|
2906
|
+
}),
|
2907
|
+
type: "danger"
|
2908
|
+
});
|
2909
|
+
return;
|
2910
|
+
}
|
2911
|
+
const res = await deleteAction({
|
2912
|
+
documentId,
|
2913
|
+
model,
|
2914
|
+
collectionType,
|
2915
|
+
params: {
|
2916
|
+
locale: "*"
|
2917
|
+
}
|
2918
|
+
});
|
2919
|
+
if (!("error" in res)) {
|
2920
|
+
navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
|
2921
|
+
}
|
2922
|
+
} finally {
|
2923
|
+
if (!listViewPathMatch) {
|
2924
|
+
setSubmitting(false);
|
2925
|
+
}
|
2926
|
+
}
|
2818
2927
|
}
|
2819
|
-
const { edit: metadata } = metadatas[field.name];
|
2820
|
-
const settings = attribute.type === "component" && components ? components.configurations[attribute.component].settings : {};
|
2821
|
-
return {
|
2822
|
-
attribute,
|
2823
|
-
disabled: !metadata.editable,
|
2824
|
-
hint: metadata.description,
|
2825
|
-
label: metadata.label ?? "",
|
2826
|
-
name: field.name,
|
2827
|
-
// @ts-expect-error – mainField does exist on the metadata for a relation.
|
2828
|
-
mainField: getMainField(attribute, metadata.mainField || settings.mainField, {
|
2829
|
-
schemas,
|
2830
|
-
components: components?.schemas ?? {}
|
2831
|
-
}),
|
2832
|
-
placeholder: metadata.placeholder ?? "",
|
2833
|
-
required: attribute.required ?? false,
|
2834
|
-
size: field.size,
|
2835
|
-
unique: "unique" in attribute ? attribute.unique : false,
|
2836
|
-
visible: metadata.visible ?? true,
|
2837
|
-
type: attribute.type
|
2838
|
-
};
|
2839
|
-
}).filter((field) => field !== null)
|
2840
|
-
);
|
2841
|
-
};
|
2842
|
-
const formatListLayout = (data, {
|
2843
|
-
schemas,
|
2844
|
-
schema,
|
2845
|
-
components
|
2846
|
-
}) => {
|
2847
|
-
const listMetadatas = Object.entries(data.contentType.metadatas).reduce(
|
2848
|
-
(acc, [attribute, metadata]) => {
|
2849
|
-
return {
|
2850
|
-
...acc,
|
2851
|
-
[attribute]: metadata.list
|
2852
|
-
};
|
2853
2928
|
},
|
2854
|
-
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2860
|
-
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
2864
|
-
|
2865
|
-
|
2866
|
-
|
2867
|
-
|
2868
|
-
|
2869
|
-
|
2870
|
-
|
2929
|
+
variant: "danger",
|
2930
|
+
position: ["header", "table-row"]
|
2931
|
+
};
|
2932
|
+
};
|
2933
|
+
DeleteAction$1.type = "delete";
|
2934
|
+
const DEFAULT_HEADER_ACTIONS = [EditTheModelAction, ConfigureTheViewAction, DeleteAction$1];
|
2935
|
+
const Panels = () => {
|
2936
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2937
|
+
const [
|
2938
|
+
{
|
2939
|
+
query: { status }
|
2940
|
+
}
|
2941
|
+
] = useQueryParams({
|
2942
|
+
status: "draft"
|
2943
|
+
});
|
2944
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2945
|
+
const plugins = useStrapiApp("Panels", (state) => state.plugins);
|
2946
|
+
const props = {
|
2947
|
+
activeTab: status,
|
2948
|
+
model,
|
2949
|
+
documentId: id,
|
2950
|
+
document: isCloning ? void 0 : document,
|
2951
|
+
meta: isCloning ? void 0 : meta,
|
2952
|
+
collectionType
|
2953
|
+
};
|
2954
|
+
return /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: /* @__PURE__ */ jsx(
|
2955
|
+
DescriptionComponentRenderer,
|
2956
|
+
{
|
2957
|
+
props,
|
2958
|
+
descriptions: plugins["content-manager"].apis.getEditViewSidePanels(),
|
2959
|
+
children: (panels) => panels.map(({ content, id: id2, ...description }) => /* @__PURE__ */ jsx(Panel, { ...description, children: content }, id2))
|
2871
2960
|
}
|
2961
|
+
) });
|
2962
|
+
};
|
2963
|
+
const ActionsPanel = () => {
|
2964
|
+
const { formatMessage } = useIntl();
|
2965
|
+
return {
|
2966
|
+
title: formatMessage({
|
2967
|
+
id: "content-manager.containers.edit.panels.default.title",
|
2968
|
+
defaultMessage: "Entry"
|
2969
|
+
}),
|
2970
|
+
content: /* @__PURE__ */ jsx(ActionsPanelContent, {})
|
2872
2971
|
};
|
2873
2972
|
};
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2973
|
+
ActionsPanel.type = "actions";
|
2974
|
+
const ActionsPanelContent = () => {
|
2975
|
+
const isCloning = useMatch(CLONE_PATH) !== null;
|
2976
|
+
const [
|
2977
|
+
{
|
2978
|
+
query: { status = "draft" }
|
2879
2979
|
}
|
2880
|
-
|
2881
|
-
|
2882
|
-
|
2883
|
-
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2980
|
+
] = useQueryParams();
|
2981
|
+
const { model, id, document, meta, collectionType } = useDoc();
|
2982
|
+
const plugins = useStrapiApp("ActionsPanel", (state) => state.plugins);
|
2983
|
+
const props = {
|
2984
|
+
activeTab: status,
|
2985
|
+
model,
|
2986
|
+
documentId: id,
|
2987
|
+
document: isCloning ? void 0 : document,
|
2988
|
+
meta: isCloning ? void 0 : meta,
|
2989
|
+
collectionType
|
2990
|
+
};
|
2991
|
+
return /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, width: "100%", children: [
|
2992
|
+
/* @__PURE__ */ jsx(
|
2993
|
+
DescriptionComponentRenderer,
|
2994
|
+
{
|
2995
|
+
props,
|
2996
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
2997
|
+
children: (actions2) => /* @__PURE__ */ jsx(DocumentActions, { actions: actions2 })
|
2998
|
+
}
|
2999
|
+
),
|
3000
|
+
/* @__PURE__ */ jsx(InjectionZone, { area: "editView.right-links", slug: model })
|
3001
|
+
] });
|
2894
3002
|
};
|
3003
|
+
const Panel = React.forwardRef(({ children, title }, ref) => {
|
3004
|
+
return /* @__PURE__ */ jsxs(
|
3005
|
+
Flex,
|
3006
|
+
{
|
3007
|
+
ref,
|
3008
|
+
tag: "aside",
|
3009
|
+
"aria-labelledby": "additional-information",
|
3010
|
+
background: "neutral0",
|
3011
|
+
borderColor: "neutral150",
|
3012
|
+
hasRadius: true,
|
3013
|
+
paddingBottom: 4,
|
3014
|
+
paddingLeft: 4,
|
3015
|
+
paddingRight: 4,
|
3016
|
+
paddingTop: 4,
|
3017
|
+
shadow: "tableShadow",
|
3018
|
+
gap: 3,
|
3019
|
+
direction: "column",
|
3020
|
+
justifyContent: "stretch",
|
3021
|
+
alignItems: "flex-start",
|
3022
|
+
children: [
|
3023
|
+
/* @__PURE__ */ jsx(Typography, { tag: "h2", variant: "sigma", textTransform: "uppercase", children: title }),
|
3024
|
+
children
|
3025
|
+
]
|
3026
|
+
}
|
3027
|
+
);
|
3028
|
+
});
|
2895
3029
|
const ConfirmBulkActionDialog = ({
|
2896
3030
|
onToggleDialog,
|
2897
3031
|
isOpen = false,
|
@@ -2930,6 +3064,7 @@ const ConfirmDialogPublishAll = ({
|
|
2930
3064
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler(getTranslation);
|
2931
3065
|
const { model, schema } = useDoc();
|
2932
3066
|
const [{ query }] = useQueryParams();
|
3067
|
+
const enableDraftRelationsCount = false;
|
2933
3068
|
const {
|
2934
3069
|
data: countDraftRelations = 0,
|
2935
3070
|
isLoading,
|
@@ -2941,7 +3076,7 @@ const ConfirmDialogPublishAll = ({
|
|
2941
3076
|
locale: query?.plugins?.i18n?.locale
|
2942
3077
|
},
|
2943
3078
|
{
|
2944
|
-
skip:
|
3079
|
+
skip: !enableDraftRelationsCount
|
2945
3080
|
}
|
2946
3081
|
);
|
2947
3082
|
React.useEffect(() => {
|
@@ -3126,7 +3261,7 @@ const SelectedEntriesTableContent = ({
|
|
3126
3261
|
status: row.status
|
3127
3262
|
}
|
3128
3263
|
) }),
|
3129
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(
|
3264
|
+
/* @__PURE__ */ jsx(Table.Cell, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
|
3130
3265
|
IconButton,
|
3131
3266
|
{
|
3132
3267
|
tag: Link,
|
@@ -3149,9 +3284,10 @@ const SelectedEntriesTableContent = ({
|
|
3149
3284
|
),
|
3150
3285
|
target: "_blank",
|
3151
3286
|
marginLeft: "auto",
|
3152
|
-
|
3287
|
+
variant: "ghost",
|
3288
|
+
children: /* @__PURE__ */ jsx(Pencil, { width: "1.6rem", height: "1.6rem" })
|
3153
3289
|
}
|
3154
|
-
) })
|
3290
|
+
) }) })
|
3155
3291
|
] }, row.id)) })
|
3156
3292
|
] });
|
3157
3293
|
};
|
@@ -3188,7 +3324,13 @@ const SelectedEntriesModalContent = ({
|
|
3188
3324
|
);
|
3189
3325
|
const { rows, validationErrors } = React.useMemo(() => {
|
3190
3326
|
if (data.length > 0 && schema) {
|
3191
|
-
const validate = createYupSchema(
|
3327
|
+
const validate = createYupSchema(
|
3328
|
+
schema.attributes,
|
3329
|
+
components,
|
3330
|
+
// Since this is the "Publish" action, the validation
|
3331
|
+
// schema must enforce the rules for published entities
|
3332
|
+
{ status: "published" }
|
3333
|
+
);
|
3192
3334
|
const validationErrors2 = {};
|
3193
3335
|
const rows2 = data.map((entry) => {
|
3194
3336
|
try {
|
@@ -3538,7 +3680,7 @@ const TableActions = ({ document }) => {
|
|
3538
3680
|
DescriptionComponentRenderer,
|
3539
3681
|
{
|
3540
3682
|
props,
|
3541
|
-
descriptions: plugins["content-manager"].apis.getDocumentActions(),
|
3683
|
+
descriptions: plugins["content-manager"].apis.getDocumentActions().filter((action) => action.name !== "PublishAction"),
|
3542
3684
|
children: (actions2) => {
|
3543
3685
|
const tableRowActions = actions2.filter((action) => {
|
3544
3686
|
const positions = Array.isArray(action.position) ? action.position : [action.position];
|
@@ -3649,7 +3791,7 @@ const CloneAction = ({ model, documentId }) => {
|
|
3649
3791
|
}),
|
3650
3792
|
content: /* @__PURE__ */ jsx(AutoCloneFailureModalBody, { prohibitedFields }),
|
3651
3793
|
footer: ({ onClose }) => {
|
3652
|
-
return /* @__PURE__ */ jsxs(
|
3794
|
+
return /* @__PURE__ */ jsxs(Modal.Footer, { children: [
|
3653
3795
|
/* @__PURE__ */ jsx(Button, { onClick: onClose, variant: "tertiary", children: formatMessage({
|
3654
3796
|
id: "cancel",
|
3655
3797
|
defaultMessage: "Cancel"
|
@@ -3880,7 +4022,7 @@ const index = {
|
|
3880
4022
|
app.router.addRoute({
|
3881
4023
|
path: "content-manager/*",
|
3882
4024
|
lazy: async () => {
|
3883
|
-
const { Layout } = await import("./layout-
|
4025
|
+
const { Layout } = await import("./layout-BavJ6v4B.mjs");
|
3884
4026
|
return {
|
3885
4027
|
Component: Layout
|
3886
4028
|
};
|
@@ -3897,7 +4039,7 @@ const index = {
|
|
3897
4039
|
async registerTrads({ locales }) {
|
3898
4040
|
const importedTrads = await Promise.all(
|
3899
4041
|
locales.map((locale) => {
|
3900
|
-
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-
|
4042
|
+
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-DKV44jRb.mjs"), "./translations/es.json": () => import("./es-CeXiYflN.mjs"), "./translations/eu.json": () => import("./eu-CdALomew.mjs"), "./translations/fr.json": () => import("./fr-CD9VFbPM.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-CtsUxOvk.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 }) => {
|
3901
4043
|
return {
|
3902
4044
|
data: prefixPluginTranslations(data, PLUGIN_ID),
|
3903
4045
|
locale
|
@@ -3918,13 +4060,15 @@ export {
|
|
3918
4060
|
BulkActionsRenderer as B,
|
3919
4061
|
COLLECTION_TYPES as C,
|
3920
4062
|
DocumentStatus as D,
|
3921
|
-
|
3922
|
-
|
3923
|
-
|
4063
|
+
extractContentTypeComponents as E,
|
4064
|
+
DEFAULT_SETTINGS as F,
|
4065
|
+
convertEditLayoutToFieldLayouts as G,
|
3924
4066
|
HOOKS as H,
|
3925
4067
|
InjectionZone as I,
|
3926
|
-
|
3927
|
-
|
4068
|
+
useDocument as J,
|
4069
|
+
index as K,
|
4070
|
+
useContentManagerContext as L,
|
4071
|
+
useDocumentActions as M,
|
3928
4072
|
Panels as P,
|
3929
4073
|
RelativeTime as R,
|
3930
4074
|
SINGLE_TYPES as S,
|
@@ -3942,18 +4086,18 @@ export {
|
|
3942
4086
|
PERMISSIONS as k,
|
3943
4087
|
DocumentRBAC as l,
|
3944
4088
|
DOCUMENT_META_FIELDS as m,
|
3945
|
-
|
3946
|
-
|
3947
|
-
|
3948
|
-
|
3949
|
-
|
4089
|
+
CLONE_PATH as n,
|
4090
|
+
useDocLayout as o,
|
4091
|
+
useGetContentTypeConfigurationQuery as p,
|
4092
|
+
CREATOR_FIELDS as q,
|
4093
|
+
getMainField as r,
|
3950
4094
|
setInitialData as s,
|
3951
|
-
|
4095
|
+
getDisplayName as t,
|
3952
4096
|
useContentTypeSchema as u,
|
3953
|
-
|
3954
|
-
|
3955
|
-
|
3956
|
-
|
3957
|
-
|
4097
|
+
checkIfAttributeIsDisplayable as v,
|
4098
|
+
useGetAllDocumentsQuery as w,
|
4099
|
+
convertListLayoutToFieldLayouts as x,
|
4100
|
+
capitalise as y,
|
4101
|
+
useUpdateContentTypeConfigurationMutation as z
|
3958
4102
|
};
|
3959
|
-
//# sourceMappingURL=index-
|
4103
|
+
//# sourceMappingURL=index-DcQ6xogO.mjs.map
|