-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Painless Lab] Fix float -> integer coercion bug #60201
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ | |
import { useRef, useCallback, useState } from 'react'; | ||
import { HttpSetup } from 'kibana/public'; | ||
import { debounce } from 'lodash'; | ||
import { Response } from '../common/types'; | ||
|
||
import { API_BASE_PATH } from '../../../common/constants'; | ||
import { Response, RequestPayloadConfig } from '../common/types'; | ||
import { buildRequestPayload } from '../lib/helpers'; | ||
import { executeCode } from '../lib/execute_code'; | ||
|
||
const DEBOUNCE_MS = 800; | ||
|
||
|
@@ -20,18 +21,19 @@ export const useSubmitCode = (http: HttpSetup) => { | |
|
||
const submit = useCallback( | ||
debounce( | ||
async (code: string, context: string, contextSetup: Record<string, any>) => { | ||
async (config: RequestPayloadConfig) => { | ||
setInProgress(true); | ||
|
||
// Prevent an older request that resolves after a more recent request from clobbering it. | ||
// We store the resulting ID in this closure for comparison when the request resolves. | ||
const requestId = ++currentRequestIdRef.current; | ||
|
||
try { | ||
localStorage.setItem('painlessLabCode', code); | ||
localStorage.setItem('painlessLabContext', context); | ||
localStorage.setItem('painlessLabContextSetup', JSON.stringify(contextSetup)); | ||
const result = await executeCode(http, buildRequestPayload(code, context, contextSetup)); | ||
const result = await http.post(`${API_BASE_PATH}/execute`, { | ||
// Stringify the string, because http runs it through JSON.parse, and we want to actually | ||
// send a JSON string. | ||
body: JSON.stringify(buildRequestPayload(config)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be even more clear if we do the double stringification here with the comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, nvm I see we are building this up manually in |
||
}); | ||
|
||
if (currentRequestIdRef.current === requestId) { | ||
setResponse(result); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we add types here for
change
?