Skip to content

Commit

Permalink
pin scroll and show errors (#47)
Browse files Browse the repository at this point in the history
* show error message when not logged in

* pin scroll on task log
  • Loading branch information
aclowes authored Jul 29, 2018
1 parent ef697df commit 888f3a7
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 116 deletions.
94 changes: 57 additions & 37 deletions frontend/src/TaskDetail.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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});
Expand Down Expand Up @@ -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) => (
<span><Link to='/queues/' key={message.id}>{message.queue}</Link> </span>
Expand All @@ -72,41 +83,50 @@ export default class TaskDetail extends React.Component {
return <div>No executions</div>
}
const execution = this.state.task.executions[this.state.execution - 1];
const canTerminate = execution.status === 'running';
return (
<dl className="dl-horizontal">
<dt>Execution</dt>
<dd>
<Pagination
ellipsis
bsSize="small"
items={this.state.task.executions.length}
maxButtons={10}
activePage={this.state.execution}
onSelect={this.selectExecution}/>
</dd>
<dt>Status</dt>
<dd>{execution.status}</dd>
<dt>Worker</dt>
<dd>
<Link to={`/workers/${execution.worker.id}`}>
{execution.worker.name}
</Link>
</dd>
<dt>Start Time</dt>
<dd>{formatDateTime(execution.start_timestamp)}</dd>
<dt>Stop Time</dt>
<dd>{formatDateTime(execution.stop_timestamp)}</dd>
<dt>Exit Code</dt>
<dd>{execution.exit_code}</dd>
<dt>Standard Output</dt>
<dd>
<pre>{execution.stdout}</pre>
</dd>
<dt>Standard Error</dt>
<dd>
<pre>{execution.stderr}</pre>
</dd>
</dl>
<div>
<dl className="dl-horizontal">
<dt>Execution</dt>
<dd>
<Pagination
ellipsis
bsSize="small"
items={this.state.task.executions.length}
maxButtons={10}
activePage={this.state.execution}
onSelect={this.selectExecution}/>
</dd>
<dt>Status</dt>
<dd>{execution.status}</dd>
<dt>Worker</dt>
<dd>
<Link to={`/workers/${execution.worker.id}`}>
{execution.worker.name}
</Link>
</dd>
<dt>Start Time</dt>
<dd>{formatDateTime(execution.start_timestamp)}</dd>
<dt>Stop Time</dt>
<dd>{formatDateTime(execution.stop_timestamp)}</dd>
<dt>Exit Code</dt>
<dd>{execution.exit_code}</dd>
<dt>Standard Output</dt>
<dd>
<pre>{execution.stdout}</pre>
</dd>
<dt>Standard Error</dt>
<dd>
<pre>{execution.stderr}</pre>
</dd>
</dl>
<ButtonToolbar>
<Button onClick={this.terminate} disabled={!canTerminate} bsStyle="danger">Terminate</Button>
<Button onClick={this.toggleFollow}>
{this.state.follow ? 'Unpin scroll' : 'Pin scroll'}
</Button>
</ButtonToolbar>
</div>
)
}

Expand All @@ -122,6 +142,7 @@ export default class TaskDetail extends React.Component {
const task = this.state.task;
return (
<div>
{this.state.error && <Alert bsStyle="danger">{this.state.error}</Alert>}
<PanelGroup>
<Panel header="Details">
<dl className="dl-horizontal">
Expand All @@ -148,7 +169,6 @@ export default class TaskDetail extends React.Component {
</Panel>
<Panel header="Executions">
{this.renderExecution()}
<Button onClick={this.terminate}>Terminate</Button>
</Panel>
</PanelGroup>
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/WorkflowDetailHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export default class WorkflowDetailHistory extends React.Component {
} else {
return (
<div>
{this.state.error && <Alert bsStyle="danger">{this.state.error}</Alert>}
<Table bordered condensed>
<thead>
<tr>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/tests/TaskDetail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ it('TaskDetail success', () => {
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});

it('TaskDetail scrolling', () => {
mockAPI();
const component = ReactTestRenderer.create(<TaskDetail params={{id: 1}}/>);
window.scroll = jest.fn();
const instance = component.getInstance();
instance.toggleFollow();
expect(window.scroll).toBeCalled();
});
173 changes: 94 additions & 79 deletions frontend/src/tests/__snapshots__/TaskDetail.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,89 +111,104 @@ exports[`TaskDetail success 1`] = `
<div
className="panel-body"
>
<dl
className="dl-horizontal"
>
<dt>
Execution
</dt>
<dd>
<ul
className="pagination pagination-sm"
>
<li
className="active"
style={undefined}
<div>
<dl
className="dl-horizontal"
>
<dt>
Execution
</dt>
<dd>
<ul
className="pagination pagination-sm"
>
<a
href="#"
onClick={[Function]}
role="button"
<li
className="active"
style={undefined}
>
1
</a>
</li>
</ul>
</dd>
<dt>
Status
</dt>
<dd>
succeeded
</dd>
<dt>
Worker
</dt>
<dd>
<a
<a
href="#"
onClick={[Function]}
role="button"
>
1
</a>
</li>
</ul>
</dd>
<dt>
Status
</dt>
<dd>
succeeded
</dd>
<dt>
Worker
</dt>
<dd>
<a
onClick={[Function]}
style={Object {}}
>
graybeard.local 35405
</a>
</dd>
<dt>
Start Time
</dt>
<dd>
January 30th 2017, 3:26:38 am
</dd>
<dt>
Stop Time
</dt>
<dd>
</dd>
<dt>
Exit Code
</dt>
<dd />
<dt>
Standard Output
</dt>
<dd>
<pre>
Starting...
</pre>
</dd>
<dt>
Standard Error
</dt>
<dd>
<pre>
</pre>
</dd>
</dl>
<div
className="btn-toolbar"
role="toolbar"
>
<button
className="btn btn-danger"
disabled={true}
onClick={[Function]}
style={Object {}}
type="button"
>
graybeard.local 35405
</a>
</dd>
<dt>
Start Time
</dt>
<dd>
January 30th 2017, 3:26:38 am
</dd>
<dt>
Stop Time
</dt>
<dd>
</dd>
<dt>
Exit Code
</dt>
<dd />
<dt>
Standard Output
</dt>
<dd>
<pre>
Starting...
</pre>
</dd>
<dt>
Standard Error
</dt>
<dd>
<pre>
</pre>
</dd>
</dl>
<button
className="btn btn-default"
disabled={false}
onClick={[Function]}
type="button"
>
Terminate
</button>
Terminate
</button>
<button
className="btn btn-default"
disabled={false}
onClick={[Function]}
type="button"
>
Pin scroll
</button>
</div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 888f3a7

Please sign in to comment.