forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Virtualize question list and misc cleanup / flow typing
- Loading branch information
1 parent
08bc82e
commit 369b43e
Showing
9 changed files
with
241 additions
and
169 deletions.
There are no files selected for viewing
This file contains 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,10 @@ | ||
/* @flow */ | ||
|
||
export type LabelId = number; | ||
|
||
export type Label = { | ||
id: LabelId, | ||
name: string, | ||
slug: string, | ||
icon: string, | ||
}; |
This file contains 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 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 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 |
---|---|---|
@@ -1,22 +1,105 @@ | ||
/* @flow */ | ||
/* eslint "react/prop-types": "warn" */ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import Item from "./Item"; | ||
|
||
import S from "./List.css"; | ||
import pure from "recompose/pure"; | ||
|
||
import EntityItem from "../containers/EntityItem.jsx"; | ||
import { List as VirtalizedList, WindowScroller } from "react-virtualized"; | ||
import "react-virtualized/styles.css"; | ||
|
||
const HORIZONTAL_PADDING = 32; | ||
const ROW_HEIGHT = 87; | ||
|
||
import type { Item as ItemType, Entity } from "../types"; | ||
|
||
type Props = { | ||
items: ItemType[], | ||
|
||
const List = ({ entityIds, ...props }) => ( | ||
<ul className={S.list}> | ||
{entityIds.map(entityId => ( | ||
<EntityItem key={entityId} entityId={entityId} {...props} /> | ||
))} | ||
</ul> | ||
); | ||
editable: boolean, | ||
showCollectionName: boolean, | ||
|
||
List.propTypes = { | ||
entityIds: PropTypes.array.isRequired, | ||
setItemSelected: (selected: { [key: number]: boolean }) => void, | ||
setFavorited: (id: number, favorited: boolean) => void, | ||
setArchived: (id: number, archived: boolean, undoable: boolean) => void, | ||
onEntityClick: (entity: Entity) => void, | ||
}; | ||
|
||
export default pure(List); | ||
type ReactVirtualizedRowRendererProps = { | ||
index: number, | ||
key: string, | ||
style: { [key: string]: any }, | ||
}; | ||
|
||
export default class List extends React.Component { | ||
props: Props; | ||
|
||
_list: ?React.Element<VirtalizedList>; | ||
|
||
static propTypes = { | ||
items: PropTypes.array.isRequired, | ||
|
||
editable: PropTypes.bool, | ||
showCollectionName: PropTypes.bool.isRequired, | ||
|
||
setItemSelected: PropTypes.func.isRequired, | ||
setFavorited: PropTypes.func.isRequired, | ||
setArchived: PropTypes.func.isRequired, | ||
onEntityClick: PropTypes.func, | ||
}; | ||
|
||
renderRow = ({ index, key, style }: ReactVirtualizedRowRendererProps) => { | ||
const { | ||
editable, | ||
setItemSelected, | ||
setFavorited, | ||
setArchived, | ||
onEntityClick, | ||
showCollectionName, | ||
items, | ||
} = this.props; | ||
const item = items[index]; | ||
return ( | ||
<div | ||
key={key} | ||
style={{ ...style, display: item.visible ? undefined : "none" }} | ||
> | ||
<Item | ||
setItemSelected={editable ? setItemSelected : null} | ||
setFavorited={editable ? setFavorited : null} | ||
setArchived={editable ? setArchived : null} | ||
onEntityClick={onEntityClick} | ||
showCollectionName={showCollectionName} | ||
{...item} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
render() { | ||
let { items } = this.props; | ||
|
||
return ( | ||
<WindowScroller> | ||
{({ height, width, isScrolling, registerChild, scrollTop }) => ( | ||
<div ref={registerChild}> | ||
<VirtalizedList | ||
ref={l => (this._list = l)} | ||
className={S.list} | ||
autoHeight | ||
height={height} | ||
isScrolling={isScrolling} | ||
rowCount={items.length} | ||
rowHeight={ROW_HEIGHT} | ||
rowRenderer={this.renderRow} | ||
scrollTop={scrollTop} | ||
width={width - HORIZONTAL_PADDING * 2} | ||
/> | ||
</div> | ||
)} | ||
</WindowScroller> | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.