Skip to content

Commit

Permalink
fix(designer): Prevent filtering of Until Nodes when getting upstream…
Browse files Browse the repository at this point in the history
… nodes for output tokens (#4560)

* add option to not include until

* small chnage

* remove comment
  • Loading branch information
Eric-B-Wu committed Apr 5, 2024
1 parent 275fa95 commit 86fafd0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -108,6 +108,7 @@ CHANGELOG.MD
.env.development.local
.env.test.local
.env.production.local
.eslintcache

npm-debug.log*
yarn-debug.log*
Expand Down
2 changes: 0 additions & 2 deletions Localize/lang/strings.json
Expand Up @@ -1900,7 +1900,6 @@
"_dwrqEc.comment": "Warnings section title",
"_e+GuGo.comment": "Placeholder title for a newly inserted Text parameter",
"_e00zot.comment": "Recurrence parameter group title",
"_e1gQAz.comment": "Debug logic app project error text",
"_e4JZEY.comment": "Time zone value ",
"_e9OvzW.comment": "Clear",
"_e9bIKh.comment": "Message on failed generation",
Expand Down Expand Up @@ -2530,7 +2529,6 @@
"dwrqEc": "Warnings",
"e+GuGo": "Input",
"e00zot": "How often do you want to check for items?",
"e1gQAz": "Please start the project by pressing F5 or run it through the Run and Debug view",
"e4JZEY": "(UTC+07:00) Tomsk",
"e9OvzW": "Clear",
"e9bIKh": "Failed to generate XSLT.",
Expand Down
2 changes: 1 addition & 1 deletion apps/Standalone/index.html
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<body style="margin: 0px">
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
15 changes: 10 additions & 5 deletions libs/designer/src/lib/core/utils/loops.ts
Expand Up @@ -205,14 +205,19 @@ export const addForeachToNode = createAsyncThunk(
}
);

interface GetRepetitionNodeIdsOptions {
includeSelf?: boolean;
ignoreUntil?: boolean;
}

export const getRepetitionNodeIds = (
nodeId: string,
nodesMetadata: NodesMetadata,
operationInfos: Record<string, NodeOperation>,
includeSelf?: boolean
{ includeSelf = false, ignoreUntil = false }: GetRepetitionNodeIdsOptions = {}
): string[] => {
const allParentNodeIds = getAllParentsForNode(nodeId, nodesMetadata);
const repetitionNodeIds = allParentNodeIds.filter((parentId) => isLoopingNode(parentId, operationInfos));
const repetitionNodeIds = allParentNodeIds.filter((parentId) => isLoopingNode(parentId, operationInfos, ignoreUntil));

if (includeSelf) {
repetitionNodeIds.unshift(nodeId);
Expand All @@ -230,7 +235,7 @@ export const getRepetitionContext = async (
splitOn: string | undefined,
idReplacements?: Record<string, string>
): Promise<RepetitionContext> => {
const repetitionNodeIds = getRepetitionNodeIds(nodeId, nodesMetadata, operationInfos, includeSelf);
const repetitionNodeIds = getRepetitionNodeIds(nodeId, nodesMetadata, operationInfos, { includeSelf });
const repetitionReferences = (
await Promise.all(
repetitionNodeIds.map((repetitionNodeId) => getRepetitionReference(repetitionNodeId, operationInfos, allInputs, idReplacements))
Expand Down Expand Up @@ -421,9 +426,9 @@ const checkArrayInRepetition = (

// Directly checking the node type, because cannot make async calls while adding token from picker to editor.
// TODO - See if this can be made async and looked at manifest.
export const isLoopingNode = (nodeId: string, operationInfos: Record<string, NodeOperation>): boolean => {
export const isLoopingNode = (nodeId: string, operationInfos: Record<string, NodeOperation>, ignoreUntil: boolean): boolean => {
const nodeType = getRecordEntry(operationInfos, nodeId)?.type;
return equals(nodeType, Constants.NODE.TYPE.FOREACH) || equals(nodeType, Constants.NODE.TYPE.UNTIL);
return equals(nodeType, Constants.NODE.TYPE.FOREACH) || (!ignoreUntil && equals(nodeType, Constants.NODE.TYPE.UNTIL));
};

export const getForeachActionName = (
Expand Down
4 changes: 2 additions & 2 deletions libs/designer/src/lib/core/utils/tokens.ts
Expand Up @@ -71,7 +71,7 @@ export const getTokenNodeIds = (
const preliminaryRepetitionNodeIds = getRepetitionNodeIds(nodeId, nodesMetadata, operationInfos);
// Remove token nodes that have inaccessible outputs due to loop scope
tokenNodeIds = tokenNodeIds.filter((tokenNodeId) => {
const tokenRepititionNodes = getRepetitionNodeIds(tokenNodeId, nodesMetadata, operationInfos);
const tokenRepititionNodes = getRepetitionNodeIds(tokenNodeId, nodesMetadata, operationInfos, { ignoreUntil: true });
// filter out if repetitionNodeIds does not contain all of tokenRepititionNodes
return tokenRepititionNodes.every((tokenRepititionId) => preliminaryRepetitionNodeIds.includes(tokenRepititionId));
});
Expand All @@ -80,7 +80,7 @@ export const getTokenNodeIds = (
// Should include itself as repetition reference if nodes can reference its outputs
// generated by its inputs like Query, Select and Table operations.
const includeSelf = shouldIncludeSelfForRepetitionReference(manifest);
const repetitionNodeIds = getRepetitionNodeIds(nodeId, nodesMetadata, operationInfos, includeSelf);
const repetitionNodeIds = getRepetitionNodeIds(nodeId, nodesMetadata, operationInfos, { includeSelf });

for (const repetitionNodeId of repetitionNodeIds) {
const nodeManifest = getRecordEntry(nodesManifest, repetitionNodeId)?.manifest;
Expand Down

0 comments on commit 86fafd0

Please sign in to comment.