Skip to content

Commit cf882eb

Browse files
Fix error with Copy CURL
1 parent 63eef0b commit cf882eb

File tree

1 file changed

+23
-26
lines changed
  • packages/graphql-playground-react/src/components/Playground/TopBar

1 file changed

+23
-26
lines changed

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

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { share } from '../../../state/sharing/actions'
2323
import { openHistory } from '../../../state/general/actions'
2424
import { getSettings } from '../../../state/workspace/reducers'
25+
import { Session } from '../../../state/sessions/reducers'
2526
import { ISettings } from '../../../types'
2627

2728
export interface Props {
@@ -30,6 +31,7 @@ export interface Props {
3031
fixedEndpoint?: boolean
3132
isPollingSchema: boolean
3233
endpointUnreachable: boolean
34+
session: Session
3335

3436
editEndpoint: (value: string) => void
3537
prettifyQuery: () => void
@@ -99,10 +101,10 @@ class TopBar extends React.Component<Props, {}> {
99101
const curl = this.getCurl()
100102
copy(curl)
101103
}
102-
onChange = e => {
104+
onChange = (e) => {
103105
this.props.editEndpoint(e.target.value)
104106
}
105-
onKeyDown = e => {
107+
onKeyDown = (e) => {
106108
if (e.keyCode === 13) {
107109
this.props.refetchSchema()
108110
}
@@ -111,8 +113,7 @@ class TopBar extends React.Component<Props, {}> {
111113
this.props.openHistory()
112114
}
113115
getCurl = () => {
114-
// no need to rerender the whole time. only on-demand the store is fetched
115-
const session = getSelectedSession(this.context.store.getState())
116+
const session = this.props.session
116117
let variables
117118
try {
118119
variables = JSON.parse(session.variables)
@@ -140,14 +141,12 @@ class TopBar extends React.Component<Props, {}> {
140141
...sessionHeaders,
141142
}
142143
const headersString = Object.keys(headers)
143-
.map(key => {
144+
.map((key) => {
144145
const value = headers[key]
145146
return `-H '${key}: ${value}'`
146147
})
147148
.join(' ')
148-
return `curl '${
149-
session.endpoint
150-
}' ${headersString} --data-binary '${data}' --compressed`
149+
return `curl '${session.endpoint}' ${headersString} --data-binary '${data}' --compressed`
151150
}
152151
}
153152

@@ -157,24 +156,22 @@ const mapStateToProps = createStructuredSelector({
157156
isPollingSchema: getIsPollingSchema,
158157
endpointUnreachable: getEndpointUnreachable,
159158
settings: getSettings,
159+
session: getSelectedSession,
160160
})
161161

162-
export default connect(
163-
mapStateToProps,
164-
{
165-
editEndpoint,
166-
prettifyQuery,
167-
openHistory,
168-
share,
169-
refetchSchema,
170-
},
171-
)(TopBar)
162+
export default connect(mapStateToProps, {
163+
editEndpoint,
164+
prettifyQuery,
165+
openHistory,
166+
share,
167+
refetchSchema,
168+
})(TopBar)
172169

173170
export const Button = styled.button`
174171
text-transform: uppercase;
175172
font-weight: 600;
176-
color: ${p => p.theme.editorColours.buttonText};
177-
background: ${p => p.theme.editorColours.button};
173+
color: ${(p) => p.theme.editorColours.buttonText};
174+
background: ${(p) => p.theme.editorColours.button};
178175
border-radius: 2px;
179176
flex: 0 0 auto;
180177
letter-spacing: 0.53px;
@@ -188,13 +185,13 @@ export const Button = styled.button`
188185
margin-left: 0;
189186
}
190187
&:hover {
191-
background-color: ${p => p.theme.editorColours.buttonHover};
188+
background-color: ${(p) => p.theme.editorColours.buttonHover};
192189
}
193190
`
194191

195192
const TopBarWrapper = styled.div`
196193
display: flex;
197-
background: ${p => p.theme.editorColours.navigationBar};
194+
background: ${(p) => p.theme.editorColours.navigationBar};
198195
padding: 10px 10px 4px;
199196
align-items: center;
200197
`
@@ -204,13 +201,13 @@ interface UrlBarProps {
204201
}
205202

206203
const UrlBar = styled<UrlBarProps, 'input'>('input')`
207-
background: ${p => p.theme.editorColours.button};
204+
background: ${(p) => p.theme.editorColours.button};
208205
border-radius: 4px;
209-
color: ${p =>
206+
color: ${(p) =>
210207
p.active
211208
? p.theme.editorColours.navigationBarText
212209
: p.theme.editorColours.textInactive};
213-
border: 1px solid ${p => p.theme.editorColours.background};
210+
border: 1px solid ${(p) => p.theme.editorColours.background};
214211
padding: 6px 12px;
215212
padding-left: 30px;
216213
font-size: 13px;
@@ -236,7 +233,7 @@ const ReachError = styled.div`
236233
const Pulse = styled.div`
237234
width: 16px;
238235
height: 16px;
239-
background-color: ${p => p.theme.editorColours.icon};
236+
background-color: ${(p) => p.theme.editorColours.icon};
240237
border-radius: 100%;
241238
`
242239

0 commit comments

Comments
 (0)