ref #5417 fix filters and view #97

Merged
jorgep merged 12 commits from 5417-fixCustomerPayments into dev 2023-10-18 07:25:29 +00:00
6 changed files with 45 additions and 27 deletions
Showing only changes of commit 98b76b2f53 - Show all commits

View File

@ -42,27 +42,24 @@ onMounted(() => {
const isLoading = ref(false); const isLoading = ref(false);
async function search() { async function search() {
if (props.showAll) { const params = userParams.value;
const params = userParams.value; for (const param in params) {
for (const param in params) { if (params[param] === '' || params[param] === null) {
if (params[param] === '' || params[param] === null) { delete userParams.value[param];
delete userParams.value[param]; delete store.userParams[param];
delete store.userParams[param];
}
} }
isLoading.value = true;
await arrayData.addFilter({ params });
isLoading.value = false;
} else {
store.data = [];
} }
isLoading.value = true;
await arrayData.addFilter({ params });
if (!props.showAll && !Object.values(params).length) store.data = [];
jorgep marked this conversation as resolved
Review

Por algún motivo, no se eliminan params.from ni params.to. Solo se elimina su valor, aunque se haga el delete, en la store.userParams si que se eliminan. @alexm

Por algún motivo, no se eliminan params.from ni params.to. Solo se elimina su valor, aunque se haga el delete, en la store.userParams si que se eliminan. @alexm
isLoading.value = false;
} }
async function reload() { async function reload() {
isLoading.value = true; isLoading.value = true;
if (props.showAll) await arrayData.fetch({ append: false });
Review

He probado a copiar el objeto con JSON.parse pero no funciona en este caso. @alexm

He probado a copiar el objeto con JSON.parse pero no funciona en este caso. @alexm
else store.data = []; await arrayData.fetch({ append: false });
if (!props.showAll && !Object.values(userParams.value).length) store.data = [];
isLoading.value = false; isLoading.value = false;
emit('refresh'); emit('refresh');
} }
@ -70,8 +67,8 @@ async function reload() {
async function clearFilters() { async function clearFilters() {
userParams.value = {}; userParams.value = {};
isLoading.value = true; isLoading.value = true;
if (props.showAll) await arrayData.applyFilter({ params: {} }); await arrayData.applyFilter({ params: {} });
else store.data = []; if (!props.showAll) store.data = [];
isLoading.value = false; isLoading.value = false;
emit('clear'); emit('clear');

View File

@ -50,6 +50,10 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
showAll: {
type: Boolean,
default: true,
},
}); });
const emit = defineEmits(['onFetch', 'onPaginate']); const emit = defineEmits(['onFetch', 'onPaginate']);
@ -72,7 +76,12 @@ const arrayData = useArrayData(props.dataKey, {
const store = arrayData.store; const store = arrayData.store;
onMounted(() => { onMounted(() => {
if (props.autoLoad) fetch(); if (props.autoLoad) {
if (props.showAll) fetch();
else if (!props.showAll && Object.values(store.userParams).length) fetch();
else if (!props.showAll && !Object.values(store.userParams).length)
store.data = [];
}
}); });
watch( watch(

View File

@ -78,6 +78,7 @@ export function useArrayData(key, userOptions) {
signal: canceller.signal, signal: canceller.signal,
params, params,
}); });
const { limit } = filter; const { limit } = filter;
hasMoreData.value = response.data.length === limit; hasMoreData.value = response.data.length === limit;
@ -135,8 +136,8 @@ export function useArrayData(key, userOptions) {
} }
async function refresh(showAll = true) { async function refresh(showAll = true) {
if (showAll) await fetch({ append: false }); if (showAll || (!showAll && Object.values(store.userParams).length))
jorgep marked this conversation as resolved Outdated

!showAll sobraria no?

!showAll sobraria no?
if (!showAll) store.data = []; await fetch({ append: false });
} }
function updateStateParams() { function updateStateParams() {

View File

@ -144,6 +144,7 @@ function stateColor(row) {
order="created DESC" order="created DESC"
:limit="20" :limit="20"
:offset="50" :offset="50"
auto-load
:show-all="false" :show-all="false"
> >
<template #body="{ rows }"> <template #body="{ rows }">

View File

@ -76,7 +76,12 @@ function isValidNumber(value) {
</QItem> </QItem>
<QItem> <QItem>
<QItemSection> <QItemSection>
<QInput v-model="params.from" :label="t('From')" mask="date"> <QInput
v-model="params.from"
:label="t('From')"
mask="date"
placeholder="yyyy/mm/dd"
>
<template #append> <template #append>
<QIcon name="event" class="cursor-pointer"> <QIcon name="event" class="cursor-pointer">
<QPopupProxy <QPopupProxy
@ -108,7 +113,12 @@ function isValidNumber(value) {
</QInput> </QInput>
</QItemSection> </QItemSection>
<QItemSection> <QItemSection>
<QInput v-model="params.to" :label="t('To')" mask="date"> <QInput
v-model="params.to"
:label="t('To')"
mask="date"
placeholder="yyyy/mm/dd"
>
<template #append> <template #append>
<QIcon name="event" class="cursor-pointer"> <QIcon name="event" class="cursor-pointer">
<QPopupProxy <QPopupProxy

View File

@ -8,18 +8,18 @@ describe('WorkerList', () => {
it('should load workers', () => { it('should load workers', () => {
cy.get('.card-list-body > .list-items > :nth-child(2) > .value > span') cy.get('.card-list-body > .list-items > :nth-child(2) > .value > span')
.eq(0) .eq(0)
.should('have.text', 'victorvd');
cy.get('.card-list-body > .list-items > :nth-child(2) > .value > span')
.eq(1)
.should('have.text', 'JessicaJones'); .should('have.text', 'JessicaJones');
cy.get('.card-list-body > .list-items > :nth-child(2) > .value > span') cy.get('.card-list-body > .list-items > :nth-child(2) > .value > span')
.eq(2) .eq(1)
.should('have.text', 'BruceBanner'); .should('have.text', 'BruceBanner');
cy.get('.card-list-body > .list-items > :nth-child(2) > .value > span')
.eq(2)
.should('have.text', 'CharlesXavier');
}); });
it('should open the worker summary', () => { it('should open the worker summary', () => {
cy.get('.card-list-body .actions .q-btn:nth-child(2)').eq(1).click(); cy.get('.card-list-body .actions .q-btn:nth-child(2)').eq(1).click();
cy.get('.summaryHeader div').should('have.text', '1110 - Jessica Jones'); cy.get('.summaryHeader div').should('have.text', '1109 - Bruce Banner');
cy.get('.summary .header').eq(0).invoke('text').should('include', 'Basic data'); cy.get('.summary .header').eq(0).invoke('text').should('include', 'Basic data');
cy.get('.summary .header').eq(1).should('have.text', 'User data'); cy.get('.summary .header').eq(1).should('have.text', 'User data');
}); });