-
Notifications
You must be signed in to change notification settings - Fork 74
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
Dashboard for ArangoLocalStorage operator #213
Changes from 11 commits
44cec70
95643d3
14ba8c5
f5caa22
6a2dba8
2710416
415563d
8bdea37
55d2bb6
60dd852
995975f
eaa1f19
581f316
8369d6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ docs | |
pkg | ||
tools | ||
deps | ||
|
||
dashboard |
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import React, { Component } from 'react'; | ||
import ReactTimeout from 'react-timeout'; | ||
import DeploymentOperator from './deployment/DeploymentOperator.js'; | ||
import StorageOperator from './storage/StorageOperator.js'; | ||
import NoOperator from './NoOperator.js'; | ||
import Loading from './util/Loading.js'; | ||
import api from './api/api.js'; | ||
import api, { IsUnauthorized } from './api/api.js'; | ||
import { Container, Segment, Message } from 'semantic-ui-react'; | ||
import './App.css'; | ||
import { withAuth } from './auth/Auth.js'; | ||
|
||
const PodInfoView = ({pod, namespace}) => ( | ||
<Segment basic> | ||
|
@@ -16,11 +17,14 @@ const PodInfoView = ({pod, namespace}) => ( | |
</Segment> | ||
); | ||
|
||
const OperatorsView = ({error, deployment, pod, namespace}) => { | ||
const OperatorsView = ({error, deployment, storage, pod, namespace}) => { | ||
const podInfoView = (<PodInfoView pod={pod} namespace={namespace}/>); | ||
if (deployment) { | ||
return (<DeploymentOperator podInfoView={podInfoView} error={error}/>); | ||
} | ||
if (storage) { | ||
return (<StorageOperator podInfoView={podInfoView} error={error}/>); | ||
} | ||
return (<NoOperator podInfoView={podInfoView} error={error}/>); | ||
} | ||
|
||
|
@@ -43,24 +47,33 @@ class App extends Component { | |
reloadOperators = async() => { | ||
try { | ||
const operators = await api.get('/api/operators'); | ||
this.setState({operators, error: undefined}); | ||
this.setState({ | ||
operators, | ||
error: undefined | ||
}); | ||
} catch (e) { | ||
this.setState({error: e.message}); | ||
this.setState({ | ||
error: e.message | ||
}); | ||
if (IsUnauthorized(e)) { | ||
this.props.doLogout(); | ||
} | ||
} | ||
this.props.setTimeout(this.reloadOperators, 10000); | ||
} | ||
|
||
render() { | ||
if (this.state.operators) { | ||
return <OperatorsView | ||
return <OperatorsView | ||
error={this.state.error} | ||
deployment={this.state.operators.deployment} | ||
pod={this.state.operators.pod} | ||
namespace={this.state.operators.namespace} | ||
/>; | ||
deployment={this.state.operators.deployment} | ||
storage={this.state.operators.storage} | ||
pod={this.state.operators.pod} | ||
namespace={this.state.operators.namespace} | ||
/>; | ||
} | ||
return (<LoadingView/>); | ||
} | ||
} | ||
|
||
export default ReactTimeout(App); | ||
export default ReactTimeout(withAuth(App)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this is why HOCs have been losing some traction to render props recently: you're now injecting props from two places. This is probably fine for the time being but it can get a bit confusing as the complexity grows. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import React, { Component } from 'react'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
import { Message } from 'semantic-ui-react'; | ||
import { Container, Message, Modal, Segment } from 'semantic-ui-react'; | ||
|
||
class NoOperator extends Component { | ||
render() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<h1 className="App-title">Welcome to Kube-ArangoDB</h1> | ||
</header> | ||
<p className="App-intro"> | ||
There are no operators available yet. | ||
</p> | ||
{this.props.podInfoView} | ||
{(this.props.error) ? <Message error content={this.props.error}/> : null} | ||
</div> | ||
<Container> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Minor nitpick: no point in using a class component here, you could just make it a function. |
||
<Modal open> | ||
<Modal.Header>Welcome to Kube-ArangoDB</Modal.Header> | ||
<Modal.Content> | ||
<Segment basic> | ||
<Message color="orange"> | ||
There are no operators available yet. | ||
</Message> | ||
</Segment> | ||
{this.props.podInfoView} | ||
{(this.props.error) ? <Message error content={this.props.error}/> : null} | ||
</Modal.Content> | ||
</Modal> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
export function IsUnauthorized(e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI in most JS styles only classes and components use leading uppercase. So this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
return (e.status === 401); | ||
} | ||
|
||
export default { | ||
token: '', | ||
|
||
async decodeResults(result) { | ||
const decoded = await result.json(); | ||
if (result.status === 401) { | ||
throw Error(decoded.error || "Unauthorized") | ||
} | ||
if (result.status !== 200) { | ||
throw Error(`Unexpected status ${result.status}`); | ||
let message = decoded.error; | ||
if (!message) { | ||
if (result.status === 401) { | ||
message = "Unauthorized"; | ||
} else { | ||
message = `Unexpected status ${result.status}`; | ||
} | ||
} | ||
throw Object.assign(new Error(message), { status: result.status }); | ||
} | ||
return decoded; | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React, { Component } from 'react'; | ||
import { Button, Container, Form, Icon, Message, Modal } from 'semantic-ui-react'; | ||
import { css } from 'react-emotion'; | ||
|
||
const LoginView = ({username, password, onUsernameChanged, onPasswordChanged, doLogin, error}) => ( | ||
<Container> | ||
|
@@ -12,6 +13,7 @@ const LoginView = ({username, password, onUsernameChanged, onPasswordChanged, do | |
<label>Password</label> | ||
<input type="password" value={password} onChange={(e) => onPasswordChanged(e.target.value)}/> | ||
</Form.Field> | ||
<Form.Button className={css`display:none`} type="submit" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason you have a hidden submit button here? Pressing enter in the input field should already trigger the form submit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also curious why you're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hidden button was out of need. I expected it to work without, but it did not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like |
||
</Form> | ||
{(error) ? <Message error content={error}/> : null} | ||
</Container> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to avoid repeating yourself a bit, you could do something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed