Skip to content

Commit a88b0ed

Browse files
Gutenberg: Make UI more intuitive when a chart is missing
1 parent 703aeb0 commit a88b0ed

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

classes/Visualizer/Gutenberg/build/block.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/src/Editor.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,20 @@ class Editor extends Component {
7878

7979
// Fetch review again if block loaded after saving.
8080
if ( this.props.attributes.id ) {
81-
let result = await apiFetch({ path: `wp/v2/visualizer/${this.props.attributes.id}` });
82-
83-
this.setState({
84-
chart: result['chart_data']
85-
});
81+
let result = await apiFetch({ path: `wp/v2/visualizer/${this.props.attributes.id}` }).catch( function( error ) {
82+
});
83+
84+
if ( result ) {
85+
this.setState({
86+
chart: result['chart_data']
87+
});
88+
} else {
89+
90+
// if the chart is not found.
91+
this.setState({
92+
route: 'error'
93+
});
94+
}
8695
}
8796
}
8897

@@ -92,6 +101,7 @@ class Editor extends Component {
92101
});
93102

94103
let result = await apiFetch({ path: `wp/v2/visualizer/${id}` });
104+
console.log( 'getChart', id, result );
95105

96106
this.setState({
97107
route: 'chartSelect',
@@ -297,6 +307,7 @@ class Editor extends Component {
297307
});
298308

299309
let result = await apiFetch({ path: `wp/v2/visualizer/${id}` });
310+
console.log( 'getChartData', id, result );
300311

301312
let chart = { ...this.state.chart };
302313

@@ -406,6 +417,17 @@ class Editor extends Component {
406417
}
407418

408419
render() {
420+
if ( 'error' === this.state.route ) {
421+
return (
422+
<div className="visualizer-settings visualizer-error">
423+
<div className="visualizer-settings__title">
424+
<Dashicon icon="chart-pie" />
425+
{ __( 'This chart is not available; it might have been deleted. Please delete this block and resubmit your chart.' ) }
426+
</div>
427+
</div>
428+
);
429+
}
430+
409431
if ( 'renderChart' === this.state.route && null !== this.state.chart ) {
410432
return (
411433
<ChartRender

0 commit comments

Comments
 (0)