Skip to content

Commit d77c55e

Browse files
authored
Merge pull request #111 from notum-cz/feature/patch-for-strapi@4.12.0
feature: add patch for strapi 4.12.0
2 parents 4a0eb72 + ce51315 commit d77c55e

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = ({ env }) => ({
5757
yarn add patch-package
5858
```
5959
2. Create folder `patches` in the root of your project
60-
3. Copy file `@strapi+admin+4.11.4.patch` located in `patches/` of this repository to the folder created in the previous step
60+
3. Copy file `@strapi+admin+4.12.0.patch` located in `patches/` of this repository to the folder created in the previous step
6161
4. Add the line `"postinstall": "patch-package",` to the scripts section of the `package.json`
6262
5. Run `npm run postinstall`
6363

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@notum-cz/strapi-plugin-content-versioning",
3-
"version": "0.4.9",
3+
"version": "0.4.10",
44
"description": "This plugin enables content versioning",
55
"license": "SEE LICENSE IN LICENSE",
66
"author": "Notum Technologies s.r.o. <sales@notum.cz> (https://notum.cz/en/strapi)",

patches/@strapi+admin+4.12.0.patch

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)