mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
More TypeScript conversions
Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
583b89a005
commit
50c0bb0112
|
@ -1,6 +1,9 @@
|
|||
import React, { Component } from 'react';
|
||||
import React, { Component, ReactNode } from 'react';
|
||||
|
||||
import { Container } from 'reactstrap';
|
||||
|
||||
import PanelList from './PanelList';
|
||||
|
||||
import './App.css';
|
||||
|
||||
class App extends Component {
|
|
@ -47,7 +47,7 @@ class DataTable extends PureComponent<QueryResult> {
|
|||
return series;
|
||||
}
|
||||
|
||||
render(): ReactNode {
|
||||
render() {
|
||||
const data = this.props.data;
|
||||
|
||||
if (data === null) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class ExpressionInput extends Component {
|
|||
return null;
|
||||
}
|
||||
|
||||
let matches = fuzzy.filter(downshift.inputValue.replace(/ /g, ''), this.props.metrics, {
|
||||
let matches = fuzzy.filter(downshift.inputValue.replace(/ /g, ''), this.props.metricNames, {
|
||||
pre: "<strong>",
|
||||
post: "</strong>",
|
||||
});
|
||||
|
|
|
@ -211,7 +211,7 @@ class Panel extends Component {
|
|||
onChange={this.handleExpressionChange}
|
||||
executeQuery={this.executeQuery}
|
||||
loading={this.state.loading}
|
||||
metrics={this.props.metrics}
|
||||
metricNames={this.props.metricNames}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
|
|
@ -4,19 +4,29 @@ import { Alert, Button, Col, Row } from 'reactstrap';
|
|||
|
||||
import Panel from './Panel';
|
||||
|
||||
class PanelList extends Component {
|
||||
constructor(props) {
|
||||
interface PanelListState {
|
||||
panels: {
|
||||
key: string,
|
||||
}[],
|
||||
metricNames: string[],
|
||||
fetchMetricsError: string | null,
|
||||
timeDriftError: string | null,
|
||||
}
|
||||
|
||||
class PanelList extends Component<any, PanelListState> {
|
||||
key: number;
|
||||
|
||||
constructor(props: []) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
panels: [],
|
||||
metrics: [],
|
||||
metricNames: [],
|
||||
fetchMetricsError: null,
|
||||
timeDriftError: null,
|
||||
};
|
||||
this.key = 0;
|
||||
|
||||
this.addPanel = this.addPanel.bind(this);
|
||||
this.removePanel = this.removePanel.bind(this);
|
||||
this.key = 0;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -30,7 +40,7 @@ class PanelList extends Component {
|
|||
throw new Error('Unexpected response status when fetching metric names: ' + resp.statusText); // TODO extract error
|
||||
}
|
||||
})
|
||||
.then(json => this.setState({ metrics: json.data }))
|
||||
.then(json => this.setState({ metricNames: json.data }))
|
||||
.catch(error => this.setState({ fetchMetricsError: error.message }));
|
||||
|
||||
const browserTime = new Date().getTime() / 1000;
|
||||
|
@ -53,18 +63,18 @@ class PanelList extends Component {
|
|||
.catch(error => this.setState({ timeDriftError: error.message }));
|
||||
}
|
||||
|
||||
getKey() {
|
||||
getKey(): string {
|
||||
return (this.key++).toString();
|
||||
}
|
||||
|
||||
addPanel() {
|
||||
addPanel = (): void => {
|
||||
const panels = this.state.panels.slice();
|
||||
const key = this.getKey();
|
||||
panels.push({key: key});
|
||||
this.setState({panels: panels});
|
||||
}
|
||||
|
||||
removePanel(key) {
|
||||
removePanel = (key: string): void => {
|
||||
const panels = this.state.panels.filter(panel => {
|
||||
return panel.key !== key;
|
||||
});
|
||||
|
@ -85,7 +95,7 @@ class PanelList extends Component {
|
|||
</Col>
|
||||
</Row>
|
||||
{this.state.panels.map(p =>
|
||||
<Panel key={p.key} removePanel={() => this.removePanel(p.key)} metrics={this.state.metrics}/>
|
||||
<Panel key={p.key} removePanel={() => this.removePanel(p.key)} metricNames={this.state.metricNames}/>
|
||||
)}
|
||||
<Button color="primary" className="add-panel-btn" onClick={this.addPanel}>Add Panel</Button>
|
||||
</>
|
1
src/react-app-env.d.ts
vendored
Normal file
1
src/react-app-env.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/// <reference types="react-scripts" />
|
Loading…
Reference in a new issue