Skip to content

Commit 174f4f7

Browse files
authored
Merge pull request #306 from graphcool/feat/settings-shortcut
Fix bunch of issues
2 parents 3aff45f + c5bc7be commit 174f4f7

File tree

10 files changed

+72
-13
lines changed

10 files changed

+72
-13
lines changed

packages/graphql-playground-electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"author": {
99
"name": "Graphcool",
1010
"email": "[email protected]",
11-
"url": "graph.cool"
11+
"url": "http://graph.cool"
1212
},
1313
"main": "lib/main.js",
1414
"build": {

packages/graphql-playground-electron/src/ElectronApp.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ cd ${folderPath}; graphql playground`)
139139
createNewWindow()
140140
}
141141

142+
openSettingsTab = () => {
143+
if (this.playground) {
144+
this.playground.openSettingsTab()
145+
}
146+
}
147+
142148
nextTab = () => {
143149
if (this.playground) {
144150
this.playground.nextTab()
@@ -172,7 +178,7 @@ cd ${folderPath}; graphql playground`)
172178
ipcRenderer.on('File', this.readFileMessage)
173179
ipcRenderer.on('OpenSelectedFile', this.readOpenSelectedFileMessage)
174180
ipcRenderer.on('OpenUrl', this.handleUrl)
175-
window.addEventListener('keydown', this.handleKeyDown)
181+
window.addEventListener('keydown', this.handleKeyDown, true)
176182
this.consumeEvents()
177183
ipcRenderer.send('ready', '')
178184
}
@@ -197,14 +203,13 @@ cd ${folderPath}; graphql playground`)
197203
this.readOpenSelectedFileMessage,
198204
)
199205
ipcRenderer.removeListener('OpenUrl', this.handleUrl)
200-
window.removeEventListener('keydown', this.handleKeyDown)
206+
window.removeEventListener('keydown', this.handleKeyDown, true)
201207
}
202208

203209
handleKeyDown = e => {
204210
if (e.key === '{' && e.metaKey) {
205211
this.prevTab()
206-
}
207-
if (e.key === '}' && e.metaKey) {
212+
} else if (e.key === '}' && e.metaKey) {
208213
this.nextTab()
209214
}
210215
}
@@ -416,6 +421,9 @@ cd ${folderPath}; graphql playground`)
416421
case 'Close':
417422
this.closeTab()
418423
break
424+
case 'Settings':
425+
this.openSettingsTab()
426+
break
419427
}
420428
}
421429

packages/graphql-playground-electron/src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ const template: any = [
185185
// click: () => manuallyCheckForUpdates(),
186186
// },
187187
{ type: 'separator' },
188+
{
189+
label: 'Settings',
190+
accelerator: 'Command+,',
191+
click: () => send('Tab', 'Settings'),
192+
},
193+
{ type: 'separator' },
188194
{
189195
label: 'Quit',
190196
accelerator: 'Command+Q',

packages/graphql-playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
"lint-staged": "^4.0.2",
7373
"node-noop": "^1.0.0",
7474
"object-assign": "4.1.0",
75-
"polished": "^1.9.0",
7675
"postcss-cssnext": "^2.9.0",
7776
"postcss-flexbugs-fixes": "^3.2.0",
7877
"postcss-import": "^9.1.0",
@@ -120,6 +119,7 @@
120119
"graphql": "^0.10.5",
121120
"isomorphic-fetch": "^2.2.1",
122121
"js-yaml": "^3.10.0",
122+
"polished": "^1.9.0",
123123
"json-stable-stringify": "^1.0.1",
124124
"keycode": "^2.1.9",
125125
"lodash": "^4.17.4",

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ export type Theme = 'dark' | 'light'
6565
export interface EditorSettings {
6666
['editor.theme']: Theme
6767
['editor.reuseHeaders']: boolean
68+
['tracing.hideTracingResponse']: boolean
6869
}
6970

7071
const defaultSettings = `{
7172
"editor.theme": "dark",
72-
"editor.reuseHeaders": true
73+
"editor.reuseHeaders": true,
74+
"tracing.hideTracingResponse": true
7375
}`
7476

7577
class MiddlewareApp extends React.Component<Props, State> {
@@ -136,16 +138,21 @@ class MiddlewareApp extends React.Component<Props, State> {
136138
}
137139

138140
migrateSettingsString(settingsString) {
141+
const defaultSettingsObject = JSON.parse(defaultSettings)
139142
const replacementMap = {
140143
theme: 'editor.theme',
141144
reuseHeaders: 'editor.reuseHeaders',
142145
}
146+
143147
try {
144148
const settings = JSON.parse(settingsString)
145149
return JSON.stringify(
146-
mapKeys(settings, (value, key) => {
147-
return replacementMap[key] || key
148-
}),
150+
{
151+
...defaultSettingsObject,
152+
...mapKeys(settings, (value, key) => {
153+
return replacementMap[key] || key
154+
}),
155+
},
149156
null,
150157
2,
151158
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
373373
reshare: this.state.changed,
374374
isSharingAuthorization: this.isSharingAuthorization(),
375375
}}
376+
settings={this.props.settings}
376377
/>
377378
)}
378379
</GraphiqlWrapper>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface Props {
7575
disableAutofocus?: boolean
7676
disableResize?: boolean
7777
fixedEndpoint?: boolean
78+
shouldHideTracingResponse: boolean
7879

7980
disableAnimation?: boolean
8081
hideLineNumbers?: boolean
@@ -902,7 +903,9 @@ export class GraphQLEditor extends React.PureComponent<
902903
let extensions
903904
if (result.extensions) {
904905
extensions = result.extensions
905-
delete result.extensions
906+
if (this.props.shouldHideTracingResponse) {
907+
delete result.extensions.tracing
908+
}
906909
}
907910
let isSubscription = false
908911
if (result.isSubscription) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Session } from '../../types'
33
import GraphQLEditor from './GraphQLEditor'
44
import { SchemaFetcher } from './SchemaFetcher'
55
import { SharingProps } from '../Share'
6+
import { EditorSettings } from '../MiddlewareApp'
67

78
export interface Props {
89
session: Session
@@ -30,6 +31,7 @@ export interface Props {
3031
sharing?: SharingProps
3132
fixedEndpoint?: boolean
3233
endpoint: string
34+
settings: EditorSettings
3335
}
3436

3537
export default class GraphQLEditorSession extends React.PureComponent<
@@ -89,6 +91,7 @@ export default class GraphQLEditorSession extends React.PureComponent<
8991
onClickShare={this.handleClickShare}
9092
sharing={sharing}
9193
fixedEndpoint={fixedEndpoint}
94+
shouldHideTracingResponse={this.shouldHideTracingResponse()}
9295
/>
9396
)
9497
}
@@ -124,4 +127,8 @@ export default class GraphQLEditorSession extends React.PureComponent<
124127
private handleClickShare = () => {
125128
this.props.onClickShare(this.props.session.id)
126129
}
130+
131+
private shouldHideTracingResponse = (): boolean => {
132+
return this.props.settings['tracing.hideTracingResponse']
133+
}
127134
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export default class Tab extends React.PureComponent<Props, State> {
6868
.tab:hover {
6969
@p: .bgDarkBlue;
7070
}
71+
.tab:hover :global(.close) {
72+
opacity: 1;
73+
}
7174
.light.tab:hover {
7275
background-color: #eeeff0;
7376
}
@@ -120,12 +123,19 @@ export default class Tab extends React.PureComponent<Props, State> {
120123
}
121124
122125
.close {
123-
@p: .ml10, .o50, .relative;
126+
@p: .ml10, .relative;
124127
top: 1px;
125128
height: 13px;
126129
width: 13px;
130+
opacity: 0;
131+
127132
&.active {
128133
@p: .o100;
134+
opacity: 1;
135+
}
136+
137+
&.hasCircle {
138+
opacity: 1;
129139
}
130140
}
131141
@@ -196,7 +206,11 @@ export default class Tab extends React.PureComponent<Props, State> {
196206
'New Tab'}
197207
</div>
198208
<div
199-
className={`close ${index === selectedSessionIndex && 'active'}`}
209+
className={`close${index === selectedSessionIndex ? ' active' : ''}${
210+
session.isFile && session.hasChanged && !this.state.overCross
211+
? ' hasCircle'
212+
: ''
213+
}`}
200214
onClick={this.handleCloseSession}
201215
onMouseEnter={this.handleMouseOverCross}
202216
onMouseLeave={this.handleMouseOutCross}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ export interface Props {
1313
readOnly?: boolean
1414
}
1515

16+
// TODO: Trigger onSave on CMD+S or CTRL+S
17+
1618
export default class SettingsEditor extends React.Component<Props, {}> {
19+
componentDidMount() {
20+
window.addEventListener('keydown', this.handleKeydown, true)
21+
}
22+
1723
render() {
1824
const { isConfig } = this.props
1925
return (
@@ -39,6 +45,13 @@ export default class SettingsEditor extends React.Component<Props, {}> {
3945
</Wrapper>
4046
)
4147
}
48+
49+
private handleKeydown = (e: KeyboardEvent) => {
50+
if (e.key === 's' && e.metaKey) {
51+
e.preventDefault()
52+
this.props.onSave()
53+
}
54+
}
4255
}
4356

4457
const backgroundColor = theme('mode', {

0 commit comments

Comments
 (0)