diff options
author | Emiliano Ciavatta | 2020-12-17 09:57:29 +0000 |
---|---|---|
committer | Emiliano Ciavatta | 2020-12-17 09:57:29 +0000 |
commit | ad0c27ae1fde7d24c24a34a7c305edeb0ea9974e (patch) | |
tree | b65405425d3325935a8bcd8fbedd7e8905eb7c6c /frontend/src/components/Timeline.js | |
parent | e4b73c0c3ce2c8817ddd1b8cfaa672823b59a422 (diff) | |
parent | 1c7bd710650cafbf1eb093344a95a57882069fae (diff) |
Merge branch 'develop' into main
Diffstat (limited to 'frontend/src/components/Timeline.js')
-rw-r--r-- | frontend/src/components/Timeline.js | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/frontend/src/components/Timeline.js b/frontend/src/components/Timeline.js index 5443a3b..ec791e0 100644 --- a/frontend/src/components/Timeline.js +++ b/frontend/src/components/Timeline.js @@ -35,6 +35,7 @@ import ChoiceField from "./fields/ChoiceField"; import "./Timeline.scss"; const minutes = 60 * 1000; +const maxTimelineRange = 24 * 60 * minutes; const classNames = require("classnames"); const leftSelectionPaddingMultiplier = 24; @@ -109,8 +110,25 @@ class Timeline extends Component { const zeroFilledMetrics = []; const toTime = (m) => new Date(m["range_start"]).getTime(); - let i = 0; - for (let interval = toTime(metrics[0]) - minutes; interval <= toTime(metrics[metrics.length - 1]) + minutes; interval += minutes) { + + let i; + let timeStart = toTime(metrics[0]) - minutes; + for (i = 0; timeStart < 0 && i < metrics.length; i++) { // workaround to remove negative timestamps :( + timeStart = toTime(metrics[i]) - minutes; + } + + let timeEnd = toTime(metrics[metrics.length - 1]) + minutes; + if (timeEnd - timeStart > maxTimelineRange) { + timeEnd = timeStart + maxTimelineRange; + + const now = new Date().getTime(); + if (!this.lastDisplayNotificationTime || this.lastDisplayNotificationTime + minutes < now) { + this.lastDisplayNotificationTime = now; + dispatcher.dispatch("notifications", {event: "timeline.range.large"}); + } + } + + for (let interval = timeStart; interval <= timeEnd; interval += minutes) { if (i < metrics.length && interval === toTime(metrics[i])) { const m = metrics[i++]; m["range_start"] = new Date(m["range_start"]); @@ -204,10 +222,12 @@ class Timeline extends Component { }; handleConnectionUpdates = (payload) => { - this.setState({ - selection: new TimeRange(payload.from, payload.to), - }); - this.adjustSelection(); + if (payload.from >= this.state.start && payload.from < payload.to && payload.to <= this.state.end) { + this.setState({ + selection: new TimeRange(payload.from, payload.to), + }); + this.adjustSelection(); + } }; handleNotifications = (payload) => { |