Skip to content

Commit 4213634

Browse files
authored
Add select-all checkbox for tool category groups in MCP key form (#14)
1 parent 718f906 commit 4213634

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

‎ui/src/components/AccessKeyForm.vue‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { McpAccessKey, McpTool, UpdateMcpAccessKeyRequest } from '@/api'
33
import McpToolCard from '@/components/McpToolCard.vue'
4-
import { ALL_TOOLS, groupTools } from '@/utils/tool'
4+
import { ALL_TOOLS, groupTools, type ToolCategoryGroup } from '@/utils/tool'
55
import { submitForm } from '@formkit/core'
66
import { VAlert, VButton, VSpace, VTag } from '@halo-dev/components'
77
import { utils } from '@halo-dev/ui-shared'
@@ -43,6 +43,20 @@ const unavailableAllowedTools = shallowRef(
4343
4444
const selectedCount = computed(() => props.tools.filter((tool) => selected[tool.name]).length)
4545
46+
function isCategoryFullySelected(category: ToolCategoryGroup) {
47+
return category.tools.every((tool) => selected[tool.name])
48+
}
49+
50+
function isCategoryPartiallySelected(category: ToolCategoryGroup) {
51+
return !isCategoryFullySelected(category) && category.tools.some((tool) => selected[tool.name])
52+
}
53+
54+
function toggleCategory(category: ToolCategoryGroup, checked: boolean) {
55+
for (const tool of category.tools) {
56+
selected[tool.name] = checked
57+
}
58+
}
59+
4660
function applyPreset(preset: 'read' | 'content' | 'all' | 'none') {
4761
if (preset === 'none') {
4862
unavailableAllowedTools.value = []
@@ -174,8 +188,18 @@ defineExpose({
174188
</div>
175189
<div class=":uno: flex flex-col gap-4">
176190
<div v-for="category in group.categories" :key="category.category">
177-
<div class=":uno: mb-2 flex items-center gap-2 text-xs text-gray-500 font-medium">
178-
<span>{{ category.label }}</span>
191+
<div class=":uno: mb-3 flex items-center gap-2 text-xs text-gray-500 font-medium">
192+
<label class=":uno: flex cursor-pointer items-center gap-1.5">
193+
<input
194+
type="checkbox"
195+
class=":uno: h-3.5 w-3.5 accent-[rgb(var(--colors-primary))]"
196+
:checked="isCategoryFullySelected(category)"
197+
:indeterminate.prop="isCategoryPartiallySelected(category)"
198+
:aria-label="`选择${category.label}分组全部工具`"
199+
@change="toggleCategory(category, ($event.target as HTMLInputElement).checked)"
200+
/>
201+
<span>{{ category.label }}</span>
202+
</label>
179203
<span>{{ category.tools.length }}</span>
180204
</div>
181205
<div class=":uno: grid grid-cols-1 gap-3 sm:grid-cols-2">

0 commit comments

Comments
 (0)