diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index b1c7606e6..521840ebc 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -249,7 +249,7 @@ function getChanges() { for (const [i, row] of formData.value.entries()) { if (!row[pk]) { creates.push(row); - } else if (originalData.value) { + } else if (originalData.value[i]) { const data = getDifferences(originalData.value[i], row); if (!isEmpty(data)) { updates.push({ diff --git a/src/components/EditTableCellValueForm.vue b/src/components/EditTableCellValueForm.vue index 7755df9ab..172866191 100644 --- a/src/components/EditTableCellValueForm.vue +++ b/src/components/EditTableCellValueForm.vue @@ -85,12 +85,14 @@ const closeForm = () => { hide-selected option-label="label" v-model="selectedField" + data-cy="field-to-edit" /> diff --git a/src/components/ItemsFilterPanel.vue b/src/components/ItemsFilterPanel.vue index 405577095..084feb377 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,21 @@ 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 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 +82,7 @@ const applyTags = (params, search) => { search(); }; -const fetchItemTypes = async (id) => { +const fetchItemTypes = async (id = selectedCategoryFk.value) => { const filter = { fields: ['id', 'name', 'categoryFk'], where: { categoryFk: id }, @@ -126,15 +121,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(); +};