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

implement react virtuoso #140

Merged
merged 1 commit into from
Jan 25, 2025
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
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"react-slick": "0.30.3",
"react-stylable-diff": "2.0.0",
"react-virtualized-auto-sizer": "1.0.25",
"react-virtuoso": "^4.12.3",
"react-window": "1.8.11",
"recharts": "2.15.0",
"redaxios": "0.5.1",
Expand Down
17 changes: 17 additions & 0 deletions src/components/Tree/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getSnapshot } from 'mobx-state-tree'
import findIndex from 'lodash/findIndex'
import isEqual from 'lodash/isEqual'
import { FixedSizeList as List } from 'react-window'
import { Virtuoso } from 'react-virtuoso'

import { MobxStoreContext } from '../../mobxStoreContext.js'
import { TreeRow } from './Row.jsx'
Expand Down Expand Up @@ -44,6 +45,22 @@ export const TreeList = observer(
}
}, [listRef, activeNode?.label, aNA, nodes, nodeIndex])

return (
<Virtuoso
style={{ height: `${height - 5}px`, width: `${width}px` }}
totalCount={nodes.length}
itemContent={(index) => (
<TreeRow
key={index}
index={index}
node={nodes[index]}
nodes={nodes}
userRole={userRole}
/>
)}
/>
)

return (
<StyledList
height={height - 5}
Expand Down
91 changes: 5 additions & 86 deletions src/components/Tree/Row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MdMoreHoriz as MoreHorizIcon,
} from 'react-icons/md'
import { observer } from 'mobx-react-lite'
// import { ContextMenuTrigger, ContextMenu, MenuItem } from 'react-contextmenu'
import last from 'lodash/last'
import { of as $of } from 'rxjs'

Expand All @@ -31,89 +30,8 @@ import {
MenuItem,
} from '../../utils/react-contextmenu/index.js'

const Container = styled.div`
.react-contextmenu {
display: flex;
flex-direction: column;
min-width: 100px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
background-color: rgb(66, 66, 66);
background-clip: padding-box;
border: 1px solid grey;
border-radius: 0.25rem;
outline: none;
opacity: 0;
pointer-events: none;
font-family: 'Roboto', sans-serif;
transition: opacity 250ms ease !important;
/* no idea why this is needed */
margin-top: -70px;
}
.react-contextmenu.react-contextmenu--visible {
color: white;
opacity: 1;
pointer-events: auto;
z-index: 1000;
}
.react-contextmenu-title {
opacity: 0;
}
.react-contextmenu--visible .react-contextmenu-title {
color: #b3b3b3;
padding-left: 10px;
padding-right: 15px;
padding-bottom: 3px;
opacity: 1;
}
.react-contextmenu-title::after {
content: ':';
}
.react-contextmenu > .react-contextmenu-item {
display: inline-block;
padding: 3px 20px;
clear: both;
font-weight: 400;
line-height: 1.5;
color: white;
text-align: inherit;
white-space: nowrap;
background: 0 0;
border: 0;
text-decoration: none;
cursor: pointer;
}
.react-contextmenu-item.active,
.react-contextmenu-item:hover {
color: #f57c00;
border-color: #0275d8;
text-decoration: none;
}
.react-contextmenu-divider {
border-top: 1px solid grey;
margin-top: 4px;
margin-bottom: 7px;
}
.react-contextmenu-submenu {
padding-right: 27px !important;
}
.react-contextmenu-submenu:after {
content: '▶';
display: inline-block;
position: absolute;
right: 7px;
bottom: 3px;
}
`
const StyledNode = styled.div`
padding-left: ${(props) => `${Number(props['data-level']) * 17 - 10}px`};
height: ${(props) => props['data-row-height']}px;
max-height: ${(props) => props['data-row-height']}px;
box-sizing: border-box;
margin: 0;
display: flex;
Expand All @@ -125,6 +43,7 @@ const StyledNode = styled.div`
props['data-nodeisinactivenodepath'] ? '#D84315'
: props['data-inaktiv'] ? 'rgba(0, 0, 0, 0.35)'
: 'inherit'};
line-height: 1.3rem;
`
const StyledExpandMoreIcon = styled(ExpandMoreIcon)`
margin-top: -5px !important;
Expand Down Expand Up @@ -175,7 +94,7 @@ const SymbolDiv = styled.div`
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
align-self: flex-start;
`
const SymbolSpan = styled.span`
padding-right: ${(props) =>
Expand All @@ -196,7 +115,7 @@ const TextSpan = styled.span`
font-size: ${(props) => `${props['data-font-size']}px !important`};
font-weight: ${(props) =>
props['data-nodeisinactivenodepath'] ? '700 !important' : 'inherit'};
white-space: nowrap;
white-space: normal;
cursor: pointer;
&:hover {
color: #f57c00;
Expand Down Expand Up @@ -318,7 +237,7 @@ export const TreeRow = observer(({ style, node, nodes, userRole }) => {
const inaktiv = node?.aktiv === false

return (
<Container style={style}>
<>
<ContextMenuTrigger id={`cm${node?.id}`}>
<StyledNode
data-level={level}
Expand Down Expand Up @@ -430,6 +349,6 @@ export const TreeRow = observer(({ style, node, nodes, userRole }) => {
)}
</ContextMenu>
)}
</Container>
</>
)
})
78 changes: 78 additions & 0 deletions src/components/Tree/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,84 @@ import { buildNodes } from './nodes/index.js'
const Container = styled.div`
width: 100%;
height: 100%;
.react-contextmenu {
display: flex;
flex-direction: column;
min-width: 100px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
background-color: rgb(66, 66, 66);
background-clip: padding-box;
border: 1px solid grey;
border-radius: 0.25rem;
outline: none;
opacity: 0;
pointer-events: none;
font-family: 'Roboto', sans-serif;
transition: opacity 250ms ease !important;
/* no idea why this is needed */
margin-top: -70px;
}
.react-contextmenu.react-contextmenu--visible {
color: white;
opacity: 1;
pointer-events: auto;
z-index: 1000;
}
.react-contextmenu-title {
opacity: 0;
}
.react-contextmenu--visible .react-contextmenu-title {
color: #b3b3b3;
padding-left: 10px;
padding-right: 15px;
padding-bottom: 3px;
opacity: 1;
}
.react-contextmenu-title::after {
content: ':';
}
.react-contextmenu > .react-contextmenu-item {
display: inline-block;
padding: 3px 20px;
clear: both;
font-weight: 400;
line-height: 1.5;
color: white;
text-align: inherit;
white-space: nowrap;
background: 0 0;
border: 0;
text-decoration: none;
cursor: pointer;
}
.react-contextmenu-item.active,
.react-contextmenu-item:hover {
color: #f57c00;
border-color: #0275d8;
text-decoration: none;
}
.react-contextmenu-divider {
border-top: 1px solid grey;
margin-top: 4px;
margin-bottom: 7px;
}
.react-contextmenu-submenu {
padding-right: 27px !important;
}
.react-contextmenu-submenu:after {
content: '▶';
display: inline-block;
position: absolute;
right: 7px;
bottom: 3px;
}
`

export const Tree = observer(() => {
Expand Down
Loading