Skip to content

Commit cc6ae1b

Browse files
committed
introduce constants for pagination limits and update logic in utils and Select component
1 parent 7d1e8d1 commit cc6ae1b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

adminforth/spa/src/afcl/Select.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function updateFromProps() {
187187
}
188188
189189
async function inputClick() {
190-
if (props.readonly && !props.searchDisabled) return;
190+
if (props.readonly || props.searchDisabled) return;
191191
// Toggle local dropdown
192192
showDropdown.value = !showDropdown.value;
193193
// If the dropdown is about to close, reset the search
@@ -266,7 +266,7 @@ onMounted(() => {
266266
267267
const filteredItems = computed(() => {
268268
269-
if (!props.searchDisabled) {
269+
if (props.searchDisabled) {
270270
return props.options || [];
271271
}
272272

adminforth/spa/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import sanitizeHtml from 'sanitize-html'
1010
import debounce from 'debounce';
1111

1212
const LS_LANG_KEY = `afLanguage`;
13+
const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
14+
const ITEMS_PER_PAGE_LIMIT = 100;
1315

1416
export async function callApi({path, method, body=undefined}: {
1517
path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
@@ -233,7 +235,7 @@ export function handleForeignResourcePagination(
233235
if (items.length === 0) {
234236
const newEmptyCount = emptyResultsCount + 1;
235237
return {
236-
hasMore: newEmptyCount < 2, // Stop loading after 2 consecutive empty results
238+
hasMore: newEmptyCount < MAX_CONSECUTIVE_EMPTY_RESULTS, // Stop loading after 2 consecutive empty results
237239
emptyResultsCount: newEmptyCount
238240
};
239241
} else {
@@ -245,7 +247,7 @@ export function handleForeignResourcePagination(
245247
}
246248
} else {
247249
return {
248-
hasMore: items.length === 100,
250+
hasMore: items.length === ITEMS_PER_PAGE_LIMIT,
249251
emptyResultsCount: 0
250252
};
251253
}

0 commit comments

Comments
 (0)