Skip to content

Commit 077a907

Browse files
authored
feat(server-routes): add optional checkbox for inputs (#474)
1 parent 0f055b6 commit 077a907

4 files changed

Lines changed: 23 additions & 16 deletions

File tree

packages/devtools-kit/src/_types/integrations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface ServerRouteInfo {
5555

5656
export type ServerRouteInputType = 'string' | 'number' | 'boolean' | 'file' | 'date' | 'time' | 'datetime-local'
5757
export interface ServerRouteInput {
58+
active: boolean
5859
key: string
5960
value: any
6061
type?: ServerRouteInputType

packages/devtools/client/components/ServerRouteDetails.vue

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ const paramNames = computed(() => parsedRoute.value?.filter(i => i.startsWith(':
6464
const routeMethod = ref(props.route.method || 'GET')
6565
const routeParams = ref<{ [key: string]: string }>({})
6666
const routeInputs = reactive({
67-
query: [{ key: '', value: '', type: 'string' }] as ServerRouteInput[],
68-
body: [{ key: '', value: '', type: 'string' }] as ServerRouteInput[],
69-
headers: [{ key: 'Content-Type', value: 'application/json', type: 'string' }] as ServerRouteInput[],
67+
query: [{ active: true, key: '', value: '', type: 'string' }] as ServerRouteInput[],
68+
body: [{ active: true, key: '', value: '', type: 'string' }] as ServerRouteInput[],
69+
headers: [{ active: true, key: 'Content-Type', value: 'application/json', type: 'string' }] as ServerRouteInput[],
7070
})
7171
const routeInputBodyJSON = ref({})
7272
const {
@@ -151,9 +151,9 @@ const finalPath = computed(() => {
151151
})
152152
const finalURL = computed(() => domain.value + finalPath.value)
153153
154-
function parseInputs(inputs: any[]) {
154+
function parseInputs(inputs: ServerRouteInput[]) {
155155
const formatted = Object.fromEntries(
156-
inputs.filter(({ key, value }) => key && value !== undefined).map(({ key, value }) => [key, value]),
156+
inputs.filter(({ active, key, value }) => active && key && value !== undefined).map(({ key, value }) => [key, value]),
157157
)
158158
return Object.entries(formatted).length ? formatted : undefined
159159
}
@@ -236,6 +236,9 @@ ${items.join(',\n').split('\n').map(line => ` ${line}`).join('\n')}
236236
return snippets
237237
})
238238
239+
const cookies = ref(getCookies())
240+
const newCookie = reactive({ key: '', value: '' })
241+
239242
const tabs = computed(() => {
240243
const items = []
241244
if (paramNames.value.length) {
@@ -265,6 +268,7 @@ const tabs = computed(() => {
265268
items.push({
266269
name: 'Cookies',
267270
slug: 'cookies',
271+
length: cookies.value.length,
268272
})
269273
items.push({
270274
name: 'Snippets',
@@ -273,17 +277,13 @@ const tabs = computed(() => {
273277
return items
274278
})
275279
276-
const cookies = ref(getCookies())
277-
278280
function getCookies() {
279281
return document.cookie.split('; ').map((i) => {
280282
const [key, value] = i.split('=')
281283
return { key, value }
282-
})
284+
}).filter(i => i.key)
283285
}
284286
285-
const newCookie = reactive({ key: '', value: '' })
286-
287287
function updateCookie(key: string, value: any) {
288288
if (!key)
289289
return
@@ -359,7 +359,7 @@ const copy = useCopy()
359359
/>
360360
</div>
361361
</div>
362-
<NButton n="primary solid" @click="fetchData">
362+
<NButton h-full n="primary solid" @click="fetchData">
363363
<NIcon icon="carbon:send" />
364364
</NButton>
365365
</div>
@@ -429,7 +429,7 @@ const copy = useCopy()
429429
@input="updateCookie(cookie.key, $event.target?.value)"
430430
/>
431431
<NButton title="Delete" n="red" @click="updateCookie(cookie.key, undefined)">
432-
<NIcon icon="i-carbon-delete" />
432+
<NIcon icon="i-carbon-trash-can" />
433433
</NButton>
434434
</div>
435435
<div flex="~ gap-4">
@@ -449,7 +449,7 @@ const copy = useCopy()
449449
</div>
450450
</div>
451451
<DefineDefaultInputs>
452-
<ServerRouteInputs v-model="currentParams" :default="{ type: 'string' }" max-h-xs of-auto>
452+
<ServerRouteInputs v-model="currentParams" :default="{ active: true, type: 'string' }" max-h-xs of-auto>
453453
<template v-if="inputDefaults[activeTab]?.length">
454454
<div flex="~ gap2" mb--2 items-center op50>
455455
<div w-5 x-divider />

packages/devtools/client/components/ServerRouteInputs.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const emit = defineEmits<{ (...args: any): void }>()
1414
const params = useVModel(props, 'modelValue', emit, { passive: true })
1515
1616
const filteredKeys = computed(() => {
17-
return [...props.keys, 'key', 'value', 'type']
17+
return [...props.keys, 'active', 'key', 'value', 'type']
1818
})
1919
2020
const keysObject = computed(() => {
@@ -72,6 +72,12 @@ watch(() => params, (items) => {
7272
<slot name="input" :item="item" />
7373

7474
<template v-for="key of filteredKeys" :key="key">
75+
<NCheckbox
76+
v-if="item.type !== null && key === 'active'"
77+
v-model="item[key]"
78+
n="sm primary"
79+
:disabled="disabled"
80+
/>
7581
<NTextInput
7682
v-if="item.type !== null && key === 'key'"
7783
v-model="item[key]"
@@ -112,7 +118,7 @@ watch(() => params, (items) => {
112118

113119
<slot name="input-actions">
114120
<NButton n="red" :disabled="disabled" :class="disabled ? 'op0!' : ''" @click="params.splice(index, 1)">
115-
<NIcon icon="carbon:delete" />
121+
<NIcon icon="carbon:trash-can" />
116122
</NButton>
117123
</slot>
118124
</div>

packages/devtools/client/pages/modules/server-routes.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function capitalize(str: string) {
194194
:padding="false"
195195
:icon="ServerRouteTabIcons[tab]"
196196
>
197-
<ServerRouteInputs v-model="inputDefaults[tab]" py0 :default="{ type: 'string' }" />
197+
<ServerRouteInputs v-model="inputDefaults[tab]" py0 :default="{ active: true, type: 'string' }" />
198198
</NSectionBlock>
199199
</div>
200200
</NDrawer>

0 commit comments

Comments
 (0)