Skip to content

Commit bcc026c

Browse files
authored
Merge pull request #470 from namespace-ee/develop
0.22.0
2 parents 9d0d3fd + 32f9e92 commit bcc026c

File tree

14 files changed

+108
-69
lines changed

14 files changed

+108
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ gh-pages
1515
# code coverage
1616
coverage
1717

18+
*.orig

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres (more or less) to [Semantic Versioning](http://semver.o
77

88
## Unreleased
99

10+
### Fixed
11+
12+
* Provided a new key `groupLabelKey` to allow splitting of the key used to render the Sidebar and the InfoLabel visible during drag operations. `groupTitleKey` continues to be used to render the Sidebar. #442 @thiagosatoshi
13+
* fix scroll left/right causes item move/edit to be at incorrect time #401 @acemac
14+
* now `getResizeProps` take `leftClassName` and `rightClassName` and returns className for left and right props @acemac
15+
* fix functionality of `itemTitle` and `itemDivTitle` [issue](https://github.com/namespace-ee/react-calendar-timeline/issues/429#issuecomment-426456693) @acemac
16+
1017
### 0.21.0
1118

1219
#### fixes

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ An array specifying keys in the `items` and `groups` objects. Defaults to
141141
groupIdKey: 'id',
142142
groupTitleKey: 'title',
143143
groupRightTitleKey: 'rightTitle',
144+
groupLabelKey: 'title', // key for what to show in `InfoLabel`
144145
itemIdKey: 'id',
145146
itemTitleKey: 'title', // key for item div content
146147
itemDivTitleKey: 'title', // key for item div title (<div title="text"/>)
147148
itemGroupKey: 'group',
148149
itemTimeStartKey: 'start_time',
149-
itemTimeEndKey: 'end_time'
150+
itemTimeEndKey: 'end_time',
150151
}
151152
```
152153

@@ -511,16 +512,20 @@ Rather than applying props on the element yourself and to avoid your props being
511512
* `getResizeProps` returns the props you should apply to the left and right resize handlers only if `useResizeHandle` set to true. The returned object has the props for the left element under property `left` and the props to be applied to the right element under `right` :
512513

513514
* left
514-
* ref: function to get element referance
515+
* ref: function to get element reference
515516
* style: style to be applied to the left element
517+
* className: class names to be applied to left className
516518
* right
517-
* ref: function to get element referance
519+
* ref: function to get element reference
518520
* style: style to be applied to the right element
521+
* className: class names to be applied to left className
519522

520-
These properties can be override using the prop argument with proprties:
523+
These properties can be override using the prop argument with properties:
521524

522525
* leftStyle: style to be added to left style
523526
* rightStyle: style to be added to right style
527+
* leftClassName: classes to be added to left handler
528+
* rightClassName: classes to be added to right handler
524529

525530
example
526531

demo/app/demo-tree-groups/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var keys = {
99
groupIdKey: 'id',
1010
groupTitleKey: 'title',
1111
groupRightTitleKey: 'rightTitle',
12+
groupLabelKey: 'label',
1213
itemIdKey: 'id',
1314
itemTitleKey: 'title',
1415
itemDivTitleKey: 'title',
@@ -105,7 +106,7 @@ export default class App extends Component {
105106
sidebarContent={<div>Above The Left</div>}
106107
rightSidebarWidth={150}
107108
rightSidebarContent={<div>Above The Right</div>}
108-
canMove
109+
canMove={true}
109110
canResize="right"
110111
canSelect
111112
itemsSorted

demo/app/generate-fake-data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default function (groupCount = 30, itemCount = 1000, daysInPast = 30) {
1010
id: `${i + 1}`,
1111
title: faker.name.firstName(),
1212
rightTitle: faker.name.lastName(),
13+
label: `Label ${faker.name.firstName()}`,
1314
bgColor: randomColor({ luminosity: 'light', seed: randomSeed + i })
1415
})
1516
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-calendar-timeline",
3-
"version": "0.21.0",
3+
"version": "0.22.0",
44
"description": "react calendar timeline",
55
"main": "lib/index.js",
66
"scripts": {
@@ -49,7 +49,7 @@
4949
"url": "https://github.com/dkarnutsch"
5050
},
5151
{
52-
"name":"Alex Maclean",
52+
"name": "Alex Maclean",
5353
"url": "https://github.com/acemac"
5454
},
5555
{

src/lib/Timeline.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default class ReactCalendarTimeline extends Component {
8888
keys: PropTypes.shape({
8989
groupIdKey: PropTypes.string,
9090
groupTitleKey: PropTypes.string,
91+
groupLabelKey: PropTypes.string,
9192
groupRightTitleKey: PropTypes.string,
9293
itemIdKey: PropTypes.string,
9394
itemTitleKey: PropTypes.string,
@@ -297,7 +298,6 @@ export default class ReactCalendarTimeline extends Component {
297298
dragTime: null,
298299
dragGroupTitle: null,
299300
resizeTime: null,
300-
topOffset: 0,
301301
resizingItem: null,
302302
resizingEdge: null
303303
}
@@ -415,12 +415,9 @@ export default class ReactCalendarTimeline extends Component {
415415
resize = (props = this.props) => {
416416
const {
417417
width: containerWidth,
418-
top: containerTop
419418
} = this.container.getBoundingClientRect()
420419

421420
let width = containerWidth - props.sidebarWidth - props.rightSidebarWidth
422-
const { headerLabelGroupHeight, headerLabelHeight } = props
423-
const headerHeight = headerLabelGroupHeight + headerLabelHeight
424421

425422
const { dimensionItems, height, groupHeights, groupTops } = stackItems(
426423
props.items,
@@ -435,11 +432,9 @@ export default class ReactCalendarTimeline extends Component {
435432

436433
// this is needed by dragItem since it uses pageY from the drag events
437434
// if this was in the context of the scrollElement, this would not be necessary
438-
const topOffset = containerTop + window.pageYOffset + headerHeight
439435

440436
this.setState({
441437
width,
442-
topOffset,
443438
dimensionItems,
444439
height,
445440
groupHeights,
@@ -648,7 +643,7 @@ export default class ReactCalendarTimeline extends Component {
648643
draggingItem: item,
649644
dragTime: dragTime,
650645
newGroupOrder: newGroupOrder,
651-
dragGroupTitle: newGroup ? _get(newGroup, keys.groupTitleKey) : ''
646+
dragGroupTitle: newGroup ? _get(newGroup, keys.groupLabelKey) : ''
652647
})
653648
}
654649

@@ -784,7 +779,6 @@ export default class ReactCalendarTimeline extends Component {
784779
useResizeHandle={this.props.useResizeHandle}
785780
canSelect={this.props.canSelect}
786781
moveResizeValidator={this.props.moveResizeValidator}
787-
topOffset={this.state.topOffset}
788782
itemSelect={this.selectItem}
789783
itemDrag={this.dragItem}
790784
itemDrop={this.dropItem}
@@ -794,6 +788,7 @@ export default class ReactCalendarTimeline extends Component {
794788
itemResized={this.resizedItem}
795789
itemRenderer={this.props.itemRenderer}
796790
selected={this.props.selected}
791+
scrollRef={this.scrollComponent}
797792
/>
798793
)
799794
}

src/lib/Timeline.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $weekend: rgba(250, 246, 225, 0.5);
5151
.rct-item-content {
5252
position: sticky;
5353
position: -webkit-sticky;
54-
left: 0;
54+
left: 0px;
5555
overflow: hidden;
5656
display: inline-block;
5757
border-radius: 2px;

src/lib/default-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const defaultKeys = {
22
groupIdKey: 'id',
33
groupTitleKey: 'title',
44
groupRightTitleKey: 'rightTitle',
5+
groupLabelKey: 'title',
56
itemIdKey: 'id',
67
itemTitleKey: 'title',
78
itemDivTitleKey: 'title',

src/lib/items/Item.js

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { _get, deepObjectCompare } from '../utility/generic'
77
import { composeEvents } from '../utility/events'
88
import { defaultItemRenderer } from './defaultItemRenderer'
99
import { coordinateToTimeRatio } from '../utility/calendar'
10+
import { getSumScroll, getSumOffset } from '../utility/dom-helpers'
1011
import {
1112
overridableStyles,
1213
selectedStyle,
@@ -50,12 +51,13 @@ export default class Item extends Component {
5051

5152
itemProps: PropTypes.object,
5253
canSelect: PropTypes.bool,
53-
topOffset: PropTypes.number,
5454
dimensions: PropTypes.object,
5555
groupTops: PropTypes.array,
5656
useResizeHandle: PropTypes.bool,
5757
moveResizeValidator: PropTypes.func,
58-
onItemDoubleClick: PropTypes.func
58+
onItemDoubleClick: PropTypes.func,
59+
60+
scrollRef: PropTypes.object
5961
}
6062

6163
static defaultProps = {
@@ -107,7 +109,6 @@ export default class Item extends Component {
107109
nextProps.minResizeWidth !== this.props.minResizeWidth ||
108110
nextProps.canChangeGroup !== this.props.canChangeGroup ||
109111
nextProps.canSelect !== this.props.canSelect ||
110-
nextProps.topOffset !== this.props.topOffset ||
111112
nextProps.canMove !== this.props.canMove ||
112113
nextProps.canResizeLeft !== this.props.canResizeLeft ||
113114
nextProps.canResizeRight !== this.props.canResizeRight ||
@@ -154,26 +155,35 @@ export default class Item extends Component {
154155
const startTime = moment(this.itemTimeStart)
155156

156157
if (this.state.dragging) {
157-
const deltaX = e.pageX - this.state.dragStart.x
158-
const timeDelta = deltaX * this.getTimeRatio()
159-
160-
return this.dragTimeSnap(startTime.valueOf() + timeDelta, true)
158+
return this.dragTimeSnap(this.timeFor(e) + this.state.dragStart.offset, true)
161159
} else {
162160
return startTime
163161
}
164162
}
165163

164+
timeFor(e) {
165+
const ratio = coordinateToTimeRatio(this.props.canvasTimeStart, this.props.canvasTimeEnd, this.props.canvasWidth)
166+
167+
const offset = getSumOffset(this.props.scrollRef).offsetLeft
168+
const scrolls = getSumScroll(this.props.scrollRef)
169+
170+
return (e.pageX - offset + scrolls.scrollLeft) * ratio + this.props.canvasTimeStart;
171+
}
172+
166173
dragGroupDelta(e) {
167-
const { groupTops, order, topOffset } = this.props
174+
const { groupTops, order } = this.props
168175
if (this.state.dragging) {
169176
if (!this.props.canChangeGroup) {
170177
return 0
171178
}
172179
let groupDelta = 0
173180

181+
const offset = getSumOffset(this.props.scrollRef).offsetTop
182+
const scrolls = getSumScroll(this.props.scrollRef)
183+
174184
for (var key of Object.keys(groupTops)) {
175-
var item = groupTops[key]
176-
if (e.pageY - topOffset > item) {
185+
var groupTop = groupTops[key]
186+
if (e.pageY - offset + scrolls.scrollTop > groupTop) {
177187
groupDelta = parseInt(key, 10) - order
178188
} else {
179189
break
@@ -211,8 +221,8 @@ export default class Item extends Component {
211221
}
212222

213223
mountInteract() {
214-
const leftResize = this.props.useResizeHandle ? this.dragLeft : true
215-
const rightResize = this.props.useResizeHandle ? this.dragRight : true
224+
const leftResize = this.props.useResizeHandle ? ".rct-item-handler-resize-left" : true
225+
const rightResize = this.props.useResizeHandle ? ".rct-item-handler-resize-right" : true
216226

217227
interact(this.item)
218228
.resizable({
@@ -231,9 +241,13 @@ export default class Item extends Component {
231241
.styleCursor(false)
232242
.on('dragstart', e => {
233243
if (this.props.selected) {
244+
const clickTime = this.timeFor(e);
234245
this.setState({
235246
dragging: true,
236-
dragStart: { x: e.pageX, y: e.pageY },
247+
dragStart: {
248+
x: e.pageX,
249+
y: e.pageY,
250+
offset: this.itemTimeStart - clickTime },
237251
preDragPosition: { x: e.target.offsetLeft, y: e.target.offsetTop },
238252
dragTime: this.itemTimeStart,
239253
dragGroupDelta: 0
@@ -318,12 +332,7 @@ export default class Item extends Component {
318332
resizeEdge = e.deltaRect.left !== 0 ? 'left' : 'right'
319333
this.setState({ resizeEdge })
320334
}
321-
const time =
322-
resizeEdge === 'left' ? this.itemTimeStart : this.itemTimeEnd
323-
324-
let resizeTime = this.resizeTimeSnap(
325-
time + this.resizeTimeDelta(e, resizeEdge)
326-
)
335+
let resizeTime = this.resizeTimeSnap(this.timeFor(e))
327336

328337
if (this.props.moveResizeValidator) {
329338
resizeTime = this.props.moveResizeValidator(
@@ -346,11 +355,7 @@ export default class Item extends Component {
346355
.on('resizeend', e => {
347356
if (this.state.resizing) {
348357
const { resizeEdge } = this.state
349-
const time =
350-
resizeEdge === 'left' ? this.itemTimeStart : this.itemTimeEnd
351-
let resizeTime = this.resizeTimeSnap(
352-
time + this.resizeTimeDelta(e, resizeEdge)
353-
)
358+
let resizeTime = this.resizeTimeSnap(this.timeFor(e))
354359

355360
if (this.props.moveResizeValidator) {
356361
resizeTime = this.props.moveResizeValidator(
@@ -406,22 +411,22 @@ export default class Item extends Component {
406411
return !!props.canMove
407412
}
408413

409-
componentWillReceiveProps(nextProps) {
410-
this.cacheDataFromProps(nextProps)
414+
componentDidUpdate(prevProps) {
415+
this.cacheDataFromProps(this.props)
411416

412417
let { interactMounted } = this.state
413418
const couldDrag = this.props.selected && this.canMove(this.props)
414419
const couldResizeLeft =
415420
this.props.selected && this.canResizeLeft(this.props)
416421
const couldResizeRight =
417422
this.props.selected && this.canResizeRight(this.props)
418-
const willBeAbleToDrag = nextProps.selected && this.canMove(nextProps)
423+
const willBeAbleToDrag = this.props.selected && this.canMove(this.props)
419424
const willBeAbleToResizeLeft =
420-
nextProps.selected && this.canResizeLeft(nextProps)
425+
this.props.selected && this.canResizeLeft(this.props)
421426
const willBeAbleToResizeRight =
422-
nextProps.selected && this.canResizeRight(nextProps)
427+
this.props.selected && this.canResizeRight(this.props)
423428

424-
if (nextProps.selected && !interactMounted) {
429+
if (this.props.selected && !interactMounted) {
425430
this.mountInteract()
426431
interactMounted = true
427432
}
@@ -511,6 +516,7 @@ export default class Item extends Component {
511516
return {
512517
key: this.itemId,
513518
ref: this.getItemRef,
519+
title: this.itemDivTitle,
514520
className: classNames + ` ${props.className ? props.className : ''}`,
515521
onMouseDown: composeEvents(this.onMouseDown, props.onMouseDown),
516522
onMouseUp: composeEvents(this.onMouseUp, props.onMouseUp),
@@ -523,13 +529,24 @@ export default class Item extends Component {
523529
}
524530

525531
getResizeProps = (props = {}) => {
532+
let leftName = "rct-item-handler rct-item-handler-left rct-item-handler-resize-left"
533+
if (props.leftClassName) {
534+
leftName += ` ${props.leftClassName}`
535+
}
536+
537+
let rightName = "rct-item-handler rct-item-handler-right rct-item-handler-resize-right"
538+
if (props.rightClassName) {
539+
rightName += ` ${props.rightClassName}`
540+
}
526541
return {
527542
left: {
528543
ref: this.getDragLeftRef,
544+
className: leftName,
529545
style: Object.assign({}, leftResizeStyle, props.leftStyle)
530546
},
531547
right: {
532548
ref: this.getDragRightRef,
549+
className: rightName,
533550
style: Object.assign({}, rightResizeStyle, props.rightStyle)
534551
}
535552
}
@@ -582,7 +599,7 @@ export default class Item extends Component {
582599
const itemContext = {
583600
dimensions: this.props.dimensions,
584601
useResizeHandle: this.props.useResizeHandle,
585-
title: this.itemDivTitle,
602+
title: this.itemTitle,
586603
canMove: this.canMove(this.props),
587604
canResizeLeft: this.canResizeLeft(this.props),
588605
canResizeRight: this.canResizeRight(this.props),

0 commit comments

Comments
 (0)