| @@ -105,10 +105,9 @@ | ||
| 105 | 105 | |
| 106 | 106 | this.setState({ |
| 107 | 107 | route: 'chartSelect', |
| 108 | 108 | chart: result['chart_data'], |
| 109 | - isLoading: true, | |
| 110 | - isModified: true | |
| 109 | + isLoading: false | |
| 111 | 110 | }); |
| 112 | 111 | |
| 113 | 112 | this.props.setAttributes({ |
| 114 | 113 | id, |
| @@ -123,11 +122,8 @@ | ||
| 123 | 122 | } |
| 124 | 123 | |
| 125 | 124 | editSettings( settings ) { |
| 126 | 125 | let chart = { ...this.state.chart }; |
| 127 | - if ( '1' !== settings.pagination ) { | |
| 128 | - delete settings.pageSize; | |
| 129 | - } | |
| 130 | 126 | chart['visualizer-settings'] = settings; |
| 131 | 127 | this.setState({ |
| 132 | 128 | chart, |
| 133 | 129 | isModified: true |
| @@ -342,41 +338,22 @@ | ||
| 342 | 338 | |
| 343 | 339 | let map = series; |
| 344 | 340 | let fieldName = 'series'; |
| 345 | 341 | |
| 346 | - switch ( type ) { | |
| 347 | - case 'pie': | |
| 348 | - map = chartData; | |
| 349 | - fieldName = 'slices'; | |
| 342 | + if ( 'pie' === type ) { | |
| 343 | + map = chartData; | |
| 344 | + fieldName = 'slices'; | |
| 350 | 345 | |
| 351 | - // pie charts are finicky about a number being a number | |
| 352 | - // and editing a number makes it a string | |
| 353 | - // so let's convert it back into a number. | |
| 354 | - chartData.map( ( i, index ) => { | |
| 355 | - switch ( series[1].type ) { | |
| 356 | - case 'number': | |
| 357 | - i[1] = parseFloat( i[1]); | |
| 358 | - break; | |
| 359 | - } | |
| 360 | - }); | |
| 361 | - break; | |
| 362 | - case 'tabular': | |
| 363 | - | |
| 364 | - // table charts are finicky about a boolean being a boolean | |
| 365 | - // and editing a boolean makes it a string | |
| 366 | - // so let's convert it back into a boolean. | |
| 367 | - chartData.map( ( i, index ) => { | |
| 368 | - series.map( ( seriesObject, seriesIndex ) => { | |
| 369 | - switch ( seriesObject.type ) { | |
| 370 | - case 'boolean': | |
| 371 | - if ( 'string' === typeof i[seriesIndex]) { | |
| 372 | - i[seriesIndex] = 'true' === i[seriesIndex]; | |
| 373 | - } | |
| 374 | - break; | |
| 375 | - } | |
| 376 | - }); | |
| 377 | - }); | |
| 378 | - break; | |
| 346 | + // pie charts are finicky about a number being a number | |
| 347 | + // and editing a number makes it a string | |
| 348 | + // so let's convert it back into a number. | |
| 349 | + chartData.map( ( i, index ) => { | |
| 350 | + switch ( series[1].type ) { | |
| 351 | + case 'number': | |
| 352 | + i[1] = parseFloat( i[1]); | |
| 353 | + break; | |
| 354 | + } | |
| 355 | + }); | |
| 379 | 356 | } |
| 380 | 357 | |
| 381 | 358 | map.map( ( i, index ) => { |
| 382 | 359 | if ( 'pie' !== type && 0 === index ) { |
| @@ -384,20 +361,18 @@ | ||
| 384 | 361 | } |
| 385 | 362 | |
| 386 | 363 | const seriesIndex = 'pie' !== type ? index - 1 : index; |
| 387 | 364 | |
| 388 | - if ( Array.isArray( settings[fieldName]) && settings[fieldName][seriesIndex] === undefined ) { | |
| 365 | + if ( settings[fieldName][seriesIndex] === undefined ) { | |
| 389 | 366 | settings[fieldName][seriesIndex] = {}; |
| 390 | 367 | settings[fieldName][seriesIndex].temp = 1; |
| 391 | 368 | } |
| 392 | 369 | }); |
| 393 | 370 | |
| 394 | - if ( Array.isArray( settings[fieldName]) ) { | |
| 395 | - settings[fieldName] = settings[fieldName].filter( ( i, index ) => { | |
| 396 | - const length = -1 >= [ 'pie', 'tabular', 'dataTable' ].indexOf( type ) ? map.length - 1 : map.length; | |
| 397 | - return index < length; | |
| 398 | - }); | |
| 399 | - } | |
| 371 | + settings[fieldName] = settings[fieldName].filter( ( i, index ) => { | |
| 372 | + const length = -1 >= [ 'pie', 'tabular', 'dataTable' ].indexOf( type ) ? map.length - 1 : map.length; | |
| 373 | + return index < length; | |
| 374 | + }); | |
| 400 | 375 | |
| 401 | 376 | chart['visualizer-source'] = source; |
| 402 | 377 | chart['visualizer-default-data'] = 0; |
| 403 | 378 | chart['visualizer-data'] = chartData; |
| @@ -468,20 +443,8 @@ | ||
| 468 | 443 | </Notice> |
| 469 | 444 | ); |
| 470 | 445 | } |
| 471 | 446 | |
| 472 | - if ( '1' === visualizerLocalize.isFullSiteEditor ) { | |
| 473 | - return ( | |
| 474 | - <Notice | |
| 475 | - status="error" | |
| 476 | - isDismissible={ false } | |
| 477 | - > | |
| 478 | - <Dashicon icon="chart-pie" /> | |
| 479 | - { __( 'Visualizer block charts are currently not available for selection here, you must visit the library, get the shortcode, and add the chart here in a shortcode tag.' ) } | |
| 480 | - </Notice> | |
| 481 | - ); | |
| 482 | - } | |
| 483 | - | |
| 484 | 447 | if ( 'renderChart' === this.state.route && null !== this.state.chart ) { |
| 485 | 448 | return ( |
| 486 | 449 | <ChartRender |
| 487 | 450 | id={ this.props.attributes.id } |
| @@ -586,9 +549,9 @@ | ||
| 586 | 549 | { ( 'showCharts' === this.state.route || 'chartSelect' === this.state.route ) && |
| 587 | 550 | <ButtonGroup> |
| 588 | 551 | |
| 589 | 552 | <Button |
| 590 | - variant="secondary" | |
| 553 | + isDefault | |
| 591 | 554 | isLarge |
| 592 | 555 | onClick={ () => { |
| 593 | 556 | let route; |
| 594 | 557 | if ( 'showCharts' === this.state.route ) { |
| @@ -595,9 +558,9 @@ | ||
| 595 | 558 | route = 'home'; |
| 596 | 559 | } else if ( 'chartSelect' === this.state.route ) { |
| 597 | 560 | route = 'showCharts'; |
| 598 | 561 | } |
| 599 | - this.setState({ route, isLoading: false }); | |
| 562 | + this.setState({ route }); | |
| 600 | 563 | this.props.setAttributes({ route }); |
| 601 | 564 | } } |
| 602 | 565 | > |
| 603 | 566 | { __( 'Back' ) } |
| @@ -607,13 +570,13 @@ | ||
| 607 | 570 | <Fragment> |
| 608 | 571 | |
| 609 | 572 | { false === this.state.isModified ? |
| 610 | 573 | <Button |
| 611 | - variant="secondary" | |
| 574 | + isDefault | |
| 612 | 575 | isLarge |
| 613 | 576 | className="visualizer-bttn-done" |
| 614 | 577 | onClick={ () => { |
| 615 | - this.setState({ route: 'renderChart', isModified: true }); | |
| 578 | + this.setState({ route: 'renderChart' }); | |
| 616 | 579 | this.props.setAttributes({ route: 'renderChart' }); |
| 617 | 580 | } } |
| 618 | 581 | > |
| 619 | 582 | { __( 'Done' ) } |