mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Generalize time input naming more
Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
parent
0901f48e82
commit
f3b9fd5989
|
@ -87,11 +87,11 @@ button.execute-btn {
|
||||||
width: 50px;
|
width: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.graph-controls .endtime-input input {
|
.graph-controls .time-input input {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.endtime-input {
|
div.time-input {
|
||||||
width: 240px !important;
|
width: 240px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,11 +103,11 @@ div.endtime-input {
|
||||||
width: 90px;
|
width: 90px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.graph-controls .endtime-input, .graph-controls .resolution-input, .graph-controls .stacked-input {
|
.graph-controls .time-input, .graph-controls .resolution-input, .graph-controls .stacked-input {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.graph-controls .clear-endtime-btn {
|
.graph-controls .clear-time-btn {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-left: none;
|
border-left: none;
|
||||||
border-top: 1px solid #ced4da;
|
border-top: 1px solid #ced4da;
|
||||||
|
|
|
@ -116,7 +116,12 @@ class GraphControls extends Component<GraphControlsProps> {
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
|
|
||||||
<TimeInput endTime={this.props.endTime} range={this.props.range} onChangeEndTime={this.props.onChangeEndTime} />
|
<TimeInput
|
||||||
|
time={this.props.endTime}
|
||||||
|
range={this.props.range}
|
||||||
|
placeholder="End time"
|
||||||
|
onChangeTime={this.props.onChangeEndTime}
|
||||||
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
placeholder="Res. (s)"
|
placeholder="Res. (s)"
|
||||||
|
|
|
@ -256,7 +256,12 @@ class Panel extends Component<PanelProps, PanelState> {
|
||||||
{this.props.options.type === 'table' &&
|
{this.props.options.type === 'table' &&
|
||||||
<>
|
<>
|
||||||
<div className="table-controls">
|
<div className="table-controls">
|
||||||
<TimeInput endTime={this.props.options.endTime} range={this.props.options.range} onChangeEndTime={this.handleChangeEndTime} />
|
<TimeInput
|
||||||
|
time={this.props.options.endTime}
|
||||||
|
range={this.props.options.range}
|
||||||
|
placeholder="Evaluation time"
|
||||||
|
onChangeTime={this.handleChangeEndTime}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<DataTable data={this.state.data} />
|
<DataTable data={this.state.data} />
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -32,41 +32,42 @@ library.add(
|
||||||
dom.watch();
|
dom.watch();
|
||||||
|
|
||||||
interface TimeInputProps {
|
interface TimeInputProps {
|
||||||
endTime: number | null;
|
time: number | null; // Timestamp in milliseconds.
|
||||||
range: number;
|
range: number; // Range in seconds.
|
||||||
|
placeholder: string;
|
||||||
|
|
||||||
onChangeEndTime: (endTime: number | null) => void;
|
onChangeTime: (time: number | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TimeInput extends Component<TimeInputProps> {
|
class TimeInput extends Component<TimeInputProps> {
|
||||||
private endTimeRef = React.createRef<HTMLInputElement>();
|
private timeInputRef = React.createRef<HTMLInputElement>();
|
||||||
private $endTime: any | null = null;
|
private $time: any | null = null;
|
||||||
|
|
||||||
getBaseEndTime = (): number => {
|
getBaseTime = (): number => {
|
||||||
return this.props.endTime || moment().valueOf();
|
return this.props.time || moment().valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
increaseEndTime = (): void => {
|
increaseTime = (): void => {
|
||||||
const endTime = this.getBaseEndTime() + this.props.range*1000/2;
|
const time = this.getBaseTime() + this.props.range*1000/2;
|
||||||
this.props.onChangeEndTime(endTime);
|
this.props.onChangeTime(time);
|
||||||
this.$endTime.datetimepicker('date', moment(endTime));
|
this.$time.datetimepicker('date', moment(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
decreaseEndTime = (): void => {
|
decreaseTime = (): void => {
|
||||||
const endTime = this.getBaseEndTime() - this.props.range*1000/2;
|
const time = this.getBaseTime() - this.props.range*1000/2;
|
||||||
this.props.onChangeEndTime(endTime);
|
this.props.onChangeTime(time);
|
||||||
this.$endTime.datetimepicker('date', moment(endTime));
|
this.$time.datetimepicker('date', moment(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
clearEndTime = (): void => {
|
clearTime = (): void => {
|
||||||
this.props.onChangeEndTime(null);
|
this.props.onChangeTime(null);
|
||||||
this.$endTime.datetimepicker('date', null);
|
this.$time.datetimepicker('date', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.$endTime = $(this.endTimeRef.current!);
|
this.$time = $(this.timeInputRef.current!);
|
||||||
|
|
||||||
this.$endTime.datetimepicker({
|
this.$time.datetimepicker({
|
||||||
icons: {
|
icons: {
|
||||||
today: 'fas fa-calendar-check',
|
today: 'fas fa-calendar-check',
|
||||||
},
|
},
|
||||||
|
@ -79,49 +80,47 @@ class TimeInput extends Component<TimeInputProps> {
|
||||||
format: 'YYYY-MM-DD HH:mm',
|
format: 'YYYY-MM-DD HH:mm',
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
timeZone: 'UTC',
|
timeZone: 'UTC',
|
||||||
defaultDate: this.props.endTime,
|
defaultDate: this.props.time,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$endTime.on('change.datetimepicker', (e: any) => {
|
this.$time.on('change.datetimepicker', (e: any) => {
|
||||||
if (e.date) {
|
if (e.date) {
|
||||||
this.props.onChangeEndTime(e.date);
|
this.props.onChangeTime(e.date);
|
||||||
} else {
|
} else {
|
||||||
this.$endTime.datetimepicker('date', e.target.value);
|
this.$time.datetimepicker('date', e.target.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.$endTime.datetimepicker('destroy');
|
this.$time.datetimepicker('destroy');
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<InputGroup className="endtime-input" size="sm">
|
<InputGroup className="time-input" size="sm">
|
||||||
<InputGroupAddon addonType="prepend">
|
<InputGroupAddon addonType="prepend">
|
||||||
<Button title="Decrease end time" onClick={this.decreaseEndTime}><FontAwesomeIcon icon="chevron-left" fixedWidth/></Button>
|
<Button title="Decrease time" onClick={this.decreaseTime}><FontAwesomeIcon icon="chevron-left" fixedWidth/></Button>
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
placeholder="End time"
|
placeholder={this.props.placeholder}
|
||||||
// value={this.props.endTime ? this.props.endTime : ''}
|
innerRef={this.timeInputRef}
|
||||||
innerRef={this.endTimeRef}
|
onFocus={() => this.$time.datetimepicker('show')}
|
||||||
// onChange={this.props.onChangeEndTime}
|
onBlur={() => this.$time.datetimepicker('hide')}
|
||||||
onFocus={() => this.$endTime.datetimepicker('show')}
|
onKeyDown={(e) => ['Escape', 'Enter'].includes(e.key) && this.$time.datetimepicker('hide')}
|
||||||
onBlur={() => this.$endTime.datetimepicker('hide')}
|
|
||||||
onKeyDown={(e) => ['Escape', 'Enter'].includes(e.key) && this.$endTime.datetimepicker('hide')}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* CAUTION: While the datetimepicker also has an option to show a 'clear' button,
|
{/* CAUTION: While the datetimepicker also has an option to show a 'clear' button,
|
||||||
that functionality is broken, so we create an external solution instead. */}
|
that functionality is broken, so we create an external solution instead. */}
|
||||||
{this.props.endTime &&
|
{this.props.time &&
|
||||||
<InputGroupAddon addonType="append">
|
<InputGroupAddon addonType="append">
|
||||||
<Button className="clear-endtime-btn" title="Clear end time" onClick={this.clearEndTime}><FontAwesomeIcon icon="times" fixedWidth/></Button>
|
<Button className="clear-time-btn" title="Clear time" onClick={this.clearTime}><FontAwesomeIcon icon="times" fixedWidth/></Button>
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
}
|
}
|
||||||
|
|
||||||
<InputGroupAddon addonType="append">
|
<InputGroupAddon addonType="append">
|
||||||
<Button title="Increase end time" onClick={this.increaseEndTime}><FontAwesomeIcon icon="chevron-right" fixedWidth/></Button>
|
<Button title="Increase time" onClick={this.increaseTime}><FontAwesomeIcon icon="chevron-right" fixedWidth/></Button>
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue