/** * External dependencies */ import { Chart } from 'react-google-charts'; import DataTable from './DataTable.js'; import { formatDate, filterCharts, formatData, googleChartPackages } from '../utils.js'; /** * WordPress dependencies */ const { startCase } = lodash; const { __ } = wp.i18n; const { apiFetch } = wp; const { Component, Fragment } = wp.element; const { Button, Dashicon, ExternalLink, Notice, Placeholder, Spinner } = wp.components; class Charts extends Component { constructor() { super( ...arguments ); this.loadMoreCharts = this.loadMoreCharts.bind( this ); this.state = { charts: null, isBusy: false, chartsLoaded: false, perPage: visualizerLocalize.chartsPerPage }; } async componentDidMount() { const perPage = visualizerLocalize.chartsPerPage; // Fetch review again if block loaded after saving. let result = await apiFetch({ path: 'wp/v2/visualizer/?per_page=' + perPage + '&meta_key=visualizer-chart-library&meta_value=ChartJS' }); this.setState({ charts: result }); } async loadMoreCharts() { const offset = ( this.state.charts ).length; let chartsLoaded = this.state.chartsLoaded; const perPage = this.state.perPage; this.setState({ isBusy: true }); let result = await apiFetch({ path: `wp/v2/visualizer/?per_page=${ perPage }&meta_key=visualizer-chart-library&meta_value=ChartJS&offset=${ offset }` }); if ( perPage > result.length ) { chartsLoaded = true; } this.setState({ charts: this.state.charts.concat( result ), isBusy: false, chartsLoaded }); } render() { let chartVersion = 'undefined' !== typeof google ? google.visualization.Version : 'current'; const { charts, isBusy, chartsLoaded, perPage } = this.state; return (
{ __( 'No charts found.' ) }
: