import {Component} from 'react'; import {Client} from 'sentry/api'; import MiniBarChart from 'sentry/components/charts/miniBarChart'; import LoadingError from 'sentry/components/loadingError'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import withApi from 'sentry/utils/withApi'; type Props = { api: Client; label: string; resolution: string; since: number; stat: string; height?: number; }; type State = { data: [number, number][] | null; error: boolean; loading: boolean; }; class InternalStatChart extends Component { state: State = { error: false, loading: true, data: null, }; componentDidMount() { this.fetchData(); } shouldComponentUpdate(_nextProps: Props, nextState: State) { return this.state.loading !== nextState.loading; } componentDidUpdate(prevProps: Props) { if ( prevProps.since !== this.props.since || prevProps.stat !== this.props.stat || prevProps.resolution !== this.props.resolution ) { this.fetchData(); } } fetchData = () => { this.setState({loading: true}); this.props.api.request('/internal/stats/', { method: 'GET', data: { since: this.props.since, resolution: this.props.resolution, key: this.props.stat, }, success: data => this.setState({ data, loading: false, error: false, }), error: () => this.setState({error: true, loading: false}), }); }; render() { const {loading, error, data} = this.state; const {label, height} = this.props; if (loading) { return ; } if (error) { return ; } const series = { seriesName: label, data: data?.map(([timestamp, value]) => ({ name: timestamp * 1000, value, })) ?? [], }; return ( ); } } export default withApi(InternalStatChart);