@retikolo/drag-drop-content-types 1.5.2 → 1.5.4

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.
@@ -2,6 +2,7 @@ import { arrayMoveImmutable } from 'array-move';
2
2
  import React, { useEffect, useState } from 'react';
3
3
  import { useDispatch } from 'react-redux';
4
4
  // import { useHistory } from 'react-router-dom';
5
+ import { useNotification, useAPIErrorHandler } from '@strapi/helper-plugin';
5
6
  import axiosInstance from '../../utils/axiosInstance';
6
7
  import { getData, getDataSucceeded } from '../../utils/strapi';
7
8
  import { useQueryParams } from '../../utils/useQueryParams';
@@ -24,6 +25,9 @@ const SortModal = () => {
24
25
  const { queryParams: params } = useQueryParams();
25
26
  const dispatch = useDispatch();
26
27
 
28
+ const toggleNotification = useNotification();
29
+ const { formatAPIError } = useAPIErrorHandler();
30
+
27
31
  // Get content type from url
28
32
  const paths = window.location.pathname.split('/');
29
33
  const contentTypePath = paths[paths.length - 1];
@@ -77,6 +81,7 @@ const SortModal = () => {
77
81
  rank: data.body.rank,
78
82
  title: data.body.title?.length > 0 ? data.body.title : mainField,
79
83
  subtitle: data.body.subtitle?.length > 0 ? data.body.subtitle : null,
84
+ mainField,
80
85
  };
81
86
  setSettings(fetchedSettings);
82
87
  } catch (e) {
@@ -190,6 +195,10 @@ const SortModal = () => {
190
195
  afterUpdate(pagination, sortedListViewEntries);
191
196
  } catch (e) {
192
197
  console.log('Could not update content type:', e);
198
+ toggleNotification({
199
+ type: 'warning',
200
+ message: formatAPIError(e)
201
+ });
193
202
  setStatus('error');
194
203
  }
195
204
  };
@@ -212,10 +221,10 @@ const SortModal = () => {
212
221
  fetchContentTypeConfig();
213
222
  }, []);
214
223
 
215
- // Fetch settings on page render
224
+ // Fetch settings when mainField changes
216
225
  useEffect(() => {
217
226
  fetchSettings();
218
- }, []);
227
+ }, [mainField]);
219
228
 
220
229
  // Update view when settings change
221
230
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retikolo/drag-drop-content-types",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "This plugin add a drag and droppable list that allows you to sort content type entries.",
5
5
  "strapi": {
6
6
  "name": "drag-drop-content-types",
@@ -13,6 +13,7 @@
13
13
  "url": "https://github.com/plantagoIT/strapi-drag-drop-content-type-plugin"
14
14
  },
15
15
  "dependencies": {
16
+ "@strapi/helper-plugin": "^4.25.0",
16
17
  "array-move": "^4.0.0",
17
18
  "react-sortable-hoc": "^2.0.0",
18
19
  "zod": "^3.20.2"
@@ -84,17 +84,13 @@ async function batchUpdate(updates, contentType) {
84
84
 
85
85
  for (const update of updates) {
86
86
  // update entry's rank in db
87
- try {
88
- const updatedEntry = await strapi.db.query(contentType).update({
89
- where: { id: update.id },
90
- data: {
91
- [sortFieldName]: update.rank,
92
- },
93
- });
94
- updatedEntry?.id && results.push(updatedEntry);
95
- } catch (err) {
96
- console.log(err);
97
- }
87
+ const updatedEntry = await strapi.db.query(contentType).update({
88
+ where: { id: update.id },
89
+ data: {
90
+ [sortFieldName]: update.rank,
91
+ },
92
+ });
93
+ updatedEntry?.id && results.push(updatedEntry);
98
94
  }
99
95
  if (results?.length !== updates?.length) {
100
96
  throw new Error('Error updating rank entries.');