Skip to content

Commit a5f76fa

Browse files
acemacIlaiwi
authored andcommitted
stackItems attempt 2 (#424)
**Issue Number** #397 replacement because I'm terrible at using git **Overview of PR** Removing the API updates that were accidentally merged in to #397 turned out to be an ordeal. This PR should be cleaner. _Don't forget to update the CHANGELOG.md file with any changes that are in this PR_
1 parent 32f9e92 commit a5f76fa

File tree

6 files changed

+132
-120
lines changed

6 files changed

+132
-120
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Expects either a vanilla JS array or an immutableJS array, consisting of objects
8383
id: 1,
8484
title: 'group 1',
8585
rightTitle: 'title in the right sidebar',
86+
stackItems?: true,
87+
height?: 30
8688
}
8789
```
8890

@@ -234,7 +236,7 @@ Append a special `.rct-drag-right` handle to the elements and only resize if dra
234236

235237
### stackItems
236238

237-
Stack items under each other, so there is no visual overlap when times collide. Defaults to `false`.
239+
Stack items under each other, so there is no visual overlap when times collide. Can be overridden in the `groups` array. Defaults to `false`.
238240

239241
## traditionalZoom
240242

demo/app/demo-performance/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export default class App extends Component {
3737
.endOf('month')
3838
.toDate()
3939

40+
groups[0].stackItems = false;
41+
groups[0].height = 300;
4042
this.state = {
4143
groups,
4244
items,

src/lib/Timeline.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
getMinUnit,
1818
getNextUnit,
1919
stackItems,
20-
calculateScrollCanvas,
21-
calculateTimeForXPosition
20+
calculateTimeForXPosition,
21+
calculateScrollCanvas
2222
} from './utility/calendar'
2323
import { _get, _length } from './utility/generic'
2424
import {

src/lib/items/Item.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class Item extends Component {
2727
canvasTimeStart: PropTypes.number.isRequired,
2828
canvasTimeEnd: PropTypes.number.isRequired,
2929
canvasWidth: PropTypes.number.isRequired,
30-
order: PropTypes.number,
30+
order: PropTypes.object,
3131

3232
dragSnap: PropTypes.number,
3333
minResizeWidth: PropTypes.number,
@@ -104,7 +104,8 @@ export default class Item extends Component {
104104
nextProps.canvasTimeStart !== this.props.canvasTimeStart ||
105105
nextProps.canvasTimeEnd !== this.props.canvasTimeEnd ||
106106
nextProps.canvasWidth !== this.props.canvasWidth ||
107-
nextProps.order !== this.props.order ||
107+
(nextProps.order ? nextProps.order.index : undefined) !==
108+
(this.props.order ? this.props.order.index : undefined) ||
108109
nextProps.dragSnap !== this.props.dragSnap ||
109110
nextProps.minResizeWidth !== this.props.minResizeWidth ||
110111
nextProps.canChangeGroup !== this.props.canChangeGroup ||
@@ -184,14 +185,14 @@ export default class Item extends Component {
184185
for (var key of Object.keys(groupTops)) {
185186
var groupTop = groupTops[key]
186187
if (e.pageY - offset + scrolls.scrollTop > groupTop) {
187-
groupDelta = parseInt(key, 10) - order
188+
groupDelta = parseInt(key, 10) - order.index
188189
} else {
189190
break
190191
}
191192
}
192193

193-
if (this.props.order + groupDelta < 0) {
194-
return 0 - this.props.order
194+
if (this.props.order.index + groupDelta < 0) {
195+
return 0 - this.props.order.index
195196
} else {
196197
return groupDelta
197198
}
@@ -273,7 +274,7 @@ export default class Item extends Component {
273274
this.props.onDrag(
274275
this.itemId,
275276
dragTime,
276-
this.props.order + dragGroupDelta
277+
this.props.order.index + dragGroupDelta
277278
)
278279
}
279280

@@ -299,7 +300,7 @@ export default class Item extends Component {
299300
this.props.onDrop(
300301
this.itemId,
301302
dragTime,
302-
this.props.order + this.dragGroupDelta(e)
303+
this.props.order.index + this.dragGroupDelta(e)
303304
)
304305
}
305306

src/lib/items/Items.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ export default class Items extends Component {
8181
)
8282
}
8383

84-
getGroupOrders() {
85-
const { keys, groups } = this.props
86-
87-
return getGroupOrders(groups, keys)
88-
}
89-
9084
isSelected(item, itemIdKey) {
9185
if (!this.props.selected) {
9286
return this.props.selectedItem === _get(item, itemIdKey)
@@ -107,10 +101,12 @@ export default class Items extends Component {
107101
canvasTimeStart,
108102
canvasTimeEnd,
109103
dimensionItems,
104+
keys,
105+
groups
110106
} = this.props
111-
const { itemIdKey, itemGroupKey } = this.props.keys
107+
const { itemIdKey, itemGroupKey } = keys
112108

113-
const groupOrders = this.getGroupOrders()
109+
const groupOrders = getGroupOrders(groups, keys)
114110
const visibleItems = this.getVisibleItems(
115111
canvasTimeStart,
116112
canvasTimeEnd,

0 commit comments

Comments
 (0)