#7136 - Enable paginate event in VnSelectFilter #255

Closed
jsegarra wants to merge 86 commits from 7136_vnselectFilter_paginate into dev
3 changed files with 59 additions and 29 deletions
Showing only changes of commit e92701de23 - Show all commits

View File

@ -66,6 +66,10 @@ const $props = defineProps({
type: Boolean, type: Boolean,
default: false, default: false,
}, },
useLike: {
Outdated
Review

Por como estaba creo recordar que myOptions era la variable para las opciones filtradas y myOptionsOriginal para las originales. myOptionsFiltered para que seria? Puede ser myOptions ?

Por como estaba creo recordar que `myOptions` era la variable para las opciones filtradas y `myOptionsOriginal ` para las originales. `myOptionsFiltered ` para que seria? Puede ser `myOptions ` ?

Me he dado cuenta que la necesidad de esa variable no cubre otro caso de uso asi que la elimino

Me he dado cuenta que la necesidad de esa variable no cubre otro caso de uso asi que la elimino
type: Boolean,
default: true,
},
}); });
const { t } = useI18n(); const { t } = useI18n();
@ -177,7 +181,7 @@ async function filterHandler(val, update) {
newOptions = filter(val, myOptions.value); newOptions = filter(val, myOptions.value);
myOptions.value = []; myOptions.value = [];
} else { } else {
newOptions = filter(val, myOptionsOriginal.value); newOptions = filter(val, isFiltered ? myOptions.value : myOptionsOriginal.value);
} }
if (useURL.value && isFiltered && arrayData.store.hasMoreData) { if (useURL.value && isFiltered && arrayData.store.hasMoreData) {
arrayData.store.skip = 0; arrayData.store.skip = 0;

View File

@ -1,4 +1,4 @@
import { onMounted, ref, computed } from 'vue'; import { onMounted, computed } from 'vue';
import { useRouter, useRoute } from 'vue-router'; import { useRouter, useRoute } from 'vue-router';
import axios from 'axios'; import axios from 'axios';
import { useArrayDataStore } from 'stores/useArrayDataStore'; import { useArrayDataStore } from 'stores/useArrayDataStore';
@ -18,7 +18,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
onMounted(() => { onMounted(() => {
setOptions(); setOptions();
store.skip = 0; arrayDataStore.reset(['skip']);
const query = route.query; const query = route.query;
const searchUrl = store.searchUrl; const searchUrl = store.searchUrl;
@ -27,7 +27,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
const filter = params?.filter; const filter = params?.filter;
delete params.filter; delete params.filter;
store.userParams = { ...params, ...store.userParams }; store.userParams = { ...params, ...store.userParams };
store.userFilter = { ...JSON.parse(filter), ...store.userFilter }; store.userFilter = { ...JSON.parse(filter ?? '{}'), ...store.userFilter };
} }
}); });
@ -85,13 +85,17 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
} }
Object.assign(filter, store.userFilter, exprFilter); Object.assign(filter, store.userFilter, exprFilter);
Object.assign(store.filter, { ...filter, skip: store.skip }); let where;
const params = { if (filter?.where || store.filter?.where)
filter: JSON.stringify(store.filter), where = Object.assign(filter?.where ?? {}, store.filter?.where ?? {});
}; Object.assign(filter, store.filter);
filter.where = where;
const params = { filter };
Object.assign(params, userParams); Object.assign(params, userParams);
params.filter.skip = store.skip;
params.filter = JSON.stringify(params.filter);
store.currentFilter = params; store.currentFilter = params;
store.isLoading = true; store.isLoading = true;
const response = await axios.get(store.url, { const response = await axios.get(store.url, {
@ -127,6 +131,10 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
delete store[option]; delete store[option];
} }
function reset(opts = []) {
if (arrayDataStore.get(key)) arrayDataStore.reset(key, opts);
}
function cancelRequest() { function cancelRequest() {
if (canceller) { if (canceller) {
canceller.abort(); canceller.abort();
@ -144,22 +152,20 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
} }
async function addFilter({ filter, params }) { async function addFilter({ filter, params }) {
if (filter) store.userFilter = Object.assign(store.userFilter, filter); if (filter) store.filter = filter;
let userParams = { ...store.userParams, ...params }; let userParams = { ...store.userParams, ...params };
userParams = sanitizerParams(userParams, store?.exprBuilder); userParams = sanitizerParams(userParams, store?.exprBuilder);
store.userParams = userParams; store.userParams = userParams;
store.skip = 0; arrayDataStore.reset(['skip', 'filter.skip', 'page']);
store.filter.skip = 0;
store.page = 1;
await fetch({ append: false }); await fetch({ append: false });
return { filter, params }; return { filter, params };
} }
async function addFilterWhere(where) { async function addFilterWhere(where) {
const storedFilter = { ...store.userFilter }; const storedFilter = { ...store.filter };
if (!storedFilter?.where) storedFilter.where = {}; if (!storedFilter?.where) storedFilter.where = {};
where = { ...storedFilter.where, ...where }; where = { ...storedFilter.where, ...where };
await addFilter({ filter: { where } }); await addFilter({ filter: { where } });
@ -242,5 +248,6 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
updateStateParams, updateStateParams,
isLoading, isLoading,
deleteOption, deleteOption,
reset,
}; };
} }

View File

@ -3,37 +3,56 @@ import { defineStore } from 'pinia';
export const useArrayDataStore = defineStore('arrayDataStore', () => { export const useArrayDataStore = defineStore('arrayDataStore', () => {
const state = ref({}); const state = ref({});
const defaultOpts = {
filter: {},
userFilter: {},
userParams: {},
url: '',
limit: 10,
skip: 0,
order: '',
isLoading: false,
userParamsChanged: false,
exprBuilder: null,
searchUrl: 'params',
navigate: null,
page: 1,
};
function get(key) { function get(key) {
return state.value[key]; return state.value[key];
} }
function set(key) { function set(key) {
state.value[key] = { state.value[key] = getDefaultState();
filter: {},
userFilter: {},
userParams: {},
url: '',
limit: 10,
skip: 0,
order: '',
data: ref(),
page: ref(1),
isLoading: false,
userParamsChanged: false,
exprBuilder: null,
searchUrl: 'params',
navigate: null,
};
} }
function clear(key) { function clear(key) {
delete state.value[key]; delete state.value[key];
} }
function reset(key, opts = []) {
if (!opts.length) state.value[key] = getDefaultState();
else
opts.forEach((opt) => {
if (opt.includes('.')) {
const [parent, child] = opt.split('.');
state.value[key][parent][child] = defaultOpts[child];
} else if (Object.hasOwn(state.value[key], opt))
state.value[key][opt] = defaultOpts[opt];
});
}
function getDefaultState() {
return Object.assign(JSON.parse(JSON.stringify(defaultOpts)), {
data: ref(),
});
}
return { return {
get, get,
set, set,
clear, clear,
reset,
}; };
}); });