@retikolo/drag-drop-content-types 1.3.4 → 1.3.6
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/README.md
CHANGED
|
@@ -31,10 +31,12 @@ module.exports = {
|
|
|
31
31
|
|
|
32
32
|
### In the app
|
|
33
33
|
Go to `Settings` -> `Drag Drop Content Type` -> `Configuration`:
|
|
34
|
-
* Specify how the rank field
|
|
35
|
-
* Add the
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
* Specify how the rank field is called in your content-types. Default value is `rank`.
|
|
35
|
+
* Add the `rank` fields to your content type. With the default value this would be `rank` (Number (Number format: integer)).
|
|
36
|
+
|
|
37
|
+
#### Hints
|
|
38
|
+
* Add "Default sort attribute" `rank`, "Default sort order" `ASC` and remove the `rank` attribute from the view using "Configure the view" button.
|
|
39
|
+
* You can also set a `title` value that is displayed in the menu instead of the default.
|
|
38
40
|
|
|
39
41
|
### In your frontend
|
|
40
42
|
Assuming you go with the default settings, you can make a request on the following url to get the ordered items:
|
|
@@ -12,17 +12,15 @@ import { Icon } from "@strapi/design-system/Icon";
|
|
|
12
12
|
import Drag from "@strapi/icons/Drag";
|
|
13
13
|
import Layer from "@strapi/icons/Layer";
|
|
14
14
|
|
|
15
|
-
const DEFAULT_SORT_MENU_PAGE_SIZE = 10;
|
|
16
|
-
const DEFAULT_NUMBER_OF_ENTRIES_FROM_NEXT_PAGE = 3;
|
|
17
|
-
|
|
18
15
|
const SortModal = () => {
|
|
19
16
|
const [data, setData] = useState([]);
|
|
20
17
|
const [currentPage, setCurrentPage] = useState(1);
|
|
21
|
-
const [pageSize, setPageSize] = useState(
|
|
18
|
+
const [pageSize, setPageSize] = useState();
|
|
22
19
|
const [pagination, setPagination] = useState();
|
|
23
20
|
const [status, setStatus] = useState("loading");
|
|
21
|
+
const [mainField, setMainField] = useState('id');
|
|
24
22
|
const [settings, setSettings] = useState();
|
|
25
|
-
const [noEntriesFromNextPage, setNoEntriesFromNextPage] = useState(
|
|
23
|
+
const [noEntriesFromNextPage, setNoEntriesFromNextPage] = useState();
|
|
26
24
|
|
|
27
25
|
// TODO: Refactor get queryParams to hook
|
|
28
26
|
const [params] = useQueryParams();
|
|
@@ -42,13 +40,32 @@ const SortModal = () => {
|
|
|
42
40
|
[dispatch, pagination, data]
|
|
43
41
|
);
|
|
44
42
|
|
|
43
|
+
// Fetch content type config settings
|
|
44
|
+
const fetchContentTypeConfig = async () => {
|
|
45
|
+
// TODO: tie this in with middleware with the request that is already being made on page load
|
|
46
|
+
try {
|
|
47
|
+
const { data } = await axiosInstance.get(
|
|
48
|
+
`/content-manager/content-types/${contentTypePath}/configuration`
|
|
49
|
+
);
|
|
50
|
+
setMainField(data.data.contentType.settings.mainField);
|
|
51
|
+
setPageSize(data.data.contentType.settings.pageSize);
|
|
52
|
+
setNoEntriesFromNextPage(data.data.contentType.settings.pageSize / 2);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log(e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
45
58
|
// Fetch settings from configuration
|
|
46
59
|
const fetchSettings = async () => {
|
|
47
60
|
try {
|
|
48
61
|
const { data } = await axiosInstance.get(
|
|
49
62
|
`/drag-drop-content-types/settings`
|
|
50
63
|
);
|
|
51
|
-
|
|
64
|
+
let fetchedSettings = {
|
|
65
|
+
rank: data.body.rank,
|
|
66
|
+
title: data.body.title.length > 0 ? data.body.title : mainField
|
|
67
|
+
}
|
|
68
|
+
setSettings(fetchedSettings);
|
|
52
69
|
} catch (e) {
|
|
53
70
|
console.log(e);
|
|
54
71
|
}
|
|
@@ -76,8 +93,7 @@ const SortModal = () => {
|
|
|
76
93
|
const entries = await getPageEntries()
|
|
77
94
|
if (
|
|
78
95
|
entries.data.length > 0 &&
|
|
79
|
-
!!toString(entries.data[0][settings.rank])
|
|
80
|
-
!!entries.data[0][settings.title]
|
|
96
|
+
!!toString(entries.data[0][settings.rank])
|
|
81
97
|
) {
|
|
82
98
|
setStatus("success");
|
|
83
99
|
}
|
|
@@ -95,7 +111,7 @@ const SortModal = () => {
|
|
|
95
111
|
setStatus("success");
|
|
96
112
|
setData(entries.data);
|
|
97
113
|
// TODO: remove this line and get pagination from elsewhere
|
|
98
|
-
const { data } = await axiosInstance.get(`/content-manager/collection-types/${contentTypePath}?sort
|
|
114
|
+
const { data } = await axiosInstance.get(`/content-manager/collection-types/${contentTypePath}?sort=${settings.rank}:asc&page=${currentPage}&pageSize=${pageSize}&locale=${locale}`);
|
|
99
115
|
setPagination(data.pagination);
|
|
100
116
|
} catch (e) {
|
|
101
117
|
console.log(e);
|
|
@@ -171,8 +187,8 @@ const SortModal = () => {
|
|
|
171
187
|
>
|
|
172
188
|
<Icon height={"0.6em"} as={Drag} />
|
|
173
189
|
|
|
174
|
-
<span title={value[settings.title]}>
|
|
175
|
-
{value[settings.title]}
|
|
190
|
+
<span title={value[settings.title] ? value[settings.title] : value[mainField] }>
|
|
191
|
+
{value[settings.title] ? value[settings.title] : value[mainField] }
|
|
176
192
|
</span>
|
|
177
193
|
</div>
|
|
178
194
|
</MenuItem>
|
|
@@ -194,7 +210,7 @@ const SortModal = () => {
|
|
|
194
210
|
<Divider unsetMargin={false} />
|
|
195
211
|
<Button
|
|
196
212
|
size="S"
|
|
197
|
-
disabled={noEntriesFromNextPage + listIncrementSize >= data.length ? true : false}
|
|
213
|
+
disabled={noEntriesFromNextPage + listIncrementSize >= data.length - 1 ? true : false}
|
|
198
214
|
onClick={() => { setNoEntriesFromNextPage(noEntriesFromNextPage + listIncrementSize) }}
|
|
199
215
|
>Show more</Button>
|
|
200
216
|
</div>
|
|
@@ -207,6 +223,7 @@ const SortModal = () => {
|
|
|
207
223
|
<SimpleMenu
|
|
208
224
|
as={IconButton}
|
|
209
225
|
icon={<Layer />}
|
|
226
|
+
label="Sort via drag and drop"
|
|
210
227
|
onClick={() => {
|
|
211
228
|
fetchContentType();
|
|
212
229
|
}}
|
|
@@ -219,10 +236,15 @@ const SortModal = () => {
|
|
|
219
236
|
);
|
|
220
237
|
};
|
|
221
238
|
|
|
239
|
+
// Fetch content-type on page render
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
fetchContentTypeConfig();
|
|
242
|
+
}, []);
|
|
243
|
+
|
|
222
244
|
// Fetch settings on page render
|
|
223
245
|
useEffect(() => {
|
|
224
246
|
fetchSettings();
|
|
225
|
-
}, []);
|
|
247
|
+
}, [mainField]);
|
|
226
248
|
|
|
227
249
|
// Update view when settings change
|
|
228
250
|
useEffect(() => {
|
|
@@ -111,7 +111,7 @@ const Settings = () => {
|
|
|
111
111
|
<TextInput
|
|
112
112
|
placeholder="Title"
|
|
113
113
|
label="Title Field Name"
|
|
114
|
-
hint="
|
|
114
|
+
hint="Select or create a Short Text Field with this label in the Content-Type Builder. Leave blank to use content-type entry title"
|
|
115
115
|
name="content"
|
|
116
116
|
onChange={e => {
|
|
117
117
|
setSettings({
|
|
@@ -142,4 +142,4 @@ const Settings = () => {
|
|
|
142
142
|
);
|
|
143
143
|
};
|
|
144
144
|
|
|
145
|
-
export default Settings;
|
|
145
|
+
export default Settings;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ async function createDefaultConfig() {
|
|
|
15
15
|
const value = {
|
|
16
16
|
body: {
|
|
17
17
|
rank: 'rank',
|
|
18
|
-
title: '
|
|
18
|
+
title: '',
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
await pluginStore.set({ key: 'settings', value });
|
|
@@ -50,7 +50,11 @@ async function index(contentType, start, limit, locale, rankFieldName) {
|
|
|
50
50
|
locale: locale,
|
|
51
51
|
}
|
|
52
52
|
indexData.sort[rankFieldName] = 'asc'
|
|
53
|
-
|
|
53
|
+
try {
|
|
54
|
+
return await strapi.entityService.findMany(contentType, indexData );
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
// Update rank of specified content type
|