From 8e67a73d9015d3785a77bf4ceeefbcab9505ecc8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sun, 17 Nov 2024 17:15:51 +0100 Subject: [PATCH] perf: #7260 ItemsFilterPanel --- src/components/ItemsFilterPanel.vue | 58 +++++++++++++++++------------ src/filters/getParamWhere.js | 17 +++++---- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/components/ItemsFilterPanel.vue b/src/components/ItemsFilterPanel.vue index e89d32da4..a70d46953 100644 --- a/src/components/ItemsFilterPanel.vue +++ b/src/components/ItemsFilterPanel.vue @@ -9,6 +9,8 @@ import VnSelect from 'components/common/VnSelect.vue'; import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue'; import axios from 'axios'; +import { getParamWhere } from 'src/filters'; +import { useRoute } from 'vue-router'; const { t } = useI18n(); const props = defineProps({ @@ -26,28 +28,33 @@ const props = defineProps({ }, }); -const itemCategories = ref([]); -const selectedCategoryFk = ref(null); -const selectedTypeFk = ref(null); +const route = useRoute(); + const itemTypesOptions = ref([]); const suppliersOptions = ref([]); const tagOptions = ref([]); const tagValues = ref([]); +const categoryList = ref(null); +const selectedCategoryFk = ref(getParamWhere(route.query.table, 'categoryFk', false)); +const selectedTypeFk = ref(getParamWhere(route.query.table, 'typeFk', false)); +// const selectedCategoryFk = ref( +// JSON.parse(route?.query?.table ?? '{}').categoryFk ?? null +// ); +// const selectedTypeFk = ref(JSON.parse(route?.query?.table ?? '{}').typeFk ?? null); +// const categoryList = computed(() => { +// return (itemCategories.value || []) +// .filter((category) => category.display) +// .map((category) => ({ +// ...category, +// icon: `vn:${(category.icon || '').split('-')[1]}`, +// })); +// }); -const categoryList = computed(() => { - return (itemCategories.value || []) - .filter((category) => category.display) - .map((category) => ({ - ...category, - icon: `vn:${(category.icon || '').split('-')[1]}`, - })); -}); - -const selectedCategory = computed(() => - (itemCategories.value || []).find( +const selectedCategory = computed(() => { + return (categoryList.value || []).find( (category) => category?.id === selectedCategoryFk.value - ) -); + ); +}); const selectedType = computed(() => { return (itemTypesOptions.value || []).find( @@ -87,7 +94,7 @@ const applyTags = (params, search) => { search(); }; -const fetchItemTypes = async (id) => { +const fetchItemTypes = async (id = selectedCategoryFk.value) => { try { const filter = { fields: ['id', 'name', 'categoryFk'], @@ -134,15 +141,19 @@ const removeTag = (index, params, search) => { (tagValues.value || []).splice(index, 1); applyTags(params, search); }; +const setCategoryList = (data) => { + categoryList.value = (data || []) + .filter((category) => category.display) + .map((category) => ({ + ...category, + icon: `vn:${(category.icon || '').split('-')[1]}`, + })); + fetchItemTypes(); +};