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

Improve CheckboxTree performance #1482

Merged
merged 6 commits into from
Dec 2, 2022
Merged
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@veupathdb/eda",
"version": "3.13.4",
"version": "3.13.5",
"dependencies": {
"debounce-promise": "^3.1.2",
"fp-ts": "^2.9.3",
Expand All @@ -19,7 +19,7 @@
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.58",
"@veupathdb/components": "^0.19.10",
"@veupathdb/coreui": "^0.18.14",
"@veupathdb/coreui": "^0.18.15",
"@veupathdb/http-utils": "^1.1.0",
"@veupathdb/study-data-access": "^0.3.5",
"@veupathdb/wdk-client": "^0.9.17",
Expand Down Expand Up @@ -79,7 +79,7 @@
"@types/uuid": "^8.3.4",
"@veupathdb/browserslist-config": "^1.1.0",
"@veupathdb/components": "^0.19.10",
"@veupathdb/coreui": "^0.18.14",
"@veupathdb/coreui": "^0.18.15",
"@veupathdb/eslint-config": "^2.0.0",
"@veupathdb/http-utils": "^1.1.0",
"@veupathdb/prettier-config": "^1.0.0",
Expand Down
163 changes: 95 additions & 68 deletions src/lib/core/components/variableTrees/VariableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,56 @@ import { useActiveDocument } from '../docs/DocumentationContainer';
import { CustomCheckboxes } from '@veupathdb/wdk-client/lib/Components/CheckboxTree/CheckboxTreeNode';
import { Toggle } from '@veupathdb/coreui';

const baseFieldNodeLinkStyle = {
padding: '0.25em 0.5em',
borderRadius: '0.5em',
display: 'inline-block',
cursor: 'pointer',
fontSize: '0.9em',
};

const activeFieldNodeLinkStyle = {
background: '#e6e6e6',
};

const disabledFieldNodeLinkStyle = {
cursor: 'not-allowed',
opacity: '0.5',
};

const fieldNodeCssSelectors = {
'.base-field-node': { ...baseFieldNodeLinkStyle },
'.active-field-node': {
...baseFieldNodeLinkStyle,
...activeFieldNodeLinkStyle,
},
'.disabled-field-node': {
...baseFieldNodeLinkStyle,
...disabledFieldNodeLinkStyle,
},
'.single-select-anchor-node': { marginLeft: '0.5em' },
'.dropdown-node-color': { color: '#2f2f2f' },
'.base-node-color': { color: '#069' },
'.entity-node': {
fontWeight: 'bold',
cursor: 'pointer',
padding: '0.25em 0.5em',
},
'.starred-var-container': {
display: 'flex',
justifyContent: 'space-between',
width: '100%',
},
'.star-selected': {
color: '#f8cb6a',
fontSize: '1.1em',
},
'.star-unselected': {
color: '#767676',
fontSize: '1.1em',
},
};

interface VariableField {
type?: string;
term: string;
Expand Down Expand Up @@ -84,6 +134,7 @@ interface FieldNodeProps {
onClickStar: () => void;
scrollIntoView: boolean;
asDropdown?: boolean;
isFeaturedField?: boolean;
}

interface getNodeSearchStringType {
Expand Down Expand Up @@ -672,6 +723,7 @@ export default function VariableList({
}
scrollIntoView={false}
asDropdown={asDropdown}
isFeaturedField={true}
/>
</div>
</li>
Expand Down Expand Up @@ -716,6 +768,7 @@ export default function VariableList({
},
},
},
customTreeNodeCssSelectors: fieldNodeCssSelectors,
};

return asDropdown ? (
Expand Down Expand Up @@ -793,33 +846,6 @@ const getNodeSearchString = (valuesMap: ValuesMap) => {
};
};

const baseFieldNodeLinkStyle = {
padding: '0.25em 0.5em',
borderRadius: '0.5em',
display: 'inline-block',
cursor: 'pointer',
fontSize: '0.9em',
};

const activeFieldNodeLinkStyle = {
background: '#e6e6e6',
};

const disabledFieldNodeLinkStyle = {
cursor: 'not-allowed',
opacity: '0.5',
};

const starStyleOff = {
color: '#767676',
fontSize: '1.1em',
};

const starStyleOn = {
color: '#f8cb6a',
fontSize: '1.1em',
};

const FieldNode = ({
field,
searchTerm,
Expand All @@ -836,11 +862,14 @@ const FieldNode = ({
isMultiFilterDescendant,
showMultiFilterDescendants,
asDropdown,
isFeaturedField,
}: FieldNodeProps) => {
const nodeRef = useRef<HTMLAnchorElement>(null);

const nodeColor = { color: asDropdown ? '#2f2f2f' : '#069' };
const anchorNodeLinkStyle = isMultiPick ? {} : { marginLeft: '0.5em' };
const nodeColorSelector = asDropdown
? 'dropdown-node-color'
: 'base-node-color';
const anchorNodeLinkSelector = isMultiPick ? '' : 'single-select-anchor-node';

useLayoutEffect(() => {
// hack: Use setTimeout since DOM may not reflect the current state of expanded nodes.
Expand Down Expand Up @@ -884,26 +913,12 @@ const FieldNode = ({
'This variable cannot be used with this plot and other variable selections.'
: 'Select this variable.'
}
style={
className={
isActive
? {
...baseFieldNodeLinkStyle,
...activeFieldNodeLinkStyle,
...anchorNodeLinkStyle,
...nodeColor,
}
? `active-field-node ${nodeColorSelector} ${anchorNodeLinkSelector}`
: isDisabled
? {
...baseFieldNodeLinkStyle,
...anchorNodeLinkStyle,
...disabledFieldNodeLinkStyle,
...nodeColor,
}
: {
...baseFieldNodeLinkStyle,
...anchorNodeLinkStyle,
...nodeColor,
}
? `disabled-field-node ${nodeColorSelector} ${anchorNodeLinkSelector}`
: `base-field-node ${nodeColorSelector} ${anchorNodeLinkSelector}`
}
href={'#' + field.term}
onClick={(e) => {
Expand All @@ -918,15 +933,10 @@ const FieldNode = ({
// </Tooltip>
//add condition for identifying entity parent and entity parent of activeField
<div
style={
className={
field.term.includes('entity')
? {
fontWeight: 'bold',
cursor: 'pointer',
padding: '0.25em 0.5em',
...nodeColor,
}
: { ...baseFieldNodeLinkStyle, ...nodeColor }
? `entity-node ${nodeColorSelector}`
: `base-field-node ${nodeColorSelector}`
}
>
{safeHtml(field.display)}
Expand All @@ -935,18 +945,36 @@ const FieldNode = ({

const canBeStarred = isFilterField(field) && !isMultiFilterDescendant;

return (
<div
style={
canBeStarred
? {
display: 'flex',
justifyContent: 'space-between',
width: '100%',
return isFeaturedField ? (
<div css={{ ...fieldNodeCssSelectors, width: '100%' }}>
<div className={canBeStarred ? 'starred-var-container' : ''}>
{fieldContents}
{isFilterField(field) && !isMultiFilterDescendant && (
/**
* Temporarily replace Tooltip components with title attribute to alleviate performance issues in new CheckboxTree.
* We are currently rendering 2 Tooltips per variable, which in Microbiome equates to several thousand Tooltips
*/
// <Tooltip title={makeStarButtonTooltipContent(field, isStarred)}>
<button
className={
isStarred ? 'link star-selected' : 'link star-unselected'
}
: {}
}
>
title={`Click to ${isStarred ? 'unstar' : 'star'}`}
onClick={(e) => {
// prevent click from toggling expansion state
e.stopPropagation();
onClickStar();
}}
disabled={starredVariablesLoading}
>
<Icon fa={isStarred ? 'star' : 'star-o'} />
</button>
// </Tooltip>
)}
</div>
</div>
) : (
<div className={canBeStarred ? 'starred-var-container' : ''}>
{fieldContents}
{isFilterField(field) && !isMultiFilterDescendant && (
/**
Expand All @@ -955,9 +983,8 @@ const FieldNode = ({
*/
// <Tooltip title={makeStarButtonTooltipContent(field, isStarred)}>
<button
className={`link`}
className={isStarred ? 'link star-selected' : 'link star-unselected'}
title={`Click to ${isStarred ? 'unstar' : 'star'}`}
style={isStarred ? { ...starStyleOn } : { ...starStyleOff }}
onClick={(e) => {
// prevent click from toggling expansion state
e.stopPropagation();
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3498,10 +3498,10 @@
react-transition-group "^4.4.1"
shape2geohash "^1.2.5"

"@veupathdb/coreui@^0.18.14":
version "0.18.14"
resolved "https://registry.yarnpkg.com/@veupathdb/coreui/-/coreui-0.18.14.tgz#ea524dc02401d87c7a4ffe76d6b60ed3301f51c2"
integrity sha512-aa13Xugh1/ngybkIUvanOqHwpsqd850iTTFH2MHAxX5pMgZKLe4iNmlsw0o0YJ4PK/yT14Apq58zdip+RSpIXQ==
"@veupathdb/coreui@^0.18.15":
version "0.18.15"
resolved "https://registry.yarnpkg.com/@veupathdb/coreui/-/coreui-0.18.15.tgz#34ead4ab1caae4e9178363627dd0c4787d7a89e1"
integrity sha512-umZuYB8qVsyCqn+pmpf77xYhDZge2edaBMgwnLC9zFKSJTDgMrn0fluQeF5TnLwslzSJTHxYjY8qw1eBjRyoKA==
dependencies:
"@react-hook/size" "^2.1.2"
core-js "^3.25.3"
Expand Down