11// @flow
22import * as React from 'react' ;
3- import classNames from 'classnames' ;
43import { CellMeasurer , CellMeasurerCache } from 'react-virtualized/dist/es/CellMeasurer' ;
54import Table , { Column } from 'react-virtualized/dist/es/Table' ;
6- import uniqueId from 'lodash/uniqueId' ;
75import getProp from 'lodash/get' ;
6+ import GridViewSlot from './GridViewSlot' ;
87
98import 'react-virtualized/styles.css' ;
109import './GridView.scss' ;
@@ -37,13 +36,13 @@ class GridView extends React.Component<Props> {
3736 fixedWidth : true ,
3837 } ) ;
3938
40- componentDidUpdate ( prevProps : Props ) {
39+ componentDidUpdate ( { columnCount : prevColumnCount , width : prevWidth } : Props ) {
4140 const { columnCount , width } = this . props ;
4241
43- // The React Virtualized Table must be notified when either the cached
44- // row sizes or the parent width change. If omitted, rows are sized
42+ // The React Virtualized Table must be notified whenever the heights of rows
43+ // could potentially change. If omitted, rows are sized
4544 // incorrectly resulting in gaps or content overlap.
46- if ( columnCount !== prevProps . columnCount || width !== prevProps . width ) {
45+ if ( columnCount !== prevColumnCount || width !== prevWidth ) {
4746 this . cache . clearAll ( ) ;
4847 this . forceUpdate ( ) ;
4948 }
@@ -58,16 +57,19 @@ class GridView extends React.Component<Props> {
5857 const maxSlotIndex = Math . min ( startingIndex + columnCount , count ) ;
5958
6059 for ( let slotIndex = startingIndex ; slotIndex < maxSlotIndex ; slotIndex += 1 ) {
60+ const { id, selected } = getProp ( currentCollection , `items[${ slotIndex } ]` ) ;
61+
6162 // using item's id as key is important for renrendering. React Virtualized Table rerenders
6263 // on every 1px scroll, so using improper key would lead to image flickering in each
6364 // card of the grid view when scrolling.
6465 contents . push (
65- < div
66- key = { getProp ( currentCollection , `items[${ slotIndex } ].id` ) || uniqueId ( 'bdl-GridView-slot' ) }
67- className = "bdl-GridView-slot"
68- >
69- { slotRenderer ( slotIndex ) }
70- </ div > ,
66+ < GridViewSlot
67+ key = { id }
68+ selected = { selected }
69+ slotIndex = { slotIndex }
70+ slotRenderer = { slotRenderer }
71+ slotWidth = { `${ ( 100 / columnCount ) . toFixed ( 4 ) } %` }
72+ /> ,
7173 ) ;
7274 }
7375
@@ -89,7 +91,7 @@ class GridView extends React.Component<Props> {
8991
9092 return (
9193 < Table
92- className = { classNames ( ' bdl-GridView' , `bdl-GridView--columns- ${ columnCount } ` ) }
94+ className = " bdl-GridView"
9395 disableHeader
9496 height = { height }
9597 rowCount = { rowCount }
0 commit comments