Skip to content

Commit

Permalink
refactor(js, import): rename to buildPathForAttribute and remove extras
Browse files Browse the repository at this point in the history
Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Jul 3, 2024
1 parent b5a0353 commit 550aeb5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions rdmo/management/assets/js/reducers/importsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down Expand Up @@ -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}
Expand Down
13 changes: 4 additions & 9 deletions rdmo/management/assets/js/utils/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 }

0 comments on commit 550aeb5

Please sign in to comment.