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

[Complex-Dom] Combine visibility: hidden and display: none for side TreeView hidden elements. #327

Merged
Show file tree
Hide file tree
Changes from 1 commit
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/todomvc/big-dom-generator/dist/index.html

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions resources/todomvc/big-dom-generator/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ Importing the CSS from the Spectrum CSS library.
min-width: 30px;
}

.display-none {
display: none;
}

.spectrum-TreeView-item.is-open > .spectrum-TreeView {
visibility: unset;
}
lpardosixtosMs marked this conversation as resolved.
Show resolved Hide resolved

/*
Layout CSS for the UI.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MAX_VISIBLE_TREE_VIEW_ITEM_DEPTH } from "../../params";
import { generateTreeHead } from "./../tree-generator";
import classNames from "classnames";

import ChevronRight from "./../assets/Smock_ChevronRight_18_N.svg";
import TaskListIcon from "./../assets/Smock_TaskList_18_N.svg";
Expand All @@ -8,10 +9,10 @@ const TreeItem = (props) => {
const { treeNode, currentDepth } = props;

const isExpandableItem = treeNode.type === "expandableItem";
const treeViewItemIsOpen = isExpandableItem && currentDepth < MAX_VISIBLE_TREE_VIEW_ITEM_DEPTH ? "is-open" : "";
const treeViewItemIsOpen = isExpandableItem && (currentDepth !== MAX_VISIBLE_TREE_VIEW_ITEM_DEPTH || treeNode.isDisplayNone);
lpardosixtosMs marked this conversation as resolved.
Show resolved Hide resolved

return (
<li className={`spectrum-TreeView-item ${treeViewItemIsOpen} nodetype-${treeNode.type}`}>
<li className={classNames("spectrum-TreeView-item", { "display-none": treeNode.isDisplayNone, "is-open": treeViewItemIsOpen }, `nodetype-${treeNode.type}`)}>
{isExpandableItem
? <>
<a className="spectrum-TreeView-itemLink">
Expand Down
49 changes: 45 additions & 4 deletions resources/todomvc/big-dom-generator/src/tree-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@ import { DEFAULT_SEED_FOR_RANDOM_NUMBER_GENERATOR, MAX_GENERATED_DOM_DEPTH, MAX_

const random = new LCG(DEFAULT_SEED_FOR_RANDOM_NUMBER_GENERATOR);

const fillSubtreeWeights = (node, expandableItemWeight, nonExpandableItemWeight) => {
lpardosixtosMs marked this conversation as resolved.
Show resolved Hide resolved
if (node.type === "expandableItem")
node.subTreeWeight = node.children.reduce((acc, child) => acc + fillSubtreeWeights(child, expandableItemWeight, nonExpandableItemWeight), expandableItemWeight);
else
node.subTreeWeight = nonExpandableItemWeight;

return node.subTreeWeight;
};

const markDisplayNoneNodes = (node, expandableItemWeight, nonExpandableItemWeight) => {
lpardosixtosMs marked this conversation as resolved.
Show resolved Hide resolved
let currentSubTreesWeights = node.subTreeWeight;
let currentIndex = 0;
let nodeQueue = [node];
while (currentSubTreesWeights >= TARGET_SIZE / 2) {
const currentNode = nodeQueue[currentIndex];
nodeQueue[currentIndex] = null;
const expandableChildren = currentNode.children.filter((child) => child.type === "expandableItem");
if (expandableChildren.length) {
nodeQueue.push(...expandableChildren);
currentSubTreesWeights -= expandableItemWeight;
let numberOfNonExpandableChildren = currentNode.children.length - expandableChildren.length;
currentSubTreesWeights -= numberOfNonExpandableChildren * nonExpandableItemWeight;
} else {
currentSubTreesWeights -= currentNode.subTreeWeight;
}
currentIndex++;
}
nodeQueue.forEach((node) => {
if (node)
node.isDisplayNone = true;
});
};

/**
* Generates the blueprint of the tree-view side panel for the complex DOM shell with expandable and non-expandable items.
* It starts with the minimum number of maximum-depth branches and randomly adds
Expand All @@ -21,15 +54,21 @@ const random = new LCG(DEFAULT_SEED_FOR_RANDOM_NUMBER_GENERATOR);
* children: [
* {
* type: "nonExpandableItem",
* children: []
* children: [],
* isDisplayNone: false,
* subTreeWeight: 0,
* }
* ]
* ],
* isDisplayNone: false,
* subTreeWeight: 0,
* }
* ]
* ],
* isDisplayNone: false,
* subTreeWeight: 0,
* }
**/
export const generateTreeHead = ({ expandableItemWeight, nonExpandableItemWeight }) => {
const treeHead = { type: "expandableItem", children: [] };
const treeHead = { type: "expandableItem", children: [], isDisplayNone: false, subTreeWeight: 0 };
const nodeWeight = { expandableItem: expandableItemWeight, nonExpandableItem: nonExpandableItemWeight };

let totalNodes = expandableItemWeight;
Expand Down Expand Up @@ -85,5 +124,7 @@ export const generateTreeHead = ({ expandableItemWeight, nonExpandableItemWeight
}
}

fillSubtreeWeights(treeHead, expandableItemWeight, nonExpandableItemWeight);
markDisplayNoneNodes(treeHead, expandableItemWeight, nonExpandableItemWeight);
return treeHead;
};

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.