-
{name}
- {isLeftDirection ? (
-
- ) : (
-
- )}
+
+
);
};
diff --git a/libs/data-mapper-v2/src/components/common/reactflow/styles.ts b/libs/data-mapper-v2/src/components/common/reactflow/styles.ts
index a950489f8d9..8ea4655155b 100644
--- a/libs/data-mapper-v2/src/components/common/reactflow/styles.ts
+++ b/libs/data-mapper-v2/src/components/common/reactflow/styles.ts
@@ -31,4 +31,9 @@ export const useStyles = makeStyles({
backgroundColor: '#C6DEEE',
...shorthands.border('1px', 'solid', '#C6DEEE'),
},
+ nodeWrapper: {
+ width: '10px',
+ height: '10px',
+ backgroundColor: 'transparent',
+ },
});
diff --git a/libs/data-mapper-v2/src/components/functionList/FunctionList.tsx b/libs/data-mapper-v2/src/components/functionList/FunctionList.tsx
index aac2197b501..91488445a9d 100644
--- a/libs/data-mapper-v2/src/components/functionList/FunctionList.tsx
+++ b/libs/data-mapper-v2/src/components/functionList/FunctionList.tsx
@@ -127,13 +127,17 @@ export const FunctionList = () => {
}
return newFunctionListTree;
- }, [functionData, searchTerm, inlineFunctionInputOutputKeys]);
+ }, [functionData, searchTerm, inlineFunctionInputOutputKeys, openItems]);
- const treeItems = functionListTree.children.map((node) => {
+ const treeItems = functionListTree.children.map((node, index) => {
return node.key.startsWith(functionCategoryItemKeyPrefix) ? (
-
+
) : (
-
+
);
});
@@ -149,7 +153,13 @@ export const FunctionList = () => {
/>
-
+
{treeItems}
>
diff --git a/libs/data-mapper-v2/src/core/DataMapperDesignerContext.tsx b/libs/data-mapper-v2/src/core/DataMapperDesignerContext.tsx
index 5593605d875..6c085362006 100644
--- a/libs/data-mapper-v2/src/core/DataMapperDesignerContext.tsx
+++ b/libs/data-mapper-v2/src/core/DataMapperDesignerContext.tsx
@@ -1,8 +1,8 @@
-import { createContext, type MutableRefObject } from 'react';
+import { createContext } from 'react';
export interface DataMapperDesignerContext {
readOnly?: boolean;
- canvasRef?: MutableRefObject;
+ canvasBounds?: DOMRect;
}
-export const DataMapperWrappedContext = createContext(null);
+export const DataMapperWrappedContext = createContext({});
diff --git a/libs/data-mapper-v2/src/core/state/DataMapSlice.ts b/libs/data-mapper-v2/src/core/state/DataMapSlice.ts
index c1592e65cd6..f980b446589 100644
--- a/libs/data-mapper-v2/src/core/state/DataMapSlice.ts
+++ b/libs/data-mapper-v2/src/core/state/DataMapSlice.ts
@@ -13,7 +13,12 @@ import type { UnknownNode } from '../../utils/DataMap.Utils';
import { getParentId } from '../../utils/DataMap.Utils';
import { getConnectedSourceSchema, getFunctionLocationsForAllFunctions, isFunctionData } from '../../utils/Function.Utils';
import { LogService } from '../../utils/Logging.Utils';
-import { flattenSchemaIntoDictionary, flattenSchemaIntoSortArray, isSchemaNodeExtended } from '../../utils/Schema.Utils';
+import {
+ flattenSchemaIntoDictionary,
+ flattenSchemaIntoSortArray,
+ flattenSchemaNodeMap,
+ isSchemaNodeExtended,
+} from '../../utils/Schema.Utils';
import type { FunctionMetadata, MapMetadata, SchemaExtended, SchemaNodeDictionary, SchemaNodeExtended } from '@microsoft/logic-apps-shared';
import { SchemaNodeProperty, SchemaType } from '@microsoft/logic-apps-shared';
import type { PayloadAction } from '@reduxjs/toolkit';
@@ -127,31 +132,49 @@ export const dataMapSlice = createSlice({
setInitialSchema: (state, action: PayloadAction) => {
const flattenedSchema = flattenSchemaIntoDictionary(action.payload.schema, action.payload.schemaType);
+ const currentState = state.curDataMapOperation;
if (action.payload.schemaType === SchemaType.Source) {
const sourceSchemaSortArray = flattenSchemaIntoSortArray(action.payload.schema.schemaTreeRoot);
+ const sourceCurrentFlattenedSchemaMap = currentState.sourceSchema
+ ? flattenSchemaNodeMap(currentState.sourceSchema.schemaTreeRoot)
+ : {};
- state.curDataMapOperation.sourceSchema = action.payload.schema;
- state.curDataMapOperation.flattenedSourceSchema = flattenedSchema;
- state.curDataMapOperation.sourceSchemaOrdering = sourceSchemaSortArray;
+ currentState.sourceSchema = action.payload.schema;
+ currentState.flattenedSourceSchema = flattenedSchema;
+ currentState.sourceSchemaOrdering = sourceSchemaSortArray;
state.pristineDataMap.sourceSchema = action.payload.schema;
state.pristineDataMap.flattenedSourceSchema = flattenedSchema;
state.pristineDataMap.sourceSchemaOrdering = sourceSchemaSortArray;
+
+ // NOTE: Reset ReactFlow nodes to filter out source nodes
+ currentState.nodes = currentState.nodes.filter((node) => !sourceCurrentFlattenedSchemaMap[node.data.id]);
} else {
const targetSchemaSortArray = flattenSchemaIntoSortArray(action.payload.schema.schemaTreeRoot);
-
- state.curDataMapOperation.targetSchema = action.payload.schema;
- state.curDataMapOperation.flattenedTargetSchema = flattenedSchema;
- state.curDataMapOperation.targetSchemaOrdering = targetSchemaSortArray;
- state.curDataMapOperation.currentTargetSchemaNode = undefined;
+ const targetCurrentFlattenedSchemaMap = currentState.targetSchema
+ ? flattenSchemaNodeMap(currentState.targetSchema.schemaTreeRoot)
+ : {};
+
+ currentState.targetSchema = action.payload.schema;
+ currentState.flattenedTargetSchema = flattenedSchema;
+ currentState.targetSchemaOrdering = targetSchemaSortArray;
+ currentState.currentTargetSchemaNode = undefined;
state.pristineDataMap.targetSchema = action.payload.schema;
state.pristineDataMap.flattenedTargetSchema = flattenedSchema;
state.pristineDataMap.targetSchemaOrdering = targetSchemaSortArray;
+
+ // NOTE: Reset ReactFlow nodes to filter out source nodes
+ currentState.nodes = currentState.nodes.filter((node) => !targetCurrentFlattenedSchemaMap[node.data.id]);
}
+ // NOTE: Reset ReactFlow edges
+ currentState.edges = [];
+
if (state.curDataMapOperation.sourceSchema && state.curDataMapOperation.targetSchema) {
- state.curDataMapOperation.currentTargetSchemaNode = state.curDataMapOperation.targetSchema.schemaTreeRoot;
+ currentState.currentTargetSchemaNode = state.curDataMapOperation.targetSchema.schemaTreeRoot;
}
+
+ state.curDataMapOperation = { ...currentState };
},
setInitialDataMap: (state, action: PayloadAction) => {
@@ -197,14 +220,14 @@ export const dataMapSlice = createSlice({
if (action.payload.reactFlowSource.startsWith(SchemaType.Source)) {
sourceNode = state.curDataMapOperation.flattenedSourceSchema[action.payload.reactFlowSource];
} else {
- sourceNode = newState.functionNodes[action.payload.reactFlowSource].functionData;
+ sourceNode = newState.functionNodes[action.payload.reactFlowSource]?.functionData;
}
let destinationNode: UnknownNode;
if (action.payload.reactFlowDestination.startsWith(SchemaType.Target)) {
destinationNode = state.curDataMapOperation.flattenedTargetSchema[action.payload.reactFlowDestination];
} else {
- destinationNode = newState.functionNodes[action.payload.reactFlowSource].functionData;
+ destinationNode = newState.functionNodes[action.payload.reactFlowSource]?.functionData;
}
addConnection(newState.dataMapConnections, action.payload, destinationNode, sourceNode);
@@ -225,7 +248,10 @@ export const dataMapSlice = createSlice({
saveDataMap: (
state,
- action: PayloadAction<{ sourceSchemaExtended: SchemaExtended | undefined; targetSchemaExtended: SchemaExtended | undefined }>
+ action: PayloadAction<{
+ sourceSchemaExtended: SchemaExtended | undefined;
+ targetSchemaExtended: SchemaExtended | undefined;
+ }>
) => {
const sourceSchemaExtended = action.payload.sourceSchemaExtended;
const targetSchemaExtended = action.payload.targetSchemaExtended;
diff --git a/libs/data-mapper-v2/src/models/ReactFlow.ts b/libs/data-mapper-v2/src/models/ReactFlow.ts
index d60b31e719d..5ecac3275d8 100644
--- a/libs/data-mapper-v2/src/models/ReactFlow.ts
+++ b/libs/data-mapper-v2/src/models/ReactFlow.ts
@@ -1,6 +1,14 @@
+import type { SchemaNodeExtended } from '@microsoft/logic-apps-shared';
+
export interface ViewportCoords {
startX: number;
endX: number;
startY: number;
endY: number;
}
+
+export type SchemaNodeReactFlowDataProps = SchemaNodeExtended & {
+ isLeftDirection: boolean;
+ id: string;
+ isConnected?: boolean;
+};
diff --git a/libs/data-mapper-v2/src/ui/DataMapperDesigner.tsx b/libs/data-mapper-v2/src/ui/DataMapperDesigner.tsx
index 89b6aff4a65..de2d353a31c 100644
--- a/libs/data-mapper-v2/src/ui/DataMapperDesigner.tsx
+++ b/libs/data-mapper-v2/src/ui/DataMapperDesigner.tsx
@@ -1,9 +1,9 @@
import type { AppDispatch, RootState } from '../core/state/Store';
-import { useEffect, useMemo, useRef, useCallback } from 'react';
+import { useEffect, useMemo, useRef, useCallback, useState } from 'react';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { useSelector, useDispatch } from 'react-redux';
-import type { Connection, CoordinateExtent, Node, Edge } from 'reactflow';
+import type { Connection, Node, Edge, ConnectionLineComponent } from 'reactflow';
import ReactFlow, { ReactFlowProvider, addEdge } from 'reactflow';
import { AddSchemaDrawer } from '../components/addSchema/AddSchemaPanel';
import { SchemaType } from '@microsoft/logic-apps-shared';
@@ -31,8 +31,17 @@ export const DataMapperDesigner = ({ fileService, readCurrentCustomXsltPathOptio
useStaticStyles();
const styles = useStyles();
const ref = useRef(null);
+ const [canvasBounds, setCanvasBounds] = useState();
const dispatch = useDispatch();
+ const updateCanvasBounds = useCallback(() => {
+ if (ref?.current) {
+ setCanvasBounds(ref.current.getBoundingClientRect());
+ }
+ }, [ref]);
+
+ const resizeObserver = useMemo(() => new ResizeObserver((_) => updateCanvasBounds()), [updateCanvasBounds]);
+
if (fileService) {
InitDataMapperFileService(fileService);
}
@@ -54,20 +63,6 @@ export const DataMapperDesigner = ({ fileService, readCurrentCustomXsltPathOptio
[]
);
- const reactFlowExtent = useMemo(() => {
- if (ref?.current) {
- const rect = ref.current.getBoundingClientRect();
- if (rect) {
- return [
- [0, 0],
- [rect.width, rect.height],
- ] as CoordinateExtent;
- }
- }
-
- return undefined;
- }, [ref]);
-
const dispatchEdgesAndNodes = useCallback(
(updatedEdges: Edge[], updatedNodes: Node[]) => {
const allNodeIds = [...updatedEdges.map((edge) => edge.source), ...updatedEdges.map((edge) => edge.target)];
@@ -141,6 +136,17 @@ export const DataMapperDesigner = ({ fileService, readCurrentCustomXsltPathOptio
[edges]
);
+ useEffect(() => {
+ if (ref?.current) {
+ resizeObserver.observe(ref.current);
+ updateCanvasBounds();
+ }
+
+ return () => {
+ resizeObserver.disconnect();
+ };
+ }, [ref, resizeObserver, updateCanvasBounds]);
+
useEffect(() => readCurrentCustomXsltPathOptions && readCurrentCustomXsltPathOptions(), [readCurrentCustomXsltPathOptions]);
// NOTE: Putting this useEffect here for vis next to onSave
@@ -153,7 +159,7 @@ export const DataMapperDesigner = ({ fileService, readCurrentCustomXsltPathOptio
return (
-
+
{}} onTestClick={() => {}} />
@@ -187,8 +193,15 @@ export const DataMapperDesigner = ({ fileService, readCurrentCustomXsltPathOptio
isValidConnection={isValidConnection}
onConnect={onEdgeConnect}
onEdgeUpdate={onEdgeUpdate}
- connectionLineComponent={ConnectionLine}
- translateExtent={reactFlowExtent}
+ connectionLineComponent={ConnectionLine as ConnectionLineComponent | undefined}
+ translateExtent={
+ canvasBounds
+ ? [
+ [0, 0],
+ [canvasBounds.right, canvasBounds.bottom],
+ ]
+ : undefined
+ }
/>
console.log(schema)} schemaType={SchemaType.Target} />
diff --git a/libs/data-mapper-v2/src/ui/styles.ts b/libs/data-mapper-v2/src/ui/styles.ts
index 3d37eec3015..76a33a2c17e 100644
--- a/libs/data-mapper-v2/src/ui/styles.ts
+++ b/libs/data-mapper-v2/src/ui/styles.ts
@@ -4,7 +4,8 @@ import type { CSSProperties } from 'react';
export const useStyles = makeStyles({
dataMapperShell: {
backgroundColor: tokens.colorNeutralBackground1,
- height: '100%',
+ minHeight: 'calc(100vh - 50px)',
+ maxHeight: 'calc(100vh - 40px)',
display: 'flex',
...shorthands.flex(1, 1, '1px'),
},
diff --git a/libs/data-mapper-v2/src/utils/Function.Utils.ts b/libs/data-mapper-v2/src/utils/Function.Utils.ts
index ffa6df53591..fa7ac5b4d2c 100644
--- a/libs/data-mapper-v2/src/utils/Function.Utils.ts
+++ b/libs/data-mapper-v2/src/utils/Function.Utils.ts
@@ -61,7 +61,8 @@ export const findFunctionForFunctionName = (nodeKey: string, functions: Function
export const findFunctionForKey = (nodeKey: string, functions: FunctionData[]): FunctionData | undefined =>
functions.find((functionData) => functionData.key === nodeKey);
-export const isFunctionData = (node: SchemaNodeExtended | FunctionData): node is FunctionData => 'functionName' in node;
+export const isFunctionData = (node: SchemaNodeExtended | FunctionData): node is FunctionData =>
+ Object.keys(node ?? {}).includes('functionName');
export const getFunctionOutputValue = (inputValues: string[], functionName: string) => {
if (!functionName) {
@@ -157,7 +158,10 @@ export const getFunctionLocationsForAllFunctions = (
});
const combinedTargetNodes = targetNodesConnectedToFunction.concat(parentNodes);
- functionNodes[connectionKey] = { functionData: func, functionLocations: combinedTargetNodes };
+ functionNodes[connectionKey] = {
+ functionData: func,
+ functionLocations: combinedTargetNodes,
+ };
}
}
return functionNodes;
diff --git a/libs/data-mapper-v2/src/utils/Schema.Utils.ts b/libs/data-mapper-v2/src/utils/Schema.Utils.ts
index 095208c6c78..6b112bfc1ff 100644
--- a/libs/data-mapper-v2/src/utils/Schema.Utils.ts
+++ b/libs/data-mapper-v2/src/utils/Schema.Utils.ts
@@ -1,11 +1,11 @@
// import type { FilteredDataTypesDict } from '../components/tree/SchemaTreeSearchbar';
// import { arrayType } from '../components/tree/SchemaTreeSearchbar';
// import type { ITreeNode } from '../components/tree/Tree';
-import { mapNodeParams } from '../constants/MapDefinitionConstants';
-import { sourcePrefix, targetPrefix } from '../constants/ReactFlowConstants';
+import { mapNodeParams } from "../constants/MapDefinitionConstants";
+import { sourcePrefix, targetPrefix } from "../constants/ReactFlowConstants";
//import { getLoopTargetNodeWithJson } from '../mapDefinitions';
-import type { FunctionData } from '../models/Function';
-import { LogCategory, LogService } from './Logging.Utils';
+import type { FunctionData } from "../models/Function";
+import { LogCategory, LogService } from "./Logging.Utils";
import type {
PathItem,
DataMapSchema,
@@ -13,17 +13,27 @@ import type {
SchemaNode,
SchemaNodeDictionary,
SchemaNodeExtended,
-} from '@microsoft/logic-apps-shared';
-import { NormalizedDataType, SchemaNodeProperty, SchemaType } from '@microsoft/logic-apps-shared';
-
-export const convertSchemaToSchemaExtended = (schema: DataMapSchema): SchemaExtended => {
+} from "@microsoft/logic-apps-shared";
+import {
+ NormalizedDataType,
+ SchemaNodeProperty,
+ SchemaType,
+} from "@microsoft/logic-apps-shared";
+
+export const convertSchemaToSchemaExtended = (
+ schema: DataMapSchema
+): SchemaExtended => {
const extendedSchema: SchemaExtended = {
...schema,
- schemaTreeRoot: convertSchemaNodeToSchemaNodeExtended(schema.schemaTreeRoot, undefined, []),
+ schemaTreeRoot: convertSchemaNodeToSchemaNodeExtended(
+ schema.schemaTreeRoot,
+ undefined,
+ []
+ ),
};
- LogService.log(LogCategory.SchemaUtils, 'convertSchemaToSchemaExtended', {
- message: 'Schema converted',
+ LogService.log(LogCategory.SchemaUtils, "convertSchemaToSchemaExtended", {
+ message: "Schema converted",
data: {
schemaFileFormat: schema.type,
largestNode: telemetryLargestNode(extendedSchema),
@@ -38,9 +48,12 @@ export const convertSchemaToSchemaExtended = (schema: DataMapSchema): SchemaExte
};
export const getFileNameAndPath = (fullPath: string): [string, string] => {
- const normalizedPath = fullPath.replaceAll('\\', '/');
- const lastIndexOfSlash = normalizedPath.lastIndexOf('/');
- const fileName = lastIndexOfSlash !== -1 ? normalizedPath.slice(lastIndexOfSlash + 1, normalizedPath.length + 1) : normalizedPath;
+ const normalizedPath = fullPath.replaceAll("\\", "/");
+ const lastIndexOfSlash = normalizedPath.lastIndexOf("/");
+ const fileName =
+ lastIndexOfSlash !== -1
+ ? normalizedPath.slice(lastIndexOfSlash + 1, normalizedPath.length + 1)
+ : normalizedPath;
const filePath = normalizedPath.slice(0, lastIndexOfSlash + 1);
return [fileName, filePath];
};
@@ -50,7 +63,9 @@ const convertSchemaNodeToSchemaNodeExtended = (
parentKey: string | undefined,
parentPath: PathItem[]
): SchemaNodeExtended => {
- const nodeProperties = parsePropertiesIntoNodeProperties(schemaNode.properties);
+ const nodeProperties = parsePropertiesIntoNodeProperties(
+ schemaNode.properties
+ );
const pathToRoot: PathItem[] = [
...parentPath,
{
@@ -65,30 +80,48 @@ const convertSchemaNodeToSchemaNodeExtended = (
...schemaNode,
nodeProperties,
children: schemaNode.children
- ? schemaNode.children.map((child) => convertSchemaNodeToSchemaNodeExtended(child, schemaNode.key, pathToRoot))
+ ? schemaNode.children.map((child) =>
+ convertSchemaNodeToSchemaNodeExtended(
+ child,
+ schemaNode.key,
+ pathToRoot
+ )
+ )
: [],
pathToRoot: pathToRoot,
parentKey,
- arrayItemIndex: nodeProperties.find((prop) => prop === SchemaNodeProperty.ArrayItem) ? 0 : undefined,
+ arrayItemIndex: nodeProperties.find(
+ (prop) => prop === SchemaNodeProperty.ArrayItem
+ )
+ ? 0
+ : undefined,
};
return extendedSchemaNode;
};
// Exported for testing purposes
-export const parsePropertiesIntoNodeProperties = (propertiesString: string): SchemaNodeProperty[] => {
+export const parsePropertiesIntoNodeProperties = (
+ propertiesString: string
+): SchemaNodeProperty[] => {
if (propertiesString) {
- return propertiesString.split(',').map((propertyString) => {
- return SchemaNodeProperty[propertyString.trim() as keyof typeof SchemaNodeProperty];
+ return propertiesString.split(",").map((propertyString) => {
+ return SchemaNodeProperty[
+ propertyString.trim() as keyof typeof SchemaNodeProperty
+ ];
});
}
return [];
};
-export const flattenSchemaIntoDictionary = (schema: SchemaExtended, schemaType: SchemaType): SchemaNodeDictionary => {
+export const flattenSchemaIntoDictionary = (
+ schema: SchemaExtended,
+ schemaType: SchemaType
+): SchemaNodeDictionary => {
const result: SchemaNodeDictionary = {};
- const idPrefix = schemaType === SchemaType.Source ? sourcePrefix : targetPrefix;
+ const idPrefix =
+ schemaType === SchemaType.Source ? sourcePrefix : targetPrefix;
const schemaNodeArray = flattenSchemaNode(schema.schemaTreeRoot);
schemaNodeArray.reduce((dict, node) => {
@@ -100,18 +133,36 @@ export const flattenSchemaIntoDictionary = (schema: SchemaExtended, schemaType:
return result;
};
-export const flattenSchemaIntoSortArray = (schemaNode: SchemaNodeExtended): string[] => {
+export const flattenSchemaIntoSortArray = (
+ schemaNode: SchemaNodeExtended
+): string[] => {
return flattenSchemaNode(schemaNode).map((node) => node.key);
};
-export const flattenSchemaNode = (schemaNode: SchemaNodeExtended): SchemaNodeExtended[] => {
+export const flattenSchemaNode = (
+ schemaNode: SchemaNodeExtended
+): SchemaNodeExtended[] => {
const result: SchemaNodeExtended[] = [schemaNode];
- const childArray = schemaNode.children.flatMap((childNode) => flattenSchemaNode(childNode));
+ const childArray = schemaNode.children.flatMap((childNode) =>
+ flattenSchemaNode(childNode)
+ );
return result.concat(childArray);
};
-export const isLeafNode = (schemaNode: SchemaNodeExtended): boolean => schemaNode.children.length < 1;
+export const flattenSchemaNodeMap = (
+ schemaNode: SchemaNodeExtended
+): Record => {
+ const flattenedSchema = flattenSchemaNode(schemaNode);
+ const result: Record = {};
+ for (const node of flattenedSchema) {
+ result[node.key] = node;
+ }
+ return result;
+};
+
+export const isLeafNode = (schemaNode: SchemaNodeExtended): boolean =>
+ schemaNode.children.length < 1;
/**
* Finds a node for a key, searching within a given schema structure
@@ -129,15 +180,18 @@ export const findNodeForKey = (
let tempKey = nodeKey;
if (tempKey.includes(mapNodeParams.for)) {
const layeredArrayItemForRegex = new RegExp(/\$for\([^)]*(?:\/\*){2,}\)/g);
- tempKey = nodeKey.replaceAll(layeredArrayItemForRegex, '');
+ tempKey = nodeKey.replaceAll(layeredArrayItemForRegex, "");
const forRegex = new RegExp(/\$for\([^)]+\)/g);
// ArrayItems will have an * instead of a key name
// And that * is stripped out during serialization
- tempKey = tempKey.replaceAll(forRegex, nodeKey.indexOf('*') !== -1 ? '*' : '');
+ tempKey = tempKey.replaceAll(
+ forRegex,
+ nodeKey.indexOf("*") !== -1 ? "*" : ""
+ );
- while (tempKey.indexOf('//') !== -1) {
- tempKey = tempKey.replaceAll('//', '/');
+ while (tempKey.indexOf("//") !== -1) {
+ tempKey = tempKey.replaceAll("//", "/");
}
}
@@ -151,20 +205,23 @@ export const findNodeForKey = (
return result;
}
- let lastInstanceOfMultiLoop = tempKey.lastIndexOf('*/*');
+ let lastInstanceOfMultiLoop = tempKey.lastIndexOf("*/*");
while (lastInstanceOfMultiLoop > -1 && !result) {
const start = tempKey.substring(0, lastInstanceOfMultiLoop);
const end = tempKey.substring(lastInstanceOfMultiLoop + 2);
tempKey = start + end;
result = searchChildrenNodeForKey(tempKey, schemaNode);
- lastInstanceOfMultiLoop = tempKey.lastIndexOf('*/*');
+ lastInstanceOfMultiLoop = tempKey.lastIndexOf("*/*");
}
return result;
};
-const searchChildrenNodeForKey = (key: string, schemaNode: SchemaNodeExtended): SchemaNodeExtended | undefined => {
+const searchChildrenNodeForKey = (
+ key: string,
+ schemaNode: SchemaNodeExtended
+): SchemaNodeExtended | undefined => {
if (schemaNode.key === key) {
return schemaNode;
}
@@ -181,68 +238,23 @@ const searchChildrenNodeForKey = (key: string, schemaNode: SchemaNodeExtended):
return result;
};
-// Search key will be the node's key
-// Returns nodes that include the search key in their node.key (while maintaining the tree/schema's structure)
-// export const searchSchemaTreeFromRoot = (
-// schemaTreeRoot: ITreeNode,
-// flattenedSchema: SchemaNodeDictionary,
-// nodeKeySearchTerm: string,
-// filteredDataTypes: FilteredDataTypesDict
-// ): ITreeNode => {
-// const fuseSchemaTreeSearchOptions = {
-// includeScore: true,
-// minMatchCharLength: 2,
-// includeMatches: true,
-// threshold: 0.4,
-// keys: ['qName'],
-// };
-
-// // Fuzzy search against flattened schema tree to build a dictionary of matches
-// const fuse = new Fuse(Object.values(flattenedSchema), fuseSchemaTreeSearchOptions);
-// const matchedSchemaNodesDict: { [key: string]: true } = {};
-
-// fuse.search(nodeKeySearchTerm).forEach((result) => {
-// matchedSchemaNodesDict[result.item.key] = true;
-// });
-
-// // Recurse through schema tree, adding children that match the criteria
-// const searchChildren = (result: ITreeNode[], node: ITreeNode) => {
-// // NOTE: Type-cast (safely) node for second condition so Typescript sees all properties
-// if (
-// (nodeKeySearchTerm.length >= fuseSchemaTreeSearchOptions.minMatchCharLength ? matchedSchemaNodesDict[node.key] : true) &&
-// (filteredDataTypes[(node as SchemaNodeExtended).type] ||
-// ((node as SchemaNodeExtended).nodeProperties.includes(SchemaNodeProperty.Repeating) && filteredDataTypes[arrayType]))
-// ) {
-// result.push({ ...node });
-// } else if (node.children && node.children.length > 0) {
-// const childNodes = node.children.reduce(searchChildren, []);
-
-// if (childNodes.length) {
-// result.push({ ...node, isExpanded: true, children: childNodes } as ITreeNode);
-// }
-// }
-
-// return result;
-// };
-
-// return {
-// ...schemaTreeRoot,
-// isExpanded: true,
-// children: schemaTreeRoot.children ? schemaTreeRoot.children.reduce[]>(searchChildren, []) : [],
-// };
-// };
-
-export const isSchemaNodeExtended = (node: SchemaNodeExtended | FunctionData): node is SchemaNodeExtended => 'pathToRoot' in node;
+export const isSchemaNodeExtended = (
+ node: SchemaNodeExtended | FunctionData
+): node is SchemaNodeExtended => Object.keys(node ?? {}).includes("pathToRoot");
export const isObjectType = (nodeType: NormalizedDataType): boolean =>
- nodeType === NormalizedDataType.Complex || nodeType === NormalizedDataType.Object;
+ nodeType === NormalizedDataType.Complex ||
+ nodeType === NormalizedDataType.Object;
export const telemetryLargestNode = (schema: SchemaExtended): number => {
return Math.max(...maxProperties(schema.schemaTreeRoot));
};
const maxProperties = (schemaNode: SchemaNodeExtended): number[] => {
- return [schemaNode.children.length, ...schemaNode.children.flatMap((childNode) => maxProperties(childNode))];
+ return [
+ schemaNode.children.length,
+ ...schemaNode.children.flatMap((childNode) => maxProperties(childNode)),
+ ];
};
export const telemetryDeepestNodeChild = (schema: SchemaExtended): number => {
@@ -250,7 +262,10 @@ export const telemetryDeepestNodeChild = (schema: SchemaExtended): number => {
};
const deepestNode = (schemaNode: SchemaNodeExtended): number[] => {
- return [schemaNode.pathToRoot.length, ...schemaNode.children.flatMap((childNode) => maxProperties(childNode))];
+ return [
+ schemaNode.pathToRoot.length,
+ ...schemaNode.children.flatMap((childNode) => maxProperties(childNode)),
+ ];
};
export const telemetrySchemaNodeCount = (schema: SchemaExtended): number => {
@@ -267,6 +282,6 @@ const nodeCount = (schemaNode: SchemaNodeExtended): number => {
};
export const removePrefixFromNodeID = (nodeID: string): string => {
- const splitID = nodeID.split('-');
+ const splitID = nodeID.split("-");
return splitID[1];
-}
+};