Skip to content

Commit 7d7969f

Browse files
BrunoScheuflertimsuchanek
authored andcommitted
Add workspaceName prop (#772)
* Fix announcement link * fix: add workspaceName prop to PlaygroundWrapper with passthrough to Playground * fix: Added mapPropsToState to react to prop changes * fix: remove unnecessary check * fix: swapped orders of workspaceName and activeProjectName
1 parent 3dcd697 commit 7d7969f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

packages/graphql-playground-react/src/components/PlaygroundWrapper.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface PlaygroundWrapperProps {
6161
tabs?: Tab[]
6262
schema?: { __schema: any } // introspection result
6363
codeTheme?: EditorColours
64+
workspaceName?: string
6465
}
6566

6667
export interface ReduxProps {
@@ -91,6 +92,11 @@ class PlaygroundWrapper extends React.Component<
9192
super(props)
9293
;(global as any).m = this
9394

95+
this.state = this.mapPropsToState(props)
96+
this.removeLoader()
97+
}
98+
99+
mapPropsToState(props: PlaygroundWrapperProps): State {
94100
const configIsYaml = props.configString
95101
? this.isConfigYaml(props.configString)
96102
: false
@@ -120,9 +126,7 @@ class PlaygroundWrapper extends React.Component<
120126
subscriptionEndpoint =
121127
this.normalizeSubscriptionUrl(endpoint, subscriptionEndpoint) || undefined
122128

123-
this.removeLoader()
124-
125-
this.state = {
129+
return {
126130
endpoint: this.absolutizeUrl(endpoint),
127131
platformToken:
128132
props.platformToken ||
@@ -190,12 +194,16 @@ class PlaygroundWrapper extends React.Component<
190194
}
191195

192196
componentWillReceiveProps(nextProps: PlaygroundWrapperProps & ReduxProps) {
197+
// Reactive props (props that cause a state change upon being changed)
193198
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
196205
) {
197-
const configIsYaml = this.isConfigYaml(nextProps.configString)
198-
this.setState({ configIsYaml })
206+
this.setState(this.mapPropsToState(nextProps))
199207
this.setInitialWorkspace(nextProps)
200208
}
201209
}
@@ -379,7 +387,9 @@ class PlaygroundWrapper extends React.Component<
379387
fixedEndpoints={Boolean(this.state.configString)}
380388
headers={this.state.headers}
381389
configPath={this.props.configPath}
382-
workspaceName={this.state.activeProjectName}
390+
workspaceName={
391+
this.props.workspaceName || this.state.activeProjectName
392+
}
383393
createApolloLink={this.props.createApolloLink}
384394
schema={this.state.schema}
385395
/>

0 commit comments

Comments
 (0)