From d2ac7b993217cb4008b344866cfe2acce4ff20fc Mon Sep 17 00:00:00 2001 From: wbuezas Date: Mon, 1 Jul 2024 11:05:14 -0300 Subject: [PATCH] Handle empty response of default columns from backend --- src/components/common/TableVisibleColumns.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/common/TableVisibleColumns.vue b/src/components/common/TableVisibleColumns.vue index 7aa696a07..a4e4afafe 100644 --- a/src/components/common/TableVisibleColumns.vue +++ b/src/components/common/TableVisibleColumns.vue @@ -52,7 +52,7 @@ const toggleMarkAll = (val) => { const getConfig = async (url, filter) => { const response = await axios.get(url, { - params: { filter: filter }, + params: { filter: JSON.stringify(filter) }, }); return response.data && response.data.length > 0 ? response.data[0] : null; }; @@ -60,7 +60,7 @@ const getConfig = async (url, filter) => { const fetchViewConfigData = async () => { try { const userConfigFilter = { - where: { tableCode: $props.tableCode, userFk: user.id }, + where: { tableCode: $props.tableCode, userFk: user.value.id }, }; const userConfig = await getConfig('UserConfigViews', userConfigFilter); @@ -74,8 +74,14 @@ const fetchViewConfigData = async () => { const defaultConfig = await getConfig('DefaultViewConfigs', defaultConfigFilter); if (defaultConfig) { + // Si el backend devuelve una configuraciĆ³n por defecto la usamos setUserConfigViewData(defaultConfig.columns); return; + } else { + // Si no hay configuraciĆ³n por defecto mostramos todas las columnas + const defaultColumns = {}; + $props.allColumns.forEach((col) => (defaultColumns[col] = true)); + setUserConfigViewData(defaultColumns); } } catch (err) { console.err('Error fetching config view data', err);