Skip to content

Commit 6f9d358

Browse files
committed
fix sidenav, fix headers
1 parent 5524fec commit 6f9d358

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

packages/graphql-playground/src/components/MiddlewareApp.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface State {
5555
config?: GraphQLConfig
5656
configIsYaml?: boolean
5757
configString?: string
58+
activeProjectName?: string
5859
activeEnv?: string
5960
}
6061

@@ -114,6 +115,7 @@ class MiddlewareApp extends React.Component<Props, State> {
114115
configIsYaml,
115116
configString: props.configString,
116117
activeEnv,
118+
activeProjectName: projectName,
117119
}
118120
}
119121

@@ -243,6 +245,7 @@ class MiddlewareApp extends React.Component<Props, State> {
243245
isElectron={Boolean(this.props.isElectron)}
244246
onEditConfig={this.handleStartEditConfig}
245247
getSessionCount={this.getSessionCount}
248+
activeProjectName={this.state.activeProjectName}
246249
/>
247250
)}
248251
<Playground
@@ -321,7 +324,12 @@ class MiddlewareApp extends React.Component<Props, State> {
321324
env,
322325
projectName,
323326
)!
324-
this.setState({ activeEnv: env, endpoint, subscriptionEndpoint })
327+
this.setState({
328+
activeEnv: env,
329+
endpoint,
330+
subscriptionEndpoint,
331+
activeProjectName: projectName,
332+
})
325333
}
326334

327335
getSettings(settingsString = this.state.settingsString): EditorSettings {

packages/graphql-playground/src/components/Playground/GraphQLEditor.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export class GraphQLEditor extends React.PureComponent<
695695
private reloadSchema = async () => {
696696
const result = await this.props.schemaFetcher.refetch(
697697
this.props.session.endpoint,
698-
this.props.session.headers,
698+
this.convertHeaders(this.props.session.headers),
699699
)
700700
if (result) {
701701
const { schema } = result
@@ -714,14 +714,30 @@ export class GraphQLEditor extends React.PureComponent<
714714
this.props.setStacks(this.props.session.id, stacks)
715715
}
716716

717+
private convertHeaders(headers) {
718+
if (headers) {
719+
try {
720+
return JSON.parse(headers)
721+
} catch (e) {
722+
/* tslint:disable-next-line */
723+
console.error(e)
724+
}
725+
}
726+
727+
return undefined
728+
}
729+
717730
private ensureOfSchema() {
718731
// Only perform introspection if a schema is not provided (undefined)
719732
if (this.state.schema !== undefined) {
720733
return
721734
}
722735

723736
this.props.schemaFetcher
724-
.fetch(this.props.session.endpoint, this.props.session.headers)
737+
.fetch(
738+
this.props.session.endpoint,
739+
this.convertHeaders(this.props.session.headers),
740+
)
725741
.then(result => {
726742
if (result) {
727743
const { schema, tracingSupported } = result

packages/graphql-playground/src/components/ProjectsSideNav.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Props {
1818
isElectron: boolean
1919
onEditConfig: () => void
2020
getSessionCount: (endpoint: string) => number
21+
activeProjectName?: string
2122
}
2223

2324
export default class ProjectsSideNav extends React.Component<Props, {}> {
@@ -93,6 +94,7 @@ export default class ProjectsSideNav extends React.Component<Props, {}> {
9394
count={count}
9495
deep={Boolean(projectName)}
9596
projectName={projectName}
97+
activeProjectName={this.props.activeProjectName}
9698
/>
9799
)
98100
})

packages/graphql-playground/src/components/ProjectsSideNavItem.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ export interface Props {
99
count: number
1010
deep: boolean
1111
projectName?: string
12+
activeProjectName?: string
1213
}
1314

1415
export default class ProjectsSideNavItem extends React.Component<Props, {}> {
1516
render() {
16-
const { env, activeEnv, count, deep } = this.props
17-
const active = activeEnv === env
17+
const {
18+
env,
19+
activeEnv,
20+
count,
21+
deep,
22+
activeProjectName,
23+
projectName,
24+
} = this.props
25+
const active = activeEnv === env && activeProjectName === projectName
1826
return (
1927
<ListItem className={cx({ active, deep })} onClick={this.selectEndpoint}>
2028
<span>{env}</span>

packages/graphql-playground/src/middlewareIndex.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ projects:
5757
default:
5858
url: 'https://airbnb.now.sh'
5959
subscription: 'wss://airbnb.now.sh'
60-
local:
60+
dev:
6161
url: 'http://localhost:4000'
6262
subscription: 'ws://localhost:4000'
6363
database:

0 commit comments

Comments
 (0)