@@ -36,17 +36,21 @@ const iconRatingMapping = {
36
36
good : 'smile' ,
37
37
} ;
38
38
39
+ const WORKER_FALLBACK_URL = '/_Resources/Static/Packages/Yoast.YoastSeoForNeos/Assets/webWorker.js' ;
40
+
39
41
@connect (
40
42
( state ) => ( {
41
43
focusedNodeContextPath : selectors . CR . Nodes . focusedNodePathSelector ( state ) ,
42
44
getNodeByContextPath : selectors . CR . Nodes . nodeByContextPath ( state ) ,
43
45
worker : yoastSelectors . worker ( state ) ,
44
46
translations : yoastSelectors . translations ( state ) ,
47
+ configuration : yoastSelectors . configuration ( state ) ,
45
48
analysis : yoastSelectors . analysis ( state ) ,
46
49
} ) ,
47
50
{
48
51
setWorker : yoastActions . setWorker ,
49
52
setTranslations : yoastActions . setTranslations ,
53
+ setConfiguration : yoastActions . setConfiguration ,
50
54
setAnalysis : yoastActions . setAnalysis ,
51
55
}
52
56
)
@@ -66,6 +70,7 @@ export default class YoastInfoView extends PureComponent {
66
70
static propTypes = {
67
71
worker : PropTypes . object ,
68
72
translations : PropTypes . object ,
73
+ configuration : PropTypes . object ,
69
74
analysis : PropTypes . object ,
70
75
canvasSrc : PropTypes . string ,
71
76
contextPath : PropTypes . string ,
@@ -74,18 +79,14 @@ export default class YoastInfoView extends PureComponent {
74
79
focusedNodeContextPath : PropTypes . string ,
75
80
getNodeByContextPath : PropTypes . func . isRequired ,
76
81
setTranslations : PropTypes . func . isRequired ,
82
+ setConfiguration : PropTypes . func . isRequired ,
77
83
setWorker : PropTypes . func . isRequired ,
78
84
setAnalysis : PropTypes . func . isRequired ,
79
- workerUrl : PropTypes . string ,
80
85
options : PropTypes . shape ( {
81
86
defaultEditPreviewMode : PropTypes . string ,
82
87
} ) ,
83
88
} ;
84
89
85
- static defaultProps = {
86
- workerUrl : '/_Resources/Static/Packages/Yoast.YoastSeoForNeos/Assets/webWorker.js' , // TODO: Resolve path via Neos api
87
- } ;
88
-
89
90
constructor ( props ) {
90
91
super ( props ) ;
91
92
const { documentNodePath, getNodeByContextPath } = this . props ;
@@ -102,12 +103,13 @@ export default class YoastInfoView extends PureComponent {
102
103
isAnalyzing : false ,
103
104
locale : 'en_US' ,
104
105
} ,
105
- i18n : { } ,
106
+ i18n : { }
106
107
} ;
107
108
}
108
109
109
110
componentDidMount ( ) {
110
111
this . fetchTranslations ( ) ;
112
+ this . fetchConfiguration ( ) ;
111
113
112
114
// Check if we can reuse that last analysis that ran if we are on the same page
113
115
const { analysis } = this . props ;
@@ -141,6 +143,35 @@ export default class YoastInfoView extends PureComponent {
141
143
) ;
142
144
} ;
143
145
146
+ fetchConfiguration = ( ) => {
147
+ if ( this . props . configuration ) {
148
+ return ;
149
+ }
150
+
151
+ fetchWithErrorHandling
152
+ . withCsrfToken ( ( csrfToken ) => ( {
153
+ url : '/neosyoastseo/data/fetchConfiguration' ,
154
+ method : 'GET' ,
155
+ credentials : 'include' ,
156
+ headers : {
157
+ 'X-Flow-Csrftoken' : csrfToken ,
158
+ 'Content-Type' : 'application/json' ,
159
+ } ,
160
+ } ) )
161
+ . then ( ( response ) => response && response . json ( ) )
162
+ . then ( ( configuration ) => {
163
+ if ( configuration && ! configuration . error ) {
164
+ this . props . setConfiguration ( configuration ) ;
165
+ }
166
+ } )
167
+ . catch ( ( ) => {
168
+ console . error ( '[Yoast SEO] Error fetching configuration - applying defaults' ) ;
169
+ this . props . setConfiguration ( {
170
+ workerUrl : WORKER_FALLBACK_URL ,
171
+ } ) ;
172
+ } ) ;
173
+ }
174
+
144
175
/**
145
176
* Fetch new translations from the backend.
146
177
*/
@@ -260,7 +291,7 @@ export default class YoastInfoView extends PureComponent {
260
291
initializeWorker = ( ) => {
261
292
let { worker } = this . props ;
262
293
if ( ! worker ) {
263
- worker = new AnalysisWorkerWrapper ( createWorker ( this . props . workerUrl ) ) ;
294
+ worker = new AnalysisWorkerWrapper ( createWorker ( this . props . configuration . workerUrl ) ) ;
264
295
this . props . setWorker ( worker ) ;
265
296
}
266
297
return worker . initialize ( {
0 commit comments