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

Pending badge for multiple choice parent #659

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion app/src/common/hooks/useIsNodePending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,34 @@ import {
useApiStaticInputsListQuery,
} from "services/api/endpoints";
import type {
Attribute,
SQLInput,
StaticInput,
} from "services/api/generated/api.generated";

/**
* Tests if node is a direct parent of attribute and if node kind is choice
*
* ie: returns true if
* Node path => `Observation.effective[x]` & attribute path => `Observation.effectiveBoolean`
* @param attribute The attribute that has an input
* @param node The current node to be tested as the attribute ancestor
* @returns True if node kind is "choice" and node is a parent of attribute
*/
const isAttributeChoiceOfNode = (
attribute: Attribute,
node: ElementNode
): boolean => {
// Node kind has to be "choice"
if (node.kind !== "choice") return false;

const isNodeParentOfAttribute = node.children.some(
({ path }) => path === attribute.path
);

return isNodeParentOfAttribute;
};

const useIsNodePending = (node: ElementNode): boolean => {
const { mappingId } = useParams<{ mappingId?: string }>();

Expand Down Expand Up @@ -66,7 +90,9 @@ const useIsNodePending = (node: ElementNode): boolean => {
attributesWithInputs !== undefined &&
attributesWithInputs.some(
(attribute) =>
attribute.path === node.path || attribute.path.startsWith(node.path)
attribute.path === node.path ||
attribute.path.startsWith(node.path) ||
isAttributeChoiceOfNode(attribute, node)
)
);
};
Expand Down