1
- import React , { useState } from "react" ;
1
+ import React , { useEffect , useState } from "react" ;
2
2
import SyntaxHighlighter from "react-syntax-highlighter" ;
3
3
import {
4
4
Button ,
5
5
Center ,
6
6
Input ,
7
+ InputGroup ,
8
+ InputRightElement ,
9
+ Select ,
7
10
Spinner ,
8
11
Tab ,
9
12
TabList ,
@@ -14,6 +17,7 @@ import {
14
17
import axios from "axios" ;
15
18
import { t } from "i18next" ;
16
19
20
+ import CopyText from "@/components/CopyText" ;
17
21
import JsonEditor from "@/components/Editor/JsonEditor" ;
18
22
import PanelHeader from "@/components/Panel/Header" ;
19
23
import { Pages } from "@/constants" ;
@@ -34,6 +38,7 @@ export default function DebugPanel() {
34
38
35
39
const [ runningResData , setRunningResData ] = useState ( ) ;
36
40
const [ isLoading , setIsLoading ] = useState ( false ) ;
41
+ const [ runningMethod , setRunningMethod ] = useState < string > ( "" ) ;
37
42
38
43
const compileMutation = useCompileMutation ( ) ;
39
44
@@ -58,6 +63,11 @@ export default function DebugPanel() {
58
63
enabled : globalStore . currentPageId === Pages . function ,
59
64
} ,
60
65
) ;
66
+ useEffect ( ( ) => {
67
+ if ( currentFunction ?. methods ) {
68
+ setRunningMethod ( currentFunction . methods [ 0 ] ) ;
69
+ }
70
+ } , [ setRunningMethod , currentFunction ] ) ;
61
71
62
72
const runningCode = async ( ) => {
63
73
if ( isLoading || ! currentFunction ?. id ) return ;
@@ -70,7 +80,7 @@ export default function DebugPanel() {
70
80
if ( ! compileRes . error ) {
71
81
const res = await axios ( {
72
82
url : getFunctionDebugUrl ( ) ,
73
- method : "post" ,
83
+ method : runningMethod ,
74
84
data : {
75
85
func : compileRes . data || "" ,
76
86
param : JSON . parse ( params ) ,
@@ -101,10 +111,29 @@ export default function DebugPanel() {
101
111
< div className = "flex flex-col h-full" >
102
112
< div className = "flex-1 border-r-slate-300 flex flex-col" >
103
113
< div className = "flex py-4 px-2 items-center" >
104
- < Button size = "sm" className = "mr-2" >
105
- GET
106
- </ Button >
107
- < Input size = "sm" readOnly rounded = { 4 } value = { getFunctionDebugUrl ( ) } />
114
+ < Select
115
+ width = "150px"
116
+ size = "sm"
117
+ value = { runningMethod }
118
+ disabled = { getFunctionDebugUrl ( ) === "" }
119
+ onChange = { ( e ) => {
120
+ setRunningMethod ( e . target . value ) ;
121
+ } }
122
+ >
123
+ { currentFunction . methods ?. map ( ( item : string ) => {
124
+ return (
125
+ < option value = { item } key = { item } >
126
+ { item }
127
+ </ option >
128
+ ) ;
129
+ } ) }
130
+ </ Select >
131
+ < InputGroup className = "ml-2" >
132
+ < Input size = "sm" readOnly rounded = { 4 } value = { getFunctionDebugUrl ( ) } />
133
+ < InputRightElement >
134
+ < CopyText text = { getFunctionDebugUrl ( ) } className = "mb-2" />
135
+ </ InputRightElement >
136
+ </ InputGroup >
108
137
< Button
109
138
style = { { borderRadius : 2 } }
110
139
size = "sm"
0 commit comments