Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit 78ae3f3

Browse files
committed
fix: Pending badge for choice nodes parend of pending attributes
1 parent 4aac553 commit 78ae3f3

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

app/src/common/hooks/useIsNodePending.tsx

+27-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,34 @@ import {
1010
useApiStaticInputsListQuery,
1111
} from "services/api/endpoints";
1212
import type {
13+
Attribute,
1314
SQLInput,
1415
StaticInput,
1516
} from "services/api/generated/api.generated";
1617

18+
/**
19+
* Tests if node is a direct parent of attribute and if node kind is choice
20+
*
21+
* ie: returns true if
22+
* Node path => `Observation.effective[x]` & attribute path => `Observation.effectiveBoolean`
23+
* @param attribute The attribute that has an input
24+
* @param node The current node to be tested as the attribute ancestor
25+
* @returns True if node kind is "choice" and node is a parent of attribute
26+
*/
27+
const isAttributeChoiceOfNode = (
28+
attribute: Attribute,
29+
node: ElementNode
30+
): boolean => {
31+
// Node kind has to be "choice"
32+
if (node.kind !== "choice") return false;
33+
34+
const isNodeParentOfAttribute = node.children.some(
35+
({ path }) => path === attribute.path
36+
);
37+
38+
return isNodeParentOfAttribute;
39+
};
40+
1741
const useIsNodePending = (node: ElementNode): boolean => {
1842
const { mappingId } = useParams<{ mappingId?: string }>();
1943

@@ -66,7 +90,9 @@ const useIsNodePending = (node: ElementNode): boolean => {
6690
attributesWithInputs !== undefined &&
6791
attributesWithInputs.some(
6892
(attribute) =>
69-
attribute.path === node.path || attribute.path.startsWith(node.path)
93+
attribute.path === node.path ||
94+
attribute.path.startsWith(node.path) ||
95+
isAttributeChoiceOfNode(attribute, node)
7096
)
7197
);
7298
};

0 commit comments

Comments
 (0)