Skip to content

Commit

Permalink
feat: add query params field for GET request routes
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Nov 7, 2024
1 parent 81fe7cd commit 7684fc4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/TestRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const TestRoute: React.FC<TestRouteProps> = ({
const [verb, setVerb] = useState<Verb>('GET')
const [body, setBody] = useState<string>()
const [wildcard, setWildcard] = useState<string>()
const [queryParams, setQueryParams] = useState<string>()
const [result, setResult] = useState<unknown>('')
const [loading, setLoading] = useState<boolean>(false)

Expand Down Expand Up @@ -68,8 +69,14 @@ const TestRoute: React.FC<TestRouteProps> = ({
setResult(undefined)
setLoading(true)

const queryPrefix = queryParams?.startsWith('?') ? '' : '?'

const resource = `routes/${route.id ?? route.code}/run${
wildcard ? `/${wildcard}` : ''
wildcard
? `/${wildcard}`
: queryParams
? `${queryPrefix}${queryParams}`
: ''
}`

if (verb === 'GET') {
Expand Down Expand Up @@ -184,6 +191,15 @@ const TestRoute: React.FC<TestRouteProps> = ({
/>
)}

{verb === 'GET' && !hasWildCardPath && (
<InputField
value={queryParams}
placeholder={'query1=value&query2=value2...'}
onChange={({ value }) => setQueryParams(value)}
label={i18n.t('Query Params')}
/>
)}

<TextAreaField
helpText={i18n.t(
'Use valid JSON for this field (i.e. double quoted properties etc..)'
Expand Down

0 comments on commit 7684fc4

Please sign in to comment.