This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(Tree): add virtualized tree prototype #1890
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1f9d3ef
add react-virtualized to package and yarn lock
silviuaavram ed9b21b
add virtualized render prop to Tree
silviuaavram 36b2383
add virtualized tree in prototypes
silviuaavram 0e39d1f
add alternative solution in comments
silviuaavram 5f016f5
add back as any from merging master
silviuaavram d4fe288
have refs for all items
silviuaavram a84c9d1
merge master
silviuaavram 5b9404e
fix the cloneElement approach
silviuaavram b3bd3f9
fix ref issue
silviuaavram 48e33cd
increase virtualized tree size
silviuaavram 47d0546
rename the render prop
silviuaavram e170048
Merge branch 'master' into feat/add-virtualized-tree-prototype
silviuaavram 4db50b7
add changelog
silviuaavram 84720aa
fix use of prop name
silviuaavram 14737cc
move items code from prototype
silviuaavram 9b77112
address code review
silviuaavram 52bfc8c
make prototype public
silviuaavram 188ae22
Merge branch 'master' into feat/add-virtualized-tree-prototype
silviuaavram d05647c
use lodash times function
silviuaavram a75d594
Merge branch 'feat/add-virtualized-tree-prototype' of https://github.…
silviuaavram 29fd807
Merge branch 'master' into feat/add-virtualized-tree-prototype
silviuaavram aeabfd8
Merge branch 'master' into feat/add-virtualized-tree-prototype
silviuaavram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import * as React from 'react' | ||
| import { Tree } from '@stardust-ui/react' | ||
| import { CellMeasurer, CellMeasurerCache, List as ReactVirtualizedList } from 'react-virtualized' | ||
| import getItems from './itemsGenerator' | ||
|
|
||
| interface TreeVirtualizerProps { | ||
| renderedItems: React.ReactElement[] | ||
| } | ||
|
|
||
| function TreeVirtualizer(props: TreeVirtualizerProps) { | ||
| const cache = new CellMeasurerCache({ | ||
| defaultHeight: 20, | ||
| fixedWidth: true, | ||
| }) | ||
|
|
||
| const rowRenderer = ({ index, isScrolling, key, parent, style }) => { | ||
| const { renderedItems } = props | ||
|
|
||
| return ( | ||
| <CellMeasurer cache={cache} columnIndex={0} key={key} parent={parent} rowIndex={index}> | ||
| {React.cloneElement(renderedItems[index], { style })} | ||
| </CellMeasurer> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <ReactVirtualizedList | ||
| deferredMeasurementCache={cache} | ||
| rowHeight={cache.rowHeight} | ||
| rowRenderer={rowRenderer} | ||
| estimatedRowSize={20} | ||
| height={300} | ||
| rowCount={props.renderedItems.length} | ||
| width={600} | ||
| /> | ||
| ) | ||
| } | ||
layershifter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const items = getItems() | ||
|
|
||
| const VirtualizedTreePrototype = () => ( | ||
| <Tree | ||
| items={items} | ||
| renderedItems={renderedItems => <TreeVirtualizer renderedItems={renderedItems} />} | ||
| /> | ||
| ) | ||
|
|
||
| export default VirtualizedTreePrototype | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import * as React from 'react' | ||
| import VirtualizedTree from './VirtualizedTree' | ||
| import { PrototypeSection, ComponentPrototype } from '../Prototypes' | ||
|
|
||
| export default () => ( | ||
| <PrototypeSection title="VirtualizedTree"> | ||
| <ComponentPrototype title="Virtualized Tree" description="Tree with its content virtualized."> | ||
| <VirtualizedTree /> | ||
| </ComponentPrototype> | ||
| </PrototypeSection> | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import * as _ from 'lodash' | ||
|
|
||
| function getItems(minItems = 20, maxItems = 40, maxLevel = 1) { | ||
| function getItemsNumber(minItems, maxItems) { | ||
| return _.random(minItems, maxItems) | ||
| } | ||
|
|
||
| function generateLevel(level, parent = '') { | ||
| const result = [] | ||
| _.times(getItemsNumber(minItems, maxItems), index => { | ||
| const item = { | ||
| id: `${parent}${parent ? '-' : ''}${index}`, | ||
| title: `Tree-Item-${parent}${parent ? '-' : ''}${index}`, | ||
| ...(level < maxLevel && { items: generateLevel(level + 1, `${parent}${index}`) }), | ||
| } | ||
| result.push(item) | ||
| }) | ||
| return result | ||
| } | ||
|
|
||
| return generateLevel(0) | ||
| } | ||
|
|
||
| export default getItems |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be persistent between renders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, I just looked at his example.
https://github.com/bvaughn/react-virtualized/blob/a390b2aa3652bdf488a1eb37348d98558617dcfd/source/CellMeasurer/CellMeasurer.DynamicHeightList.example.js#L19
probably not needed.