forked from verdnatura/salix-front
Reviewed-on: verdnatura/salix-front#273 Reviewed-by: Javier Segarra <jsegarra@verdnatura.es>
This commit is contained in:
commit
a153146f82
|
@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- (General) => Se vuelven a mostrar los parámetros en la url al aplicar un filtro
|
||||||
|
|
||||||
## [2414.01] - 2024-04-04
|
## [2414.01] - 2024-04-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -101,16 +101,16 @@ onMounted(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeRouteLeave((to, from, next) => {
|
onBeforeRouteLeave((to, from, next) => {
|
||||||
if (!hasChanges.value) next();
|
if (hasChanges.value)
|
||||||
|
quasar.dialog({
|
||||||
quasar.dialog({
|
component: VnConfirm,
|
||||||
component: VnConfirm,
|
componentProps: {
|
||||||
componentProps: {
|
title: t('Unsaved changes will be lost'),
|
||||||
title: t('Unsaved changes will be lost'),
|
message: t('Are you sure exit without saving?'),
|
||||||
message: t('Are you sure exit without saving?'),
|
promise: () => next(),
|
||||||
promise: () => next(),
|
},
|
||||||
},
|
});
|
||||||
});
|
else next();
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { useCapitalize } from 'src/composables/useCapitalize';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: { type: String, default: '' },
|
modelValue: { type: [String, Number], default: '' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { onMounted, ref, computed } from 'vue';
|
import { onMounted, ref, computed } from 'vue';
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useArrayDataStore } from 'stores/useArrayDataStore';
|
import { useArrayDataStore } from 'stores/useArrayDataStore';
|
||||||
import { buildFilter } from 'filters/filterPanel';
|
import { buildFilter } from 'filters/filterPanel';
|
||||||
|
@ -15,7 +15,6 @@ export function useArrayData(key, userOptions) {
|
||||||
|
|
||||||
const store = arrayDataStore.get(key);
|
const store = arrayDataStore.get(key);
|
||||||
const hasMoreData = ref(false);
|
const hasMoreData = ref(false);
|
||||||
const router = useRouter();
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
let canceller = null;
|
let canceller = null;
|
||||||
|
|
||||||
|
@ -105,7 +104,7 @@ export function useArrayData(key, userOptions) {
|
||||||
for (const row of response.data) store.data.push(row);
|
for (const row of response.data) store.data.push(row);
|
||||||
} else {
|
} else {
|
||||||
store.data = response.data;
|
store.data = response.data;
|
||||||
if (!document.querySelectorAll('[role="dialog"]'))
|
if (!document.querySelectorAll('[role="dialog"]').length)
|
||||||
updateRouter && updateStateParams();
|
updateRouter && updateStateParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,11 +187,15 @@ export function useArrayData(key, userOptions) {
|
||||||
if (store.userParams && Object.keys(store.userParams).length !== 0)
|
if (store.userParams && Object.keys(store.userParams).length !== 0)
|
||||||
query.params = JSON.stringify(store.userParams);
|
query.params = JSON.stringify(store.userParams);
|
||||||
|
|
||||||
if (router)
|
const url = new URL(window.location.href);
|
||||||
router.replace({
|
const { hash: currentHash } = url;
|
||||||
path: route.path,
|
const [currentRoute] = currentHash.split('?');
|
||||||
query: query,
|
|
||||||
});
|
const params = new URLSearchParams();
|
||||||
|
for (const param in query) params.append(param, query[param]);
|
||||||
|
|
||||||
|
url.hash = currentRoute + '?' + params.toString();
|
||||||
|
window.history.pushState({}, '', url.hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalRows = computed(() => (store.data && store.data.length) || 0);
|
const totalRows = computed(() => (store.data && store.data.length) || 0);
|
||||||
|
|
|
@ -36,7 +36,7 @@ describe('VnSearchBar', () => {
|
||||||
const checkCardListAndUrl = (expectedLength) => {
|
const checkCardListAndUrl = (expectedLength) => {
|
||||||
cy.get(cardList).then(($cardList) => {
|
cy.get(cardList).then(($cardList) => {
|
||||||
expect($cardList.find('.q-card').length).to.equal(expectedLength);
|
expect($cardList.find('.q-card').length).to.equal(expectedLength);
|
||||||
cy.url().then((currentUrl) => expect(currentUrl).to.equal(url));
|
cy.url().then((currentUrl) => expect(currentUrl).to.contain(url));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { describe, expect, it, beforeAll } from 'vitest';
|
||||||
|
import { axios } from 'app/test/vitest/helper';
|
||||||
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
|
|
||||||
|
describe('useArrayData', () => {
|
||||||
|
let arrayData;
|
||||||
|
beforeAll(() => {
|
||||||
|
axios.get.mockResolvedValue({ data: [] });
|
||||||
|
arrayData = useArrayData('InvoiceIn', { url: 'invoice-in/list' });
|
||||||
|
Object.defineProperty(window.location, 'href', {
|
||||||
|
writable: true,
|
||||||
|
value: 'localhost:9000/invoice-in/list',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mock the window.history.pushState method within useArrayData
|
||||||
|
window.history.pushState = (data, title, url) => (window.location.href = url);
|
||||||
|
|
||||||
|
// Mock the URL constructor within useArrayData
|
||||||
|
global.URL = class URL {
|
||||||
|
constructor(url) {
|
||||||
|
this.hash = url.split('localhost:9000/')[1];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the params to the url', async () => {
|
||||||
|
arrayData.store.userParams = { supplierFk: 2 };
|
||||||
|
arrayData.updateStateParams();
|
||||||
|
expect(window.location.href).contain('params=%7B%22supplierFk%22%3A2%7D');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue