Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-4045: Display only tests with results in result viewer #2049

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const computeParents = (
tests.push(...newTests);
lowestParents.push(...newLowestParents);
});
} else if (node.obs?.length > 0) {
// Treat the current node as a leaf and a test
leaves.push(node.flatName);
tests.push([node.flatName, node]);
// Add the current node to the lowest parents list
lowestParents.push({ flatName: node.flatName, display: node.display });
}
parents[node.flatName] = leaves;
return { parents, leaves, tests, lowestParents };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ interface filterNodeParentProps extends Pick<FilterNodeProps, 'root'> {
}

function filterTreeNode(inputValue, treeNode) {
// If the tree node's display value contains the user input, or any of its children's display contains the user input, return true
if (
treeNode &&
(treeNode.display.toLowerCase().includes(inputValue.toLowerCase()) ||
(treeNode.subSets && treeNode.subSets.some((child) => filterTreeNode(inputValue, child))))
) {
return true;
}

// Otherwise, return false
return false;
}

Expand Down Expand Up @@ -62,23 +59,39 @@ const FilterSet: React.FC<FilterSetProps> = () => {
);
};

// Recursive function to check if a node or any of its descendants have data
const hasNodeOrChildrenWithData = (node) => {
if (node.hasData) {
return true;
}
if (node.subSets) {
return node.subSets.some((subNode) => hasNodeOrChildrenWithData(subNode));
}
return false;
};

const FilterNodeParent = ({ root, itemNumber }: filterNodeParentProps) => {
const config = useConfig<ConfigObject>();
const { t } = useTranslation();
const tablet = useLayoutType() === 'tablet';
const [expandAll, setExpandAll] = useState<boolean | undefined>(undefined);

if (!root.subSets) return;
if (!hasNodeOrChildrenWithData(root)) {
return null;
}

const filterParent = root.subSets.map((node) => {
return (
<FilterNode
root={node}
level={0}
open={expandAll === undefined ? config.resultsViewerConcepts[itemNumber].defaultOpen : expandAll}
/>
);
});
const filterParent = root.subSets
.filter((node) => hasNodeOrChildrenWithData(node))
.map((node) => {
return (
<FilterNode
root={node}
level={0}
open={expandAll === undefined ? config.resultsViewerConcepts[itemNumber].defaultOpen : expandAll}
key={node.flatName}
/>
);
});

return (
<div>
Expand All @@ -104,6 +117,11 @@ const FilterNode = ({ root, level, open }: FilterNodeProps) => {
const indeterminate = isIndeterminate(parents[root.flatName], checkboxes);
const allChildrenChecked = parents[root.flatName]?.every((kid) => checkboxes[kid]);

// Filter out nodes that don't have data or descendants with data
if (!hasNodeOrChildrenWithData(root)) {
return null;
}

return (
<Accordion align="start" size={tablet ? 'md' : 'sm'}>
<AccordionItem
Expand All @@ -121,23 +139,31 @@ const FilterNode = ({ root, level, open }: FilterNodeProps) => {
open={open ?? false}
>
{!root?.subSets?.[0]?.obs &&
root?.subSets?.map((node, index) => <FilterNode root={node} level={level + 1} key={index} />)}
{root?.subSets?.[0]?.obs && root.subSets?.map((obs, index) => <FilterLeaf leaf={obs} key={index} />)}
root?.subSets
?.filter((node) => hasNodeOrChildrenWithData(node))
.map((node, index) => <FilterNode root={node} level={level + 1} key={index} />)}
{root?.subSets?.[0]?.obs &&
root.subSets?.filter((obs) => obs.hasData).map((obs, index) => <FilterLeaf leaf={obs} key={index} />)}
</AccordionItem>
</Accordion>
);
};

const FilterLeaf = ({ leaf }: FilterLeafProps) => {
const { checkboxes, toggleVal } = useContext(FilterContext);

// Filter out leaves without data
if (!leaf.hasData) {
return null;
}

return (
<div className={styles.filterItem}>
<Checkbox
id={leaf?.flatName}
labelText={leaf?.display}
checked={checkboxes?.[leaf.flatName]}
onChange={() => toggleVal(leaf.flatName)}
disabled={!leaf.hasData}
/>
</div>
);
Expand Down
Loading