7299_testToMaster #351

Merged
alexm merged 321 commits from 7299_testToMaster into master 2024-05-07 05:36:02 +00:00
3 changed files with 16 additions and 16 deletions
Showing only changes of commit 3abc504158 - Show all commits

View File

@ -78,7 +78,6 @@ const arrayData = useArrayData(props.dataKey, {
exprBuilder: props.exprBuilder, exprBuilder: props.exprBuilder,
}); });
const store = arrayData.store; const store = arrayData.store;
const hasMoreData = arrayData.hasMoreData;
onMounted(() => { onMounted(() => {
if (props.autoLoad) fetch(); if (props.autoLoad) fetch();
@ -97,7 +96,7 @@ const addFilter = async (filter, params) => {
async function fetch() { async function fetch() {
await arrayData.fetch({ append: false }); await arrayData.fetch({ append: false });
if (!hasMoreData.value) { if (!store.hasMoreData) {
isLoading.value = false; isLoading.value = false;
} }
emit('onFetch', store.data); emit('onFetch', store.data);
@ -110,8 +109,8 @@ async function paginate() {
isLoading.value = true; isLoading.value = true;
await arrayData.loadMore(); await arrayData.loadMore();
if (!hasMoreData.value) { if (!store.hasMoreData) {
if (store.userParamsChanged) hasMoreData.value = true; if (store.userParamsChanged) store.hasMoreData = true;
store.userParamsChanged = false; store.userParamsChanged = false;
endPagination(); endPagination();
return; return;
@ -140,7 +139,7 @@ async function onLoad(index, done) {
await paginate(); await paginate();
let isDone = false; let isDone = false;
if (store.userParamsChanged) isDone = !hasMoreData.value; if (store.userParamsChanged) isDone = !store.hasMoreData;
done(isDone); done(isDone);
} }
@ -185,7 +184,7 @@ defineExpose({ fetch, addFilter });
@load="onLoad" @load="onLoad"
:offset="offset" :offset="offset"
class="full-width" class="full-width"
:disable="disableInfiniteScroll || !hasMoreData" :disable="disableInfiniteScroll || !store.hasMoreData"
v-bind="$attrs" v-bind="$attrs"
> >
<slot name="body" :rows="store.data"></slot> <slot name="body" :rows="store.data"></slot>
@ -193,7 +192,10 @@ defineExpose({ fetch, addFilter });
<QSpinner color="orange" size="md" /> <QSpinner color="orange" size="md" />
</div> </div>
</QInfiniteScroll> </QInfiniteScroll>
<div v-if="!isLoading && hasMoreData" class="w-full flex justify-center q-mt-md"> <div
v-if="!isLoading && store.hasMoreData"
class="w-full flex justify-center q-mt-md"
>
<QBtn color="primary" :label="t('Load more data')" @click="paginate()" /> <QBtn color="primary" :label="t('Load more data')" @click="paginate()" />
</div> </div>
</template> </template>

View File

@ -12,7 +12,6 @@ export function useArrayData(key, userOptions) {
if (!arrayDataStore.get(key)) arrayDataStore.set(key); if (!arrayDataStore.get(key)) arrayDataStore.set(key);
const store = arrayDataStore.get(key); const store = arrayDataStore.get(key);
const hasMoreData = computed(() => arrayDataStore.hasMoreData);
const route = useRoute(); const route = useRoute();
let canceller = null; let canceller = null;
@ -93,7 +92,7 @@ export function useArrayData(key, userOptions) {
}); });
const { limit } = filter; const { limit } = filter;
arrayDataStore.hasMoreData = limit && response.data.length >= limit; store.hasMoreData = limit && response.data.length >= limit;
if (append) { if (append) {
if (!store.data) store.data = []; if (!store.data) store.data = [];
@ -165,7 +164,7 @@ export function useArrayData(key, userOptions) {
} }
async function loadMore() { async function loadMore() {
if (!hasMoreData.value) return; if (!store.hasMoreData) return;
store.skip = store.limit * page.value; store.skip = store.limit * page.value;
page.value += 1; page.value += 1;
@ -207,7 +206,6 @@ export function useArrayData(key, userOptions) {
destroy, destroy,
loadMore, loadMore,
store, store,
hasMoreData,
totalRows, totalRows,
updateStateParams, updateStateParams,
isLoading, isLoading,

View File

@ -48,7 +48,7 @@ describe('VnPaginate', () => {
{ id: 3, name: 'Bruce Wayne' }, { id: 3, name: 'Bruce Wayne' },
], ],
}); });
vm.arrayData.hasMoreData.value = true; vm.store.hasMoreData = true;
await vm.$nextTick(); await vm.$nextTick();
vm.store.data = [ vm.store.data = [
@ -59,13 +59,13 @@ describe('VnPaginate', () => {
await vm.paginate(); await vm.paginate();
expect(vm.store.skip).toEqual(0); expect(vm.store.skip).toEqual(3);
expect(vm.store.data.length).toEqual(3); expect(vm.store.data.length).toEqual(6);
await vm.paginate(); await vm.paginate();
expect(vm.store.skip).toEqual(0); expect(vm.store.skip).toEqual(6);
expect(vm.store.data.length).toEqual(3); expect(vm.store.data.length).toEqual(9);
}); });
}); });