Skip to content

Commit 1873b97

Browse files
Merge branch 'development' into issue-750
2 parents 4d5f825 + dc457fa commit 1873b97

File tree

12 files changed

+79
-38
lines changed

12 files changed

+79
-38
lines changed

bin/wp-init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ docker exec $args visualizer_wordpress wp --allow-root core install --url="http:
2323
# update core
2424
docker exec $args visualizer_wordpress chown -R www-data:www-data /var/www/html/
2525
docker exec $args visualizer_wordpress chmod 0777 -R /var/www/html/wp-content
26-
docker exec $args visualizer_wordpress wp --allow-root core update --version=5.4
26+
docker exec $args visualizer_wordpress wp --allow-root core update --version=5.5
2727
docker exec $args visualizer_wordpress wp --allow-root core update-db
2828

2929
# install required external plugins

classes/Visualizer/Gutenberg/build/block.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.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ChartSelect extends Component {
147147
</InspectorControls>
148148
}
149149

150-
<div className="visualizer-settings__chart">
150+
<div className="visualizer-settings__chart" data-chart-type={ chart }>
151151

152152
{ ( null !== this.props.chart ) &&
153153

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Charts extends Component {
132132
}
133133

134134
return (
135-
<div className="visualizer-settings__charts-single" key={ `chart-${ charts[i].id }` }>
135+
<div className="visualizer-settings__charts-single" data-chart-type={ chart }> key={ `chart-${ charts[i].id }` }>
136136

137137
<div className="visualizer-settings__charts-title">
138138
{ title }

classes/Visualizer/Module/Chart.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ public function setJsonData() {
215215
$chart = get_post( $chart_id );
216216

217217
$source = new Visualizer_Source_Json( $params );
218+
update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true );
218219
$source->fetchFromEditableTable();
219220

220-
$content = $source->getData();
221+
$content = $source->getData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
221222
$chart->post_content = $content;
222223
wp_update_post( $chart->to_array() );
223224
update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
@@ -266,7 +267,7 @@ public function setJsonData() {
266267

267268
$render = new Visualizer_Render_Page_Update();
268269
$render->id = $chart->ID;
269-
$render->data = json_encode( $source->getRawData() );
270+
$render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
270271
$render->series = json_encode( $source->getSeries() );
271272
$render->render();
272273

@@ -498,7 +499,7 @@ public function renderChartPages() {
498499
'post_title' => 'Visualization',
499500
'post_author' => get_current_user_id(),
500501
'post_status' => 'auto-draft',
501-
'post_content' => $source->getData(),
502+
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
502503
)
503504
);
504505
if ( $chart_id && ! is_wp_error( $chart_id ) ) {
@@ -851,7 +852,7 @@ private function _handleTypesPage() {
851852
if ( filter_var( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, true ), FILTER_VALIDATE_BOOLEAN ) ) {
852853
$source = new Visualizer_Source_Csv( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . $type . '.csv' );
853854
$source->fetch();
854-
$this->_chart->post_content = $source->getData();
855+
$this->_chart->post_content = $source->getData( get_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
855856
wp_update_post( $this->_chart->to_array() );
856857
update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
857858
}
@@ -1087,7 +1088,7 @@ public function uploadData() {
10871088

10881089
if ( $source ) {
10891090
if ( $source->fetch() ) {
1090-
$content = $source->getData();
1091+
$content = $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) );
10911092
$populate = true;
10921093
if ( is_string( $content ) && is_array( unserialize( $content ) ) ) {
10931094
$json = unserialize( $content );
@@ -1114,7 +1115,7 @@ public function uploadData() {
11141115
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
11151116

11161117
$render->id = $chart->ID;
1117-
$render->data = json_encode( $source->getRawData() );
1118+
$render->data = json_encode( $source->getRawData( get_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
11181119
$render->series = json_encode( $source->getSeries() );
11191120
$render->settings = json_encode( $settings );
11201121
} else {
@@ -1349,10 +1350,10 @@ public function saveQuery() {
13491350
wp_update_post(
13501351
array(
13511352
'ID' => $chart_id,
1352-
'post_content' => $source->getData(),
1353+
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
13531354
)
13541355
);
1355-
$render->data = json_encode( $source->getRawData() );
1356+
$render->data = json_encode( $source->getRawData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ) );
13561357
$render->series = json_encode( $source->getSeries() );
13571358
$render->id = $chart_id;
13581359
} else {

classes/Visualizer/Module/Frontend.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ function endpoint_register() {
108108
'visualizer/v' . VISUALIZER_REST_VERSION,
109109
'/action/(?P<chart>\d+)/(?P<type>.+)/',
110110
array(
111-
'methods' => 'GET',
111+
// POST is required for save/cancel, GET for all others
112+
'methods' => array( 'POST', 'GET' ),
112113
'args' => array(
113114
'chart' => array(
114115
'required' => true,
@@ -119,11 +120,17 @@ function endpoint_register() {
119120
'type' => array(
120121
'required' => true,
121122
'type' => 'string',
122-
'enum' => array_keys( $this->get_actions() ),
123+
'enum' => array_merge( array( 'save', 'cancel' ), array_keys( $this->get_actions() ) ),
123124
),
124125
),
125126
'permission_callback' => function ( WP_REST_Request $request ) {
126127
$chart_id = filter_var( sanitize_text_field( $request->get_param( 'chart' ), FILTER_VALIDATE_INT ) );
128+
if ( ! empty( $chart_id ) && in_array( $request->get_param( 'type' ), array( 'save', 'cancel' ), true ) ) {
129+
// let save and cancel go without any check as past version of pro
130+
// did not send the X-WP-Nonce
131+
// we can change this at a later date.
132+
return true;
133+
}
127134
return ! empty( $chart_id ) && apply_filters( 'visualizer_pro_show_chart', true, $chart_id );
128135
},
129136
'callback' => array( $this, 'perform_action' ),

classes/Visualizer/Module/Setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
309309
wp_update_post(
310310
array(
311311
'ID' => $chart_id,
312-
'post_content' => $source->getData(),
312+
'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ),
313313
)
314314
);
315315

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Visualizer_Plugin {
4545

4646
const CF_SOURCE_FILTER = 'visualizer-source-filter';
4747
const CF_FILTER_CONFIG = 'visualizer-filter-config';
48+
const CF_EDITABLE_TABLE = 'visualizer-editable-table';
4849

4950
// custom actions
5051
const ACTION_GET_CHARTS = 'visualizer-get-charts';

classes/Visualizer/Source.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ public function getSeries() {
141141
* @access public
142142
* @return string The serialized array of data.
143143
*/
144-
public function getData() {
144+
public function getData( $fetch_from_editable_table = false ) {
145+
if ( $fetch_from_editable_table ) {
146+
$this->_fetchDataFromEditableTable();
147+
}
145148
return serialize( $this->_data );
146149
}
147150

@@ -153,7 +156,10 @@ public function getData() {
153156
* @access public
154157
* @return array
155158
*/
156-
public function getRawData() {
159+
public function getRawData( $fetch_from_editable_table = false ) {
160+
if ( $fetch_from_editable_table ) {
161+
$this->_fetchDataFromEditableTable();
162+
}
157163
return $this->_data;
158164
}
159165

@@ -443,7 +449,6 @@ private function _fetchSeriesFromEditableTable() {
443449
* @access private
444450
*/
445451
private function _fetchDataFromEditableTable() {
446-
$params = $this->_args;
447452
$headers = wp_list_pluck( $this->_series, 'label' );
448453
$this->fetch();
449454

@@ -452,7 +457,10 @@ private function _fetchDataFromEditableTable() {
452457

453458
foreach ( $data as $line ) {
454459
$data_row = array();
455-
foreach ( $line as $header => $value ) {
460+
// we have to make sure we are fetching the data in the right order
461+
// in case the columns have been reordered
462+
foreach ( $headers as $header ) {
463+
$value = $line[ $header ];
456464
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
457465
if ( in_array( $header, $headers ) ) {
458466
$data_row[] = $value;

cypress/integration/free-gutenberg-datatable.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ describe('Test Free - gutenberg (datatable)', function() {
2727

2828
cy.wrap(charts).each((value, i, array) => {
2929
// insert a visualizer block
30-
cy.get('div.edit-post-header-toolbar .block-editor-inserter button').click();
31-
cy.get('.components-popover__content').then(function ($popup) {
32-
cy.wrap($popup).find('.block-editor-inserter__search').type('visua');
33-
cy.wrap($popup).find('.block-editor-inserter__results ul.block-editor-block-types-list li').should('have.length', 1);
34-
cy.wrap($popup).find('.block-editor-inserter__results ul.block-editor-block-types-list li button').click();
30+
cy.get('div.edit-post-header-toolbar button.edit-post-header-toolbar__inserter-toggle').click();
31+
cy.get('.edit-post-layout__inserter-panel-popover-wrapper').then(function ($popup) {
32+
cy.wrap($popup).find('.block-editor-inserter__search-input').type('visua');
33+
cy.wrap($popup).find('.block-editor-inserter__block-list .block-editor-block-types-list__list-item').should('have.length', 1);
34+
cy.wrap($popup).find('.block-editor-inserter__block-list button.editor-block-list-item-visualizer-chart').click();
3535
});
3636

3737
// see the block has the correct elements.
38-
cy.get('div[data-type="visualizer/chart"]').should('have.length', (i + 2));
38+
cy.get('div[data-type="visualizer/chart"]').should('have.length', (i + 1));
3939

4040
cy.get('div[data-type="visualizer/chart"]:nth-child(' + (i + 1) + ')').then( ($block) => {
4141
// 2 rows - create and insert
@@ -45,8 +45,11 @@ describe('Test Free - gutenberg (datatable)', function() {
4545
cy.wrap($block).find('.visualizer-settings__content-option').last().click({force:true});
4646

4747
// insert chart
48+
cy.wrap($block).find('.visualizer-settings .visualizer-settings__charts-single:nth-child(' + (i + 1) + ')').then( ($chart_block) => {
49+
cy.log('Inserting chart: ' + Cypress.$($chart_block).attr('data-chart-type'));
50+
});
4851
cy.wrap($block).find('.visualizer-settings .visualizer-settings__charts-single:nth-child(' + (i + 1) + ') .visualizer-settings__charts-controls').click();
49-
52+
5053
cy.wrap($block).find('.visualizer-settings .visualizer-settings__chart').should('have.length', 1);
5154

5255
// log a line to show which chart we are trying to insert.
@@ -61,7 +64,10 @@ describe('Test Free - gutenberg (datatable)', function() {
6164
cy.wrap($block).find('.visualizer-settings .components-button-group button').should('have.length', 2);
6265
cy.wrap($block).find('.visualizer-settings .components-button-group button.visualizer-bttn-done').should('have.length', 1);
6366

64-
// click advanced options
67+
// make the settings block appear.
68+
cy.wrap($block).type('{ctrl}{shift},');
69+
70+
// click advanced options.
6571
cy.get('.visualizer-advanced-options button.components-button').click({force:true});
6672

6773
// done button disappears, save button appears
@@ -74,4 +80,4 @@ describe('Test Free - gutenberg (datatable)', function() {
7480
});
7581
});
7682

77-
})
83+
})

0 commit comments

Comments
 (0)