@@ -61,6 +61,7 @@ export interface PlaygroundWrapperProps {
61
61
tabs ?: Tab [ ]
62
62
schema ?: { __schema : any } // introspection result
63
63
codeTheme ?: EditorColours
64
+ workspaceName ?: string
64
65
}
65
66
66
67
export interface ReduxProps {
@@ -91,6 +92,11 @@ class PlaygroundWrapper extends React.Component<
91
92
super ( props )
92
93
; ( global as any ) . m = this
93
94
95
+ this . state = this . mapPropsToState ( props )
96
+ this . removeLoader ( )
97
+ }
98
+
99
+ mapPropsToState ( props : PlaygroundWrapperProps ) : State {
94
100
const configIsYaml = props . configString
95
101
? this . isConfigYaml ( props . configString )
96
102
: false
@@ -120,9 +126,7 @@ class PlaygroundWrapper extends React.Component<
120
126
subscriptionEndpoint =
121
127
this . normalizeSubscriptionUrl ( endpoint , subscriptionEndpoint ) || undefined
122
128
123
- this . removeLoader ( )
124
-
125
- this . state = {
129
+ return {
126
130
endpoint : this . absolutizeUrl ( endpoint ) ,
127
131
platformToken :
128
132
props . platformToken ||
@@ -190,12 +194,16 @@ class PlaygroundWrapper extends React.Component<
190
194
}
191
195
192
196
componentWillReceiveProps ( nextProps : PlaygroundWrapperProps & ReduxProps ) {
197
+ // Reactive props (props that cause a state change upon being changed)
193
198
if (
194
- nextProps . configString !== this . props . configString &&
195
- nextProps . configString
199
+ nextProps . endpoint !== this . props . endpoint ||
200
+ nextProps . endpointUrl !== this . props . endpointUrl ||
201
+ nextProps . subscriptionEndpoint !== this . props . subscriptionEndpoint ||
202
+ nextProps . configString !== this . props . configString ||
203
+ nextProps . platformToken !== this . props . platformToken ||
204
+ nextProps . config !== this . props . config
196
205
) {
197
- const configIsYaml = this . isConfigYaml ( nextProps . configString )
198
- this . setState ( { configIsYaml } )
206
+ this . setState ( this . mapPropsToState ( nextProps ) )
199
207
this . setInitialWorkspace ( nextProps )
200
208
}
201
209
}
@@ -379,7 +387,9 @@ class PlaygroundWrapper extends React.Component<
379
387
fixedEndpoints = { Boolean ( this . state . configString ) }
380
388
headers = { this . state . headers }
381
389
configPath = { this . props . configPath }
382
- workspaceName = { this . state . activeProjectName }
390
+ workspaceName = {
391
+ this . props . workspaceName || this . state . activeProjectName
392
+ }
383
393
createApolloLink = { this . props . createApolloLink }
384
394
schema = { this . state . schema }
385
395
/>
0 commit comments