forked from verdnatura/salix-front
Handle empty response of default columns from backend
This commit is contained in:
parent
9f68c380da
commit
d2ac7b9932
|
@ -52,7 +52,7 @@ const toggleMarkAll = (val) => {
|
||||||
|
|
||||||
const getConfig = async (url, filter) => {
|
const getConfig = async (url, filter) => {
|
||||||
const response = await axios.get(url, {
|
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;
|
return response.data && response.data.length > 0 ? response.data[0] : null;
|
||||||
};
|
};
|
||||||
|
@ -60,7 +60,7 @@ const getConfig = async (url, filter) => {
|
||||||
const fetchViewConfigData = async () => {
|
const fetchViewConfigData = async () => {
|
||||||
try {
|
try {
|
||||||
const userConfigFilter = {
|
const userConfigFilter = {
|
||||||
where: { tableCode: $props.tableCode, userFk: user.id },
|
where: { tableCode: $props.tableCode, userFk: user.value.id },
|
||||||
};
|
};
|
||||||
const userConfig = await getConfig('UserConfigViews', userConfigFilter);
|
const userConfig = await getConfig('UserConfigViews', userConfigFilter);
|
||||||
|
|
||||||
|
@ -74,8 +74,14 @@ const fetchViewConfigData = async () => {
|
||||||
const defaultConfig = await getConfig('DefaultViewConfigs', defaultConfigFilter);
|
const defaultConfig = await getConfig('DefaultViewConfigs', defaultConfigFilter);
|
||||||
|
|
||||||
if (defaultConfig) {
|
if (defaultConfig) {
|
||||||
|
// Si el backend devuelve una configuración por defecto la usamos
|
||||||
setUserConfigViewData(defaultConfig.columns);
|
setUserConfigViewData(defaultConfig.columns);
|
||||||
return;
|
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) {
|
} catch (err) {
|
||||||
console.err('Error fetching config view data', err);
|
console.err('Error fetching config view data', err);
|
||||||
|
|
Loading…
Reference in New Issue