Skip to content

Commit e7fff71

Browse files
committed
Fix bug with multiple table instances
This makes sure all blocks have different IDs so they don't conflict.
1 parent 9566a9a commit e7fff71

File tree

9 files changed

+34
-114
lines changed

9 files changed

+34
-114
lines changed

classes/Visualizer/Gutenberg/build/block.css

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/build/block.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classes/Visualizer/Gutenberg/build/handsontable.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

classes/Visualizer/Gutenberg/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"merge": "^1.2.1",
1818
"react": "16.4.1",
1919
"react-google-charts": "^3.0.8",
20-
"react-json-editor-ajrm": "^2.5.8"
20+
"react-json-editor-ajrm": "^2.5.8",
21+
"uuid": "^3.3.3"
2122
},
2223
"devDependencies": {
2324
"@babel/core": "^7.1.6",

classes/Visualizer/Gutenberg/src/Components/CreateCharts.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

classes/Visualizer/Gutenberg/src/Components/DataTable.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import uuidv4 from 'uuid';
5+
16
/**
27
* WordPress dependencies
38
*/
@@ -14,6 +19,7 @@ class DataTables extends Component {
1419
this.dataRenderer = this.dataRenderer.bind( this );
1520

1621
this.table;
22+
this.uniqueId = uuidv4();
1723
}
1824

1925
componentDidMount() {
@@ -28,12 +34,12 @@ class DataTables extends Component {
2834
if ( this.props !== prevProps ) {
2935
if ( this.props.options.responsive_bool !== prevProps.options.responsive_bool ) {
3036
if ( 'true' === prevProps.options.responsive_bool ) {
31-
document.getElementById( `dataTable-instances-${ this.props.id }` ).classList.remove( 'collapsed' );
37+
document.getElementById( `dataTable-instances-${ this.props.id }-${ this.uniqueId }` ).classList.remove( 'collapsed' );
3238
}
3339
}
3440

3541
this.table.destroy();
36-
document.getElementById( `dataTable-instances-${ this.props.id }` ).innerHTML = '';
42+
document.getElementById( `dataTable-instances-${ this.props.id }-${ this.uniqueId }` ).innerHTML = '';
3743
this.initDataTable( this.props.columns, this.props.rows );
3844
}
3945
}
@@ -73,7 +79,7 @@ class DataTables extends Component {
7379
return row;
7480
});
7581

76-
this.table = jQuery( `#dataTable-instances-${ this.props.id }` ).DataTable({
82+
this.table = jQuery( `#dataTable-instances-${ this.props.id }-${ this.uniqueId }` ).DataTable({
7783
destroy: true,
7884
data: data,
7985
columns: columns,
@@ -145,24 +151,24 @@ class DataTables extends Component {
145151
{ settings.customcss && (
146152
<style>
147153
{ settings.customcss.oddTableRow && (
148-
`#dataTable-instances-${ this.props.id } tr.odd {
154+
`#dataTable-instances-${ this.props.id }-${ this.uniqueId } tr.odd {
149155
${ settings.customcss.oddTableRow.color ? `color: ${ settings.customcss.oddTableRow.color } !important;` : '' }
150156
${ settings.customcss.oddTableRow['background-color'] ? `background-color: ${ settings.customcss.oddTableRow['background-color'] } !important;` : '' }
151157
${ settings.customcss.oddTableRow.transform ? `transform: rotate( ${ settings.customcss.oddTableRow.transform }deg ) !important;` : '' }
152158
}`
153159
)}
154160

155161
{ settings.customcss.evenTableRow && (
156-
`#dataTable-instances-${ this.props.id } tr.even {
162+
`#dataTable-instances-${ this.props.id }-${ this.uniqueId } tr.even {
157163
${ settings.customcss.evenTableRow.color ? `color: ${ settings.customcss.evenTableRow.color } !important;` : '' }
158164
${ settings.customcss.evenTableRow['background-color'] ? `background-color: ${ settings.customcss.evenTableRow['background-color'] } !important;` : '' }
159165
${ settings.customcss.evenTableRow.transform ? `transform: rotate( ${ settings.customcss.evenTableRow.transform }deg ) !important;` : '' }
160166
}`
161167
)}
162168

163169
{ settings.customcss.tableCell && (
164-
`#dataTable-instances-${ this.props.id } tr td,
165-
#dataTable-instances-${ this.props.id }_wrapper tr th {
170+
`#dataTable-instances-${ this.props.id }-${ this.uniqueId } tr td,
171+
#dataTable-instances-${ this.props.id }-${ this.uniqueId }_wrapper tr th {
166172
${ settings.customcss.tableCell.color ? `color: ${ settings.customcss.tableCell.color } !important;` : '' }
167173
${ settings.customcss.tableCell['background-color'] ? `background-color: ${ settings.customcss.tableCell['background-color'] } !important;` : '' }
168174
${ settings.customcss.tableCell.transform ? `transform: rotate( ${ settings.customcss.tableCell.transform }deg ) !important;` : '' }
@@ -171,7 +177,7 @@ class DataTables extends Component {
171177
</style>
172178
) }
173179

174-
<table id={ `dataTable-instances-${ this.props.id }` }></table>
180+
<table id={ `dataTable-instances-${ this.props.id }-${ this.uniqueId }` }></table>
175181
</Fragment>
176182
);
177183
}

classes/Visualizer/Gutenberg/src/Editor.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/**
22
* External dependencies
33
*/
4-
import CreateCharts from './Components/CreateCharts.js';
5-
64
import Charts from './Components/Charts.js';
75

86
import ChartSelect from './Components/ChartSelect.js';
@@ -56,7 +54,6 @@ class Editor extends Component {
5654
* Block Route Status
5755
*
5856
* home - Initial screen.
59-
* createChart - Option to create new charts.
6057
* showCharts - Display list of charts to pick.
6158
* chartSelect - Chart selected.
6259
* renderChart - Chart render.
@@ -402,8 +399,6 @@ class Editor extends Component {
402399
</Placeholder>
403400
) }
404401

405-
{ ( 'createChart' === this.state.route && false === this.state.isLoading ) && <CreateCharts/> }
406-
407402
{ ( 'showCharts' === this.state.route && false === this.state.isLoading ) && <Charts getChart={ this.getChart }/> }
408403

409404
{ ( 'chartSelect' === this.state.route && null !== this.state.chart ) &&
@@ -425,15 +420,15 @@ class Editor extends Component {
425420

426421
<div className="visualizer-settings__controls">
427422

428-
{ ( 'createChart' === this.state.route || 'showCharts' === this.state.route || 'chartSelect' === this.state.route ) &&
423+
{ ( 'showCharts' === this.state.route || 'chartSelect' === this.state.route ) &&
429424
<ButtonGroup>
430425

431426
<Button
432427
isDefault
433428
isLarge
434429
onClick={ () => {
435430
let route;
436-
if ( 'createChart' === this.state.route || 'showCharts' === this.state.route ) {
431+
if ( 'showCharts' === this.state.route ) {
437432
route = 'home';
438433
} else if ( 'chartSelect' === this.state.route ) {
439434
route = 'showCharts';

classes/Visualizer/Gutenberg/src/style.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@
106106
cursor: pointer;
107107
}
108108
}
109-
110-
.visualizer-settings__create-charts {
111-
display: block;
112-
width: 270px;
113-
height: 205px;
114-
padding: 15px;
115-
border: 1px solid #e0e0e0;
116-
background-color: white;
117-
background-image: url(../../../../images/chart_types_june2019_g.png);
118-
background-repeat: no-repeat;
119-
background-position: center center;
120-
}
121109
}
122110

123111
.dataTables_wrapper {

0 commit comments

Comments
 (0)