Skip to content

Commit 0ef92d0

Browse files
committed
fix(graphql-playground-react): Replaced triangle Icon component with React SVG component
1 parent 802b62e commit 0ef92d0

File tree

4 files changed

+62
-39
lines changed

4 files changed

+62
-39
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react'
2+
3+
export const Triangle = () => (
4+
<svg
5+
width="6px"
6+
height="7px"
7+
viewBox="40 0 6 7"
8+
version="1.1"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
11+
<polygon
12+
id="Triangle"
13+
stroke="none"
14+
fill="rgba(0, 0, 0, .2)"
15+
fillRule="evenodd"
16+
points="40 7 40 0 46 3.5"
17+
/>
18+
</svg>
19+
)

packages/graphql-playground-react/src/components/Playground/DocExplorer/GraphDocs.tsx

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -215,39 +215,41 @@ class GraphDocs extends React.Component<
215215
onMouseDown={this.handleDocsResizeStart}
216216
/>
217217
<div className="doc-explorer-gradient" />
218-
<div
219-
className="doc-explorer"
220-
onKeyDown={this.handleKeyDown}
221-
onMouseMove={this.handleMouseMove}
222-
tabIndex={0}
223-
ref={this.setDocExplorerRef}
224-
>
225-
<div className="doc-explorer-container">
226-
{emptySchema && <ColumnDoc>{emptySchema}</ColumnDoc>}
227-
{schema && (
228-
<RootColumn
229-
schema={schema}
230-
width={this.state.widthMap.root || columnWidth - 1}
231-
searchValue={this.state.searchValue}
232-
handleSearch={this.handleSearch}
233-
sessionId={this.props.sessionId}
234-
/>
235-
)}
236-
{navStack.map((stack, index) => (
237-
<ColumnDoc
238-
key={index}
239-
width={this.state.widthMap[stack.field.path] || columnWidth}
240-
>
241-
<FieldDoc
218+
{docsOpen && (
219+
<div
220+
className="doc-explorer"
221+
onKeyDown={this.handleKeyDown}
222+
onMouseMove={this.handleMouseMove}
223+
tabIndex={0}
224+
ref={this.setDocExplorerRef}
225+
>
226+
<div className="doc-explorer-container">
227+
{emptySchema && <ColumnDoc>{emptySchema}</ColumnDoc>}
228+
{schema && (
229+
<RootColumn
242230
schema={schema}
243-
field={stack.field}
244-
level={index + 1}
231+
width={this.state.widthMap.root || columnWidth - 1}
232+
searchValue={this.state.searchValue}
233+
handleSearch={this.handleSearch}
245234
sessionId={this.props.sessionId}
246235
/>
247-
</ColumnDoc>
248-
))}
236+
)}
237+
{navStack.map((stack, index) => (
238+
<ColumnDoc
239+
key={index}
240+
width={this.state.widthMap[stack.field.path] || columnWidth}
241+
>
242+
<FieldDoc
243+
schema={schema}
244+
field={stack.field}
245+
level={index + 1}
246+
sessionId={this.props.sessionId}
247+
/>
248+
</ColumnDoc>
249+
))}
250+
</div>
249251
</div>
250-
</div>
252+
)}
251253
</div>
252254
)
253255
}
@@ -261,7 +263,7 @@ class GraphDocs extends React.Component<
261263
}
262264

263265
private handleToggleDocs = () => {
264-
if (!this.props.docsOpen) {
266+
if (!this.props.docsOpen && this.refDocExplorer) {
265267
this.refDocExplorer.focus()
266268
}
267269
this.props.toggleDocs(this.props.sessionId)

packages/graphql-playground-react/src/components/Playground/DocExplorer/TypeLink.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as cx from 'classnames'
33
import { bindActionCreators } from 'redux'
44
import { connect } from 'react-redux'
55
import { GraphQLList, GraphQLNonNull, isType } from 'graphql'
6-
import { Icon } from 'graphcool-styles'
76
import ArgumentInline from './ArgumentInline'
87
import { addStack } from '../../../actions/graphiql-docs'
8+
import { Triangle } from '../../Icons/Triangle'
99

1010
interface ReduxProps {
1111
keyMove: boolean
@@ -155,7 +155,8 @@ class TypeLink extends React.Component<
155155
.doc-category-icon {
156156
@p: .absolute;
157157
right: 10px;
158-
top: calc(50% - 4px);
158+
top: 50%;
159+
transform: translateY(-50%);
159160
}
160161
`}</style>
161162
<style jsx={true} global={true}>{`
@@ -208,12 +209,7 @@ class TypeLink extends React.Component<
208209
<span className="type-name">{renderType(type.type || type)}</span>
209210
{clickable && (
210211
<span className="doc-category-icon">
211-
<Icon
212-
src={require('graphcool-styles/icons/fill/triangle.svg')}
213-
color="rgba(0, 0, 0, .2)"
214-
width={6}
215-
height={7}
216-
/>
212+
<Triangle />
217213
</span>
218214
)}
219215
{afterNode && ' '}

packages/graphql-playground-react/src/components/PlaygroundStorage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,17 @@ export default class PlaygroundStorage {
172172
}
173173

174174
public setItem(key: string, value: string) {
175+
if (!this.project.data) {
176+
this.project.data = {}
177+
}
175178
this.project.data[key] = value
176179
}
177180

178181
public getItem(key: string) {
179-
return this.project.data[key]
182+
if (this.project && this.project.data) {
183+
return this.project.data[key]
184+
}
185+
return null
180186
}
181187

182188
public saveProject() {

0 commit comments

Comments
 (0)