Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

[Timeline] Fix react integration, fix content applying mechanics #3760

Merged
merged 2 commits into from
Jan 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions lib/timeline/component/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function Group (groupId, data, itemSet) {
this.itemSet = itemSet;
this.isVisible = null;
this.stackDirty = true; // if true, items will be restacked on next redraw

if (data && data.nestedGroups) {
this.nestedGroups = data.nestedGroups;
if (data.showNested == false) {
Expand Down Expand Up @@ -135,11 +135,14 @@ Group.prototype.setData = function(data) {
}

if (content instanceof Element) {
this.dom.inner.appendChild(content);
while (this.dom.inner.firstChild) {
this.dom.inner.removeChild(this.dom.inner.firstChild);
}
this.dom.inner.appendChild(content);
} else if (content instanceof Object && content.isReactComponent) {
// Do nothing. Component was rendered into the node be ReactDOM.render.
// That branch is necessary for evasion of a second call templateFunction.
// Supports only React < 16(due to the asynchronous nature of React 16).
} else if (content instanceof Object) {
templateFunction(data, this.dom.inner);
} else if (content !== undefined && content !== null) {
Expand All @@ -161,7 +164,7 @@ Group.prototype.setData = function(data) {
if (!this.nestedGroups || this.nestedGroups != data.nestedGroups) {
this.nestedGroups = data.nestedGroups;
}

if (data.showNested !== undefined || this.showNested === undefined) {
if (data.showNested == false) {
this.showNested = false;
Expand Down Expand Up @@ -345,20 +348,20 @@ Group.prototype._redrawItems = function(forceRestack, lastIsVisible, margin, ran

if (this.doInnerStack && this.itemSet.options.stackSubgroups) {
// Order the items within each subgroup
for(subgroup in this.subgroups) {
for(subgroup in this.subgroups) {
visibleSubgroups[subgroup] = this.subgroups[subgroup].items.slice().sort(function (a, b) {
return me.itemSet.options.order(a.data, b.data);
});
}

stack.stackSubgroupsWithInnerStack(visibleSubgroups, margin, this.subgroups);
stack.stackSubgroupsWithInnerStack(visibleSubgroups, margin, this.subgroups);
}
else {
// order all items and force a restacking
var customOrderedItems = this.orderedItems.byStart.slice().sort(function (a, b) {
return me.itemSet.options.order(a.data, b.data);
});
this.shouldBailStackItems = stack.stack(customOrderedItems, margin, true, this._shouldBailItemsRedraw.bind(this));
this.shouldBailStackItems = stack.stack(customOrderedItems, margin, true, this._shouldBailItemsRedraw.bind(this));
}

this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);
Expand All @@ -367,8 +370,8 @@ Group.prototype._redrawItems = function(forceRestack, lastIsVisible, margin, ran
this.visibleItems = this._updateItemsInRange(this.orderedItems, this.visibleItems, range);

if (this.itemSet.options.stack) {
if (this.doInnerStack && this.itemSet.options.stackSubgroups) {
for(subgroup in this.subgroups) {
if (this.doInnerStack && this.itemSet.options.stackSubgroups) {
for(subgroup in this.subgroups) {
visibleSubgroups[subgroup] = this.subgroups[subgroup].items;
}

Expand Down Expand Up @@ -669,7 +672,6 @@ Group.prototype._addToSubgroup = function(item, subgroupId) {
}

this.subgroups[subgroupId].items.push(item);

};

Group.prototype._updateSubgroupsSizes = function () {
Expand All @@ -681,8 +683,8 @@ Group.prototype._updateSubgroupsSizes = function () {
var newEnd = initialEnd - 1;

me.subgroups[subgroup].items.forEach(function(item) {
if (new Date(item.data.start) < new Date(newStart)) {
newStart = item.data.start;
if (new Date(item.data.start) < new Date(newStart)) {
newStart = item.data.start;
}

var itemEnd = item.data.end || item.data.start;
Expand Down