mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-05 05:37:10 +02:00
* Initial commit from Create React App Signed-off-by: Julius Volz <julius.volz@gmail.com> * Initial Prometheus expression browser code Signed-off-by: Julius Volz <julius.volz@gmail.com> * Grpahing, try out echarts Signed-off-by: Julius Volz <julius.volz@gmail.com> * Switch to flot Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add metrics fetching and stuff Signed-off-by: Julius Volz <julius.volz@gmail.com> * Autosuggest and graph improvements Signed-off-by: Julius Volz <julius.volz@gmail.com> * Start implementing graph controls, add loading spinner Signed-off-by: Julius Volz <julius.volz@gmail.com> * So many new features and fixes Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fixed and built more features Signed-off-by: Julius Volz <julius.volz@gmail.com> * Make datetimepicker clear work Signed-off-by: Julius Volz <julius.volz@gmail.com> * Don't abort when executing empty expression Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove TabPaneAlert Signed-off-by: Julius Volz <julius.volz@gmail.com> * Split components into separate files Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add table time input Signed-off-by: Julius Volz <julius.volz@gmail.com> * Move first files to TypeScript! Signed-off-by: Julius Volz <julius.volz@gmail.com> * More TypeScript conversions Signed-off-by: Julius Volz <julius.volz@gmail.com> * More TS conversions Signed-off-by: Julius Volz <julius.volz@gmail.com> * More TS conversions Signed-off-by: Julius Volz <julius.volz@gmail.com> * More TS conversions Signed-off-by: Julius Volz <julius.volz@gmail.com> * More TS conversions Signed-off-by: Julius Volz <julius.volz@gmail.com> * More TS fixes Signed-off-by: Julius Volz <julius.volz@gmail.com> * Convert Graph to TS Signed-off-by: Julius Volz <julius.volz@gmail.com> * Changes Signed-off-by: Julius Volz <julius.volz@gmail.com> * Resize detector, start building legend, axis font colors Signed-off-by: Julius Volz <julius.volz@gmail.com> * Make graph legend work Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add URL params support and much more Signed-off-by: Julius Volz <julius.volz@gmail.com> * Put panel state into panel list, write URL options Signed-off-by: Julius Volz <julius.volz@gmail.com> * Change order of Graph and Table tabs Signed-off-by: Julius Volz <julius.volz@gmail.com> * Generalize time input naming more Signed-off-by: Julius Volz <julius.volz@gmail.com> * Work on history functionality Signed-off-by: Julius Volz <julius.volz@gmail.com> * npm updates Signed-off-by: Julius Volz <julius.volz@gmail.com> * Move loading indicator into "Execute" button Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix typo Signed-off-by: Julius Volz <julius.volz@gmail.com> * Revert "Move loading indicator into "Execute" button" This reverts commit ce7daee1f1af35da6c0d8b5517272839285ccfec. Signed-off-by: Julius Volz <julius.volz@gmail.com> * Improve error message when failing to fetch server time Signed-off-by: Julius Volz <julius.volz@gmail.com> * Move all code to Prometheus repo target dir Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add react-app Makefile step and check in generated assets Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add preliminary npm packages notice to NOTICE file Signed-off-by: Julius Volz <julius.volz@gmail.com> * Update React app's favicon and metadata Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove RP server refs, cleanups Signed-off-by: Julius Volz <julius.volz@gmail.com> * Use CircleCI image that includes NodeJS Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add some missing React output assets Signed-off-by: Julius Volz <julius.volz@gmail.com> * Preserve CRLF in generated React files Signed-off-by: Julius Volz <julius.volz@gmail.com> * Switch from npm to yarn for React UI Signed-off-by: Julius Volz <julius.volz@gmail.com> * Save npm licenses and include them in release tarball Signed-off-by: Julius Volz <julius.volz@gmail.com> * Install npm on Travis Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove npm license tarball from source Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove React graph bundle from source Signed-off-by: Julius Volz <julius.volz@gmail.com> * Don't check in any compiled web assets Signed-off-by: Julius Volz <julius.volz@gmail.com> * Update README.md with node/yarn/React UI info Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix asset build step on CircleCI promu crossbuild Signed-off-by: Julius Volz <julius.volz@gmail.com> * Try to fix multi-arch go generate Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove check_assets from Travis CI build Signed-off-by: Julius Volz <julius.volz@gmail.com> * Prevent rebuilding of unchanged React app parts Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix npm license tarball path for promu Signed-off-by: Julius Volz <julius.volz@gmail.com> * Simplify Makefile Signed-off-by: Julius Volz <julius.volz@gmail.com> * Clarify build instructions in README.md Signed-off-by: Julius Volz <julius.volz@gmail.com> * Make minimal JS test pass Signed-off-by: Julius Volz <julius.volz@gmail.com> * Integrate React app tests into Makefile Signed-off-by: Julius Volz <julius.volz@gmail.com> * Separate react-app-tests target, but run it from CI Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix working directory for React app tests Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove local modifications to Makefile.common This means that CircleCI will not run the React app tests, but at least Travis still will... Signed-off-by: Julius Volz <julius.volz@gmail.com> * Depend on node_modules path for npm_licenses target Signed-off-by: Julius Volz <julius.volz@gmail.com> * Simplify tarball/docker/build Makefile targets Signed-off-by: Julius Volz <julius.volz@gmail.com> * Include React tests in "test" target Signed-off-by: Julius Volz <julius.volz@gmail.com> * Remove reference to removed "check_assets" target Signed-off-by: Julius Volz <julius.volz@gmail.com> * Do initial resize of expression input field Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add React app proxying to local Prometheus in dev mode Signed-off-by: Julius Volz <julius.volz@gmail.com>
131 lines
3.6 KiB
TypeScript
131 lines
3.6 KiB
TypeScript
import $ from 'jquery';
|
|
import React, { Component } from 'react';
|
|
import { Button, InputGroup, InputGroupAddon, Input } from 'reactstrap';
|
|
|
|
import moment from 'moment-timezone';
|
|
|
|
import 'tempusdominus-core';
|
|
import 'tempusdominus-bootstrap-4';
|
|
import '../node_modules/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.min.css';
|
|
|
|
import { dom, library } from '@fortawesome/fontawesome-svg-core';
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
import {
|
|
faChevronLeft,
|
|
faChevronRight,
|
|
faCalendarCheck,
|
|
faArrowUp,
|
|
faArrowDown,
|
|
faTimes,
|
|
} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
library.add(
|
|
faChevronLeft,
|
|
faChevronRight,
|
|
faCalendarCheck,
|
|
faArrowUp,
|
|
faArrowDown,
|
|
faTimes,
|
|
);
|
|
|
|
// Sadly needed to also replace <i> within the date picker, since it's not a React component.
|
|
dom.watch();
|
|
|
|
interface TimeInputProps {
|
|
time: number | null; // Timestamp in milliseconds.
|
|
range: number; // Range in seconds.
|
|
placeholder: string;
|
|
|
|
onChangeTime: (time: number | null) => void;
|
|
}
|
|
|
|
class TimeInput extends Component<TimeInputProps> {
|
|
private timeInputRef = React.createRef<HTMLInputElement>();
|
|
private $time: any | null = null;
|
|
|
|
getBaseTime = (): number => {
|
|
return this.props.time || moment().valueOf();
|
|
}
|
|
|
|
increaseTime = (): void => {
|
|
const time = this.getBaseTime() + this.props.range*1000/2;
|
|
this.props.onChangeTime(time);
|
|
}
|
|
|
|
decreaseTime = (): void => {
|
|
const time = this.getBaseTime() - this.props.range*1000/2;
|
|
this.props.onChangeTime(time);
|
|
}
|
|
|
|
clearTime = (): void => {
|
|
this.props.onChangeTime(null);
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.$time = $(this.timeInputRef.current!);
|
|
|
|
this.$time.datetimepicker({
|
|
icons: {
|
|
today: 'fas fa-calendar-check',
|
|
},
|
|
buttons: {
|
|
//showClear: true,
|
|
showClose: true,
|
|
showToday: true,
|
|
},
|
|
sideBySide: true,
|
|
format: 'YYYY-MM-DD HH:mm',
|
|
locale: 'en',
|
|
timeZone: 'UTC',
|
|
defaultDate: this.props.time,
|
|
});
|
|
|
|
this.$time.on('change.datetimepicker', (e: any) => {
|
|
if (e.date) {
|
|
this.props.onChangeTime(e.date.valueOf());
|
|
}
|
|
});
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.$time.datetimepicker('destroy');
|
|
}
|
|
|
|
componentDidUpdate() {
|
|
console.log(this.props);
|
|
this.$time.datetimepicker('date', this.props.time ? moment(this.props.time) : null);
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<InputGroup className="time-input" size="sm">
|
|
<InputGroupAddon addonType="prepend">
|
|
<Button title="Decrease time" onClick={this.decreaseTime}><FontAwesomeIcon icon="chevron-left" fixedWidth/></Button>
|
|
</InputGroupAddon>
|
|
|
|
<Input
|
|
placeholder={this.props.placeholder}
|
|
innerRef={this.timeInputRef}
|
|
onFocus={() => this.$time.datetimepicker('show')}
|
|
onBlur={() => this.$time.datetimepicker('hide')}
|
|
onKeyDown={(e) => ['Escape', 'Enter'].includes(e.key) && this.$time.datetimepicker('hide')}
|
|
/>
|
|
|
|
{/* CAUTION: While the datetimepicker also has an option to show a 'clear' button,
|
|
that functionality is broken, so we create an external solution instead. */}
|
|
{this.props.time &&
|
|
<InputGroupAddon addonType="append">
|
|
<Button className="clear-time-btn" title="Clear time" onClick={this.clearTime}><FontAwesomeIcon icon="times" fixedWidth/></Button>
|
|
</InputGroupAddon>
|
|
}
|
|
|
|
<InputGroupAddon addonType="append">
|
|
<Button title="Increase time" onClick={this.increaseTime}><FontAwesomeIcon icon="chevron-right" fixedWidth/></Button>
|
|
</InputGroupAddon>
|
|
</InputGroup>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default TimeInput;
|