PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Gutenberg/src/Components/ChartSelect.js +130 -27 3.10.133.11.7 View file →
@@ -31,9 +31,15 @@
31 31 const { startCase } = lodash;
32 32
33 33 const { __ } = wp.i18n;
34 34
35 +const { apiFetch } = wp;
36 +
35 37 const {
38 + Button
39 +} = wp.components;
40 +
41 +const {
36 42 Component,
37 43 Fragment
38 44 } = wp.element;
39 45
@@ -38,8 +44,61 @@
38 44 } = wp.element;
39 45
40 46 const { InspectorControls } = wp.blockEditor || wp.editor;
41 47
48 +let visualizerMedia, visualizerMediaView;
49 +visualizerMedia = visualizer.media = {};
50 +visualizerMediaView = visualizerMedia.view = {};
51 +
52 +visualizerMediaView.Chart = wp.media.view.MediaFrame.extend(
53 + {
54 + initialize: function() {
55 + const self = this;
56 +
57 + _.defaults(
58 + self.options, {
59 + action: '',
60 + id: 'visualizer',
61 + state: 'iframe:visualizer',
62 + title: 'Visualizer'
63 + }
64 + );
65 +
66 + wp.media.view.MediaFrame.prototype.initialize.apply( self, arguments );
67 +
68 + wp.media.view.settings.tab = 'Visualizer';
69 + wp.media.view.settings.tabUrl = self.options.action;
70 + self.createIframeStates();
71 + },
72 +
73 + createIframeStates: function( passedOptions ) {
74 + const self = this;
75 + wp.media.view.MediaFrame.prototype.createIframeStates.apply( self, arguments );
76 +
77 + self.state( self.options.state ).set(
78 + _.defaults(
79 + {
80 + tab: self.options.id,
81 + src: self.options.action + '&tab=' + self.options.id,
82 + title: self.options.title,
83 + content: 'iframe',
84 + menu: 'default'
85 + }, passedOptions
86 + )
87 + );
88 +
89 + },
90 +
91 + open: function() {
92 + try {
93 + wp.media.view.MediaFrame.prototype.open.apply( this, arguments );
94 + } catch ( error ) {
95 + console.error( error );
96 + }
97 + }
98 + }
99 +);
100 +
42 101 class ChartSelect extends Component {
43 102 constructor() {
44 103 super( ...arguments );
45 104
@@ -55,8 +114,9 @@
55 114 };
56 115 }
57 116
58 117 render() {
118 + const { legacyBlockEdit, blockEditDoc } = window.visualizerLocalize;
59 119 let chartVersion = 'undefined' !== typeof google.visualization ? google.visualization.Version : 'current';
60 120
61 121 let chart, footer;
62 122
@@ -79,43 +139,84 @@
79 139 if ( data['visualizer-data-exploded']) {
80 140 footer = __( 'Annotations in this chart may not display here but they will display in the front end.' );
81 141 }
82 142
143 + const openEditChart = ( chartId ) => {
144 + const baseURL = ( window.visualizerLocalize.chartEditUrl ) ? window.visualizerLocalize.chartEditUrl : '';
145 + let view = new visualizerMediaView.Chart(
146 + {
147 + action: `${baseURL}?action=visualizer-edit-chart&library=yes&chart=` + chartId
148 + }
149 + );
150 + const updateChartState = async() => {
151 + await this.setState({
152 + isLoading: 'getChart'
153 + });
154 +
155 + let result = await apiFetch({ path: `wp/v2/visualizer/${chartId}` });
156 + await this.props.editSettings( result['chart_data']['visualizer-settings']);
157 + await this.props.getChartData( chartId );
158 +
159 + await this.setState({ route: 'home', chart: result['chart_data'], isModified: true, isLoading: true });
160 + };
161 + // eslint-disable-next-line camelcase
162 + window.send_to_editor = function() {
163 + updateChartState().then( () => {
164 + view.close();
165 + });
166 + };
167 +
168 + view.open();
169 + };
170 +
83 171 return (
84 172 <Fragment>
85 173 { 'home' === this.state.route &&
86 174 <InspectorControls>
175 + { ! legacyBlockEdit && (
176 + <div className="viz-edit-chart-new">
177 + <Button
178 + isPrimary={true}
179 + onClick={ () => {
180 + openEditChart( this.props.id );
181 +} }> Edit Chart </ Button>
182 + <p dangerouslySetInnerHTML={{__html: blockEditDoc}}></p>
183 + </div>
184 + ) }
87 185
186 + { legacyBlockEdit && (
187 + <>
188 +
189 + <ManualData chart={ this.props.chart } editChartData={ this.props.editChartData } />
190 +
88 191 <FileImport
89 192 chart={ this.props.chart }
90 193 readUploadedFile={ this.props.readUploadedFile }
91 194 />
92 195
93 - <RemoteImport
94 - id={ this.props.id }
95 - chart={ this.props.chart }
96 - editURL={ this.props.editURL }
97 - isLoading={ this.props.isLoading }
98 - uploadData={ this.props.uploadData }
99 - editSchedule={ this.props.editSchedule }
100 - editJSONSchedule={ this.props.editJSONSchedule }
101 - editJSONURL={ this.props.editJSONURL }
102 - editJSONHeaders={ this.props.editJSONHeaders }
103 - editJSONRoot={ this.props.editJSONRoot }
104 - editJSONPaging={ this.props.editJSONPaging }
105 - JSONImportData={ this.props.JSONImportData }
106 - />
196 + <RemoteImport
197 + id={ this.props.id }
198 + chart={ this.props.chart }
199 + editURL={ this.props.editURL }
200 + isLoading={ this.props.isLoading }
201 + uploadData={ this.props.uploadData }
202 + editSchedule={ this.props.editSchedule }
203 + editJSONSchedule={ this.props.editJSONSchedule }
204 + editJSONURL={ this.props.editJSONURL }
205 + editJSONHeaders={ this.props.editJSONHeaders }
206 + editJSONRoot={ this.props.editJSONRoot }
207 + editJSONPaging={ this.props.editJSONPaging }
208 + JSONImportData={ this.props.JSONImportData }
209 + />
107 210
108 - <ChartImport getChartData={ this.props.getChartData } isLoading={ this.props.isLoading } />
211 + <ChartImport getChartData={ this.props.getChartData } isLoading={ this.props.isLoading } />
109 212
110 - <DataImport
111 - chart={ this.props.chart }
112 - editSchedule={ this.props.editDatabaseSchedule }
113 - databaseImportData={ this.props.databaseImportData }
114 - />
213 + <DataImport
214 + chart={ this.props.chart }
215 + editSchedule={ this.props.editDatabaseSchedule }
216 + databaseImportData={ this.props.databaseImportData }
217 + />
115 218
116 - <ManualData chart={ this.props.chart } editChartData={ this.props.editChartData } />
117 -
118 219 <PanelButton
119 220 label={ __( 'Advanced Options' ) }
120 221 className="visualizer-advanced-options"
121 222 icon="admin-tools"
@@ -121,13 +222,15 @@
121 222 icon="admin-tools"
122 223 onClick={ () => this.setState({ route: 'showAdvanced' }) }
123 224 />
124 225
125 - <PanelButton
126 - label={ __( 'Chart Permissions' ) }
127 - icon="admin-users"
128 - onClick={ () => this.setState({ route: 'showPermissions' }) }
129 - />
226 + <PanelButton
227 + label={ __( 'Chart Permissions' ) }
228 + icon="admin-users"
229 + onClick={ () => this.setState({ route: 'showPermissions' }) }
230 + />
231 + </>
232 + ) }
130 233 </InspectorControls>
131 234 }
132 235
133 236 { ( 'showAdvanced' === this.state.route || 'showPermissions' === this.state.route ) &&