Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

19 - set selection fix #20

Merged
merged 9 commits into from
Aug 10, 2017
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Overview
Add general description explaining this issue

## Package versions
react-visjs-timeline:
vis version:

## Steps to reproduce
Add step by step guide to reproduce issue

1. Step 1
2. Step 2

## Code Snippet

```js
Add relevant code snippet here
```

## Related issues
Any issue which is related to this issue

* e.g. issue 123

## Screenshots (if appropriate)
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Overview
Add general description explaining what this PR achieves

## Updates
Add high level overview of the individual changes in this PR

* e.g. Updated package to version x.x.x

## Dependencies
Add any dependencies associated with this PR e.g.

- [ ] e.g. Wait for PR to be merged

## Outstanding Tasks
Add any tasks which need to be completed before merge

- [ ] e.g. Functional testing

## Screenshots (if appropriate)
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
src
.babelrc
.gitignore
.github

examples
src
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ for (let i = 0; i < itemCount; i++) {
}

class App extends Component {
constructor(props) {
super(props)

this.state = {
selectedIds: []
}
}

render() {
return (
<div className="App">
Expand All @@ -59,10 +67,20 @@ class App extends Component {
and groups via the DataSet.</p>
<Timeline
{...groupsExample}
clickHandler={this.clickHandler.bind(this)}
selection={this.state.selectedIds}
/>
</div>
)
}

clickHandler(props) {
const { group } = props
const selectedIds = groupsExample.items.filter(item => item.group === group).map(item => item.id)
this.setState({
selectedIds
})
}
}

export default App
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ export default class Timeline extends Component {
const groupsChange = groups !== nextProps.groups
const optionsChange = options !== nextProps.options
const customTimesChange = customTimes !== nextProps.customTimes
const selectionChange = selection !== nextProps.selection

return itemsChange ||
groupsChange ||
optionsChange ||
customTimesChange
customTimesChange ||
selectionChange
}

init() {
Expand All @@ -87,6 +89,7 @@ export default class Timeline extends Component {
groups,
options,
selection,
selectionOptions = {},
customTimes,
animate = true,
currentTime
Expand All @@ -107,7 +110,7 @@ export default class Timeline extends Component {

this.$el.setOptions(timelineOptions)
this.$el.setItems(items)
this.$el.setSelection(selection)
this.$el.setSelection(selection, selectionOptions)

if (hasGroups) {
this.$el.setGroups(groups)
Expand Down