Merge pull request 'perf: refs #8197 fix and imrpove filters' (!1234) from 8197-fix_filters into dev
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #1234
Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
Alex Moreno 2025-01-21 10:48:31 +00:00
commit 9f280c6089
6 changed files with 50 additions and 41 deletions

View File

@ -52,7 +52,8 @@ const sectionValue = computed(() => $props.section ?? $props.dataKey);
const isMainSection = computed(() => {
const isSame = sectionValue.value == route.name;
if (!isSame && arrayData) {
arrayData.reset(['userParams', 'userFilter']);
arrayData.reset(['userParams', 'filter']);
arrayData.setCurrentFilter();
}
return isSame;
});

View File

@ -232,12 +232,15 @@ async function fetchFilter(val) {
} else defaultWhere = { [key]: getVal(val) };
const where = { ...(val ? defaultWhere : {}), ...$props.where };
$props.exprBuilder && Object.assign(where, $props.exprBuilder(key, val));
const fetchOptions = { where, include, limit };
if (fields) fetchOptions.fields = fields;
if (sortBy) fetchOptions.order = sortBy;
const filterOptions = { where, include, limit };
if (fields) filterOptions.fields = fields;
if (sortBy) filterOptions.order = sortBy;
arrayData.resetPagination();
const { data } = await arrayData.applyFilter({ filter: fetchOptions });
const { data } = await arrayData.applyFilter(
{ filter: filterOptions },
{ updateRouter: false }
);
setOptions(data);
return data;
}

View File

@ -113,23 +113,20 @@ onMounted(() => {
});
async function search() {
const staticParams = Object.keys(store.userParams ?? {}).length
? store.userParams
: store.defaultParams;
arrayData.resetPagination();
const filter = {
params: {
search: searchText.value,
},
filter: props.filter,
};
let filter = { params: { search: searchText.value } };
if (!props.searchRemoveParams || !searchText.value) {
filter.params = {
...staticParams,
search: searchText.value,
filter = {
params: {
...store.userParams,
search: searchText.value,
},
filter: store.filter,
};
} else {
arrayData.reset(['currentFilter', 'userParams']);
}
if (props.whereFilter) {

View File

@ -33,10 +33,11 @@ export function useArrayData(key, userOptions) {
: JSON.parse(params?.filter ?? '{}');
delete params.filter;
store.userParams = { ...store.userParams, ...params };
store.userParams = params;
store.filter = { ...filter, ...store.userFilter };
if (filter?.order) store.order = filter.order;
}
setCurrentFilter();
});
if (key && userOptions) setOptions();
@ -78,11 +79,7 @@ export function useArrayData(key, userOptions) {
cancelRequest();
canceller = new AbortController();
const { params, limit } = getCurrentFilter();
store.currentFilter = JSON.parse(JSON.stringify(params));
delete store.currentFilter.filter.include;
store.currentFilter.filter = JSON.stringify(store.currentFilter.filter);
const { params, limit } = setCurrentFilter();
let exprFilter;
if (store?.exprBuilder) {
@ -107,7 +104,7 @@ export function useArrayData(key, userOptions) {
store.hasMoreData = limit && response.data.length >= limit;
if (!append && !isDialogOpened() && updateRouter) {
if (updateStateParams(response.data)?.redirect) return;
if (updateStateParams(response.data)?.redirect && !store.keepData) return;
}
store.isLoading = false;
canceller = null;
@ -142,12 +139,12 @@ export function useArrayData(key, userOptions) {
}
}
async function applyFilter({ filter, params }) {
async function applyFilter({ filter, params }, fetchOptions = {}) {
if (filter) store.userFilter = filter;
store.filter = {};
if (params) store.userParams = { ...params };
const response = await fetch({});
const response = await fetch(fetchOptions);
return response;
}
@ -276,14 +273,14 @@ export function useArrayData(key, userOptions) {
}
function getCurrentFilter() {
if (!Object.keys(store.userParams).length)
store.userParams = store.defaultParams ?? {};
const filter = {
limit: store.limit,
...store.userFilter,
};
let userParams = { ...store.userParams };
Object.assign(filter, store.userFilter);
let where;
if (filter?.where || store.filter?.where)
where = Object.assign(filter?.where ?? {}, store.filter?.where ?? {});
@ -291,7 +288,7 @@ export function useArrayData(key, userOptions) {
filter.where = where;
const params = { filter };
Object.assign(params, userParams);
Object.assign(params, store.userParams);
if (params.filter) params.filter.skip = store.skip;
if (store?.order && typeof store?.order == 'string') store.order = [store.order];
if (store.order?.length) params.filter.order = [...store.order];
@ -300,6 +297,14 @@ export function useArrayData(key, userOptions) {
return { filter, params, limit: filter.limit };
}
function setCurrentFilter() {
const { params, limit } = getCurrentFilter();
store.currentFilter = JSON.parse(JSON.stringify(params));
delete store.currentFilter.filter.include;
store.currentFilter.filter = JSON.stringify(store.currentFilter.filter);
return { params, limit };
}
function processData(data, { map = true, append = true }) {
if (!append) {
store.data = [];
@ -333,6 +338,7 @@ export function useArrayData(key, userOptions) {
applyFilter,
addFilter,
getCurrentFilter,
setCurrentFilter,
addFilterWhere,
addOrder,
deleteOrder,

View File

@ -29,8 +29,12 @@ export function useFilterParams(key) {
orders.value = orderObject;
}
function setUserParams(watchedParams) {
if (!watchedParams || Object.keys(watchedParams).length == 0) return;
function setUserParams(watchedParams = {}) {
if (Object.keys(watchedParams).length == 0) {
params.value = {};
orders.value = {};
return;
}
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
if (typeof watchedParams?.filter == 'string')

View File

@ -7,6 +7,7 @@ import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
import VnInput from 'src/components/common/VnInput.vue';
import VnInputDate from 'components/common/VnInputDate.vue';
import VnSelect from 'src/components/common/VnSelect.vue';
import VnSelectWorker from 'src/components/common/VnSelectWorker.vue';
const { t } = useI18n();
const props = defineProps({
@ -81,15 +82,12 @@ const getGroupedStates = (data) => {
</QItem>
<QItem>
<QItemSection>
<VnSelect
:label="t('Salesperson')"
<VnSelectWorker
:label="t('globals.salesPerson')"
v-model="params.salesPersonFk"
url="Workers/activeWithInheritedRole"
:where="{ role: 'salesPerson' }"
option-value="id"
option-label="firstName"
:use-like="false"
sort-by="firstName ASC"
:params="{
departmentCodes: ['VT'],
}"
dense
outlined
rounded