From c61c644e46f467e4b4fa5f1754568403a4e680f5 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 10 Mar 2025 09:34:15 +0100 Subject: [PATCH 1/3] refactor: refs #8197 simplify menu retrieval logic in LeftMenu component --- src/components/LeftMenu.vue | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/components/LeftMenu.vue b/src/components/LeftMenu.vue index 9a9949499..544b1287c 100644 --- a/src/components/LeftMenu.vue +++ b/src/components/LeftMenu.vue @@ -92,7 +92,7 @@ function findMatches(search, item) { } function addChildren(module, route, parent) { - const menus = route?.meta?.menu ?? route?.menus?.[props.source]; //backwards compatible + const menus = route?.meta?.menu; if (!menus) return; const matches = findMatches(menus, route); @@ -132,21 +132,16 @@ function getMainRoutes() { function getCardRoutes() { const currentRoute = route.matched[1]; 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; - while (!menuRoute && index > 0) { - if (route.matched[index]?.meta?.menu) menuRoute = route.matched[index]; + while (!moduleDef && index > 0) { + if (route.matched[index]?.meta?.menu) moduleDef = route.matched[index]; index--; } - return menuRoute; + + if (!moduleDef) return; + addChildren(currentModule, moduleDef, items.value); } async function togglePinned(item, event) { From bd72ccbb051efbd38f8735dfb86813b5f6927cb4 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 10 Mar 2025 09:54:36 +0100 Subject: [PATCH 2/3] test: refs #8197 comment out ticket list tests for refactoring --- test/cypress/integration/ticket/ticketList.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cypress/integration/ticket/ticketList.spec.js b/test/cypress/integration/ticket/ticketList.spec.js index 25ee05033..2409dd149 100644 --- a/test/cypress/integration/ticket/ticketList.spec.js +++ b/test/cypress/integration/ticket/ticketList.spec.js @@ -38,8 +38,8 @@ describe('TicketList', () => { it('filter client and create ticket', () => { cy.intercept('GET', /\/api\/Tickets\/filter/).as('ticketSearchbar'); searchResults(); + cy.wait('@ticketSearchbar'); - cy.intercept('GET', /\/api\/Tickets\/filter/).as('ticketFilter'); cy.dataCy('Customer ID_input').clear('1'); cy.dataCy('Customer ID_input').type('1101{enter}'); From 759701fcbe2c5ef7af1e2906a7bbb99e0b1e3432 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 11 Mar 2025 10:47:40 +0100 Subject: [PATCH 3/3] fix(LeftMenu): refs #8197 handle missing children in findRoute and update menu structure --- src/components/LeftMenu.vue | 8 ++------ src/components/__tests__/Leftmenu.spec.js | 21 +++++---------------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/components/LeftMenu.vue b/src/components/LeftMenu.vue index 544b1287c..8e83bf579 100644 --- a/src/components/LeftMenu.vue +++ b/src/components/LeftMenu.vue @@ -77,6 +77,7 @@ watch( function findMatches(search, item) { const matches = []; function findRoute(search, item) { + if (!item?.children) return; for (const child of item.children) { if (search?.indexOf(child.name) > -1) { matches.push(child); @@ -107,11 +108,7 @@ function getRoutes() { main: getMainRoutes, card: getCardRoutes, }; - try { - handleRoutes[props.source](); - } catch (error) { - throw new Error(`Method is not defined`); - } + handleRoutes[props.source](); } function getMainRoutes() { const modules = Object.assign([], navigation.getModules().value); @@ -122,7 +119,6 @@ function getMainRoutes() { ); if (!moduleDef) continue; item.children = []; - addChildren(item.module, moduleDef, item.children); } diff --git a/src/components/__tests__/Leftmenu.spec.js b/src/components/__tests__/Leftmenu.spec.js index 4ab8b527f..ef82cf9ad 100644 --- a/src/components/__tests__/Leftmenu.spec.js +++ b/src/components/__tests__/Leftmenu.spec.js @@ -15,10 +15,7 @@ vi.mock('src/router/modules', () => ({ meta: { title: 'customers', icon: 'vn:client', - }, - menus: { - main: ['CustomerList', 'CustomerCreate'], - card: ['CustomerBasicData'], + menu: ['CustomerList', 'CustomerCreate'], }, children: [ { @@ -98,7 +95,7 @@ vi.spyOn(vueRouter, 'useRoute').mockReturnValue({ icon: 'vn:client', moduleName: 'Customer', 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', () => { vm.props.source = 'main'; vm.getRoutes(); @@ -351,8 +339,9 @@ describe('addChildren', () => { it('should handle routes with no meta menu', () => { const route = { - meta: {}, - menus: {}, + meta: { + menu: [], + }, }; const parent = [];