diff --git a/rdmo/management/assets/js/reducers/importsReducer.js b/rdmo/management/assets/js/reducers/importsReducer.js index e6a0f32b1b..775cb28d97 100644 --- a/rdmo/management/assets/js/reducers/importsReducer.js +++ b/rdmo/management/assets/js/reducers/importsReducer.js @@ -2,7 +2,7 @@ import isArray from 'lodash/isArray' import isNil from 'lodash/isNil' import isUndefined from 'lodash/isUndefined' -import { buildUri, buildPath } from '../utils/elements' +import { buildUri, buildPathForAttribute } from '../utils/elements' import processElementDiffs from '../utils/processElementDiffs' @@ -49,7 +49,7 @@ export default function importsReducer(state = initialState, action) { const elements = [...state.elements] elements[index] = {...elements[index], ...action.values} if (elements[index].model === 'domain.attribute') { - elements[index].path = buildPath(elements[index].key, elements[index].parent ? elements[index].parent.uri : null, elements) + elements[index].path = buildPathForAttribute(elements[index].key, elements[index].parent ? elements[index].parent.uri : null) } elements[index].uri = buildUri(elements[index]) return {...state, elements} diff --git a/rdmo/management/assets/js/utils/elements.js b/rdmo/management/assets/js/utils/elements.js index f56f86df04..5abdaa934a 100644 --- a/rdmo/management/assets/js/utils/elements.js +++ b/rdmo/management/assets/js/utils/elements.js @@ -174,16 +174,11 @@ const buildUri = (element) => { return uri } -const buildPath = (key, parentUri, elements) => { - +const buildPathForAttribute = (key, parentUri) => { let path = key if (parentUri) { - const parentElement = elements.find(element => element.uri === parentUri) - if (parentElement) { - const parentPath = parentElement.path - path = parentPath ? `${parentPath}/${key}` : key - } else if (parentUri.includes('/domain/')) { - // If parentElement is not found, construct the path using parentUri directly + if (parentUri.includes('/domain/')) { + // construct the path using parentUri directly const parentPath = parentUri.split('/domain/')[1] path = parentPath ? `${parentPath}/${key}` : key } @@ -194,4 +189,4 @@ const buildPath = (key, parentUri, elements) => { -export { compareElements, updateElement, resetElement, canMoveElement, moveElement, findDescendants, buildUri, buildPath } +export { compareElements, updateElement, resetElement, canMoveElement, moveElement, findDescendants, buildUri, buildPathForAttribute }