@strapi/content-manager 5.13.0-beta.0 → 5.13.0-beta.1
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/admin/components/LeftMenu.js +34 -30
- package/dist/admin/components/LeftMenu.js.map +1 -1
- package/dist/admin/components/LeftMenu.mjs +36 -32
- package/dist/admin/components/LeftMenu.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentActions.js +1 -5
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs +1 -5
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentContext.js.map +1 -1
- package/dist/admin/hooks/useDocumentContext.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js +21 -206
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +23 -208
- package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +137 -199
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs +137 -199
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +50 -89
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +52 -91
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +77 -0
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs +78 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
- package/dist/admin/src/hooks/useDocumentContext.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations/RelationModal.d.ts +5 -26
- package/dist/admin/translations/en.json.js +1 -2
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +1 -2
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/server/src/index.d.ts +1 -0
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/services/data-mapper.d.ts +1 -0
- package/dist/server/src/services/data-mapper.d.ts.map +1 -1
- package/dist/server/src/services/homepage.d.ts +11 -0
- package/dist/server/src/services/homepage.d.ts.map +1 -0
- package/dist/server/src/services/index.d.ts +1 -0
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/package.json +5 -5
@@ -4,57 +4,21 @@ import { useNotification, useAPIErrorHandler, useQueryParams, useForm } from '@s
|
|
4
4
|
import { Menu, Flex, Button, VisuallyHidden, Dialog, Modal, Typography, Radio } from '@strapi/design-system';
|
5
5
|
import { More, Cross, WarningCircle } from '@strapi/icons';
|
6
6
|
import mapValues from 'lodash/fp/mapValues';
|
7
|
-
import get from 'lodash/get';
|
8
|
-
import merge from 'lodash/merge';
|
9
|
-
import set from 'lodash/set';
|
10
7
|
import { useIntl } from 'react-intl';
|
11
8
|
import { useNavigate, useMatch, useParams } from 'react-router-dom';
|
12
9
|
import { styled } from 'styled-components';
|
13
10
|
import { PUBLISHED_AT_ATTRIBUTE_NAME } from '../../../constants/attributes.mjs';
|
14
11
|
import { SINGLE_TYPES } from '../../../constants/collections.mjs';
|
15
12
|
import { useDocumentRBAC } from '../../../features/DocumentRBAC.mjs';
|
16
|
-
import {
|
13
|
+
import { useDoc } from '../../../hooks/useDocument.mjs';
|
17
14
|
import { useDocumentActions } from '../../../hooks/useDocumentActions.mjs';
|
18
15
|
import { useDocumentContext } from '../../../hooks/useDocumentContext.mjs';
|
19
16
|
import { usePreviewContext } from '../../../preview/pages/Preview.mjs';
|
20
17
|
import { LIST_PATH, CLONE_PATH } from '../../../router.mjs';
|
21
|
-
import { useGetDraftRelationCountQuery as useLazyGetDraftRelationCountQuery
|
18
|
+
import { useGetDraftRelationCountQuery as useLazyGetDraftRelationCountQuery } from '../../../services/documents.mjs';
|
22
19
|
import { isBaseQueryError, buildValidParams } from '../../../utils/api.mjs';
|
23
20
|
import { getTranslation } from '../../../utils/translations.mjs';
|
24
|
-
import { useRelationModal } from './FormInputs/Relations/RelationModal.mjs';
|
25
21
|
|
26
|
-
const connectRelationToParent = (parentDataToUpdate, fieldToConnect, data, fieldToConnectUID)=>{
|
27
|
-
/*
|
28
|
-
* Check if the fieldToConnect is already present in the parentDataToUpdate.
|
29
|
-
* This happens in particular when in the parentDocument you have created
|
30
|
-
* a new component without saving.
|
31
|
-
*/ const isFieldPresent = !!get(parentDataToUpdate, fieldToConnect);
|
32
|
-
const fieldToConnectPath = isFieldPresent ? fieldToConnect : fieldToConnect.split('.').slice(0, -1).join('.');
|
33
|
-
const fieldToConnectValue = isFieldPresent ? {
|
34
|
-
connect: [
|
35
|
-
{
|
36
|
-
id: data.documentId,
|
37
|
-
documentId: data.documentId,
|
38
|
-
locale: data.locale
|
39
|
-
}
|
40
|
-
]
|
41
|
-
} : {
|
42
|
-
[fieldToConnect.split('.').pop()]: {
|
43
|
-
connect: [
|
44
|
-
{
|
45
|
-
id: data.documentId,
|
46
|
-
documentId: data.documentId,
|
47
|
-
locale: data.locale
|
48
|
-
}
|
49
|
-
],
|
50
|
-
disconnect: []
|
51
|
-
},
|
52
|
-
// In case the object was not present you need to pass the componentUID of the parent document
|
53
|
-
__component: fieldToConnectUID
|
54
|
-
};
|
55
|
-
const objectToConnect = set({}, fieldToConnectPath, fieldToConnectValue);
|
56
|
-
return merge(parentDataToUpdate, objectToConnect);
|
57
|
-
};
|
58
22
|
const DocumentActions = ({ actions })=>{
|
59
23
|
const { formatMessage } = useIntl();
|
60
24
|
const [primaryAction, secondaryAction, ...restActions] = actions.filter((action)=>{
|
@@ -410,17 +374,7 @@ const transformData = (data)=>{
|
|
410
374
|
const setErrors = useForm('PublishAction', (state)=>state.setErrors);
|
411
375
|
const formValues = useForm('PublishAction', ({ values })=>values);
|
412
376
|
const resetForm = useForm('PublishAction', ({ resetForm })=>resetForm);
|
413
|
-
// need to discriminate if the publish is coming from a relation modal or in the edit view
|
414
|
-
const relationContext = useRelationModal('PublishAction', ()=>true, false);
|
415
|
-
const fromRelationModal = relationContext != undefined;
|
416
|
-
const dispatch = useRelationModal('PublishAction', (state)=>state.dispatch);
|
417
|
-
const fieldToConnect = useRelationModal('PublishAction', (state)=>state.state.fieldToConnect, false);
|
418
|
-
const fieldToConnectUID = useRelationModal('PublishAction', (state)=>state.state.fieldToConnectUID, false);
|
419
|
-
const documentHistory = useRelationModal('PublishAction', (state)=>state.state.documentHistory, false);
|
420
|
-
const rootDocumentMeta = useRelationModal('PublishAction', (state)=>state.rootDocumentMeta);
|
421
377
|
const { currentDocumentMeta } = useDocumentContext('PublishAction');
|
422
|
-
const [updateDocumentMutation] = useUpdateDocumentMutation();
|
423
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
424
378
|
const idToPublish = currentDocumentMeta.documentId || id;
|
425
379
|
React.useEffect(()=>{
|
426
380
|
if (isErrorDraftRelations) {
|
@@ -504,16 +458,6 @@ const transformData = (data)=>{
|
|
504
458
|
model,
|
505
459
|
currentDocumentMeta.params
|
506
460
|
]);
|
507
|
-
const parentDocumentMetaToUpdate = documentHistory?.at(-2) ?? rootDocumentMeta;
|
508
|
-
const parentDocumentData = useDocument({
|
509
|
-
documentId: parentDocumentMetaToUpdate?.documentId,
|
510
|
-
model: parentDocumentMetaToUpdate?.model,
|
511
|
-
collectionType: parentDocumentMetaToUpdate?.collectionType,
|
512
|
-
params: parentDocumentMetaToUpdate?.params
|
513
|
-
}, {
|
514
|
-
skip: !parentDocumentMetaToUpdate
|
515
|
-
});
|
516
|
-
const { getInitialFormValues } = useDoc();
|
517
461
|
const isDocumentPublished = (document?.[PUBLISHED_AT_ATTRIBUTE_NAME] || meta?.availableStatus.some((doc)=>doc[PUBLISHED_AT_ATTRIBUTE_NAME] !== null)) && document?.status !== 'modified';
|
518
462
|
if (!schema?.options?.draftAndPublish) {
|
519
463
|
return null;
|
@@ -547,59 +491,11 @@ const transformData = (data)=>{
|
|
547
491
|
if ('data' in res && collectionType !== SINGLE_TYPES) {
|
548
492
|
/**
|
549
493
|
* TODO: refactor the router so we can just do `../${res.data.documentId}` instead of this.
|
550
|
-
*/ if (idToPublish === 'create'
|
494
|
+
*/ if (idToPublish === 'create') {
|
551
495
|
navigate({
|
552
496
|
pathname: `../${collectionType}/${model}/${res.data.documentId}`,
|
553
497
|
search: rawQuery
|
554
498
|
});
|
555
|
-
} else if (fromRelationModal) {
|
556
|
-
const newRelation = {
|
557
|
-
documentId: res.data.documentId,
|
558
|
-
collectionType,
|
559
|
-
model,
|
560
|
-
params: currentDocumentMeta.params
|
561
|
-
};
|
562
|
-
/*
|
563
|
-
* Update, if needed, the parent relation with the newly published document.
|
564
|
-
* Check if in history we have the parent relation otherwise use the
|
565
|
-
* rootDocument
|
566
|
-
*/ if (fieldToConnect && documentHistory && (parentDocumentMetaToUpdate.documentId || parentDocumentMetaToUpdate.collectionType === SINGLE_TYPES)) {
|
567
|
-
const parentDataToUpdate = parentDocumentMetaToUpdate.collectionType === SINGLE_TYPES ? getInitialFormValues() : parentDocumentData.getInitialFormValues();
|
568
|
-
const metaDocumentToUpdate = documentHistory.at(-2) ?? rootDocumentMeta;
|
569
|
-
const dataToUpdate = connectRelationToParent(parentDataToUpdate, fieldToConnect, res.data, fieldToConnectUID);
|
570
|
-
try {
|
571
|
-
const updateRes = await updateDocumentMutation({
|
572
|
-
collectionType: metaDocumentToUpdate.collectionType,
|
573
|
-
model: metaDocumentToUpdate.model,
|
574
|
-
documentId: metaDocumentToUpdate.collectionType !== SINGLE_TYPES ? metaDocumentToUpdate.documentId : undefined,
|
575
|
-
params: metaDocumentToUpdate.params,
|
576
|
-
data: dataToUpdate
|
577
|
-
});
|
578
|
-
if ('error' in updateRes) {
|
579
|
-
toggleNotification({
|
580
|
-
type: 'danger',
|
581
|
-
message: formatAPIError(updateRes.error)
|
582
|
-
});
|
583
|
-
return;
|
584
|
-
}
|
585
|
-
} catch (err) {
|
586
|
-
toggleNotification({
|
587
|
-
type: 'danger',
|
588
|
-
message: formatMessage({
|
589
|
-
id: 'notification.error',
|
590
|
-
defaultMessage: 'An error occurred'
|
591
|
-
})
|
592
|
-
});
|
593
|
-
throw err;
|
594
|
-
}
|
595
|
-
}
|
596
|
-
dispatch({
|
597
|
-
type: 'GO_TO_CREATED_RELATION',
|
598
|
-
payload: {
|
599
|
-
document: newRelation,
|
600
|
-
shouldBypassConfirmation: true
|
601
|
-
}
|
602
|
-
});
|
603
499
|
}
|
604
500
|
} else if ('error' in res && isBaseQueryError(res.error) && res.error.name === 'ValidationError') {
|
605
501
|
setErrors(formatValidationErrors(res.error));
|
@@ -675,34 +571,14 @@ const UpdateAction = ({ activeTab, documentId, model, collectionType })=>{
|
|
675
571
|
const { create, update, clone, isLoading } = useDocumentActions();
|
676
572
|
const [{ rawQuery }] = useQueryParams();
|
677
573
|
const onPreview = usePreviewContext('UpdateAction', (state)=>state.onPreview, false);
|
678
|
-
const { getInitialFormValues } = useDoc();
|
679
574
|
const isSubmitting = useForm('UpdateAction', ({ isSubmitting })=>isSubmitting);
|
680
575
|
const modified = useForm('UpdateAction', ({ modified })=>modified);
|
681
576
|
const setSubmitting = useForm('UpdateAction', ({ setSubmitting })=>setSubmitting);
|
682
577
|
const document = useForm('UpdateAction', ({ values })=>values);
|
683
578
|
const validate = useForm('UpdateAction', (state)=>state.validate);
|
684
579
|
const setErrors = useForm('UpdateAction', (state)=>state.setErrors);
|
685
|
-
const resetForm = useForm('
|
686
|
-
const dispatch = useRelationModal('UpdateAction', (state)=>state.dispatch);
|
687
|
-
// need to discriminate if the update is coming from a relation modal or in the edit view
|
688
|
-
const relationContext = useRelationModal('UpdateAction', ()=>true, false);
|
689
|
-
const fieldToConnect = useRelationModal('UpdateAction', (state)=>state.state.fieldToConnect, false);
|
690
|
-
const fieldToConnectUID = useRelationModal('PublishAction', (state)=>state.state.fieldToConnectUID, false);
|
691
|
-
const documentHistory = useRelationModal('UpdateAction', (state)=>state.state.documentHistory, false);
|
692
|
-
const rootDocumentMeta = useRelationModal('UpdateAction', (state)=>state.rootDocumentMeta);
|
693
|
-
const fromRelationModal = relationContext != undefined;
|
580
|
+
const resetForm = useForm('PublishAction', ({ resetForm })=>resetForm);
|
694
581
|
const { currentDocumentMeta } = useDocumentContext('UpdateAction');
|
695
|
-
const [updateDocumentMutation] = useUpdateDocumentMutation();
|
696
|
-
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
697
|
-
const parentDocumentMetaToUpdate = documentHistory?.at(-2) ?? rootDocumentMeta;
|
698
|
-
const parentDocumentData = useDocument({
|
699
|
-
documentId: parentDocumentMetaToUpdate?.documentId,
|
700
|
-
model: parentDocumentMetaToUpdate?.model,
|
701
|
-
collectionType: parentDocumentMetaToUpdate?.collectionType,
|
702
|
-
params: parentDocumentMetaToUpdate?.params
|
703
|
-
}, {
|
704
|
-
skip: !parentDocumentMetaToUpdate
|
705
|
-
});
|
706
582
|
const handleUpdate = React.useCallback(async ()=>{
|
707
583
|
setSubmitting(true);
|
708
584
|
try {
|
@@ -756,64 +632,13 @@ const UpdateAction = ({ activeTab, documentId, model, collectionType })=>{
|
|
756
632
|
params: currentDocumentMeta.params
|
757
633
|
}, transformData(document));
|
758
634
|
if ('data' in res && collectionType !== SINGLE_TYPES) {
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
/*
|
767
|
-
* Update, if needed, the parent relation with the newly published document.
|
768
|
-
* Check if in history we have the parent relation otherwise use the
|
769
|
-
* rootDocument
|
770
|
-
*/ if (fieldToConnect && documentHistory && (parentDocumentMetaToUpdate.documentId || parentDocumentMetaToUpdate.collectionType === SINGLE_TYPES)) {
|
771
|
-
const parentDataToUpdate = parentDocumentMetaToUpdate.collectionType === SINGLE_TYPES ? getInitialFormValues() : parentDocumentData.getInitialFormValues();
|
772
|
-
const dataToUpdate = connectRelationToParent(parentDataToUpdate, fieldToConnect, res.data, fieldToConnectUID);
|
773
|
-
try {
|
774
|
-
const updateRes = await updateDocumentMutation({
|
775
|
-
collectionType: parentDocumentMetaToUpdate.collectionType,
|
776
|
-
model: parentDocumentMetaToUpdate.model,
|
777
|
-
documentId: parentDocumentMetaToUpdate.collectionType !== SINGLE_TYPES ? parentDocumentMetaToUpdate.documentId : undefined,
|
778
|
-
params: parentDocumentMetaToUpdate.params,
|
779
|
-
data: {
|
780
|
-
...dataToUpdate
|
781
|
-
}
|
782
|
-
});
|
783
|
-
if ('error' in updateRes) {
|
784
|
-
toggleNotification({
|
785
|
-
type: 'danger',
|
786
|
-
message: formatAPIError(updateRes.error)
|
787
|
-
});
|
788
|
-
return;
|
789
|
-
}
|
790
|
-
} catch (err) {
|
791
|
-
toggleNotification({
|
792
|
-
type: 'danger',
|
793
|
-
message: formatMessage({
|
794
|
-
id: 'notification.error',
|
795
|
-
defaultMessage: 'An error occurred'
|
796
|
-
})
|
797
|
-
});
|
798
|
-
throw err;
|
799
|
-
}
|
800
|
-
}
|
801
|
-
dispatch({
|
802
|
-
type: 'GO_TO_CREATED_RELATION',
|
803
|
-
payload: {
|
804
|
-
document: createdRelation,
|
805
|
-
shouldBypassConfirmation: true
|
806
|
-
}
|
807
|
-
});
|
808
|
-
} else {
|
809
|
-
navigate({
|
810
|
-
pathname: `../${res.data.documentId}`,
|
811
|
-
search: rawQuery
|
812
|
-
}, {
|
813
|
-
replace: true,
|
814
|
-
relative: 'path'
|
815
|
-
});
|
816
|
-
}
|
635
|
+
navigate({
|
636
|
+
pathname: `../${res.data.documentId}`,
|
637
|
+
search: rawQuery
|
638
|
+
}, {
|
639
|
+
replace: true,
|
640
|
+
relative: 'path'
|
641
|
+
});
|
817
642
|
} else if ('error' in res && isBaseQueryError(res.error) && res.error.name === 'ValidationError') {
|
818
643
|
setErrors(formatValidationErrors(res.error));
|
819
644
|
}
|
@@ -825,36 +650,26 @@ const UpdateAction = ({ activeTab, documentId, model, collectionType })=>{
|
|
825
650
|
}
|
826
651
|
}
|
827
652
|
}, [
|
828
|
-
setSubmitting,
|
829
|
-
modified,
|
830
|
-
validate,
|
831
|
-
isCloning,
|
832
|
-
documentId,
|
833
|
-
collectionType,
|
834
|
-
toggleNotification,
|
835
|
-
formatMessage,
|
836
653
|
clone,
|
837
|
-
model,
|
838
654
|
cloneMatch?.params.origin,
|
655
|
+
collectionType,
|
656
|
+
create,
|
839
657
|
currentDocumentMeta.params,
|
840
658
|
document,
|
659
|
+
documentId,
|
660
|
+
formatMessage,
|
661
|
+
formatValidationErrors,
|
662
|
+
isCloning,
|
663
|
+
model,
|
664
|
+
modified,
|
841
665
|
navigate,
|
842
666
|
rawQuery,
|
667
|
+
resetForm,
|
843
668
|
setErrors,
|
844
|
-
|
669
|
+
setSubmitting,
|
670
|
+
toggleNotification,
|
845
671
|
update,
|
846
|
-
|
847
|
-
create,
|
848
|
-
fromRelationModal,
|
849
|
-
fieldToConnect,
|
850
|
-
documentHistory,
|
851
|
-
parentDocumentMetaToUpdate,
|
852
|
-
dispatch,
|
853
|
-
getInitialFormValues,
|
854
|
-
parentDocumentData,
|
855
|
-
fieldToConnectUID,
|
856
|
-
updateDocumentMutation,
|
857
|
-
formatAPIError,
|
672
|
+
validate,
|
858
673
|
onPreview
|
859
674
|
]);
|
860
675
|
// Auto-save on CMD+S or CMD+Enter on macOS, and CTRL+S or CTRL+Enter on Windows/Linux
|