|
| 1 | +diff --git a/node_modules/@strapi/admin/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js b/node_modules/@strapi/admin/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js |
| 2 | +index eb7b5dd..f4e25bd 100644 |
| 3 | +--- a/node_modules/@strapi/admin/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js |
| 4 | ++++ b/node_modules/@strapi/admin/admin/src/content-manager/components/CollectionTypeFormWrapper/index.js |
| 5 | +@@ -62,6 +62,11 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin } |
| 6 | + const requestURL = |
| 7 | + isCreatingEntry && !origin ? null : getRequestUrl(`collection-types/${slug}/${origin || id}`); |
| 8 | + |
| 9 | ++ const currentContentTypeLayout = get(allLayoutData, ['contentType'], {}); |
| 10 | ++ const hasVersions = () => { |
| 11 | ++ return get(currentContentTypeLayout, ['pluginOptions', 'versions', 'versioned'], false); |
| 12 | ++ }; |
| 13 | ++ |
| 14 | + const cleanReceivedData = useCallback((data) => { |
| 15 | + const cleaned = removePasswordFieldsFromData( |
| 16 | + data, |
| 17 | +@@ -221,6 +226,7 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin } |
| 18 | + */ |
| 19 | + const endPoint = isCloning |
| 20 | + ? getRequestUrl(`collection-types/${slug}/clone/${origin}`) |
| 21 | ++ : hasVersions ? `/content-versioning/${slug}/save${rawQuery}` |
| 22 | + : getRequestUrl(`collection-types/${slug}`); |
| 23 | + try { |
| 24 | + // Show a loading button in the EditView/Header.js && lock the app => no navigation |
| 25 | +@@ -228,8 +234,12 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin } |
| 26 | + |
| 27 | + const { id, ...restBody } = body; |
| 28 | + |
| 29 | ++ if (hasVersions) { |
| 30 | ++ body.isDuplicatingEntry = isCreatingEntry && !!origin |
| 31 | ++ } |
| 32 | ++ |
| 33 | + const { data } = await post(endPoint, isCloning ? restBody : body, { |
| 34 | +- params: query, |
| 35 | ++ params: hasVersions ? rawQuery : query, |
| 36 | + }); |
| 37 | + |
| 38 | + trackUsageRef.current('didCreateEntry', trackerProperty); |
| 39 | +@@ -326,14 +336,14 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin } |
| 40 | + |
| 41 | + const onPut = useCallback( |
| 42 | + async (body, trackerProperty) => { |
| 43 | +- const endPoint = getRequestUrl(`collection-types/${slug}/${id}`); |
| 44 | ++ const endPoint = hasVersions ? `/content-versioning/${slug}/save${rawQuery}` : getRequestUrl(`collection-types/${slug}/${id}`); |
| 45 | + |
| 46 | + try { |
| 47 | + trackUsageRef.current('willEditEntry', trackerProperty); |
| 48 | + |
| 49 | + dispatch(setStatus('submit-pending')); |
| 50 | + |
| 51 | +- const { data } = await put(endPoint, body); |
| 52 | ++ const { data } = hasVersions ? await post(endPoint, body) : await put(endPoint, body); |
| 53 | + |
| 54 | + trackUsageRef.current('didEditEntry', { trackerProperty }); |
| 55 | + toggleNotification({ |
| 56 | +@@ -348,6 +358,10 @@ const CollectionTypeFormWrapper = ({ allLayoutData, children, slug, id, origin } |
| 57 | + |
| 58 | + dispatch(setStatus('resolved')); |
| 59 | + |
| 60 | ++ if(hasVersions){ |
| 61 | ++ replace(`/content-manager/collectionType/${slug}/${data.id}${rawQuery}`) |
| 62 | ++ } |
| 63 | ++ |
| 64 | + return Promise.resolve(data); |
| 65 | + } catch (err) { |
| 66 | + trackUsageRef.current('didNotEditEntry', { error: err, trackerProperty }); |
| 67 | +diff --git a/node_modules/@strapi/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js b/node_modules/@strapi/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js |
| 68 | +index 8b3d9b8..0a25b84 100644 |
| 69 | +--- a/node_modules/@strapi/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js |
| 70 | ++++ b/node_modules/@strapi/admin/admin/src/content-manager/components/EditViewDataManagerProvider/index.js |
| 71 | +@@ -81,6 +81,10 @@ const EditViewDataManagerProvider = ({ |
| 72 | + return get(currentContentTypeLayout, ['options', 'draftAndPublish'], false); |
| 73 | + }, [currentContentTypeLayout]); |
| 74 | + |
| 75 | ++ const hasVersions = useMemo(() => { |
| 76 | ++ return get(currentContentTypeLayout, ['pluginOptions', 'versions', 'versioned'], false); |
| 77 | ++ }, [currentContentTypeLayout]); |
| 78 | ++ |
| 79 | + const shouldNotRunValidations = useMemo(() => { |
| 80 | + return hasDraftAndPublish && !initialData.publishedAt; |
| 81 | + }, [hasDraftAndPublish, initialData.publishedAt]); |
| 82 | +@@ -663,7 +667,7 @@ const EditViewDataManagerProvider = ({ |
| 83 | + <> |
| 84 | + {!isSaving ? ( |
| 85 | + <Prompt |
| 86 | +- when={!isEqual(modifiedData, initialData)} |
| 87 | ++ when={!hasVersions && !isEqual(modifiedData, initialData)} |
| 88 | + message={formatMessage({ id: 'global.prompt.unsaved' })} |
| 89 | + /> |
| 90 | + ) : null} |
0 commit comments