Skip to content

Commit

Permalink
Merge pull request #239 from CSCfi/CSCFC4EMSCR-585_Suggestion-for-imp…
Browse files Browse the repository at this point in the history
…lementing-elementpath

CSCFC4EMSCR-585 Change node elementpath to array to fix tree selection
  • Loading branch information
masillan authored Dec 11, 2024
2 parents 7db19f8 + 86d6bac commit df14a39
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
13 changes: 6 additions & 7 deletions mscr-ui/src/common/components/schema-info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,17 @@ export default function SchemaInfo(props: {

// Used by tree select and filtering
function getAllNodeIdsOnPathToLeaf(nodeIds: string[]) {
const elementPaths: string[] = [];
let idsOnPath: string[] = [];
nodeIds.forEach((nodeId) => {
const nodes = nodeIdToNodeDictionary[nodeId];
nodes.map((node) => elementPaths.push(node.elementPath));
nodes.map((node) => {
idsOnPath = idsOnPath.concat(node.rootPathIds);
});
});

const nodesToSelect: Set<string> = new Set();
elementPaths.forEach((path) => {
const nodeIdsOnPath = path.split('.');
nodeIdsOnPath.forEach((nodeId) => {
nodesToSelect.add(nodeId);
});
idsOnPath.forEach((pathNodeId) => {
nodesToSelect.add(pathNodeId);
});

return Array.from(nodesToSelect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export default function NodeInfo(props: {
)}
{props.isNodeEditable &&
selectedNode &&
selectedNode?.elementPath !== 'ROOT' &&
!isLeafNode &&
!props.hasCustomRoot && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let treeIndex = 0;

function createRenderTree(
input: any,
elementPath: string,
rootPathIds: string[],
definitions: any,
idToNodeDictionary: { [key: string]: RenderTree[] },
) {
Expand All @@ -16,8 +16,7 @@ function createRenderTree(
visualTreeId: treeIndex.toString(),
id: obj.toString(),
properties: definitions[obj],
elementPath: elementPath == '' ? obj.toString() : elementPath + '.' + obj.toString(),
parentElementPath: elementPath,
rootPathIds: [...rootPathIds, obj.toString()],
children: [],
uri: definitions[obj]['@id'],
};
Expand All @@ -29,7 +28,7 @@ function createRenderTree(
// HAS CHILDREN, OTHERWISE IS LEAF
newNode.children = createRenderTree(
input[obj],
newNode.elementPath,
newNode.rootPathIds,
definitions,
idToNodeDictionary,
);
Expand All @@ -47,7 +46,7 @@ export function generateTreeFromJson(jsonInput: any) {
const generatedTree = new Promise<RenderTree[]>((resolve) => {
const renderedTree = createRenderTree(
jsonInput.content.tree,
'',
[],
jsonInput.content.definitions,
nodeIdToShallowNode
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export interface RenderTree {
visualTreeId: string;
id: string;
properties: any;
elementPath: string;
parentElementPath: string | undefined;
rootPathIds: string[];
children: RenderTree[];
uri: string;
}
Expand Down
3 changes: 1 addition & 2 deletions mscr-ui/src/modules/crosswalk-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default function CrosswalkEditor({
const isEditModeActive = useSelector(selectIsEditContentActive());

const emptyTreeSelection: RenderTree = {
elementPath: '',
parentElementPath: undefined,
rootPathIds: [],
name: '',
id: '',
visualTreeId: '',
Expand Down

0 comments on commit df14a39

Please sign in to comment.