fix: refs #8197 staticParams and redirect
gitea/salix-front/pipeline/pr-beta This commit looks good Details

This commit is contained in:
Alex Moreno 2024-12-23 17:56:09 +01:00
parent a940eb9861
commit dd36b35bf7
8 changed files with 23 additions and 14 deletions

View File

@ -59,6 +59,7 @@ const pinnedModulesRef = ref();
'no-visible': !stateQuery.isLoading().value, 'no-visible': !stateQuery.isLoading().value,
}" }"
size="xs" size="xs"
data-cy="loading-spinner"
/> />
<QSpace /> <QSpace />
<div id="searchbar" class="searchbar"></div> <div id="searchbar" class="searchbar"></div>

View File

@ -34,15 +34,20 @@ const $props = defineProps({
type: Object, type: Object,
default: null, default: null,
}, },
redirect: {
type: Boolean,
default: true,
},
}); });
const sectionValue = computed(() => $props.section ?? $props.dataKey); const sectionValue = computed(() => $props.section ?? $props.dataKey);
let arrayData;
onBeforeMount(() => { onBeforeMount(() => {
if ($props.dataKey) if ($props.dataKey)
useArrayData($props.dataKey, { arrayData = useArrayData($props.dataKey, {
searchUrl: 'table', searchUrl: 'table',
...$props.arrayDataProps, ...$props.arrayDataProps,
navigate: $props.redirect,
}); });
}); });
</script> </script>
@ -63,12 +68,12 @@ onBeforeMount(() => {
<VnTableFilter <VnTableFilter
v-if="rightFilter && columns" v-if="rightFilter && columns"
:data-key="dataKey" :data-key="dataKey"
:array-data="arrayData"
:columns="columns" :columns="columns"
/> />
</slot> </slot>
</template> </template>
</RightMenu> </RightMenu>
<slot name="body" v-if="sectionValue == $route.name" /> <slot name="body" v-if="sectionValue == $route.name" />
<RouterView v-else /> <RouterView v-else />
</template> </template>

View File

@ -112,7 +112,6 @@ onMounted(async () => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
arrayData.resetPagination(); arrayData.resetPagination();
arrayData.reset(['currentFilter', 'userParams', 'userFilter']);
}); });
watch( watch(
@ -142,7 +141,7 @@ const addFilter = async (filter, params) => {
async function fetch(params) { async function fetch(params) {
useArrayData(props.dataKey, params); useArrayData(props.dataKey, params);
arrayData.resetPagination(); arrayData.resetPagination();
await arrayData.fetch({ append: false, updateRouter: mounted.value }); await arrayData.fetch({ append: false });
return emitStoreData(); return emitStoreData();
} }
@ -217,7 +216,7 @@ defineExpose({
<template> <template>
<div class="full-width"> <div class="full-width">
<div <div
v-if="!props.autoLoad && !store.data && !isLoading" v-if="!store.data && !store.data?.length && !isLoading"
class="info-row q-pa-md text-center" class="info-row q-pa-md text-center"
> >
<h5> <h5>

View File

@ -100,7 +100,9 @@ onMounted(() => {
}); });
async function search() { async function search() {
const staticParams = Object.entries(store.userParams); const staticParams = Object.keys(store.userParams ?? {}).length
? store.userParams
: store.defaultParams;
arrayData.resetPagination(); arrayData.resetPagination();
const filter = { const filter = {
@ -112,7 +114,7 @@ async function search() {
if (!props.searchRemoveParams || !searchText.value) { if (!props.searchRemoveParams || !searchText.value) {
filter.params = { filter.params = {
...Object.fromEntries(staticParams), ...staticParams,
search: searchText.value, search: searchText.value,
}; };
} }

View File

@ -64,6 +64,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) {
store[option] = userOptions.keepOpts?.includes(option) store[option] = userOptions.keepOpts?.includes(option)
? Object.assign(defaultOpts, store[option]) ? Object.assign(defaultOpts, store[option])
: defaultOpts; : defaultOpts;
if (option === 'userParams') store.defaultParams = store[option];
} }
} }
} }

View File

@ -1,10 +1,11 @@
<script setup> <script setup>
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { computed } from 'vue'; import { computed, ref } from 'vue';
import VnTable from 'components/VnTable/VnTable.vue'; import VnTable from 'components/VnTable/VnTable.vue';
import AccountSummary from './Card/AccountSummary.vue'; import AccountSummary from './Card/AccountSummary.vue';
import { useSummaryDialog } from 'src/composables/useSummaryDialog'; import { useSummaryDialog } from 'src/composables/useSummaryDialog';
import VnSection from 'src/components/common/VnSection.vue'; import VnSection from 'src/components/common/VnSection.vue';
import FetchData from 'src/components/FetchData.vue';
const { t } = useI18n(); const { t } = useI18n();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
@ -12,6 +13,7 @@ const filter = {
include: { relation: 'role', scope: { fields: ['id', 'name'] } }, include: { relation: 'role', scope: { fields: ['id', 'name'] } },
}; };
const dataKey = 'AccountList'; const dataKey = 'AccountList';
const roles = ref([]);
const columns = computed(() => [ const columns = computed(() => [
{ {
align: 'left', align: 'left',
@ -29,7 +31,7 @@ const columns = computed(() => [
component: 'select', component: 'select',
name: 'roleFk', name: 'roleFk',
attrs: { attrs: {
url: 'VnRoles', options: roles,
optionValue: 'id', optionValue: 'id',
optionLabel: 'name', optionLabel: 'name',
}, },
@ -103,6 +105,7 @@ function exprBuilder(param, value) {
</script> </script>
<template> <template>
<FetchData url="VnRoles" @on-fetch="(data) => (roles = data)" auto-load />
<VnSection <VnSection
:data-key="dataKey" :data-key="dataKey"
:columns="columns" :columns="columns"

View File

@ -419,7 +419,6 @@ function handleLocation(data, location) {
:columns="columns" :columns="columns"
redirect="customer" redirect="customer"
:right-search="false" :right-search="false"
auto-load
> >
<template #more-create-dialog="{ data }"> <template #more-create-dialog="{ data }">
<VnSelect <VnSelect

View File

@ -7,10 +7,10 @@ describe('VnSearchBar', () => {
beforeEach(() => { beforeEach(() => {
cy.viewport(1280, 720); cy.viewport(1280, 720);
cy.login('developer'); cy.login('developer');
cy.visit('#/customer/list'); cy.visit('#/account/list');
}); });
it('should redirect to customer summary page', () => { it('should redirect to account summary page', () => {
searchAndCheck('1', employeeId); searchAndCheck('1', employeeId);
searchAndCheck('salesPerson', salesPersonId); searchAndCheck('salesPerson', salesPersonId);
}); });
@ -20,7 +20,6 @@ describe('VnSearchBar', () => {
checkTableLength(2); checkTableLength(2);
cy.clearSearchbar(); cy.clearSearchbar();
cy.writeSearchbar('0{enter}'); cy.writeSearchbar('0{enter}');
checkTableLength(0); checkTableLength(0);
}); });