@retikolo/drag-drop-content-types 1.3.0 → 1.3.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.
@@ -5,6 +5,7 @@ import axiosInstance from "../../utils/axiosInstance";
5
5
  import { SortableContainer, SortableElement } from "react-sortable-hoc";
6
6
  import { arrayMoveImmutable } from "array-move";
7
7
  import { useQueryParams } from "../../utils/useQueryParams";
8
+ import { Button, Divider } from '@strapi/design-system';
8
9
  import { SimpleMenu, MenuItem } from "@strapi/design-system/SimpleMenu";
9
10
  import { IconButton } from "@strapi/design-system/IconButton";
10
11
  import { Icon } from "@strapi/design-system/Icon";
@@ -12,7 +13,7 @@ import Drag from "@strapi/icons/Drag";
12
13
  import Layer from "@strapi/icons/Layer";
13
14
 
14
15
  const DEFAULT_SORT_MENU_PAGE_SIZE = 10;
15
- const NUMBER_OF_ENTRIES_FROM_NEXT_PAGES = 3;
16
+ const DEFAULT_NUMBER_OF_ENTRIES_FROM_NEXT_PAGE = 3;
16
17
 
17
18
  const SortModal = () => {
18
19
  const [data, setData] = useState([]);
@@ -21,6 +22,7 @@ const SortModal = () => {
21
22
  const [pagination, setPagination] = useState();
22
23
  const [status, setStatus] = useState("loading");
23
24
  const [settings, setSettings] = useState();
25
+ const [noEntriesFromNextPage, setNoEntriesFromNextPage] = useState(DEFAULT_NUMBER_OF_ENTRIES_FROM_NEXT_PAGE);
24
26
 
25
27
  // TODO: Refactor get queryParams to hook
26
28
  const [params] = useQueryParams();
@@ -58,8 +60,8 @@ const SortModal = () => {
58
60
  `/drag-drop-content-types/sort-index`,
59
61
  {
60
62
  contentType: contentTypePath,
61
- start: Math.max(0, (currentPage - 1) * pageSize - NUMBER_OF_ENTRIES_FROM_NEXT_PAGES),
62
- limit: currentPage == 1 ? pageSize + NUMBER_OF_ENTRIES_FROM_NEXT_PAGES : pageSize + 2 * NUMBER_OF_ENTRIES_FROM_NEXT_PAGES,
63
+ start: Math.max(0, (currentPage - 1) * pageSize - noEntriesFromNextPage),
64
+ limit: currentPage == 1 ? pageSize + noEntriesFromNextPage : pageSize + 2 * noEntriesFromNextPage,
63
65
  locale: locale,
64
66
  }
65
67
  );
@@ -100,14 +102,6 @@ const SortModal = () => {
100
102
  }
101
103
  };
102
104
 
103
- // Shorten string to prevent line break
104
- const shortenString = (string) => {
105
- if (string.length > 40) {
106
- return string.substring(0, 37) + "...";
107
- }
108
- return string;
109
- };
110
-
111
105
  // Update all ranks via put request.
112
106
  const updateContentType = async ({ oldIndex, newIndex }) => {
113
107
  try {
@@ -141,9 +135,9 @@ const SortModal = () => {
141
135
  :
142
136
  sortedList.length < pageSize
143
137
  ?
144
- sortedList.slice(NUMBER_OF_ENTRIES_FROM_NEXT_PAGES, sortedList.length)
138
+ sortedList.slice(noEntriesFromNextPage, sortedList.length)
145
139
  :
146
- sortedList.slice(NUMBER_OF_ENTRIES_FROM_NEXT_PAGES, pageSize + NUMBER_OF_ENTRIES_FROM_NEXT_PAGES)
140
+ sortedList.slice(noEntriesFromNextPage, pageSize + noEntriesFromNextPage)
147
141
  // set new sorted data (refresh UI list component)
148
142
  setData(sortedList);
149
143
  setStatus("success");
@@ -163,6 +157,7 @@ const SortModal = () => {
163
157
 
164
158
  // Render the menu
165
159
  const showMenu = () => {
160
+
166
161
  const SortableItem = SortableElement(({ value }) => (
167
162
  <MenuItem style={{ zIndex: 10, cursor: "all-scroll" }}>
168
163
  <div
@@ -175,7 +170,6 @@ const SortModal = () => {
175
170
  <Icon height={"0.6em"} as={Drag} />
176
171
  &nbsp;
177
172
  <span title={value[settings.title]}>
178
- {/* {shortenString(value[settings.title])} */}
179
173
  {value[settings.title]}
180
174
  </span>
181
175
  </div>
@@ -195,24 +189,31 @@ const SortModal = () => {
195
189
  />
196
190
  ))}
197
191
  </ul>
192
+ <Divider unsetMargin={false} />
193
+ <Button
194
+ size="S"
195
+ disabled={noEntriesFromNextPage + listIncrementSize >= data.length ? true : false}
196
+ onClick={() => { setNoEntriesFromNextPage(noEntriesFromNextPage + listIncrementSize) }}
197
+ >Show more</Button>
198
198
  </div>
199
199
  );
200
200
  });
201
201
  return (
202
+ // Only show menu when the content type has needed fields
202
203
  status == 'success' ?
203
- <>
204
- <SimpleMenu
205
- as={IconButton}
206
- icon={<Layer />}
207
- onClick={() => {
208
- fetchContentType();
209
- }}
210
- >
211
- <SortableList items={data} onSortEnd={updateContentType} />
212
- </SimpleMenu>
213
- </>
214
- :
215
- <></>
204
+ <>
205
+ <SimpleMenu
206
+ as={IconButton}
207
+ icon={<Layer />}
208
+ onClick={() => {
209
+ fetchContentType();
210
+ }}
211
+ >
212
+ <SortableList items={data} onSortEnd={updateContentType} />
213
+ </SimpleMenu>
214
+ </>
215
+ :
216
+ <></>
216
217
  );
217
218
  };
218
219
 
@@ -226,6 +227,11 @@ const SortModal = () => {
226
227
  initializeContentType();
227
228
  }, [settings]);
228
229
 
230
+ // Update menu when loading more elements
231
+ useEffect(() => {
232
+ fetchContentType();
233
+ }, [noEntriesFromNextPage])
234
+
229
235
  // Sync entries in sort menu to match current page of ListView when content-manager page changes
230
236
  useEffect(() => {
231
237
  if (params?.page) {
@@ -242,6 +248,7 @@ const SortModal = () => {
242
248
  const queryParams = new URLSearchParams(window.location.search);
243
249
  const contentTypePath = paths[paths.length - 1];
244
250
  const locale = queryParams.get("plugins[i18n][locale]");
251
+ const listIncrementSize = pageSize / 2;
245
252
 
246
253
  return <>{showMenu()}</>;
247
254
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retikolo/drag-drop-content-types",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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",