Skip to content

Commit

Permalink
fix: check for optional sibling only if ref is unsatisfied
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Oct 11, 2021
1 parent f28705a commit 451b19f
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/redux/services/resourceRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,6 @@ function handleRefMappingByKey(
}

sourceRefNodes.forEach(sourceRefNode => {
if (outgoingRefMapper.source.hasOptionalSibling) {
const optionalSiblingPath = joinPathParts([...outgoingRefMapper.source.pathParts.slice(0, -1), 'optional']);

const optionalSiblingRefNode = sourceResource.refNodesByPath
? sourceResource.refNodesByPath[optionalSiblingPath]?.find(refNode =>
refNode.parentKeyPath.startsWith(sourceRefNode.parentKeyPath)
)
: undefined;
if (optionalSiblingRefNode && optionalSiblingRefNode.scalar.value === true) {
return;
}
}

// if no target resources are found, then mark the source ref as unsatisfied
if (targetResources.length === 0) {
createResourceRef(
Expand Down Expand Up @@ -280,13 +267,27 @@ function handleRefMappingByKey(
});

if (!hasSatisfiedRefs) {
createResourceRef(
sourceResource,
ResourceRefType.Unsatisfied,
new NodeWrapper(sourceRefNode.scalar, sourceResource.lineCounter),
undefined,
outgoingRefMapper.target.kind
);
let shouldCreateUnsatisfiedRef = true;
if (outgoingRefMapper.source.hasOptionalSibling) {
const optionalSiblingPath = joinPathParts([...outgoingRefMapper.source.pathParts.slice(0, -1), 'optional']);
const optionalSiblingRefNode = sourceResource.refNodesByPath
? sourceResource.refNodesByPath[optionalSiblingPath]?.find(refNode =>
refNode.parentKeyPath.startsWith(sourceRefNode.parentKeyPath)
)
: undefined;
if (optionalSiblingRefNode && optionalSiblingRefNode.scalar.value === true) {
shouldCreateUnsatisfiedRef = false;
}
}
if (shouldCreateUnsatisfiedRef) {
createResourceRef(
sourceResource,
ResourceRefType.Unsatisfied,
new NodeWrapper(sourceRefNode.scalar, sourceResource.lineCounter),
undefined,
outgoingRefMapper.target.kind
);
}
}
}
});
Expand Down

0 comments on commit 451b19f

Please sign in to comment.