From 0384ab8568dd8aa2abbac547c043b834cc0a0dee Mon Sep 17 00:00:00 2001 From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com> Date: Wed, 2 Dec 2020 12:59:54 -0400 Subject: [PATCH] fix: Relations in context menu. (#553) --- .../ADempiere/ContextMenu/index.vue | 2 +- .../ADempiere/ContextMenu/relationsMixin.js | 13 +++++---- src/router/modules/ADempiere/menu.js | 2 ++ src/utils/ADempiere/valueUtils.js | 29 +++++++------------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/components/ADempiere/ContextMenu/index.vue b/src/components/ADempiere/ContextMenu/index.vue index 5497b8b6..a76be1ee 100644 --- a/src/components/ADempiere/ContextMenu/index.vue +++ b/src/components/ADempiere/ContextMenu/index.vue @@ -29,7 +29,7 @@ export default { // uuid of the component where it is called containerUuid: { type: String, - required: true + default: undefined }, panelType: { type: String, diff --git a/src/components/ADempiere/ContextMenu/relationsMixin.js b/src/components/ADempiere/ContextMenu/relationsMixin.js index 40eadd42..caed2a7f 100644 --- a/src/components/ADempiere/ContextMenu/relationsMixin.js +++ b/src/components/ADempiere/ContextMenu/relationsMixin.js @@ -8,12 +8,13 @@ export default { menuUuid = this.menuParentUuid } const relations = this.$store.getters.getRelations(menuUuid) - - if (!this.isEmptyValue(relations.children)) { - return relations.children - } - if (relations.meta && !this.isEmptyValue(relations.meta.childs)) { - return relations.meta.childs + if (!this.isEmptyValue(relations)) { + if (!this.isEmptyValue(relations.children)) { + return relations.children + } + if (relations.meta && !this.isEmptyValue(relations.meta.childs)) { + return relations.meta.childs + } } return [] }, diff --git a/src/router/modules/ADempiere/menu.js b/src/router/modules/ADempiere/menu.js index 7d42461b..8b7949ae 100644 --- a/src/router/modules/ADempiere/menu.js +++ b/src/router/modules/ADempiere/menu.js @@ -6,6 +6,7 @@ import Layout from '@/layout' /** * Get Menu from server + * @author Elsio Sanchez * @author Edwin Betancourt * @param {string} sessionUuid * @param {string} roleUuid @@ -63,6 +64,7 @@ export function loadMainMenu({ /** * Get Only Child + * @author Elsio Sanchez * @author Edwin Betancourt * @param {object} menu * @param {number} index diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index fee3ab79..c6c3ba95 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -188,24 +188,20 @@ export const recursiveTreeSearch = ({ treeData, attributeValue, attributeName = 'id', - secondAttributeName = '', + secondAttribute = false, attributeChilds = 'childsList', isParent = false }) => { if (Array.isArray(treeData)) { - // search in childs attribute let index = 0 const length = treeData.length while (index < length) { let value = treeData[index] - if (!isEmptyValue(value) && - Object.prototype.hasOwnProperty.call(value, attributeName)) { + if (!isEmptyValue(value) && Object.prototype.hasOwnProperty.call(value, attributeName)) { value = value[attributeName] } - if (!isEmptyValue(value) && - secondAttributeName && - Object.prototype.hasOwnProperty.call(value, secondAttributeName)) { - value = value[secondAttributeName] + if (!isEmptyValue(value) && secondAttribute && Object.prototype.hasOwnProperty.call(value, secondAttribute)) { + value = value[secondAttribute] } // compare item to search @@ -214,12 +210,11 @@ export const recursiveTreeSearch = ({ } if (treeData[index] && treeData[index][attributeChilds]) { - const newTree = treeData[index][attributeChilds] const found = recursiveTreeSearch({ - treeData: newTree, + treeData: treeData[index][attributeChilds], attributeValue, attributeName, - secondAttributeName, + secondAttribute, attributeChilds, isParent }) @@ -230,16 +225,12 @@ export const recursiveTreeSearch = ({ index++ } } else { - // search into meta attribute let value = treeData - if (!isEmptyValue(value) && - Object.prototype.hasOwnProperty.call(value, attributeName)) { + if (!isEmptyValue(value) && Object.prototype.hasOwnProperty.call(value, attributeName)) { value = value[attributeName] } - if (!isEmptyValue(value) && - secondAttributeName && - Object.prototype.hasOwnProperty.call(value, secondAttributeName)) { - value = value[secondAttributeName] + if (!isEmptyValue(value) && secondAttribute && Object.prototype.hasOwnProperty.call(value, secondAttribute)) { + value = value[secondAttribute] } // compare item to search @@ -251,7 +242,7 @@ export const recursiveTreeSearch = ({ treeData: treeData[attributeChilds], attributeValue, attributeName, - secondAttributeName, + secondAttribute, attributeChilds }) return found