Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix-front into 8041-unifyClassLink
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
3d33208228
|
@ -77,6 +77,7 @@ watch(
|
||||||
function findMatches(search, item) {
|
function findMatches(search, item) {
|
||||||
const matches = [];
|
const matches = [];
|
||||||
function findRoute(search, item) {
|
function findRoute(search, item) {
|
||||||
|
if (!item?.children) return;
|
||||||
for (const child of item.children) {
|
for (const child of item.children) {
|
||||||
if (search?.indexOf(child.name) > -1) {
|
if (search?.indexOf(child.name) > -1) {
|
||||||
matches.push(child);
|
matches.push(child);
|
||||||
|
@ -92,7 +93,7 @@ function findMatches(search, item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addChildren(module, route, parent) {
|
function addChildren(module, route, parent) {
|
||||||
const menus = route?.meta?.menu ?? route?.menus?.[props.source]; //backwards compatible
|
const menus = route?.meta?.menu;
|
||||||
if (!menus) return;
|
if (!menus) return;
|
||||||
|
|
||||||
const matches = findMatches(menus, route);
|
const matches = findMatches(menus, route);
|
||||||
|
@ -107,11 +108,7 @@ function getRoutes() {
|
||||||
main: getMainRoutes,
|
main: getMainRoutes,
|
||||||
card: getCardRoutes,
|
card: getCardRoutes,
|
||||||
};
|
};
|
||||||
try {
|
|
||||||
handleRoutes[props.source]();
|
handleRoutes[props.source]();
|
||||||
} catch (error) {
|
|
||||||
throw new Error(`Method is not defined`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function getMainRoutes() {
|
function getMainRoutes() {
|
||||||
const modules = Object.assign([], navigation.getModules().value);
|
const modules = Object.assign([], navigation.getModules().value);
|
||||||
|
@ -122,7 +119,6 @@ function getMainRoutes() {
|
||||||
);
|
);
|
||||||
if (!moduleDef) continue;
|
if (!moduleDef) continue;
|
||||||
item.children = [];
|
item.children = [];
|
||||||
|
|
||||||
addChildren(item.module, moduleDef, item.children);
|
addChildren(item.module, moduleDef, item.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,21 +128,16 @@ function getMainRoutes() {
|
||||||
function getCardRoutes() {
|
function getCardRoutes() {
|
||||||
const currentRoute = route.matched[1];
|
const currentRoute = route.matched[1];
|
||||||
const currentModule = toLowerCamel(currentRoute.name);
|
const currentModule = toLowerCamel(currentRoute.name);
|
||||||
let moduleDef = routes.find((route) => toLowerCamel(route.name) === currentModule);
|
let moduleDef;
|
||||||
|
|
||||||
if (!moduleDef) return;
|
|
||||||
if (!moduleDef?.menus) moduleDef = betaGetRoutes();
|
|
||||||
addChildren(currentModule, moduleDef, items.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function betaGetRoutes() {
|
|
||||||
let menuRoute;
|
|
||||||
let index = route.matched.length - 1;
|
let index = route.matched.length - 1;
|
||||||
while (!menuRoute && index > 0) {
|
while (!moduleDef && index > 0) {
|
||||||
if (route.matched[index]?.meta?.menu) menuRoute = route.matched[index];
|
if (route.matched[index]?.meta?.menu) moduleDef = route.matched[index];
|
||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
return menuRoute;
|
|
||||||
|
if (!moduleDef) return;
|
||||||
|
addChildren(currentModule, moduleDef, items.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function togglePinned(item, event) {
|
async function togglePinned(item, event) {
|
||||||
|
|
|
@ -15,10 +15,7 @@ vi.mock('src/router/modules', () => ({
|
||||||
meta: {
|
meta: {
|
||||||
title: 'customers',
|
title: 'customers',
|
||||||
icon: 'vn:client',
|
icon: 'vn:client',
|
||||||
},
|
menu: ['CustomerList', 'CustomerCreate'],
|
||||||
menus: {
|
|
||||||
main: ['CustomerList', 'CustomerCreate'],
|
|
||||||
card: ['CustomerBasicData'],
|
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
@ -98,7 +95,7 @@ vi.spyOn(vueRouter, 'useRoute').mockReturnValue({
|
||||||
icon: 'vn:client',
|
icon: 'vn:client',
|
||||||
moduleName: 'Customer',
|
moduleName: 'Customer',
|
||||||
keyBinding: 'c',
|
keyBinding: 'c',
|
||||||
menu: 'customer',
|
menu: ['customer'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -260,15 +257,6 @@ describe('Leftmenu as main', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle a single matched route with a menu', () => {
|
|
||||||
const route = {
|
|
||||||
matched: [{ meta: { menu: 'customer' } }],
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = vm.betaGetRoutes();
|
|
||||||
|
|
||||||
expect(result.meta.menu).toEqual(route.matched[0].meta.menu);
|
|
||||||
});
|
|
||||||
it('should get routes for main source', () => {
|
it('should get routes for main source', () => {
|
||||||
vm.props.source = 'main';
|
vm.props.source = 'main';
|
||||||
vm.getRoutes();
|
vm.getRoutes();
|
||||||
|
@ -351,8 +339,9 @@ describe('addChildren', () => {
|
||||||
|
|
||||||
it('should handle routes with no meta menu', () => {
|
it('should handle routes with no meta menu', () => {
|
||||||
const route = {
|
const route = {
|
||||||
meta: {},
|
meta: {
|
||||||
menus: {},
|
menu: [],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const parent = [];
|
const parent = [];
|
||||||
|
|
Loading…
Reference in New Issue