0
0
Fork 0

Merge pull request 'fix(VnFilterPanel): emit userParams better' (!607) from warmFix_vnFilterPanel_setUserParams into dev

Reviewed-on: verdnatura/salix-front#607
Reviewed-by: Jorge Penades <jorgep@verdnatura.es>
This commit is contained in:
Alex Moreno 2024-08-09 10:38:01 +00:00
commit 42a490cf18
2 changed files with 15 additions and 12 deletions

View File

@ -154,7 +154,7 @@ watch(
const isTableMode = computed(() => mode.value == TABLE_MODE); const isTableMode = computed(() => mode.value == TABLE_MODE);
function setUserParams(watchedParams) { function setUserParams(watchedParams, watchedOrder) {
if (!watchedParams) return; if (!watchedParams) return;
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams); if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
@ -163,7 +163,7 @@ function setUserParams(watchedParams) {
? JSON.parse(watchedParams?.filter) ? JSON.parse(watchedParams?.filter)
: watchedParams?.filter; : watchedParams?.filter;
const where = filter?.where; const where = filter?.where;
const order = filter?.order; const order = watchedOrder ?? filter?.order;
watchedParams = { ...watchedParams, ...where }; watchedParams = { ...watchedParams, ...where };
delete watchedParams.filter; delete watchedParams.filter;

View File

@ -82,23 +82,26 @@ onMounted(() => {
}); });
function setUserParams(watchedParams) { function setUserParams(watchedParams) {
if (!watchedParams) return; if (!watchedParams || Object.keys(watchedParams).length == 0) return;
if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams); if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams);
if (typeof watchedParams?.filter == 'string')
watchedParams.filter = JSON.parse(watchedParams.filter);
watchedParams = { ...watchedParams, ...watchedParams.filter?.where }; watchedParams = { ...watchedParams, ...watchedParams.filter?.where };
const order = watchedParams.filter?.order;
delete watchedParams.filter; delete watchedParams.filter;
userParams.value = { ...userParams.value, ...watchedParams }; userParams.value = { ...userParams.value, ...sanitizer(watchedParams) };
emit('setUserParams', userParams.value); emit('setUserParams', userParams.value, order);
} }
watch( watch(
() => route.query[$props.searchUrl], () => [route.query[$props.searchUrl], arrayData.store.userParams],
(val) => setUserParams(val) ([newSearchUrl, newUserParams], [oldSearchUrl, oldUserParams]) => {
); if (newSearchUrl || oldSearchUrl) setUserParams(newSearchUrl);
if (newUserParams || oldUserParams) setUserParams(newUserParams);
watch( }
() => arrayData.store.userParams,
(val) => setUserParams(val)
); );
watch( watch(