From 888f3a7f121477954c35cfa4fd2218e943ed7821 Mon Sep 17 00:00:00 2001 From: Alec Clowes Date: Sun, 29 Jul 2018 14:41:48 -0400 Subject: [PATCH] pin scroll and show errors (#47) * show error message when not logged in * pin scroll on task log --- frontend/src/TaskDetail.js | 94 ++++++---- frontend/src/WorkflowDetailHistory.js | 1 + frontend/src/tests/TaskDetail.test.js | 9 + .../__snapshots__/TaskDetail.test.js.snap | 173 ++++++++++-------- 4 files changed, 161 insertions(+), 116 deletions(-) diff --git a/frontend/src/TaskDetail.js b/frontend/src/TaskDetail.js index 7577dfc..31b6914 100644 --- a/frontend/src/TaskDetail.js +++ b/frontend/src/TaskDetail.js @@ -1,5 +1,5 @@ import React from 'react'; -import {PanelGroup, Panel, Alert, Pagination, Button} from 'react-bootstrap'; +import {PanelGroup, Panel, Alert, Pagination, Button, ButtonToolbar} from 'react-bootstrap'; import {Link} from 'react-router'; import API from "./API"; @@ -8,13 +8,20 @@ import {formatDateTime} from "./utilities"; export default class TaskDetail extends React.Component { constructor(props) { super(props); - this.state = {task: null, error: null}; + this.state = {task: null, error: null, follow: false}; } componentDidMount() { this.refreshExecution(); } + componentDidUpdate() { + if (this.state.follow) { + const maxScroll = document.documentElement.scrollHeight - document.documentElement.clientHeight; + window.scroll(0, maxScroll); + } + }; + enqueue = () => { API.patch(`/api/tasks/${this.props.params.id}/`, {enqueue: true}, (payload, error) => { this.setState({task: payload, error}); @@ -52,6 +59,10 @@ export default class TaskDetail extends React.Component { }); }; + toggleFollow = () => { + this.setState({follow: !this.state.follow}); + }; + renderMessages() { return this.state.task.messages.map((message) => ( {message.queue} @@ -72,41 +83,50 @@ export default class TaskDetail extends React.Component { return
No executions
} const execution = this.state.task.executions[this.state.execution - 1]; + const canTerminate = execution.status === 'running'; return ( -
-
Execution
-
- -
-
Status
-
{execution.status}
-
Worker
-
- - {execution.worker.name} - -
-
Start Time
-
{formatDateTime(execution.start_timestamp)}
-
Stop Time
-
{formatDateTime(execution.stop_timestamp)}
-
Exit Code
-
{execution.exit_code}
-
Standard Output
-
-
{execution.stdout}
-
-
Standard Error
-
-
{execution.stderr}
-
-
+
+
+
Execution
+
+ +
+
Status
+
{execution.status}
+
Worker
+
+ + {execution.worker.name} + +
+
Start Time
+
{formatDateTime(execution.start_timestamp)}
+
Stop Time
+
{formatDateTime(execution.stop_timestamp)}
+
Exit Code
+
{execution.exit_code}
+
Standard Output
+
+
{execution.stdout}
+
+
Standard Error
+
+
{execution.stderr}
+
+
+ + + + +
) } @@ -122,6 +142,7 @@ export default class TaskDetail extends React.Component { const task = this.state.task; return (
+ {this.state.error && {this.state.error}}
@@ -148,7 +169,6 @@ export default class TaskDetail extends React.Component { {this.renderExecution()} -
diff --git a/frontend/src/WorkflowDetailHistory.js b/frontend/src/WorkflowDetailHistory.js index 8d5fe38..696318c 100644 --- a/frontend/src/WorkflowDetailHistory.js +++ b/frontend/src/WorkflowDetailHistory.js @@ -130,6 +130,7 @@ export default class WorkflowDetailHistory extends React.Component { } else { return (
+ {this.state.error && {this.state.error}} diff --git a/frontend/src/tests/TaskDetail.test.js b/frontend/src/tests/TaskDetail.test.js index a976d51..fcd9fd1 100644 --- a/frontend/src/tests/TaskDetail.test.js +++ b/frontend/src/tests/TaskDetail.test.js @@ -51,3 +51,12 @@ it('TaskDetail success', () => { let tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); + +it('TaskDetail scrolling', () => { + mockAPI(); + const component = ReactTestRenderer.create(); + window.scroll = jest.fn(); + const instance = component.getInstance(); + instance.toggleFollow(); + expect(window.scroll).toBeCalled(); +}); diff --git a/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap b/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap index 1f893db..60f9b56 100644 --- a/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap +++ b/frontend/src/tests/__snapshots__/TaskDetail.test.js.snap @@ -111,89 +111,104 @@ exports[`TaskDetail success 1`] = `
-
-
- Execution -
-
-
    -
  • +
    +
    + Execution +
    +
    + -
    -
    - Status -
    -
    - succeeded -
    -
    - Worker -
    -
    - + 1 + +
  • +
+
+
+ Status +
+
+ succeeded +
+
+ Worker +
+
+ + graybeard.local 35405 + +
+
+ Start Time +
+
+ January 30th 2017, 3:26:38 am +
+
+ Stop Time +
+
+ +
+
+ Exit Code +
+
+
+ Standard Output +
+
+
+                Starting...
+                
+              
+
+
+ Standard Error +
+
+
+                
+              
+
+
+
+ + Terminate + + +
+